Java Code Examples for org.openide.loaders.DataObject#getNodeDelegate()

The following examples show how to use org.openide.loaders.DataObject#getNodeDelegate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoreAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public JMenuItem getPopupPresenter() {
    Lookup l = Utilities.actionsGlobalContext();
    Collection<? extends MatchingObject> matchingObjects
            = l.lookupAll(MatchingObject.class);
    LinkedHashSet<Action> commonActions = new LinkedHashSet<Action>();
    boolean first = true;
    for (MatchingObject mo : matchingObjects) {
        DataObject dob = mo.getDataObject();
        if (dob != null) {
            Node nodeDelegate = dob.getNodeDelegate();
            Collection<Action> dobActions = Arrays.asList(
                    nodeDelegate.getActions(false));
            if (first) {
                commonActions.addAll(dobActions);
                first = false;
            } else {
                commonActions.retainAll(dobActions);
            }
        }
    }
    return actionsToMenu(commonActions, l);
}
 
Example 2
Source File: PageFlowView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void setActivatedNode(final DataObject dataObject, final DataObject srcFolder) {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                setActivatedNode(dataObject, srcFolder);
            }
        });
        return;
    }
    if (dataObject == null) {
        setActivatedNodes(new Node[]{});
        return;
    }
    Node node = new DefaultDataNode(dataObject, srcFolder != null ? srcFolder.getNodeDelegate() : null);
    setActivatedNodes(new Node[]{node});
}
 
Example 3
Source File: ProjectAssetsNodeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public NodeList createNodes(Project project) {

        this.proj = project;

        DataObject assetsFolder;
        try {
            //return a new node for the project view if theres an assets folder:
            ProjectAssetManager item = project.getLookup().lookup(ProjectAssetManager.class);
            if (item != null) {
                assetsFolder = DataObject.find(item.getAssetFolder());
                Node node = assetsFolder.getNodeDelegate();
//                return NodeFactorySupport.fixedNodeList(node);
                ProjectAssetsNode nd = new ProjectAssetsNode(item, proj, node);
//                return NodeFactorySupport.createCompositeChildren(project, item.getAssetFolderName());//fixedNodeList(nd);
                return NodeFactorySupport.fixedNodeList(nd);
            }
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }

        //If our item isn't in the lookup,
        //then return an empty list of nodes:
        return NodeFactorySupport.fixedNodeList();

    }
 
Example 4
Source File: ModuleLogicalViewTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails // NB-Core-Build #7306: same result for DataObject as for FileObject expected:<null> but was:<FilterNode[Name=FreeformProjectTest...]>
public void testFindPath() throws Exception {
    Project freeform = ProjectManager.getDefault().findProject(FileUtil.toFileObject(file("ant.freeform")));
    assertNotNull("have project in ant.freeform", freeform);
    LogicalViewProvider lvp = freeform.getLookup().lookup(LogicalViewProvider.class);
    assertNotNull("have a LogicalViewProvider", lvp);
    assertNotNull("found arch.xml", find(lvp, "ant.freeform/arch.xml"));
    assertNotNull("found FreeformProject.java", find(lvp, "ant.freeform/src/org/netbeans/modules/ant/freeform/FreeformProject.java"));
    assertNotNull("found freeform-project-general.xsd", find(lvp, "ant.freeform/src/org/netbeans/modules/ant/freeform/resources/freeform-project-general.xsd"));
    assertNotNull("found FreeformProjectTest.java", find(lvp, "ant.freeform/test/unit/src/org/netbeans/modules/ant/freeform/FreeformProjectTest.java"));
    Node layer = find(lvp, "ant.freeform/src/org/netbeans/modules/ant/freeform/resources/layer.xml");
    assertNotNull("Found layer", layer);
    assertEquals("Sources is parent parent of the layer", "${src.dir}", layer.getParentNode().getParentNode().getName());
    assertFalse("Has children: " + layer, layer.isLeaf());
    DataObject obj = layer.getLookup().lookup(DataObject.class);
    assertNotNull("There is a data object", obj);
    Node origLayer = obj.getNodeDelegate();
    assertFalse("Also has children", origLayer.isLeaf());
}
 
