Search in sources :

Example 51 with TypeDefinition

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

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

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

the class RuleStylePage method createEditor.

/**
 * Create a rule editor
 *
 * @param rule the rule
 * @param parent the parent composite
 *
 * @return the {@link Rule} editor
 */
private Editor<Rule> createEditor(Rule rule, Composite parent) {
    TypeDefinition type = getParent().getType();
    Filter filter = rule.getFilter();
    Symbolizer symbolizer = null;
    Symbolizer[] symbolizers = rule.getSymbolizers();
    if (symbolizers != null && symbolizers.length > 0) {
        symbolizer = symbolizers[0];
    }
    if (symbolizer == null) {
        // fallback if there is no symbolizer defined
        FeatureTypeStyle fts = StyleHelper.getDefaultStyle(type, getParent().getDataSet());
        symbolizer = fts.rules().get(0).getSymbolizers()[0];
    }
    Editor<Rule> editor;
    if (symbolizer instanceof PointSymbolizer) {
        editor = createEditor(parent, type, filter, PointSymbolizer.class, (PointSymbolizer) symbolizer);
    } else if (symbolizer instanceof PolygonSymbolizer) {
        editor = createEditor(parent, type, filter, PolygonSymbolizer.class, (PolygonSymbolizer) symbolizer);
    } else {
        // TODO support other symbolizers
        // default: LineSymbolizer
        editor = createEditor(parent, type, filter, LineSymbolizer.class, (LineSymbolizer) symbolizer);
    }
    return editor;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) Filter(org.opengis.filter.Filter) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 54 with TypeDefinition

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

the class SpectrumColorSchemeHandler method execute.

/**
 * @see IHandler#execute(ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // collect all types
    SetMultimap<DataSet, TypeDefinition> types = HashMultimap.create();
    SchemaService schemas = PlatformUI.getWorkbench().getService(SchemaService.class);
    for (TypeDefinition type : schemas.getSchemas(SchemaSpaceID.SOURCE).getMappingRelevantTypes()) {
        types.put(DataSet.SOURCE, type);
    }
    for (TypeDefinition type : schemas.getSchemas(SchemaSpaceID.TARGET).getMappingRelevantTypes()) {
        types.put(DataSet.TRANSFORMED, type);
    }
    Style style = StyleHelper.getSpectrumStyles(types);
    StyleService styleService = PlatformUI.getWorkbench().getService(StyleService.class);
    styleService.addStyles(style);
    return null;
}
Also used : DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) StyleService(eu.esdihumboldt.hale.ui.common.service.style.StyleService) Style(org.geotools.styling.Style) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 55 with TypeDefinition

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

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