Example usage for org.eclipse.jface.viewers StructuredSelection toList

List of usage examples for org.eclipse.jface.viewers StructuredSelection toList

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection toList.

Prototype

@Override
    public List toList() 

Source Link

Usage

From source file:eu.geclipse.traceview.logicalgraph.LogicalGraphPaintListener.java

License:Open Source License

void drawSelection() {
    ISelection selection = null;//w  w w  .j  av a  2  s  .  co  m
    try {
        ISelectionProvider provider = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow()
                .getActivePage().getActivePart().getSite().getSelectionProvider();
        if (provider != null) {
            selection = provider.getSelection();
        }
    } catch (Exception e) {
        // ignore
    }
    if (selection != null && selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        for (Object obj : structuredSelection.toList()) {
            if (obj instanceof ILamportEvent) {
                ILamportEvent event = (ILamportEvent) obj;
                if (event.getProcess().getTrace() != this.trace)
                    continue;
                if (this.fromClock <= event.getLamportClock() && event.getLamportClock() <= this.toClock) {
                    if (procDrawingEnabled(event.getProcessId(), true)) {
                        int x = getXPosForClock(event.getLamportClock()) - this.eventSize / 2;
                        int y = getYPosForProcId(event.getProcessId()) - this.eventSize / 2;
                        this.gc.setForeground(this.selectionColor);
                        this.gc.setBackground(this.selectionColor);
                        this.gc.fillOval(x - this.eventSize / 4, y - this.eventSize / 4,
                                this.eventSize + this.eventSize / 2, this.eventSize + this.eventSize / 2);
                    }
                }
            } else if (obj instanceof IProcess) {
                IProcess process = (IProcess) obj;
                if (process.getTrace() != this.trace)
                    continue;
                if (procDrawingEnabled(process.getProcessId(), true)) {
                    int x = 0;
                    int y = getYPosForProcId(process.getProcessId()) - this.eventSize / 2;
                    this.gc.setForeground(this.selectionColor);
                    this.gc.setBackground(this.selectionColor);
                    this.gc.fillRectangle(x, y + this.eventSize / 4, this.width, this.eventSize / 2);
                }
            }
        }
    }
}

From source file:eu.geclipse.traceview.physicalgraph.PhysicalGraphPaintListener.java

License:Open Source License

void drawSelection() {
    ISelection selection = null;/*  w w w. ja va  2 s . c  om*/
    try {
        selection = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .getActivePart().getSite().getSelectionProvider().getSelection();
    } catch (Exception e) {
        // ignore
    }
    if (selection != null && selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        for (Object obj : structuredSelection.toList()) {
            if (obj instanceof IPhysicalEvent) {
                IPhysicalEvent event = (IPhysicalEvent) obj;
                if (event.getProcess().getTrace() != this.trace)
                    continue;
                if (procDrawingEnabled(event.getProcessId(), true)) {
                    if (this.fromTime <= event.getPhysicalStopClock()
                            || event.getPartnerPhysicalStartClock() <= this.toTime) {
                        int y = getYPosForProcId(event.getProcessId()) - this.eventSize / 2;
                        this.gc.setForeground(this.selectionColor);
                        this.gc.setBackground(this.selectionColor);
                        int x = getXPosForClock(event.getPhysicalStartClock());
                        int rectWidth = getXPosForClock(event.getPhysicalStopClock()) - x;
                        this.gc.fillRectangle(x - 2, y - 2, rectWidth + 5, 2 * this.vzoomfactor + 5);
                    }
                }
            } else if (obj instanceof IProcess) {
                IProcess process = (IProcess) obj;
                if (process.getTrace() != this.trace)
                    continue;
                if (procDrawingEnabled(process.getProcessId(), true)) {
                    int x = 0;
                    int y = getYPosForProcId(process.getProcessId()) - this.eventSize / 2;
                    this.gc.setForeground(this.selectionColor);
                    this.gc.setBackground(this.selectionColor);
                    this.gc.fillRectangle(x, y + this.eventSize / 4, this.width, this.eventSize / 2);
                }
            }
        }
    }
}

From source file:fr.lip6.move.coloane.core.ui.commands.LocatedElementSetConstraintCmd.java

License:Open Source License

/**
 * Constructor//from  w  ww. ja  va  2 s .co  m
 * @param element Model object to move
 * @param newLocation New location for the model object
 */
