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:fr.inria.soctrace.framesoc.ui.views.TraceDetailsView.java

License:Open Source License

private IAction createDelParamsAction() {
    delParamsAction = new Action("Delete property") {
        @Override/*from ww  w  . j  a  v  a  2 s  .  co m*/
        public void run() {

            if (!editingClean())
                return;

            // get the selection
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object[] rows = selection.toArray();
            List<String> params = new ArrayList<>(rows.length);

            StringBuilder sb = new StringBuilder();
            sb.append("Remove the following properties from the selected traces?\n\n");
            sb.append("Properties to remove:\n");
            for (Object row : rows) {
                String name = (String) ((DetailsTableRow) row).getName();
                params.add(name);
                sb.append("* ");
                sb.append(name);
                sb.append("\n");
            }

            if (!MessageDialog.openQuestion(getSite().getShell(), "Remove properties", sb.toString())) {
                return;
            }

            // delete corresponding params in all selected traces
            List<Trace> traces = getSelectedTraces();
            try {
                FramesocManager.getInstance().deleteParams(traces, params);
                showSelection();
            } catch (SoCTraceException e) {
                MessageDialog.openError(getSite().getShell(), "Error",
                        "An error occurred removing the properties.\n" + e.getMessage());
                e.printStackTrace();
            }
        }
    };
    delParamsAction.setImageDescriptor(
            ResourceManager.getPluginImageDescriptor(Activator.PLUGIN_ID, "icons/minus.png"));
    delParamsAction.setEnabled(false);
    return delParamsAction;

}

From source file:fr.inria.soctrace.framesoc.ui.views.TraceDetailsView.java

License:Open Source License

private List<Trace> getSelectedTraces() {
    IStructuredSelection selection = (IStructuredSelection) FramesocBus.getInstance()
            .getVariable(FramesocBusVariable.TRACE_VIEW_CURRENT_TRACE_SELECTION);
    Object[] traceNodes = selection.toArray();
    List<Trace> traces = new ArrayList<>(traceNodes.length);
    for (Object node : traceNodes) {
        traces.add(((TraceNode) node).getTrace());
    }//from   w  w w  . j  a v a  2  s.c  om
    return traces;
}

From source file:gov.redhawk.bulkio.ui.handlers.GetSriHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    final Set<ScaUsesPort> elements = new HashSet<ScaUsesPort>();
    final Map<ScaUsesPort, PlotSource> portToPlotSourceMap = new HashMap<ScaUsesPort, PlotSource>();

    // Launches from an plot view dropdown
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof IPlotView) {
        IPlotView view = (IPlotView) HandlerUtil.getActivePart(event);
        List<PlotSource> sources = view.getPlotPageBook().getSources();
        for (PlotSource source : sources) {
            elements.add(source.getInput());
            portToPlotSourceMap.put(source.getInput(), source);
        }/*from  ww w. jav a2  s. co m*/
    } else if (selection == null) {
        selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
    }

    // Launches from a context menu 
    if (selection != null) {
        for (Object obj : selection.toArray()) {
            ScaUsesPort port = PluginUtil.adapt(ScaUsesPort.class, obj);
            if (port != null) {
                elements.add(port);
            }
        }
    }

    if (elements.isEmpty()) {
        return null;
    }

    for (final ScaUsesPort port : elements) {
        if (port == null) {
            StatusManager.getManager().handle(new Status(IStatus.ERROR, BulkIOUIActivator.PLUGIN_ID,
                    "Failed to find port for SRI Data View", null), StatusManager.LOG);
            continue;
        }

        try {
            IViewPart view = window.getActivePage().showView(SriDataView.ID,
                    SriDataView.createSecondaryId(port), IWorkbenchPage.VIEW_ACTIVATE);
            if (view instanceof SriDataView) {
                final SriDataView sriView = (SriDataView) view;

                Job job = new Job("SRI View setup...") {

                    @Override
                    protected IStatus run(IProgressMonitor monitor) {
                        final ScaItemProviderAdapterFactory factory = new ScaItemProviderAdapterFactory();
                        final StringBuilder name = new StringBuilder();
                        final StringBuilder tooltip = new StringBuilder();
                        SubMonitor subMonitor = SubMonitor.convert(monitor, "Fetching SRI...", elements.size());

                        port.fetchAttributes(subMonitor.newChild(1));
                        List<String> tmpList = new LinkedList<String>();
                        for (EObject eObj = port; !(eObj instanceof ScaDomainManagerRegistry)
                                && eObj != null; eObj = eObj.eContainer()) {
                            Adapter adapter = factory.adapt(eObj, IItemLabelProvider.class);
                            if (adapter instanceof IItemLabelProvider) {
                                IItemLabelProvider lp = (IItemLabelProvider) adapter;
                                String text = lp.getText(eObj);
                                if (text != null && !text.isEmpty()) {
                                    tmpList.add(0, text);
                                }
                            }
                        }

                        String nameStr = port.getName();
                        if (nameStr != null && nameStr != null && !nameStr.isEmpty()) {
                            name.append(nameStr + " SRI ");
                        }

                        if (!tmpList.isEmpty()) {
                            for (Iterator<String> i = tmpList.iterator(); i.hasNext();) {
                                tooltip.append(i.next());
                                if (i.hasNext()) {
                                    tooltip.append(" -> ");
                                } else {
                                    tooltip.append(" -> SRI");
                                }
                            }
                            tooltip.append("\n");
                        }

                        PlotSource source = portToPlotSourceMap.get(port);

                        if (source != null) {
                            String connectionId = source.getBulkIOBlockSettings().getConnectionID();
                            sriView.activateReceiver(port, connectionId);
                        } else {
                            sriView.activateReceiver(port);
                        }

                        factory.dispose();
                        if (name.length() > 0 || tooltip.length() > 0) {
                            Display display = window.getWorkbench().getDisplay();
                            display.asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    if (name.length() > 0) {
                                        sriView.setPartName(name.toString());
                                    }
                                    if (tooltip.length() > 0) {
                                        sriView.setTitleToolTip(tooltip.toString());
                                    }
                                }
                            });
                        }
                        return Status.OK_STATUS;
                    }
                };
                job.schedule();
            }
        } catch (PartInitException e) {
            StatusManager.getManager().handle(
                    new Status(IStatus.ERROR, BulkIOUIActivator.PLUGIN_ID, "Failed to show SRI Data View", e),
                    StatusManager.LOG | StatusManager.SHOW);
        }
    }

    return null;
}

