Note: These pages are being reviewed.
How can we reuse and organise existing actions in our menus or pop menus? Usually you need to know the original location of the action you want to use and then refer to it as shadow in your layer.xml file. This requires you to create such as file what you want less and less.
Fortunately there is solution: use annotations such as @ActionReference, @ActionReferences and @ActionID. Their usage is obvious when you create your own actions, but how can they be used to refer to existing actions?
Create an empty class that you will include in your module:
public class ActionsRefs {
}
Next annotate this class with @ActionReference, @ActionReferences:
@ActionReferences(value = {
@ActionReference(id = @ActionID(category = "System",
id = "org.openide.actions.FileSystemRefreshAction"),
path = "Console/Service/Brokers/Actions/MessageBus",
position = 200)})
class ActionsRefs {
}
This class will be used as action reference configuration and the annotation preprocessor will create the proper entries the the generated layer.xml file. Notice the embeded @ActionID? This refers to the existing Action.
Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DevFaqHowOrganizeOrReuseExistingActionsWithAnnotations , that was last modified by NetBeans user Jmborer on 2014-01-09T14:05:20Z.
NOTE: This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.