Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EnableBackgroundScanningActions to SQE DropDownButton. #9

Merged
merged 1 commit into from
Oct 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.nbheaven.sqe.codedefects.core.util.SQECodedefectSupport;
import org.nbheaven.sqe.codedefects.ui.actions.AbstractQualitySessionAwareAction;
import org.netbeans.api.project.Project;
import org.openide.awt.Actions;
import org.openide.util.Lookup;
import org.openide.util.actions.Presenter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import javax.swing.AbstractAction;
import org.nbheaven.sqe.codedefects.core.api.QualityProvider.SessionEventProxy;
import org.nbheaven.sqe.core.utilities.SQEProjectSupport;
import org.netbeans.api.project.Project;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import org.nbheaven.sqe.codedefects.core.api.QualityProvider;
import org.nbheaven.sqe.codedefects.core.api.QualitySession;
import org.nbheaven.sqe.codedefects.core.util.SQECodedefectSupport;
import org.nbheaven.sqe.codedefects.ui.actions.AbstractQualitySessionAwareAction;
import org.netbeans.api.project.Project;
import org.openide.awt.Actions;
import org.openide.util.Lookup;
import org.openide.util.actions.Presenter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,13 @@
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import org.openide.awt.Actions;
import org.openide.awt.DropDownButtonFactory;
import org.openide.cookies.InstanceCookie;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.util.ContextAwareAction;
import org.openide.util.Lookup;
import org.openide.util.Utilities;
Expand All @@ -49,50 +39,29 @@
*/
public class QualityProvidersToolbarDropdownAction implements Action, Presenter.Toolbar, ContextAwareAction {

private List<Action> providerActions;
private List<? extends Action> actions;
private final Action defaultAction;
private JButton toolbarPresenter;
private JPopupMenu dropdownPopup;
private Lookup context;

public QualityProvidersToolbarDropdownAction() {
this(Utilities.actionsGlobalContext());
}

private QualityProvidersToolbarDropdownAction(Lookup context) {
providerActions = findProviderActions(context);
defaultAction = providerActions.iterator().next();
this.context = context;
actions = findActions(context);
defaultAction = actions.iterator().next();
}

@Override
public Action createContextAwareInstance(Lookup actionContext) {
return new QualityProvidersToolbarDropdownAction(actionContext);
}

private static List<Action> findProviderActions(Lookup context) {
// XXX could probably use Utilities.actionsForPath + Utilities.actionsToPopup
FileObject actionsFO = FileUtil.getConfigFile("Menu/Quality/CodeDefects");
ArrayList<Action> actions = new ArrayList<Action>();
for (FileObject actionsFileObject : FileUtil.getOrder(Arrays.asList(actionsFO.getChildren()), true)) {
try {
if (actionsFileObject.isData()) {
DataObject dob = DataObject.find(actionsFileObject);
InstanceCookie cookie = dob.getLookup().lookup(InstanceCookie.class);
if (null != cookie) {
Action action = (Action) cookie.instanceCreate();
if (null != context && action instanceof ContextAwareAction) {
actions.add(((ContextAwareAction) action).createContextAwareInstance(context));
} else {
actions.add(action);
}
}
}
} catch (DataObjectNotFoundException donfe) {
} catch (IOException ioex) {
} catch (ClassNotFoundException cnfe) {
}
}
actions.trimToSize();
return actions.isEmpty() ? Collections.<Action>emptyList() : actions;
private static List<? extends Action> findActions(Lookup context) {
return Utilities.actionsForPath("Menu/Quality/CodeDefects");
}

@Override
Expand Down Expand Up @@ -133,62 +102,13 @@ public void removePropertyChangeListener(PropertyChangeListener listener) {
@Override
public Component getToolbarPresenter() {
if (toolbarPresenter == null) {

dropdownPopup = new DropDownPopupMenu();
for (Action action : providerActions) {
dropdownPopup.add(createDropdownItem(action));
}

dropdownPopup = Utilities.actionsToPopup(actions.toArray(new Action[0]), context);
JButton button = DropDownButtonFactory.createDropDownButton(new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), dropdownPopup);
Actions.connect(button, this);
// defaultAction.addPropertyChangeListener(new PropertyChangeListener() {
//
// public void propertyChange(PropertyChangeEvent evt) {
// if (defaultAction.isEnabled()) {
// toolbarPresenter.putClientProperty(DropDownButtonFactory.PROP_DROP_DOWN_MENU, dropdownPopup);
// } else {
// toolbarPresenter.putClientProperty(DropDownButtonFactory.PROP_DROP_DOWN_MENU, null);
// }
// }
// });

toolbarPresenter = button;
}

return toolbarPresenter;
}

private static JMenuItem createDropdownItem(final Action action) {
JMenuItem item;
if (action instanceof Presenter.Popup) {
item = ((Presenter.Popup) action).getPopupPresenter();
} else {
item = new JMenuItem(action);
}
Actions.connect(item, action, true);
return item;
}

private static class DropDownPopupMenu extends JPopupMenu {

private DropDownPopupMenu() {
}

@Override
public void setVisible(boolean visible) {
for (Component c : getComponents()) {
if (c instanceof Actions.MenuItem) {
Actions.MenuItem item = (Actions.MenuItem) c;
item.synchMenuPresenters(null); // Hack to force item state update
} else if (c instanceof JMenuItem) {
JMenuItem item = (JMenuItem) c;
Action action = item.getAction();
if (null != action) {
item.setEnabled(action.isEnabled());
}
}
}
super.setVisible(visible);
}
}
}
}
8 changes: 8 additions & 0 deletions codedefects.ui/src/org/nbheaven/sqe/codedefects/ui/layer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
<attr name="originalFile" stringvalue="Actions/Quality/org-nbheaven-sqe-codedefects-ui-actions-RunAllQualityProvidersAction.instance"/>
<attr name="position" intvalue="100"/>
</file>
<file name="org-nbheaven-sqe-codedefects-ui-actions-separatorAfter.instance">
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="150"/>
</file>
<file name="org-nbheaven-sqe-codedefects-ui-actions-separatorBefore.instance">
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="900"/>
</file>
</folder>
</folder>
</folder>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
import javax.swing.Action;
import org.nbheaven.sqe.codedefects.ui.actions.AbstractEnableBackgroundScanningAction;
import org.nbheaven.sqe.tools.checkstyle.codedefects.core.CheckstyleQualityProvider;
import org.nbheaven.sqe.codedefects.ui.actions.AbstractShowProjectResultAnnotationsAction;
import org.nbheaven.sqe.core.utilities.SQEProjectSupport;
import org.nbheaven.sqe.tools.checkstyle.codedefects.core.CheckstyleSession;
import org.openide.util.ContextAwareAction;
import org.openide.util.ImageUtilities;
import org.openide.util.Lookup;
import org.openide.util.Utilities;

