Example usage for org.eclipse.jface.viewers IStructuredSelection iterator

List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection iterator.

Prototype

@Override
public Iterator iterator();

Source Link

Document

Returns an iterator over the elements of this selection.

Usage

From source file:com.bluexml.side.view.edit.ui.actions.MergeCols.java

License:Open Source License

public boolean updateSelection(IStructuredSelection selection) {
    selectedObject = new ArrayList<Col>();
    for (Iterator<?> objects = selection.iterator(); objects.hasNext();) {
        Object object = objects.next();
        if (object instanceof Col) {
            // We add cols having the same parent only
            Col col = (Col) object;/* w  w  w .  j  a  va 2  s  .  c om*/
            if (selectedObject.size() > 0 && selectedObject.get(0).eContainer().equals(col.eContainer())) {
                selectedObject.add(col);
            } else if (selectedObject.size() == 0) {
                selectedObject.add((Col) object);
                container = col.eContainer();
            }
        } else {
            return false;
        }
    }
    return selectedObject.size() > 1;
}

From source file:com.bluexml.side.view.edit.ui.actions.PasteColConfAction.java

License:Open Source License

public boolean updateSelection(IStructuredSelection selection) {
    if (selection.size() == 1) {
        Iterator<?> objects = selection.iterator();
        Object object = objects.next();
        if (object instanceof Col) {
            selectedObject = (Col) object;
        }/*from w w  w.  j  a  v  a2s .c om*/
    }
    return (selectedObject != null && ColConfManager.getActualCopiedCol() != null);
}

From source file:com.bluexml.side.view.edit.ui.actions.RefreshOutline.java

License:Open Source License

public boolean updateSelection(IStructuredSelection selection) {
    selectedObject = null;/*from  ww w  .  j  a  v a2 s.  co m*/
    for (Iterator<?> objects = selection.iterator(); objects.hasNext();) {
        Object object = objects.next();
        if (object instanceof FieldContainer) {
            selectedObject = (FieldContainer) object;
            XMIResource xmiRessource = (XMIResource) ((EObject) object).eResource();
            ;
            fileURI = xmiRessource.getURI();
        } else {
            return false;
        }
    }

    return selectedObject != null;
}

From source file:com.bluexml.side.view.edit.ui.actions.RestoreFieldAction.java

License:Open Source License

public boolean updateSelection(IStructuredSelection selection) {
    selectedObject = null;/*from  w ww.  j a  v a 2  s  . c  o  m*/
    for (Iterator<?> objects = selection.iterator(); objects.hasNext();) {
        Object object = objects.next();
        if (object instanceof AbstractView) {
            selectedObject = (AbstractView) object;
        } else {
            return false;
        }
    }

    return selectedObject != null;
}

From source file:com.bluexml.side.view.edit.ui.actions.ShowLinkedClassAction.java

License:Open Source License

public boolean updateSelection(IStructuredSelection selection) {
    selectedObject = null;//from ww w  .j ava2 s . co  m
    for (Iterator<?> objects = selection.iterator(); objects.hasNext();) {
        Object object = objects.next();
        if (object instanceof AbstractViewOf) {
            selectedObject = (EObject) object;
        } else {
            return false;
        }
    }

    return selectedObject != null;
}

From source file:com.bluexml.side.view.edit.ui.actions.SynchronizeViews.java

License:Open Source License

public boolean updateSelection(IStructuredSelection selection) {
    selectedObject = null;/*w  w w  .j  av  a2s  . c o  m*/
    for (Iterator<?> objects = selection.iterator(); objects.hasNext();) {
        Object object = objects.next();
        if (object instanceof ViewCollection) {
            selectedObject = (ViewCollection) object;
        } else {
            return false;
        }
    }
    return selectedObject != null;
}

From source file:com.bluexml.side.view.edit.ui.actions.TransformField.java

License:Open Source License

public boolean updateSelection(IStructuredSelection selection) {
    selectedObject = null;//from w  w  w  . j av a2  s .  c  o m
    for (Iterator<?> objects = selection.iterator(); objects.hasNext();) {
        Object object = objects.next();
        if (object instanceof Field) {
            selectedObject = (Field) object;
        } else {
            return false;
        }
    }
    return selectedObject != null;
}

From source file:com.buildml.eclipse.actions.ActionsEditorDragSource.java

License:Open Source License

/**
 * A drag operation has been started. We need to validate whether the element being
 * dragged is something we can handle. For an ActionsEditor, we can drag one or more
 * UIAction objects.//from   ww w.  j  a va2s. co m
 */
