package net.sourceforge.javydreamercsw.vm.client.hierarchy.hierarchyvisualizer;

import com.validation.manager.core.db.Requirement;
import java.awt.BorderLayout;
import java.util.Collection;
import java.util.logging.Logger;
import javax.swing.JComponent;
import net.sourceforge.javydreamercsw.vm.client.hierarchy.hierarchyvisualizer.scene.HierarchyScene;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.explorer.view.BeanTreeView;
import org.openide.util.Lookup;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;
import org.openide.util.Utilities;
import org.openide.util.lookup.Lookups;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(
        dtd = "-//net.sourceforge.javydreamercsw.vm.client.hierarchy.hierarchyvisualizer//HierarchyViewer//EN",
        autostore = false)
@TopComponent.Description(
        preferredID = "HierarchyViewerTopComponent",
        //iconBase="SET/PATH/TO/ICON/HERE", 
        persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "editor", openAtStartup = true)
@ActionID(category = "Window", id = "net.sourceforge.javydreamercsw.vm.client.hierarchy.hierarchyvisualizer.HierarchyViewerTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
        displayName = "#CTL_HierarchyViewerAction",
        preferredID = "HierarchyViewerTopComponent")
@Messages({
    "CTL_HierarchyViewerAction=Hierarchy Viewer",
    "CTL_HierarchyViewerTopComponent=Relationship Window",
    "HINT_HierarchyViewerTopComponent=This is a Hierarchy Viewer window"
})
public final class HierarchyViewerTopComponent extends TopComponent implements LookupListener {

    private final Lookup.Result<Requirement> result =
            Utilities.actionsGlobalContext().lookupResult(Requirement.class);
    private static final Logger LOG =
            Logger.getLogger(HierarchyViewerTopComponent.class.getSimpleName());
    private final HierarchyScene scene;
    private final JComponent myView;

    public HierarchyViewerTopComponent() {
        initComponents();
        setName(Bundle.CTL_HierarchyViewerTopComponent());
        setToolTipText(Bundle.HINT_HierarchyViewerTopComponent());

        scene = new HierarchyScene();
        myView = scene.createView();

        hierarchyPane.setViewportView(myView);
        
        add(scene.createSatelliteView(), BorderLayout.WEST);
        
        associateLookup(Lookups.fixed(
                // exposed TopComponent, 
                //   and SatelliteViewProvider, BirdViewProvider interfaces, too
                (HierarchyViewerTopComponent) this, 
                getActionMap() // do not forget expose ActionMap
                , scene // if some object needs it and if it is final
                ));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        hierarchyPane = new BeanTreeView();

        setLayout(new java.awt.BorderLayout());
        add(hierarchyPane, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane hierarchyPane;
    // End of variables declaration//GEN-END:variables
    @Override
    public void componentOpened() {
        result.addLookupListener((HierarchyViewerTopComponent) this);
    }

    @Override
    public void componentClosed() {
        result.removeLookupListener((HierarchyViewerTopComponent) this);
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    void readProperties(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }

    @Override
    public void resultChanged(LookupEvent le) {
        Collection<? extends Requirement> results = result.allInstances();
        if (results.isEmpty()) {
            LOG.fine("No requirements selected.");
        } else {
            LOG.fine("Selected the following requirements:");
            scene.clear();
            for (Requirement req : results) {
                LOG.info(req.getUniqueId());
                scene.addRequirement(req);
            }
        }
    }
}

@@ -406,81 +406,8 @@
 es;%0A
-import org.openide.awt.ActionID;%0Aimport org.openide.awt.ActionReference;%0A
 impo
@@ -449,16 +449,16 @@
 eeView;%0A
+
 import o
@@ -1053,17 +1053,16 @@
 N/HERE%22,
- 
 %0A       
@@ -1183,207 +1183,8 @@
 ue)%0A
-@ActionID(category = %22Window%22, id = %22net.sourceforge.javydreamercsw.vm.client.hierarchy.hierarchyvisualizer.HierarchyViewerTopComponent%22)%0A@ActionReference(path = %22Menu/Window%22 /*, position = 333 */)%0A
 @Top
@@ -1667,18 +1667,16 @@
 %3E result
- =
 %0A       
@@ -1679,16 +1679,18 @@
         
+ =
  Utiliti
@@ -1783,18 +1783,16 @@
 gger LOG
- =
 %0A       
@@ -1795,16 +1795,18 @@
         
+ =
  Logger.
@@ -2264,25 +2264,17 @@
 yView);%0A
-        
 %0A
+
         
@@ -2330,17 +2330,9 @@
 T);%0A
-        
 %0A
+
     
@@ -2406,17 +2406,16 @@
 mponent,
- 
 %0A       
@@ -2539,17 +2539,16 @@
 t) this,
- 
 %0A       
@@ -2675,24 +2675,16 @@
 s final%0A
-        
         

Remove action from menu.