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

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

Introduction

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

Prototype

public Object[] toArray();

Source Link

Document

Returns the elements in this selection as an array.

Usage

From source file:ac.soton.eventb.roseEditor.properties.ElementLabelProvider.java

License:Open Source License

/**
 * Determine if a multiple object selection has been passed to the label
 * provider. If the objects is a IStructuredSelection, see if all the
 * objects in the selection are the same and if so, we want to provide
 * labels for the common selected element.
 *
 * @param objects//  w  ww. j a  v  a2  s .  c o m
 *            a single object or a IStructuredSelection.
 * @param multiple
 *            first element in the array is true if there is multiple
 *            unequal selected elements in a IStructuredSelection.
 * @return the object to get labels for.
 */
private Object getObject(final Object objects, final boolean multiple[]) {
    Assert.isNotNull(objects);
    Object object = null;
    if (objects instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) objects;
        object = selection.getFirstElement();
        if (selection.size() == 1) {
            // one element selected
            multiple[0] = false;
            return object;
        }
        // multiple elements selected
        multiple[0] = true;
        Class<?> firstClass = typeMapper.mapType(object);
        // determine if all the objects in the selection are the same type
        for (Object next : selection.toArray()) {
            //= i.next();
            Class<?> nextClass = typeMapper.mapType(next);
            if (!nextClass.equals(firstClass)) {
                // two elements not equal == multiple selected unequal
                multiple[0] = false;
                object = null;
                break;
            }
        }
    } else {
        multiple[0] = false;
        object = objects;
    }
    return object;
}

From source file:actions.DeleteAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    selectedObjects.clear();// w ww.j  a v  a2  s.  co m
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        Object[] objects = structedSelection.toArray();
        selectToBeRemoved(objects);
    }
    if (!selectedObjects.isEmpty() && PARENT_FEATURE != null) {
        action.setEnabled(true);
    } else
        action.setEnabled(false);

}

From source file:alma.acs.eventbrowser.parts.ChannelTreePart.java

License:Open Source License

/**
 * See http://www.vogella.com/articles/EclipseJFaceTree/article.html
 *//*from   w  w w.  ja  v  a 2  s.c  om*/
@PostConstruct
public void postConstruct(Composite parent, final IEclipseContext context, EMenuService menuService,
        IEventBroker eventBroker) {
    try {
        eventModel = EventModel.getInstance();
    } catch (Throwable thr) {
        thr.printStackTrace();
        IStatus someStatus = statusReporter.newStatus(IStatus.ERROR, "Connection with NCs failed.", thr);
        statusReporter.report(someStatus, StatusReporter.SHOW);
        throw new RuntimeException(thr);
    }
    //      eventModel.getLogger().info("ChannelTreePart got EventModel instance.");

    statusLineWriter = new StatusLineWriter(eventBroker);

    viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.setContentProvider(new ChannelTreeContentProvider());
    viewer.setLabelProvider(new ChannelTreeLabelProvider());
    // Expand the tree. '2' means to show only the visible top-level nodes.
    viewer.setAutoExpandLevel(2);

    viewer.setComparator(new ServiceViewerComparator());

    // Provide the root node to the ContentProvider
    viewer.setInput(eventModel.getNotifyServicesRoot());

    // Expand with doubleclick
    viewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection thisSelection = (IStructuredSelection) event.getSelection();
            Object selectedNode = thisSelection.getFirstElement();
            viewer.setExpandedState(selectedNode, !viewer.getExpandedState(selectedNode));
        }
    });

    // Attach a selection listener to our tree that will post selections to the ESelectionService
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            selectionService
                    .setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray());
        }
    });

    // TODO: Take care of help system. Here's the E3 code:
    //      // Create the help context id for the viewer's control
    //      PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "alma.acs.eventbrowser.viewer");

    hookContextMenu(menuService);

    // TODO: this could be used by handlers etc, currently it's not
    context.set(ChannelTreePart.class, this);
}

From source file:at.medevit.menus.parts.SelectorPart.java

License:Open Source License

/**
 * Create contents of the view part./* ww  w.  j av  a  2 s .c  o m*/
 */
@PostConstruct
public void createControls(Composite parent) {
    parent.setLayout(new GridLayout(1, false));

    // -- person selector
    Label lblPerson = new Label(parent, SWT.NONE);
    lblPerson.setText("Person");

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    composite.setLayout(new TableColumnLayout());

    selectPersonTV = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
    selectPersonTV.setLabelProvider(new AdapterFactoryLabelProvider(mipaf));
    selectPersonTV.setContentProvider(new AdapterFactoryContentProvider(mipaf));
    selectPersonTV.setInput(SampleModel.getDirectory());
    selectPersonTV.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();

            Person p = (Person) selection.getFirstElement();

            selectionService.setSelection(selection.size() == 1 ? p : selection.toArray());

            if (selection.size() == 1) {
                if (p.getPartner() != null) {
                    partnerPersonTV.setSelection(new StructuredSelection(p.getPartner()));
                } else {
                    partnerPersonTV.setSelection(null);
                }
            }
        }
    });
    ViewerFilter[] filters = new ViewerFilter[] { new PersonViewerFilter(selectPersonTV) };
    selectPersonTV.setFilters(filters);

    menuService.registerContextMenu(selectPersonTV.getTable(), SELECTOR_POPUPMENU_ID);

    // -- partner selector
    Label lblPartner = new Label(parent, SWT.NONE);
    lblPartner.setText("Partner");

    Composite composite2 = new Composite(parent, SWT.NONE);
    composite2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    composite2.setLayout(new TableColumnLayout());

    partnerPersonTV = new TableViewer(composite2, SWT.BORDER | SWT.FULL_SELECTION);
    partnerPersonTV.setLabelProvider(new AdapterFactoryLabelProvider(mipaf));
    partnerPersonTV.setContentProvider(new AdapterFactoryContentProvider(mipaf));
    partnerPersonTV.setInput(SampleModel.getDirectory());

}

