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

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

Introduction

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

Prototype

@Override
    public Object[] toArray() 

Source Link

Usage

From source file:org.eclipse.epf.importing.wizards.SelectPluginsToImport.java

License:Open Source License

/**
 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
 *///from   w ww . ja  v a 2s .  c o m
public void selectionChanged(SelectionChangedEvent event) {
    StructuredSelection selection = (StructuredSelection) event.getSelection();
    if (!selection.isEmpty()) {
        Object[] plugin = selection.toArray();
        setDisplayAttributes((PluginInfo) plugin[0]);
    } else {
        clearDisplayAttributes();
    }
}

From source file:org.eclipse.epf.publishing.ui.wizards.SelectConfigPage.java

License:Open Source License

/**
 * Adds event handlers to the wizard page controls.
 *///  w  ww  . jav  a  2 s  . c  o  m
protected void addListeners() {
    configViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                Object[] configs = selection.toArray();
                setBriefDescription((MethodConfiguration) configs[0]);
            }
            setPageComplete(isPageComplete());
            getWizard().getContainer().updateButtons();
        }
    });
}

From source file:org.eclipse.gef4.mvc.fx.ui.parts.SelectionForwarder.java

License:Open Source License

@Override
public void selectionChanged(SelectionChangedEvent event) {
    ISelection selection = event.getSelection();
    if (selection instanceof StructuredSelection) {
        StructuredSelection sel = (StructuredSelection) selection;
        if (sel.isEmpty()) {
            selectionModel.prependToSelection(Collections.<IContentPart<VR, ? extends VR>>emptyList());
        } else {/*from w  ww  . ja  v  a2 s . c o  m*/
            // find the content parts associated with the selection
            Object[] selected = sel.toArray();
            List<IContentPart<VR, ? extends VR>> parts = new ArrayList<>(selected.length);
            for (Object content : selected) {
                IContentPart<VR, ? extends VR> part = viewer.getContentPartMap().get(content);
                if (part != null) {
                    parts.add(part);
                }
            }
            // set the content parts as the new selection on the
            // SelectionModel
            if (!selectionModel.getSelection().equals(parts)) {
                selectionModel.prependToSelection(parts);
            }
        }
    }
}

From source file:org.eclipse.gef4.zest.fx.jface.ZestContentViewer.java

License:Open Source License

@Override
public void setSelection(ISelection selection, boolean reveal) {
    if (selection.isEmpty()) {
        getSelectionModel().clearSelection();
    } else if (selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        if (!structuredSelection.isEmpty()) {
            List<IContentPart<javafx.scene.Node, ? extends javafx.scene.Node>> toBeSelectedParts = new ArrayList<>();
            for (Object toBeSelectedContent : structuredSelection.toArray()) {
                IContentPart<javafx.scene.Node, ? extends javafx.scene.Node> toBeSelectedPart = viewer
                        .getContentPartMap().get(toBeSelectedContent);
                if (toBeSelectedPart != null) {
                    toBeSelectedParts.add(toBeSelectedPart);
                    if (reveal) {
                        // TODO: we need to reveal all in a single step
                        viewer.reveal(toBeSelectedPart);
                    }/* ww w  . j  a v  a 2 s  .c  om*/
                } else {
                    throw new IllegalArgumentException(
                            toBeSelectedContent + " is not visualized by a content part of this viewer.");
                }
            }
            getSelectionModel().prependToSelection(toBeSelectedParts);
        }
    } else {
        throw new IllegalArgumentException(
                "A non-empty selection of unsupported type '" + selection.getClass() + "' was passed in.");
    }
}

From source file:org.eclipse.gef4.zest.fx.ui.jface.ZestContentViewer.java

License:Open Source License

@Override
public void setSelection(ISelection selection, boolean reveal) {
    if (this.selection != selection && (this.selection == null || !this.selection.equals(selection))) {
        this.selection = selection;
        fireSelectionChanged(new SelectionChangedEvent(this, selection));
        if (reveal) {
            if (selection instanceof StructuredSelection) {
                // TODO: Find a better place to parse an ISelection.
                StructuredSelection sel = (StructuredSelection) selection;
                if (!sel.isEmpty()) {
                    for (Object content : sel.toArray()) {
                        IContentPart<javafx.scene.Node, ? extends javafx.scene.Node> part = viewer
                                .getContentPartMap().get(content);
                        if (part != null) {
                            viewer.reveal(part);
                        }/*  ww  w.  j a v a 2 s.c  o  m*/
                    }
                }
            }
        }
    }
}

