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.vectrace.MercurialEclipse.synchronize.actions.PathAwareAction.java

License:Open Source License

@Override
protected boolean updateSelection(IStructuredSelection selection) {
    // TODO: why do we calculate this only if parent says it should be disabled?
    if (!super.updateSelection(selection)) {
        Object[] array = normalize(selection.toArray());
        for (Object object : array) {
            if (!isSupported(object)) {
                return false;
            }//from  w  ww .ja  v a2  s.  c  o m
        }
        return true;
    }
    return true;
}

From source file:com.vectrace.MercurialEclipse.wizards.MercurialParticipantSynchronizeWizard.java

License:Open Source License

public void init(IWorkbench workbench, IStructuredSelection selection) {
    if (selection != null && !selection.isEmpty()) {
        Object[] array = selection.toArray();
        Set<IProject> roots = new HashSet<IProject>();
        List<IProject> managed = MercurialTeamProvider.getKnownHgProjects();
        for (Object object : array) {
            IResource iResource = ResourceUtils.getResource(object);
            if (iResource != null) {
                IProject another = iResource.getProject();
                for (IProject project : managed) {
                    if (project.equals(another)) {
                        // add project as a root of resource
                        roots.add(project);
                    }/*from  www . j  a v  a 2s . c  o m*/
                }
                if (roots.isEmpty()) {
                    roots.add((IProject) iResource);
                }
            }
        }
        projects = roots.toArray(new IProject[roots.size()]);
    }
}

From source file:com.wdev91.eclipse.copyright.actions.ApplyCopyrightOnSelectionHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    // Creates list of selected files
    List<IFile> resources = new ArrayList<IFile>();
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    for (Object sel : selection.toArray()) {
        if (sel instanceof IFile || sel instanceof IFolder) {
            addFile((IResource) sel, resources);
        } else {//from   w  w w . j a  v a 2s.  com
            Object ao = null;
            if (sel instanceof IAdaptable) {
                ao = ((IAdaptable) sel).getAdapter(IFile.class);
                if (ao == null) {
                    ao = ((IAdaptable) sel).getAdapter(IFolder.class);
                }
            }
            if (ao == null) {
                ao = findJavaResource(sel);
            }
            if (ao != null) {
                addFile((IResource) ao, resources);
            }
        }
    }

    // List of projects containing the selected files, with analyze if wizard is needed
    List<IProject> projects = new ArrayList<IProject>();
    boolean wizard = false;
    for (IFile f : resources) {
        IProject p = f.getProject();
        if (!projects.contains(p)) {
            projects.add(p);
            ProjectPreferences prefs;
            if ((prefs = CopyrightManager.getProjectPreferences(p)) == null || prefs.getHeaderText() == null)
                wizard = true;
        }
    }

    // Apply the copyrights
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    if (wizard) {
        ApplyCopyrightWizard.openWizard(shell, projects, resources);
    } else {
        if (MessageDialog.openConfirm(shell, Messages.ApplyCopyrightOnSelectionHandler_messageTitle,
                NLS.bind(Messages.ApplyCopyrightOnSelectionHandler_confirmMessage, resources.size()))) {
            CopyrightSettings settings = new CopyrightSettings();
            settings.setFiles(resources.toArray(new IFile[] {}));
            CopyrightManager.applyCopyrightJob(settings);
        }
    }

    return null;
}

From source file:com.windowtester.eclipse.ui.viewers.EventSequenceTreeViewer.java

License:Open Source License

protected ISemanticEvent[] getEvents(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    return adapt(selection.toArray());
}

From source file:com.zeus.eclipsePlugin.model.ModelSelection.java

License:Open Source License

/**
 * This can be used to create a ModelSelection from a generic structured 
 * selection. If the passed in StructuredSelection is a model selection,
 * then it is just returned.//from   www .j  ava  2s.com
 * @param other The selection you want to turn into a ModelSelection
 * @return A model selection containing all the ZXTMs/rules that the
 * passed in selection did.
 */
public static ModelSelection createFromOtherSelection(IStructuredSelection other) {
    if (other instanceof ModelSelection) {
        return (ModelSelection) other;
    } else {
        if (other == null) {
            return new ModelSelection();
        }

        Object[] selection = other.toArray();
        if (selection.length < 1) {
            return new ModelSelection();
        }

        LinkedList<ZXTM> zxtmList = new LinkedList<ZXTM>();
        LinkedList<Rule> ruleList = new LinkedList<Rule>();

        for (int i = 0; i < selection.length; i++) {
            Object data = selection[i];
            if (data instanceof ModelElement) {
                ModelElement element = (ModelElement) data;

                switch (element.getModelType()) {
                case ZXTM:
                    zxtmList.add((ZXTM) element);
                    break;
                case RULE:
                    ruleList.add((Rule) element);
                    break;
                }
            }
        }

        return new ModelSelection(zxtmList, ruleList);
    }
}