Example 5
Source File: BrowseFolders.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected Node[] createNodes(Key key) {
    FileObject fObj = key.folder;
    SourceGroup grp = key.group;
    boolean isFile = !fObj.isFolder();

    try {
        DataObject dobj = DataObject.find(fObj);
        FilterNode fn = new FilterNode(dobj.getNodeDelegate(), isFile ? Children.LEAF : new SourceGroupsChildren(fObj, grp)) {
            @Override
            public Action getPreferredAction() {
                // #161908
                return null;
            }
        };
        return new Node[] {fn};
    } catch (DataObjectNotFoundException e) {
        return null;
    }
}
 
Example 6
Source File: ResNodeFactoryProvider.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public Node createNode(Project p, SourceGroup sg) {
    try {
        DataObject dobj = DataObject.find(sg.getRootFolder());
        Node node = cache.get(dobj);
        if (node == null) {
            node = new AndroidResourceNode(dobj.getNodeDelegate(), p, sg.getDisplayName());
            cache.put(dobj, node);
        }
        return node;
    } catch (DataObjectNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    }
    return null;
}
 
Example 7
Source File: HtmlEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean close(boolean ask) {
    boolean closed = super.close(ask);
    DataObject dobj = getDataObject();
    if(closed && dobj.isValid()) {
        //set the original property sets
        HtmlDataNode nodeDelegate = (HtmlDataNode)dobj.getNodeDelegate();
        nodeDelegate.setPropertySets(null);
    }
    return closed;
}
 
Example 8
Source File: SerialDataNodeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDisplayName() throws Exception {
    String res = "Settings/org-netbeans-modules-settings-convertors-testDisplayName.settings";
    FileObject fo = FileUtil.getConfigFile(res);
    assertNotNull(res, fo);
    assertNull("name", fo.getAttribute("name"));
    
    DataObject dobj = DataObject.find (fo);
    Node n = dobj.getNodeDelegate();
    assertNotNull(n);
    assertEquals("I18N", n.getDisplayName());
    
    // property sets have to be initialized otherwise the change name would be
    // propagated to the node after some delay (~2s)
    Object garbage = n.getPropertySets();
    
    InstanceCookie ic = (InstanceCookie) dobj.getCookie(InstanceCookie.class);
    assertNotNull (dobj + " does not contain instance cookie", ic);
    
    FooSetting foo = (FooSetting) ic.instanceCreate();
    String newName = "newName";
    foo.setName(newName);
    assertEquals(n.toString(), newName, n.getDisplayName());
    
    newName = "newNameViaNode";
    n.setName(newName);
    assertEquals(n.toString(), newName, n.getDisplayName());
    assertEquals(n.toString(), newName, foo.getName());
}
 
Example 9
Source File: ImportantFilesNode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected Node[] createNodes(FileObject key) {
    try {
        DataObject obj = DataObject.find(key);
        return new Node[]{obj.getNodeDelegate()};
    } catch (DataObjectNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    }
    return new Node[]{};
}
 
Example 10
Source File: SdksCustomizer.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void refreshPlatforms() {
    platformsList.clear();
    FileObject storage = FileUtil.getConfigFile(STORAGE);
    if (storage != null) {
        java.util.Map<String, PlatformCategoriesDescriptor> categories = new HashMap<String, PlatformCategoriesDescriptor>();
        for (FileObject child : storage.getChildren()) {
            try {
                final DataObject dobj = DataObject.find(child);
                Node node = dobj.getNodeDelegate();
                AndroidSdk platform = node.getLookup().lookup(AndroidSdk.class);
                if (platform != null) {
                    platformsList.add(platform);
                    final String platformType = "Android";
                    final String platformTypeDisplayName = "Android";
                    PlatformCategoriesDescriptor platforms = categories.get(platformType);
                    if (platforms == null) {
                        platforms = new PlatformCategoriesDescriptor(platformTypeDisplayName);
                        categories.put(platformType, platforms);
                    }
                    platforms.add(node);
                } else {
                    LOG.log(Level.WARNING, "Platform node for : {0} has no platform in its lookup.", node.getDisplayName());   //NOI18N
                }
            } catch (DataObjectNotFoundException e) {
                Exceptions.printStackTrace(e);
            }
        }
        List<PlatformCategoriesDescriptor> keys = new ArrayList<SdksCustomizer.PlatformCategoriesDescriptor>(categories.values());
        Collections.sort(keys);
        setKeys(keys);
    }
}
 
