Switching @ActionRegistration to be lazy.
authorJesse Glick <jglick@netbeans.org>
Wed, 23 May 2012 10:01:43 -0400
changeset 17829d3543b073d02
parent 17828 3068981dcc29
child 17830 082d5b484874
Switching @ActionRegistration to be lazy.
apisupport.projectinspector/src/org/netbeans/modules/apisupport/projectinspector/InspectProjectAction.java
     1.1 --- a/apisupport.projectinspector/src/org/netbeans/modules/apisupport/projectinspector/InspectProjectAction.java	Mon May 07 17:34:21 2012 -0400
     1.2 +++ b/apisupport.projectinspector/src/org/netbeans/modules/apisupport/projectinspector/InspectProjectAction.java	Wed May 23 10:01:43 2012 -0400
     1.3 @@ -30,6 +30,7 @@
     1.4  
     1.5  import java.awt.EventQueue;
     1.6  import java.awt.event.ActionEvent;
     1.7 +import java.awt.event.ActionListener;
     1.8  import java.io.File;
     1.9  import java.io.PrintWriter;
    1.10  import java.lang.reflect.Field;
    1.11 @@ -38,13 +39,11 @@
    1.12  import java.net.URL;
    1.13  import java.util.Arrays;
    1.14  import java.util.Comparator;
    1.15 +import java.util.List;
    1.16  import java.util.Map;
    1.17  import java.util.TreeMap;
    1.18  import java.util.TreeSet;
    1.19 -import javax.swing.AbstractAction;
    1.20  import javax.swing.Action;
    1.21 -import javax.swing.JComponent;
    1.22 -import javax.swing.JMenuItem;
    1.23  import org.netbeans.api.java.classpath.ClassPath;
    1.24  import org.netbeans.api.java.classpath.JavaClassPathConstants;
    1.25  import org.netbeans.api.java.project.JavaProjectConstants;
    1.26 @@ -79,13 +78,11 @@
    1.27  import org.openide.awt.ActionReference;
    1.28  import org.openide.awt.ActionRegistration;
    1.29  import org.openide.awt.Actions;
    1.30 -import org.openide.awt.DynamicMenuContent;
    1.31  import org.openide.filesystems.FileObject;
    1.32  import org.openide.filesystems.FileUtil;
    1.33  import org.openide.filesystems.URLMapper;
    1.34  import org.openide.loaders.DataObject;
    1.35  import org.openide.nodes.Node;
    1.36 -import org.openide.util.ContextAwareAction;
    1.37  import org.openide.util.Exceptions;
    1.38  import org.openide.util.Lookup;
    1.39  import org.openide.util.RequestProcessor;
    1.40 @@ -99,30 +96,14 @@
    1.41  @ActionID(id = "org.netbeans.modules.apisupport.projectinspector.InspectProjectAction", category = "Tools")
    1.42  @ActionRegistration(displayName = "Inspect Project Metadata")
    1.43  @ActionReference(path = "Projects/Actions", position = 2000)
    1.44 -public class InspectProjectAction extends AbstractAction implements ContextAwareAction {
    1.45 +public class InspectProjectAction implements ActionListener {
    1.46  
    1.47 -    /** Default constructor for layer. */
    1.48 -    public InspectProjectAction() {
    1.49 -        super("Inspect Project Metadata");
    1.50 +    private final List<Project> projects;
    1.51 +
    1.52 +    public InspectProjectAction(List<Project> projects) {
    1.53 +        this.projects = projects;
    1.54      }
    1.55  
    1.56 -    public void actionPerformed(ActionEvent e) {
    1.57 -        assert false;
    1.58 -    }
    1.59 -
    1.60 -    public Action createContextAwareInstance(Lookup actionContext) {
    1.61 -        return new Impl(actionContext);
    1.62 -    }
    1.63 -
    1.64 -    private static final class Impl extends AbstractAction implements DynamicMenuContent {
    1.65 -
    1.66 -        private final Lookup actionContext;
    1.67 -
    1.68 -        public Impl(Lookup actionContext) {
    1.69 -            super("Inspect Project Metadata");
    1.70 -            this.actionContext = actionContext;
    1.71 -        }
    1.72 -
    1.73          public void actionPerformed(ActionEvent e) {
    1.74              RequestProcessor.getDefault().post(new Runnable() {
    1.75                  public void run() {
    1.76 @@ -134,7 +115,7 @@
    1.77                              try {
    1.78                                  pw.reset();
    1.79                                  boolean first = true;
    1.80 -                                for (Project p : actionContext.lookupAll(Project.class)) {
    1.81 +                                for (Project p : projects) {
    1.82                                      if (!first) {
    1.83                                          pw.println();
    1.84                                          pw.println("-------------------------------------------");
    1.85 @@ -154,19 +135,6 @@
    1.86              });
    1.87          }
    1.88  
    1.89 -        public JComponent[] getMenuPresenters() {
    1.90 -            if (actionContext.lookup(Project.class) != null) {
    1.91 -                return new JComponent[] {new JMenuItem(this)};
    1.92 -            } else {
    1.93 -                return new JComponent[0];
    1.94 -            }
    1.95 -        }
    1.96 -
    1.97 -        public JComponent[] synchMenuPresenters(JComponent[] items) {
    1.98 -            return getMenuPresenters();
    1.99 -        }
   1.100 -    }
   1.101 -
   1.102      private static void dump(Project p, final PrintWriter pw) throws Exception {
   1.103          pw.println("Project: \"" + ProjectUtils.getInformation(p).getDisplayName() + "\" (" + ProjectUtils.getInformation(p).getName() + ")");
   1.104          pw.println("Location: " + FileUtil.getFileDisplayName(p.getProjectDirectory()));