Example usage for org.eclipse.jface.viewers IStructuredSelection toList

List of usage examples for org.eclipse.jface.viewers IStructuredSelection toList

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection toList.

Prototype

public List toList();

Source Link

Document

Returns the elements in this selection as a List.

Usage

From source file:gov.redhawk.ide.codegen.ui.internal.command.GenerateCodeHandler.java

License:Open Source License

@Override
public void setEnabled(final Object evaluationContext) {
    final IEvaluationContext context = (IEvaluationContext) evaluationContext;
    final IWorkbenchWindow window = (IWorkbenchWindow) context.getVariable("activeWorkbenchWindow");
    if (window == null) {
        setBaseEnabled(false);// w w w .  j  ava2  s.c  om
        return;
    }

    // We check two things.
    // 1.) If the user has right clicked on an item that is appropriate
    // 2.) If not then we check the open active editor.

    // The highest priority check is the right click action. If they have right clicked on something that object is
    // the proper context
    // so we check that first.
    if (context.getVariable("activeMenuSelection") != null
            && context.getVariable("activeMenuSelection") instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) context.getVariable("activeMenuSelection");

        for (Object selection : ss.toList()) {
            if (selection instanceof IFile && isSpdFile((IFile) selection)
                    && waveDevFileExists((IFile) selection)) {
                continue;
            } else if (selection instanceof Implementation) {
                Implementation impl = (Implementation) selection;
                WaveDevSettings wavDev = CodegenUtil.getWaveDevSettings(impl);

                if (wavDev != null) {
                    continue;
                }
            }

            // One of the selections did not meet the tests above.
            setBaseEnabled(false);
            return;
        }

        // If we made it through the for loop then all the objects passed.
        setBaseEnabled(true);
        return;
    } else if (window.getActivePage() != null) {
        // If we've gotten this far we know they have not right clicked on anything so all we need to check is the
        // open active editor
        IWorkbenchPage activePage = window.getActivePage();
        IEditorPart activeEditor = activePage.getActiveEditor();
        if (activeEditor != null) {
            if ((activeEditor.getEditorInput() instanceof FileEditorInput)) {
                IFile spdFile = ((FileEditorInput) activeEditor.getEditorInput()).getFile();
                if (isSpdFile(spdFile)) {
                    setBaseEnabled(waveDevFileExists(spdFile));
                    return;
                }
            }
        }
    }

    // Set to false if none of the appropriate situations are met
    setBaseEnabled(false);
    return;
}

From source file:gov.redhawk.ide.dcd.internal.ui.editor.DevicesSection.java

License:Open Source License

/**
 * Handle delete.// w w w .ja va  2s .c o m
 */
private void handleDelete() {
    final IStructuredSelection selections = ((IStructuredSelection) getTreePart().getViewer().getSelection());

    if (selections != null) {
        List<?> selectionList = selections.toList();
        for (Object selection : selectionList) {
            execute(RemoveCommand.create(getEditingDomain(), getDeviceConfiguration().getPartitioning(),
                    PartitioningPackage.Literals.PARTITIONING__COMPONENT_PLACEMENT, selection));
        }
    }

    this.refresh(this.dcdResource);
}

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

License:Open Source License

/**
 * {@inheritDoc}//from  www.  j  a v  a  2s .  com
 */
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getActiveMenuSelection(event);
    if (sel == null) {
        sel = HandlerUtil.getCurrentSelection(event);
    }
    if (sel instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) sel;
        for (final Object obj : ss.toList()) {
            try {
                handleLaunch(obj, event);
            } catch (final CoreException e) {
                StatusManager.getManager().handle(
                        new Status(IStatus.ERROR, ScaDebugUiPlugin.PLUGIN_ID, e.getLocalizedMessage(), e),
                        StatusManager.LOG | StatusManager.SHOW);
            }
        }
    }
    return null;
}

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

License:Open Source License

