Example usage for javax.swing.tree TreePath getLastPathComponent

List of usage examples for javax.swing.tree TreePath getLastPathComponent

Introduction

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

Prototype

public Object getLastPathComponent() 

Source Link

Document

Returns the last element of this path.

Usage

From source file:com.pironet.tda.TDA.java

/**
 * navigate to monitor// w ww  . j  av  a 2 s.c o  m
 *
 * @param monitorLink the monitor link to navigate to
 */
private void navigateToMonitor(String monitorLink) {
    String monitor = monitorLink.substring(monitorLink.lastIndexOf('/') + 1);

    // find monitor node for this thread info
    DefaultMutableTreeNode dumpNode;
    if (monitorLink.indexOf("Dump No.") > 0) {
        dumpNode = getDumpRootNode(
                monitorLink.substring(monitorLink.indexOf('/') + 1, monitorLink.lastIndexOf('/')),
                (DefaultMutableTreeNode) tree.getLastSelectedPathComponent());
    } else {
        dumpNode = getDumpRootNode((DefaultMutableTreeNode) tree.getLastSelectedPathComponent());
    }
    final Enumeration children = dumpNode.children();
    DefaultMutableTreeNode monitorNode = null;
    DefaultMutableTreeNode monitorWithoutLocksNode = null;
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        if (child.getUserObject() instanceof TreeCategory) {
            if (((TreeCategory) child.getUserObject()).getName().startsWith("Monitors (")) {
                monitorNode = child;
            } else if (((TreeCategory) child.getUserObject()).getName().startsWith("Monitors without")) {
                monitorWithoutLocksNode = child;
            }
        }
    }

    // highlight chosen monitor
    JTree searchTree = (JTree) ((TreeCategory) monitorNode.getUserObject()).getCatComponent(this);
    TreePath searchPath = searchTree.getNextMatch(monitor, 0, Position.Bias.Forward);
    if ((searchPath == null) && (monitorWithoutLocksNode != null)) {
        searchTree = (JTree) ((TreeCategory) monitorWithoutLocksNode.getUserObject()).getCatComponent(this);
        searchPath = searchTree.getNextMatch(monitor, 0, Position.Bias.Forward);
        monitorNode = monitorWithoutLocksNode;
    }

    if (searchPath != null) {
        TreePath monitorPath = new TreePath(monitorNode.getPath());
        tree.setSelectionPath(monitorPath);
        tree.scrollPathToVisible(monitorPath);

        displayCategory(monitorNode.getUserObject());

        TreePath threadInMonitor = searchPath
                .pathByAddingChild(((DefaultMutableTreeNode) searchPath.getLastPathComponent()).getLastChild());
        searchTree.setSelectionPath(threadInMonitor);
        searchTree.scrollPathToVisible(searchPath);
        searchTree.setSelectionPath(searchPath);
    }
}

From source file:com.mirth.connect.client.ui.dependencies.ChannelDependenciesPanel.java

