use of eu.esdihumboldt.hale.ui.service.instance.InstanceService in project hale by halestudio.
the class ClearInstancesHandler method execute.
/**
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (MessageDialog.openQuestion(HandlerUtil.getActiveShell(event), "Delete source data", "Do you really want to delete all source data?")) {
InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
is.clearInstances();
}
return null;
}
use of eu.esdihumboldt.hale.ui.service.instance.InstanceService in project hale by halestudio.
the class HaleServiceFactory method create.
/**
* @see AbstractServiceFactory#create(Class, IServiceLocator,
* IServiceLocator)
*/
@Override
public Object create(@SuppressWarnings("rawtypes") Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) {
if (AlignmentService.class.equals(serviceInterface)) {
return new AlignmentServiceUndoSupport(new AlignmentServiceImpl(locator.getService(ProjectService.class)));
}
if (CompatibilityService.class.equals(serviceInterface)) {
return new CompatibilityServiceImpl();
}
if (EntityDefinitionService.class.equals(serviceInterface)) {
return new EntityDefinitionServiceUndoSupport(new EntityDefinitionServiceImpl(locator.getService(AlignmentService.class), locator.getService(ProjectService.class)));
}
if (EntityResolver.class.equals(serviceInterface)) {
return new UserFallbackEntityResolver();
}
if (FunctionService.class.equals(serviceInterface)) {
return new HaleFunctionService(locator.getService(AlignmentService.class));
}
if (GeometrySchemaService.class.equals(serviceInterface)) {
return new ProjectGeometrySchemaService(locator.getService(ProjectService.class));
}
if (GroovyService.class.equals(serviceInterface)) {
return new PreferencesGroovyService(locator.getService(ProjectService.class), locator.getService(AlignmentService.class));
}
if (InstanceSampleService.class.equals(serviceInterface)) {
return new InstanceSampleServiceImpl();
}
if (InstanceService.class.equals(serviceInterface)) {
final InstanceService is = OrientInstanceService.getInstance(locator.getService(SchemaService.class), locator.getService(ProjectService.class), locator.getService(AlignmentService.class), locator.getService(GroovyService.class));
// Add a listener to close all InstanceProcessors when source data
// is cleared
// XXX There may a better place to add this listener
is.addListener(new InstanceServiceAdapter() {
@Override
public void datasetChanged(DataSet type) {
if (type != DataSet.SOURCE) {
return;
}
InstanceCollection instances = is.getInstances(type);
if (instances.isEmpty()) {
// data was cleared, close instance
// processors
final InstanceProcessingExtension ext = new InstanceProcessingExtension(HaleUI.getServiceProvider());
for (InstanceProcessor processor : ext.getInstanceProcessors()) {
try {
processor.close();
} catch (IOException e) {
// Ignore
}
}
}
}
});
return is;
}
if (InstanceValidationService.class.equals(serviceInterface))
return new InstanceValidationServiceImpl(locator.getService(InstanceService.class), locator.getService(ReportService.class));
if (InstanceViewService.class.equals(serviceInterface)) {
return new InstanceViewServiceImpl(locator.getService(ProjectService.class));
}
if (OccurringValuesService.class.equals(serviceInterface)) {
return new OccurringValuesServiceImpl(locator.getService(InstanceService.class), locator.getService(ProjectService.class));
}
if (PopulationService.class.equals(serviceInterface)) {
return new PopulationServiceImpl(locator.getService(InstanceService.class));
}
if (ProjectService.class.equals(serviceInterface)) {
return new ProjectServiceImpl();
}
if (ProjectInfoService.class.equals(serviceInterface)) {
return locator.getService(ProjectService.class);
}
if (RecentProjectsService.class.equals(serviceInterface)) {
return new RecentProjectsServiceImpl();
}
if (RecentResources.class.equals(serviceInterface)) {
return new RecentResourcesService(locator.getService(ProjectService.class));
}
if (ReportService.class.equals(serviceInterface)) {
return new ReportServiceImpl();
}
if (SchemaService.class.equals(serviceInterface)) {
return new SchemaServiceImpl(locator.getService(ProjectService.class));
}
if (TaskService.class.equals(serviceInterface)) {
return new TaskServiceImpl();
}
if (TransformationFunctionService.class.equals(serviceInterface)) {
return new HaleTransformationFunctionService(locator.getService(AlignmentService.class));
}
if (TransformationSchemas.class.equals(serviceInterface)) {
return locator.getService(SchemaService.class);
}
return null;
}
use of eu.esdihumboldt.hale.ui.service.instance.InstanceService in project hale by halestudio.
the class InstanceImportAdvisor method handleResults.
/**
* @see IOAdvisor#handleResults(IOProvider)
*/
@Override
public void handleResults(InstanceReader provider) {
// add instances to instance service
InstanceService is = getService(InstanceService.class);
InstanceCollection instances = provider.getInstances();
ResourceIterator<Instance> it = instances.iterator();
try {
if (!it.hasNext()) {
URI loc = provider.getSource().getLocation();
if (loc != null) {
log.warn(MessageFormat.format("No instances could be imported with the given configuration from {0}", loc.toString()));
} else {
log.warn("No instances could be imported with the given configuration.");
}
}
} finally {
it.close();
}
// apply sampling before adding to the instance service
InstanceViewService ivs = PlatformUI.getWorkbench().getService(InstanceViewService.class);
if (ivs != null) {
instances = ivs.sample(instances);
}
is.addSourceInstances(instances);
super.handleResults(provider);
}
use of eu.esdihumboldt.hale.ui.service.instance.InstanceService in project hale by halestudio.
the class SourceInstanceExportAdvisor 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.SOURCE));
// set instances to export
InstanceService is = getService(InstanceService.class);
provider.setInstances(is.getInstances(DataSet.SOURCE));
}
use of eu.esdihumboldt.hale.ui.service.instance.InstanceService 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;
}
Aggregations