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:gov.redhawk.sca.internal.ui.handlers.DisconnectDomainHandler.java

License:Open Source License

/**
 * {@inheritDoc}//w  w w  .j  a va  2s.  c om
 */

@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()) {
            if (obj instanceof ScaDomainManager) {
                final ScaDomainManager domMgr = (ScaDomainManager) obj;
                final Job job = new Job("Disconnecting Domain") {

                    @Override
                    protected IStatus run(final IProgressMonitor monitor) {
                        monitor.beginTask("Disconnecting from domain " + domMgr.getName(),
                                IProgressMonitor.UNKNOWN);
                        try {
                            domMgr.disconnect();
                            return Status.OK_STATUS;
                        } catch (final Exception e) { // SUPPRESS CHECKSTYLE Logged Catch all exception
                            return new Status(IStatus.ERROR, ScaUiPlugin.PLUGIN_ID, "Failed to connect", e);
                        }
                    }

                };
                job.setPriority(Job.LONG);
                job.setUser(true);
                job.schedule();
            }
        }
    }
    // TODO Auto-generated method stub
    return null;
}

From source file:gov.redhawk.sca.internal.ui.handlers.DisconnectPortHandler.java

License:Open Source License

/**
 * {@inheritDoc}/*from   www  .  j  av  a  2  s.  c o m*/
 */
@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()) {
            if (obj instanceof ScaConnection) {
                new DisconnectJob((ScaConnection) obj).schedule();
            }
        }
    }
    return null;
}

From source file:gov.redhawk.sca.internal.ui.handlers.InitHandler.java

License:Open Source License

/**
 * {@inheritDoc}// w  w  w. j  av a 2 s.c o  m
 */

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;
        for (final Object obj : ss.toArray()) {
            if (obj instanceof LifeCycleOperations) {
                final LifeCycleOperations op = (LifeCycleOperations) obj;
                final Job job = new Job("Initializing") {

                    @Override
                    protected IStatus run(final IProgressMonitor monitor) {
                        monitor.beginTask("Initializing: " + op, IProgressMonitor.UNKNOWN);
                        try {
                            op.initialize();
                            return Status.OK_STATUS;
                        } catch (final InitializeError e) {
                            return new Status(IStatus.ERROR, ScaUiPlugin.PLUGIN_ID,
                                    "Failed to initialize: " + op, e);
                        }
                    }

                };
                job.schedule();
            }
        }
    }
    // TODO Auto-generated method stub
    return null;
}

From source file:gov.redhawk.sca.internal.ui.handlers.RefreshHandler.java

License:Open Source License

/**
 * {@inheritDoc}/*  www. j  av  a2s .c  o  m*/
 */
@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 structuredSelection = (IStructuredSelection) selection;
        final List<IRefreshable> refreshList = new ArrayList<IRefreshable>();
        for (final Object obj : structuredSelection.toList()) {
            final IRefreshable dataObj = PluginUtil.adapt(IRefreshable.class, obj, true);
            if (dataObj != null) {
                refreshList.add(dataObj);
            }
        }
        final int size = refreshList.size();
        if (size > 0) {
            final IProgressMonitor refreshProgressGroup = Job.getJobManager().createProgressGroup();
            final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
            refreshProgressGroup.beginTask("Refreshing elements...", size);
            final ScaItemProviderAdapterFactory adapterFactory = new ScaItemProviderAdapterFactory();
            final Display display = HandlerUtil.getActiveShell(event).getDisplay();
            for (final IRefreshable dataObj : refreshList) {
                final IItemLabelProvider lp = (IItemLabelProvider) adapterFactory.adapt(dataObj,
                        IItemLabelProvider.class);
                String label = "";
                if (lp != null) {
                    label = " " + lp.getText(dataObj);
                }
                final Job job = new Job("Refreshing" + label) {

                    @Override
                    protected IStatus run(final IProgressMonitor monitor) {
                        try {
                            dataObj.refresh(monitor, RefreshDepth.CHILDREN);
                            final WorkbenchJob uiJob = new WorkbenchJob(display, "Refresh viewer") {

                                @Override
                                public IStatus runInUIThread(final IProgressMonitor monitor) {
                                    if (activePart instanceof CommonNavigator) {
                                        final CommonNavigator navigator = (CommonNavigator) activePart;
                                        navigator.getCommonViewer().refresh(structuredSelection.toArray());
                                    }
                                    refreshProgressGroup.done();
                                    return Status.OK_STATUS;
                                }
                            };
                            uiJob.setPriority(Job.INTERACTIVE);
                            uiJob.setUser(false);
                            uiJob.schedule();
                        } catch (final InterruptedException e) {
                            return Status.CANCEL_STATUS;
                        }
                        return Status.OK_STATUS;
                    }

                    @Override
                    protected void canceling() {
                        getThread().interrupt();
                        super.canceling();
                    }
                };
                job.setProgressGroup(refreshProgressGroup, 1);
                job.setUser(true);
                job.schedule();
            }
            adapterFactory.dispose();
        }
    }
    return null;
}