private void initComponents() {
    setBackground(UIConstants.BACKGROUND_COLOR);

    dependencyLabel = new JLabel("This channel depends upon:");

    dependencyTreeTable = new MirthTreeTable();

    DefaultTreeTableModel dependencyModel = new SortableTreeTableModel();
    DefaultMutableTreeTableNode dependencyRootNode = new DefaultMutableTreeTableNode();
    dependencyModel.setRoot(dependencyRootNode);

    dependencyTreeTable.setTreeTableModel(dependencyModel);
    dependencyTreeTable.setRootVisible(false);
    dependencyTreeTable.setDoubleBuffered(true);
    dependencyTreeTable.setDragEnabled(false);
    dependencyTreeTable.setRowSelectionAllowed(true);
    dependencyTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    dependencyTreeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    dependencyTreeTable.setFocusable(true);
    dependencyTreeTable.setOpaque(true);
    dependencyTreeTable.setEditable(false);
    dependencyTreeTable.setSortable(true);
    dependencyTreeTable.putClientProperty("JTree.lineStyle", "Horizontal");
    dependencyTreeTable.setAutoCreateColumnsFromModel(false);
    dependencyTreeTable.setShowGrid(true, true);
    dependencyTreeTable.setTableHeader(null);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        dependencyTreeTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }//  w  w  w . jav a 2s . co m

    dependencyTreeTable.setTreeCellRenderer(new DependencyTreeCellRenderer(dependencyTreeTable));

    dependencyTreeTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelection(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelection(evt);
        }

        private void checkSelection(MouseEvent evt) {
            if (dependencyTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())) < 0) {
                dependencyTreeTable.clearSelection();
            }
        }
    });

    dependencyTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                boolean removeEnabled = false;
                int[] rows = dependencyTreeTable.getSelectedModelRows();

                if (rows.length == 1) {
                    TreePath selectedPath = dependencyTreeTable.getPathForRow(rows[0]);

                    if (selectedPath != null) {
                        if (selectedPath.getPathCount() == 2) {
                            removeEnabled = true;
                        }
                    }
                }

                dependencyRemoveButton.setEnabled(removeEnabled);
            }
        }
    });

    dependencyScrollPane = new JScrollPane(dependencyTreeTable);

    dependencyExpandAllLabel = new JLabel("<html><u>Expand All</u></html>");
    dependencyExpandAllLabel.setForeground(Color.BLUE);
    dependencyExpandAllLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    dependencyExpandAllLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent evt) {
            dependencyTreeTable.expandAll();
        }
    });

    dependencyCollapseAllLabel = new JLabel("<html><u>Collapse All</u></html>");
    dependencyCollapseAllLabel.setForeground(Color.BLUE);
    dependencyCollapseAllLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    dependencyCollapseAllLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent evt) {
            dependencyTreeTable.collapseAll();
        }
    });

    dependencyAddButton = new JButton("Add");
    dependencyAddButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            Map<String, String> allowedChannelsMap = getAllowedChannels(true);

            if (MapUtils.isNotEmpty(allowedChannelsMap)) {
                AddDialog dialog = new AddDialog(allowedChannelsMap, true);

                if (dialog.wasSaved()) {
                    for (String dependencyId : dialog.getSelectedChannelIds()) {
                        dependencies.add(new ChannelDependency(channel.getId(), dependencyId));
                    }

                    updateTreeTable(true, dependencies);
                    updateAddButton();
                }
            }
        }
    });

    dependencyRemoveButton = new JButton("Remove");
    dependencyRemoveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            int[] rows = dependencyTreeTable.getSelectedModelRows();

            if (rows.length == 1) {
                TreePath selectedPath = dependencyTreeTable.getPathForRow(rows[0]);

                if (selectedPath != null && selectedPath.getPathCount() == 2) {
                    Pair<String, String> pair = (Pair<String, String>) ((MutableTreeTableNode) selectedPath
                            .getLastPathComponent()).getUserObject();

                    for (Iterator<ChannelDependency> it = dependencies.iterator(); it.hasNext();) {
                        ChannelDependency dependency = it.next();
                        if (StringUtils.equals(channel.getId(), dependency.getDependentId())
                                && StringUtils.equals(pair.getLeft(), dependency.getDependencyId())) {
                            it.remove();
                        }
                    }

                    updateTreeTable(true, dependencies);
                    updateAddButton();
                }
            }
        }
    });
    dependencyRemoveButton.setEnabled(false);

    dependentLabel = new JLabel("This channel is depended upon by:");

    dependentTreeTable = new MirthTreeTable();

    DefaultTreeTableModel dependentModel = new SortableTreeTableModel();
    DefaultMutableTreeTableNode dependentRootNode = new DefaultMutableTreeTableNode();
    dependentModel.setRoot(dependentRootNode);

    dependentTreeTable.setTreeTableModel(dependentModel);
    dependentTreeTable.setRootVisible(false);
    dependentTreeTable.setDoubleBuffered(true);
    dependentTreeTable.setDragEnabled(false);
    dependentTreeTable.setRowSelectionAllowed(true);
    dependentTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    dependentTreeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    dependentTreeTable.setFocusable(true);
    dependentTreeTable.setOpaque(true);
    dependentTreeTable.setEditable(false);
    dependentTreeTable.setSortable(true);
    dependentTreeTable.putClientProperty("JTree.lineStyle", "Horizontal");
    dependentTreeTable.setAutoCreateColumnsFromModel(false);
    dependentTreeTable.setShowGrid(true, true);
    dependentTreeTable.setTableHeader(null);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        dependentTreeTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    dependentTreeTable.setTreeCellRenderer(new DependencyTreeCellRenderer(dependentTreeTable));

    dependentTreeTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelection(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelection(evt);
        }

        private void checkSelection(MouseEvent evt) {
            if (dependentTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())) < 0) {
                dependentTreeTable.clearSelection();
            }
        }
    });

    dependentTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                boolean removeEnabled = false;
                int[] rows = dependentTreeTable.getSelectedModelRows();

                if (rows.length == 1) {
                    TreePath selectedPath = dependentTreeTable.getPathForRow(rows[0]);

                    if (selectedPath != null) {
                        if (selectedPath.getPathCount() == 2) {
                            removeEnabled = true;
                        }
                    }
                }

                dependentRemoveButton.setEnabled(removeEnabled);
            }
        }
    });

    dependentScrollPane = new JScrollPane(dependentTreeTable);

    dependentExpandAllLabel = new JLabel("<html><u>Expand All</u></html>");
    dependentExpandAllLabel.setForeground(Color.BLUE);
    dependentExpandAllLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    dependentExpandAllLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent evt) {
            dependentTreeTable.expandAll();
        }
    });

    dependentCollapseAllLabel = new JLabel("<html><u>Collapse All</u></html>");
    dependentCollapseAllLabel.setForeground(Color.BLUE);
    dependentCollapseAllLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    dependentCollapseAllLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent evt) {
            dependentTreeTable.collapseAll();
        }
    });

    dependentAddButton = new JButton("Add");
    dependentAddButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            Map<String, String> allowedChannelsMap = getAllowedChannels(false);

            if (MapUtils.isNotEmpty(allowedChannelsMap)) {
                AddDialog dialog = new AddDialog(allowedChannelsMap, false);

                if (dialog.wasSaved()) {
                    for (String dependentId : dialog.getSelectedChannelIds()) {
                        dependencies.add(new ChannelDependency(dependentId, channel.getId()));
                    }

                    updateTreeTable(false, dependencies);
                    updateAddButton();
                }
            }
        }
    });

    dependentRemoveButton = new JButton("Remove");
    dependentRemoveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            int[] rows = dependentTreeTable.getSelectedModelRows();

            if (rows.length == 1) {
                TreePath selectedPath = dependentTreeTable.getPathForRow(rows[0]);

                if (selectedPath != null && selectedPath.getPathCount() == 2) {
                    Pair<String, String> pair = (Pair<String, String>) ((MutableTreeTableNode) selectedPath
                            .getLastPathComponent()).getUserObject();

                    for (Iterator<ChannelDependency> it = dependencies.iterator(); it.hasNext();) {
                        ChannelDependency dependency = it.next();
                        if (StringUtils.equals(pair.getLeft(), dependency.getDependentId())
                                && StringUtils.equals(channel.getId(), dependency.getDependencyId())) {
                            it.remove();
                        }
                    }

                    updateTreeTable(false, dependencies);
                    updateAddButton();
                }
            }
        }
    });
    dependentRemoveButton.setEnabled(false);
}

