Search in sources :

Example 81 with TreePath

use of javax.swing.tree.TreePath in project ACS by ACS-Community.

the class CDBLogic method valueChanged.

/**
     *  Called whenever the value of the selection changes.
     *  @param event the event that characterizes the change.
     */
public void valueChanged(TreeSelectionEvent event) {
    TreePath tp = event.getPath();
    String path = stringPath(tp);
    Browser.getInstance().setPath(path);
    //  check that selected node has a corresponding tabbed pane
    if (tabbedPanes.containsKey(path)) {
        //  update selected components
        selectedTable = tables.get(path);
        selectedTableModel = tableModels.get(path);
        selectedXMLArea = (JTextArea) xmls.get(path);
        selectedTabbedPane = (JTabbedPane) tabbedPanes.get(path);
        //  set selected tabbedPane
        Browser.getInstance().setRightComp(selectedTabbedPane, true);
    } else {
        //Browser.getInstance().display(" No tabbed pane available for this node", false);
        //  set selected components
        selectedTabbedPane = null;
        selectedTable = null;
        selectedTableModel = null;
        selectedXMLArea = null;
        //  set an emty text area
        JTextArea empty = new JTextArea();
        empty.setBackground(Color.LIGHT_GRAY);
        empty.setEditable(false);
        Browser.getInstance().setRightComp(empty, false);
    }
}
Also used : JTextArea(javax.swing.JTextArea) TreePath(javax.swing.tree.TreePath)

Example 82 with TreePath

use of javax.swing.tree.TreePath in project ACS by ACS-Community.

the class ObjectExplorer method oETree1_MouseClicked.

/**
	 * Comment
	 */
public void oETree1_MouseClicked(java.awt.event.MouseEvent mouseEvent) {
    //TODO ?!?!?!?!?!?!?
    if (SwingUtilities.isRightMouseButton(mouseEvent)) {
        TreePath clickedPath = getOETree1().getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
        Object clicked = null;
        if (clickedPath != null)
            clicked = clickedPath.getLastPathComponent();
        if (clicked instanceof Introspectable) {
            Introspectable node = (Introspectable) clicked;
            getconnectMenuItem().setEnabled(!node.isConnected());
            getdisconnectMenuItem().setEnabled(node.isConnected() && !node.isNonSticky());
            getJLabel1().setText(node.toString());
            getTreeHandlerBean1().setClicked(node);
            // disable/enable converters
            Converter currentConverter = ObjectExplorer.getConverter(node);
            int len = getconverterMenu().getItemCount();
            for (int i = 0; i < len; i++) {
                JMenuItem item = getconverterMenu().getItem(i);
                if (item != null && item.getActionListeners() != null && item.getActionListeners().length == 1 && item.getActionListeners()[0] instanceof SetConverterActionListener) {
                    SetConverterActionListener scal = (SetConverterActionListener) item.getActionListeners()[0];
                    if (scal.getConverter() == currentConverter)
                        item.setEnabled(false);
                    else
                        item.setEnabled(true);
                }
            }
            getoeTreePopup().show(getOETree1(), mouseEvent.getX(), mouseEvent.getY());
        }
    }
    return;
}
Also used : TreePath(javax.swing.tree.TreePath) SimpleIntrospectable(si.ijs.acs.objectexplorer.engine.SimpleIntrospectable) Introspectable(si.ijs.acs.objectexplorer.engine.Introspectable) Converter(si.ijs.acs.objectexplorer.engine.Converter) JMenuItem(javax.swing.JMenuItem)

Example 83 with TreePath

use of javax.swing.tree.TreePath in project ACS by ACS-Community.

the class TreeHandlerBean method disconnect.

/**
	 * @author Miha Kadunc
	 * @author rbertoncelj
	 */
public void disconnect() {
    notifier.reportDebug("TreeHandlerBean::disconnect", "Requesting engine to disconnect the introspectable..:");
    if (clicked instanceof BACIRemoteNode) {
        BACIRemoteNode myNode = (BACIRemoteNode) clicked;
        RemoteNodeCouple rnc;
        String curl;
        if (myNode.getUserObject() instanceof String) {
            curl = (String) myNode.getUserObject();
        } else {
            curl = (String) ((OETreeNode) myNode.getParent()).getUserObject() + ":" + myNode.toString();
        }
        rnc = (RemoteNodeCouple) devices.get(curl);
        if (rnc == null) {
            clicked = null;
            notifier.reportError("TreeHandlerBean::disconnect - Unexpected null pointer (rnc).");
            return;
        }
        /*
				 * Clean treeByType
				 */
        if (rnc.deviceByType.isConnected()) {
            OETreeNode clk = (OETreeNode) rnc.deviceByType;
            clk.setChildrenDefined(true);
            rnc.deviceByType.disconnect();
            TreePath clkPath = new TreePath(clk.getPath());
            if (clkPath.isDescendant(tree.getSelectionPath()) || (clkPath.equals(tree.getSelectionPath()))) {
                this.selectedNode = clk;
                tree.setSelectionPath(clkPath);
                handler.setObject(null);
            }
            tree.collapsePath(clkPath);
            clk.removeAllChildren();
            ((DefaultTreeModel) tree.getModel()).reload(clk);
            clk.setChildrenDefined(false);
        }
        /*
				 * Clean treeByName
				 */
        OETreeNode clk = (OETreeNode) rnc.deviceByName;
        clk.setChildrenDefined(true);
        rnc.deviceByName.disconnect();
        TreePath clkPath = new TreePath(clk.getPath());
        if (clkPath.isDescendant(treeByName.getSelectionPath()) || (clkPath.equals(treeByName.getSelectionPath()))) {
            this.selectedNode = clk;
            treeByName.setSelectionPath(clkPath);
            handler.setObject(null);
        }
        treeByName.collapsePath(clkPath);
        purgeChildren(clk);
        clk.removeAllChildren();
        ((DefaultTreeModel) treeByName.getModel()).reload(clk);
        clk.setChildrenDefined(false);
    } else {
        notifier.reportError("TreeHandlerBean::disconnect - clicked not instanceof BACIRemoteNode.");
        if (clicked instanceof OETreeNode) {
            if (clicked.isConnected()) {
                OETreeNode clk = (OETreeNode) clicked;
                clk.setChildrenDefined(true);
                clicked.disconnect();
                TreePath clkPath = new TreePath(clk.getPath());
                if (clkPath.isDescendant(tree.getSelectionPath()) || (clkPath.equals(tree.getSelectionPath()))) {
                    this.selectedNode = clk;
                    tree.setSelectionPath(clkPath);
                    handler.setObject(null);
                }
                tree.collapsePath(clkPath);
                purgeChildren(clk);
                clk.removeAllChildren();
                ((DefaultTreeModel) tree.getModel()).reload(clk);
                clk.setChildrenDefined(false);
            }
        }
    }
    clicked = null;
}
Also used : TreePath(javax.swing.tree.TreePath) BACIRemoteNode(si.ijs.acs.objectexplorer.engine.BACI.BACIRemoteNode) RemoteNodeCouple(si.ijs.acs.objectexplorer.engine.BACI.RemoteNodeCouple) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 84 with TreePath

