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:com.nokia.s60tools.remotecontrol.ftp.ui.view.FtpView.java

License:Open Source License

/**
 * Is selected item(s) a file(s)//from w w  w .ja va  2 s. c  o m
 * @return True if file else false
 */
private boolean isSelectionFile() {
    boolean retVal = false;
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Object[] selectionArray = selection.toArray();

    if (selection.size() > 0) {
        // Checking that all selected items are files.
        for (Object selectedObject : selectionArray) {
            if (FtpFileObject.class.isInstance(selectedObject)) {
                retVal = true;
            } else {
                retVal = false;
                break;
            }
        }
    }

    return retVal;
}

From source file:com.nokia.s60tools.remotecontrol.ftp.ui.view.FtpView.java

License:Open Source License

/**
 * Is size of selection bigger than 1 and does it contain folder(s).
 * @return True if size is bigger than 1 and contains one or more folders, false otherwise.
 *///from   www. j a v  a 2  s.c  om
private boolean isSelectionMultiFolder() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Object[] selectionArray = selection.toArray();

    if (selection.size() > 1) {
        // Checking if there is is folder in selection.
        for (Object selectedObject : selectionArray) {
            if (FtpFolderObject.class.isInstance(selectedObject)) {
                return true;
            }
        }
    }

    return false;
}

From source file:com.nokia.s60tools.testdrop.util.StartUp.java

License:Open Source License

/**
 * Resolves selected project from project explorer
 * //from   ww w . j a  va 2 s.  co m
 * @param action
 *            action
 * @param workbenchPart
 *            workbench part
 * @throws NullPointerException
 *             if there is not selected project form project explorer
 */
public static void setActivePartTargetDialog(IAction action, IWorkbenchPart workbenchPart)
        throws NullPointerException {
    ISelection selection = workbenchPart.getSite().getPage().getSelection();
    IStructuredSelection sel = (IStructuredSelection) selection;
    Object res = sel.getFirstElement();
    if (res instanceof IProject) {
        selectedCfgFiles = null;
        IProject project = ((IResource) res).getProject();
        if (selectedProject == null) {
            selectedProject = project;
        } else {
            if (!selectedProject.getName().equals(project.getName())) {
                selectedProject = project;
                dialogModel = null;
            }
        }
        LogExceptionHandler.log("project name: " + selectedProject.getName());
    } else if (res instanceof IFile) {
        selectedProject = null;
        Object[] cfgObjects = sel.toArray();
        IFile[] cfgFiles = new IFile[cfgObjects.length];
        for (int i = 0; i < cfgObjects.length; i++) {
            cfgFiles[i] = (IFile) cfgObjects[i];
        }
        if (selectedCfgFiles == null) {
            selectedCfgFiles = cfgFiles;
        } else {
            if (!selectedCfgFiles.equals(cfgFiles)) {
                selectedCfgFiles = cfgFiles;
                dialogModel = null;
            }
        }
    }
    if (selectedProject == null && selectedCfgFiles == null) {
        throw new NullPointerException("Not found selected project or file.");
    }
}

From source file:com.nokia.sdt.uidesigner.events.EventPage.java

License:Open Source License

private IComponentInstance[] getInstancesFromSelection(ISelection selection) {
    IComponentInstance[] result = null;/*from ww w .j  av a2 s.  c o  m*/
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;

        // We must be able to get an IComponentInstance for each
        // object in the selection
        Object[] objects = ss.toArray();

        boolean selectionContainsNonInstance = false;
        // the same object can be selected in two parts of the editor, so use a set
        Set<IComponentInstance> instances = new HashSet<IComponentInstance>();
        for (int i = 0; i < objects.length; i++) {
            IComponentInstance ci = convertToInstance(objects[i]);
            if (ci != null) {
                instances.add(ci);
            } else {
                selectionContainsNonInstance = true;
                break;
            }
        }

        if (!selectionContainsNonInstance && (instances.size() > 0)) {
            result = (IComponentInstance[]) instances.toArray(new IComponentInstance[instances.size()]);
        }
    }
    return result;
}

From source file:com.nokia.testfw.codegen.ui.popup.actions.SUTNewTestWizardAction.java

License:Open Source License

