Example usage for javax.swing.tree DefaultTreeModel DefaultTreeModel

List of usage examples for javax.swing.tree DefaultTreeModel DefaultTreeModel

Introduction

In this page you can find the example usage for javax.swing.tree DefaultTreeModel DefaultTreeModel.

Prototype

@ConstructorProperties({ "root" })
public DefaultTreeModel(TreeNode root) 

Source Link

Document

Creates a tree in which any node can have children.

Usage

From source file:org.openengsb.ui.admin.testClient.TestClient.java

private TreeModel createModel() {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode("Select Instance");
    TreeModel model = new DefaultTreeModel(node);
    LOGGER.info("adding domains");
    List<? extends DomainProvider> providerList = domainProvider.getObject();
    Collections.sort(providerList, Comparators.forDomainProvider());
    for (DomainProvider provider : providerList) {
        LOGGER.info("adding " + provider.getName());
        addDomainProvider(provider, node);
    }// www  . j  a  v  a  2  s  .  c om
    LOGGER.info("done adding domains;");
    return model;
}

From source file:org.openengsb.ui.admin.wiringPage.WiringPage.java

@SuppressWarnings("serial")
private IModel<TreeModel> createGlobalTreeModel(final Class<? extends Domain> domainType) {
    return new LoadableDetachableModel<TreeModel>() {
        @Override//  w  ww. java2  s. com
        protected TreeModel load() {
            DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Globals");
            if (domainType != null) {
                for (Entry<String, String> e : ruleManager.listGlobals().entrySet()) {
                    if (e.getValue().equals(domainType.getCanonicalName())) {
                        DefaultMutableTreeNode child = new DefaultMutableTreeNode(e.getKey());
                        rootNode.add(child);
                    }
                }
            }
            return new DefaultTreeModel(rootNode);
        }
    };
}

From source file:org.openengsb.ui.admin.wiringPage.WiringPage.java

@SuppressWarnings("serial")
private IModel<TreeModel> createEndpointsModel(final Class<? extends Domain> domainType) {
    return new LoadableDetachableModel<TreeModel>() {
        @Override//w w w  .  j ava 2s .c  o  m
        protected TreeModel load() {
            DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Domain endpoints");
            if (domainType != null) {
                for (Domain d : wiringService.getDomainEndpoints(domainType, "*")) {
                    String id = d.getInstanceId();
                    if (id != null) {
                        DefaultMutableTreeNode child = new DefaultMutableTreeNode(id);
                        rootNode.add(child);
                    }
                }
            }
            return new DefaultTreeModel(rootNode);
        }
    };
}

From source file:org.openengsb.ui.admin.wiringPage.WiringPage.java

