/*
 * Copyright 2015 Matthew Aguirre
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.l2fprod.common.beans.editor;

import com.l2fprod.common.annotations.EditorRegistry;
import javax.swing.JComboBox;

/**
 *
 * @author matta
 */
@EditorRegistry(type = Enum.class)
public class EnumerationPropertyEditor extends ComboBoxPropertyEditor {

    private Class<?> baseType;

    public EnumerationPropertyEditor() {
        super();

    }

    @Override
    public Object getValue() {
        JComboBox e = (JComboBox) editor;
        return e.getSelectedItem();
    }

    @Override
    public void setValue(Object value) {
        if (this.baseType == null) {
            this.baseType = value.getClass();
            setAvailableValues(baseType.getEnumConstants());
        }

        JComboBox e = (JComboBox) editor;

        for (int ii = 0; ii < e.getItemCount(); ii++) {
            if (value != null && e.getItemAt(ii).equals(value.getClass().getCanonicalName())) {
                e.setSelectedIndex(ii);
                break;
            }
        }
    }
}

@@ -1,10 +1,11 @@
 /*
+%0D
 %0A * Copy
@@ -30,20 +30,22 @@
  Aguirre
+%0D
 %0A * 
+%0D
 %0A * Lice
@@ -103,16 +103,17 @@
 cense%22);
+%0D
 %0A * you 
@@ -172,16 +172,17 @@
 License.
+%0D
 %0A * You 
@@ -216,20 +216,22 @@
 cense at
+%0D
 %0A * 
+%0D
 %0A *     
@@ -272,20 +272,22 @@
 ENSE-2.0
+%0D
 %0A * 
+%0D
 %0A * Unle
@@ -349,16 +349,17 @@
 software
+%0D
 %0A * dist
@@ -419,16 +419,17 @@
 %22 BASIS,
+%0D
 %0A * WITH
@@ -496,16 +496,17 @@
 implied.
+%0D
 %0A * See 
@@ -568,16 +568,17 @@
 ions and
+%0D
 %0A * limi
@@ -603,20 +603,22 @@
 License.
+%0D
 %0A */
+%0D
 %0Apackage
@@ -650,17 +650,19 @@
 .editor;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -707,16 +707,17 @@
 egistry;
+%0D
 %0Aimport 
@@ -742,16 +742,20 @@
 Box;
-%0A
+%0D%0A%0D
 %0A/**
+%0D
 %0A *
+%0D
 %0A * 
@@ -767,20 +767,22 @@
 or matta
+%0D
 %0A */
+%0D
 %0A@Editor
@@ -808,16 +808,17 @@
 m.class)
+%0D
 %0Apublic 
@@ -881,17 +881,19 @@
 Editor %7B
-%0A
+%0D%0A%0D
 %0A    pri
@@ -915,17 +915,19 @@
 aseType;
-%0A
+%0D%0A%0D
 %0A    pub
@@ -955,24 +955,25 @@
 tyEditor() %7B
+%0D
 %0A        sup
@@ -981,16 +981,20 @@
 r();
-%0A
+%0D%0A%0D
 %0A    %7D
-%0A
+%0D%0A%0D
 %0A   
@@ -995,32 +995,33 @@
 %0A%0D%0A    @Override
+%0D
 %0A    public Obje
@@ -1035,16 +1035,17 @@
 alue() %7B
+%0D
 %0A       
@@ -1078,16 +1078,17 @@
  editor;
+%0D
 %0A       
@@ -1115,23 +1115,26 @@
 dItem();
+%0D
 %0A    %7D
-%0A
+%0D%0A%0D
 %0A    @Ov
@@ -1139,16 +1139,17 @@
 Override
+%0D
 %0A    pub
@@ -1181,16 +1181,17 @@
 value) %7B
+%0D
 %0A       
@@ -1219,16 +1219,17 @@
  null) %7B
+%0D
 %0A       
@@ -1266,16 +1266,17 @@
 Class();
+%0D
 %0A       
@@ -1328,16 +1328,17 @@
 ants());
+%0D
 %0A       
@@ -1339,17 +1339,19 @@
        %7D
-%0A
+%0D%0A%0D
 %0A       
@@ -1388,253 +1388,62 @@
 tor;
+%0D
 %0A
-%0A 
        
-for (int ii = 0; ii %3C e.getItemCount(); ii++) %7B%0A            if (value != null && e.getItemAt(ii).equals(value.getClass().getCanonicalName())) %7B%0A                e.setSelectedIndex(ii);%0A                break;%0A            %7D%0A        %7D%0A    %7D%0A%7D
+ e.getModel().setSelectedItem(value);%0D%0A    %7D%0D%0A%7D%0D
 %0A

Fix item selection in enum property editor.