public void run(IAction action) {

    if (selection instanceof IStructuredSelection) {
        IStructuredSelection sel = (IStructuredSelection) selection;
        Object[] elements = sel.toArray();
        Set<ICProject> projectSet = new HashSet<ICProject>();
        for (Object element : elements) {
            projectSet.add(((ICElement) element).getCProject());
            if (element instanceof ITranslationUnit) {
                if (!((ITranslationUnit) element).isHeaderUnit()) {
                    MessageBox box = new MessageBox(new Shell(), SWT.ICON_ERROR);
                    box.setText("Impossible to generate test cases");
                    box.setMessage("SymbianUnitTest Case Wizard works only with header files.");
                    box.open();/*w w  w  . j  a v a 2s  .  c o m*/
                    return;
                }
            }
            if (element instanceof IMethodDeclaration
                    && !(((IMethodDeclaration) element).getParent() instanceof IStructure)) {
                MessageBox box = new MessageBox(new Shell(), SWT.ICON_ERROR);
                box.setText("Impossible to generate test cases");
                box.setMessage("SymbianUnitTest Case Wizard works only with header files.");
                box.open();
                return;
            }
        }
        if (projectSet.size() > 1) {
            MessageBox box = new MessageBox(new Shell(), SWT.ICON_ERROR);
            box.setText("Impossible to generate test cases");
            box.setMessage("SymbianUnitTest Case Wizard works only with single project.");
            box.open();
            return;
        }

        SUTNewTestWizard wizard = new SUTNewTestWizard();
        wizard.setShowChooseProjectPage(false);
        wizard.init(part.getSite().getWorkbenchWindow().getWorkbench(), sel);
        // Instantiates the wizard container with the wizard and
        // opens it
        WizardDialog dialog = new WizardDialog(part.getSite().getShell(), wizard);
        dialog.setTitle("New SymbianUnitTest Case(s) Wizard");
        dialog.create();
        dialog.open();
    }
}

From source file:com.nokia.testfw.codegen.ui.preferences.TESTFWTemplatePreferencePage.java

License:Open Source License

private void edit() {
    IStructuredSelection selection = (IStructuredSelection) iTreeViewer.getSelection();

    Object[] objects = selection.toArray();
    if ((objects == null) || (objects.length != 1))
        return;//from   w  ww. j  ava 2 s.  com

    TemplatePersistenceData data = (TemplatePersistenceData) ((PathNode) selection.getFirstElement()).getData();
    if (data != null)
        edit(data);
}

From source file:com.nokia.testfw.codegen.ui.preferences.TESTFWTemplatePreferencePage.java

License:Open Source License

private void export() {
    IStructuredSelection selection = (IStructuredSelection) iTreeViewer.getSelection();
    Object[] nodes = selection.toArray();

    Set<TemplatePersistenceData> dataSet = new HashSet<TemplatePersistenceData>();
    for (int i = 0; i != nodes.length; i++) {
        dataSet.addAll(getChildrenTemplate((PathNode) nodes[i]));
    }/*from www. j  a  va  2s  . c  om*/
    export(dataSet.toArray(new TemplatePersistenceData[0]));
}

From source file:com.nokia.tools.media.utils.editor.frameanimation.FrameAnimationContainer.java

License:Open Source License

public void selectionChanged(final IStructuredSelection selection) {
    final Object first = selection.getFirstElement();
    if (first instanceof IAnimationFrame) {
        if (Display.getCurrent() != null) {
            setFocus((IAnimationFrame) first);
        } else {/*ww w. j  a v  a2  s  . c o  m*/
            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    setFocus((IAnimationFrame) first);
                }
            });
        }
        curNode = (TimeLineNode) selection.toArray()[1];
    } else if (first instanceof TimeLineNode) {
        curNode = (TimeLineNode) first;
    } else {
        curNode = null;
    }
}

From source file:com.nokia.tools.s60.editor.dnd.S60BaseDragListener.java

License:Open Source License

