Search in sources :

Example 51 with Instance

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

the class PolygonHandler method createGeometry.

/**
 * @see GeometryHandler#createGeometry(Instance, int, IOProvider)
 */
@SuppressWarnings("unchecked")
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
    LinearRing[] holes = null;
    Polygon polygon = null;
    CRSDefinition crs = null;
    // for use with GML 2
    // to parse outer linear rings
    Collection<Object> values = PropertyResolver.getValues(instance, "outerBoundaryIs.LinearRing", false);
    if (values != null && !values.isEmpty()) {
        Iterator<Object> iterator = values.iterator();
        List<LinearRing> outerRing = new ArrayList<>(1);
        while (iterator.hasNext()) {
            Object value = iterator.next();
            if (value instanceof Instance) {
                // outerRing must be a
                // GeometryProperty<LinearRing> instance
                GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                outerRing.add(ring.getGeometry());
                crs = checkCommonCrs(crs, ring.getCRSDefinition());
            }
        }
        // to parse inner linear rings
        values = PropertyResolver.getValues(instance, "innerBoundaryIs.LinearRing", false);
        if (values != null && !values.isEmpty()) {
            iterator = values.iterator();
            List<LinearRing> innerRings = new ArrayList<LinearRing>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // innerRings have to be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    innerRings.add(ring.getGeometry());
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            holes = innerRings.toArray(new LinearRing[innerRings.size()]);
        }
        polygon = getGeometryFactory().createPolygon(outerRing.get(0), holes);
    }
    // to parse inner linear rings
    if (polygon == null) {
        values = PropertyResolver.getValues(instance, "interior.LinearRing", false);
        Collection<Object> ringValues = PropertyResolver.getValues(instance, "interior.Ring", false);
        values = combineCollections(values, ringValues);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<LinearRing> innerRings = new ArrayList<LinearRing>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // innerRings have to be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    innerRings.add(ring.getGeometry());
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            holes = innerRings.toArray(new LinearRing[innerRings.size()]);
        }
        // to parse outer linear rings
        values = PropertyResolver.getValues(instance, "exterior.LinearRing", false);
        ringValues = PropertyResolver.getValues(instance, "exterior.Ring", false);
        values = combineCollections(values, ringValues);
        List<LinearRing> outerRing = new ArrayList<>(1);
        if (values != null && !values.isEmpty()) {
            LinearRing outer = null;
            Iterator<Object> iterator = values.iterator();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // outerRing must be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    outer = ring.getGeometry();
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            outerRing.add(outer);
            polygon = getGeometryFactory().createPolygon(outerRing.get(0), holes);
        }
    }
    if (polygon != null) {
        if (crs == null) {
            crs = GMLGeometryUtil.findCRS(instance);
        }
        return new DefaultGeometryProperty<Polygon>(crs, polygon);
    }
    throw new GeometryNotSupportedException();
}
Also used : DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) ArrayList(java.util.ArrayList) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 52 with Instance

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

the class SourceDataView method onSelectionChange.

/**
 * @see AbstractDataView#onSelectionChange(Iterable)
 */
@Override
protected void onSelectionChange(Iterable<Instance> selection) {
    InstanceSampleService rss = PlatformUI.getWorkbench().getService(InstanceSampleService.class);
    List<Instance> res = new ArrayList<Instance>();
    if (selection != null) {
        for (Instance instance : selection) {
            res.add(instance);
        }
    }
    rss.setReferenceInstances(res);
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) ArrayList(java.util.ArrayList) InstanceSampleService(eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService)

Example 53 with Instance

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

the class DefinitionInstanceLabelProvider method update.

/**
 * @see CellLabelProvider#update(ViewerCell)
 */
@Override
public void update(ViewerCell cell) {
    TreePath treePath = cell.getViewerRow().getTreePath();
    InstanceEntry entry = findInstanceEntry(treePath);
    Object value = entry.value;
    InstanceValidationReport report = null;
    // If childDef is null we are at the top element.
    if (entry.definition && entry.childDef == null) {
        report = validator.validate(instance);
    }
    boolean hasValue = false;
    if (entry.definition && value instanceof Instance) {
        hasValue = ((Instance) value).getValue() != null;
    } else if (!entry.definition && treePath.getSegmentCount() == 1) {
        // metadata root
        if (instance.getMetaDataNames().isEmpty()) {
            hasValue = true;
            value = null;
        }
    }
    StyledString styledString;
    if (value == null) {
        styledString = new StyledString("no value", StyledString.DECORATIONS_STYLER);
    } else if (value instanceof Group && !hasValue) {
        styledString = new StyledString("+", StyledString.QUALIFIER_STYLER);
    } else {
        if (value instanceof Instance) {
            value = ((Instance) value).getValue();
        }
        // TODO some kind of conversion?
        String stringValue = value.toString();
        /*
			 * Values that are very large, e.g. string representations of very
			 * complex geometries lead to
			 * StyledCellLabelProvider.updateTextLayout taking a very long time,
			 * rendering the application unresponsive when the data views are
			 * displayed. As such, we reduce the string to a maximum size.
			 */
        if (stringValue.length() > MAX_STRING_LENGTH) {
            stringValue = stringValue.substring(0, MAX_STRING_LENGTH) + "...";
        }
        styledString = new StyledString(stringValue, null);
    }
    // mark cell if there are other values
    if (entry.valueCount > 1) {
        String decoration = " " + MessageFormat.format(MULTIPLE_VALUE_FORMAT, entry.choice + 1, entry.valueCount);
        styledString.append(decoration, StyledString.COUNTER_STYLER);
    }
    cell.setText(styledString.toString());
    cell.setStyleRanges(styledString.getStyleRanges());
    if (report != null && !report.getWarnings().isEmpty())
        cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    super.update(cell);
}
Also used : InstanceValidationReport(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport) Group(eu.esdihumboldt.hale.common.instance.model.Group) TreePath(org.eclipse.jface.viewers.TreePath) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 54 with Instance

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

