use of org.eclipse.jface.viewers.TreeColumnViewerLabelProvider in project hale by halestudio.
the class DefinitionInstanceTreeViewer method setInput.
/**
* @see InstanceViewer#setInput(TypeDefinition, Iterable)
*/
@Override
public void setInput(TypeDefinition type, Iterable<Instance> instances) {
// remove old columns
TreeColumn[] columns = treeViewer.getTree().getColumns();
if (columns != null) {
for (TreeColumn column : columns) {
column.dispose();
}
labelProviders.clear();
}
// set input
if (type != null) {
// pass metadatas to the treeviewer, if instances contain metadatas
Set<String> completeMetaNames = new HashSet<String>();
for (Instance inst : instances) {
for (String name : inst.getMetaDataNames()) {
completeMetaNames.add(name);
}
}
Pair<TypeDefinition, Set<String>> pair = new Pair<TypeDefinition, Set<String>>(type, completeMetaNames);
treeViewer.setInput(pair);
} else
treeViewer.setInput(Collections.emptySet());
Layout layout = treeViewer.getTree().getParent().getLayout();
// add type column
if (type != null) {
TreeViewerColumn column = new TreeViewerColumn(treeViewer, SWT.LEFT);
column.getColumn().setText(type.getDisplayName());
column.setLabelProvider(new TreeColumnViewerLabelProvider(new DefinitionMetaCompareLabelProvider(treeViewer)));
if (layout instanceof TreeColumnLayout) {
((TreeColumnLayout) layout).setColumnData(column.getColumn(), new ColumnWeightData(1));
}
}
// add columns for features
int index = 1;
if (instances != null) {
// // sort features
// List<Feature> sortedFeatures = new ArrayList<Feature>();
// for (Feature f : features) {
// sortedFeatures.add(f);
// }
// Collections.sort(sortedFeatures, new Comparator<Feature>() {
//
// @Override
// public int compare(Feature o1, Feature o2) {
// FeatureId id1 = FeatureBuilder.getSourceID(o1);
// if (id1 == null) {
// id1 = o1.getIdentifier();
// }
//
// FeatureId id2 = FeatureBuilder.getSourceID(o2);
// if (id2 == null) {
// id2 = o2.getIdentifier();
// }
//
// return id1.getID().compareTo(id2.getID());
// }
//
// });
List<Instance> insts = new ArrayList<Instance>();
for (Instance instance : instances) {
// sortedFeatures) {
final TreeViewerColumn column = new TreeViewerColumn(treeViewer, SWT.LEFT);
// FeatureId id = FeatureBuilder.getSourceID(feature);
// if (id == null) {
// id = feature.getIdentifier();
// }
// column.getColumn().setText(id.toString());
// XXX
column.getColumn().setText(String.valueOf(index));
// identifier?
DefinitionInstanceLabelProvider labelProvider = new DefinitionInstanceLabelProvider(instance);
labelProviders.put(index, labelProvider);
column.setLabelProvider(labelProvider);
if (layout instanceof TreeColumnLayout) {
((TreeColumnLayout) layout).setColumnData(column.getColumn(), new ColumnWeightData(1));
}
// add tool tip
// new ColumnBrowserTip(treeViewer, 400, 300, true, index, null);
insts.add(instance);
index++;
}
((MetadataCompareActionProvider) maep).setInput(insts, labelProviders);
}
treeViewer.refresh();
treeViewer.getTree().getParent().layout(true, true);
selectionProvider.updateSelection(instances);
// auto-expand attributes/metadata
treeViewer.expandToLevel(2);
}
use of org.eclipse.jface.viewers.TreeColumnViewerLabelProvider in project hale by halestudio.
the class InstanceExplorer method createControls.
/**
* @see InstanceViewer#createControls(Composite, SchemaSpaceID)
*/
@Override
public void createControls(Composite parent, SchemaSpaceID schemaSpace) {
main = new Composite(parent, SWT.NONE);
main.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create());
// selector composite
selectorComposite = new Composite(main, SWT.NONE);
selectorComposite.setLayoutData(GridDataFactory.swtDefaults().create());
selectorComposite.setLayout(GridLayoutFactory.fillDefaults().create());
// viewer composite
Composite viewerComposite = new Composite(main, SWT.NONE);
viewerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
TreeColumnLayout layout = new TreeColumnLayout();
viewerComposite.setLayout(layout);
viewer = new TreeViewer(viewerComposite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
viewer.getTree().setLinesVisible(true);
// set content provider
viewer.setContentProvider(new InstanceContentProvider());
viewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
// TODO set label provider?
// add definition columns
TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.LEFT);
column.getColumn().setText("Definition");
column.setLabelProvider(new TreeColumnViewerLabelProvider(new PairLabelProvider(true, new DefinitionMetaLabelProvider(viewer, false, true))));
layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
// add value column
column = new TreeViewerColumn(viewer, SWT.LEFT);
column.getColumn().setText("Value");
final InstanceValueLabelProvider instanceLabelProvider = new InstanceValueLabelProvider();
column.setLabelProvider(instanceLabelProvider);
// new PairLabelProvider(false, new LabelProvider())));
ColumnViewerToolTipSupport.enableFor(viewer);
layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
MetadataActionProvider maep = new MetadataExploreActionProvider(viewer);
maep.setup();
// Add an editor for copying instance values
editor = new TreeEditor(viewer.getTree());
editor.horizontalAlignment = SWT.RIGHT;
viewer.getTree().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
final ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
// Selected cell changed?
if (cell == null || editor.getItem() != cell.getItem() || editor.getColumn() != cell.getColumnIndex()) {
// Clean up any previous editor control
Control oldEditor = editor.getEditor();
if (oldEditor != null) {
oldEditor.dispose();
editor.setEditor(null, null, 0);
}
}
// No valid selected cell
if (cell == null || cell.getColumnIndex() == 0) {
return;
}
// cell didn't change
if ((editor.getItem() == cell.getItem() && editor.getColumn() == cell.getColumnIndex())) {
return;
}
// determine instance value
Object value = ((Pair<?, ?>) cell.getViewerRow().getTreePath().getLastSegment()).getSecond();
if (value instanceof Instance) {
value = ((Instance) value).getValue();
}
// copy button
if (value != null) {
final String textValue = value.toString();
if (!textValue.isEmpty()) {
// empty string invalid for
// clipboard
Button button = new Button(viewer.getTree(), SWT.PUSH | SWT.FLAT);
button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
button.setToolTipText("Copy string value");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// copy content to clipboard
Clipboard clipBoard = new Clipboard(Display.getCurrent());
clipBoard.setContents(new Object[] { textValue }, new Transfer[] { TextTransfer.getInstance() });
clipBoard.dispose();
}
});
// calculate editor size
Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
editor.minimumHeight = size.y;
editor.minimumWidth = size.x;
editor.setEditor(button, (TreeItem) cell.getItem(), cell.getColumnIndex());
}
}
}
});
update();
}
use of org.eclipse.jface.viewers.TreeColumnViewerLabelProvider in project hale by halestudio.
the class ReportList method createViewControl.
/**
* Create contents of the view part.
*
* @param parent parent element
*/
@Override
public void createViewControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
TreeColumnLayout layout = new TreeColumnLayout();
composite.setLayout(layout);
{
_treeViewer = new TreeViewer(composite, SWT.BORDER);
final Tree tree = _treeViewer.getTree();
tree.setHeaderVisible(false);
tree.setLinesVisible(false);
// create column for reports
TreeViewerColumn col1 = new TreeViewerColumn(_treeViewer, SWT.NONE);
// add the label provider
col1.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelProvider()));
// and layout
layout.setColumnData(col1.getColumn(), new ColumnWeightData(3));
// create column for reports
TreeViewerColumn col2 = new TreeViewerColumn(_treeViewer, SWT.NONE);
// add the label provider
col2.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelDateProvider()));
// create column for reports
layout.setColumnData(col2.getColumn(), new ColumnWeightData(1));
new ReportListMenu(getSite(), _treeViewer);
}
createActions();
initializeToolBar();
initializeMenu();
// set label provider
// _treeViewer.setLabelProvider(new ReportListLabelProvider());
// set content provider
_treeViewer.setContentProvider(new ReportListContentProvider());
// disable this if it uses too much memory
// but should maintain the list much faster
_treeViewer.setUseHashlookup(true);
// order the sessions from latest to oldest
_treeViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 instanceof ReportSession && e2 instanceof ReportSession) {
long first = ((ReportSession) e1).getId();
long second = ((ReportSession) e2).getId();
if (first > second) {
return -1;
} else if (first < second) {
return 1;
} else {
return 0;
}
} else if (e1 instanceof Report<?> && e2 instanceof Report<?>) {
Report<?> first = (Report<?>) e1;
Report<?> second = (Report<?>) e2;
if (first.getStartTime() == null && second.getStartTime() == null) {
return 0;
} else if (first.getStartTime() == null) {
return 1;
} else if (second.getStartTime() == null) {
return -1;
} else if (first.getStartTime().getTime() > second.getStartTime().getTime()) {
return -1;
} else if (first.getStartTime().getTime() < second.getStartTime().getTime()) {
return 1;
} else {
return 0;
}
}
return 0;
}
});
// set selection provider
getSite().setSelectionProvider(_treeViewer);
_treeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
OpenPropertiesHandler.unpinAndOpenPropertiesView(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
}
});
// load all added reports
this.loadReports();
}
use of org.eclipse.jface.viewers.TreeColumnViewerLabelProvider 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);
}
}
}
}
});
}
Aggregations