@Override
public void setEnabled(Object evaluationContext) {
    final IEvaluationContext context = (IEvaluationContext) evaluationContext;
    final IWorkbenchWindow window = (IWorkbenchWindow) context.getVariable("activeWorkbenchWindow");
    if (window == null) {
        setBaseEnabled(false);//from w  w  w.jav a  2  s .c  om
        return;
    }

    if (context.getVariable("activeMenuSelection") != null
            && context.getVariable("activeMenuSelection") instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) context.getVariable("activeMenuSelection");
        boolean enabled = true;
        out: for (final Object obj : ss.toList()) {
            if (obj instanceof SoftPkg) {
                SoftPkg spd = (SoftPkg) obj;
                for (Implementation impl : spd.getImplementation()) {
                    enabled = checkImpl(impl);
                    if (!enabled) {
                        break out;
                    }
                }
            } else if (obj instanceof Implementation) {
                Implementation impl = (Implementation) obj;
                enabled = checkImpl(impl);
                if (!enabled) {
                    break out;
                }
            }
        }
        setBaseEnabled(enabled);
    }
}

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

License:Open Source License

@Override
public void setEnabled(final Object evaluationContext) {
    if (evaluationContext instanceof IEvaluationContext) {
        final IEvaluationContext context = (IEvaluationContext) evaluationContext;
        final Object sel = context.getVariable("selection");
        if (sel instanceof IStructuredSelection) {
            final IStructuredSelection ss = (IStructuredSelection) sel;
            for (final Object obj : ss.toList()) {
                final ScaComponent comp = PluginUtil.adapt(ScaComponent.class, obj);
                if (comp != null && comp.getWaveform() != null) {
                    final ScaWaveform waveform = comp.getWaveform();
                    setBaseEnabled(waveform instanceof LocalScaWaveform);
                    return;
                }//w w  w  .  j  a va  2 s.  co  m
            }
        }
    }
    setBaseEnabled(false);
}

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

License:Open Source License

/**
 * {@inheritDoc}/* www .  j a v  a 2 s .co  m*/
 */
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getActiveMenuSelection(event);
    if (sel == null) {
        sel = HandlerUtil.getCurrentSelection(event);
    }
    if (sel instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) sel;
        for (final Object obj : ss.toList()) {
            try {
                handleShowConsole(obj, event);
            } catch (final CoreException e) {
                StatusManager.getManager().handle(e, ScaDebugUiPlugin.PLUGIN_ID);
            }
        }
    }
    return null;
}

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

License:Open Source License

@Override
public void setEnabled(final Object evaluationContext) {
    if (evaluationContext instanceof IEvaluationContext) {
        final IEvaluationContext context = (IEvaluationContext) evaluationContext;
        final Object sel = context.getVariable("selection");
        if (sel instanceof IStructuredSelection) {
            final IStructuredSelection ss = (IStructuredSelection) sel;
            for (final Object obj : ss.toList()) {
                final LocalLaunch ll = PluginUtil.adapt(LocalLaunch.class, obj);
                if (ll != null && ll.getLaunch() != null) {
                    setBaseEnabled(true);
                    return;
                }/*from   ww  w . j  ava  2s  . c  o m*/
            }
        }
    }
    setBaseEnabled(false);
}

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

License:Open Source License

/**
 * {@inheritDoc}/*w  w w.  j  a v a 2  s .  co  m*/
 */
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getActiveMenuSelection(event);
    if (sel == null) {
        sel = HandlerUtil.getCurrentSelection(event);
    }
    if (sel instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) sel;
        for (final Object obj : ss.toList()) {
            try {
                handleTerminate(obj, event);
            } catch (final CoreException e) {
                StatusManager.getManager().handle(e, ScaDebugUiPlugin.PLUGIN_ID);
            }
        }
    }
    return null;
}

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

License:Open Source License

@Override
public void setEnabled(final Object evaluationContext) {
    super.setEnabled(evaluationContext);
    if (evaluationContext instanceof IEvaluationContext) {
        final IEvaluationContext context = (IEvaluationContext) evaluationContext;
        final Object sel = context.getVariable("selection");
        if (sel instanceof IStructuredSelection) {
            final IStructuredSelection ss = (IStructuredSelection) sel;
            for (final Object obj : ss.toList()) {
                final LocalLaunch ll = PluginUtil.adapt(LocalLaunch.class, obj);
                if (ll != null) {
                    setBaseEnabled(true);
                    return;
                }//from www. ja va2s .  c om
            }
        }
    }
    setBaseEnabled(false);
}

From source file:gov.redhawk.internal.ui.port.nxmplot.handlers.PlotPortHandler.java

License:Open Source License