Example 11
Source File: SourcesNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static Node createResourcesFolderNode(SourceGroup group) {
    try {
        DataObject root = DataObject.find(group.getRootFolder());
        return new ResourcesFolderNode(group, root.getNodeDelegate());
    } catch(DataObjectNotFoundException ex) {
        //Shall not happen...
    }
    return null;
}
 
Example 12
Source File: AbstractPaletteTestHid.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected Node getItemNode( String catName, String itemName ) throws DataObjectNotFoundException {
    FileObject fo = getItemFile( catName, itemName );
    DataObject dobj = DataObject.find( fo );
    if( null == dobj ) {
        fail( "Item data object '" + itemName + "' not found." );
    }
    return dobj.getNodeDelegate();
}
 
Example 13
Source File: OpenProjectList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static List<TemplateItem> prepareTemplates(@NullAllowed Project project, @NonNull Lookup lookup) {
    // check the action context for recommmended/privileged templates..
    PrivilegedTemplates privs = lookup.lookup(PrivilegedTemplates.class);
    final List<TemplateItem> items = new ArrayList<TemplateItem>();
    for (DataObject template : OpenProjectList.getDefault().getTemplatesLRU(project, privs)) {
        Node delegate = template.getNodeDelegate();
        items.add(new TemplateItem(template, delegate.getDisplayName(), ImageUtilities.image2Icon(delegate.getIcon(BeanInfo.ICON_COLOR_16x16))));
    }
    return items;
}
 
Example 14
Source File: RunAnalysisPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Icon getIcon() {
    try {
        DataObject d = DataObject.find(file);
        Node n = d.getNodeDelegate();
        return ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
    } catch (DataObjectNotFoundException ex) {
        LOG.log(Level.FINE, null, ex);
        return null;
    }
}
 
Example 15
Source File: DefaultDataLoadersBridge.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Node getNodeDelegate(JTextComponent target) {
    DataObject dobj = getDataObject(target.getDocument());
    return dobj!=null ? dobj.getNodeDelegate() : null;
}
 
Example 16
Source File: ApksFilterNodeChildrens.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@Override
protected Node[] createNodes(DataObject key) {
    return new Node[]{new FilterNode(key.getNodeDelegate())};
}
 
Example 17
Source File: LayerNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override protected Node createNodeForKey(DataObject key) {
    return new LayerFilterNode(key.getNodeDelegate());
}
 
Example 18
Source File: DefaultOpenFileImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void openInEDT(FileObject fileObject, DataObject dataObject, int line) {
    Class<? extends Node.Cookie> cookieClass;        
    Node.Cookie cookie;
    
    if ((line != -1)
        && (   ((cookie = dataObject.getCookie(cookieClass = EditorCookie.Observable.class)) != null)
            || ((cookie = dataObject.getCookie(cookieClass = EditorCookie.class)) != null) )) {
        boolean ret = openByCookie(cookie, cookieClass, line);
        if (!ret) {
            showNotPlainFileWarning(fileObject);
        }
        return;
    } 
                        
    /* try to open the object using the default action */
    Node dataNode = dataObject.getNodeDelegate();        
    Action action = dataNode.getPreferredAction();
    if ((action != null)
            && !(action instanceof FileSystemAction)
            && !(action instanceof ToolsAction)) {
        if (log.isLoggable(FINEST)) {
            log.log(FINEST, " - using preferred action "            //NOI18N
                    + "(\"{0}\" - {1}) for opening the file",       //NOI18N
                    new Object[]{action.getValue(Action.NAME),
                        action.getClass().getName()});
        }

        if (action instanceof ContextAwareAction) {
            action = ((ContextAwareAction) action)
              .createContextAwareInstance(dataNode.getLookup());
            if (log.isLoggable(FINEST)) {
                log.finest("    - it is a ContextAwareAction");     //NOI18N
                log.log(FINEST, "    - using a context-aware "      //NOI18N
                        + "instance instead (\"{0}\" - {1})",       //NOI18N
                        new Object[]{action.getValue(Action.NAME),
                            action.getClass().getName()});
            }
        }

        log.finest("   - will call action.actionPerformed(...)");   //NOI18N
        final Action a = action;
        final Node n = dataNode;
        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {

            @Override
            public void run() {
                a.actionPerformed(new ActionEvent(n, 0, ""));
            }
        });
        return;
    }             
    String fileName = fileObject.getNameExt();
    /* Try to grab an editor/open/edit/view cookie and open the object: */
    StatusDisplayer.getDefault().setStatusText(
            NbBundle.getMessage(DefaultOpenFileImpl.class,
                                "MSG_opening",                      //NOI18N
                                fileName));
    boolean success = openDataObjectByCookie(dataObject, line);
    if (success) {
        return;
    }        
    if (fileObject.isFolder() || FileUtil.isArchiveFile(fileObject)) {
        // select it in explorer:
        final Node node = dataObject.getNodeDelegate();
        if (node != null) {
            WindowManager.getDefault().invokeWhenUIReady(new Runnable() {

                @Override
                public void run() {
                    NodeOperation.getDefault().explore(node);
                }
            });
            return;
        }
    }
    showNotPlainFileWarning(fileObject);
}
 