From source file:com.mirth.connect.client.ui.ChannelPanel.java

public void createNewChannel() {
    if (isSaveEnabled() && !promptSave(true)) {
        return;/* w ww  .j  a  v  a  2 s . c om*/
    }

    Channel channel = new Channel();

    try {
        channel.setId(parent.mirthClient.getGuid());
    } catch (ClientException e) {
        parent.alertThrowable(parent, e);
    }

    channel.setName("");

    Set<String> selectedGroupIds = new HashSet<String>();

    if (((ChannelTreeTableModel) channelTable.getTreeTableModel()).isGroupModeEnabled()) {
        for (int row : channelTable.getSelectedModelRows()) {
            TreePath path = channelTable.getPathForRow(row);
            if (path != null) {
                AbstractChannelTableNode node = (AbstractChannelTableNode) path.getLastPathComponent();
                if (node.isGroupNode()) {
                    selectedGroupIds.add(node.getGroupStatus().getGroup().getId());
                } else if (node.getParent() instanceof AbstractChannelTableNode) {
                    node = (AbstractChannelTableNode) node.getParent();
                    if (node.isGroupNode()) {
                        selectedGroupIds.add(node.getGroupStatus().getGroup().getId());
                    }
                }
            }
        }
    }

    parent.setupChannel(channel, selectedGroupIds.size() == 1 ? selectedGroupIds.iterator().next() : null);
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private JPanel createAParameterBox(final boolean first) {

    final JLabel runLabel = new JLabel("<html><b>Number of runs:</b> 0</html>");
    final JLabel warningLabel = new JLabel();

    final JButton closeButton = new JButton();
    closeButton.setOpaque(false);/*from w w  w  .j a  v a2s  .  c  o m*/
    closeButton.setBorder(null);
    closeButton.setFocusable(false);

    if (!first) {
        closeButton.setRolloverIcon(PARAMETER_BOX_REMOVE);
        closeButton.setRolloverEnabled(true);
        closeButton.setIcon(RGBGrayFilter.getDisabledIcon(closeButton, PARAMETER_BOX_REMOVE));
        closeButton.setActionCommand(ACTIONCOMMAND_REMOVE_BOX);
    }

    final JScrollPane treeScrPane = new JScrollPane();
    final DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode();
    final JTree tree = new JTree(treeRoot);
    ToolTipManager.sharedInstance().registerComponent(tree);

    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(new ParameterBoxTreeRenderer());
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(final TreeSelectionEvent e) {
            final TreePath selectionPath = tree.getSelectionPath();
            boolean success = true;
            if (editedNode != null
                    && (selectionPath == null || !editedNode.equals(selectionPath.getLastPathComponent())))
                success = modify();

            if (success) {
                if (selectionPath != null) {
                    cancelAllSelectionBut(tree);
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                            .getLastPathComponent();
                    if (!node.equals(editedNode)) {
                        ParameterInATree userObj = null;
                        final DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
                        if (!node.isRoot()
                                && selectionPath.getPathCount() == model.getPathToRoot(node).length) {
                            userObj = (ParameterInATree) node.getUserObject();
                            final ParameterInfo info = userObj.info;
                            editedNode = node;
                            editedTree = tree;
                            edit(info);
                        } else {
                            tree.setSelectionPath(null);
                            if (cancelButton.isEnabled())
                                cancelButton.doClick();
                            resetSettings();
                            enableDisableSettings(false);
                            editedNode = null;
                            editedTree = null;
                        }

                        updateDescriptionField(userObj);
                    } else
                        updateDescriptionField();

                } else
                    updateDescriptionField();

                enableDisableParameterCombinationButtons();
            } else {
                final DefaultTreeModel model = (DefaultTreeModel) editedTree.getModel();
                final DefaultMutableTreeNode storedEditedNode = editedNode;
                editedNode = null;
                tree.setSelectionPath(null);
                editedNode = storedEditedNode;
                editedTree.setSelectionPath(new TreePath(model.getPathToRoot(editedNode)));
            }
        }
    });

    treeScrPane.setViewportView(tree);
    treeScrPane.setBorder(null);
    treeScrPane.setViewportBorder(null);
    treeScrPane.setPreferredSize(new Dimension(450, 250));

    final JButton upButton = new JButton();
    upButton.setOpaque(false);
    upButton.setRolloverEnabled(true);
    upButton.setIcon(PARAMETER_UP_ICON);
    upButton.setRolloverIcon(PARAMETER_UP_ICON_RO);
    upButton.setDisabledIcon(PARAMETER_UP_ICON_DIS);
    upButton.setBorder(null);
    upButton.setToolTipText("Move up the selected parameter");
    upButton.setActionCommand(ACTIONCOMMAND_MOVE_UP);

    final JButton downButton = new JButton();
    downButton.setOpaque(false);
    downButton.setRolloverEnabled(true);
    downButton.setIcon(PARAMETER_DOWN_ICON);
    downButton.setRolloverIcon(PARAMETER_DOWN_ICON_RO);
    downButton.setDisabledIcon(PARAMETER_DOWN_ICON_DIS);
    downButton.setBorder(null);
    downButton.setToolTipText("Move down the selected parameter");
    downButton.setActionCommand(ACTIONCOMMAND_MOVE_DOWN);

    final JPanel mainPanel = FormsUtils.build("~ f:p:g ~ p ~ r:p",
            "012||" + "333||" + "44_||" + "445||" + "446||" + "44_ f:p:g", runLabel, first ? "" : warningLabel,
            first ? warningLabel : closeButton, new FormsUtils.Separator(""), treeScrPane, upButton, downButton)
            .getPanel();

    mainPanel.setBorder(BorderFactory.createTitledBorder(""));

    final JButton addButton = new JButton();
    addButton.setOpaque(false);
    addButton.setRolloverEnabled(true);
    addButton.setIcon(PARAMETER_ADD_ICON);
    addButton.setRolloverIcon(PARAMETER_ADD_ICON_RO);
    addButton.setDisabledIcon(PARAMETER_ADD_ICON_DIS);
    addButton.setBorder(null);
    addButton.setToolTipText("Add selected parameter");
    addButton.setActionCommand(ACTIONCOMMAND_ADD_PARAM);

    final JButton removeButton = new JButton();
    removeButton.setOpaque(false);
    removeButton.setRolloverEnabled(true);
    removeButton.setIcon(PARAMETER_REMOVE_ICON);
    removeButton.setRolloverIcon(PARAMETER_REMOVE_ICON_RO);
    removeButton.setDisabledIcon(PARAMETER_REMOVE_ICON_DIS);
    removeButton.setBorder(null);
    removeButton.setToolTipText("Remove selected parameter");
    removeButton.setActionCommand(ACTIONCOMMAND_REMOVE_PARAM);

    final JPanel result = FormsUtils.build("p ~ f:p:g", "_0 f:p:g||" + "10 p ||" + "20 p||" + "_0 f:p:g",
            mainPanel, addButton, removeButton).getPanel();

    Style.registerCssClasses(result, Dashboard.CSS_CLASS_COMMON_PANEL);

    final ParameterCombinationGUI pcGUI = new ParameterCombinationGUI(tree, treeRoot, runLabel, warningLabel,
            addButton, removeButton, upButton, downButton);
    parameterTreeBranches.add(pcGUI);

    final ActionListener boxActionListener = new ActionListener() {

        //====================================================================================================
        // methods

        //----------------------------------------------------------------------------------------------------
        public void actionPerformed(final ActionEvent e) {
            final String cmd = e.getActionCommand();

            if (ACTIONCOMMAND_ADD_PARAM.equals(cmd))
                handleAddParameter(pcGUI);
            else if (ACTIONCOMMAND_REMOVE_PARAM.equals(cmd))
                handleRemoveParameter(tree);
            else if (ACTIONCOMMAND_REMOVE_BOX.equals(cmd))
                handleRemoveBox(tree);
            else if (ACTIONCOMMAND_MOVE_UP.equals(cmd))
                handleMoveUp();
            else if (ACTIONCOMMAND_MOVE_DOWN.equals(cmd))
                handleMoveDown();
        }

        //----------------------------------------------------------------------------------------------------
        private void handleAddParameter(final ParameterCombinationGUI pcGUI) {
            final Object[] selectedValues = parameterList.getSelectedValues();
            if (selectedValues != null && selectedValues.length > 0) {
                final AvailableParameter[] params = new AvailableParameter[selectedValues.length];
                System.arraycopy(selectedValues, 0, params, 0, selectedValues.length);
                addParameterToTree(params, pcGUI);
                enableDisableParameterCombinationButtons();
            }
        }

        //----------------------------------------------------------------------------------------------------
        private void handleRemoveParameter(final JTree tree) {
            final TreePath selectionPath = tree.getSelectionPath();
            if (selectionPath != null) {
                cancelButton.doClick();

                final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                        .getLastPathComponent();
                if (!node.isRoot()) {
                    final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
                    if (parentNode.isRoot()) {
                        removeParameter(tree, node, parentNode);
                        enableDisableParameterCombinationButtons();
                    }
                }
            }
        }

        //----------------------------------------------------------------------------------------------------
        private void handleRemoveBox(final JTree tree) {
            final int answer = Utilities.askUser(dashboard, false, "Comfirmation",
                    "This operation deletes the combination.",
                    "All related parameter returns back to the list on the left side.", "Are you sure?");
            if (answer == 1) {
                final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();

                if (tree.getSelectionCount() > 0) {
                    editedNode = null;
                    tree.setSelectionPath(null);
                    if (cancelButton.isEnabled())
                        cancelButton.doClick();
                }

                final DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
                for (int i = 0; i < root.getChildCount(); ++i) {
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i);
                    removeParameter(tree, node, root);
                }

                enableDisableParameterCombinationButtons();

                parameterTreeBranches.remove(pcGUI);
                combinationsPanel.remove(result);
                combinationsPanel.revalidate();

                updateNumberOfRuns();
            }
        }

        //----------------------------------------------------------------------------------------------------
        private void removeParameter(final JTree tree, final DefaultMutableTreeNode node,
                final DefaultMutableTreeNode parentNode) {
            final ParameterInATree userObj = (ParameterInATree) node.getUserObject();
            final ParameterInfo originalInfo = findOriginalInfo(userObj.info);
            if (originalInfo != null) {
                final DefaultListModel model = (DefaultListModel) parameterList.getModel();
                model.addElement(new AvailableParameter(originalInfo, currentModelHandler.getModelClass()));
                final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
                treeModel.removeNodeFromParent(node);
                updateNumberOfRuns();
                tree.expandPath(new TreePath(treeModel.getPathToRoot(parentNode)));
            } else
                throw new IllegalStateException(
                        "Parameter " + userObj.info.getName() + " is not found in the model.");
        }

        //----------------------------------------------------------------------------------------------------
        private void handleMoveUp() {
            final TreePath selectionPath = tree.getSelectionPath();
            if (selectionPath != null) {
                boolean success = true;
                if (editedNode != null)
                    success = modify();

                if (success) {
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                            .getLastPathComponent();
                    final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();

                    if (parent == null || parent.getFirstChild().equals(node)) {
                        tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel
                        tree.setSelectionPath(new TreePath(node.getPath()));
                        return;
                    }

                    final int index = parent.getIndex(node);
                    final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel();
                    treemodel.removeNodeFromParent(node);
                    treemodel.insertNodeInto(node, parent, index - 1);
                    tree.setSelectionPath(new TreePath(node.getPath()));
                }

            }
        }

        //----------------------------------------------------------------------------------------------------
        private void handleMoveDown() {
            final TreePath selectionPath = tree.getSelectionPath();
            if (selectionPath != null) {
                boolean success = true;
                if (editedNode != null)
                    success = modify();

                if (success) {
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                            .getLastPathComponent();
                    final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();

                    if (parent == null || parent.getLastChild().equals(node)) {
                        tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel
                        tree.setSelectionPath(new TreePath(node.getPath()));
                        return;
                    }

                    final int index = parent.getIndex(node);
                    final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel();
                    treemodel.removeNodeFromParent(node);
                    treemodel.insertNodeInto(node, parent, index + 1);
                    tree.setSelectionPath(new TreePath(node.getPath()));
                }
            }
        }
    };

    GUIUtils.addActionListener(boxActionListener, closeButton, upButton, downButton, addButton, removeButton);

    result.setPreferredSize(new Dimension(500, 250));
    enableDisableParameterCombinationButtons();

    Style.apply(result, dashboard.getCssStyle());

    return result;
}