the class DefinitionInstanceTreeViewer method setInput.

/**
 * @see InstanceViewer#setInput(TypeDefinition, Iterable)
 */
@Override
public void setInput(TypeDefinition type, Iterable<Instance> instances) {
    // remove old columns
    TreeColumn[] columns = treeViewer.getTree().getColumns();
    if (columns != null) {
        for (TreeColumn column : columns) {
            column.dispose();
        }
        labelProviders.clear();
    }
    // set input
    if (type != null) {
        // pass metadatas to the treeviewer, if instances contain metadatas
        Set<String> completeMetaNames = new HashSet<String>();
        for (Instance inst : instances) {
            for (String name : inst.getMetaDataNames()) {
                completeMetaNames.add(name);
            }
        }
        Pair<TypeDefinition, Set<String>> pair = new Pair<TypeDefinition, Set<String>>(type, completeMetaNames);
        treeViewer.setInput(pair);
    } else
        treeViewer.setInput(Collections.emptySet());
    Layout layout = treeViewer.getTree().getParent().getLayout();
    // add type column
    if (type != null) {
        TreeViewerColumn column = new TreeViewerColumn(treeViewer, SWT.LEFT);
        column.getColumn().setText(type.getDisplayName());
        column.setLabelProvider(new TreeColumnViewerLabelProvider(new DefinitionMetaCompareLabelProvider(treeViewer)));
        if (layout instanceof TreeColumnLayout) {
            ((TreeColumnLayout) layout).setColumnData(column.getColumn(), new ColumnWeightData(1));
        }
    }
    // add columns for features
    int index = 1;
    if (instances != null) {
        // // sort features
        // List<Feature> sortedFeatures = new ArrayList<Feature>();
        // for (Feature f : features) {
        // sortedFeatures.add(f);
        // }
        // Collections.sort(sortedFeatures, new Comparator<Feature>() {
        // 
        // @Override
        // public int compare(Feature o1, Feature o2) {
        // FeatureId id1 = FeatureBuilder.getSourceID(o1);
        // if (id1 == null) {
        // id1 = o1.getIdentifier();
        // }
        // 
        // FeatureId id2 = FeatureBuilder.getSourceID(o2);
        // if (id2 == null) {
        // id2 = o2.getIdentifier();
        // }
        // 
        // return id1.getID().compareTo(id2.getID());
        // }
        // 
        // });
        List<Instance> insts = new ArrayList<Instance>();
        for (Instance instance : instances) {
            // sortedFeatures) {
            final TreeViewerColumn column = new TreeViewerColumn(treeViewer, SWT.LEFT);
            // FeatureId id = FeatureBuilder.getSourceID(feature);
            // if (id == null) {
            // id = feature.getIdentifier();
            // }
            // column.getColumn().setText(id.toString());
            // XXX
            column.getColumn().setText(String.valueOf(index));
            // identifier?
            DefinitionInstanceLabelProvider labelProvider = new DefinitionInstanceLabelProvider(instance);
            labelProviders.put(index, labelProvider);
            column.setLabelProvider(labelProvider);
            if (layout instanceof TreeColumnLayout) {
                ((TreeColumnLayout) layout).setColumnData(column.getColumn(), new ColumnWeightData(1));
            }
            // add tool tip
            // new ColumnBrowserTip(treeViewer, 400, 300, true, index, null);
            insts.add(instance);
            index++;
        }
        ((MetadataCompareActionProvider) maep).setInput(insts, labelProviders);
    }
    treeViewer.refresh();
    treeViewer.getTree().getParent().layout(true, true);
    selectionProvider.updateSelection(instances);
    // auto-expand attributes/metadata
    treeViewer.expandToLevel(2);
}
Also used : TreeColumnViewerLabelProvider(org.eclipse.jface.viewers.TreeColumnViewerLabelProvider) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Set(java.util.Set) HashSet(java.util.HashSet) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) Layout(org.eclipse.swt.widgets.Layout) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) HashSet(java.util.HashSet) Pair(eu.esdihumboldt.util.Pair)

