use of eu.esdihumboldt.hale.ui.service.schema.SchemaService in project hale by halestudio.
the class SpectrumColorSchemeHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// collect all types
SetMultimap<DataSet, TypeDefinition> types = HashMultimap.create();
SchemaService schemas = PlatformUI.getWorkbench().getService(SchemaService.class);
for (TypeDefinition type : schemas.getSchemas(SchemaSpaceID.SOURCE).getMappingRelevantTypes()) {
types.put(DataSet.SOURCE, type);
}
for (TypeDefinition type : schemas.getSchemas(SchemaSpaceID.TARGET).getMappingRelevantTypes()) {
types.put(DataSet.TRANSFORMED, type);
}
Style style = StyleHelper.getSpectrumStyles(types);
StyleService styleService = PlatformUI.getWorkbench().getService(StyleService.class);
styleService.addStyles(style);
return null;
}
use of eu.esdihumboldt.hale.ui.service.schema.SchemaService 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;
}
use of eu.esdihumboldt.hale.ui.service.schema.SchemaService in project hale by halestudio.
the class TransformDataExportAdvisor method prepareProvider.
/**
* @see IOAdvisor#prepareProvider(IOProvider)
*/
@Override
public void prepareProvider(InstanceWriter provider) {
super.prepareProvider(provider);
// set target schema
SchemaService ss = getService(SchemaService.class);
provider.setTargetSchema(ss.getSchemas(SchemaSpaceID.TARGET));
// set instances to export
provider.setInstances(instances);
}
use of eu.esdihumboldt.hale.ui.service.schema.SchemaService in project hale by halestudio.
the class InstanceValidationReportDetailsContentProvider method inputChanged.
/**
* @see ITreePathContentProvider#inputChanged(Viewer, Object, Object)
*/
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
childCache.clear();
messages.clear();
limitedPaths.clear();
if (newInput instanceof Collection<?>) {
SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
TreePath emptyPath = new TreePath(new Object[0]);
for (Object o : (Collection<?>) newInput) {
if (o instanceof InstanceValidationMessage) {
InstanceValidationMessage message = ((InstanceValidationMessage) o);
Set<Object> baseTypes = childCache.get(emptyPath);
if (baseTypes == null) {
baseTypes = new HashSet<Object>();
childCache.put(emptyPath, baseTypes);
}
// XXX maybe expand messages with SSID?
TypeDefinition typeDef = null;
if (message.getType() != null) {
typeDef = ss.getSchemas(SchemaSpaceID.TARGET).getType(message.getType());
}
// use typeDef if available, QName otherwise
Object use = typeDef == null ? message.getType() : typeDef;
if (use == null) {
// fall-back to generic category
use = "General";
}
baseTypes.add(use);
messages.put(new TreePath(new Object[] { use }), message);
}
}
}
}
use of eu.esdihumboldt.hale.ui.service.schema.SchemaService in project hale by halestudio.
the class AbstractTargetAction method run.
@Override
public void run() {
// if Display not the active Thread
if (Display.getCurrent() == null) {
// execute in display thread
PlatformUI.getWorkbench().getDisplay().asyncExec(this);
return;
}
if (params == null || params.isEmpty()) {
return;
}
// retrieve the target schema
SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
SchemaSpace targetSchema = ss.getSchemas(SchemaSpaceID.TARGET);
// find type
QName typeName = QName.valueOf(params.get(0));
TypeDefinition type = targetSchema.getType(typeName);
if (type == null) {
// check all mapping relevant types for local name only
for (TypeDefinition candidate : targetSchema.getMappingRelevantTypes()) {
if (candidate.getName().getLocalPart().equals(params.get(0))) {
// use the first found
type = candidate;
break;
}
}
}
if (type != null) {
EntityDefinition entity = new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null);
if (params.size() > 1) {
// determine property entity
EntityAccessor accessor = new EntityAccessor(entity);
for (int i = 1; i < params.size(); i++) {
QName propertyName = QName.valueOf(params.get(i));
String namespace = propertyName.getNamespaceURI();
if (namespace != null && namespace.isEmpty()) {
// treat empty namespace as ignoring namespace
namespace = null;
}
accessor = accessor.findChildren(propertyName.getLocalPart(), namespace);
}
entity = accessor.toEntityDefinition();
}
if (entity != null) {
run(entity, manager);
} else {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Schema element not found", "The schema element was not found in the target schema, please make sure the correct schema is loaded.");
}
} else {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Schema element not found", MessageFormat.format("The type {0} was not found in the target schema, please make sure the correct schema is loaded.", typeName.getLocalPart()));
}
}
Aggregations