Example usage for org.eclipse.jface.viewers TreeViewer getTree

List of usage examples for org.eclipse.jface.viewers TreeViewer getTree

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TreeViewer getTree.

Prototype

public Tree getTree() 

Source Link

Document

Returns this tree viewer's tree control.

Usage

From source file:com.amalto.workbench.editors.DataModelMainPage.java

License:Open Source License

public void stepUp(TreeViewer targetTreeViewer) {
    TreeItem item;/*w ww. j av  a  2s .c om*/
    TreeItem[] items = targetTreeViewer.getTree().getSelection();
    boolean isDirty = false;
    for (TreeItem item2 : items) {
        item = item2;
        Object data = item.getData();
        EList content = getXSDComponentContainer(data);
        if (content != null) {
            int index = content.indexOf(data);
            if (index > 0) {
                content.move(index - 1, index);
                isDirty = true;
                this.refresh();
            }
        }
    }
    if (isDirty) {
        this.markDirtyWithoutCommit();
    }
}

From source file:com.amalto.workbench.editors.DataModelMainPage.java

License:Open Source License

public void stepDown(TreeViewer targetTreeViewer) {
    TreeItem item;//from  w  ww  .j a v  a 2 s  . co  m
    TreeItem[] items = targetTreeViewer.getTree().getSelection();
    boolean isDirty = false;
    for (int i = items.length - 1; i >= 0; i--) {
        item = items[i];
        Object data = item.getData();
        EList content = getXSDComponentContainer(data);
        if (content != null) {
            int index = content.indexOf(data);
            if (index < content.size() - 1) {
                content.move(index, index + 1);
                isDirty = true;
                this.refresh();
            }
        }
    }
    if (isDirty) {
        this.markDirtyWithoutCommit();
    }
}

From source file:com.amazonaws.eclipse.cloudformation.templates.editor.TemplateContentOutlinePage.java

License:Apache License

private void updateContent() {
    TreeViewer viewer = getTreeViewer();

    if (document.getModel() == null)
        return;/*  w  w w  . j  a  va  2 s . c o m*/

    expandedPaths = new HashSet<String>();
    for (Object obj : viewer.getExpandedElements()) {
        TemplateOutlineNode expandedNode = (TemplateOutlineNode) obj;
        expandedPaths.add(expandedNode.getNode().getPath());
    }

    viewer.setInput(new TemplateOutlineNode("ROOT", document.getModel()));

    for (TreeItem treeItem : viewer.getTree().getItems()) {
        expandTreeItems(treeItem, expandedPaths);
    }
}

From source file:com.amazonaws.eclipse.codedeploy.explorer.editor.table.DeploymentsTableView.java

License:Apache License