From source file:org.eclipse.gyrex.admin.ui.internal.widgets.FilteredItemsSelectionDialog.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  w  w w  .j a v  a  2s  .c  om
 * @param selection
 *            the new selection
 */
@SuppressWarnings("unchecked")
protected void handleSelected(final StructuredSelection selection) {
    IStatus status = new Status(IStatus.OK, AdminUiActivator.SYMBOLIC_NAME, IStatus.OK, EMPTY_STRING, null);

    final Object[] lastSelection = currentSelection;

    currentSelection = selection.toArray();

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

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

        currentSelection = null;

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

        final List<Object> items = selection.toList();

        Object item = null;
        IStatus tempStatus = null;

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

            item = o;
            tempStatus = validateItem(item);

            if (tempStatus.isOK()) {
                status = new Status(IStatus.OK, AdminUiActivator.SYMBOLIC_NAME, 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(currentSelection, null);
        }
    }

    refreshDetails();
    updateStatus(status);
}

From source file:org.eclipse.n4js.tests.bugs.SelectAllProjectExplorer_PluginUITest.java

License:Open Source License

/***/
@Test/*from   w ww .ja v  a2 s  .  c o  m*/
public void testSelectAllCommand() throws ExecutionException {
    // Set projects as top level
    broker.setWorkingSetTopLevel(false);
    waitForIdleState();

    commonViewer.expandToLevel(2);
    waitForIdleState();

    // Make sure project explorer is in focus
    projectExplorer.setFocus();
    // Select all
    executeSelectAllCommand();
    waitForIdleState();

    // Test navigator selection to be complete
    StructuredSelection navigatorSelection = (StructuredSelection) commonViewer.getSelection();
    assertSelectionContainsAccessibleWorkspace(Arrays.asList(navigatorSelection.toArray()));

    assertContextMenuNoActionDuplicates();

    // Test context menu behavior
    assertContextMenuContains("Open Project", "Close Project");

    // If all is selected, there can't be unrelated projects
    assertContextMenuDoesNotContain("Close Unrelated Projects");
}

From source file:org.eclipse.n4js.ui.navigator.internal.N4JSNavigatorActionProvider.java

License:Open Source License

@Override
public void setContext(final ActionContext context) {
    super.setContext(context);

    projectGroup.setContext(context);//  ww  w  .  j  a va2s.  co m

    // context is null if disposal of the provider is triggered
    if (null != context) {
        StructuredSelection selection = (StructuredSelection) context.getSelection();
        List<Object> selectedElements = Arrays.asList(selection.toArray());

        selectionContainsWorkingSet = selectedElements.stream()
                .anyMatch(element -> element instanceof WorkingSet);

        // try to minimize number of context updates for working set action provider
        if (selectionContainsWorkingSet) {
            workingSetActionProvider.setContext(context);
        }

        assignWorkingSetsAction.selectionChanged(selection);
    }
}

From source file:org.eclipse.osee.ote.ui.define.viewers.DragDropHandler.java

License:Open Source License

private void performDrop(DropTargetEvent e) throws OseeCoreException {
    Object object = e.data;/* w  w  w.  j a  va2s. c  o  m*/
    if (object instanceof ArtifactData) {
        handleArtifactDrops((ArtifactData) object);
    } else if (object instanceof TreeSelection) {
        StructuredSelection selection = (StructuredSelection) object;
        if (selection.size() > 0) {
            URI[] iFiles = toResourceArray(selection.toArray());
            if (iFiles.length > 0) {
                try {
                    handleResourceDrops(iFiles);
                } catch (OseeCoreException ex) {
                    OseeLog.log(OteUiDefinePlugin.class, Level.SEVERE, ex);
                }
            } else {
                OseeLog.log(OteUiDefinePlugin.class, Level.WARNING, "No valid files dropped");
            }
        }
    }
}

From source file:org.eclipse.pde.internal.ui.editor.actions.ToggleExpandStateAction.java

License:Open Source License

public void toggleExpandState(int state, StructuredSelection selection) {
    TreeItem[] items = fExtensionTree.getTree().getSelection();
    if (state == NEEDS_EXPAND) { // expand sub tree
        traverseChildrenAndSetExpanded(items); // load non-expanded children
        fExtensionTree.refresh();/*from www  . j  a  v  a  2  s.c  o m*/
        expandChildrenElements(selection.toArray(), true);
        fExtensionTree.setSelection(selection, false);
    } else { // collapse sub tree
        for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
            fExtensionTree.setExpandedState(iterator.next(), false);
        }
    }
}