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;
}
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;
}
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;
}
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;
}
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()]));
}
Aggregations