Search in sources :

Example 6 with DataSet

use of eu.esdihumboldt.hale.common.instance.model.DataSet in project hale by halestudio.

the class TypeRandomColorHandler method execute.

/**
 * @see IHandler#execute(ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // collect types and associated data sets
    SetMultimap<DataSet, TypeDefinition> types = TypeStyleHandler.collectTypesFromSelection(event);
    Style style = StyleHelper.getRandomStyles(types);
    StyleService styleService = PlatformUI.getWorkbench().getService(StyleService.class);
    styleService.addStyles(style);
    return null;
}
Also used : DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) StyleService(eu.esdihumboldt.hale.ui.common.service.style.StyleService) Style(org.geotools.styling.Style) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 7 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)

Example 8 with DataSet

use of eu.esdihumboldt.hale.common.instance.model.DataSet 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;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) ISelection(org.eclipse.jface.viewers.ISelection) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 9 with DataSet

use of eu.esdihumboldt.hale.common.instance.model.DataSet in project hale by halestudio.

the class InstanceValidationStatusAction method createListeners.

/**
 * Registers needed listeners.
 */
private void createListeners() {
    InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
    is.addListener(new InstanceServiceAdapter() {

        @Override
        public void datasetAboutToChange(DataSet type) {
            report = null;
            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    updateStatus();
                }
            });
        }
    });
    final InstanceValidationService ivs = PlatformUI.getWorkbench().getService(InstanceValidationService.class);
    ivs.addListener(new InstanceValidationListener() {

        @Override
        public void instancesValidated(InstanceValidationReport report) {
            InstanceValidationStatusAction.this.report = report;
            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    updateStatus();
                }
            });
        }

        @Override
        public void validationEnabledChange() {
        // don't care
        }
    });
}
Also used : InstanceValidationReport(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) InstanceServiceAdapter(eu.esdihumboldt.hale.ui.service.instance.InstanceServiceAdapter) InstanceValidationService(eu.esdihumboldt.hale.ui.service.instance.validation.InstanceValidationService) InstanceValidationListener(eu.esdihumboldt.hale.ui.service.instance.validation.InstanceValidationListener)

Example 10 with DataSet

use of eu.esdihumboldt.hale.common.instance.model.DataSet in project hale by halestudio.

the class StyleHelper method getRandomStyles.

/**
 * Returns a default style for the given type.
 *
 * @param dataSetTypes type definitions associated to their data set
 * @return the style
 */
public static Style getRandomStyles(SetMultimap<DataSet, TypeDefinition> dataSetTypes) {
    int defWidth = StylePreferences.getDefaultWidth();
    Style style = styleFactory.createStyle();
    for (Entry<DataSet, TypeDefinition> entry : dataSetTypes.entries()) {
        DataSet dataSet = entry.getKey();
        TypeDefinition typeDef = entry.getValue();
        FeatureTypeStyle fts;
        // TODO based on default geometry?
        // polygon is always OK as it contains stroke and fill
        // Color color = generateRandomColor(Color.WHITE);
        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;
        }
        Color color = generateRandomColor(saturation, brightness);
        fts = createPolygonStyle(color, defWidth);
        fts.featureTypeNames().add(new NameImpl(getFeatureTypeName(typeDef)));
        style.featureTypeStyles().add(fts);
    }
    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) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)12 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)8 Style (org.geotools.styling.Style)4 InstanceService (eu.esdihumboldt.hale.ui.service.instance.InstanceService)3 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 InstanceServiceAdapter (eu.esdihumboldt.hale.ui.service.instance.InstanceServiceAdapter)2 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)2 SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)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 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)1 InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)1 MultiInstanceCollection (eu.esdihumboldt.hale.common.instance.model.impl.MultiInstanceCollection)1