Search in sources :

Example 1 with DataSet

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;
}
Also used : UserFallbackEntityResolver(eu.esdihumboldt.hale.ui.service.align.resolver.UserFallbackEntityResolver) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) TaskServiceImpl(eu.esdihumboldt.hale.ui.service.tasks.internal.TaskServiceImpl) CompatibilityServiceImpl(eu.esdihumboldt.hale.ui.compatibility.extension.impl.CompatibilityServiceImpl) EntityDefinitionServiceUndoSupport(eu.esdihumboldt.hale.ui.service.entity.internal.EntityDefinitionServiceUndoSupport) AlignmentServiceUndoSupport(eu.esdihumboldt.hale.ui.service.align.internal.AlignmentServiceUndoSupport) PreferencesGroovyService(eu.esdihumboldt.hale.ui.service.groovy.internal.PreferencesGroovyService) GroovyService(eu.esdihumboldt.util.groovy.sandbox.GroovyService) ProjectServiceImpl(eu.esdihumboldt.hale.ui.service.project.internal.ProjectServiceImpl) InstanceViewServiceImpl(eu.esdihumboldt.hale.ui.service.instance.sample.internal.InstanceViewServiceImpl) PopulationServiceImpl(eu.esdihumboldt.hale.ui.service.population.internal.PopulationServiceImpl) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) InstanceSampleServiceImpl(eu.esdihumboldt.hale.ui.service.instance.sample.internal.InstanceSampleServiceImpl) SchemaServiceImpl(eu.esdihumboldt.hale.ui.service.schema.internal.SchemaServiceImpl) InstanceProcessor(eu.esdihumboldt.hale.common.instance.processing.InstanceProcessor) RecentResourcesService(eu.esdihumboldt.hale.ui.service.project.internal.resources.RecentResourcesService) InstanceServiceAdapter(eu.esdihumboldt.hale.ui.service.instance.InstanceServiceAdapter) PreferencesGroovyService(eu.esdihumboldt.hale.ui.service.groovy.internal.PreferencesGroovyService) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) InstanceValidationServiceImpl(eu.esdihumboldt.hale.ui.service.instance.validation.internal.InstanceValidationServiceImpl) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) IOException(java.io.IOException) ReportServiceImpl(eu.esdihumboldt.hale.ui.service.report.internal.ReportServiceImpl) RecentProjectsServiceImpl(eu.esdihumboldt.hale.ui.service.project.internal.RecentProjectsServiceImpl) EntityDefinitionServiceImpl(eu.esdihumboldt.hale.ui.service.entity.internal.EntityDefinitionServiceImpl) InstanceProcessingExtension(eu.esdihumboldt.hale.common.instance.processing.InstanceProcessingExtension) AlignmentServiceImpl(eu.esdihumboldt.hale.ui.service.align.internal.AlignmentServiceImpl) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) ProjectGeometrySchemaService(eu.esdihumboldt.hale.ui.service.geometry.ProjectGeometrySchemaService) GeometrySchemaService(eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService) OrientInstanceService(eu.esdihumboldt.hale.ui.service.instance.internal.orient.OrientInstanceService) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) OccurringValuesServiceImpl(eu.esdihumboldt.hale.ui.service.values.internal.OccurringValuesServiceImpl) ProjectGeometrySchemaService(eu.esdihumboldt.hale.ui.service.geometry.ProjectGeometrySchemaService)

Example 2 with DataSet

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;
}
Also used : GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) Cardinality(eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) Image(org.eclipse.swt.graphics.Image) BufferedImage(java.awt.image.BufferedImage) GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) BufferedImage(java.awt.image.BufferedImage) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) ImageData(org.eclipse.swt.graphics.ImageData) Classification(eu.esdihumboldt.hale.common.schema.Classification) PopulationService(eu.esdihumboldt.hale.ui.common.service.population.PopulationService) Population(eu.esdihumboldt.hale.ui.common.service.population.Population) GC(org.eclipse.swt.graphics.GC)

Example 3 with DataSet

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));
    }
}
Also used : DefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionLabelProvider) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeIndexContentProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.TypeIndexContentProvider) ArrayList(java.util.ArrayList) List(java.util.List) Image(org.eclipse.swt.graphics.Image) Pair(eu.esdihumboldt.util.Pair) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 4 with DataSet

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;
}
Also used : NameImpl(org.geotools.feature.NameImpl) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) Color(java.awt.Color) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) GeometrySchemaService(eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) HashSet(java.util.HashSet)

Example 5 with DataSet

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;
}
Also used : DataSetTypeSelectionDialog(eu.esdihumboldt.hale.ui.style.DataSetTypeSelectionDialog) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) ExecutionException(org.eclipse.core.commands.ExecutionException) FeatureStyleDialog(eu.esdihumboldt.hale.ui.style.dialog.FeatureStyleDialog) ExecutionException(org.eclipse.core.commands.ExecutionException) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)13 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)8 InstanceService (eu.esdihumboldt.hale.ui.service.instance.InstanceService)4 InstanceServiceAdapter (eu.esdihumboldt.hale.ui.service.instance.InstanceServiceAdapter)3 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)3 SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)3 Style (org.geotools.styling.Style)3 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)2 InstanceReference (eu.esdihumboldt.hale.common.instance.model.InstanceReference)2 StyleService (eu.esdihumboldt.hale.ui.common.service.style.StyleService)2 GeometrySchemaService (eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService)2 ArrayList (java.util.ArrayList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Image (org.eclipse.swt.graphics.Image)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 ProjectInfo (eu.esdihumboldt.hale.common.core.io.project.ProjectInfo)1 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)1