public LocatedElementSetConstraintCmd(ILocatedElement element, Point newLocation) {
    super(Messages.NodeSetConstraintCmd_0);
    if (element == null || newLocation == null) {
        throw new NullPointerException();
    }
    this.element = element;
    this.newLocation = newLocation.getCopy();
    this.newLocation.x = Math.max(this.newLocation.x, 0);
    this.newLocation.y = Math.max(this.newLocation.y, 0);

    // Need to get the current selection to control if arcs are involved in the move
    ColoaneEditor ce = (ColoaneEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getActiveEditor();
    GraphicalViewer viewer = (GraphicalViewer) ce.getAdapter(GraphicalViewer.class);

    // List of selected objects (try to know if arcs are involved in this move)
    StructuredSelection s = (StructuredSelection) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
            .getActivePage().getActiveEditor().getSite().getSelectionProvider().getSelection();
    List<?> selection = s.toList();

    // If the element is a node, some arcs may be involved in the move
    // If source node and target node are selected, arc has to be moved too (and also inflex point)
    if (element instanceof INode) {
        INode node = (INode) element;

        // Deal with incoming arcs.
        // Attributes have to be moved too.
        // Inflex point may be moved too.
        for (IArc in : node.getIncomingArcs()) {
            INode src = in.getSource();
            // If the source node is also moved, the arc will be moved automatically (but not its inflex point)
            if (selection.contains(viewer.getEditPartRegistry().get(src))) {
                arcsForPI.add(in);
            }

            // If the target node is moved... The arc will be moved too (but not its attributes)
            for (IAttribute arcAttr : in.getAttributes()) {
                if (!selection.contains(viewer.getEditPartRegistry().get(arcAttr))) {
                    arcsForAttr.add(arcAttr);
                }
            }
        }

        // If the source node is moved... The outgoing arcs will be moved too (but not their attributes)
        for (IArc out : node.getOutgoingArcs()) {
            for (IAttribute arcAttr : out.getAttributes()) {
                if (!selection.contains(viewer.getEditPartRegistry().get(arcAttr))) {
                    arcsForAttr.add(arcAttr);
                }
            }
        }
    }

    // Generally, attributes of the moved element must be moved too
    if (element instanceof IElement) {
        IElement modelElement = (IElement) element;

        for (IAttribute attr : modelElement.getDrawableAttributes()) {
            if (!selection.contains(viewer.getEditPartRegistry().get(attr))) {
                attributes.add(attr);
            }
        }
    }
}

From source file:gov.nasa.arc.spife.core.plan.editor.timeline.TimelineEditorPart.java

License:Open Source License

private EPlanElement getFirstSelectedEPlanElement() {
    EPlanElement firstElement = null;/*www .j  av  a 2 s. com*/
    ISelection selection = getCurrentSelection();
    if (selection != null && selection instanceof StructuredSelection) {
        StructuredSelection selection2 = (StructuredSelection) selection;
        for (Object obj : selection2.toList()) {
            if (obj instanceof EPlanElement) {
                firstElement = (EPlanElement) obj;
                break;
            }
        }
    }
    return firstElement;
}

From source file:gov.nasa.arc.spife.ui.timeline.TimelineTool.java

License:Open Source License

private boolean handleDragCompleted() {
    boolean result;
    try {//w ww  .  j av  a  2s.c om
        draggingCompleting = true;
        ChangeBoundsRequest request = null;
        result = false;
        EditPart editPart = this.getTargetUnderMouse();
        DragTracker dragTracker = getDragTracker();
        if (dragTracker != null) {
            dragTracker.deactivate();
        }
        if (currentCursor == super.calculateCursor()) {
            request = new ChangeBoundsRequest(REQ_MOVE_COMPLETED);
            request.setLocation(getLocation());
            StructuredSelection selection = (StructuredSelection) getCurrentViewer().getSelection();
            request.setEditParts(selection.toList());
            result = processRequest(request, selection.toList());
        } else if (currentCursor.equals(TimelineTool.leftHandleCursor)) {
            request = new ChangeBoundsRequest(REQ_CHANGE_START_TIME_COMPLETED);
            request.setLocation(getLocation());
            request.setEditParts(editPart);
            result = processRequest(request, Arrays.asList(editPart));
        } else if (currentCursor.equals(TimelineTool.leftHandleCursor)) {
            request = new ChangeBoundsRequest(REQ_CHANGE_END_TIME_COMPLETED);
            request.setLocation(getLocation());
            request.setEditParts(editPart);
            result = processRequest(request, Arrays.asList(editPart));
        }
        if (!result && (dragTracker != null)) {
            // if the request somehow fails, reactivate the drag tracker
            dragTracker.activate();
        }
    } finally {
        draggingCompleting = false;
    }
    return result;
}

From source file:gov.nasa.ensemble.core.detail.emf.binding.ChildrenHyperlinkListener.java

License:Open Source License

private List<Object> getModifiedSelection(Object node) {
    boolean elementFound = false;
    List<Object> elements = new ArrayList<Object>();
    ISelection oldSelection = selectionProvider.getSelection();
    if (oldSelection instanceof StructuredSelection) {
        StructuredSelection selection = (StructuredSelection) oldSelection;
        for (Object object : selection.toList()) {
            //            if (object instanceof Object) {
            //               Object element = object;
            if (object == node) {
                elementFound = true;/*from   ww  w.ja  va  2  s .c  o m*/
            } else {
                elements.add(object);
            }
            //            }
        }
    }
    if (!elementFound) {
        elements.add(node);
    }
    return elements;
}

From source file:name.schedenig.eclipse.grepconsole.view.items.ItemsTreePanel.java

License:Open Source License

/**
 * Returns the set of currently selected element. If no element is selected,
 * <code>null</code> is returned.
 * /*  w w w. ja  va 2 s  . co m*/
 * @return Selected elements, or <code>null</code>.
 */
public Set<AbstractGrepModelElement> getSelectedElements() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();

    if (selection.isEmpty()) {
        return null;
    }

    @SuppressWarnings("unchecked")
    LinkedHashSet<AbstractGrepModelElement> elements = new LinkedHashSet<AbstractGrepModelElement>(
            selection.toList());

    return elements;
}

