Example usage for javax.swing.tree DefaultMutableTreeNode getUserObject

List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject

Introduction

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

Prototype

public Object getUserObject() 

Source Link

Document

Returns this node's user object.

Usage

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel);
    treeScroll = new JScrollPane(tree);
    add(treeScroll, BorderLayout.WEST);

    properties.setProperty("foo1", "bar1");
    properties.setProperty("foo2", "bar2");
    properties.setProperty("foo3", "bar3");
    properties.setProperty("foo4", "bar4");

    Set<Object> keySet = properties.keySet();
    for (Object key : keySet) {
        root.add(new DefaultMutableTreeNode(key));
    }//from  w w w  .  j a  va 2s .c  om

    tree.expandPath(new TreePath(root));
    descriptionLabel = new JLabel(NOTHING_SELECTED);
    add(descriptionLabel, BorderLayout.CENTER);

    tree.addTreeSelectionListener(e -> {
        DefaultMutableTreeNode selection = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
        if (selection != null) {
            String key = (String) selection.getUserObject();
            String command = properties.getProperty(key);
            descriptionLabel.setText(command);
        } else {
            descriptionLabel.setText(NOTHING_SELECTED);
        }
    });
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
}

From source file:org.syncope.console.commons.RoleTreeBuilder.java

private void populateSubtree(final DefaultMutableTreeNode subRoot, final List<RoleTO> roles) {

    RoleTO role = (RoleTO) subRoot.getUserObject();

    DefaultMutableTreeNode child;
    for (RoleTO subRoleTO : getChildRoles(role.getId(), roles)) {
        child = new DefaultMutableTreeNode(subRoleTO);
        subRoot.add(child);// ww w . j  a  v  a 2s  .  c  om
        populateSubtree(child, roles);
    }
}

From source file:it.unibas.spicygui.controllo.datasource.operators.CreaWidgetEsisteSelectionCondition.java

public void creaWidgetEsisteSelectionCondition(DefaultMutableTreeNode treeNode, String espressione,
        SelectionCondition selectionCondition) {
    TreeNodeAdapter adapter = (TreeNodeAdapter) treeNode.getUserObject();
    INode iNode = adapter.getINode();/*from  www . j a  va  2s  .co m*/

    if (!espressione.equalsIgnoreCase("true") && !espressione.equalsIgnoreCase("")) {
        adapter.setSelectionCondition(true);
        VMDPinWidget vMDPinWidget = (VMDPinWidget) iNode.getAnnotation(Costanti.PIN_WIDGET_TREE);
        if (selectionCondition != null) {
            vMDPinWidget.setToolTipText(selectionCondition.toString());
        }
    } else if ((espressione.equalsIgnoreCase("true") || espressione.equalsIgnoreCase(""))) {
        adapter.setSelectionCondition(false);
    }
}

From source file:MyData.java

public Main() {
    super();/*from   w w  w .  j a v  a2  s  . c o  m*/
    JTree tree = new JTree(getRootNode()) {
        public boolean isPathEditable(TreePath path) {
            Object comp = path.getLastPathComponent();
            if (comp instanceof DefaultMutableTreeNode) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) comp;
                Object userObject = node.getUserObject();
                if (userObject instanceof Main) {
                    return true;
                }
            }
            return false;
        }
    };
    QuestionCellRenderer renderer = new QuestionCellRenderer();
    tree.setCellRenderer(renderer);
    QuestionCellEditor editor = new QuestionCellEditor();
    tree.setCellEditor(editor);
    tree.setEditable(true);
    JScrollPane jsp = new JScrollPane(tree);
    getContentPane().add(jsp);
}

From source file:it.unibas.spicygui.controllo.tree.ActionDeleteDuplicateSetCloneNode.java

public void actionPerformed(ActionEvent e) {
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) jTree.getLastSelectedPathComponent();
    TreeNodeAdapter adapter = (TreeNodeAdapter) treeNode.getUserObject();
    INode iNode = adapter.getINode();//from w w  w  .  j  a v  a2 s . c o m
    PathExpression pathExpression = pathGenerator.generatePathFromRoot(iNode);
    try {
        if (logger.isDebugEnabled())
            logger.debug(dataSource);
        if (logger.isDebugEnabled())
            logger.debug(pathExpression);
        dataSource.removeDuplication(pathExpression);
        recreateTree();
    } catch (IllegalArgumentException iae) {
        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                NbBundle.getMessage(Costanti.class, Costanti.DELETE_DUPLICATION_NO) + ": " + iae.getMessage(),
                DialogDescriptor.ERROR_MESSAGE));
    }
}

From source file:it.unibas.spicygui.controllo.tree.ActionSelectMappingTask.java

public void actionPerformed(ActionEvent e) {
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) albero.getLastSelectedPathComponent();
    TreeTopComponentAdapter adapter = (TreeTopComponentAdapter) treeNode.getUserObject();
    AbstractScenario scenarioNew = adapter.getScenario();
    Scenario scenarioOld = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO);
    //        File savaFile_old = model
    if (scenarioOld != null) {
        scenarioOld.setSelected(false);/*  w  w w.  j  av  a2 s .  co  m*/
        scenarioOld.setStato(lastActionBean.getLastAction());
    }
    scenarioNew.setSelected(true);
    enableActions(scenarioNew.getStato());
    modello.putBean(Costanti.CURRENT_SCENARIO, scenarioNew);
    albero.updateUI();
}

From source file:it.unibas.spicygui.controllo.tree.ActionRemoveScenario.java

