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();
}
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);
}
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);
}
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);
}
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();
}
Aggregations