package nl.fontys.sofa.limo.view.node.property.editor;

import com.sksamuel.gaia.Country;
import java.awt.Component;
import java.beans.PropertyEditorSupport;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import nl.fontys.sofa.limo.domain.component.hub.Location;
import org.openide.nodes.PropertyEditorRegistration;

/**
 *
 * @author Dominik Kaisers <d.kaisers@student.fontys.nl>
 */
@PropertyEditorRegistration(targetType = Country.class)
public class CountryPopertyEditor extends PropertyEditorSupport{
    
    private HashMap<String, Country> countriesByName = new HashMap<>();

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        setValue(countriesByName.get(text));
    }

    @Override
    public String getAsText() {
        if (getValue() == null)
            return "";
        
        return ((Country) getValue()).getName();
    }

    @Override
    public String[] getTags() {
        String[] names = new String[Country.getAll().size()];
        List<Country> selectable = Country.getAll();
        countriesByName.clear();
        for (Country country : selectable) {
            names[selectable.indexOf(country)] = country.getName();
            countriesByName.put(country.getName(), country);
        }
        return names;
    }
    
}

@@ -87,35 +87,8 @@
 ry;%0A
-import java.awt.Component;%0A
 impo
@@ -177,88 +177,8 @@
 st;%0A
-import java.util.Map;%0Aimport nl.fontys.sofa.limo.domain.component.hub.Location;%0A
 impo
@@ -581,16 +581,83 @@
 ption %7B%0A
+        if (text.equals(%22-%22))%0A            setValue(null);%0A        %0A
         
@@ -798,16 +798,17 @@
 return %22
+-
 %22;%0A     
@@ -972,16 +972,20 @@
 ).size()
+ + 1
 %5D;%0A     
@@ -1061,24 +1061,48 @@
 me.clear();%0A
+        names%5B0%5D = %22-%22;%0A
         for 
@@ -1179,16 +1179,20 @@
 country)
+ + 1
 %5D = coun

Fix for "no country select"