Calling Back to NetBeans Platform Actions

When registering custom Actions for Cut and Copy, this is the code to use in NetBeans Platform 7.1:

ActionMap actionMap = getActionMap();
actionMap.put("copy-to-clipboard",
        FileUtil.getConfigObject(
        "Actions/Customer/org-shop-editor-MyCustomCopyAction.instance", Action.class));
actionMap.put("cut-to-clipboard",
        FileUtil.getConfigObject(
        "Actions/Customer/org-shop-editor-MyCustomCutAction.instance", Action.class));
associateLookup(new ProxyLookup(
        ExplorerUtils.createLookup(em, actionMap),
        new AbstractLookup(instanceContent)));

However, what about NetBeans Platform actions for which there are no standard macros? Today I discovered that you can, at least in the instances below, use the "id" of the NetBeans Platform Action class as your key, where the Action class must be a CallbackSystemAction, as shown below for the FindAction and the ReplaceAction:

ActionMap actionMap = getActionMap();
actionMap.put("org.openide.actions.FindAction",
        FileUtil.getConfigObject(
        "Actions/Customer/org-shop-editor-MyCustomFindAction.instance", Action.class));
actionMap.put("org.openide.actions.ReplaceAction",
        FileUtil.getConfigObject(
        "Actions/Customer/org-shop-editor-MyCustomReplaceAction.instance", Action.class));
associateLookup(new ProxyLookup(
        ExplorerUtils.createLookup(em, actionMap),
        new AbstractLookup(instanceContent))); 

Now, when you look in the Edit menu or Edit toolbar, you'll see that your Find and Replace actions are enabled and will do whatever is defined in your custom action.

Comments:

I tried your example using MyAction which implements the DeleteAction. DeleteAction has a macro defined so I connected it using "delete" in the ActionMap.

In this case how should MyAction be declared if it's a context aware action ?

Mine is declared using annotations:

@ActionID(category = "Edit", id = "org.MyAction")
@ActionRegistration(displayName = "My Action")
public final class MyAction implements ActionListener
{
private final List<MyObject> context;

public MyAction (List<MyObject> context)
{
this.context = context;
}

@Override
public void actionPerformed(ActionEvent ev)
{
// Do nothing
}
}

I can see in the menu the Delete action gets enabled/disabled OK according to selection, but when I execute it (actionPerformed does nothing), I get a strange Exception

SEVERE [org.openide.util.RequestProcessor]: Error in RequestProcessor org.openide.util.actions.ActionInvoker$2
java.lang.AssertionError
at org.openide.awt.GeneralAction$BaseDelAction.actionPerformed(GeneralAction.java:231)

Which is Caused: org.openide.util.RequestProcessor$SlowItem: task failed due to...

Any idea ?

Posted by guest on December 20, 2011 at 12:14 AM PST #

Hi Geertjan --

I'm working on functional-test projects where TestNG tests live on the "Source Packages" side of the project instead of in "Test Packages" where you would normally find them.

The test actions in Netbeans, "Test File", and "Run Focused Test File" (grayed-out) will not execute these tests from the IDE. I'm forced to run the test projects via Maven on the CLI. Apparently, IntelliJ can do this, and I am being encouraged strongly to switch IDEs for my current work.

Do you have any advice on getting tests in "Source" to behave and respond in the IDE like they live in "Tests"?

thanks for your help,

cg

Posted by cg on June 09, 2016 at 04:06 PM PDT #

Unclear what this has to do with this blog entry. Why not join the NetBeans mailing lists like everyone else who has questions about NetBeans IDE?

Posted by Geertjan on June 09, 2016 at 04:18 PM PDT #

PS: For the record, test files, regardless of whether they're functional or not, do not live in Source Packages, but in Test Packages.

Posted by Geertjan on June 09, 2016 at 04:20 PM PDT #

Yup, I know ... but ... out of my control.

I'll dig through the fora to see if this has ever come up. Single-method tests on the test side of projects of course works great.

Thanks, Geertjan.

cg

Posted by cg on June 09, 2016 at 04:28 PM PDT #

It's beyond your control to put test files in the correct place in your project? No, there's no need to dig around anywhere, since that doesn't make sense at all.

Posted by Geertjan on June 09, 2016 at 04:31 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Categories
Archives
« July 2016
SunMonTueWedThuFriSat
     
3
9
15
16
17
18
20
24
25
26
27
28
29
30
31
      
Today