From source file:gov.redhawk.datalist.ui.handlers.DataListHandler.java

License:Open Source License

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    if (selection == null) {
        selection = HandlerUtil.getCurrentSelection(event);
    }//ww  w .  j  a v  a  2s  .  c  o m
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        final IStructuredSelection ss = (IStructuredSelection) selection;
        for (final Object obj : ss.toArray()) {
            final ScaUsesPort port = PluginUtil.adapt(ScaUsesPort.class, obj, true);
            if (port != null) {
                try {
                    final IViewPart view = window.getActivePage().showView(DataListView.ID,
                            String.valueOf(port.hashCode()), IWorkbenchPage.VIEW_ACTIVATE);
                    if (view instanceof DataListView) {
                        final DataListView dView = (DataListView) view;
                        dView.setInput(port);
                    }
                } catch (final PartInitException e) {
                    e.fillInStackTrace();
                    DataListPlugin.getDefault().getLog().log(new Status(Status.WARNING,
                            DataListPlugin.PLUGIN_ID, "Problem initializing part.", e));
                }
            }
        }
    }
    return null;
}

From source file:gov.redhawk.frontend.ui.internal.AllocateHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    if (selection == null) {
        selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
    }/*  w w w.  j  ava  2 s  .com*/

    if (selection.getFirstElement() instanceof TunerStatus && selection.size() > 1) {
        Object[] items = selection.toArray();
        TunerStatus[] tuners = castArray(items, new TunerStatus[0]);
        if (tuners.length > 0) {
            WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                    new TunerAllocationWizard(tuners[0]));
            dialog.open();
        }
    } else {
        Object obj = selection.getFirstElement();
        if (obj instanceof UnallocatedTunerContainer) {
            UnallocatedTunerContainer container = (UnallocatedTunerContainer) obj;
            TunerStatus[] tuners = getUnallocatedTunersOfType(container.getTunerContainer(),
                    container.getTunerType());
            if (tuners.length > 0) {
                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                        new TunerAllocationWizard(tuners[0]));
                dialog.open();
            }
        } else if (obj instanceof TunerContainer) {
            TunerContainer container = (TunerContainer) obj;
            TunerStatus[] tuners = container.getTunerStatus().toArray(new TunerStatus[0]);
            if (tuners.length > 0) {
                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                        new TunerAllocationWizard(tuners[0]));
                dialog.open();
            } else {
                ScaDevice<?> device = ScaEcoreUtils.getEContainerOfType(container, ScaDevice.class);
                if (device != null) {
                    WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                            new TunerAllocationWizard(FrontendFactory.eINSTANCE.createTunerStatus(), device));
                    warnNoTuners(event);
                    dialog.open();
                } else {
                    MessageDialog warning = new MessageDialog(HandlerUtil.getActiveShell(event),
                            "Error - No Device Found", null, "The device could not be found.",
                            MessageDialog.ERROR, new String[] { "OK" }, 0);
                    warning.open();
                    return null;
                }
            }
        } else if (obj instanceof ScaDevice<?>) {
            ScaDevice<?> device = (ScaDevice<?>) obj;
            TunerContainer container = TunerUtils.INSTANCE.getTunerContainer(device);
            if (container == null) {
                MessageDialog warning = new MessageDialog(HandlerUtil.getActiveShell(event),
                        "Error - No Tuner Container Found", null,
                        "The device's tuner container could not be found.  Make sure the device's \"Data Providers Enabled\" property is set to \"true\".",
                        MessageDialog.ERROR, new String[] { "OK" }, 0);
                warning.open();
                return null;
            }
            TunerStatus[] tuners = container.getTunerStatus().toArray(new TunerStatus[0]);
            if (tuners.length > 0) {
                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                        new TunerAllocationWizard(tuners[0]));
                dialog.open();
            } else {
                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                        new TunerAllocationWizard(FrontendFactory.eINSTANCE.createTunerStatus(), device));
                warnNoTuners(event);
                dialog.open();
            }
        }
    }

    return null;
}

