Search in sources :

Example 1 with DefaultInstanceSelection

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());
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) ISelection(org.eclipse.jface.viewers.ISelection) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) DefaultInstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) HashSet(java.util.HashSet) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection)

Example 2 with DefaultInstanceSelection

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);
}
Also used : InstanceSelection(eu.esdihumboldt.hale.ui.selection.InstanceSelection) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection)

Example 3 with DefaultInstanceSelection

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);
}
Also used : AbstractInstancePainter(eu.esdihumboldt.hale.ui.views.styledmap.painter.AbstractInstancePainter) ISelection(org.eclipse.jface.viewers.ISelection) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection)

Aggregations

DefaultInstanceSelection (eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection)3 ISelection (org.eclipse.jface.viewers.ISelection)2 InstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage)1 DefaultInstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage)1 InstanceReference (eu.esdihumboldt.hale.common.instance.model.InstanceReference)1 InstanceSelection (eu.esdihumboldt.hale.ui.selection.InstanceSelection)1 InstanceService (eu.esdihumboldt.hale.ui.service.instance.InstanceService)1 AbstractInstancePainter (eu.esdihumboldt.hale.ui.views.styledmap.painter.AbstractInstancePainter)1 HashSet (java.util.HashSet)1 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)1 TreePath (org.eclipse.jface.viewers.TreePath)1