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

The following examples show how to use org.openide.nodes.Node#getPropertySets() . 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: NodeTableModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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
Source File: DataShadowTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 3
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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 4
Source File: TreeTableView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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
Source File: PropertiesRowModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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
Source File: ModelProperty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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
Source File: DataShadowTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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
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: PropertiesAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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
Source File: PropertySheet.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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);
}