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