use of org.eclipse.jface.viewers.TreeNode in project hale by halestudio.
the class TaskDescriptionLabelProvider method getNodeLevel.
/**
* Get the given node's severity level
*
* @param node the node
*
* @return the severity level or <code>null</code>
*/
private TaskSeverity getNodeLevel(MapTreeNode<?, ?> node) {
TaskSeverity level = null;
TreeNode[] children = node.getChildren();
for (TreeNode child : children) {
if (child instanceof DefaultTreeNode) {
// child is task node
DefaultTreeNode childNode = (DefaultTreeNode) child;
Object tmp = childNode.getValue();
// get value
Object value;
if (tmp.getClass().isArray()) {
value = ((Object[]) tmp)[index];
} else {
value = tmp;
}
// determine level
if (value instanceof ResolvedTask) {
ResolvedTask<?> task = (ResolvedTask<?>) value;
if (task.isOpen()) {
// only inspect open tasks
level = TaskSeverity.max(level, task.getSeverityLevel());
}
}
} else if (child instanceof MapTreeNode<?, ?>) {
// child is map node
MapTreeNode<?, ?> childNode = (MapTreeNode<?, ?>) child;
TaskSeverity childLevel = getNodeLevel(childNode);
level = TaskSeverity.max(level, childLevel);
}
}
return level;
}
use of org.eclipse.jface.viewers.TreeNode in project hale by halestudio.
the class TaskTreeView method createPartControl.
/**
* @see WorkbenchPart#createPartControl(Composite)
*/
@Override
public void createPartControl(Composite parent) {
Composite page = new Composite(parent, SWT.NONE);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
page.setLayoutData(data);
// tree column layout
TreeColumnLayout layout = new TreeColumnLayout();
page.setLayout(layout);
// tree viewer
tree = new TreeViewer(page, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
tree.setContentProvider(new CollectionTreeNodeContentProvider());
tree.setUseHashlookup(true);
tree.getTree().setHeaderVisible(true);
tree.getTree().setLinesVisible(true);
tree.setComparator(new TaskTreeComparator());
taskService = HaleUI.getServiceProvider().getService(TaskService.class);
// columns
IColorProvider colorProvider = new TaskColorProvider(Display.getCurrent());
// title/description
TreeViewerColumn description = new TreeViewerColumn(tree, SWT.LEFT);
description.getColumn().setText(Messages.TaskTreeView_TitleDescriptionText);
description.getColumn().setToolTipText(Messages.TaskTreeView_description_tooltip);
TreeColumnViewerLabelProvider descriptionLabelProvider = new TreeColumnViewerLabelProvider(new TaskDescriptionLabelProvider(0));
descriptionLabelProvider.setProviders(colorProvider);
description.setLabelProvider(descriptionLabelProvider);
description.setEditingSupport(new ReadOnlyEditingSupport(tree, descriptionLabelProvider));
layout.setColumnData(description.getColumn(), new ColumnWeightData(4));
// number of tasks
TreeViewerColumn number = new TreeViewerColumn(tree, SWT.RIGHT);
// $NON-NLS-1$
number.getColumn().setText("#");
number.getColumn().setToolTipText(Messages.TaskTreeView_NumberText);
TreeColumnViewerLabelProvider numberLabelProvider = new TreeColumnViewerLabelProvider(new TaskCountLabelProvider(0));
numberLabelProvider.setProviders(colorProvider);
number.setLabelProvider(numberLabelProvider);
layout.setColumnData(number.getColumn(), new ColumnWeightData(0, 48));
// user data: status
TreeViewerColumn status = new TreeViewerColumn(tree, SWT.LEFT);
status.getColumn().setText(Messages.TaskTreeView_StatusText);
TreeColumnViewerLabelProvider statusLabelProvider = new TreeColumnViewerLabelProvider(new TaskStatusLabelProvider(0));
statusLabelProvider.setProviders(colorProvider);
status.setLabelProvider(statusLabelProvider);
layout.setColumnData(status.getColumn(), new ColumnWeightData(1));
status.setEditingSupport(new TaskStatusEditingSupport(tree, taskService));
// user data: comment
// TreeViewerColumn comment = new TreeViewerColumn(tree, SWT.LEFT);
// comment.getColumn().setText(Messages.TaskTreeView_CommentText);
// TreeColumnViewerLabelProvider commentLabelProvider = new TreeColumnViewerLabelProvider(
// new TaskCommentLabelProvider(0));
// commentLabelProvider.setProviders(colorProvider);
// comment.setLabelProvider(commentLabelProvider);
// layout.setColumnData(comment.getColumn(), new ColumnWeightData(4));
// comment.setEditingSupport(new TaskCommentEditingSupport(tree, taskService));
// listeners
taskService.addListener(taskListener = new TaskServiceAdapter() {
@Override
public void tasksRemoved(final Iterable<Task<?>> tasks) {
if (Display.getCurrent() != null) {
removeTasks(tasks);
} else {
final Display display = PlatformUI.getWorkbench().getDisplay();
display.syncExec(new Runnable() {
@Override
public void run() {
removeTasks(tasks);
}
});
}
}
@Override
public void tasksAdded(final Iterable<Task<?>> tasks) {
if (Display.getCurrent() != null) {
addTasks(tasks);
} else {
final Display display = PlatformUI.getWorkbench().getDisplay();
display.syncExec(new Runnable() {
@Override
public void run() {
addTasks(tasks);
}
});
}
}
@Override
public void taskUserDataChanged(final ResolvedTask<?> task) {
if (Display.getCurrent() != null) {
updateNode(task);
} else {
final Display display = PlatformUI.getWorkbench().getDisplay();
display.syncExec(new Runnable() {
@Override
public void run() {
updateNode(task);
}
});
}
}
});
getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (!(part instanceof PropertiesViewPart)) {
// selections
return;
}
if (part != TaskTreeView.this) {
update(selection);
}
}
});
createInput();
configureActions();
// interaction
tree.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
ISelection selection = event.getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
Object selected = ((IStructuredSelection) selection).getFirstElement();
if (selected instanceof TreeNode) {
// determine value
Object tmp = ((TreeNode) selected).getValue();
Object value;
if (tmp.getClass().isArray()) {
value = ((Object[]) tmp)[0];
} else {
value = tmp;
}
if (value instanceof Task) {
// node is task node
Task<?> task = (Task<?>) value;
onDoubleClick(task.getMainContext());
} else if (value instanceof Cell) {
onDoubleClick(value);
}
}
}
}
});
}
use of org.eclipse.jface.viewers.TreeNode in project hale by halestudio.
the class TaskTreeView method addTask.
/**
* Add a resolved task
*
* @param task the task to add
*/
@SuppressWarnings("unchecked")
private <C> void addTask(ResolvedTask<C> task) {
// add task to model
MapTreeNode<ResolvedTask<C>, TreeNode> parent = (MapTreeNode<ResolvedTask<C>, TreeNode>) getParentNode(task, true);
if (parent != null) {
DefaultTreeNode node = new DefaultTreeNode(task);
parent.addChild(task, node);
taskNodes.put(task.getTask(), node);
// update viewer
tree.refresh(parent, true);
// update icons
TreeNode updateNode = parent.getParent();
while (updateNode != null) {
tree.update(updateNode, null);
updateNode = updateNode.getParent();
}
}
}
use of org.eclipse.jface.viewers.TreeNode in project xtext-eclipse by eclipse.
the class OutlinePage method showBusyStatus.
/**
* @since 2.8
*/
protected void showBusyStatus() {
TreeViewer treeViewer = getTreeViewer();
treeViewer.setLabelProvider(busyLabelProvider);
treeViewer.setContentProvider(new TreeNodeContentProvider());
treeViewer.setInput(new TreeNode[] { new TreeNode("Loading...") });
}
use of org.eclipse.jface.viewers.TreeNode in project pmd-eclipse-plugin by pmd.
the class CPDView 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) {
// iterate the matches
for (int count = 0; matches.hasNext() && count < MAX_MATCHES; count++) {
Match match = matches.next();
// create a treenode for the match and add to the list
// NOPMD by Sven on 02.11.06 11:27
TreeNode matchNode = new TreeNode(match);
elements.add(matchNode);
// create the children of the match
// NOPMD by Sven on 02.11.06 11:28
TreeNode[] children = new TreeNode[match.getMarkCount()];
Iterator<Mark> entryIterator = match.getMarkSet().iterator();
for (int j = 0; entryIterator.hasNext(); j++) {
final Mark entry = entryIterator.next();
// NOPMD by Sven on 02.11.06 11:28
children[j] = new TreeNode(entry);
children[j].setParent(matchNode);
}
matchNode.setChildren(children);
}
}
// set the children of the rootnode: the matches
treeViewer.setInput(elements.toArray(new TreeNode[elements.size()]));
}
Aggregations