From source file:at.spardat.xma.gui.mapper.MapperDialog.java

License:Open Source License

/**
 * Returns the Mdl???-objects selected in the BDTree as array.
 *///from  w ww .j  av a  2  s. c  o  m

private Object[] getSelectedBdMdls() {
    ISelection sel = bdTreeViewer.getSelection();
    if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
        IStructuredSelection sSel = (IStructuredSelection) sel;
        return sSel.toArray();
    }
    return new Object[0];
}

From source file:bndtools.editor.project.ClassPathPart.java

License:Open Source License

private void doRemove() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    classPath.removeAll(selection.toList());
    viewer.remove(selection.toArray());
    markDirty();//from w  w w  .  j a  v a 2s. co  m
}

From source file:ca.mcgill.cs.swevo.qualyzer.handlers.OpenAllHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    CommonNavigator view = (CommonNavigator) page.findView(QualyzerActivator.PROJECT_EXPLORER_VIEW_ID);
    ISelection selection = view.getCommonViewer().getSelection();

    if (selection != null && selection instanceof IStructuredSelection) {
        IStructuredSelection structSelection = (IStructuredSelection) selection;

        for (Object element : structSelection.toArray()) {
            if (element instanceof Participant) {
                ResourcesUtil.openEditor(page, (Participant) element);
            } else if (element instanceof Investigator) {
                ResourcesUtil.openEditor(page, (Investigator) element);
            } else if (element instanceof Transcript) {
                ResourcesUtil.openEditor(page, (Transcript) element);
            } else if (element instanceof WrapperCode) {
                ResourcesUtil.openEditor(page, (WrapperCode) element);
            } else if (element instanceof Memo) {
                ResourcesUtil.openEditor(page, (Memo) element);
            }/*from w  ww  . jav a 2s.  c  o  m*/
        }
    }

    return null;
}

From source file:ca.uvic.cs.tagsea.ui.views.WaypointsComposite.java

License:Open Source License

/**
 * Gets the selected waypoints or returns empty array.
 * @return Waypoint[] the selected waypoints or an empty array
 *///from  w ww  .  j  av  a 2 s. co m
public Waypoint[] getSelectedWaypoints() {
    Waypoint[] wps = new Waypoint[0];
    IStructuredSelection sel = (IStructuredSelection) waypointsTableViewer.getSelection();
    if (!sel.isEmpty()) {
        Object[] array = sel.toArray();
        ArrayList<Waypoint> wpList = new ArrayList<Waypoint>(array.length);
        for (Object obj : array) {
            if (obj instanceof Waypoint) {
                wpList.add((Waypoint) obj);
            }
        }
        wps = new Waypoint[wpList.size()];
        wps = (Waypoint[]) wpList.toArray(wps);
    }
    return wps;
}

From source file:cane.brothers.e4.commander.part.DynamicTab.java

License:Open Source License

@Override
public void selectionChanged(SelectionChangedEvent event) {
    Object prevSelection = selectionService.getSelection();
    if (log.isDebugEnabled()) {
        log.debug("Prev selection is {}", prevSelection); //$NON-NLS-1$
    }//from  w  w w  .j a  v a 2 s.co  m

    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    boolean hasSelection = selection != null && selection.isEmpty() == false;

    if (hasSelection) {
        Object firstElement = selection.getFirstElement();
        if (log.isDebugEnabled()) {
            log.debug("Current selection is {}", firstElement); //$NON-NLS-1$
        }

        // set the selection to the service
        selectionService.setSelection(firstElement);

        if (log.isDebugEnabled()) {
            log.debug("Selection changed:"); //$NON-NLS-1$
        }

        // trace selected objects
        for (Object sel : selection.toArray()) {
            if (sel instanceof PathFixture) {
                PathFixture fixture = (PathFixture) sel;
                if (log.isDebugEnabled()) {
                    log.debug("   " + fixture); //$NON-NLS-1$
                }
            }
        }
    }
}

From source file:ch.elexis.core.ui.util.viewers.CommonViewer.java

License:Open Source License

/**
 * Die aktuelle Auswahl des Viewers liefern
 * /*from w w  w. ja v  a  2  s . com*/
 * @return null oder ein Array mit den selektierten Objekten-
 */
public Object[] getSelection() {
    IStructuredSelection sel = (IStructuredSelection) viewer.getSelection();
    if (sel != null) {
        return sel.toArray();
    }
    return null;

}