private TreeViewer createControls(FormToolkit toolkit) {
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.marginWidth = 0;// w  w w  .  ja  va2  s . c om
    gridLayout.marginHeight = 0;
    setLayout(gridLayout);

    Composite sectionComp = toolkit.createComposite(this, SWT.None);
    sectionComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    sectionComp.setLayout(new GridLayout(1, false));

    Composite headingComp = toolkit.createComposite(sectionComp, SWT.None);
    headingComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    headingComp.setLayout(new GridLayout());
    tableTitleLabel = toolkit.createLabel(headingComp, "Deployments");
    tableTitleLabel.setFont(JFaceResources.getHeaderFont());
    tableTitleLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));

    Composite tableHolder = toolkit.createComposite(sectionComp, SWT.None);
    tableHolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    FillLayout layout = new FillLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 10;
    layout.type = SWT.VERTICAL;
    tableHolder.setLayout(layout);

    Composite tableComp = toolkit.createComposite(tableHolder, SWT.None);
    final TreeColumnLayout tableColumnLayout = new TreeColumnLayout();
    tableComp.setLayout(tableColumnLayout);

    final TreeViewer viewer = new TreeViewer(tableComp, SWT.BORDER | SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL);
    viewer.getTree().setLinesVisible(true);
    viewer.getTree().setHeaderVisible(true);
    viewer.setUseHashlookup(true);
    viewer.setLabelProvider(new DeploymentsTableViewLabelProvider());
    viewer.setContentProvider(new DeploymentsTableViewContentProvider(this.viewer, this.contentCache));

    Tree tree = viewer.getTree();

    createColumns(tableColumnLayout, tree);

    viewer.setInput(loadingContentProvider);
    updateRefreshProgress(0, false);

    // Async load top-level data
    new Thread(new Runnable() {

        public void run() {
            Display.getDefault().syncExec(new Runnable() {
                public void run() {
                    // Preserve the current column widths
                    int[] colWidth = new int[viewer.getTree().getColumns().length];
                    int i = 0;
                    for (TreeColumn col : viewer.getTree().getColumns()) {
                        colWidth[i++] = col.getWidth();
                    }

                    i = 0;
                    for (TreeColumn col : viewer.getTree().getColumns()) {
                        tableColumnLayout.setColumnData(col, new ColumnPixelData(colWidth[i]));
                    }
                }
            });

            // Cache the children of all the top-level elements before
            // updating the tree view
            loadAllTopLevelElements();

            Display.getDefault().syncExec(new Runnable() {
                public void run() {
                    viewer.setInput(contentCache);
                }
            });
        }
    }).start();

    return viewer;
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.OutlinePage.java

License:Open Source License

/** Refresh all the icon state */
public void refreshIcons() {
    TreeViewer treeViewer = getTreeViewer();
    if (treeViewer != null) {
        Tree tree = treeViewer.getTree();
        if (tree != null && !tree.isDisposed()) {
            treeViewer.refresh();/*from   ww  w.java  2 s .  c om*/
        }
    }
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.OutlinePage.java

License:Open Source License

private void createOutline(Composite parent) {
    if (AdtUtils.isEclipse4()) {
        // This is a workaround for the focus behavior in Eclipse 4 where
        // the framework ends up calling setFocus() on the first widget in the outline
        // AFTER a mouse click has been received. Specifically, if the user clicks in
        // the embedded property sheet to for example give a Text property editor focus,
        // then after the mouse click, the Outline window activation event is processed,
        // and this event causes setFocus() to be called first on the PageBookView (which
        // ends up calling setFocus on the first control, normally the TreeViewer), and
        // then on the Page itself. We're dealing with the page setFocus() in the override
        // of that method in the class, such that it does nothing.
        // However, we have to also disable the setFocus on the first control in the
        // outline page. To deal with that, we create our *own* first control in the
        // outline, and make its setFocus() a no-op. We also make it invisible, since we
        // don't actually want anything but the tree viewer showing in the outline.
        Text text = new Text(parent, SWT.NONE) {
            @Override// w ww.  j  ava  2 s .c  om
            public boolean setFocus() {
                // Focus no-op
                return true;
            }

            @Override
            protected void checkSubclass() {
                // Disable the check that prevents subclassing of SWT components
            }
        };
        text.setVisible(false);
    }

    super.createControl(parent);

    TreeViewer tv = getTreeViewer();
    tv.setAutoExpandLevel(2);
    tv.setContentProvider(new ContentProvider());
    tv.setLabelProvider(new LabelProvider());
    tv.setInput(mRootWrapper);
    tv.expandToLevel(mRootWrapper.getRoot(), 2);

    int supportedOperations = DND.DROP_COPY | DND.DROP_MOVE;
    Transfer[] transfers = new Transfer[] { SimpleXmlTransfer.getInstance() };

    tv.addDropSupport(supportedOperations, transfers, new OutlineDropListener(this, tv));
    tv.addDragSupport(supportedOperations, transfers, new OutlineDragListener(this, tv));

    // The tree viewer will hold CanvasViewInfo instances, however these
    // change each time the canvas is reloaded. OTOH layoutlib gives us
    // constant UiView keys which we can use to perform tree item comparisons.
    tv.setComparer(new IElementComparer() {
        @Override
        public int hashCode(Object element) {
            if (element instanceof CanvasViewInfo) {
                UiViewElementNode key = ((CanvasViewInfo) element).getUiViewNode();
                if (key != null) {
                    return key.hashCode();
                }
            }
            if (element != null) {
                return element.hashCode();
            }
            return 0;
        }

        @Override
        public boolean equals(Object a, Object b) {
            if (a instanceof CanvasViewInfo && b instanceof CanvasViewInfo) {
                UiViewElementNode keyA = ((CanvasViewInfo) a).getUiViewNode();
                UiViewElementNode keyB = ((CanvasViewInfo) b).getUiViewNode();
                if (keyA != null) {
                    return keyA.equals(keyB);
                }
            }
            if (a != null) {
                return a.equals(b);
            }
            return false;
        }
    });
    tv.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            // This used to open the property view, but now that properties are docked
            // let's use it for something else -- such as showing the editor source
            /*
            // Front properties panel; its selection is already linked
            IWorkbenchPage page = getSite().getPage();
            try {
            page.showView(IPageLayout.ID_PROP_SHEET, null, IWorkbenchPage.VIEW_ACTIVATE);
            } catch (PartInitException e) {
            AdtPlugin.log(e, "Could not activate property sheet");
            }
            */

            TreeItem[] selection = getTreeViewer().getTree().getSelection();
            if (selection.length > 0) {
                CanvasViewInfo vi = getViewInfo(selection[0].getData());
                if (vi != null) {
                    LayoutCanvas canvas = mGraphicalEditorPart.getCanvasControl();
                    canvas.show(vi);
                }
            }
        }
    });

    setupContextMenu();

    // Listen to selection changes from the layout editor
    getSite().getPage().addSelectionListener(this);
    getControl().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            dispose();
        }
    });

    Tree tree = tv.getTree();
    tree.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.character == '-') {
                if (mMoveUpAction.isEnabled()) {
                    mMoveUpAction.run();
                }
            } else if (e.character == '+') {
                if (mMoveDownAction.isEnabled()) {
                    mMoveDownAction.run();
                }
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }
    });

    setupTooltip();
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.OutlinePage.java

