use of eu.esdihumboldt.hale.common.instance.model.DataSet 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.common.instance.model.DataSet in project hale by halestudio.
the class DefinitionImages method getImage.
/**
* Get the image for the given definition
*
* @param entityDef the entity definition, may be <code>null</code>
* @param def the definition
* @return the image, may be <code>null</code>
*/
protected Image getImage(EntityDefinition entityDef, Definition<?> def) {
Classification clazz = Classification.getClassification(def);
String imageName = getImageForClassification(clazz);
// retrieve image for key
Image image;
if (imageName == null) {
// default
imageName = ISharedImages.IMG_OBJ_ELEMENT;
image = PlatformUI.getWorkbench().getSharedImages().getImage(imageName);
} else {
image = CommonSharedImages.getImageRegistry().get(imageName);
}
// XXX not supported yet
if (def instanceof TypeDefinition && !((TypeDefinition) def).getConstraint(AbstractFlag.class).isEnabled() && hasGeometry((TypeDefinition) def)) {
TypeDefinition type = (TypeDefinition) def;
DataSet dataSet = DataSet.SOURCE;
// defined styles
if (entityDef != null) {
dataSet = DataSet.forSchemaSpace(entityDef.getSchemaSpace());
}
String typeKey = dataSet.name() + "::" + type.getIdentifier();
// XXX check if style image is already there?
// XXX how to handle style changes?
BufferedImage img = getLegendImage(type, dataSet, true);
if (img != null) {
// replace image with style image
ImageData imgData = SwingRcpUtilities.convertToSWT(img);
image = new Image(Display.getCurrent(), imgData);
final Image old;
if (styleImages.containsKey(typeKey)) {
old = styleImages.get(typeKey);
} else {
old = null;
}
styleImages.put(typeKey, image);
if (old != null) {
// schedule image to be disposed when there are no
// references to it
handles.addReference(image);
}
}
} else // check for inline attributes
{
boolean attribute = (def instanceof PropertyDefinition) && ((PropertyDefinition) def).getConstraint(XmlAttributeFlag.class).isEnabled();
boolean mandatory = false;
if (!suppressMandatory) {
if (def instanceof PropertyDefinition) {
Cardinality cardinality = ((PropertyDefinition) def).getConstraint(Cardinality.class);
mandatory = cardinality.getMinOccurs() > 0 && !((PropertyDefinition) def).getConstraint(NillableFlag.class).isEnabled();
} else if (def instanceof GroupPropertyDefinition) {
Cardinality cardinality = ((GroupPropertyDefinition) def).getConstraint(Cardinality.class);
mandatory = cardinality.getMinOccurs() > 0;
}
}
boolean deflt = false;
boolean faded = false;
if (entityDef != null) {
// entity definition needed to determine if item is a default
// geometry
deflt = DefaultGeometryUtil.isDefaultGeometry(entityDef);
// and to determine population
PopulationService ps = PlatformUI.getWorkbench().getService(PopulationService.class);
if (ps != null && ps.hasPopulation(entityDef.getSchemaSpace())) {
Population pop = ps.getPopulation(entityDef);
faded = (pop != null && pop.getOverallCount() == 0);
}
}
if (deflt || mandatory || attribute || faded) {
// overlayed image
ImageConf conf = new ImageConf(imageName, attribute, deflt, mandatory, faded);
Image overlayedImage = overlayedImages.get(conf);
if (overlayedImage == null) {
// apply overlays to image
Image copy = new Image(image.getDevice(), image.getBounds());
// draw on image
GC gc = new GC(copy);
try {
gc.drawImage(image, 0, 0);
if (attribute) {
gc.drawImage(attribOverlay, 0, 0);
}
if (deflt) {
gc.drawImage(defOverlay, 0, 0);
}
if (mandatory) {
gc.drawImage(mandatoryOverlay, 0, 0);
}
} finally {
gc.dispose();
}
if (faded) {
ImageData imgData = copy.getImageData();
imgData.alpha = 150;
Image copy2 = new Image(image.getDevice(), imgData);
copy.dispose();
copy = copy2;
}
image = copy;
overlayedImages.put(conf, copy);
} else {
image = overlayedImage;
}
}
}
return image;
}
use of eu.esdihumboldt.hale.common.instance.model.DataSet in project hale by halestudio.
the class DataSetTypeSelectionDialog method setupViewer.
@Override
protected void setupViewer(TreeViewer viewer, Pair<TypeDefinition, DataSet> initialSelection) {
viewer.setLabelProvider(new DefinitionLabelProvider(viewer) {
@Override
public String getText(Object element) {
if (element instanceof DataSet) {
switch((DataSet) element) {
case TRANSFORMED:
return "Transformed";
case SOURCE:
default:
return "Source";
}
}
if (element instanceof Pair) {
element = ((Pair<?, ?>) element).getFirst();
}
return super.getText(element);
}
@Override
public Image getImage(Object element) {
if (element instanceof DataSet) {
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
}
if (element instanceof Pair) {
element = ((Pair<?, ?>) element).getFirst();
}
return super.getImage(element);
}
});
viewer.setContentProvider(new TypeIndexContentProvider(viewer) {
@Override
public Object[] getElements(Object inputElement) {
return types.keySet().toArray();
}
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof DataSet) {
DataSet dataSet = (DataSet) parentElement;
List<Pair<TypeDefinition, DataSet>> typeList = new ArrayList<Pair<TypeDefinition, DataSet>>();
for (TypeDefinition type : types.get(dataSet)) {
typeList.add(new Pair<TypeDefinition, DataSet>(type, dataSet));
}
return typeList.toArray();
}
return new Object[] {};
}
@Override
public boolean hasChildren(Object parentElement) {
return parentElement instanceof DataSet && !types.get((DataSet) parentElement).isEmpty();
}
});
viewer.setAutoExpandLevel(2);
viewer.setInput(types);
if (initialSelection != null) {
viewer.setSelection(new StructuredSelection(initialSelection));
}
}
use of eu.esdihumboldt.hale.common.instance.model.DataSet in project hale by halestudio.
the class StyleHelper method getSpectrumStyles.
/**
* Returns a default style for the given type.
*
* @param dataSetTypes type definitions associated to their data set
* @return the style
*/
public static Style getSpectrumStyles(SetMultimap<DataSet, TypeDefinition> dataSetTypes) {
int defWidth = StylePreferences.getDefaultWidth();
Style style = styleFactory.createStyle();
GeometrySchemaService gss = PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
for (DataSet dataSet : dataSetTypes.keySet()) {
float saturation;
float brightness;
switch(dataSet) {
case TRANSFORMED:
saturation = 0.8f;
brightness = 0.6f;
break;
case SOURCE:
default:
saturation = 0.75f;
brightness = 0.8f;
break;
}
Set<TypeDefinition> types = new HashSet<>(dataSetTypes.get(dataSet));
Iterator<TypeDefinition> it = types.iterator();
while (it.hasNext()) {
TypeDefinition type = it.next();
// remove invalid types
if (type.getConstraint(AbstractFlag.class).isEnabled() || gss.getDefaultGeometry(type) == null) {
it.remove();
}
}
int numberOfTypes = types.size();
int index = 0;
for (TypeDefinition typeDef : types) {
FeatureTypeStyle fts;
// TODO based on default geometry?
// polygon is always OK as it contains stroke and fill
// Color color = generateRandomColor(Color.WHITE);
Color color;
if (numberOfTypes == 1) {
color = generateRandomColor(saturation, brightness);
} else {
color = Color.getHSBColor((float) index / (float) numberOfTypes, saturation, brightness);
}
fts = createPolygonStyle(color, defWidth);
fts.featureTypeNames().add(new NameImpl(getFeatureTypeName(typeDef)));
style.featureTypeStyles().add(fts);
index++;
}
}
return style;
}
use of eu.esdihumboldt.hale.common.instance.model.DataSet 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;
}
Aggregations