Java Code Examples for org.openide.nodes.Node.getPropertySets()

The following are Jave code examples for showing how to use getPropertySets() of the org.openide.nodes.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: NodeTableModel.java   Source Code and License Vote up 6 votes
/** Returns node property if found in nodes property sets. Could be overriden to
 * return property which is not in nodes property sets.
 * @param node represents single row
 * @param prop represents column
 * @return nodes property
 */
protected Property getPropertyFor(Node node, Property prop) {
    Node.PropertySet[] propSets = node.getPropertySets();

    for (int i = 0; i < propSets.length; i++) {
        Node.Property[] props = propSets[i].getProperties();

        for (int j = 0; j < props.length; j++) {
            if (prop.equals(props[j])) {
                return props[j];
            }
        }
    }

    return null;
}
 
Example 2
Project: incubator-netbeans   File: NodeTableModel.java   Source Code and License Vote up 6 votes
/** Returns node property if found in nodes property sets. Could be overriden to
 * return property which is not in nodes property sets.
 * @param node represents single row
 * @param prop represents column
 * @return nodes property
 */
protected Property getPropertyFor(Node node, Property prop) {
    Node.PropertySet[] propSets = node.getPropertySets();

    for (int i = 0; i < propSets.length; i++) {
        Node.Property[] props = propSets[i].getProperties();

        for (int j = 0; j < props.length; j++) {
            if (prop.equals(props[j])) {
                return props[j];
            }
        }
    }

    return null;
}
 
Example 3
Project: incubator-netbeans   File: DataShadowTest.java   Source Code and License Vote up 6 votes
private static Node.Property findProperty (Node n, String name) {
    Node.PropertySet[] arr = n.getPropertySets ();
    StringBuffer names = new StringBuffer ();
    
    String prefix = "";
    for (int i = 0; i < arr.length; i++) {
        Node.PropertySet set = arr[i];
        Node.Property[] properties = set.getProperties ();
        for (int j = 0; j < properties.length; j++) {
            Node.Property p = properties[j];
            if (name.equals (p.getName ())) {
                return p;
            }
            names.append (prefix);
            names.append (p.getName ());
            prefix = ", ";
        }
    }
    
    fail ("Cannot find property \"" + name + "\" in node " + n + " it has only " + names + " propeties.");
    return null;
}
 
Example 4
Project: incubator-netbeans   File: TreeTableView.java   Source Code and License Vote up 5 votes
private Node.Property getNodeProperty(Node node, Node.Property prop) {
    Node.PropertySet[] propsets = node.getPropertySets();

    for (int i = 0, n = propsets.length; i < n; i++) {
        Node.Property[] props = propsets[i].getProperties();

        for (int j = 0, m = props.length; j < m; j++) {
            if (props[j].equals(prop)) {
                return props[j];
            }
        }
    }

    return null;
}
 
Example 5
Project: incubator-netbeans   File: PropertiesRowModel.java   Source Code and License Vote up 5 votes
protected Node.Property getPropertyFor(Node node, Node.Property prop) {
    Node.PropertySet[] propSets = node.getPropertySets();

    for (int i = 0; i < propSets.length; i++) {
        Node.Property[] props = propSets[i].getProperties();

        for (int j = 0; j < props.length; j++) {
            if (prop.equals(props[j])) {
                return props[j];
            }
        }
    }

    return null;
}
 
Example 6
Project: incubator-netbeans   File: ModelProperty.java   Source Code and License Vote up 5 votes
/** Used in case of 1 element array */
static Property findProperty(Node n, String name) throws NullPointerException {
    PropertySet[] ps = n.getPropertySets();

    for (int j = 0; j < ps.length; j++) {
        Property p = findProperty(ps[j], name);

        if (p != null) {
            return p;
        }
    }

    return null;
}
 
Example 7
Project: incubator-netbeans   File: DataShadowTest.java   Source Code and License Vote up 5 votes
public void testCreateTheShadow () throws Exception {
    DataShadow shade = original.createShadow (folder);
    
    Node node = shade.createNodeDelegate();
    
    final AtomicBoolean modified = new AtomicBoolean();
    shade.getPrimaryFile().addFileChangeListener(new FileChangeAdapter() {

        @Override
        public void fileChanged (FileEvent fe) {
            modified.set(true);
        }
        
    });
    
    String originName = node.getName();
    PropertySet[] props = node.getPropertySets();
    Node.Property p = null;
    for (PropertySet propSet : props) {
        for (Node.Property prop : propSet.getProperties()) {
            if ("OriginalName".equals(prop.getName())) {
                p = prop;
                break;
            }
        }
    }
    assertNotNull(p);
    // set name to the same value
    p.setValue(originName);
    // nothing should happen
    assertFalse(modified.get());
    assertEquals(originName, original.getName());
    // set name to the same value
    p.setValue(originName + ".txt");
    // link should be changed
    assertTrue(modified.get());
    assertEquals(originName + ".txt", original.getName());
}
 
Example 8
Project: incubator-netbeans   File: SerialDataNodeTest.java   Source Code and License Vote up 5 votes
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
Project: incubator-netbeans   File: PropertiesAction.java   Source Code and License Vote up 5 votes
public JMenuItem getPopupPresenter() {
    JMenuItem prop = new Actions.MenuItem(this, false);

    Action customizeAction = SystemAction.get(CustomizeAction.class);

    // Retrieve context sensitive action instance if possible.
    if (lookup != null) {
        customizeAction = ((ContextAwareAction) customizeAction).createContextAwareInstance(lookup);
    }

    if (customizeAction.isEnabled()) {
        JInlineMenu mi = new JInlineMenu();
        mi.setMenuItems(new JMenuItem[] { new Actions.MenuItem(customizeAction, false), prop });

        return mi;
    } else {
        for (Node n : nodes()) {
            for (Node.PropertySet ps : n.getPropertySets()) {
                if (ps.getProperties().length > 0) {
                    // OK, we have something to show!
                    return prop;
                }
            }
        }
        // else nothing to show, so show nothing
        return new JInlineMenu();
    }
}
 
Example 10
Project: incubator-netbeans   File: PropertySheet.java   Source Code and License Vote up 4 votes
private static final TabInfo getTabItems(Node n) {
    Map<String, List<PropertySet>> titlesToContents = new HashMap<String, List<PropertySet>>();
    ArrayList<String> order = new ArrayList<String>();

    PropertySet[] sets = n.getPropertySets();

    for (int i = 0; i < sets.length; i++) {
        String currTab = (String) sets[i].getValue("tabName"); //NOI18N

        if (currTab == null) {
            currTab = PropUtils.basicPropsTabName();
        }

        List<PropertySet> l = titlesToContents.get(currTab);

        if (l == null) {
            l = new ArrayList<PropertySet>();
            l.add(sets[i]);
            titlesToContents.put(currTab, l);
        } else {
            l.add(sets[i]);
        }

        if (!order.contains(currTab)) {
            order.add(currTab);
        }
    }

    String[] titles = new String[order.size()];
    Object[] setSets = new Object[order.size()];
    int count = 0;

    for (Iterator<String> i = order.iterator(); i.hasNext();) {
        titles[count] = i.next();

        List<PropertySet> currSets = titlesToContents.get(titles[count]);
        setSets[count] = new PropertySet[currSets.size()];
        setSets[count] = currSets.toArray((PropertySet[]) setSets[count]);
        count++;
    }

    return new TabInfo(titles, setSets);
}