This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 136334 - Utilities.actionsForPath
Summary: Utilities.actionsForPath
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Nodes (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Jesse Glick
URL:
Keywords: API, API_REVIEW_FAST
Depends on:
Blocks:
 
Reported: 2008-06-03 03:53 UTC by Jesse Glick
Modified: 2008-12-22 10:56 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Proposed patch for main (101.05 KB, patch)
2008-06-05 04:43 UTC, Jesse Glick
Details | Diff
Proposed patch for contrib (20.29 KB, patch)
2008-06-05 04:43 UTC, Jesse Glick
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2008-06-03 03:53:29 UTC
A lot of code in NB uses the following idiom:

private void addFromLayers(List<Action> actions, String path) {
    Lookup look = Lookups.forPath(path);
    for (Object next : look.lookupAll(Object.class)) {
        if (next instanceof Action) {
            actions.add((Action) next);
        } else if (next instanceof JSeparator) {
            actions.add(null);
        }
    }
}                

This is used especially in project type logical views to add actions defined in a folder. (DataLoader.actionsContext has
rather more complex code, as it also handles setActions, and has some weird threading logic.)

Sometimes an older and even more verbose variant is used that uses Repository.getDefault(), DataObject, and FolderLookup
or InstanceCookie.

Most of these usages could be replaced with

public static List<? extends Action/*|null*/> NodeOp.actionsForPath(String path);
Comment 1 Jesse Glick 2008-06-05 04:43:13 UTC
Created attachment 62397 [details]
Proposed patch for main
Comment 2 Jesse Glick 2008-06-05 04:43:56 UTC
Created attachment 62398 [details]
Proposed patch for contrib
Comment 3 Jesse Glick 2008-06-05 04:45:17 UTC
Please review the proposed change.
Comment 4 Milos Kleint 2008-06-05 12:55:48 UTC
looks great. It indeed removed a lot of duplicated code. I'm wondering if we could use layers to specify the complete
project node popup. the profiler actions location is a clear workaround of that. The challenge there would be to combine
actions that are project type specific with the ones that are to be applied to projects of any type.
Comment 5 Jesse Glick 2008-06-05 14:02:07 UTC
Right, I don't have a proposal at the moment for completely specifying project root node actions by layer. You could do
something like what the MIME Lookup API does for merging SFS folders. (Which gets a bit ugly when you deal with folder
ordering: positions are spread across several physical folders.) Or perhaps an entry in the folder could be a *.shadow
pointing to a generic dir like Projects/Actions (not sure offhand if FolderLookup handles this), assuming you never need
to interpolate project-specific actions into the block of generic actions. Such a system would probably be useful for
many project types; freeform and autoproject would likely not use it since they do runtime calculation of a context
menu; apisupport does too.
Comment 6 Jaroslav Tulach 2008-06-05 19:37:30 UTC
Y01 the change does not belong to Nodes API, it is unrelated to nodes. Imho it belongs next to actionsToPopup and 
actionsGlobalContext.
Comment 7 Jesse Glick 2008-06-05 19:44:25 UTC
To Y01: could go into org.openide.util.Utilities. I picked NodeOp because it is generally used to implement
Node.getActions() and has similarities to other methods in NodeOp used for working with context menus. Anyone else have
an opinion on placement?
Comment 8 Jesse Glick 2008-06-11 19:45:14 UTC
Moved to Utilities and committed: core-main #8cda72aa3101

Will leave contrib until gets pushed to main.
Comment 9 Jesse Glick 2008-06-12 14:51:19 UTC
contrib #548925bdefcf