use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class TypeStyleHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// collect types and associated data sets
SetMultimap<DataSet, TypeDefinition> types = collectTypesFromSelection(event);
Pair<TypeDefinition, DataSet> typeInfo = null;
// select a type
if (types.size() == 1) {
Entry<DataSet, TypeDefinition> entry = types.entries().iterator().next();
typeInfo = new Pair<TypeDefinition, DataSet>(entry.getValue(), entry.getKey());
} else if (!types.isEmpty()) {
// choose through dialog
DataSetTypeSelectionDialog dialog = new DataSetTypeSelectionDialog(Display.getCurrent().getActiveShell(), "Multiple types: select which to change the style for", null, types);
if (dialog.open() == DataSetTypeSelectionDialog.OK) {
typeInfo = dialog.getObject();
}
}
if (typeInfo != null) {
try {
FeatureStyleDialog dialog = new FeatureStyleDialog(typeInfo.getFirst(), typeInfo.getSecond());
dialog.setBlockOnOpen(false);
dialog.open();
} catch (Exception e) {
throw new ExecutionException("Could not open style dialog", e);
}
}
return null;
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class TypeStyleHandler method collectTypesFromSelection.
/**
* Collect all type definitions and data sets from the current selection of
* {@link TypeDefinition}s, {@link EntityDefinition}s, {@link Instance}s and
* {@link InstanceReference}s.
*
* @param event the handler execution event
* @return the collected type definitions
*/
public static SetMultimap<DataSet, TypeDefinition> collectTypesFromSelection(ExecutionEvent event) {
SetMultimap<DataSet, TypeDefinition> types = HashMultimap.create();
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
for (Object object : ((IStructuredSelection) selection).toArray()) {
if (object instanceof TypeDefinition) {
TypeDefinition type = (TypeDefinition) object;
if (!types.containsValue(type)) {
DataSet dataSet = findDataSet(type);
types.put(dataSet, type);
}
}
if (object instanceof EntityDefinition) {
EntityDefinition entityDef = (EntityDefinition) object;
if (entityDef.getPropertyPath().isEmpty()) {
DataSet dataSet = (entityDef.getSchemaSpace() == SchemaSpaceID.SOURCE) ? (DataSet.SOURCE) : (DataSet.TRANSFORMED);
types.put(dataSet, entityDef.getType());
}
}
if (object instanceof InstanceReference) {
InstanceService is = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().getService(InstanceService.class);
object = is.getInstance((InstanceReference) object);
}
if (object instanceof Instance) {
Instance instance = (Instance) object;
types.put(instance.getDataSet(), instance.getDefinition());
}
}
}
return types;
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class StyleServiceImpl method getStyle.
private Style getStyle(final DataSet dataset, boolean selected) {
SchemaSpace schemas = schemaService.getSchemas((dataset == DataSet.SOURCE) ? (SchemaSpaceID.SOURCE) : (SchemaSpaceID.TARGET));
Style style = styleFactory.createStyle();
for (TypeDefinition type : schemas.getMappingRelevantTypes()) {
if (!type.getConstraint(AbstractFlag.class).isEnabled()) {
// only add styles for non-abstract feature types
FeatureTypeStyle fts = styles.get(type);
if (fts == null) {
if (fbStyle != null) {
fts = fbStyle;
} else {
fts = StyleHelper.getDefaultStyle(type, dataset);
}
}
if (selected) {
fts = getSelectedStyle(fts);
}
style.featureTypeStyles().add(fts);
}
}
return style;
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class StyleServiceImpl method addStyles.
/**
* @see StyleService#addStyles(Style[])
*/
@Override
public void addStyles(Style... styles) {
boolean somethingHappened = false;
for (Style style : styles) {
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
if (!fts.featureTypeNames().isEmpty() && fts.featureTypeNames().iterator().next().getLocalPart().equals("Feature")) {
this.fbStyle = fts;
somethingHappened = true;
} else {
Collection<TypeDefinition> types = findTypes(fts.featureTypeNames());
if (types != null && !types.isEmpty()) {
for (TypeDefinition type : types) {
if (addStyle(type, fts)) {
somethingHappened = true;
}
}
} else {
/*
* store for later schema update when feature type might
* be present
*/
queuedStyles.add(fts);
}
}
}
}
if (somethingHappened) {
notifyStylesAdded();
}
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class MarkTypeUnmappableHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
SchemaService schemaService = PlatformUI.getWorkbench().getService(SchemaService.class);
Iterator<?> it = ((IStructuredSelection) selection).iterator();
List<TypeDefinition> sourceTypes = new ArrayList<>();
List<TypeDefinition> targetTypes = new ArrayList<>();
while (it.hasNext()) {
Object selected = it.next();
TypeDefinition type = null;
if (selected instanceof TypeEntityDefinition) {
type = ((TypeEntityDefinition) selected).getDefinition();
} else if (selected instanceof TypeDefinition) {
type = (TypeDefinition) selected;
}
if (type != null) {
if (schemaService.getSchemas(SchemaSpaceID.SOURCE).getMappingRelevantTypes().contains(type)) {
sourceTypes.add(type);
} else {
targetTypes.add(type);
}
}
}
if (!sourceTypes.isEmpty()) {
schemaService.toggleMappable(SchemaSpaceID.SOURCE, sourceTypes);
}
if (!targetTypes.isEmpty()) {
schemaService.toggleMappable(SchemaSpaceID.TARGET, targetTypes);
}
}
return null;
}
Aggregations