Example 55 with Instance

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

the class InstanceExplorer method createControls.

/**
 * @see InstanceViewer#createControls(Composite, SchemaSpaceID)
 */
@Override
public void createControls(Composite parent, SchemaSpaceID schemaSpace) {
    main = new Composite(parent, SWT.NONE);
    main.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create());
    // selector composite
    selectorComposite = new Composite(main, SWT.NONE);
    selectorComposite.setLayoutData(GridDataFactory.swtDefaults().create());
    selectorComposite.setLayout(GridLayoutFactory.fillDefaults().create());
    // viewer composite
    Composite viewerComposite = new Composite(main, SWT.NONE);
    viewerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    TreeColumnLayout layout = new TreeColumnLayout();
    viewerComposite.setLayout(layout);
    viewer = new TreeViewer(viewerComposite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    viewer.getTree().setLinesVisible(true);
    // set content provider
    viewer.setContentProvider(new InstanceContentProvider());
    viewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
    // TODO set label provider?
    // add definition columns
    TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.LEFT);
    column.getColumn().setText("Definition");
    column.setLabelProvider(new TreeColumnViewerLabelProvider(new PairLabelProvider(true, new DefinitionMetaLabelProvider(viewer, false, true))));
    layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
    // add value column
    column = new TreeViewerColumn(viewer, SWT.LEFT);
    column.getColumn().setText("Value");
    final InstanceValueLabelProvider instanceLabelProvider = new InstanceValueLabelProvider();
    column.setLabelProvider(instanceLabelProvider);
    // new PairLabelProvider(false, new LabelProvider())));
    ColumnViewerToolTipSupport.enableFor(viewer);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
    MetadataActionProvider maep = new MetadataExploreActionProvider(viewer);
    maep.setup();
    // Add an editor for copying instance values
    editor = new TreeEditor(viewer.getTree());
    editor.horizontalAlignment = SWT.RIGHT;
    viewer.getTree().addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            final ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
            // Selected cell changed?
            if (cell == null || editor.getItem() != cell.getItem() || editor.getColumn() != cell.getColumnIndex()) {
                // Clean up any previous editor control
                Control oldEditor = editor.getEditor();
                if (oldEditor != null) {
                    oldEditor.dispose();
                    editor.setEditor(null, null, 0);
                }
            }
            // No valid selected cell
            if (cell == null || cell.getColumnIndex() == 0) {
                return;
            }
            // cell didn't change
            if ((editor.getItem() == cell.getItem() && editor.getColumn() == cell.getColumnIndex())) {
                return;
            }
            // determine instance value
            Object value = ((Pair<?, ?>) cell.getViewerRow().getTreePath().getLastSegment()).getSecond();
            if (value instanceof Instance) {
                value = ((Instance) value).getValue();
            }
            // copy button
            if (value != null) {
                final String textValue = value.toString();
                if (!textValue.isEmpty()) {
                    // empty string invalid for
                    // clipboard
                    Button button = new Button(viewer.getTree(), SWT.PUSH | SWT.FLAT);
                    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
                    button.setToolTipText("Copy string value");
                    button.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            // copy content to clipboard
                            Clipboard clipBoard = new Clipboard(Display.getCurrent());
                            clipBoard.setContents(new Object[] { textValue }, new Transfer[] { TextTransfer.getInstance() });
                            clipBoard.dispose();
                        }
                    });
                    // calculate editor size
                    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                    editor.minimumHeight = size.y;
                    editor.minimumWidth = size.x;
                    editor.setEditor(button, (TreeItem) cell.getItem(), cell.getColumnIndex());
                }
            }
        }
    });
    update();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PairLabelProvider(eu.esdihumboldt.hale.ui.util.viewer.PairLabelProvider) TreeColumnViewerLabelProvider(org.eclipse.jface.viewers.TreeColumnViewerLabelProvider) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) TreeEditor(org.eclipse.swt.custom.TreeEditor) MetadataActionProvider(eu.esdihumboldt.hale.ui.views.data.internal.MetadataActionProvider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) Clipboard(org.eclipse.swt.dnd.Clipboard)

Aggregations

Instance (eu.esdihumboldt.hale.common.instance.model.Instance)203 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)131 Test (org.junit.Test)122 AbstractHandlerTest (eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest)97 QName (javax.xml.namespace.QName)29 ArrayList (java.util.ArrayList)26 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)25 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)23 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)22 Group (eu.esdihumboldt.hale.common.instance.model.Group)15 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)12 Geometry (com.vividsolutions.jts.geom.Geometry)12 FamilyInstance (eu.esdihumboldt.hale.common.instance.model.FamilyInstance)10 Polygon (com.vividsolutions.jts.geom.Polygon)9 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)8 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)8 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)8 HashSet (java.util.HashSet)8 Point (com.vividsolutions.jts.geom.Point)7