Search in sources :

Example 1 with TreeSelection

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

the class GridTreeViewer method remove.

/**
	 * Removes the element at the specified index of the parent.  The selection is updated if required.
	 *
	 * @param parentOrTreePath the parent element, the input element, or a tree path to the parent element
	 * @param index child index
	 * @since 3.3
	 */
public void remove(final Object parentOrTreePath, final int index) {
    if (checkBusy())
        return;
    final List oldSelection = new LinkedList(Arrays.asList(((TreeSelection) getSelection()).getPaths()));
    preservingSelection(new Runnable() {

        public void run() {
            TreePath removedPath = null;
            if (internalIsInputOrEmptyPath(parentOrTreePath)) {
                Tree tree = (Tree) getControl();
                if (index < tree.getItemCount()) {
                    TreeItem item = tree.getItem(index);
                    if (item.getData() != null) {
                        removedPath = getTreePathFromItem(item);
                        disassociate(item);
                    }
                    item.dispose();
                }
            } else {
                Widget[] parentItems = internalFindItems(parentOrTreePath);
                for (int i = 0; i < parentItems.length; i++) {
                    TreeItem parentItem = (TreeItem) parentItems[i];
                    if (parentItem.isDisposed())
                        continue;
                    if (index < parentItem.getItemCount()) {
                        TreeItem item = parentItem.getItem(index);
                        if (item.getData() != null) {
                            removedPath = getTreePathFromItem(item);
                            disassociate(item);
                        }
                        item.dispose();
                    }
                }
            }
            if (removedPath != null) {
                boolean removed = false;
                for (Iterator it = oldSelection.iterator(); it.hasNext(); ) {
                    TreePath path = (TreePath) it.next();
                    if (path.startsWith(removedPath, getComparer())) {
                        it.remove();
                        removed = true;
                    }
                }
                if (removed) {
                    setSelection(new TreeSelection((TreePath[]) oldSelection.toArray(new TreePath[oldSelection.size()]), getComparer()), false);
                }
            }
        }
    });
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) Tree(org.eclipse.swt.widgets.Tree) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 2 with TreeSelection

use of org.eclipse.jface.viewers.TreeSelection in project tdi-studio-se by Talend.

the class PushToPaletteActionProvider method fillContextMenu.

/**
     * Adds a submenu to the given menu with the name "New Component".
     */
@Override
public void fillContextMenu(IMenuManager menu) {
    //$NON-NLS-1$
    menu.insertBefore("group.edit", copyProjectAction);
    // Object obj = ((TreeSelection) this.getContext().getSelection()).getFirstElement();// need to get all
    // selected.
    Iterator ite = ((TreeSelection) this.getContext().getSelection()).iterator();
    selectedFolderList = new ArrayList<IFolder>();
    while (ite.hasNext()) {
        Object obj = ite.next();
        if (obj instanceof IFolder) {
            selectedFolderList.add((IFolder) obj);
        }
    }
}
Also used : TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with TreeSelection

use of org.eclipse.jface.viewers.TreeSelection in project tdi-studio-se by Talend.

the class FindDialog method getSelectedNode.

/**
     * Gets the selected node.
     * 
     * @param viewer The tree viewer
     * @return The selected node
     */
private static ITreeNode getSelectedNode(TreeViewer viewer) {
    ISelection selection = viewer.getSelection();
    if (selection instanceof TreeSelection) {
        TreeSelection treeSelection = (TreeSelection) selection;
        Object element = treeSelection.getFirstElement();
        if (element instanceof ITreeNode) {
            return (ITreeNode) element;
        }
    }
    return null;
}
Also used : ITreeNode(org.talend.designer.runtime.visualization.internal.core.cpu.ITreeNode) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection)

Example 4 with TreeSelection

use of org.eclipse.jface.viewers.TreeSelection in project tdi-studio-se by Talend.

the class AbstractTreeNodeButton method init.

private void init(Composite parent, String tooltip, Image image) {
    button = new Button(parent, SWT.PUSH);
    button.setToolTipText(tooltip);
    button.setImage(image);
    button.setEnabled(false);
    button.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            if (treeViewer != null && !treeViewer.getTree().isDisposed() && treeViewer.getSelection() instanceof ITreeSelection) {
                handleSelectionEvent((TreeSelection) treeViewer.getSelection());
            }
        }
    });
    treeViewer = form.getTreeViewer();
    addTreeListeners();
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) Button(org.eclipse.swt.widgets.Button) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreeSelection(org.eclipse.jface.viewers.TreeSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event)

Example 5 with TreeSelection

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

the class MultiDBQueryDNDController method setTreeSelectedItems.

/**
	 * setTreeSelectedItems
	 */
public void setTreeSelectedItems() {
    synchronized (this) {
        //queryTree.refresh();
        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();
        for (Object obj : objs) {
            //			queryTree.setChecked(obj, true);
            if (obj instanceof ICubridNode) {
                multiDBQueryComposite.getSelectedNodes().add((ICubridNode) obj);
            }
        }
        //		multiDBQueryComposite.initialIndex();
        //refresh again make the new drag item can be selected
        //		queryTree.refresh();
        multiDBQueryComposite.setInput();
    //queryTree.refresh();
    }
}
Also used : ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Aggregations

TreeSelection (org.eclipse.jface.viewers.TreeSelection)15 ISelection (org.eclipse.jface.viewers.ISelection)6 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)4 TreeViewer (org.eclipse.jface.viewers.TreeViewer)4 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 TreePath (org.eclipse.jface.viewers.TreePath)2 Button (org.eclipse.swt.widgets.Button)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)1 LinkedList (java.util.LinkedList)1 Node (net.sourceforge.nattable.columnCategories.Node)1 IFolder (org.eclipse.core.resources.IFolder)1 StyledString (org.eclipse.jface.viewers.StyledString)1