Search in sources :

Example 96 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer in project eclipse.platform.text by eclipse.

the class AbstractTextSearchViewPage method handleOpen.

/**
 * <p>This method is called when the search page gets an 'open' event from its
 * underlying viewer (for example on double click). The default
 * implementation will open the first match on any element that has matches.
 * If the element to be opened is an inner node in the tree layout, the node
 * will be expanded if it's collapsed and vice versa. Subclasses are allowed
 * to override this method.
 * </p>
 * @param event
 *            the event sent for the currently shown viewer
 *
 * @see IOpenListener
 */
protected void handleOpen(OpenEvent event) {
    Viewer viewer = event.getViewer();
    boolean hasCurrentMatch = showCurrentMatch(OpenStrategy.activateOnOpen());
    ISelection sel = event.getSelection();
    if (viewer instanceof TreeViewer && sel instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) sel;
        TreeViewer tv = (TreeViewer) getViewer();
        Object element = selection.getFirstElement();
        if (element != null) {
            if (!hasCurrentMatch && getDisplayedMatchCount(element) > 0)
                gotoNextMatch(OpenStrategy.activateOnOpen());
            else
                tv.setExpandedState(element, !tv.getExpandedState(element));
        }
        return;
    } else if (!hasCurrentMatch) {
        gotoNextMatch(OpenStrategy.activateOnOpen());
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelection(org.eclipse.jface.viewers.ISelection) TableViewer(org.eclipse.jface.viewers.TableViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 97 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer in project eclipse.platform.text by eclipse.

the class AbstractTextSearchViewPage method createViewer.

private void createViewer(Composite parent, int layout) {
    if ((layout & FLAG_LAYOUT_FLAT) != 0) {
        TableViewer viewer = createTableViewer(parent);
        fViewer = viewer;
        configureTableViewer(viewer);
    } else if ((layout & FLAG_LAYOUT_TREE) != 0) {
        TreeViewer viewer = createTreeViewer(parent);
        fViewer = viewer;
        configureTreeViewer(viewer);
        fCollapseAllAction.setViewer(viewer);
        fExpandAllAction.setViewer(viewer);
    }
    fCopyToClipboardAction.setViewer(fViewer);
    fSelectAllAction.setViewer(fViewer);
    IToolBarManager tbm = getSite().getActionBars().getToolBarManager();
    tbm.removeAll();
    SearchView.createToolBarGroups(tbm);
    fillToolbar(tbm);
    tbm.update(false);
    new OpenAndLinkWithEditorHelper(fViewer) {

        @Override
        protected void activate(ISelection selection) {
            final int currentMode = OpenStrategy.getOpenMethod();
            try {
                OpenStrategy.setOpenMethod(OpenStrategy.DOUBLE_CLICK);
                handleOpen(new OpenEvent(fViewer, selection));
            } finally {
                OpenStrategy.setOpenMethod(currentMode);
            }
        }

        @Override
        protected void linkToEditor(ISelection selection) {
        // not supported by this part
        }

        @Override
        protected void open(ISelection selection, boolean activate) {
            handleOpen(new OpenEvent(fViewer, selection));
        }
    };
    fViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            fCurrentMatchIndex = -1;
            fRemoveSelectedMatches.setEnabled(canRemoveMatchesWith(event.getSelection()));
        }
    });
    fViewer.addSelectionChangedListener(fViewerAdapter);
    Menu menu = fMenu.createContextMenu(fViewer.getControl());
    fViewer.getControl().setMenu(menu);
    updateLayoutActions();
    getViewPart().updateLabel();
}
Also used : OpenAndLinkWithEditorHelper(org.eclipse.ui.OpenAndLinkWithEditorHelper) IToolBarManager(org.eclipse.jface.action.IToolBarManager) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Menu(org.eclipse.swt.widgets.Menu) TableViewer(org.eclipse.jface.viewers.TableViewer) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 98 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer in project eclipse.platform.text by eclipse.

the class JavaContentOutlinePage method createControl.

