use of eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator in project hale by halestudio.
the class MergeParameterPage method createContent.
@Override
protected void createContent(Composite page) {
// set layout of page
page.setLayout(new GridLayout());
Label name = new Label(page, SWT.NONE);
name.setText(parameter.getDisplayName());
// create checkbox tree viewer
viewer = new CheckboxTreeViewer(page, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
viewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
// comparator
viewer.setComparator(new DefinitionComparator());
// label provider
viewer.setLabelProvider(labelProvider);
// content provider
viewer.setContentProvider(new PropertyPathContentProvider(SchemaSpaceID.SOURCE));
// check state listener
viewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
// add/remove it from/to set of selected properties
EntityDefinition eventSource = (EntityDefinition) event.getElement();
if (event.getChecked())
selection.add(eventSource);
else
selection.remove(eventSource);
}
});
// for now filter everything after first level
viewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return parentElement == sourceType;
}
});
if (parameter.getName().equals(PARAMETER_ADDITIONAL_PROPERTY))
viewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return !filtered.contains(element);
}
});
Cell unfinishedCell = getWizard().getUnfinishedCell();
if (unfinishedCell.getSource() != null) {
sourceType = (TypeDefinition) unfinishedCell.getSource().values().iterator().next().getDefinition().getDefinition();
}
viewer.setInput(sourceType);
// add initial selection
if (sourceType != null && initialSelection != null) {
for (String propertyPath : initialSelection) {
EntityDefinition entity = getEntityDefinition(propertyPath, sourceType);
if (entity != null) {
selection.add(entity);
} else {
log.warn("Could not find child for property path " + propertyPath);
}
}
viewer.setCheckedElements(selection.toArray());
}
}
use of eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator in project hale by halestudio.
the class DefinitionInstanceTreeViewer method createControls.
/**
* @see InstanceViewer#createControls(Composite, SchemaSpaceID)
*/
@Override
public void createControls(final Composite parent, SchemaSpaceID schemaSpace) {
main = new Composite(parent, SWT.NONE);
main.setLayout(new TreeColumnLayout());
treeViewer = new TreeViewer(main, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
treeViewer.setContentProvider(new TypeMetaPairContentProvider(treeViewer, schemaSpace));
treeViewer.setLabelProvider(new DefinitionMetaCompareLabelProvider(treeViewer));
// Add an editor for selecting specific paths.
editor = new TreeEditor(treeViewer.getTree());
editor.horizontalAlignment = SWT.RIGHT;
treeViewer.getTree().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
final ViewerCell cell = treeViewer.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;
}
Composite editorControl = new Composite(treeViewer.getTree(), SWT.NONE);
GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).numColumns(2).applyTo(editorControl);
boolean hideCopy = false;
// multi value selector
// Quote the format first. Pattern.quote does the same, except,
// that it checks the input for \Es.
// Since we know that there will be no \Es in this case
// do it ourselves to be safe from changes to Pattern.quote.
String pattern = "\\Q" + DefinitionInstanceLabelProvider.MULTIPLE_VALUE_FORMAT + "\\E$";
pattern = pattern.replace("{0}", "\\E(\\d+)\\Q").replace("{1}", "\\E(\\d+)\\Q");
Matcher m = Pattern.compile(pattern).matcher(cell.getText());
if (m.find()) {
// multi value element
int current = Integer.parseInt(m.group(1));
int total = Integer.parseInt(m.group(2));
// Create the selection control.
ComboViewer combo = new ComboViewer(editorControl);
Integer[] values = new Integer[total];
for (int i = 1; i <= total; i++) values[i - 1] = i;
combo.setContentProvider(ArrayContentProvider.getInstance());
combo.setInput(values);
combo.setSelection(new StructuredSelection(current));
combo.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof IStructuredSelection) {
// Update label provider and refresh viewer.
labelProviders.get(cell.getColumnIndex()).selectPath(cell.getViewerRow().getTreePath(), (Integer) (((IStructuredSelection) event.getSelection()).getFirstElement()));
treeViewer.refresh(cell.getElement(), true);
}
}
});
} else {
/*
* only one value - so we can safely determine if the copy
* button should be shown
*/
Object value = labelProviders.get(cell.getColumnIndex()).findInstanceEntry(cell.getViewerRow().getTreePath()).getValue();
if (value instanceof Instance) {
value = ((Instance) value).getValue();
}
hideCopy = value == null || value.toString().isEmpty();
}
// copy button
if (!hideCopy) {
Button button = new Button(editorControl, 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) {
// determine text value
Object value = labelProviders.get(cell.getColumnIndex()).findInstanceEntry(cell.getViewerRow().getTreePath()).getValue();
if (value instanceof Instance) {
value = ((Instance) value).getValue();
}
if (value != null) {
final String textValue = value.toString();
if (!textValue.isEmpty()) {
// empty string is
// invalid
// 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 = editorControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
editor.minimumHeight = size.y;
editor.minimumWidth = size.x;
editor.setEditor(editorControl, (TreeItem) cell.getItem(), cell.getColumnIndex());
}
});
maep = new MetadataCompareActionProvider(treeViewer);
maep.setup();
treeViewer.setComparator(new DefinitionComparator());
treeViewer.getTree().setHeaderVisible(true);
treeViewer.getTree().setLinesVisible(true);
ColumnViewerToolTipSupport.enableFor(treeViewer);
setInput(null, null);
}
use of eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator in project hale by halestudio.
the class TypeHierarchyView method createViewControl.
/**
* @see eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart#createViewControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createViewControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setContentProvider(new TypeHierarchyContentProvider());
viewer.setLabelProvider(new TypeHierarchyLabelProvider(viewer));
viewer.setComparator(new DefinitionComparator());
contributeToActionBars();
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
update(event.getSelection());
}
});
getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (!(part instanceof PropertiesViewPart)) {
// selections
return;
}
if (part != TypeHierarchyView.this) {
update(selection);
}
}
});
getSite().setSelectionProvider(selectionProvider = new SelectionFilter(viewer) {
@Override
protected ISelection filter(ISelection selection) {
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
List<Object> elements = new ArrayList<Object>();
for (Object element : ((IStructuredSelection) selection).toList()) {
if (element instanceof ParentPath) {
// add parent path head instead of parent path
elements.add(((ParentPath) element).getHead());
} else {
elements.add(element);
}
}
return new StructuredSelection(elements);
} else {
return selection;
}
}
});
new ViewerMenu(getSite(), viewer);
}
use of eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator in project hale by halestudio.
the class EntityDialog method createViewer.
/**
* @see AbstractViewerSelectionDialog#createViewer(Composite)
*/
@Override
protected TreeViewer createViewer(Composite parent) {
// create viewer
SchemaPatternFilter patternFilter = new SchemaPatternFilter() {
@Override
protected boolean matches(Viewer viewer, Object element) {
boolean superMatches = super.matches(viewer, element);
if (!superMatches)
return false;
return acceptObject(viewer, getFilters(), ((TreePath) element).getLastSegment());
}
};
patternFilter.setUseEarlyReturnIfMatcherIsNull(false);
patternFilter.setIncludeLeadingWildcard(true);
FilteredTree tree = new TreePathFilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
tree.getViewer().setComparator(new DefinitionComparator());
// create context menu
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(this);
Menu targetMenu = menuManager.createContextMenu(tree.getViewer().getControl());
tree.getViewer().getControl().setMenu(targetMenu);
if (SchemaSpaceID.SOURCE.equals(ssid)) {
// condition contexts only supported for source schema
// ensure viewer is updated on context changes
final EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
eds.addListener(entityDefinitionListener = new EntityDefinitionServiceListener() {
@Override
public void contextsAdded(Iterable<EntityDefinition> contextEntities) {
getViewer().refresh();
}
@Override
public void contextRemoved(EntityDefinition contextEntity) {
getViewer().refresh();
}
@Override
public void contextAdded(EntityDefinition contextEntity) {
getViewer().refresh();
}
});
// remove listener from entity def service
tree.getViewer().getControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (entityDefinitionListener != null) {
eds.removeListener(entityDefinitionListener);
}
}
});
}
return tree.getViewer();
}
Aggregations