public void dragStart(DragSourceEvent event) {

    event.detail = DND.DROP_NONE;//w w  w .j  a  v  a 2 s .c om
    if (transfer == LocalSelectionTransfer.getInstance()) {
        LocalSelectionTransfer.getInstance().setSelection(null);
    }

    Object selectedData = getSelectedElement(event);
    List<ClipboardContentDescriptor> extendedSelection = null;
    if (selectedData != null) {
        if (DNDUtil.isSelectionDraggeable(selectedData)) {

            IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
            //items from selection            
            if (selection.size() > 1) {
                Object[] test = selection.toArray();
                Object matchedElement = null;
                for (Object item : test) {
                    if (equals(selectedData, item)) {
                        matchedElement = item;
                        break;
                    }
                }
                if (matchedElement != null) {

                    extendedSelection = new ArrayList<ClipboardContentDescriptor>();
                    extendedSelection.add(new ClipboardContentDescriptor(matchedElement,
                            ClipboardContentDescriptor.ContentType.CONTENT_ELEMENT));
                    for (int i = 0; i < test.length; i++) {
                        Object selContent = test[i];
                        if (selContent instanceof IContentData && selContent != matchedElement) {
                            ClipboardContentDescriptor ccd = new ClipboardContentDescriptor(selContent,
                                    ClipboardContentDescriptor.ContentType.CONTENT_ELEMENT);
                            extendedSelection.add(ccd);
                        }
                    }
                }
            }
        } else
            selectedData = null;
    }

    if (selectedData != null) {

        if (transfer == LocalSelectionTransfer.getInstance()) {

            List<ClipboardContentDescriptor> dragContent = null;

            if (extendedSelection == null) {
                dragContent = new ArrayList<ClipboardContentDescriptor>();
                ClipboardContentDescriptor ccd = new ClipboardContentDescriptor(selectedData,
                        ClipboardContentDescriptor.ContentType.CONTENT_ELEMENT);
                dragContent.add(ccd);
            } else {
                dragContent = extendedSelection;
            }

            eventDataLocal = new StructuredSelection(dragContent);
            eventDetail = DND.DROP_COPY;
            LocalSelectionTransfer.getInstance().setSelection((ISelection) eventDataLocal);
            LocalSelectionTransfer.getInstance().setSelectionSetTime(event.time & 0xFFFF);

        } else if (transfer instanceof FileTransfer) {

            if (extendedSelection == null) {
                extendedSelection = new ArrayList<ClipboardContentDescriptor>();
                extendedSelection.add(new ClipboardContentDescriptor(selectedData,
                        ClipboardContentDescriptor.ContentType.CONTENT_ELEMENT));
            }

            Clipboard clip = new Clipboard("");
            List<String> result = new ArrayList<String>();
            for (ClipboardContentDescriptor cc : extendedSelection) {
                selectedData = cc.getContent();
                CopyImageAction copyAction = new CopyImageAction(new SimpleSelectionProvider(selectedData),
                        clip);
                copyAction.setSilent(true);
                if (copyAction.isEnabled())
                    copyAction.run();
                Object possibleFile = ClipboardHelper.getSupportedClipboardContent(clip);
                if (possibleFile instanceof List) {
                    List files = (List) possibleFile;
                    for (Object item : files) {
                        if (item instanceof File)
                            result.add(((File) item).getAbsolutePath());
                    }
                }
            }
            if (result.size() > 0) {
                eventData = result.toArray(new String[result.size()]);
                eventDetail = DND.DROP_COPY;
            }
        }
    }
}

From source file:com.nokia.tools.s60.editor.ui.views.LayersPage.java

License:Open Source License