Expand All @@ -46,8 +44,8 @@ public EnableCheckstyleBackgroundScanningAction(CheckstyleSession session) {
private EnableCheckstyleBackgroundScanningAction(Lookup context) {
super(context, CheckstyleQualityProvider.getDefault());

putValue(Action.NAME, "Enable checkstyle background scanning");//NbBundle.getMessage(ShowCheckstyleProjectResultAnnotationsAction.class, "LBL_CheckstyleAction")); //NOI18N
putValue(SMALL_ICON, ImageUtilities.image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/tools/checkstyle/codedefects/core/resources/visible.png")));
putValue(Action.NAME, "Enable Checkstyle background scanning");//NbBundle.getMessage(ShowCheckstyleProjectResultAnnotationsAction.class, "LBL_CheckstyleAction")); //NOI18N
// putValue(SMALL_ICON, ImageUtilities.image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/tools/checkstyle/codedefects/core/resources/visible.png")));
updateActionState();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*
* @author Florian Vogler
*/
public class RunCheckstyleAction extends AbstractQualitySessionAwareAction implements ContextAwareAction {
public final class RunCheckstyleAction extends AbstractQualitySessionAwareAction implements ContextAwareAction {

private final QualityProvider provider;

Expand All @@ -49,10 +49,9 @@ public RunCheckstyleAction() {
private RunCheckstyleAction(Lookup context) {
super(context, CheckstyleQualityProvider.getDefault().getSessionEventProxy());
this.provider = CheckstyleQualityProvider.getDefault();

// putValue("noIconInMenu", Boolean.TRUE); // NOI18N
putValue(Action.NAME, NbBundle.getMessage(RunCheckstyleAction.class, "LBL_CheckstyleAction")); //NOI18N
putValue(SMALL_ICON, ImageUtilities.image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/tools/checkstyle/codedefects/core/resources/checkstyle.png")));
updateActionState();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,14 @@
<attr name="originalFile" stringvalue="Actions/Quality/org-nbheaven-sqe-tools-checkstyle-codedefects-core-actions-RunCheckstyleAction.instance"/>
<attr name="position" intvalue="400"/>
</file>
<file name="EnableCheckstyleBackgroundScanningAction.shadow">
<attr name="originalFile" stringvalue="Actions/Quality/org-nbheaven-sqe-tools-checkstyle-codedefects-core-actions-EnableCheckstyleBackgroundScanningAction.instance"/>
<attr name="position" intvalue="1400"/>
</file>
</folder>
</folder>
</folder>

<folder name="Toolbars">
<folder name="Quality">
<attr name="position" intvalue="569"/>
<file name="EnableCheckstyleBackgroundScanningAction.shadow">
<attr name="originalFile" stringvalue="Actions/Quality/org-nbheaven-sqe-tools-checkstyle-codedefects-core-actions-EnableCheckstyleBackgroundScanningAction.instance"/>
<attr name="position" intvalue="400"/>
</file>
</folder>
</folder>

<!-- SQE Integration -->
<folder name="SQE">
<folder name="Providers">
Expand All @@ -70,6 +64,7 @@
<attr name="originalFile" stringvalue="Actions/Quality/org-nbheaven-sqe-tools-checkstyle-codedefects-core-actions-RunCheckstyleAction.instance"/>
<attr name="position" intvalue="400"/>
</file>

</folder>
</folder>
</folder>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import org.nbheaven.sqe.codedefects.core.api.QualityProvider;
import org.nbheaven.sqe.codedefects.core.api.QualityProvider.SessionEventProxy;
import org.nbheaven.sqe.codedefects.core.api.QualityResult;
import org.nbheaven.sqe.codedefects.core.api.QualitySession;
import org.nbheaven.sqe.core.utilities.SQEProjectSupport;
import org.nbheaven.sqe.tools.checkstyle.codedefects.core.CheckstyleQualityProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

import javax.swing.Action;
import org.nbheaven.sqe.codedefects.ui.actions.AbstractEnableBackgroundScanningAction;
import org.nbheaven.sqe.codedefects.ui.actions.AbstractShowProjectResultAnnotationsAction;
import org.nbheaven.sqe.core.utilities.SQEProjectSupport;
import org.nbheaven.sqe.tools.findbugs.codedefects.core.FindBugsQualityProvider;
import org.nbheaven.sqe.tools.findbugs.codedefects.core.FindBugsSession;
import org.openide.util.ContextAwareAction;
import org.openide.util.ImageUtilities;
import org.openide.util.Lookup;
import org.openide.util.Utilities;

Expand All @@ -46,8 +44,8 @@ public EnableFindBugsBackgroundScanningAction(FindBugsSession session) {
private EnableFindBugsBackgroundScanningAction(Lookup context) {
super(context, FindBugsQualityProvider.getDefault());

putValue(Action.NAME, "Enable findbugs background scanning");//NbBundle.getMessage(ShowCheckstyleProjectResultAnnotationsAction.class, "LBL_CheckstyleAction")); //NOI18N
putValue(SMALL_ICON, ImageUtilities.image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/visible.png")));
putValue(Action.NAME, "Enable FindBugs background scanning");//NbBundle.getMessage(ShowCheckstyleProjectResultAnnotationsAction.class, "LBL_CheckstyleAction")); //NOI18N
// putValue(SMALL_ICON, ImageUtilities.image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/visible.png")));
updateActionState();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*
* @author Florian Vogler
*/
public class RunFindBugsAction extends AbstractQualitySessionAwareAction implements ContextAwareAction {
public final class RunFindBugsAction extends AbstractQualitySessionAwareAction implements ContextAwareAction {

private final QualityProvider provider;

Expand All @@ -54,6 +54,7 @@ private RunFindBugsAction(Lookup context) {
// putValue("noIconInMenu", Boolean.TRUE); // NOI18N
putValue(Action.NAME, NbBundle.getMessage(RunFindBugsAction.class, "LBL_RunFindBugsAction")); //NOI18N
putValue(SMALL_ICON, ImageUtilities.image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/findbugs.png")));
updateActionState();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,14 @@
<attr name="originalFile" stringvalue="Actions/Quality/org-nbheaven-sqe-tools-findbugs-codedefects-core-actions-RunFindBugsAction.instance"/>
<attr name="position" intvalue="200"/>
</file>
<file name="EnableFindBugsBackgroundScanningAction.shadow">
<attr name="originalFile" stringvalue="Actions/Quality/org-nbheaven-sqe-tools-findbugs-codedefects-core-actions-EnableFindBugsBackgroundScanningAction.instance"/>
<attr name="position" intvalue="1200"/>
</file>
</folder>
</folder>
</folder>

<folder name="Toolbars">
<folder name="Quality">
<attr name="position" intvalue="569"/>
<file name="EnableFindBugsBackgroundScanningAction.shadow">
<attr name="originalFile" stringvalue="Actions/Quality/org-nbheaven-sqe-tools-findbugs-codedefects-core-actions-EnableFindBugsBackgroundScanningAction.instance"/>
<attr name="position" intvalue="200"/>
</file>
</folder>
</folder>

<!-- SQE Integration -->
<folder name="SQE">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

import javax.swing.Action;
import org.nbheaven.sqe.codedefects.ui.actions.AbstractEnableBackgroundScanningAction;
import org.nbheaven.sqe.codedefects.ui.actions.AbstractShowProjectResultAnnotationsAction;
import org.nbheaven.sqe.core.utilities.SQEProjectSupport;
import org.nbheaven.sqe.tools.pmd.codedefects.core.PMDQualityProvider;
import org.nbheaven.sqe.tools.pmd.codedefects.core.PMDSession;
import org.openide.util.ContextAwareAction;
import org.openide.util.ImageUtilities;
import org.openide.util.Lookup;
import org.openide.util.Utilities;

Expand All @@ -46,8 +44,8 @@ public EnablePMDBackgroundScanningAction(PMDSession session) {
private EnablePMDBackgroundScanningAction(Lookup context) {
super(context, PMDQualityProvider.getDefault());

putValue(Action.NAME, "Enable findbugs background scanning");//NbBundle.getMessage(ShowCheckstyleProjectResultAnnotationsAction.class, "LBL_CheckstyleAction")); //NOI18N
putValue(SMALL_ICON, ImageUtilities.image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/visible.png")));
putValue(Action.NAME, "Enable PMD background scanning");//NbBundle.getMessage(ShowCheckstyleProjectResultAnnotationsAction.class, "LBL_CheckstyleAction")); //NOI18N
// putValue(SMALL_ICON, ImageUtilities.image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/visible.png")));
updateActionState();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*
* @author Florian Vogler
*/
public class RunPMDAction extends AbstractQualitySessionAwareAction implements ContextAwareAction {
public final class RunPMDAction extends AbstractQualitySessionAwareAction implements ContextAwareAction {

private final QualityProvider provider;

Expand All @@ -54,6 +54,7 @@ private RunPMDAction(Lookup context) {
// putValue("noIconInMenu", Boolean.TRUE); // NOI18N
putValue(Action.NAME, NbBundle.getMessage(RunPMDAction.class, "LBL_RunPMDAction")); //NOI18N
putValue(SMALL_ICON, ImageUtilities.image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/tools/pmd/codedefects/core/resources/pmd.png")));
updateActionState();
}

@Override
Expand Down
Loading