From source file:net.enilink.komma.edit.ui.dialogs.FilteredList.java

License:Open Source License

/**
 * Handle selection in the items list by updating labels of selected and
 * unselected items and refresh the details field using the selection.
 * /*from ww  w  .  ja va2 s.c  o  m*/
 * @param selection
 *            the new selection
 */
protected void handleSelected(StructuredSelection selection) {
    IStatus status = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, EMPTY_STRING, null);

    if (selection.size() == 0) {
        status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR, EMPTY_STRING, null);

        if (lastSelection != null && getListSelectionLabelDecorator() != null) {
            list.update(lastSelection, null);
        }

        lastSelection = null;

    } else {
        status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR, EMPTY_STRING, null);

        List<?> items = selection.toList();

        Object item = null;
        IStatus tempStatus = null;

        for (Object o : items) {
            if (o instanceof ItemsListSeparator) {
                continue;
            }

            item = o;
            tempStatus = validateItem(item);

            if (tempStatus.isOK()) {
                status = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, EMPTY_STRING, null);
            } else {
                status = tempStatus;
                // if any selected element is not valid status is set to
                // ERROR
                break;
            }
        }

        if (lastSelection != null && getListSelectionLabelDecorator() != null) {
            list.update(lastSelection, null);
        }

        if (getListSelectionLabelDecorator() != null) {
            list.update(items.toArray(), null);
        }

        lastSelection = items.toArray();
    }

    refreshDetails();
    updateStatus(status);
}

From source file:net.enilink.komma.edit.ui.dialogs.FilteredList.java

License:Open Source License

/**
 * Returns the current selection.//from   w ww.j  a  va  2 s  .c  o m
 * 
 * @return the current selection
 */
protected StructuredSelection getSelectedItems() {
    StructuredSelection selection = (StructuredSelection) list.getSelection();

    List<?> selectedItems = selection.toList();
    Object itemToRemove = null;

    for (Object item : selectedItems) {
        if (item instanceof ItemsListSeparator) {
            itemToRemove = item;
            break;
        }
    }

    if (itemToRemove == null)
        return new StructuredSelection(selectedItems);
    // Create a new selection without the collision
    List<Object> newItems = new ArrayList<Object>(selectedItems);
    newItems.remove(itemToRemove);
    return new StructuredSelection(newItems);

}

From source file:net.refractions.udig.project.ui.internal.LegendView.java

License:Open Source License

/**
 * Gets an adapted selection from the current selection. This method checks each object in the
 * selection if they can adapt to an object that can be deleted.
 * <p>//  ww w  .  j a va2s .co  m
 * Example. if LayerLegendItem, return LayerLegendItem.getLayer()
 * 
 * @return selection to be deleted
 */
private ISelection getDeleteSelection() {

    final ISelection selection = viewer.getSelection();
    final StructuredSelection strucSelection = (StructuredSelection) selection;

    final List<Object> adaptedObjs = new ArrayList<Object>();
    for (Object obj : strucSelection.toList()) {
        if (obj instanceof Folder) {
            adaptedObjs.add(obj);
        } else if (obj instanceof LayerLegendItem) {
            final LayerLegendItem layerItem = (LayerLegendItem) obj;
            adaptedObjs.add(layerItem.getLayer());
        }
    }

    final StructuredSelection adaptedSelection = new StructuredSelection(adaptedObjs);
    return adaptedSelection;

}