public void selectionChanged(IWorkbenchPart part, ISelection selection, SkinnableEntity skinnableEntity) {
    if (target != null) {
        target.eAdapters().remove(refreshAdapter);
    }//from  www  .  java 2  s  .  c  o m
    try {
        if (part instanceof ColorsView) {
            return;
        }

        if (part instanceof PropertySheet || part instanceof Series60EditorPart && part != owningEditor)
            return;

        // ------------------------
        if (part == parentView || !(selection instanceof IStructuredSelection))
            return;

        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        boolean selectionIsList = false;
        boolean selectionIsListWithOneElement = false;
        if (structuredSelection.getFirstElement() instanceof List) {
            selectionIsList = true;
            List tempList = (List) (structuredSelection.getFirstElement());
            if (tempList.size() == 1) {
                selectionIsListWithOneElement = true;
            }
        }

        toggleColorModeAction.setEnabled(false);

        if (structuredSelection.size() == 1 && !(selectionIsList && !selectionIsListWithOneElement)) {

            // when selection contains valid contents -
            // EditPart or IContentData, refresh
            Object element = structuredSelection.getFirstElement();
            Object elementToSearch = null;
            if (element instanceof List) {
                elementToSearch = ((List) element).get(0);
            } else {
                elementToSearch = element;
            }
            IContentData cd = findContentData(elementToSearch);
            if (cd != null) {
                target = (EObject) cd.getAdapter(EditObject.class);
            }
            EditPart editPart = (EditPart) (elementToSearch instanceof EditPart ? elementToSearch : null);
            if (isAppTheme(editPart)) {
                _clearViewer();
                return;
            }

            if (cd != null) {

                try {

                    IToolBoxAdapter tba = (IToolBoxAdapter) cd.getAdapter(IToolBoxAdapter.class);
                    if (tba != null && tba.isFile()) {
                        _clearViewer();
                        return;
                    }

                    ISkinnableEntityAdapter sk = (ISkinnableEntityAdapter) cd
                            .getAdapter(ISkinnableEntityAdapter.class);

                    if (null != sk && sk.isColour() && !sk.hasImage()) {
                        IImageAdapter adapter = (IImageAdapter) cd.getAdapter(IImageAdapter.class);

                        IImage image = adapter == null ? null : adapter.getImage();
                        this.cdatas.clear();
                        this.currentParts.clear();
                        this.cdatas.add(cd);
                        this.currentParts.add(editPart);
                        image.removePropertyChangeListener(this);
                        image.addPropertyListener(this);
                        if (treeViewer.getInput() != image && treeViewerLabelProvider != null) {
                            treeViewerLabelProvider.flushImageCache();
                        }

                        try {
                            // parentSelectionIndex, ChildSelectionIndex
                            int[] tSIndex = { -1, -1 };

                            if (true == image.isMultiPiece()) {
                                if (skinnableEntity != null) {
                                    tSIndex = getTreeSelectionForMultipiece(skinnableEntity);
                                }
                            } else {
                                tSIndex = getTreeSelectionForSinglePiece();
                            }

                            treeViewer.setInput(image.getLayer(0).getLayerEffects().get(0));
                            treeViewer.expandAll();
                            makeTreeSelection(tSIndex);

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return;
                    }

                    IImageAdapter adapter = (IImageAdapter) cd.getAdapter(IImageAdapter.class);
                    // adapter can be null for non-theme elements
                    IImage image = adapter == null ? null : adapter.getImage();

                    if (image != null) {
                        this.cdatas.clear();
                        this.currentParts.clear();
                        this.cdatas.add(cd);
                        this.currentParts.add(editPart);

                        image.removePropertyChangeListener(this);
                        image.addPropertyListener(this);
                        if (treeViewer.getInput() != image && treeViewerLabelProvider != null) {
                            treeViewerLabelProvider.flushImageCache();
                        }

                        // parentSelectionIndex, ChildSelectionIndex
                        int[] tSIndex = { -1, -1 };

                        if (true == image.isMultiPiece()) {
                            if (skinnableEntity != null) {
                                tSIndex = getTreeSelectionForMultipiece(skinnableEntity);
                            }
                        } else {
                            tSIndex = getTreeSelectionForSinglePiece();
                        }

                        treeViewer.setInput(image);
                        treeViewer.expandAll();
                        makeTreeSelection(tSIndex);

                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else {
            // when selection contains valid multiselection contents -
            // EditParts or IContentDatas, refresh
            Object[] elements = structuredSelection.toArray();
            ArrayList<IImage> images = new ArrayList<IImage>();
            if (elements.length > 0) {
                this.cdatas = new ArrayList<IContentData>();
                this.currentParts = new ArrayList<EditPart>();

                if (elements[0] instanceof List) {
                    elements = ((List) elements[0]).toArray();
                }
            }
            for (Object element : elements) {
                IContentData cd = findContentData(element);
                if (cd != null) {
                    EObject object = (EObject) cd.getAdapter(EditObject.class);
                    if (object != null) {
                        target = object;
                    }
                }
                EditPart editPart = (EditPart) (element instanceof EditPart ? element : null);

                try {
                    if (null == cd) {
                        _clearViewer();
                        return;
                    }

                    IToolBoxAdapter tba = (IToolBoxAdapter) cd.getAdapter(IToolBoxAdapter.class);
                    if (tba != null && tba.isFile()) {
                        _clearViewer();
                        return;
                    }

                    IImageAdapter adapter = (IImageAdapter) cd.getAdapter(IImageAdapter.class);
                    // adapter can be null for non-theme elements
                    IImage image = adapter == null ? null : adapter.getImage();

                    if (image != null) {
                        this.currentParts.add(editPart);
                        this.cdatas.add(cd);

                        image.removePropertyChangeListener(this);
                        image.addPropertyListener(this);

                        images.add(image);
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            treeViewerLabelProvider.flushImageCache();
            treeViewer.setInput(images);
            treeViewer.expandAll();
        }
        // ------------------------

        SimpleSelectionProvider ssp = new SimpleSelectionProvider((cdatas.size() == 1) ? cdatas.get(0) : null);
        clearAction.setSelectionProvider(ssp);
        clearAction.update();
        animateAction.setSelectionProvider(ssp);
        animateAction.update();
    } finally {
        if (target != null) {
            target.eAdapters().add(refreshAdapter);
        }
    }
}