From source file:gov.redhawk.ide.dcd.internal.ui.handlers.LaunchDeviceManager.java

License:Open Source License

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    final List<DeviceManagerLaunchConfiguration> launchConfigs = new ArrayList<DeviceManagerLaunchConfiguration>();

    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;
        for (final Object obj : ss.toArray()) {
            if (obj instanceof DeviceConfiguration) {
                launchConfigs.add(new DeviceManagerLaunchConfiguration(null, (DeviceConfiguration) obj,
                        (DebugLevel) null, null)); // The debug level will be correctly placed in later. 
            }/*ww  w . j a  va 2s .c o  m*/
        }

        if (launchConfigs.size() > 0) {

            final LaunchDeviceManagerDialog dialog = new LaunchDeviceManagerDialog(
                    HandlerUtil.getActiveShell(event));

            if (dialog.open() == Window.OK) {
                final Object[] result = dialog.getResult();
                ScaDomainManager tmpDomMgr = null;

                if (result.length > 0 && result[0] instanceof ScaDomainManager) {
                    tmpDomMgr = (ScaDomainManager) result[0];
                }

                DeviceManagerLaunchConfiguration conf = dialog.getConfiguration();
                // If Default was chosen then tmpDomMgr is null.
                final ScaDomainManager domMgr = tmpDomMgr;
                String domainName = (domMgr == null) ? "" : domMgr.getName();

                // Go through and set the debug Level for them all.  Currently the GUI only allows a single debug level to be applied to all of them.
                for (DeviceManagerLaunchConfiguration entry : launchConfigs) {
                    entry.setDebugLevel(conf.getDebugLevel());
                    entry.setAdditionalArguments(conf.getAdditionalArguments());
                    entry.setDomainName(domainName);
                }
                final Job refreshJob;
                if (domMgr != null) {
                    refreshJob = new Job("Refreshing Device Managers of " + domMgr.getName()) {

                        @Override
                        protected IStatus run(final IProgressMonitor monitor) {
                            domMgr.fetchDeviceManagers(monitor);
                            return Status.OK_STATUS;
                        }

                    };
                } else {
                    refreshJob = null;
                }

                final Job launchDeviceManagerJob = new UIJob("Launching Device Manager(s)") {

                    @Override
                    public IStatus runInUIThread(final IProgressMonitor monitor) {
                        IStatus retVal = LaunchDeviceManagersHelper.launchDeviceManagers(monitor,
                                launchConfigs);
                        if (retVal.isOK() && refreshJob != null) {
                            refreshJob.schedule();
                        }
                        return retVal;
                    }
                };

                launchDeviceManagerJob.setPriority(Job.LONG);
                launchDeviceManagerJob.schedule();
            }

        }
    }
    return null;
}

From source file:gov.redhawk.ide.debug.internal.ui.ResetHandler.java

License:Open Source License

/**
 * {@inheritDoc}// w  w w.  j  a  va2s .com
 */
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    if (selection == null) {
        selection = HandlerUtil.getCurrentSelection(event);
    }
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;
        for (final Object obj : ss.toArray()) {
            final ScaComponent comp = PluginUtil.adapt(ScaComponent.class, obj);
            if (comp != null) {
                final ScaWaveform waveform = comp.getWaveform();
                if (waveform != null && waveform instanceof LocalScaWaveform) {
                    new ResetJob(comp).schedule();
                }
            }
        }
    }
    return null;
}

From source file:gov.redhawk.ide.sad.internal.ui.handler.MarkExternalHandler.java

License:Open Source License

