use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class ClassificationFilter method select.
/**
* @see ViewerFilter#select(Viewer, Object, Object)
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof TreePath) {
element = ((TreePath) element).getLastSegment();
}
if (element instanceof EntityDefinition) {
element = ((EntityDefinition) element).getDefinition();
}
if (hidden.isEmpty() || !(element instanceof Definition<?>)) {
// fast exit
return true;
}
Definition<?> def = (Definition<?>) element;
Classification clazz = Classification.getClassification(def);
return !hidden.contains(clazz);
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class SchemaExplorerLabelProvider method getBackground.
/**
* @see IColorProvider#getBackground(Object)
*/
@Override
public Color getBackground(Object element) {
if (element instanceof EntityDefinition) {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
Alignment alignment = as.getAlignment();
EntityDefinition entityDef = (EntityDefinition) element;
return getEntityBackground(entityDef, alignment, entityDef.getPropertyPath().isEmpty());
}
return null;
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class TypeHierarchyView method update.
/**
* Update the hierarchy view with the given selection
*
* @param selection the selection
*/
protected void update(ISelection selection) {
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof ParentPath) {
element = ((ParentPath) element).getHead();
}
if (element instanceof Entity) {
element = ((Entity) element).getDefinition();
}
if (element instanceof EntityDefinition) {
element = ((EntityDefinition) element).getDefinition();
}
viewer.setInput(element);
ParentPath path = TypeHierarchyContentProvider.createPath(element);
viewer.expandAll();
if (path != null) {
viewer.setSelection(new StructuredSelection(path.getMainPath()));
}
} else {
viewer.setInput(null);
}
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition 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();
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class PropertyEntityDialog method getObjectFromSelection.
/**
* @see EntityDialog#getObjectFromSelection(ISelection)
*/
@Override
protected EntityDefinition getObjectFromSelection(ISelection selection) {
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof EntityDefinition) {
return (EntityDefinition) element;
}
}
if (!selection.isEmpty() && selection instanceof ITreeSelection) {
// create property definition w/ default contexts
TreePath path = ((ITreeSelection) selection).getPaths()[0];
// get parent type
TypeDefinition type = ((PropertyDefinition) path.getFirstSegment()).getParentType();
// determine definition path
List<ChildContext> defPath = new ArrayList<ChildContext>();
for (int i = 0; i < path.getSegmentCount(); i++) {
defPath.add(new ChildContext((ChildDefinition<?>) path.getSegment(i)));
}
// TODO check if property entity definition is applicable?
return new PropertyEntityDefinition(type, defPath, ssid, parentType.getFilter());
}
return null;
}
Aggregations