KacerCZ commented on a change in pull request #2173:
URL: https://github.com/apache/netbeans/pull/2173#discussion_r437592446



##########
File path: 
php/php.composer/src/org/netbeans/modules/php/composer/ui/actions/ComposerScriptsAction.java
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.php.composer.ui.actions;
+
+import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
+import org.netbeans.modules.php.api.phpmodule.PhpModule;
+import org.netbeans.modules.php.composer.commands.Composer;
+import org.netbeans.modules.php.composer.files.ComposerJson;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionRegistration;
+import org.openide.awt.Actions;
+import org.openide.awt.DynamicMenuContent;
+import org.openide.util.ContextAwareAction;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle;
+import org.openide.util.actions.Presenter;
+
+@ActionID(id = 
"org.netbeans.modules.php.composer.ui.actions.ComposerScriptsAction", category 
= "Project")
+@ActionRegistration(displayName = "#ComposerScriptsAction.name", lazy = false)
+@ActionReference(path = "Projects/org-netbeans-modules-php-project/Actions", 
position = 1051)
[email protected]("ComposerScriptsAction.name=Composer Scripts")
+public class ComposerScriptsAction extends AbstractAction implements 
ContextAwareAction, Presenter.Popup {
+
+    final Project project;
+    final List<String> scripts = new CopyOnWriteArrayList<>();
+
+    public ComposerScriptsAction() {
+        this(null, null);
+    }
+
+    public ComposerScriptsAction(Project project, Collection<String> scripts) {
+        this.project = project;
+        if (scripts != null) {
+            this.scripts.addAll(scripts);
+        }
+        setEnabled(project != null);
+        putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
+        // hide this action from Tools > Keymap
+        putValue(Action.NAME, ""); // NOI18N
+    }
+
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        assert false;
+    }
+
+    @Override
+    public Action createContextAwareInstance(Lookup context) {
+        Project contextProject = context.lookup(Project.class);
+        if (contextProject == null) {
+            return this;
+        }
+        PhpModule phpModule = PhpModule.Factory.lookupPhpModule(context);
+        ComposerJson composerJson = new 
ComposerJson(phpModule.getProjectDirectory());
+        if (composerJson == null) {
+            return this;
+        }
+        Set<String> allScripts = composerJson.getScripts();
+        if (allScripts.isEmpty()) {
+            return this;
+        }
+        List<String> scripts = new ArrayList<>(allScripts);
+        Collections.sort(scripts);
+        return new ComposerScriptsAction(contextProject, scripts);
+    }
+
+    @Override
+    public JMenuItem getPopupPresenter() {
+        if (project == null) {
+            return new Actions.MenuItem(this, false);
+        }
+        return createScriptsMenu();
+    }
+
+    private JMenuItem createScriptsMenu() {
+        assert project != null;
+        assert !scripts.isEmpty();
+        JMenu menu = new JMenu(Bundle.ComposerScriptsAction_name());
+        for (final String command : scripts) {
+            RunScriptAction scriptAction = new RunScriptAction(command);
+            menu.add(scriptAction);
+        }
+        return menu;
+    }
+
+    //~ Inner classes
+    private class RunScriptAction extends BaseComposerAction {

Review comment:
       Changed class to `static`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to