use of eu.esdihumboldt.hale.ui.filter.extension.FilterDialogDefinition in project hale by halestudio.
the class AddConditionContextContribution method fill.
@Override
public void fill(Menu menu, int index) {
ISelection selection = getSelection();
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof EntityDefinition) {
/*
* Determine available filters and filter UI for current
* compatibility mode.
*/
// get all filters supported by the compatibility mode
CompatibilityService cs = PlatformUI.getWorkbench().getService(CompatibilityService.class);
Set<String> supportedFilters = cs.getCurrentDefinition().getSupportedFilters();
// get filter dialog definitions for those filters
Map<String, FilterDialogDefinition> definitions = new HashMap<>();
for (String filterId : supportedFilters) {
FilterDialogDefinition def = FilterUIExtension.getInstance().getFactory(filterId);
if (def != null) {
definitions.put(filterId, def);
}
}
if (definitions.isEmpty()) {
return;
}
// basics for dialog configuration
EntityDefinition entityDef = (EntityDefinition) element;
String title;
if (entityDef.getPropertyPath().isEmpty())
title = "Type condition";
else
title = "Property condition";
String message = "Define the condition for the new context";
// add items for each filter type
for (Entry<String, FilterDialogDefinition> entry : definitions.entrySet()) {
IAction action = new AddConditionAction(entry.getKey(), entry.getValue(), entityDef, title, message);
IContributionItem item = new ActionContributionItem(action);
item.fill(menu, index++);
}
}
}
}
use of eu.esdihumboldt.hale.ui.filter.extension.FilterDialogDefinition 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