Search in sources :

Example 56 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition 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 57 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition 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 58 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class StyleServiceImpl method getStyle.

private Style getStyle(final DataSet dataset, boolean selected) {
    SchemaSpace schemas = schemaService.getSchemas((dataset == DataSet.SOURCE) ? (SchemaSpaceID.SOURCE) : (SchemaSpaceID.TARGET));
    Style style = styleFactory.createStyle();
    for (TypeDefinition type : schemas.getMappingRelevantTypes()) {
        if (!type.getConstraint(AbstractFlag.class).isEnabled()) {
            // only add styles for non-abstract feature types
            FeatureTypeStyle fts = styles.get(type);
            if (fts == null) {
                if (fbStyle != null) {
                    fts = fbStyle;
                } else {
                    fts = StyleHelper.getDefaultStyle(type, dataset);
                }
            }
            if (selected) {
                fts = getSelectedStyle(fts);
            }
            style.featureTypeStyles().add(fts);
        }
    }
    return style;
}
Also used : SchemaSpace(eu.esdihumboldt.hale.common.schema.model.SchemaSpace) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 59 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class StyleServiceImpl method addStyles.

/**
 * @see StyleService#addStyles(Style[])
 */
@Override
public void addStyles(Style... styles) {
    boolean somethingHappened = false;
    for (Style style : styles) {
        for (FeatureTypeStyle fts : style.featureTypeStyles()) {
            if (!fts.featureTypeNames().isEmpty() && fts.featureTypeNames().iterator().next().getLocalPart().equals("Feature")) {
                this.fbStyle = fts;
                somethingHappened = true;
            } else {
                Collection<TypeDefinition> types = findTypes(fts.featureTypeNames());
                if (types != null && !types.isEmpty()) {
                    for (TypeDefinition type : types) {
                        if (addStyle(type, fts)) {
                            somethingHappened = true;
                        }
                    }
                } else {
                    /*
						 * store for later schema update when feature type might
						 * be present
						 */
                    queuedStyles.add(fts);
                }
            }
        }
    }
    if (somethingHappened) {
        notifyStylesAdded();
    }
}
Also used : Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 60 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition 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;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)192 QName (javax.xml.namespace.QName)58 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)38 ArrayList (java.util.ArrayList)32 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)26 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)26 Test (org.junit.Test)24 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)22 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)21 HashSet (java.util.HashSet)21 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)20 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)20 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)16 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)15 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)14 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)12 Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)12 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)12