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

import java.io.IOException;
import javax.swing.Action;
import nl.fontys.sofa.limo.api.exception.ServiceNotFoundException;
import nl.fontys.sofa.limo.api.service.provider.EventService;
import nl.fontys.sofa.limo.domain.component.event.Event;
import nl.fontys.sofa.limo.view.custom.pane.NameDescriptionDialogInputPane;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.actions.NewAction;
import org.openide.nodes.Children;
import org.openide.util.actions.SystemAction;
import org.openide.util.datatransfer.NewType;

/**
 *
 * @author Sebastiaan Heijmann
 */
public class EventRootNode extends AbstractRootNode {

    public EventRootNode(Children children) throws ServiceNotFoundException {
        super(children);
    }

    @Override
    Class getServiceClass() {
        return EventService.class;
    }

    @Override
    Class getBeanClass() {
        return Event.class;
    }
    
    @Override
    public Action[] getActions(boolean context) {
        return new Action[]{SystemAction.get(NewAction.class)};
    }
    
    @Override
    public NewType[] getNewTypes() {
        return new NewType[]{new NewType() {

            @Override
            public String getName() {
                return "Hub";
            }

            @Override
            public void create() throws IOException {
                NameDescriptionDialogInputPane inputPane = new NameDescriptionDialogInputPane();
                DialogDescriptor dd = new DialogDescriptor(inputPane, "Event");
                Object result = DialogDisplayer.getDefault().notify(dd);

                String name = inputPane.getNameFieldValue();
                String description = inputPane.getDescriptionFieldValue();

                if (!name.isEmpty() && !description.isEmpty()) {
                    Event e = new Event();
                    e.setName(name);
                    e.setDescription(description);
                    service.insert(e);
                }
            }
        }};
    }
}

@@ -949,36 +949,32 @@
 nt.class;%0A    %7D%0A
-    
 %0A    @Override%0A 
@@ -1092,20 +1092,16 @@
 ;%0A    %7D%0A
-    
 %0A    @Ov
@@ -1278,11 +1278,13 @@
 rn %22
-Hub
+Event
 %22;%0A 

fix typo