Search in sources :

Example 16 with TreeNode

use of org.eclipse.jface.viewers.TreeNode in project pmd-eclipse-plugin by pmd.

the class CPDViewDoubleClickEventListener method doubleClick.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.
     * jface.viewers.DoubleClickEvent)
     */
public void doubleClick(DoubleClickEvent event) {
    final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    final Object object = selection.getFirstElement();
    final TreeNode node = (TreeNode) object;
    final Object value = node.getValue();
    final TreeViewer treeViewer = view.getTreeViewer();
    if (value instanceof Match) {
        if (treeViewer.getExpandedState(node)) {
            // the node is expanded, so collapse
            treeViewer.collapseToLevel(node, TreeViewer.ALL_LEVELS);
        } else {
            // the node is collapsed, so expand
            treeViewer.expandToLevel(node, 1);
        }
    } else if (value instanceof TokenEntry) {
        final TokenEntry entry = (TokenEntry) value;
        final Match match = (Match) node.getParent().getValue();
        highlightText(match, entry);
    }
}
Also used : TokenEntry(net.sourceforge.pmd.cpd.TokenEntry) TreeNode(org.eclipse.jface.viewers.TreeNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Match(net.sourceforge.pmd.cpd.Match)

Example 17 with TreeNode

use of org.eclipse.jface.viewers.TreeNode in project pmd-eclipse-plugin by pmd.

the class CPDViewLabelProvider method getColumnImage.

/*
     * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
     */
public Image getColumnImage(Object element, int columnIndex) {
    Image image = null;
    final TreeNode node = (TreeNode) element;
    final Object value = node.getValue();
    // if the Element is a Match or TokenEntry
    switch(columnIndex) {
        case 1:
            if (value instanceof Match) {
                image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
            } else if (value instanceof TokenEntry) {
                image = PlatformUI.getWorkbench().getSharedImages().getImage(SharedImages.IMG_OPEN_MARKER);
            }
            break;
        default:
    }
    return image;
}
Also used : TokenEntry(net.sourceforge.pmd.cpd.TokenEntry) TreeNode(org.eclipse.jface.viewers.TreeNode) Image(org.eclipse.swt.graphics.Image) Match(net.sourceforge.pmd.cpd.Match)

Example 18 with TreeNode

use of org.eclipse.jface.viewers.TreeNode in project pmd-eclipse-plugin by pmd.

the class CPDViewTooltipListener method handleEvent.

/*
     * @see
     * org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.
     * Event)
     */
public void handleEvent(Event event) {
    final Tree tree = view.getTreeViewer().getTree();
    final TreeItem item = tree.getItem(new Point(event.x, event.y));
    switch(event.type) {
        case SWT.Dispose:
        case SWT.KeyDown:
            disposeTooltip();
            break;
        case SWT.MouseMove:
            if (this.shownItem != null && !shownItem.equals(item)) {
                disposeTooltip();
            }
            break;
        case SWT.MouseHover:
            if (item != null) {
                final TreeNode node = (TreeNode) item.getData();
                if (node.getValue() instanceof Match) {
                    final Match match = (Match) node.getValue();
                    final String text = createText(match);
                    showTooltip(item, text);
                }
            }
            break;
        default:
            break;
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TreeNode(org.eclipse.jface.viewers.TreeNode) Tree(org.eclipse.swt.widgets.Tree) Point(org.eclipse.swt.graphics.Point) Match(net.sourceforge.pmd.cpd.Match)

Example 19 with TreeNode

use of org.eclipse.jface.viewers.TreeNode in project pmd-eclipse-plugin by pmd.

the class CPDView2 method addPainters.

private void addPainters(Tree tree) {
    Listener paintListener = new Listener() {

        public void handleEvent(Event event) {
            if (event.index != SOURCE_COLUMN_IDX) {
                return;
            }
            Object item = ((TreeNode) event.item.getData()).getValue();
            String[] names;
            if (item instanceof Match) {
                names = CPDViewLabelProvider2.sourcesFor((Match) item);
            } else {
                return;
            }
            int descent = event.gc.getFontMetrics().getDescent();
            int colWidth = widthOf(SOURCE_COLUMN_IDX);
            int cellWidth = colWidth / names.length;
            for (int i = 0; i < names.length; i++) {
                int rightEdge = colWidth - (cellWidth * i);
                paintName(event.gc, event.x, event.y, names[i], rightEdge, descent, cellWidth);
            }
        }
    };
    Listener measureListener = new Listener() {

        public void handleEvent(Event event) {
            if (event.index != SOURCE_COLUMN_IDX) {
                return;
            }
            event.width = 400;
            event.height = 24;
        }
    };
    tree.addListener(SWT.PaintItem, paintListener);
    tree.addListener(SWT.MeasureItem, measureListener);
}
Also used : IPropertyListener(org.eclipse.ui.IPropertyListener) Listener(org.eclipse.swt.widgets.Listener) TreeNode(org.eclipse.jface.viewers.TreeNode) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) Point(org.eclipse.swt.graphics.Point) Match(net.sourceforge.pmd.cpd.Match)

Aggregations

TreeNode (org.eclipse.jface.viewers.TreeNode)19 Match (net.sourceforge.pmd.cpd.Match)10 DefaultTreeNode (eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode)8 MapTreeNode (eu.esdihumboldt.hale.ui.util.tree.MapTreeNode)8 ResolvedTask (eu.esdihumboldt.hale.common.tasks.ResolvedTask)7 SortedMapTreeNode (eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode)6 Cell (eu.esdihumboldt.hale.common.align.model.Cell)4 TokenEntry (net.sourceforge.pmd.cpd.TokenEntry)4 Point (org.eclipse.swt.graphics.Point)4 ArrayList (java.util.ArrayList)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 Task (eu.esdihumboldt.hale.common.tasks.Task)2 TaskService (eu.esdihumboldt.hale.common.tasks.TaskService)2 Image (org.eclipse.swt.graphics.Image)2 TaskSeverity (eu.esdihumboldt.hale.common.tasks.TaskType.TaskSeverity)1 TaskServiceAdapter (eu.esdihumboldt.hale.ui.service.tasks.TaskServiceAdapter)1 CollectionTreeNodeContentProvider (eu.esdihumboldt.hale.ui.util.tree.CollectionTreeNodeContentProvider)1 ReadOnlyEditingSupport (eu.esdihumboldt.hale.ui.util.viewer.ReadOnlyEditingSupport)1 PropertiesViewPart (eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart)1