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

The following examples show how to use org.openide.nodes.Node#getName() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   File: DomPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Expands {@code HTML} and {@code BODY} nodes.
 */
private void expandNodes() {
    Node root = manager.getRootContext();
    treeView.expandNode(root);
    for (Node node : root.getChildren().getNodes()) {
        String nodeName = node.getName();
        if (nodeName != null && nodeName.trim().toLowerCase().equals("html")) { // NOI18N
            treeView.expandNode(node);
            for (Node subNode : node.getChildren().getNodes()) {
                nodeName = subNode.getName();
                if (nodeName != null && nodeName.trim().toLowerCase().equals("body")) { // NOI18N
                    treeView.expandNode(subNode);
                }
            }
        }
    }
}
 
Example 2
Source Project: netbeans   File: DiffUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Makes an HTML display name for the given node, if the node should be
 * rendered with a non-default font and/or color. The returned string
 * (if non-{@code null}) does not contain the leading
 * {@code "<html>"} string that in many cases neccessary
 * if the HTML markup should be interpreted during rendering.
 *
 * @param  node  node to make a display name for
 * @param  fileModified  {@code true} if the file represented by the node
 *                       is modified (contains unsaved changes)
 * @param  selected  if the node is selected (in a table, in a tree, ...)
 * @return  string with HTML markups included,
 *          or {@code null} if no HTML markup is neccessary
 * @since 1.9.1
 */
public static String getHtmlDisplayName(Node node,
                                        boolean fileModified,
                                        boolean selected) {
    boolean bold = fileModified;
    boolean colored = !selected;

    if (!bold && !colored) {
        return null;            //no HTML markup necessary
    }

    String normal = colored ? node.getHtmlDisplayName()
                            : node.getName();
    return bold ? makeBold(normal)
                : normal;
}
 
Example 3
Source Project: netbeans   File: DataShadowTest.java    License: 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 4
Source Project: netbeans   File: ConnectDatabaseAction.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void performAction(Node[] activatedNodes) {
    if ( activatedNodes == null || activatedNodes.length == 0 ) {
        return;
    }
    Node n = activatedNodes[0];

    final String dbname = n.getName();

    List<DatabaseConnection> conns = DerbyDatabasesImpl.getDefault().findDatabaseConnections(dbname);

    try {
        if ( conns.isEmpty() )
        {
            JDBCDriver drivers[] = JDBCDriverManager.getDefault().getDrivers(DerbyOptions.DRIVER_CLASS_NET);
            if (drivers.length == 0) {
                showDriverNotFoundDialog();
                return;
            }
            final DatabaseConnection dbconn = DatabaseConnection.create(drivers[0], "jdbc:derby://localhost:" + // NOI18N
                    RegisterDerby.getDefault().getPort() +
                    "/" + dbname, // NOI18N
                    DerbyDatabasesImpl.getDefault().getUser(dbname),
                    DerbyDatabasesImpl.getDefault().getSchema(dbname),
                    DerbyDatabasesImpl.getDefault().getPassword(dbname),
                    true);

            // Can't display the dialog until the connection has been succesfully added
            // to the database explorer.
            ConnectionManager.getDefault().addConnectionListener(new ConnectionListener() {
                @Override
                public void connectionsChanged() {
                    ConnectionManager.getDefault().showConnectionDialog(dbconn);
                    ConnectionManager.getDefault().removeConnectionListener(this);
                }
            });

            ConnectionManager.getDefault().addConnection(dbconn);
        } else {
            ConnectionManager.getDefault().showConnectionDialog(conns.get(0));
        }

    } catch (DatabaseException dbe) {
        LOGGER.log(Level.INFO, dbe.getMessage(), dbe);
    } finally {
        // Refresh in case the state of the server changed... (e.g. the connection was lost)
    }
}