private TreeModel createContextModel() {
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Contexts");
    for (String c : getAvailableContexts()) {
        rootNode.add(new DefaultMutableTreeNode(c));
    }/*from   w  ww  . j  a v  a  2  s  . co m*/
    return new DefaultTreeModel(rootNode);
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/** 
 * Helper method to create the trees hosting the display. 
 * /*  w w  w.  j  a va2 s .  com*/
 * @param exp The logged in experimenter.
 */
private void createTrees(ExperimenterData exp) {
    treeDisplay = new DnDTree(model.getUserID(), TreeViewerAgent.isAdministrator());
    treeDisplay.addPropertyChangeListener(this);
    String key = "meta pressed A";
    if (UIUtilities.isWindowsOS())
        key = "ctrl pressed A";
    KeyStroke ks = KeyStroke.getKeyStroke(key);
    treeDisplay.getInputMap().put(ks, "none");
    treeDisplay.setVisible(true);
    treeDisplay.setRootVisible(false);
    ToolTipManager.sharedInstance().registerComponent(treeDisplay);
    treeDisplay.setCellRenderer(new TreeCellRenderer(model.getUserID()));
    treeDisplay.setShowsRootHandles(true);
    TreeImageSet root = new TreeImageSet("");
    treeDisplay.setModel(new DefaultTreeModel(root));
    if (model.getBrowserType() != Browser.ADMIN_EXPLORER) {
        TreeImageDisplay node = buildTreeNodes(exp);
        if (node != null)
            treeDisplay.collapsePath(new TreePath(node.getPath()));
    }
    //Add Listeners
    //treeDisplay.requestFocus();
    treeDisplay.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            mousePressedTime = e.getWhen();
            rightClickPad = UIUtilities.isMacOS() && SwingUtilities.isLeftMouseButton(e) && e.isControlDown();
            rightClickButton = SwingUtilities.isRightMouseButton(e);
            ctrl = e.isControlDown();
            if (UIUtilities.isMacOS())
                ctrl = e.isMetaDown();
            leftMouseButton = SwingUtilities.isLeftMouseButton(e);
            if (UIUtilities.isMacOS() || UIUtilities.isLinuxOS())
                onClick(e, false);
        }

        public void mouseReleased(MouseEvent e) {
            leftMouseButton = SwingUtilities.isLeftMouseButton(e);
            if (UIUtilities.isWindowsOS())
                onClick(e, true);
        }

        // public void mouseMoved(MouseEvent e) { rollOver(e); }
    });
    treeDisplay.addMouseMotionListener(new MouseMotionAdapter() {

        public void mouseMoved(MouseEvent e) {
            rollOver(e);
        }
    });
    treeDisplay.addTreeExpansionListener(listener);
    selectionListener = new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            event = e;
            eventHandledTime = System.currentTimeMillis();

            if (delayedHandlingTreeSelection)
                /* mouse click delayed handling until this event occurred */
                handleTreeSelection();

            switch (keyEvent) {
            case KeyEvent.VK_DOWN:
            case KeyEvent.VK_UP:
                TreePath[] paths = treeDisplay.getSelectionPaths();
                if (paths != null)
                    controller.onClick(Arrays.asList(paths));
                else
                    controller.onClick(new ArrayList<TreePath>());
                break;
            }
        }
    };
    treeDisplay.addTreeSelectionListener(selectionListener);
    //remove standard behaviour
    treeDisplay.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            ctrl = false;
            switch (e.getKeyCode()) {
            case KeyEvent.VK_ENTER:
                ViewCmd cmd = new ViewCmd(model.getParentModel(), true);
                cmd.execute();
                break;
            case KeyEvent.VK_DELETE:
                switch (model.getState()) {
                case Browser.LOADING_DATA:
                case Browser.LOADING_LEAVES:
                    //case Browser.COUNTING_ITEMS:  
                    break;
                default:
                    model.delete();
                }
                break;
            case KeyEvent.VK_CONTROL:
                if (!UIUtilities.isMacOS())
                    ctrl = true;
                break;
            case KeyEvent.VK_META:
                if (UIUtilities.isMacOS())
                    ctrl = true;
                break;
            case KeyEvent.VK_A:
                if (UIUtilities.isWindowsOS() && e.isControlDown()
                        || !UIUtilities.isWindowsOS() && e.isMetaDown()) {
                    handleMultiSelection();
                }
                break;
            case KeyEvent.VK_DOWN:
            case KeyEvent.VK_UP:
            case KeyEvent.VK_RIGHT:
                keyEvent = e.getKeyCode();
                break;
            case KeyEvent.VK_LEFT:
                TreePath[] paths = treeDisplay.getSelectionPaths();
                TreeImageDisplay node;
                Object o;
                for (int i = 0; i < paths.length; i++) {
                    o = paths[i].getLastPathComponent();
                    if (o instanceof TreeImageDisplay) {
                        node = (TreeImageDisplay) o;
                        if (node.isExpanded())
                            node.setExpanded(false);
                    }
                }
            }
        }

        public void keyReleased(KeyEvent e) {
            ctrl = false;
            keyEvent = -1;
        }

    });
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.util.MoveGroupSelectionDialog.java

/**
 * Sets the values where to import the data.
 * /* w w  w .  j  a  va  2s .c o m*/
 * @param targets The values to display.
 */
public void setTargets(Collection<DataObject> targets) {
    Container c = getContentPane();
    c.remove(body);
    c.remove(1);
    treeDisplay = new JTree();
    treeDisplay.setVisible(true);
    treeDisplay.setRootVisible(false);
    ToolTipManager.sharedInstance().registerComponent(treeDisplay);
    treeDisplay.setCellRenderer(new TreeCellRenderer(userID));
    treeDisplay.setShowsRootHandles(true);
    TreeImageSet root = new TreeImageSet("");
    treeDisplay.setModel(new DefaultTreeModel(root));
    treeDisplay.addTreeSelectionListener(this);
    if (CollectionUtils.isEmpty(targets)) {
        buildNoContentPane();
        return;
    }
    Set<TreeImageDisplay> nodes = TreeViewerTranslator.transformHierarchy(new ArrayList<Object>(targets));
    List<TreeImageDisplay> transformedNodes = prepareSortedList(sorter.sort(nodes));
    if (transformedNodes.size() == 0) {
        buildNoContentPane();
        return;
    }
    DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel();
    buildTreeNode(root, transformedNodes, dtm);
    dtm.reload();
    c.add(new JScrollPane(treeDisplay), BorderLayout.CENTER);
    c.add(buildToolBar(), BorderLayout.SOUTH);
    validate();
    repaint();
}