@Override
public void createControl(Composite parent) {
    super.createControl(parent);
    TreeViewer viewer = getTreeViewer();
    viewer.setContentProvider(new ContentProvider());
    viewer.setLabelProvider(new LabelProvider());
    viewer.addSelectionChangedListener(this);
    if (fInput != null)
        viewer.setInput(fInput);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 99 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer in project eclipse.platform.text by eclipse.

the class JavaContentOutlinePage method update.

/**
 * Updates the outline page.
 */
public void update() {
    TreeViewer viewer = getTreeViewer();
    if (viewer != null) {
        Control control = viewer.getControl();
        if (control != null && !control.isDisposed()) {
            control.setRedraw(false);
            viewer.setInput(fInput);
            viewer.expandAll();
            control.setRedraw(true);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) TreeViewer(org.eclipse.jface.viewers.TreeViewer)

Example 100 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer in project uiautomatorviewer by yangzaiCN.

the class UiAutomatorViewer method createContents.

/**
 * Create contents of the application window.
 *
 * @param parent
 */
@Override
protected Control createContents(Composite parent) {
    UiAutomatorModel.createInstance(this);
    Composite basePane = new Composite(parent, SWT.NONE);
    basePane.setLayout(new GridLayout(2, false));
    mScreenshotCanvas = new Canvas(basePane, SWT.NONE);
    mScreenshotCanvas.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            UiAutomatorModel.getModel().toggleExploreMode();
        }
    });
    mScreenshotCanvas.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
    mScreenshotCanvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
    mScreenshotCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (mCachedScaleImage != null) {
                // shifting the image here, so that there's a border around screen shot
                // this makes highlighting red rectangles on the screen shot edges more visible
                e.gc.drawImage(mCachedScaleImage, IMG_BORDER, IMG_BORDER);
                Rectangle rect = UiAutomatorModel.getModel().getCurrentDrawingRect();
                if (rect != null) {
                    e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_RED));
                    if (UiAutomatorModel.getModel().isExploreMode()) {
                        // when we highlight nodes dynamically on mouse move,
                        // use dashed borders
                        e.gc.setLineStyle(SWT.LINE_DASH);
                        e.gc.setLineWidth(1);
                    } else {
                        // when highlighting nodes on tree node selection,
                        // use solid borders
                        e.gc.setLineStyle(SWT.LINE_SOLID);
                        e.gc.setLineWidth(2);
                    }
                    e.gc.drawRectangle(IMG_BORDER + getScaledSize(rect.x), IMG_BORDER + getScaledSize(rect.y), getScaledSize(rect.width), getScaledSize(rect.height));
                }
            }
        }
    });
    mScreenshotCanvas.addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            if (UiAutomatorModel.getModel().isExploreMode()) {
                UiAutomatorModel.getModel().updateSelectionForCoordinates(getInverseScaledSize(e.x - IMG_BORDER), getInverseScaledSize(e.y - IMG_BORDER));
            }
        }
    });
    mScreenshotCanvas.setBackgroundImage(ImageHelper.loadImageDescriptorFromResource("images/logo.png").createImage());
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    toolBarManager.add(mOpenFilesAction);
    toolBarManager.add(mExpandAllAction);
    toolBarManager.add(mScreenshotAction);
    toolBarManager.createControl(basePane);
    mTreeViewer = new TreeViewer(basePane, SWT.BORDER);
    Tree tree = mTreeViewer.getTree();
    GridData gd_Tree = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
    gd_Tree.widthHint = 350;
    tree.setLayoutData(gd_Tree);
    mTreeViewer.setContentProvider(new BasicTreeNodeContentProvider());
    // default LabelProvider uses toString() to generate text to display
    mTreeViewer.setLabelProvider(new LabelProvider());
    mTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection().isEmpty()) {
                UiAutomatorModel.getModel().setSelectedNode(null);
            } else if (event.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                Object o = selection.toArray()[0];
                if (o instanceof BasicTreeNode) {
                    UiAutomatorModel.getModel().setSelectedNode((BasicTreeNode) o);
                }
            }
        }
    });
    // move focus so that it's not on tool bar (looks weird)
    tree.setFocus();
    Group grpNodeDetail = new Group(basePane, SWT.NONE);
    grpNodeDetail.setLayout(new FillLayout(SWT.HORIZONTAL));
    GridData gd_grpNodeDetail = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_grpNodeDetail.heightHint = FIXED_DETAIL_VIEW_HEIGHT;
    gd_grpNodeDetail.minimumHeight = FIXED_DETAIL_VIEW_HEIGHT;
    gd_grpNodeDetail.widthHint = FIXED_RHS_WIDTH;
    gd_grpNodeDetail.minimumWidth = FIXED_RHS_WIDTH;
    grpNodeDetail.setLayoutData(gd_grpNodeDetail);
    grpNodeDetail.setText("Node Detail");
    Composite tableContainer = new Composite(grpNodeDetail, SWT.NONE);
    tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    TableColumnLayout columnLayout = new TableColumnLayout();
    tableContainer.setLayout(columnLayout);
    mTableViewer = new TableViewer(tableContainer, SWT.BORDER | SWT.FULL_SELECTION);
    Table table = mTableViewer.getTable();
    table.setLinesVisible(true);
    // use ArrayContentProvider here, it assumes the input to the TableViewer
    // is an array, where each element represents a row in the table
    mTableViewer.setContentProvider(new ArrayContentProvider());
    TableViewerColumn tableViewerColumnKey = new TableViewerColumn(mTableViewer, SWT.NONE);
    TableColumn tblclmnKey = tableViewerColumnKey.getColumn();
    tableViewerColumnKey.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof AttributePair) {
                // first column, shows the attribute name
                return ((AttributePair) element).key;
            }
            return super.getText(element);
        }
    });
    columnLayout.setColumnData(tblclmnKey, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
    TableViewerColumn tableViewerColumnValue = new TableViewerColumn(mTableViewer, SWT.NONE);
    tableViewerColumnValue.setEditingSupport(new AttributeTableEditingSupport(mTableViewer));
    TableColumn tblclmnValue = tableViewerColumnValue.getColumn();
    columnLayout.setColumnData(tblclmnValue, new ColumnWeightData(2, ColumnWeightData.MINIMUM_WIDTH, true));
    tableViewerColumnValue.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof AttributePair) {
                // second column, shows the attribute value
                return ((AttributePair) element).value;
            }
            return super.getText(element);
        }
    });
    return basePane;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Group(org.eclipse.swt.widgets.Group) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Rectangle(org.eclipse.swt.graphics.Rectangle) AttributePair(com.android.uiautomator.tree.AttributePair) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ToolBarManager(org.eclipse.jface.action.ToolBarManager) BasicTreeNode(com.android.uiautomator.tree.BasicTreeNode) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) BasicTreeNodeContentProvider(com.android.uiautomator.tree.BasicTreeNodeContentProvider) Tree(org.eclipse.swt.widgets.Tree) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

TreeViewer (org.eclipse.jface.viewers.TreeViewer)248 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)62 GridData (org.eclipse.swt.layout.GridData)50 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)45 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)43 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)42 Composite (org.eclipse.swt.widgets.Composite)42 Tree (org.eclipse.swt.widgets.Tree)42 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)40 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)39 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)38 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)36 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)36 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)36 GridLayout (org.eclipse.swt.layout.GridLayout)34 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)31 ArrayList (java.util.ArrayList)29 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)27 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)27 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)25