From source file:com.mirth.connect.client.ui.ChannelPanel.java

private void initComponents() {
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    splitPane.setOneTouchExpandable(true);

    topPanel = new JPanel();

    List<String> columns = new ArrayList<String>();

    for (ChannelColumnPlugin plugin : LoadedExtensions.getInstance().getChannelColumnPlugins().values()) {
        if (plugin.isDisplayFirst()) {
            columns.add(plugin.getColumnHeader());
        }/*ww  w.  ja  va2s  .c o  m*/
    }

    columns.addAll(Arrays.asList(DEFAULT_COLUMNS));

    for (ChannelColumnPlugin plugin : LoadedExtensions.getInstance().getChannelColumnPlugins().values()) {
        if (!plugin.isDisplayFirst()) {
            columns.add(plugin.getColumnHeader());
        }
    }

    channelTable = new MirthTreeTable("channelPanel", new LinkedHashSet<String>(columns));

    channelTable.setColumnFactory(new ChannelTableColumnFactory());

    ChannelTreeTableModel model = new ChannelTreeTableModel();
    model.setColumnIdentifiers(columns);
    model.setNodeFactory(new DefaultChannelTableNodeFactory());
    channelTable.setTreeTableModel(model);

    channelTable.setDoubleBuffered(true);
    channelTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    channelTable.getTreeSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    channelTable.setHorizontalScrollEnabled(true);
    channelTable.packTable(UIConstants.COL_MARGIN);
    channelTable.setRowHeight(UIConstants.ROW_HEIGHT);
    channelTable.setOpaque(true);
    channelTable.setRowSelectionAllowed(true);
    channelTable.setSortable(true);
    channelTable.putClientProperty("JTree.lineStyle", "Horizontal");
    channelTable.setAutoCreateColumnsFromModel(false);
    channelTable.setShowGrid(true, true);
    channelTable.restoreColumnPreferences();
    channelTable.setMirthColumnControlEnabled(true);

    channelTable.setDragEnabled(true);
    channelTable.setDropMode(DropMode.ON);
    channelTable.setTransferHandler(new ChannelTableTransferHandler() {
        @Override
        public boolean canImport(TransferSupport support) {
            // Don't allow files to be imported when the save task is enabled 
            if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && isSaveEnabled()) {
                return false;
            }
            return super.canImport(support);
        }

        @Override
        public void importFile(final File file, final boolean showAlerts) {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    @Override
                    public void run() {
                        String fileString = StringUtils.trim(parent.readFileToString(file));

                        try {
                            // If the table is in channel view, don't allow groups to be imported
                            ChannelGroup group = ObjectXMLSerializer.getInstance().deserialize(fileString,
                                    ChannelGroup.class);
                            if (group != null && !((ChannelTreeTableModel) channelTable.getTreeTableModel())
                                    .isGroupModeEnabled()) {
                                return;
                            }
                        } catch (Exception e) {
                        }

                        if (showAlerts && !parent.promptObjectMigration(fileString, "channel or group")) {
                            return;
                        }

                        try {
                            importChannel(
                                    ObjectXMLSerializer.getInstance().deserialize(fileString, Channel.class),
                                    showAlerts);
                        } catch (Exception e) {
                            try {
                                importGroup(ObjectXMLSerializer.getInstance().deserialize(fileString,
                                        ChannelGroup.class), showAlerts, !showAlerts);
                            } catch (Exception e2) {
                                if (showAlerts) {
                                    parent.alertThrowable(parent, e,
                                            "Invalid channel or group file:\n" + e.getMessage());
                                }
                            }
                        }
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public boolean canMoveChannels(List<Channel> channels, int row) {
            if (row >= 0) {
                TreePath path = channelTable.getPathForRow(row);
                if (path != null) {
                    AbstractChannelTableNode node = (AbstractChannelTableNode) path.getLastPathComponent();

                    if (node.isGroupNode()) {
                        Set<String> currentChannelIds = new HashSet<String>();
                        for (Enumeration<? extends MutableTreeTableNode> channelNodes = node
                                .children(); channelNodes.hasMoreElements();) {
                            currentChannelIds.add(((AbstractChannelTableNode) channelNodes.nextElement())
                                    .getChannelStatus().getChannel().getId());
                        }

                        for (Iterator<Channel> it = channels.iterator(); it.hasNext();) {
                            if (currentChannelIds.contains(it.next().getId())) {
                                it.remove();
                            }
                        }

                        return !channels.isEmpty();
                    }
                }
            }

            return false;
        }

        @Override
        public boolean moveChannels(List<Channel> channels, int row) {
            if (row >= 0) {
                TreePath path = channelTable.getPathForRow(row);
                if (path != null) {
                    AbstractChannelTableNode node = (AbstractChannelTableNode) path.getLastPathComponent();

                    if (node.isGroupNode()) {
                        Set<String> currentChannelIds = new HashSet<String>();
                        for (Enumeration<? extends MutableTreeTableNode> channelNodes = node
                                .children(); channelNodes.hasMoreElements();) {
                            currentChannelIds.add(((AbstractChannelTableNode) channelNodes.nextElement())
                                    .getChannelStatus().getChannel().getId());
                        }

                        for (Iterator<Channel> it = channels.iterator(); it.hasNext();) {
                            if (currentChannelIds.contains(it.next().getId())) {
                                it.remove();
                            }
                        }

                        if (!channels.isEmpty()) {
                            ListSelectionListener[] listeners = ((DefaultListSelectionModel) channelTable
                                    .getSelectionModel()).getListSelectionListeners();
                            for (ListSelectionListener listener : listeners) {
                                channelTable.getSelectionModel().removeListSelectionListener(listener);
                            }

                            try {
                                ChannelTreeTableModel model = (ChannelTreeTableModel) channelTable
                                        .getTreeTableModel();
                                Set<String> channelIds = new HashSet<String>();
                                for (Channel channel : channels) {
                                    model.addChannelToGroup(node, channel.getId());
                                    channelIds.add(channel.getId());
                                }

                                List<TreePath> selectionPaths = new ArrayList<TreePath>();
                                for (Enumeration<? extends MutableTreeTableNode> channelNodes = node
                                        .children(); channelNodes.hasMoreElements();) {
                                    AbstractChannelTableNode channelNode = (AbstractChannelTableNode) channelNodes
                                            .nextElement();
                                    if (channelIds
                                            .contains(channelNode.getChannelStatus().getChannel().getId())) {
                                        selectionPaths.add(new TreePath(
                                                new Object[] { model.getRoot(), node, channelNode }));
                                    }
                                }

                                parent.setSaveEnabled(true);
                                channelTable.expandPath(new TreePath(
                                        new Object[] { channelTable.getTreeTableModel().getRoot(), node }));
                                channelTable.getTreeSelectionModel().setSelectionPaths(
                                        selectionPaths.toArray(new TreePath[selectionPaths.size()]));
                                return true;
                            } finally {
                                for (ListSelectionListener listener : listeners) {
                                    channelTable.getSelectionModel().addListSelectionListener(listener);
                                }
                            }
                        }
                    }
                }
            }

            return false;
        }
    });

    channelTable.setTreeCellRenderer(new DefaultTreeCellRenderer() {
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
            JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row,
                    hasFocus);

            TreePath path = channelTable.getPathForRow(row);
            if (path != null && ((AbstractChannelTableNode) path.getLastPathComponent()).isGroupNode()) {
                setIcon(UIConstants.ICON_GROUP);
            }

            return label;
        }
    });
    channelTable.setLeafIcon(UIConstants.ICON_CHANNEL);
    channelTable.setOpenIcon(UIConstants.ICON_GROUP);
    channelTable.setClosedIcon(UIConstants.ICON_GROUP);

    channelTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            channelListSelected(evt);
        }
    });

    // listen for trigger button and double click to edit channel.
    channelTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelectionAndPopupMenu(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelectionAndPopupMenu(evt);
        }

        @Override
        public void mouseClicked(MouseEvent evt) {
            int row = channelTable.rowAtPoint(new Point(evt.getX(), evt.getY()));
            if (row == -1) {
                return;
            }

            if (evt.getClickCount() >= 2 && channelTable.getSelectedRowCount() == 1
                    && channelTable.getSelectedRow() == row) {
                AbstractChannelTableNode node = (AbstractChannelTableNode) channelTable.getPathForRow(row)
                        .getLastPathComponent();
                if (node.isGroupNode()) {
                    doEditGroupDetails();
                } else {
                    doEditChannel();
                }
            }
        }
    });

    // Key Listener trigger for DEL
    channelTable.addKeyListener(new KeyListener() {
        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
                if (channelTable.getSelectedModelRows().length == 0) {
                    return;
                }

                boolean allGroups = true;
                boolean allChannels = true;
                for (int row : channelTable.getSelectedModelRows()) {
                    AbstractChannelTableNode node = (AbstractChannelTableNode) channelTable.getPathForRow(row)
                            .getLastPathComponent();
                    if (node.isGroupNode()) {
                        allChannels = false;
                    } else {
                        allGroups = false;
                    }
                }

                if (allChannels) {
                    doDeleteChannel();
                } else if (allGroups) {
                    doDeleteGroup();
                }
            }
        }

        @Override
        public void keyReleased(KeyEvent evt) {
        }

        @Override
        public void keyTyped(KeyEvent evt) {
        }
    });

    // MIRTH-2301
    // Since we are using addHighlighter here instead of using setHighlighters, we need to remove the old ones first.
    channelTable.setHighlighters();

    // Set highlighter.
    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR);
        channelTable.addHighlighter(highlighter);
    }

    HighlightPredicate revisionDeltaHighlighterPredicate = new HighlightPredicate() {
        @Override
        public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
            if (adapter.column == channelTable.convertColumnIndexToView(
                    channelTable.getColumnExt(DEPLOYED_REVISION_DELTA_COLUMN_NAME).getModelIndex())) {
                if (channelTable.getValueAt(adapter.row, adapter.column) != null
                        && ((Integer) channelTable.getValueAt(adapter.row, adapter.column)).intValue() > 0) {
                    return true;
                }

                if (channelStatuses != null) {
                    String channelId = (String) channelTable.getModel()
                            .getValueAt(channelTable.convertRowIndexToModel(adapter.row), ID_COLUMN_NUMBER);
                    ChannelStatus status = channelStatuses.get(channelId);
                    if (status != null && status.isCodeTemplatesChanged()) {
                        return true;
                    }
                }
            }
            return false;
        }
    };
    channelTable.addHighlighter(new ColorHighlighter(revisionDeltaHighlighterPredicate, new Color(255, 204, 0),
            Color.BLACK, new Color(255, 204, 0), Color.BLACK));

    HighlightPredicate lastDeployedHighlighterPredicate = new HighlightPredicate() {
        @Override
        public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
            if (adapter.column == channelTable.convertColumnIndexToView(
                    channelTable.getColumnExt(LAST_DEPLOYED_COLUMN_NAME).getModelIndex())) {
                Calendar checkAfter = Calendar.getInstance();
                checkAfter.add(Calendar.MINUTE, -2);

                if (channelTable.getValueAt(adapter.row, adapter.column) != null
                        && ((Calendar) channelTable.getValueAt(adapter.row, adapter.column))
                                .after(checkAfter)) {
                    return true;
                }
            }
            return false;
        }
    };
    channelTable.addHighlighter(new ColorHighlighter(lastDeployedHighlighterPredicate, new Color(240, 230, 140),
            Color.BLACK, new Color(240, 230, 140), Color.BLACK));

    channelScrollPane = new JScrollPane(channelTable);
    channelScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

    filterPanel = new JPanel();
    filterPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(164, 164, 164)));

    tagsFilterButton = new IconButton();
    tagsFilterButton
            .setIcon(new ImageIcon(getClass().getResource("/com/mirth/connect/client/ui/images/wrench.png")));
    tagsFilterButton.setToolTipText("Show Channel Filter");
    tagsFilterButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            tagsFilterButtonActionPerformed();
        }
    });

    tagsLabel = new JLabel();

    ButtonGroup tableModeButtonGroup = new ButtonGroup();

    tableModeGroupsButton = new IconToggleButton(UIConstants.ICON_GROUP);
    tableModeGroupsButton.setToolTipText("Groups");
    tableModeGroupsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            if (!switchTableMode(true)) {
                tableModeChannelsButton.setSelected(true);
            }
        }
    });
    tableModeButtonGroup.add(tableModeGroupsButton);

    tableModeChannelsButton = new IconToggleButton(UIConstants.ICON_CHANNEL);
    tableModeChannelsButton.setToolTipText("Channels");
    tableModeChannelsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            if (!switchTableMode(false)) {
                tableModeGroupsButton.setSelected(true);
            }
        }
    });
    tableModeButtonGroup.add(tableModeChannelsButton);

    tabPane = new JTabbedPane();

    splitPane.setTopComponent(topPanel);
    splitPane.setBottomComponent(tabPane);
}

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

