use of eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection in project hale by halestudio.
the class InstanceValidationReportDetailsPage method getValidSelection.
/**
* Returns a valid instance selection for the current selection of the tree
* viewer. Returns <code>null</code> if there is none.
*
* @return a valid instance selection for the current selection of the tree
* viewer or <code>null</code>
*/
private InstanceSelection getValidSelection() {
ISelection viewerSelection = treeViewer.getSelection();
if (!(viewerSelection instanceof ITreeSelection) || viewerSelection.isEmpty())
return null;
ITreeSelection treeSelection = (ITreeSelection) treeViewer.getSelection();
// XXX use all paths
TreePath firstPath = treeSelection.getPaths()[0];
// instead of first
// only?
InstanceValidationMessage firstMessage;
Iterator<InstanceValidationMessage> restIter;
if (firstPath.getLastSegment() instanceof InstanceValidationMessage) {
firstMessage = (InstanceValidationMessage) firstPath.getLastSegment();
restIter = Collections.emptyIterator();
} else {
Collection<InstanceValidationMessage> messages = contentProvider.getMessages(treeSelection.getPaths()[0]);
if (messages.isEmpty())
// shouldn't happen, but doesn't really matter
return null;
restIter = messages.iterator();
firstMessage = restIter.next();
}
InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
// check first message for valid instance reference
if (firstMessage.getInstanceReference() == null || is.getInstance(firstMessage.getInstanceReference()) == null)
return null;
Set<InstanceReference> references = new HashSet<InstanceReference>();
references.add(firstMessage.getInstanceReference());
while (restIter.hasNext()) references.add(restIter.next().getInstanceReference());
return new DefaultInstanceSelection(references.toArray());
}
use of eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection in project hale by halestudio.
the class SimpleInstanceSelectionProvider method updateSelection.
/**
* Update the instance selection.
*
* @param instances the selected instances
*/
public void updateSelection(Iterable<Instance> instances) {
InstanceSelection selection;
if (instances != null) {
selection = new DefaultInstanceSelection(Iterables.toArray(instances, Instance.class));
} else {
selection = new DefaultInstanceSelection();
}
fireSelectionChange(selection);
}
use of eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection in project hale by halestudio.
the class AbstractInstanceTool method updateSelection.
/**
* Update the selection for the given selection area.
*
* @param selectionArea the selection area (as supported by
* {@link #getSelection(AbstractInstancePainter, Object)})
* @param combineWithLast if the selection shall be combined with the last
* selection
* @param allowPainterCombine if selections from different painters may be
* combined
*/
protected void updateSelection(Object selectionArea, boolean combineWithLast, boolean allowPainterCombine) {
ISelection newSelection = null;
// determine new selection
for (AbstractInstancePainter painter : mapKit.getTilePainters(AbstractInstancePainter.class)) {
ISelection selection = getSelection(painter, selectionArea);
if (allowPainterCombine) {
newSelection = AbstractInstancePainter.combineSelection(newSelection, selection);
} else {
newSelection = AbstractInstancePainter.preferSelection(newSelection, selection);
}
}
// combine with old
if (combineWithLast) {
newSelection = AbstractInstancePainter.combineSelection(lastSelection, newSelection);
}
if (newSelection == null) {
newSelection = new DefaultInstanceSelection();
}
// selection update
lastSelection = newSelection;
fireSelectionChange(newSelection);
}
Aggregations