License:Open Source License

/**
 * Invoked by {@link LayoutCanvas} to set the model (a.k.a. the root view info).
 *
 * @param rootViewInfo The root of the view info hierarchy. Can be null.
 */// w  w  w  .  ja  v a2s. c  o m
public void setModel(CanvasViewInfo rootViewInfo) {
    if (!mActive) {
        return;
    }

    mRootWrapper.setRoot(rootViewInfo);

    TreeViewer tv = getTreeViewer();
    if (tv != null && !tv.getTree().isDisposed()) {
        Object[] expanded = tv.getExpandedElements();
        tv.refresh();
        tv.setExpandedElements(expanded);
        // Ensure that the root is expanded
        tv.expandToLevel(rootViewInfo, 2);
    }
}

From source file:com.application.areca.launcher.gui.composites.ArchiveExplorer.java

License:Open Source License

public ArchiveExplorer(Composite parent, boolean aggregated) {
    super(parent, SWT.NONE);
    try {/*from   w  ww.j  av  a 2  s .  c  om*/
        this.aggregated = aggregated;

        setLayout(new FillLayout());
        TreeViewer viewer = new TreeViewer(this, SWT.BORDER | SWT.MULTI);
        tree = viewer.getTree();
        tree.setLinesVisible(AbstractWindow.getTableLinesVisible());
        tree.setHeaderVisible(true);
        tree.addMouseListener(this);
        tree.addListener(SWT.Selection, this);

        TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
        column1.setText(RM.getLabel("mainpanel.name.label"));
        column1.setWidth(AbstractWindow.computeWidth(400));
        TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
        column2.setText(RM.getLabel("mainpanel.size.label"));
        column2.setWidth(AbstractWindow.computeWidth(120));

        viewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                TreeItem item = tree.getSelection()[0];
                if (item.getExpanded()) {
                    item.setExpanded(false);
                    handleExpansion(item, false);
                } else {
                    handleExpansion(item, true);
                    item.setExpanded(true);
                }
            }
        });

        TreeListener listener = new TreeListener() {
            public void treeCollapsed(TreeEvent arg0) {
                TreeItem item = (TreeItem) arg0.item;
                handleExpansion(item, false);
            }

            public void treeExpanded(TreeEvent event) {
                TreeItem item = (TreeItem) event.item;
                handleExpansion(item, true);
            }
        };
        tree.addTreeListener(listener);
    } catch (RuntimeException e) {
        Application.getInstance().handleException(e);
        throw e;
    }
}

