Search in sources :

Example 6 with TreeNode

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

the class CPDViewLabelProvider2 method getColumnText.

/*
     * @see
     * org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.
     * Object, int)
     */
public String getColumnText(Object element, int columnIndex) {
    final TreeNode node = (TreeNode) element;
    final Object value = node.getValue();
    String result = "";
    switch(columnIndex) {
        case 0:
            int count = lineCountFor(node);
            if (count > 0) {
                result = Integer.toString(count);
            }
            break;
        // show the source
        case 1:
            if (value instanceof String) {
                result = String.valueOf(value);
                if (result.endsWith("\r")) {
                    result = result.substring(0, result.length() - 1);
                }
            }
            if (value instanceof Match) {
            // do nothing, let the painter show it
            }
            break;
        default:
    }
    return result;
}
Also used : TreeNode(org.eclipse.jface.viewers.TreeNode) Match(net.sourceforge.pmd.cpd.Match)

Example 7 with TreeNode

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

the class CPDViewLabelProvider2 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 0:
            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 8 with TreeNode

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

the class CPDViewTooltipListener2 method itemAt.

private Mark itemAt(TreeItem treeItem, Point location, GC gc) {
    if (treeItem == null) {
        return null;
    }
    Object item = ((TreeNode) treeItem.getData()).getValue();
    String[] names;
    if (item instanceof Match) {
        names = CPDViewLabelProvider2.sourcesFor((Match) item);
    } else {
        return null;
    }
    // subtract width of preceeding columns
    location.x -= view.widthOf(0);
    int colWidth = view.widthOf(CPDView2.SOURCE_COLUMN_IDX);
    int cellWidth = colWidth / names.length;
    for (int i = 0; i < names.length; i++) {
        int rightEdge = colWidth - (cellWidth * i);
        int[] widths = view.widthsFor(names[i]);
        if (widths == null) {
            continue;
        }
        int classWidth = widths[1];
        if (// right of the start?
        location.x > rightEdge - classWidth && location.x < rightEdge) {
            // left of the end?
            return CPDViewLabelProvider2.entriesFor((Match) item)[i];
        }
    }
    return null;
}
Also used : TreeNode(org.eclipse.jface.viewers.TreeNode) Point(org.eclipse.swt.graphics.Point) Match(net.sourceforge.pmd.cpd.Match)

Example 9 with TreeNode

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

the class CPDViewLabelProvider method getColumnText.

/*
     * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
     */
public String getColumnText(Object element, int columnIndex) {
    final TreeNode node = (TreeNode) element;
    final Object value = node.getValue();
    String result = "";
    switch(columnIndex) {
        // show the message
        case 2:
            if (value instanceof Match) {
                final Match match = (Match) value;
                final StringBuilder buffer = new StringBuilder(50);
                buffer.append("Found suspect cut & paste (");
                buffer.append(match.getMarkCount()).append(" matches,");
                buffer.append(match.getLineCount());
                if (match.getLineCount() == 1) {
                    buffer.append(" line)");
                } else {
                    buffer.append(" lines)");
                }
                result = buffer.toString();
            } else if (value instanceof TokenEntry) {
                final TokenEntry entry = (TokenEntry) value;
                final Match match = (Match) node.getParent().getValue();
                final int startLine = entry.getBeginLine();
                final int endLine = entry.getBeginLine() + match.getLineCount() - 1;
                final IPath path = Path.fromOSString(entry.getTokenSrcID());
                final StringBuilder buffer = new StringBuilder(100);
                if (startLine == endLine) {
                    buffer.append("line ").append(startLine);
                } else {
                    buffer.append("lines ").append(startLine).append('-').append(endLine);
                }
                buffer.append(" in file ").append(path.lastSegment());
                result = buffer.toString();
            }
            break;
        case 3:
            if (value instanceof TokenEntry) {
                final TokenEntry entry = (TokenEntry) value;
                final IPath path = Path.fromOSString(entry.getTokenSrcID());
                final IResource resource = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(path);
                if (resource != null) {
                    result = resource.getProjectRelativePath().removeFileExtension().toString().replace(IPath.SEPARATOR, '.');
                }
            }
            break;
        default:
    }
    return result;
}
Also used : TokenEntry(net.sourceforge.pmd.cpd.TokenEntry) IPath(org.eclipse.core.runtime.IPath) TreeNode(org.eclipse.jface.viewers.TreeNode) IResource(org.eclipse.core.resources.IResource) Match(net.sourceforge.pmd.cpd.Match)

Example 10 with TreeNode

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

the class CPDView2 method setData.

/**
 * Sets input for the table.
 *
 * @param matches
 *            CPD Command that contain the matches from the CPD
 */
public void setData(Iterator<Match> matches) {
    List<TreeNode> elements = new ArrayList<TreeNode>();
    if (matches != null) {
        for (Match match : asList(matches)) {
            // create a treenode for the match and add to the list
            TreeNode matchNode = new TreeNode(match);
            elements.add(matchNode);
            String[] lines = sourceLinesFrom(match, true);
            TreeNode[] children = new TreeNode[lines.length];
            for (int j = 0; j < lines.length; j++) {
                String line = lines[j];
                if (line == null) {
                    System.out.println();
                }
                children[j] = new TreeNode(line);
                children[j].setParent(matchNode);
            }
            matchNode.setChildren(children);
        }
    }
    // set the children of the rootnode: the matches
    treeViewer.setInput(elements.toArray(new TreeNode[elements.size()]));
}
Also used : TreeNode(org.eclipse.jface.viewers.TreeNode) ArrayList(java.util.ArrayList) 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