use of javax.swing.tree.TreePath in project ACS by ACS-Community.

the class TreeHandlerBean method removeNode.

/**
	 * removeNode method comment.
	 */
public void removeNode(javax.swing.tree.TreeNode node) {
    if (node.getParent() == null) {
        return;
    }
    InvocationCouple ic = getInvocationCouple((Invocation) node);
    if (ic == null) {
        notifier.reportError("TreeHandlerBean::removeNode - Unexpected null pointer (ic).");
        return;
    }
    /*
		 * Selecet parent if the note that is to be deleted is currently selected
		 */
    if (tree.getSelectionPath() != null) {
        if (tree.getSelectionPath().getLastPathComponent() == node)
            tree.setSelectionPath(new TreePath(((DefaultMutableTreeNode) node.getParent()).getPath()));
    } else if (treeByName.getSelectionPath() == null) {
        if (treeByName.getSelectionPath().getLastPathComponent() == ic.invocationByName)
            treeByName.setSelectionPath(new TreePath(((DefaultMutableTreeNode) ic.invocationByName.getParent()).getPath()));
    }
    /*
		 * remove node from treeByType
		 */
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    model.removeNodeFromParent((MutableTreeNode) ic.invocationByType);
    /*
		 * remove node from treeByName
		 */
    model = (DefaultTreeModel) treeByName.getModel();
    model.removeNodeFromParent((MutableTreeNode) ic.invocationByName);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) InvocationCouple(si.ijs.acs.objectexplorer.engine.BACI.InvocationCouple) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 85 with TreePath

use of javax.swing.tree.TreePath in project ACS by ACS-Community.

the class TreeMouseListener method mousePressed.

/**
	 * @see java.awt.event.MouseListener
	 */
public void mousePressed(MouseEvent e) {
    TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
    if (selPath == null) {
        // No object selected but the user expand/compress a node
        return;
    }
    if (e.getClickCount() == 2) {
        tree.setSelectionPath(selPath);
        /*class TabShower implements Runnable {
				TreePath selectedPath;
				public TabShower(TreePath path) {
					selectedPath=path;
				}
				public void run() {
					showLoggingConfigTab(selectedPath);
				}
			};
			TabShower shower = new TabShower(selPath);
			Thread t = new Thread(shower);
			t.run();*/
        showLoggingConfigTab(selPath);
        return;
    }
    if (e.isPopupTrigger()) {
        //Toolkit tk = Toolkit.getDefaultToolkit();
        PointerInfo pi = MouseInfo.getPointerInfo();
        Point mouseLocation = pi.getLocation();
        SwingUtilities.convertPointFromScreen(mouseLocation, tree);
        popupMenu.show(tree, mouseLocation.x, mouseLocation.y);
    }
}
Also used : PointerInfo(java.awt.PointerInfo) TreePath(javax.swing.tree.TreePath) Point(java.awt.Point)

Aggregations

TreePath (javax.swing.tree.TreePath)539 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)177 ArrayList (java.util.ArrayList)58 TreeNode (javax.swing.tree.TreeNode)56 Nullable (org.jetbrains.annotations.Nullable)49 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)46 JTree (javax.swing.JTree)34 NotNull (org.jetbrains.annotations.NotNull)32 Test (org.junit.Test)22 Tree (com.intellij.ui.treeStructure.Tree)21 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)21 TreeSelectionListener (javax.swing.event.TreeSelectionListener)21 MouseEvent (java.awt.event.MouseEvent)18 Point (java.awt.Point)17 ActionEvent (java.awt.event.ActionEvent)15 KeyEvent (java.awt.event.KeyEvent)12 EVTask (net.sourceforge.processdash.ev.EVTask)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 KeyAdapter (java.awt.event.KeyAdapter)11 List (java.util.List)11