From source file:com.application.areca.launcher.gui.composites.SearchComposite.java

License:Open Source License

private Composite buildBottomComposite(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new GridLayout(2, false));

    TreeViewer tv = new TreeViewer(panel, SWT.BORDER);
    tree = tv.getTree();
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    tree.setLinesVisible(AbstractWindow.getTableLinesVisible());
    tree.addMouseListener(this);

    lblLog = new Label(panel, SWT.NONE);
    lblLog.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    btnClear = new Button(panel, SWT.PUSH);
    btnClear.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false));
    btnClear.setText(RM.getLabel("search.clearall.label"));
    btnClear.addListener(SWT.Selection, this);

    return panel;
}

From source file:com.application.areca.launcher.gui.composites.TreeComposite.java

License:Open Source License

public TreeComposite(Composite parent) {
    super(parent, SWT.NONE);
    setLayout(new FillLayout());

    TreeViewer viewer = new TreeViewer(this, SWT.BORDER);
    tree = viewer.getTree();
    tree.addMouseListener(this);
    tree.addListener(SWT.Selection, this);

    viewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            if (application.isCurrentObjectTarget()) {
                application.showEditTarget(application.getCurrentTarget());
            } else if (application.isCurrentObjectProcess()) {
                application.showEditGroup(application.getCurrentTargetGroup());
            }/*from w  w  w .j  a va2  s  .  co  m*/
        }
    });

    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    final int operation = DND.DROP_MOVE;

    final DragSource source = new DragSource(tree, operation);
    source.setTransfer(types);
    source.addDragListener(new DragSourceAdapter() {
        public void dragStart(DragSourceEvent event) {
            TreeItem[] selection = tree.getSelection();
            if (selection.length > 0 && selection[0].getData() instanceof AbstractRecoveryTarget) {
                event.doit = true;
            } else {
                event.doit = false;
            }
        };

        public void dragSetData(DragSourceEvent event) {
            event.data = "dummy data";
        }
    });

    DropTarget target = new DropTarget(tree, operation);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {
        public void dragEnter(DropTargetEvent event) {
            event.detail = DND.DROP_NONE;
            event.feedback = DND.FEEDBACK_NONE;
        }

        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
            if (event.item != null && isValidTreeItem((TreeItem) event.item)) {
                event.feedback |= DND.FEEDBACK_SELECT;
                event.detail = operation;
            } else {
                event.feedback |= DND.FEEDBACK_NONE;
                event.detail = DND.DROP_NONE;
            }
        }

        public void drop(DropTargetEvent event) {
            if (event.item != null) {
                TreeItem item = (TreeItem) event.item;
                AbstractRecoveryTarget draggedTarget = Application.getInstance().getCurrentTarget();
                TargetGroup sourceProcess = draggedTarget.getGroup();
                TargetGroup destinationProcess = extractRecoveryProcess(item);

                if (!destinationProcess.equals(sourceProcess)) {
                    sourceProcess.removeTarget(draggedTarget);

                    if (destinationProcess.getTargetById(draggedTarget.getId()) != null) {
                        // A target with same ID already exists
                        draggedTarget.setId(destinationProcess.getNextFreeTargetId());
                    }

                    destinationProcess.addTarget(draggedTarget);
                    draggedTarget.setGroup(destinationProcess);
                }

                application.saveProcess(sourceProcess);
                application.saveProcess(destinationProcess);
                refresh();
            }
        }
    });

    refresh();
}