From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java

/**
 * Initializes the specified tree/*from  www.j  a  v a2s  .c  o  m*/
 * 
 * @param tree The tree to handle.
 * @param user The user currently logged in.
 */
private void initializeTree(JTree tree, ExperimenterData user) {
    tree.setVisible(true);
    tree.setRootVisible(false);
    ToolTipManager.sharedInstance().registerComponent(tree);
    tree.setCellRenderer(new TreeCellRenderer(user.getId()));
    tree.setShowsRootHandles(true);
    TreeImageSet root = new TreeImageSet("");
    tree.setModel(new DefaultTreeModel(root));
}

From source file:org.optaplanner.benchmark.impl.aggregator.swingui.BenchmarkAggregatorFrame.java

private void refresh() {
    initPlannerBenchmarkResultList();/*from   ww w  . java2s .c o m*/
    solverBenchmarkResultNameMapping = new HashMap<SolverBenchmarkResult, String>();
    resultCheckBoxMapping = new LinkedHashMap<SingleBenchmarkResult, DefaultMutableTreeNode>();
    checkBoxTree.setSelectedSingleBenchmarkNodes(new HashSet<DefaultMutableTreeNode>());
    DefaultMutableTreeNode newCheckBoxRootNode = initBenchmarkHierarchy(true);
    DefaultTreeModel treeModel = new DefaultTreeModel(newCheckBoxRootNode);
    checkBoxTree.setModel(treeModel);
    treeModel.nodeStructureChanged(newCheckBoxRootNode);
    setEnabled(true);
}

From source file:org.pentaho.reporting.designer.core.welcome.SamplesTreeBuilder.java

private static DefaultTreeModel createModel() {
    final DefaultMutableTreeNode root = new DefaultMutableTreeNode(Messages.getString("WelcomePane.samples"));// NON-NLS
    final DefaultTreeModel model = new DefaultTreeModel(root);

    try {// w  w w  .  j av a 2 s  .  c  o  m
        final ResourceManager resourceManager = new ResourceManager();
        final HashMap cache = loadFromCache(resourceManager);

        final File installationDirectory = SettingsUtil.computeInstallationDirectory();
        if (installationDirectory != null) {
            final File configTemplateDir = new File(installationDirectory, "samples");// NON-NLS
            if (configTemplateDir.exists() && configTemplateDir.isDirectory()) {
                processDirectory(root, configTemplateDir, cache, resourceManager);
            }
        }

        storeToCache(cache);
    } catch (Exception e) {
        return model;
    }
    return model;
}

From source file:org.pentaho.reporting.engine.classic.demo.util.CompoundDemoFrame.java

protected Container createDefaultContentPane() {

    demoContent = new JPanel();
    demoContent.setLayout(new BorderLayout());
    demoContent.setMinimumSize(new Dimension(100, 100));
    demoContent.add(getNoHandlerInfoPane(), BorderLayout.CENTER);

    JPanel placeHolder = new JPanel();
    placeHolder.setMinimumSize(new Dimension(300, 0));
    placeHolder.setPreferredSize(new Dimension(300, 0));
    placeHolder.setMaximumSize(new Dimension(300, 0));

    JPanel rootContent = new JPanel();
    rootContent.setLayout(new BorderLayout());
    rootContent.add(demoContent, BorderLayout.CENTER);
    rootContent.add(placeHolder, BorderLayout.NORTH);

    final DemoSelectorTreeNode root = new DemoSelectorTreeNode(null, demoSelector);
    final DefaultTreeModel model = new DefaultTreeModel(root);
    final JTree demoTree = new JTree(model);
    demoTree.addTreeSelectionListener(new TreeSelectionHandler());

    JSplitPane rootSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(demoTree),
            rootContent);//from w  w w  . ja va  2s. co m
    rootSplitPane.setContinuousLayout(true);
    rootSplitPane.setDividerLocation(200);
    rootSplitPane.setOneTouchExpandable(true);
    return rootSplitPane;
}