From source file:gov.redhawk.sca.internal.ui.handlers.ReleaseHandler.java

License:Open Source License

/**
 * {@inheritDoc}/*from   w w w .  ja va 2 s  .c o m*/
 */

@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()) {
            release(obj, event);
        }
    } else {
        final IEditorPart editor = HandlerUtil.getActiveEditor(event);
        release(editor, event);
    }

    return null;
}

From source file:gov.redhawk.sca.internal.ui.handlers.RemoveDomainHandler.java

License:Open Source License

/**
 * {@inheritDoc}/*from   w ww .  ja  v  a  2s.  co m*/
 */

@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;
        final MessageDialog dialog = new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Delete Domain Connection",
                null, "Are you sure you want to remove the selected domains?", MessageDialog.QUESTION,
                new String[] { "OK", "Cancel" }, 0);
        if (dialog.open() == Window.OK) {
            for (final Object obj : ss.toArray()) {
                if (obj instanceof ScaDomainManager) {
                    final ScaDomainManager domMgr = (ScaDomainManager) obj;
                    domMgr.disconnect();
                    ScaModelCommand.execute(domMgr, new ScaModelCommand() {

                        @Override
                        public void execute() {
                            ScaPlugin.getDefault().getDomainManagerRegistry(Display.getCurrent()).getDomains()
                                    .remove(domMgr);
                        }

                    });
                }
            }
        }
    }
    return null;
}

From source file:gov.redhawk.sca.internal.ui.handlers.ShutdownNodeHandler.java

License:Open Source License

/**
 * {@inheritDoc}/*from w w w  . j  a  v  a2s .c  o  m*/
 */

@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 DeviceManagerOperations op = PluginUtil.adapt(DeviceManagerOperations.class, obj);
            if (op != null) {
                final Job job = new Job("Shutting down Device Manager") {

                    @Override
                    protected IStatus run(final IProgressMonitor monitor) {
                        monitor.beginTask("Shutting down: " + op.label(), IProgressMonitor.UNKNOWN);

                        // Try to shutdown the Device Manager
                        op.shutdown();
                        return Status.OK_STATUS;
                    }

                };
                job.setUser(true);
                job.schedule();
            }
        }
    }
    return null;
}

From source file:gov.redhawk.sca.internal.ui.handlers.StartResouceOpHandler.java

License:Open Source License

/**
 * {@inheritDoc}/*from  ww w  .ja  v  a 2 s.  co  m*/
 */

@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()) {
            start(obj);
        }
    } else {
        final IEditorPart editor = HandlerUtil.getActiveEditor(event);
        start(editor);
    }
    // TODO Auto-generated method stub
    return null;
}

From source file:gov.redhawk.sca.internal.ui.handlers.StopResourceOpHandler.java

License:Open Source License

/**
 * {@inheritDoc}//  w  ww  .j a  v  a 2s. 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()) {
            stop(obj);
        }
    } else {
        final IEditorPart editor = HandlerUtil.getActiveEditor(event);
        stop(editor);
    }
    // TODO Auto-generated method stub
    return null;
}

From source file:gov.redhawk.sca.model.provider.refresh.internal.ui.handlers.AutoRefreshHandler.java

License:Open Source License

/**
 * {@inheritDoc}//from  w  w  w. j a v a  2  s . c o  m
 */
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;
        for (final Object obj : ss.toArray()) {
            if (obj instanceof DataProviderObject) {
                try {
                    ScaModelCommand.runExclusive((DataProviderObject) obj,
                            new RunnableWithResult.Impl<Object>() {

                                @Override
                                public void run() {
                                    final DataProviderObject dataObj = (DataProviderObject) obj;
                                    final Object[] providers = dataObj.getDataProviders().toArray();
                                    boolean state = false;
                                    for (final Object provider : providers) {
                                        if (provider instanceof RefreshTasker) {
                                            final RefreshTasker job = (RefreshTasker) provider;
                                            state = !job.isActive();
                                            job.setActive(state);
                                        }
                                    }
                                    updateRefreshDataProvider(state, dataObj);
                                }

                            });
                } catch (final InterruptedException e) {
                    // PASS
                }
            }
        }
    }
    return null;
}