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

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

Introduction

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

Prototype

@Override
    public Iterator iterator() 

Source Link

Usage

From source file:org.mwc.cmap.core.ui_support.DragDropSupport.java

License:Open Source License

@SuppressWarnings("rawtypes")
public void drop(final DropTargetEvent event) {
    // hmm, what type of data are we receiving, is it a file?
    if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
        final String[] names = (String[]) event.data;
        final String fileName = names[0];
        final File theFile = new File(fileName);
        if (theFile.exists()) {
            // right, is it our correct type?

            // is it an xml file
            final int fileSep = fileName.lastIndexOf('.');
            final String suffix = fileName.substring(fileSep + 1);
            final String uSuffix = suffix.toUpperCase();
            if (uSuffix.equals("XML")) {
                // hey, could be. Extract the first 100 characters
                try {
                    final FileReader fr = new FileReader(theFile);
                    BufferedReader re = new BufferedReader(fr);
                    String firstLine = re.readLine();

                    // get some more data
                    boolean inComplete = true;
                    while ((firstLine != null) && (firstLine.length() < 200) && (inComplete)) {
                        final String newLine = re.readLine();
                        if (newLine == null)
                            inComplete = false;

                        firstLine += newLine;
                    }/*  www. ja v  a2  s.c o m*/

                    re.close();
                    re = null;

                    // our text (called firstLine) should have around 200 chars in it
                    // now.

                    // does it have an xml declaration
                    int index = firstLine.indexOf("<?");

                    // hey, either the number is looking at the first occurence
                    // of the declaration, or it's looking at minus one. switch
                    // minus one to zero, so we can get started
                    if (index == -1)
                        index = 0;
                    else
                        index = Math.max(index, 5);

                    // now find the next xml marker
                    index = firstLine.indexOf('<', index);

                    // now, find the end of this XML item
                    final int endOfElement = firstLine.indexOf(" ", index);
                    final String thisElement = firstLine.substring(index + 1, endOfElement);

                    // do we have any loaders?
                    if (_myDropHelpers != null) {
                        for (final Iterator<XMLFileDropHandler> iter = _myDropHelpers.iterator(); iter
                                .hasNext();) {
                            final XMLFileDropHandler handler = (XMLFileDropHandler) iter.next();

                            // right, does it handle this kind of element?
                            if (handler.handlesThis(thisElement)) {
                                // yup, can it drop on our target?
                                final Object tgt = event.item.getData();
                                if (tgt instanceof EditableWrapper) {
                                    final EditableWrapper ew = (EditableWrapper) tgt;
                                    if (handler.canBeDroppedOn(ew.getEditable())) {
                                        // yes, go for it!
                                        handler.handleDrop(new FileInputStream(theFile), ew.getEditable(),
                                                ew.getLayers());
                                        break;
                                    }
                                }
                            }
                        }
                    }

                } catch (final FileNotFoundException e) {
                    CorePlugin.logError(Status.ERROR, "File not found for drag/drop:" + fileName, e);
                } catch (final IOException e) {
                    CorePlugin.logError(Status.ERROR, "IOException handling drag/drop:" + fileName, e);
                }
            } else {
                // no chance
            }

            // hmm, does it start off with <SC
        }
    } else {

        final StructuredSelection sel = getSelection();

        // cycle through the elements
        for (final Iterator iter = sel.iterator(); iter.hasNext();) {
            final EditableWrapper thisP = (EditableWrapper) iter.next();
            final Editable dragee = thisP.getEditable();

            // right, are we cutting?
            if ((_oldDetail & DND.DROP_MOVE) != 0) {
                // remove from current parent
                final EditableWrapper parent = thisP.getParent();

                // is this a top-level item?
                if (parent == null) {
                    final Layers layers = thisP.getLayers();
                    layers.removeThisLayer((Layer) dragee);
                } else {
                    final BaseLayer parentLayer = (BaseLayer) parent.getEditable();
                    parentLayer.removeElement(dragee);
                }
            }

            // add to new parent
            final TreeItem ti = (TreeItem) event.item;
            final EditableWrapper destination = (EditableWrapper) ti.getData();

            // ok, we need to add a new instance of the dragee (so we can support
            // multiple instances)
            final Editable newDragee = (Editable) RightClickCutCopyAdaptor.cloneThis(dragee);

            // also add it to the plottable layer target
            final BaseLayer dest = (BaseLayer) destination.getEditable();
            dest.add(newDragee);
        }
    }
    // fire update
    final Layers destL = (Layers) _parent.getInput();
    destL.fireExtended();
}

