use of eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService 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.ui.service.entity.EntityDefinitionService in project hale by halestudio.
the class PropertyEntityDialog method setupViewer.
/**
* @see EntityDialog#setupViewer(TreeViewer, EntityDefinition)
*/
@Override
protected void setupViewer(TreeViewer viewer, EntityDefinition initialSelection) {
viewer.setLabelProvider(new StyledDefinitionLabelProvider(viewer));
EntityDefinitionService entityDefinitionService = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
if (parentType != null) {
viewer.setContentProvider(new TreePathProviderAdapter(new EntityTypePropertyContentProvider(entityDefinitionService, ssid)));
viewer.setInput(parentType);
} else {
flatRelevantProvider = new TreePathProviderAdapter(new EntityTypeIndexContentProvider(entityDefinitionService, ssid, true, false));
hierarchicalRelevantProvider = new TreePathProviderAdapter(new EntityTypeIndexHierarchy(entityDefinitionService, ssid, true, false));
flatAllProvider = new TreePathProviderAdapter(new EntityTypeIndexContentProvider(entityDefinitionService, ssid, false, false));
hierarchicalAllProvider = new TreePathProviderAdapter(new EntityTypeIndexHierarchy(entityDefinitionService, ssid, false, false));
viewer.setContentProvider(flatRelevantProvider);
SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
viewer.setInput(ss.getSchemas(ssid));
}
if (initialSelection != null) {
viewer.setSelection(new StructuredSelection(initialSelection));
}
}
use of eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService in project hale by halestudio.
the class TypeEntityDialog method setupViewer.
/**
* @see EntityDialog#setupViewer(TreeViewer, EntityDefinition)
*/
@Override
protected void setupViewer(TreeViewer viewer, EntityDefinition initialSelection) {
viewer.setLabelProvider(new StyledDefinitionLabelProvider(viewer));
EntityDefinitionService entityDefinitionService = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
flatRelevantProvider = new TreePathProviderAdapter(new EntityTypeIndexContentProvider(entityDefinitionService, ssid, true, true));
if (!onlyMappingRelevant) {
hierarchicalRelevantProvider = new TreePathProviderAdapter(new EntityTypeIndexHierarchy(entityDefinitionService, ssid, true, true));
flatAllProvider = new TreePathProviderAdapter(new EntityTypeIndexContentProvider(entityDefinitionService, ssid, false, true));
hierarchicalAllProvider = new TreePathProviderAdapter(new EntityTypeIndexHierarchy(entityDefinitionService, ssid, false, true));
viewer.setContentProvider(flatAllProvider);
} else {
viewer.setContentProvider(flatRelevantProvider);
}
SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
viewer.setInput(ss.getSchemas(ssid));
if (initialSelection instanceof TypeEntityDefinition) {
viewer.setSelection(new StructuredSelection(initialSelection));
}
}
use of eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService in project hale by halestudio.
the class AddNamedContextHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof EntityDefinition) {
EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
eds.addNamedContext((EntityDefinition) element);
}
}
return null;
}
use of eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService in project hale by halestudio.
the class EditConditionContextHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof EntityDefinition) {
EntityDefinition entityDef = (EntityDefinition) element;
String title;
if (entityDef.getPropertyPath().isEmpty())
title = "Edit type condition";
else
title = "Edit property condition";
Condition condition = AlignmentUtil.getContextCondition(entityDef);
if (condition != null && condition.getFilter() != null) {
Pair<String, String> filterDef = FilterDefinitionManager.getInstance().asPair(condition.getFilter());
if (filterDef != null && filterDef.getFirst() != null) {
String filterId = filterDef.getFirst();
// retrieve filter UI from extension point
FilterDialogDefinition def = FilterUIExtension.getInstance().getFactory(filterId);
if (def != null) {
Filter filter = null;
try {
filter = def.createExtensionObject().openDialog(HandlerUtil.getActiveShell(event), entityDef, title, "Define the condition for the new context");
} catch (Exception e) {
log.userError("Failed to create editor for filter", e);
}
if (filter != null) {
EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
eds.editConditionContext((EntityDefinition) element, filter);
}
} else {
log.userError("No editor for this kind of filter available");
}
} else {
log.error("No filter definition for filter found, definition ID could not be determined");
}
}
}
}
return null;
}
Aggregations