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:descent.ui.actions.OpenAction.java

License:Open Source License

public void run(IStructuredSelection selection) {
    if (!checkEnabled(selection))
        return;// w  ww.j av a2  s  .  c o  m
    run(selection.toArray());
}

From source file:dk.itu.sdg.language.xwpf.AbstractConverter.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);

    if (selection.size() == 1) {
        Object[] selections = selection.toArray();
        Object fstSelection = selections[0];

        if (fstSelection instanceof IFile) {
            final IFile file = (IFile) fstSelection;

            Job convertToModelJob = new Job("Converting Word File...") {

                @Override//from   w  w w  .j a  va2 s  . com
                protected IStatus run(IProgressMonitor monitor) {

                    try {
                        DocX2Model converter = new DocX2Model(file);
                        EObject modelDocument = converter.transform();
                        //                     converter.saveModel(modelDocument)
                        convert(converter, modelDocument, file);

                        //                     def Model2DocX backConverter = new Model2DocX(modelDocument)
                        //                     def docxDocument = backConverter.transform()
                        //                     backConverter.saveDocX(docxDocument)

                        return Status.OK_STATUS;
                    } catch (Exception e) {
                        e.printStackTrace();
                        return Status.CANCEL_STATUS;
                    }
                }
            };

            convertToModelJob.schedule();
        }
    }

    return null;
}

From source file:e4.handler.E4TemplatePreferencePage.java

License:Open Source License

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

    Object[] objects = selection.toArray();
    if ((objects == null) || (objects.length != 1))
        return;//from ww w  . j  a va 2 s  .  c o m

    TemplatePersistenceData data = (TemplatePersistenceData) selection.getFirstElement();
    edit(data);
}

From source file:e4.handler.E4TemplatePreferencePage.java

License:Open Source License

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

    TemplatePersistenceData[] datas = new TemplatePersistenceData[templates.length];
    for (int i = 0; i != templates.length; i++)
        datas[i] = (TemplatePersistenceData) templates[i];

    export(datas);//from  ww  w.j  a  v  a  2s. c o  m
}

From source file:eclox.ui.DoxyfileSelector.java

License:Open Source License

/**
 * Opens the selection dialog and tells if the user validated to selection.
 *
 * @return   true when a selection was made, false otherwise.
 *//*from w  w w .  j a  va  2s  .c  om*/
public boolean open() {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService()
            .getSelection();
    IStructuredSelection structuredSelection = (selection != null && selection instanceof IStructuredSelection)
            ? (IStructuredSelection) selection
            : new StructuredSelection();
    boolean result = false;

    try {
        ResourceCollector collector = root != null ? ResourceCollector.run(root) : ResourceCollector.run();

        hadDoxyfiles = collector.isEmpty() == false;

        if (collector.isEmpty() == false) {
            ElementTreeSelectionDialog selectionDialog = new ElementTreeSelectionDialog(shell,
                    new MyLabelProvider(), new MyContentProvider());

            selectionDialog.setAllowMultiple(false);
            selectionDialog.setInput(collector.getDoxyfiles());
            selectionDialog.setValidator(new MySelectionValidator());
            selectionDialog.setEmptyListMessage("No Doxyfile found in opened projects.");
            selectionDialog.setMessage("Select a Doxyfile:");
            selectionDialog.setTitle("Doxyfile Selection");
            selectionDialog.setInitialSelections(structuredSelection.toArray());

            // Opens the selection dialog and save the selection.
            if (selectionDialog.open() == ElementTreeSelectionDialog.OK) {
                doxyfile = (IFile) selectionDialog.getFirstResult();
                result = true;
            }
        }
    } catch (Throwable t) {
        eclox.ui.Plugin.log(t);
    }

    return result;
}

From source file:edu.buffalo.cse.green.editor.DiagramEditor.java

License:Open Source License

/**
 * Creates a new editor using the given selection.
 * // ww  w .j  a v  a2  s. co m
 * @param selection - The selection of elements to add to the editor.
 * @return The editor that was created.
 */
public static DiagramEditor createEditor(IStructuredSelection selection) throws JavaModelException {

    for (Object element : selection.toArray()) {
        if (element instanceof IJavaElement) {
            return createEditor((IJavaElement) element);
        }
    }

    return null;
}

From source file:edu.washington.cs.cupid.wizards.popup.actions.CreatePipelineContextAction.java

License:Open Source License

/**
 * @see IActionDelegate#run(IAction)/*from w  w w . j  a v a 2  s  . c o  m*/
 */
public void run(IAction action) {

    CreatePipelineWizard wizard = null;

    if (selection.isEmpty()) {
        wizard = new CreatePipelineWizard();
    } else if (selection instanceof IStructuredSelection) {

        IStructuredSelection values = (IStructuredSelection) selection;

        if (values.size() == 1) {
            wizard = new CreatePipelineWizard(TypeToken.of(values.getFirstElement().getClass()),
                    values.toArray());
        } else {
            List<Class<?>> classes = Lists.newArrayList();
            for (Object value : values.toList()) {
                classes.add(value.getClass());
            }

            List<Class<?>> common = TypeManager.commonSuperClass(classes.toArray(new Class[] {}));
            if (common.isEmpty()) {
                wizard = new CreatePipelineWizard();
            } else {
                wizard = new CreatePipelineWizard(TypeToken.of(common.get(0)), values.toArray());
            }
        }
    }

    WizardDialog dialog = new WizardDialog(shell, wizard);
    dialog.create();
    dialog.open();
}

From source file:es.sotileza.plugin.handler.Generator.java

License:Creative Commons License

public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);

    if (MessageDialog.openConfirm(window.getShell(), "Confirmacin",
            "Est a punto de sotilizar est aplicacin. Est seguro?")) {

        Object[] element = selection.toArray();
        String resultado = "";
        for (Object o : element) {
            if (o instanceof IFile) {
                IFile f = (IFile) o;/*w ww . ja v a 2s  . c om*/
                if (validaFichero(f)) {
                    try {
                        generadorFinal(f);
                        resultado += "\nAplicacin Sotilizada.";
                    } catch (Exception e) {
                        resultado += "\nAplicacin sotilizada con errores. " + e.getMessage();
                    }
                } else {
                    resultado += "\nLa aplicacin no se ha podido sotilizar.";
                }
            } else {
                resultado += "\nFichero no sotilizable.";
            }
        }
        MessageDialog.openInformation(window.getShell(), "Operacin Finalizada", resultado);
    }

    return null;
}

From source file:eu.aniketos.wp1.ststool.commitments.view.part.CommitmentsView.java

License:Open Source License

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {

    if (!followSelection)
        return;/*from  ww  w.  j ava  2s . c  om*/
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection s = (IStructuredSelection) selection;
        List<String> selectionPattern = new ArrayList<String>();
        for (Object o : s.toArray()) {
            Actor a = resolveElement(o);
            if (a != null)
                selectionPattern.add(a.getName());
        }
        if (selectionPattern.size() > 0)
            setActorsFilter(selectionPattern);
        else if (getActorsFilter() != null)
            setActorsFilter(null);

    }
}

From source file:eu.geclipse.servicejob.ui.actions.DeleteServiceJobAction.java

License:Open Source License

public void selectionChanged(final IAction action, final ISelection selection) {
    this.serviceJobList = new ArrayList<IServiceJob>();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection sselection = (IStructuredSelection) selection;
        for (Object obj : sselection.toArray()) {
            if (obj instanceof IServiceJob) {
                this.serviceJobList.add((IServiceJob) obj);
            }/*from ww  w.  j  a v a  2 s. co m*/
        }
    }
}