/**
     * ??  ?     .//www . j  av a  2s.c o m
     */
    private void infoListChange() {
        final TreePath selectedPath = treeInfo.getSelectionPath();
        if (selectedPath != null) {
            showInfoInfo((QInfoItem) selectedPath.getLastPathComponent());
        }
    }

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

/**
     * ??  ?    ?? ?.//from  w w w  .j  a va  2  s . co m
     */
    private void serviceListChange() {
        final TreePath selectedPath = treeServices.getSelectionPath();
        if (selectedPath != null) {
            showServiceInfo((QService) selectedPath.getLastPathComponent());
        }
    }

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

@Action
    public void editLangs() {
        final TreePath selectedPath = treeServices.getSelectionPath();
        if (selectedPath != null) {
            final QService service = (QService) selectedPath.getLastPathComponent();
            FServiceLangList.changeServiceLangList(this, true, service);
            showServiceInfo(service);//w w w. ja va  2s.c  o m
        }
    }

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

@Action
    public void editService() {
        final TreePath selectedPath = treeServices.getSelectionPath();
        if (selectedPath != null) {
            final QService service = (QService) selectedPath.getLastPathComponent();
            FServiceChangeDialod.changeService(this, true, service, (ComboBoxModel) listSchedule.getModel(),
                    (ComboBoxModel) listCalendar.getModel());
            showServiceInfo(service);/* w  w w .  j a  v  a 2s. c  o m*/
        }
    }

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