From source file:de.cau.cs.kieler.ecoreviz.OpenDiagramHandler.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w w  w.j  ava 2s .co  m*/
 */
@SuppressWarnings("unchecked")
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);

    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection sSelection = (IStructuredSelection) selection;
        final List<EModelElement> listSelection = new LinkedList<EModelElement>();
        if (selection instanceof KlighdTreeSelection) {
            // do not react on selections in KLighD diagrams
            return null;
        }

        // if all elements are either ecore packages or classes
        if (Iterators.all(sSelection.iterator(), EPACKAGE_ECLASS_PREDICATE)) {
            Iterator<EModelElement> emIt = Iterators.filter(sSelection.iterator(), EMODEL_ELEMENT_PREDICATE);
            while (emIt.hasNext()) {
                listSelection.add(emIt.next());
            }
        } else {
            // otherwise check the elements piece by piece for files
            for (Object o : sSelection.toArray()) {
                if (o instanceof IFile) {
                    try {
                        IFile f = (IFile) o;
                        ResourceSet rs = new ResourceSetImpl();
                        Resource r = rs.getResource(
                                URI.createPlatformResourceURI(f.getFullPath().toString(), true), true);
                        if (r.getContents().size() > 0) {
                            if (r.getContents().get(0) instanceof EPackage) {
                                listSelection.add((EModelElement) r.getContents().get(0));
                            }
                        }
                    } catch (Exception e) {
                        StatusManager.getManager().handle(
                                new Status(IStatus.ERROR, PLUGIN_ID, "Could not load selected file.", e),
                                StatusManager.SHOW);
                    }
                } else {
                    handleUnknownSelection(selection);

                    return null;
                }
            }
        }

        EModelElementCollection model = EModelElementCollection.of(listSelection.iterator());

        DiagramViewManager.createView("de.cau.cs.kieler.ecoreviz.EModelElementCollectionDiagram",
                "Ecore Diagram", model, KlighdSynthesisProperties.create());

        return null;
    }

    handleUnknownSelection(selection);

    return null;
}

From source file:de.jwi.ostendoplugin.views.OstendoView.java

License:Open Source License

private void logSelectionChanged(IStructuredSelection selection) {
    LoggedMessage message = (LoggedMessage) selection.getFirstElement();

    // de-selected?
    if (message == null) {
        runAction.setEnabled(false);//from   ww  w .ja  v  a2  s .c o  m
        isLogSelected = false;
        idlViewer.setSelection(new StructuredSelection(new ArrayList()));
        return;
    }

    String fileName = message.file.getName();
    String opName = null;
    currentRequest = null;
    currentReply = null;

    IDLOperation currentOperation = null;

    int n = selection.size();

    if (n == 1) {
        if (message.isRequest()) {
            opName = message.getOperation(plugin.orb);
            currentRequest = message;
            currentReply = null;
        }
    } else if (n == 2) {
        LoggedMessage message2 = (LoggedMessage) selection.toArray()[1];

        if (message.isRequest() && message2.isReply()) {
            opName = message.getOperation(plugin.orb);
            currentRequest = message;
            currentReply = message2;
        } else if (message2.isRequest() && message.isReply()) {
            opName = message2.getOperation(plugin.orb);
            currentRequest = message2;
            currentReply = message;
        }
    }

    if (currentRequest != null) {
        isLogSelected = true;

        currentOperation = plugin.opnames.get(opName);

        if (currentOperation != null) {
            Integer ic = plugin.opnameInstanceCount.get(currentOperation.name);
            if (ic.intValue() == 1) {
                ArrayList l = new ArrayList();
                l.add(currentOperation);
                idlViewer.setSelection(new StructuredSelection(l));
            }
        } else {
            idlViewer.setSelection(new StructuredSelection(new ArrayList()));
        }
    } else {
        isLogSelected = false;

        idlViewer.setSelection(new StructuredSelection(new ArrayList()));
    }
    System.out.println("logSelectionChanged done, isLogSelected: " + isLogSelected);
}

From source file:de.loskutov.anyedit.ui.preferences.AnyEditPreferencePage.java

License:Open Source License

protected void removeFilters() {
    IStructuredSelection selection = (IStructuredSelection) filterViewer.getSelection();
    fileFilterContentProvider.removeFilters(selection.toArray());
}

From source file:de.loskutov.anyedit.ui.preferences.ProjectPreferencePage.java

License:Open Source License

protected void removeFilters() {
    IStructuredSelection selection = (IStructuredSelection) fFilterViewer.getSelection();
    fStepFilterContentProvider.removeFilters(selection.toArray());
}

From source file:de.loskutov.dh.preferences.FilterListEditor.java

License:Open Source License

private void removeFilters() {
    IStructuredSelection selection = (IStructuredSelection) filterViewer.getSelection();
    fileFilterContentProvider.removeFilters(selection.toArray());
}