@Override
public void dragStart(DragSourceEvent event) {

    /* 
     * Determine what is being dragged. Assuming everything in the selection is a UIAction,
     * we're OK to proceed.
     */
    IStructuredSelection selection = ((IStructuredSelection) treeViewer.getSelection());
    @SuppressWarnings("unchecked")
    Iterator<Object> iter = selection.iterator();
    while (iter.hasNext()) {
        Object node = iter.next();
        if ((node == null) || (!(node instanceof UIAction))) {

            /* something in the selection is not a UIAction - we can't drag */
            event.doit = false;
            return;
        }
    }

    /* OK, we can drag the selection */
    event.doit = true;
}

From source file:com.buildml.eclipse.actions.ActionsEditorDragSource.java

License:Open Source License

/** 
 * This method is called by the drag/drop framework to obtain the actual "transfer" data
 * for the tree node that was selected when the drag/drop started. For UIAction, we create
 * a corresponding BuildMLTransferType object. For other things, we abort.
 *//*from   www.  ja v  a  2s .c  o  m*/
@Override
public void dragSetData(DragSourceEvent event) {
    if (BuildMLTransfer.getInstance().isSupportedType(event.dataType)) {

        /*
         * Identify the currently-selected tree node, and create a corresponding
         * BuildMLTransferType object for each selected element. We know how many
         * elements are in the selection, so create a BuildMLTransferType for each.
         */
        IStructuredSelection selection = ((IStructuredSelection) treeViewer.getSelection());
        BuildMLTransferType data[] = new BuildMLTransferType[selection.size()];

        /* populate the array */
        int elementNum = 0;
        @SuppressWarnings("unchecked")
        Iterator<Object> iter = selection.iterator();
        while (iter.hasNext()) {
            Object node = iter.next();
            int transferType;

            /* check the type of the tree node (must be a UIAction). */
            if (node instanceof UIAction) {
                transferType = BuildMLTransferType.TYPE_ACTION;
            } else {
                /* we can't proceed, not a recognized type */
                event.doit = false;
                return;
            }

            /*
             * The selected node is valid, create the data to pass to the drag/drop framework.
             */
            int id = ((UIInteger) node).getId();
            data[elementNum++] = new BuildMLTransferType(buildStore.toString(), transferType, id);
        }
        ;

        /* 
         * We now have a complete array of BuildMLTransferType[], each entry represents
         * a unique UIAction that was part of our selection.
         */
        event.data = data;
    }
}

From source file:com.buildml.eclipse.packages.handlers.HandlerMoveToPackage.java

License:Open Source License

/**
 * @param selection The current Eclipse selection
 * @return A list of valid business objects (UIAction, UIFileGroup, etc) that have been
 * selected by the user. Returns null if any non-valid objects were selected. Note that
 * connection arrows are silently ignored, rather than flagged as invalid.
 *///  w w w  .  j a  va2  s  .c  o  m
private List<MemberDesc> getSelectedObjects(IStructuredSelection selection) {

    /* we'll return a list of valid business objects */
    List<MemberDesc> result = new ArrayList<MemberDesc>();

    Iterator<Object> iter = selection.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();

        /* Graphiti shapes */
        if (obj instanceof GraphitiShapeEditPart) {
            GraphitiShapeEditPart shape = (GraphitiShapeEditPart) obj;
            Object bo = GraphitiUtils.getBusinessObject(shape.getPictogramElement());
            if (bo instanceof UIAction) {
                result.add(new MemberDesc(IPackageMemberMgr.TYPE_ACTION, ((UIAction) bo).getId(), 0, 0));
            } else if (bo instanceof UIFileGroup) {
                result.add(new MemberDesc(IPackageMemberMgr.TYPE_FILE_GROUP, ((UIFileGroup) bo).getId(), 0, 0));
            }
        }

        /* silently ignore connections */
        else if (obj instanceof GraphitiConnectionEditPart) {
            /* silently do nothing - not an error */
        }

        /* Other objects, selectable from TreeViewers (rather than from Graphiti diagrams) */
        else if (obj instanceof UIAction) {
            result.add(new MemberDesc(IPackageMemberMgr.TYPE_ACTION, ((UIAction) obj).getId(), 0, 0));
        } else if (obj instanceof UIFile) {
            result.add(new MemberDesc(IPackageMemberMgr.TYPE_FILE, ((UIFile) obj).getId(), 0, 0));
        } else if (obj instanceof UIDirectory) {
            // TODO: expand this into files?
            result.add(new MemberDesc(IPackageMemberMgr.TYPE_FILE, ((UIFile) obj).getId(), 0, 0));
        }

        /* else, anything else is invalid */
        else {
            return null;
        }
    }

    /* finally, there must be at least one valid thing selected */
    if (result.size() > 0) {
        return result;
    }
    return null;
}