package nl.fontys.sofa.limo.view.node.bean;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
import nl.fontys.sofa.limo.domain.component.Icon;
import nl.fontys.sofa.limo.domain.component.leg.Leg;
import nl.fontys.sofa.limo.view.node.property.StupidProperty;
import nl.fontys.sofa.limo.view.node.property.editor.EventPropertyEditor;
import nl.fontys.sofa.limo.view.node.property.editor.ProcedurePropertyEditor;
import nl.fontys.sofa.limo.view.util.LIMOResourceBundle;
import org.openide.ErrorManager;
import org.openide.nodes.Sheet;

/**
 * View representation of a Leg. This class is used to display a NormalLeg and
 * is used by ScheduledLegNode and MultiModeLegNode.
 *
 * @author Sebastiaan Heijmann
 */
public class LegNode extends AbstractBeanNode<Leg> {

    /**
     * /**
     * constructor for LegNode, calls the second constructor with the correct
     * class name.
     *
     * @param bean
     * @throws IntrospectionException
     */
    public LegNode(Leg bean) throws IntrospectionException {
        this(bean, Leg.class);
    }

    /**
     * constructor for LegNode, adds the bean to the instancecontent.
     *
     * @param bean the base entity
     * @param entityClass the class name of the entity
     * @throws IntrospectionException
     */
    public LegNode(Leg bean, Class entityClass) throws IntrospectionException {
        super(bean, entityClass);
    }
    
    protected PropertyChangeListener getListener() {
        return new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue());
                if (evt.getPropertyName().equals("name")) {
                    setDisplayName((String) evt.getNewValue());
                } else if (evt.getPropertyName().equals("description")) {
                    setShortDescription((String) evt.getNewValue());
                } else if (evt.getPropertyName().equals("icon")) {
                    createProperties(getBean(), null);
                    setSheet(getSheet());
                }
            }
        };
    }
    
    @Override
    public boolean canDestroy() {
        throw new UnsupportedOperationException(LIMOResourceBundle.getString("NOT_SUPPORTED"));
    }
    
    @Override
    public AbstractBeanNode getDetachedNodeCopy() {
        throw new UnsupportedOperationException(LIMOResourceBundle.getString("COPY_NOT_SUPPORTED"));
    }
    
    @Override
    Class getServiceClass() {
        return null;
    }
    
    @Override
    protected Icon getBeanIcon() {
        return getBean().getIcon();
    }
    
    public void refresh() {
        createProperties(bean, null);
    }
    
    @Override
    protected void createProperties(Leg bean, BeanInfo info) {
        Sheet sets = getSheet();
        Sheet.Set set = super.getBaseEntityPropertySheet();
        
        try {
            StupidProperty eventProp = new StupidProperty(getBean(), List.class, "events");
            eventProp.addPropertyChangeListener(getListener());
            eventProp.setPropertyEditorClass(EventPropertyEditor.class);
            eventProp.setDisplayName(LIMOResourceBundle.getString("EVENTS"));
            eventProp.setShortDescription(LIMOResourceBundle.getString("EVENTS_OF", LIMOResourceBundle.getString("HUB")));
            eventProp.setValue("canEditAsText", false);
            
            StupidProperty procedureProp = new StupidProperty(getBean(), List.class, "procedures");
            procedureProp.addPropertyChangeListener(getListener());
            procedureProp.setPropertyEditorClass(ProcedurePropertyEditor.class);
            procedureProp.setDisplayName(LIMOResourceBundle.getString("PROCEDURES"));
            procedureProp.setShortDescription(LIMOResourceBundle.getString("PROCEDURES_OF", LIMOResourceBundle.getString("HUB")));
            procedureProp.setValue("canEditAsText", false);
            set.put(procedureProp);
            set.put(eventProp);
        } catch (NoSuchMethodException ex) {
            ErrorManager.getDefault();
        }
        sets.put(set);
    }

    @Override
    public void delete() {
        //TODO
    }
    
}

@@ -1504,29 +1504,25 @@
 ass);%0A    %7D%0A
-    
 %0A
+
     protecte
@@ -2265,37 +2265,33 @@
        %7D;%0A    %7D%0A
-    
 %0A
+
     @Override%0A  
@@ -2416,37 +2416,33 @@
 ORTED%22));%0A    %7D%0A
-    
 %0A
+
     @Override%0A  
@@ -2590,37 +2590,33 @@
 ORTED%22));%0A    %7D%0A
-    
 %0A
+
     @Override%0A  
@@ -2662,37 +2662,33 @@
 urn null;%0A    %7D%0A
-    
 %0A
+
     @Override%0A  
@@ -2758,29 +2758,25 @@
 on();%0A    %7D%0A
-    
 %0A
+
     public v
@@ -2835,21 +2835,17 @@
 ;%0A    %7D%0A
-    
 %0A
+
     @Ove
@@ -3006,25 +3006,17 @@
 heet();%0A
-        
 %0A
+
         
@@ -3511,21 +3511,9 @@
 e);%0A
-            
 %0A
+
     
@@ -4280,23 +4280,146 @@
    /
-/TODO
+**%0A         * Delete is empty because the LegNodes aren't saved in the database and therefore didn't need to be deleted.%0A         */
 %0A    %7D%0A
-    
 %0A%7D%0A

Add comment to empty delete in LegNode