From source file:org.mwc.cmap.grideditor.table.actons.GridEditorActionGroup.java

License:Open Source License

@Override
public void fillContextMenu(final IMenuManager menu) {
    initActions();//w  ww  .ja  va 2  s.  co m
    menu.add(myInsertRowAction);
    menu.add(myDeleteRowAction);
    menu.add(myInterpolateAction);
    menu.add(new Separator());
    menu.add(myExportAction);
    menu.add(new Separator());
    menu.add(myShowVisItemsAction);
    menu.add(myTrackSelectionAction);
    menu.add(new Separator());

    // right, find the selection
    final StructuredSelection sel = (StructuredSelection) myView.getUI().getTable().getTableViewer()
            .getSelection();

    // do we have something?
    if (sel.size() > 0) {

        // create an array of the items being edited
        final Editable[] items = new Editable[sel.size()];
        int index = 0;
        @SuppressWarnings("rawtypes")
        final Iterator iter = sel.iterator();
        while (iter.hasNext()) {
            items[index++] = (Editable) iter.next();
        }

        // collate the other metadata
        final GriddableWrapper wrapper = (GriddableWrapper) myView.getUI().getTable().getTableViewer()
                .getInput();

        // fill the layers objects
        final Layer[] topLayers = new Layer[sel.size()];
        final Layer[] parentLayers = new Layer[sel.size()];
        for (int i = 0; i < sel.size(); i++) {
            topLayers[i] = wrapper.getWrapper().getTopLevelLayer();
            parentLayers[i] = wrapper.getWrapper().getTopLevelLayer();
        }
        final Layers theLayers = wrapper.getWrapper().getLayers();

        // create a drop-down menu for this item
        RightClickSupport.getDropdownListFor(menu, items, topLayers, parentLayers, theLayers, true);
    }
}

From source file:org.mwc.debrief.core.editors.PlotOutlinePage.java

License:Open Source License

/**
 * find out if the selection is valid for setting as primary
 * /* ww w. ja  va  2s.  c  o m*/
 * @param ss
 * @return
 */
