Search in sources :

Example 16 with TreeSelection

use of org.eclipse.jface.viewers.TreeSelection in project knime-core by knime.

the class WorkflowGroupSelectionDialog method pathToTreeSelection.

/**
 * @param path the path of a resource
 * @return the selection to be passed to a tree in order to select the
 *  resource denoted by the given path
 */
public static IStructuredSelection pathToTreeSelection(final IPath path) {
    if (path != null) {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IResource r = root.findMember(path);
        if (r != null && !r.equals(root)) {
            IContainer c = r.getParent();
            if (r instanceof IContainer) {
                c = (IContainer) r;
            }
            String[] segments = c.getFullPath().segments();
            Object[] treePathSegments = new Object[segments.length];
            // find all parents in order to create the path segments
            int i = 1;
            while (c.getParent() != null) {
                treePathSegments[treePathSegments.length - i] = c;
                c = c.getParent();
                i++;
            }
            TreePath treePath = new TreePath(treePathSegments);
            return new TreeSelection(treePath);
        }
    }
    // default: return empty selection
    return new TreeSelection();
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 17 with TreeSelection

use of org.eclipse.jface.viewers.TreeSelection in project translationstudio8 by heartsome.

the class ColumnCategoriesDialog method getColumnIndexesFromTreeNodes.

/**
	 * @return selected columns index(s) from the tree viewer
	 */
private List<Integer> getColumnIndexesFromTreeNodes() {
    Object[] nodes = ((TreeSelection) treeViewer.getSelection()).toArray();
    List<Integer> indexes = new ArrayList<Integer>();
    for (Object object : nodes) {
        Node node = (Node) object;
        if (Type.COLUMN == node.getType()) {
            indexes.add(Integer.parseInt(node.getData()));
        }
    }
    return indexes;
}
Also used : TreeSelection(org.eclipse.jface.viewers.TreeSelection) Node(net.sourceforge.nattable.columnCategories.Node) ArrayList(java.util.ArrayList)

Example 18 with TreeSelection

use of org.eclipse.jface.viewers.TreeSelection in project cubrid-manager by CUBRID.

the class QueryEditorDNDController method fillInSelectedNode.

/**
	 *
	 * Fill in the selected node
	 *
	 * @param schemaNodeList all table nodes
	 * @param columnNodeMap all columns node
	 * @return boolean
	 */
private boolean fillInSelectedNode(List<ISchemaNode> schemaNodeList, Map<String, List<ISchemaNode>> columnNodeMap) {
    TreeViewer treeViewer = perspectiveTreeviewerMap.get(PerspectiveManager.getInstance().getCurrentPerspectiveId());
    if (treeViewer == null) {
        return false;
    }
    ISelection selection = treeViewer.getSelection();
    if (!(selection instanceof TreeSelection)) {
        return false;
    }
    TreeSelection ts = (TreeSelection) selection;
    Object[] objs = ts.toArray();
    String dbId = null;
    for (Object obj : objs) {
        if (obj instanceof ISchemaNode) {
            ISchemaNode node = (ISchemaNode) obj;
            CubridDatabase database = node.getDatabase();
            if (dbId == null) {
                dbId = database.getId();
            }
            if (!dbId.equals(database.getId())) {
                return false;
            }
            String type = node.getType();
            if (NodeType.SYSTEM_TABLE.equals(type) || NodeType.SYSTEM_VIEW.equals(type) || NodeType.USER_TABLE.equals(type) || NodeType.USER_PARTITIONED_TABLE.equals(type) || NodeType.USER_VIEW.equals(type) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
                schemaNodeList.add(node);
            } else if (NodeType.TABLE_COLUMN.equals(type)) {
                String name = node.getParent().getParent().getName();
                List<ISchemaNode> columnNodeList = columnNodeMap.get(name);
                if (columnNodeList == null) {
                    columnNodeList = new ArrayList<ISchemaNode>();
                    columnNodeMap.put(name, columnNodeList);
                }
                columnNodeList.add(node);
            }
        }
    }
    return true;
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 19 with TreeSelection

use of org.eclipse.jface.viewers.TreeSelection in project cubrid-manager by CUBRID.

the class UnifyHostConfigDialogDNDController method addHost.

/**
	 * add database
	 */
public void addHost() {
    synchronized (this) {
        ISelection selection = navigatorTreeViewer.getSelection();
        if (!(selection instanceof TreeSelection)) {
            return;
        }
        TreeSelection ts = (TreeSelection) selection;
        Object[] objs = ts.toArray();
        dialog.addHost(objs);
    }
}
Also used : TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection)

Example 20 with TreeSelection

use of org.eclipse.jface.viewers.TreeSelection in project cubrid-manager by CUBRID.

the class RunSQLFileDialogDNDController method addDatabase.

/**
	 * add database
	 */
public void addDatabase() {
    synchronized (this) {
        TreeViewer treeViewer = perspectiveTreeviewerMap.get(PerspectiveManager.getInstance().getCurrentPerspectiveId());
        if (treeViewer == null) {
            return;
        }
        ISelection selection = treeViewer.getSelection();
        if (!(selection instanceof TreeSelection)) {
            return;
        }
        TreeSelection ts = (TreeSelection) selection;
        Object[] objs = ts.toArray();
        dialog.addDatabase(objs);
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection)

Aggregations

TreeSelection (org.eclipse.jface.viewers.TreeSelection)31 TreePath (org.eclipse.jface.viewers.TreePath)12 ISelection (org.eclipse.jface.viewers.ISelection)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)6 Test (org.junit.Test)6 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)4 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)4 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)4 IValgrindMessage (org.eclipse.linuxtools.valgrind.core.IValgrindMessage)4 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)3 ValgrindViewPart (org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart)3 UiModelSession (org.eclipse.linuxtools.oprofile.ui.model.UiModelSession)3 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 CachegrindViewPart (org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart)2 CachegrindOutput (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindOutput)2