public static IPlotView showView(ExecutionEvent event) {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    String plotTypeStr = event.getParameter(IPlotView.PARAM_PLOT_TYPE);

    // need to grab Port selections first, otherwise Plot Wizard option below will change the selection
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    if (selection == null) {
        selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
    }/*ww w.j a v a  2 s.  c o  m*/
    if (selection == null) {
        return null;
    }
    final List<?> elements = selection.toList();

    // Both of these are always set (below)
    final boolean isFFT;
    PlotSettings plotSettings = new PlotSettings();

    // Either fft gets set, or plotWizardSettings and fftNxmBlockSettings get set (below)
    final BulkIONxmBlockSettings bulkIOBlockSettings;
    final SddsNxmBlockSettings sddsBlockSettings;
    final FftNxmBlockSettings fftBlockSettings;
    final PlotNxmBlockSettings plotBlockSettings;
    final String pipeQualifiers = null;

    boolean containsBulkIOPort = false;
    boolean containsSDDSPort = false;
    for (Object obj : elements) {
        ScaUsesPort port = PluginUtil.adapt(ScaUsesPort.class, obj, true);
        if (port != null) {
            String idl = port.getRepid();
            if (dataSDDSHelper.id().equals(idl)) { // a BULKIO:dataSDDS Port
                containsSDDSPort = true;
            } else if (PlotPortHandler.isBulkIOPortSupported(idl)) { // BULKIO data Port
                containsBulkIOPort = true;
            }
        }
    }

    if (plotTypeStr != null) {
        //because this evaluates to true, we do not end up using addSource2 method
        plotSettings.setPlotType(PlotType.valueOf(plotTypeStr));
        isFFT = Boolean.valueOf(event.getParameter(IPlotView.PARAM_ISFFT));

        if (isFFT) {
            plotSettings.setPlotMode(PlotMode.valueOf(
                    FftPreferences.FFT_MODE.getValue(PlotActivator.getDefault().getPreferenceStore())));
            fftBlockSettings = new FftNxmBlockSettings();
        } else {
            fftBlockSettings = null;
        }
        if (containsSDDSPort) {
            sddsBlockSettings = new SddsNxmBlockSettings();
        } else {
            sddsBlockSettings = null;
        }
        if (containsBulkIOPort) {
            bulkIOBlockSettings = new BulkIONxmBlockSettings();
            bulkIOBlockSettings.setConnectionID(event.getParameter(IPlotView.PARAM_CONNECTION_ID));
        } else {
            bulkIOBlockSettings = null;
        }
        plotBlockSettings = new PlotNxmBlockSettings();
    } else { // run advanced Port plot wizard
        PlotWizard wizard = new PlotWizard(containsBulkIOPort, containsSDDSPort); // advanced Port Plot wizard
        bulkIOBlockSettings = wizard.getBulkIOBlockSettings();
        if (bulkIOBlockSettings != null) {
            bulkIOBlockSettings.setConnectionID(event.getParameter(IPlotView.PARAM_CONNECTION_ID));
        }

        WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
        if (dialog.open() != Window.OK) {
            return null;
        }
        plotSettings = wizard.getPlotSettings();
        isFFT = wizard.isFft();
        if (isFFT) {
            fftBlockSettings = wizard.getFftBlockSettings();
        } else {
            fftBlockSettings = null;
        }

        sddsBlockSettings = wizard.getSddsBlockSettings();
        plotBlockSettings = wizard.getPlotBlockSettings();
    }

    try {
        String secondaryID = event.getParameter(IPlotView.PARAM_SECONDARY_ID);
        if (secondaryID == null || secondaryID.isEmpty()) {
            secondaryID = PlotView2.createSecondaryId();
        }
        final IViewPart view = window.getActivePage().showView(PlotView2.ID, secondaryID,
                IWorkbenchPage.VIEW_ACTIVATE);
        if (view instanceof PlotView2) {
            final PlotView2 plotView = (PlotView2) view;
            plotView.getPlotPageBook().showPlot(plotSettings);

            Job job = new Job("Adding plot sources...") {
                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    return PlotPortHandler.addPlotSources(elements, bulkIOBlockSettings, sddsBlockSettings,
                            fftBlockSettings, plotBlockSettings, pipeQualifiers, plotView, monitor);
                }
            };
            job.setUser(true);
            job.schedule();
            return plotView;
        }
    } catch (PartInitException e) {
        StatusManager.getManager().handle(
                new Status(IStatus.ERROR, PlotActivator.PLUGIN_ID, "Failed to show Plot View", e),
                StatusManager.LOG | StatusManager.SHOW);
    }
    return null;
}