protected boolean isValidSecondary(final StructuredSelection ss) {
    boolean res = false;
    if (ss.size() >= 1) {
        Iterator<?> iter = ss.iterator();
        while (iter.hasNext()) {
            EditableWrapper pw = (EditableWrapper) iter.next();
            final Editable pl = pw.getEditable();
            if (!(pl instanceof WatchableList)) {
                // nope - we can just make them all secondaries! drop out
                res = false;
                break;
            } else {
                // hey, it's a maybe.
                res = true;

                // ok, it's a candidate. now see if it's already one of the secondaries
                if (_theTrackDataListener == null) {
                    CorePlugin.logError(Status.INFO,
                            "PROBLEM: Outline View does not hold track data listener.  Maintaner to track this occurrence",
                            null);
                } else {
                    final WatchableList[] secs = _theTrackDataListener.getSecondaryTracks();
                    if (secs != null) {
                        for (int i = 0; i < secs.length; i++) {
                            final WatchableList thisList = secs[i];
                            if (thisList == pl) {
                                res = false;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return res;
}

From source file:org.mwc.debrief.track_shift.views.BaseStackedDotsView.java

License:Open Source License

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it.// w w  w  .  j av  a  2  s  .c  o  m
 */
@Override
public void createPartControl(final Composite parent) {

    _holder = new ChartComposite(parent, SWT.NONE, null, 400, 600, 300, 200, 1800, 1800, true, true, true, true,
            true, true) {
        @Override
        public void mouseUp(MouseEvent event) {
            super.mouseUp(event);
            JFreeChart c = getChart();
            if (c != null) {
                c.setNotify(true); // force redraw
            }
        }
    };

    // hey - now create the stacked plot!
    createStackedPlot();

    // /////////////////////////////////////////
    // ok - listen out for changes in the view
    // /////////////////////////////////////////
    _selProviders = new Vector<ISelectionProvider>();
    _mySelListener = new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ISelection sel = event.getSelection();
            final Vector<DraggableItem> dragees = new Vector<DraggableItem>();
            if (sel instanceof StructuredSelection) {
                final StructuredSelection str = (StructuredSelection) sel;
                final Iterator<?> iter = str.iterator();
                while (iter.hasNext()) {
                    final Object object = (Object) iter.next();
                    if (object instanceof EditableWrapper) {
                        final EditableWrapper ew = (EditableWrapper) object;
                        final Editable item = ew.getEditable();
                        if (item instanceof DraggableItem) {

                            dragees.add((DraggableItem) item);
                        }
                    } else {
                        return;
                    }
                }

                // ok, we've just got draggable items - override the current
                // item
                _draggableSelection = dragees;
            }
        }
    };

    // sort out the part monitor
    _myPartMonitor = new PartMonitor(getSite().getWorkbenchWindow().getPartService());

    // now start listening out for people's parts
    watchMyParts();

    // put the actions in the UI
    contributeToActionBars();
}

From source file:org.neuro4j.studio.core.diagram.sheet.Neuro4jPropertySection.java

License:Apache License

/**
 * @generated/*from  w  w  w  . j a va 2s.c  o m*/
 */
public void setInput(IWorkbenchPart part, ISelection selection) {
    if (selection.isEmpty() || false == selection instanceof StructuredSelection) {
        super.setInput(part, selection);
        return;
    }
    final StructuredSelection structuredSelection = ((StructuredSelection) selection);
    ArrayList transformedSelection = new ArrayList(structuredSelection.size());
    for (Iterator it = structuredSelection.iterator(); it.hasNext();) {
        Object r = transformSelection(it.next());
        if (r != null) {
            transformedSelection.add(r);
        }
    }
    // super.setInput(part, new StructuredSelection(transformedSelection));
    selection = new StructuredSelection(transformedSelection);
    IEditingDomainProvider provider = (IEditingDomainProvider) part.getAdapter(IEditingDomainProvider.class);
    if (provider != null) {
        EditingDomain theEditingDomain = provider.getEditingDomain();
        if (theEditingDomain instanceof TransactionalEditingDomain) {
            setEditingDomain((TransactionalEditingDomain) theEditingDomain);
        }
    }

    // Set the eObject for the section, too. The workbench part may not
    // adapt to IEditingDomainProvider, in which case the selected EObject
    // will be used to derive the editing domain.
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
        Object firstElement = ((IStructuredSelection) selection).getFirstElement();

        if (firstElement != null) {
            EObject adapted = unwrap(firstElement);

            if (adapted != null) {
                setEObject(adapted);
            }
        }
    }

    page.selectionChanged(part, selection);
}

From source file:org.nightlabs.base.ui.util.SelectionUtil.java

License:Open Source License

/**
 * //  w  w  w .  ja  va  2  s.  c o  m
 * @param selection the ISelection to check
 * @param clazz the Class which determines which entries are allowed
 * @return a StructuredSelection which contains only Objects from the given
 * selection of the given Class
 */
@SuppressWarnings("unchecked") //$NON-NLS-1$
public static StructuredSelection checkSelection(ISelection selection, Class clazz) {
    if (!selection.isEmpty() && selection instanceof StructuredSelection) {
        List<Object> list = new ArrayList<Object>();
        boolean containsOther = false;
        StructuredSelection s = (StructuredSelection) selection;
        for (Iterator it = s.iterator(); it.hasNext();) {
            Object o = it.next();
            if (clazz.isAssignableFrom(o.getClass())) {
                list.add(o);
            } else {
                containsOther = true;
            }
        }
        if (!containsOther)
            return s;
        else
            return new StructuredSelection(list);
    }
    return StructuredSelection.EMPTY;
}

From source file:org.ow2.aspirerfid.ide.bpwme.diagram.sheet.BusinessStepPropertySection.java

License:Open Source License

public void setInput(IWorkbenchPart part, ISelection selection) {
    if (selection.isEmpty() || false == selection instanceof StructuredSelection) {
        super.setInput(part, selection);
        return;/*from w ww .jav a2s  . c om*/
    }
    final StructuredSelection structuredSelection = ((StructuredSelection) selection);
    ArrayList transformedSelection = new ArrayList(structuredSelection.size());
    for (Iterator it = structuredSelection.iterator(); it.hasNext();) {
        Object r = transformSelection(it.next());
        if (r != null) {
            transformedSelection.add(r);
        }
    }
    super.setInput(part, new StructuredSelection(transformedSelection));

    MasterDataBuilder mdb = MasterDataBuilder.getInstance();
    MainControl mc = MainControl.getMainControl();

    IStructuredSelection selection1 = (IStructuredSelection) getSelection();
    if (selection1.getFirstElement() instanceof org.ow2.aspirerfid.ide.bpwme.impl.OLCBProcImpl) {
        mdb.setOLCBProc(mc.getOLCBProc());
    }

}

From source file:org.seasar.s2junit4plugin.wizard.S2JUnit4SuperInterfaceSelectionDialog.java

License:Apache License

private void addSelectedInterfaces() {
    StructuredSelection selection = getSelectedItems();
    if (selection == null)
        return;/*  w  w  w  .  java2  s. c  o  m*/
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        Object obj = iter.next();
        if (obj instanceof TypeNameMatch) {
            accessedHistoryItem(obj);
            TypeNameMatch type = (TypeNameMatch) obj;
            String qualifiedName = getNameWithTypeParameters(type.getType());
            String message;

            if (fTypeWizardPage.addSuperInterface(qualifiedName)) {
                message = Messages.format(NewWizardMessages.SuperInterfaceSelectionDialog_interfaceadded_info,
                        qualifiedName);
            } else {
                message = Messages.format(
                        NewWizardMessages.SuperInterfaceSelectionDialog_interfacealreadyadded_info,
                        qualifiedName);
            }
            updateStatus(new StatusInfo(IStatus.INFO, message));
        }
    }
}

From source file:org.switchyard.tools.ui.editor.impl.security.SecurityInstanceTable.java

License:Open Source License

/**
 * Remove a multiple selected security configs from the list
 *//* www  .j  av  a  2  s. com*/
protected void removeMultipleFromList() {
    final StructuredSelection ssel = (StructuredSelection) _propertyTreeTable.getSelection();
    if (ssel.getFirstElement() != null && ssel.getFirstElement() instanceof SecurityType) {
        if (_syRoot != null) {
            final SwitchYardType finalRoot = _syRoot;
            _editDomain.getCommandStack().execute(new RecordingCommand(_editDomain) {
                @Override
                protected void doExecute() {
                    Iterator<?> configIter = ssel.iterator();
                    while (configIter.hasNext()) {
                        SecurityType security = (SecurityType) configIter.next();
                        DomainType domain = finalRoot.getDomain();
                        if (domain == null) {
                            domain = SwitchyardFactory.eINSTANCE.createDomainType();
                            finalRoot.setDomain(domain);
                        }
                        SecuritiesType securities = domain.getSecurities();
                        securities.getSecurity().remove(security);
                    }
                }
            });
        }
    }
}

From source file:org.thanlwinsoft.languagetest.eclipse.editors.TestItemEditor.java

License:Open Source License

@SuppressWarnings("unchecked")
public TestItemType[] getSelectedItems() {
    TestItemType[] items = null;/*ww  w  . j ava  2s.  c  o m*/
    ISelection s = tableViewer.getSelection();
    if (s instanceof StructuredSelection) {
        StructuredSelection ss = (StructuredSelection) s;
        items = new TestItemType[ss.size()];
        int row = 0;
        Iterator i = ss.iterator();
        while (i.hasNext()) {
            Object o = i.next();
            if (ss.getFirstElement() instanceof TestItemType) {
                items[row++] = (TestItemType) o;
            }
        }
    }
    return items;
}