/**
 * {@inheritDoc}/*from   www .  j a v a 2 s .co  m*/
 */
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    final IStructuredSelection ss = (IStructuredSelection) selection;
    for (final Object obj : ss.toArray()) {
        final Object selectedElement = obj;
        Port port = null;
        SadComponentInstantiation componentInstantiation = null;

        if (selectedElement instanceof EditPart && ((EditPart) selectedElement).getModel() instanceof Node) {
            final Node node = (Node) ((EditPart) selectedElement).getModel();
            if (node.getElement() instanceof EObject
                    && (node.getElement()).eContainer() instanceof SadComponentInstantiation) {
                componentInstantiation = (SadComponentInstantiation) (node.getElement()).eContainer();
            }
        }
        if (componentInstantiation == null) {
            return null;
        }

        EObject componentPort = null;

        final SoftwareAssembly softwareAssembly = SoftwareAssembly.Util
                .getSoftwareAssembly(componentInstantiation.eResource());

        if (selectedElement instanceof UsesPortStubEditPart) {
            final UsesPortStubEditPart editPart = (UsesPortStubEditPart) selectedElement;
            final UsesPortStub uses = (UsesPortStub) ((View) editPart.getModel()).getElement();
            port = findInExternalPorts(uses);
            componentPort = uses;
        } else if (selectedElement instanceof ProvidesPortStubEditPart) {
            final ProvidesPortStubEditPart editPart = (ProvidesPortStubEditPart) selectedElement;
            final ProvidesPortStub provides = (ProvidesPortStub) ((View) editPart.getModel()).getElement();
            port = findInExternalPorts(provides);
            componentPort = provides;
        }
        //         else if (selectedElement instanceof ComponentSupportedInterfaceStubEditPart) {
        //            final ComponentSupportedInterfaceStubEditPart editPart = (ComponentSupportedInterfaceStubEditPart) selectedElement;
        //            final ComponentSupportedInterfaceStub interfacePort = (ComponentSupportedInterfaceStub) ((View) editPart.getModel()).getElement();
        //            port = findInExternalPorts(interfacePort);
        //            componentPort = interfacePort;
        //         }
        if (port != null) {
            final RemoveExternalPortAction action = new RemoveExternalPortAction();
            action.setPort(port);
            action.run();
        } else {
            final AddExternalPortAction action = new AddExternalPortAction();
            action.setComponentInstantiation(componentInstantiation);
            action.setComponentPort(componentPort);
            action.setSoftwareAssembly(softwareAssembly);
            action.run();
        }

    }
    return null;
}

From source file:gov.redhawk.ide.sad.internal.ui.handler.MarkExternalHandler.java

License:Open Source License

@Override
public void setEnabled(final Object evaluationContext) {
    if ((evaluationContext != null) && (evaluationContext instanceof IEvaluationContext)) {
        final IEvaluationContext context = (IEvaluationContext) evaluationContext;
        final Object sel = context.getVariable("selection");
        if (sel instanceof IStructuredSelection) {
            final IStructuredSelection ss = (IStructuredSelection) sel;
            boolean enabled = true;
            for (final Object obj : ss.toArray()) {
                if (obj instanceof IGraphicalEditPart) {
                    final EditorPart editor = (EditorPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                            .getActivePage().getActiveEditor();

                    if ((editor == null) || (editor.getEditorSite().getId().equals(SadEditor.ID))) {
                        enabled = false;
                        break;
                    }/*w ww .  j av a  2s  . com*/

                    final EObject semanticObject = EditPartUtil.getSemanticModelObject((EditPart) obj);
                    if (semanticObject == null || semanticObject instanceof ComponentSupportedInterfaceStub
                            || semanticObject.eContainer() instanceof FindByStub) {
                        enabled = false;
                        break;
                    }
                    final IGraphicalEditPart editPart = (IGraphicalEditPart) obj;
                    if (!editPart.isEditModeEnabled()) {
                        enabled = false;
                        break;
                    }
                }
            }
            this.setBaseEnabled(enabled);
        }
    } else {
        super.setEnabled(evaluationContext);
    }
}

From source file:gov.redhawk.ide.sdr.ui.export.DeployableScaExportWizard.java

License:Open Source License

@Override
public void init(final IWorkbench workbench, final IStructuredSelection initialSelection) {
    this.model = new DeployableScaExportWizardModel();
    this.model.directoryDestination.setValue(SdrUiPlugin.getDefault().getTargetSdrPath().toOSString());
    this.model.directoryExport.setValue(Boolean.TRUE);

    if (initialSelection != null) {
        for (final Object item : initialSelection.toArray()) {
            if (item instanceof IProject) {
                final IProject proj = (IProject) item;
                try {
                    if (proj.hasNature(ScaProjectNature.ID)) {
                        this.model.projectsToExport.add(item);
                    }//from w ww.j  a  v  a  2s  .c  o  m
                } catch (final CoreException e) {
                    RedhawkIDEUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                            RedhawkIDEUiPlugin.PLUGIN_ID, "Unexpected error loading projects", e));
                }
            }
        }
    }
    this.selection = initialSelection;
}