public void actionPerformed(ActionEvent e) {
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) albero.getLastSelectedPathComponent();
    TreeTopComponentAdapter adapter = (TreeTopComponentAdapter) treeNode.getUserObject();
    Scenario scenario = adapter.getScenario();
    boolean isClose = false;
    if (scenario.getMappingTaskTopComponent().isOpened()) {
        isClose = scenario.getMappingTaskTopComponent().close();
    } else {/*from ww w .ja v a  2s  .  c o  m*/
        isClose = scenario.getMappingTaskTopComponent().canClose();
    }
    if (isClose) {
        for (Scenario scenarioRelated : scenario.getRelatedScenarios()) {
            if (scenarioRelated.getMappingTaskTopComponent().isOpened()) {
                scenarioRelated.getMappingTaskTopComponent().close();
            } else {
                scenarioRelated.getMappingTaskTopComponent().canClose();
            }
        }
    }
    //        boolean esito = scenario.getMappingTaskTopComponent().canClose();
    //        if (esito) {
    //            scenario.getMappingTaskTopComponent().close();
    //        }

    //        Lookups.forPath("Azione").lookup(ActionCloseMappingTask.class).checkClosure(scenario.getMappingTaskTopComponent());
    albero.updateUI();
}

From source file:it.unibas.spicygui.controllo.tree.ActionSettingEngineConfiguration.java

public void actionPerformed(ActionEvent e) {
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) albero.getLastSelectedPathComponent();
    TreeTopComponentAdapter adapter = (TreeTopComponentAdapter) treeNode.getUserObject();
    Scenario scenario = adapter.getScenario();
    EngineConfigurationPM engineConfigurationOld = scenario.getEngineConfigurationPM().clone();
    dialog.changeMappingTask(scenario);// w w  w. jav a  2 s. c  o  m
    dialog.setVisible(true);
    if (dialog.getReturnStatus() == SettingEngineConfigurationDialog.RET_CANCEL) {
        ripristinaConfigurazione(scenario.getEngineConfigurationPM(), engineConfigurationOld);
    } else {
        scenario.getEngineConfigurationPM()
                .setSortStrategy(dialog.getComboBoxUseSortStrategy().getSelectedIndex());
        scenario.getEngineConfigurationPM()
                .setSkolemTableStrategy(dialog.getComboBoxUseSkolemTableStrategy().getSelectedIndex());
    }
}

From source file:it.unibas.spicygui.controllo.tree.ActionCreateCompositionScene.java

public void actionPerformed(ActionEvent e) {
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) albero.getLastSelectedPathComponent();
    TreeTopComponentAdapter adapter = (TreeTopComponentAdapter) treeNode.getUserObject();
    Scenario scenarioSelected = adapter.getScenario();
    if (scenarioSelected.getCompositionTopComponent() == null) {
        CompositionTopComponent compositionTopComponent = new CompositionTopComponent(scenarioSelected);
        //            new TreeDropTarget(compositionTopComponent.getGlassPane());
        scenarioSelected.setCompositionTopComponent(compositionTopComponent);
        //            this.modello.putBean(Costanti.SELECTED_COMPOSITION, compositionTopComponent);

        //            CompositionTopComponent compositionTopComponent = scenarioSelected.getCompositionTopComponent();
        //            WidgetCreator widgetCreator = new WidgetCreator();
        ///*from   w  w w .ja v  a 2s .c  o  m*/
        //            widgetCreator.createCompositionWidget(compositionTopComponent.getGlassPane().getScene(), compositionTopComponent.getGlassPane().getMainLayer(), compositionTopComponent.getGlassPane().getConnectionLayer(), new Point(10, 10), compositionTopComponent.getGlassPane(), (Scenario) scenarioSelected);
        //            compositionTopComponent.getGlassPane().getScene().validate();
        //            scenarioSelected.setInComposition(true);

    } else {
        StatusDisplayer.getDefault()
                .setStatusText(NbBundle.getMessage(Costanti.class, Costanti.ALREADY_CREATED_COMPOSITION));
    }
}

From source file:it.unibas.spicygui.controllo.tree.ActionAddMappingInCompositionScene.java

public void actionPerformed(ActionEvent e) {
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) albero.getLastSelectedPathComponent();
    TreeTopComponentAdapter adapter = (TreeTopComponentAdapter) treeNode.getUserObject();
    Scenario scenarioTreeSelected = adapter.getScenario();
    WidgetCreator widgetCreator = new WidgetCreator();
    Scenario currentScenarioSelected = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO);
    if (currentScenarioSelected != null && currentScenarioSelected.getCompositionTopComponent() != null) {
        CompositionTopComponent compositionTopComponent = currentScenarioSelected.getCompositionTopComponent();

        Widget widget = widgetCreator.createConstantWidget(compositionTopComponent.getGlassPane().getScene(),
                compositionTopComponent.getGlassPane().getMainLayer(),
                compositionTopComponent.getGlassPane().getConnectionLayer(), new Point(10, 10),
                compositionTopComponent.getGlassPane(), scenarioTreeSelected);
        if (widget == null) {
            StatusDisplayer.getDefault()
                    .setStatusText(NbBundle.getMessage(Costanti.class, Costanti.NOT_ADDED_IN_COMPOSITION));
        }//from w  ww . j a v  a2 s  . c  om

        //            widgetCreator.createConstantWidget(compositionTopComponent.getGlassPane().getScene(), compositionTopComponent.getGlassPane().getMainLayer(), compositionTopComponent.getGlassPane().getConnectionLayer(), new Point(10, 10), compositionTopComponent.getGlassPane());
        compositionTopComponent.getGlassPane().getScene().validate();
        //            scenarioSelected.setInComposition(true);
    } else {
        StatusDisplayer.getDefault()
                .setStatusText(NbBundle.getMessage(Costanti.class, Costanti.NOT_ADDED_IN_COMPOSITION));
    }
}