Example 19
Source File: HtmlElementProperties.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static void parsed(final HtmlParserResult result, SchedulerEvent event) {
    try {
        FileObject file = result.getSnapshot().getSource().getFileObject();
        if (file == null) {
            LOGGER.log(LEVEL, "null file, exit");
            return;
        }

        if (!file.isValid()) {
            LOGGER.log(LEVEL, "invalid file, exit");
            return;
        }

        final DataObject dobj = DataObject.find(file);
        org.openide.nodes.Node dataObjectNode = dobj.getNodeDelegate();
        if(!(dataObjectNode instanceof HtmlDataNode)) {
            return ;
        }
        final HtmlDataNode htmlNode =  (HtmlDataNode) dataObjectNode;
        
        final int caretOffset;
        if (event == null) {
            LOGGER.log(LEVEL, "run() - NULL SchedulerEvent?!?!?!");
            caretOffset = -1;
        } else {
            if (event instanceof CursorMovedSchedulerEvent) {
                caretOffset = ((CursorMovedSchedulerEvent) event).getCaretOffset();
            } else {
                LOGGER.log(LEVEL, "run() - !(event instanceof CursorMovedSchedulerEvent)");
                caretOffset = -1;
            }
        }

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                runInEDT(result, htmlNode, dobj, caretOffset);
            }
        });


    } catch (DataObjectNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    }

}
 
Example 20
Source File: WebFolderListener.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void fileCreatedEventHandler(FileObject fileObj) {
    PageFlowView view = pfc.getView();
    if (!isKnownFileEvent(fileObj)) {

        /* Semi Hack: The point is to update a model if a new model is created
        for a given page as a sideeffect of an "UNKNOWN" page being created */
        for (PageContentModelProvider provider : impls) {
            FileObject jspFileObject = provider.isNewPageContentModel(fileObj);
            if (jspFileObject != null && isKnownFileEvent(jspFileObject)) {

                //DataObject dobj = DataObject.find(jspFileObject);
                //DISPLAYNAME:
                //System.out.println("webFolder: " + webFolder);
                String pageDisplayName = Page.getFolderDisplayName(webFolder, jspFileObject);

                Page relevantPage = pfc.getPageName2Page(pageDisplayName); /* I can't remember if this*/
                if (relevantPage != null) {
                    relevantPage.updateContentModel();
                    view.resetNodeWidget(relevantPage, true);
                    view.validateGraph();
                }
            }
        }
        return;
    }

    try {
        if (pfc.isKnownFile(fileObj)) {
            pfc.addWebFile(fileObj);
            DataObject dataObj = DataObject.find(fileObj);
            Node dataNode = dataObj.getNodeDelegate();
            //                    PageFlowNode pageNode = pageName2Node.get(dataNode.getDisplayName());
            //DISPLAYNAME:
            Page pageNode = pfc.getPageName2Page(Page.getFolderDisplayName(webFolder, fileObj));
            if (pageNode != null) {
                pageNode.replaceWrappedNode(dataNode);
                view.resetNodeWidget(pageNode, false);
                view.validateGraph();
            } else if (pfc.isCurrentScope(PageFlowToolbarUtilities.Scope.SCOPE_PROJECT)) {
                Page node = pfc.createPage(dataNode);
                view.createNode(node, null, null);
                view.validateGraph();
            }
        }
    } catch (DataObjectNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    }
}