@Action
    public void setDisableService() {
        final TreePath selectedPath = treeServices.getSelectionPath();
        if (selectedPath != null) {
            final QService service = (QService) selectedPath.getLastPathComponent();
            final String name = (String) JOptionPane.showInputDialog(this,
                    getLocaleMessage("admin.select_ability.message") + " \"" + service.getName() + "\"",
                    getLocaleMessage("admin.select_ability.title"), JOptionPane.QUESTION_MESSAGE, null,
                    new String[] { getLocaleMessage("admin.service_ability.yes"),
                            getLocaleMessage("admin.service_ability.no") },
                    null);/*from www  . j a  va2 s.c om*/
            //?  ,  
            if (name != null) {
                if (name.equalsIgnoreCase(getLocaleMessage("admin.service_ability.yes"))) {
                    NetCommander.changeTempAvailableService(new ServerNetProperty(), service.getId(), "");
                } else {
                    final String mess = (String) JOptionPane.showInputDialog(this,
                            getLocaleMessage("admin.ability.enter_reason"),
                            getLocaleMessage("admin.select_ability.title"), JOptionPane.QUESTION_MESSAGE);
                    if (mess != null) {
                        NetCommander.changeTempAvailableService(new ServerNetProperty(), service.getId(), mess);
                    } else {
                        return;
                    }
                }
                JOptionPane.showMessageDialog(this,
                        getLocaleMessage("admin.select_ability.message") + " " + service.getName() + " \"" + name
                                + "\"",
                        getLocaleMessage("admin.select_ability.title"), JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }