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.astra.ses.spell.gui.views.controls.watchvariables.WatchVariablesPage.java

License:Open Source License

/**************************************************************************
 * Unsubscribe to selected variables.//from www. j  a  va  2s  .com
 *************************************************************************/
public void unsubscribeSelected() {
    IStructuredSelection sel = (IStructuredSelection) m_viewer.getSelection();
    Object[] list = sel.toArray();
    for (Object obj : list) {
        VariableData var = (VariableData) obj;
        /*
         * Prepare command arguments
         */
        HashMap<String, String> args = new HashMap<String, String>();
        args.put(IWatchCommandArgument.PROCEDURE_ID, m_procId);
        args.put(IWatchCommandArgument.VARIABLE_NAME, var.name);
        args.put(IWatchCommandArgument.VARIABLE_GLOBAL, new Boolean(var.isGlobal).toString());

        /*
         * Execute the command
         */
        CommandResult result = (CommandResult) CommandHelper.execute(StopWatchVariable.ID, args);
        if (result == CommandResult.SUCCESS) {
            var.isRegistered = false;
        }
    }
    m_viewer.refresh();
}

From source file:com.astra.ses.spell.gui.watchvariables.views.controls.WatchVariablesPage.java

License:Open Source License

/**************************************************************************
 * Subscribe to selected variables.//from  w  ww .j a va2s.c o  m
 *************************************************************************/
public void subscribeSelected() {
    Logger.debug("Subscribe to selected", Level.PROC, this);
    IStructuredSelection sel = (IStructuredSelection) m_viewer.getSelection();
    Object[] list = sel.toArray();
    for (Object obj : list) {
        VariableData var = (VariableData) obj;
        /*
         * Prepare command arguments
         */
        HashMap<String, String> args = new HashMap<String, String>();
        args.put(IWatchCommandArgument.PROCEDURE_ID, m_proc.getProcId());
        args.put(IWatchCommandArgument.VARIABLE_NAME, var.name);
        args.put(IWatchCommandArgument.VARIABLE_GLOBAL, new Boolean(var.isGlobal).toString());

        /*
         * Execute the command
         */
        CommandResult result = (CommandResult) CommandHelper.execute(WatchVariable.ID, args);
        if (result == CommandResult.SUCCESS) {
            var.isRegistered = true;
        }
    }
    showRegisteredNow();
}

From source file:com.astra.ses.spell.gui.watchvariables.views.controls.WatchVariablesPage.java

License:Open Source License

/**************************************************************************
 * Unsubscribe to selected variables.//from   ww w.j  a v  a  2 s. c o  m
 *************************************************************************/
public void unsubscribeSelected() {
    Logger.debug("Unsubscribe selected", Level.PROC, this);
    IStructuredSelection sel = (IStructuredSelection) m_viewer.getSelection();
    Object[] list = sel.toArray();
    for (Object obj : list) {
        VariableData var = (VariableData) obj;
        /*
         * Prepare command arguments
         */
        HashMap<String, String> args = new HashMap<String, String>();
        args.put(IWatchCommandArgument.PROCEDURE_ID, m_proc.getProcId());
        args.put(IWatchCommandArgument.VARIABLE_NAME, var.name);
        args.put(IWatchCommandArgument.VARIABLE_GLOBAL, new Boolean(var.isGlobal).toString());

        /*
         * Execute the command
         */
        CommandResult result = (CommandResult) CommandHelper.execute(StopWatchVariable.ID, args);
        if (result == CommandResult.SUCCESS) {
            var.isRegistered = false;
        }
    }
    m_viewer.refresh();
}

From source file:com.atlassian.connector.eclipse.ui.actions.AbstractResourceAction.java

License:Open Source License

private List<ResourceEditorBean> getData(ISelection selection) {
    List<ResourceEditorBean> ret = new ArrayList<ResourceEditorBean>();
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structuredSelection = (IStructuredSelection) selection;

        Object[] selectedObjects = structuredSelection.toArray();

        for (Object selectedObject : selectedObjects) {

            if (selectedObject instanceof IEditorResource) {
                IEditorResource a = (IEditorResource) selectedObject;
                ret.add(new ResourceEditorBean(a.getResource(), a.getLineRange()));

            } else if (structuredSelection.getFirstElement() instanceof IAdaptable) {
                IResource resource = null;
                LineRange lineRange = null;
                resource = (IResource) ((IAdaptable) structuredSelection.getFirstElement())
                        .getAdapter(IResource.class);
                lineRange = getJavaEditorSelection(structuredSelection);
                ret.add(new ResourceEditorBean(resource, lineRange));
            }//from w w w .  ja va  2  s .  c  o  m
        }
    } else {
        IEditorPart activeEditor = getActiveEditor();
        if (activeEditor != null) {
            IEditorInput editorInput = getEditorInputFromSelection(selection);
            if (editorInput != null) {
                IResource resource = null;
                LineRange lineRange = null;
                resource = (IResource) editorInput.getAdapter(IResource.class);
                // such call:
                //            lineRange = new LineRange(textSelection.getStartLine(), textSelection.getEndLine()
                //                  - textSelection.getStartLine());
                // does not work (i.e. it returns previously selected text region rather than selected now ?!?
                lineRange = AtlassianUiUtil.getSelectedLineNumberRangeFromEditorInput(activeEditor,
                        activeEditor.getEditorInput());
                ret.add(new ResourceEditorBean(resource, lineRange));
            }
        }
    }
    return ret;
}

From source file:com.baremetalstudios.mapleide.internal.ResourceNavigator.java

License:Open Source License

@Inject
public ResourceNavigator(Composite parent, final IEclipseContext context, IWorkspace workspace) {
    final Realm realm = SWTObservables.getRealm(parent.getDisplay());
    this.context = context;
    parent.setLayout(new FillLayout());
    TreeViewer viewer = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            selectionService//from w  w w.j  a v  a2  s .  c  o  m
                    .setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray());
            //            context.modify(IServiceConstants.ACTIVE_SELECTION, selection.size() == 1 ? selection.getFirstElement() : selection.toArray());
        }
    });

    IObservableFactory setFactory = new IObservableFactory() {
        public IObservable createObservable(Object element) {
            if (element instanceof IContainer && ((IContainer) element).exists()) {
                IObservableSet observableSet = observableSets.get(element);
                if (observableSet == null) {
                    observableSet = new WritableSet(realm);
                    try {
                        observableSet.addAll(Arrays.asList(((IContainer) element).members()));
                    } catch (CoreException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    observableSets.put((IContainer) element, observableSet);
                }
                return observableSet;
            }
            return Observables.emptyObservableSet();
        }
    };
    viewer.setContentProvider(new ObservableSetTreeContentProvider(setFactory, new TreeStructureAdvisor() {
        public Boolean hasChildren(Object element) {
            return Boolean.valueOf(element instanceof IContainer);
        }
    }));

    viewer.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            if (element instanceof IResource)
                return ((IResource) element).getName();
            return element == null ? "" : element.toString();
        }
    });
    viewer.setSorter(new ViewerSorter());
    viewer.setInput(workspace.getRoot());
    viewer.addOpenListener(new IOpenListener() {

        public void open(OpenEvent event) {

            MapleIDEApplication app = (MapleIDEApplication) application;
            IStructuredSelection s = (IStructuredSelection) event.getSelection();
            for (Object o : s.toArray()) {
                if (o instanceof IFile) {
                    IFile f = (IFile) o;
                    context.set(IFile.class, f);
                    String fExt = f.getFileExtension();
                    EDITOR: for (EditorPartDescriptor desc : app.getEditorPartDescriptors()) {
                        for (String ext : desc.getFileextensions()) {
                            if (ext.equals(fExt)) {
                                context.set(EditorPartDescriptor.class, desc);
                                System.err.println("Opening with: " + desc);

                                Command cmd = commandService
                                        .getCommand("com.baremetalstudios.mapleide.command.openeditor");
                                //                           Command cmd = commandService.getCommand("simpleide.command.openeditor");
                                ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(cmd, null);
                                handlerService.executeHandler(pCmd);

                                break EDITOR;
                            }
                        }
                    }
                }
            }

        }
    });
    setupContextMenu(viewer, parent.getShell());
    workspace.addResourceChangeListener(listener);
}

From source file:com.bdaum.zoom.gps.internal.dialogs.TrackpointDialog.java

License:Open Source License

protected void updateMap() {
    IStructuredSelection selection = viewer.getStructuredSelection();
    double minLat = Double.MAX_VALUE, maxLat = Double.MIN_VALUE, minLng = Double.MAX_VALUE,
            maxLng = Double.MIN_VALUE;
    Object[] tracks = selection.toArray();
    LinkedList<Trackpoint> pnts = new LinkedList<Trackpoint>();
    int start = 0;
    for (Trackpoint trackpoint : trackpoints) {
        long time = trackpoint.getTime();
        for (int i = start; i < tracks.length; i++)
            if (time >= ((SubTrack) tracks[i]).getStart()) {
                start = i;/*from   w ww .  j a  v a2s .c  o m*/
                if (time <= ((SubTrack) tracks[i]).getEnd()) {
                    pnts.add(trackpoint);
                    double latitude = trackpoint.getLatitude();
                    double longitude = trackpoint.getLongitude();
                    if (latitude > maxLat)
                        maxLat = latitude;
                    if (latitude < minLat)
                        minLat = latitude;
                    if (longitude > maxLng)
                        maxLng = longitude;
                    if (longitude < minLng)
                        minLng = longitude;
                    break;
                }
            }
    }
    double latDist = Math.abs(maxLat - minLat) / 100;
    double lngDist = Math.abs(maxLng - minLng) / 100;
    boolean done = false;
    while (!done) {
        done = true;
        Trackpoint previous = null;
        Iterator<Trackpoint> it = pnts.iterator();
        while (it.hasNext()) {
            Trackpoint pnt = it.next();
            if (previous != null && Math.abs(previous.getLatitude() - pnt.getLatitude()) < latDist
                    && Math.abs(previous.getLongitude() - pnt.getLongitude()) < lngDist) {
                it.remove();
                done = false;
                continue;
            }
            previous = pnt;
        }
    }
    mapComponent.setInput(null, 12, null, null, pnts.toArray(new Trackpoint[pnts.size()]), IMapComponent.TRACK);
}

From source file:com.bdaum.zoom.ui.internal.views.TableView.java

License:Open Source License

protected AssetSelection doGetAssetSelection() {
    IStructuredSelection s = gallery.getStructuredSelection();
    AssetSelection sel = new AssetSelection(s.size());
    for (Object item : s.toArray())
        sel.add((Asset) item);//w  w  w .ja  v a 2  s. c  o m
    return sel;
}

From source file:com.centurylink.mdw.plugin.designer.views.ProcessExplorerActionGroup.java

License:Apache License

public boolean exportProjectApplies(IStructuredSelection selection) {
    if (selection.size() == 0)
        return false;

    for (Object element : selection.toArray()) {
        if (!(element instanceof WorkflowProject))
            return false;
    }/*from  w  ww  .  jav  a 2s  .c om*/

    return true;
}

From source file:com.centurylink.mdw.plugin.designer.views.ProcessExplorerActionGroup.java

License:Apache License

public boolean runApplies(IStructuredSelection selection) {
    if (selection.size() > 1) {
        Boolean legacy = null;//from   ww w. jav  a 2 s .  com
        WorkflowPackage testPkg = null;
        for (Object o : selection.toArray()) {
            if (!(o instanceof AutomatedTestCase))
                return false;
            // make sure they're all in the same package or legacy suite
            AutomatedTestCase testCase = (AutomatedTestCase) o;
            if (legacy == null)
                legacy = testCase.isLegacy();
            if (legacy.booleanValue() != testCase.isLegacy())
                return false;
            if (!testCase.isLegacy()) {
                if (testPkg == null)
                    testPkg = testCase.getPackage();
                if (!testPkg.equals(testCase.getPackage()))
                    return false;
            }
        }
        return ((AutomatedTestCase) selection.getFirstElement()).getProject()
                .isUserAuthorizedInAnyGroup(UserRoleVO.PROCESS_EXECUTION);
    }

    if (selection.size() != 1 || !(selection.getFirstElement() instanceof WorkflowElement))
        return false;

    WorkflowElement workflowElement = (WorkflowElement) selection.getFirstElement();

    if (workflowElement instanceof Report)
        return true;

    if (workflowElement instanceof Page)
        return true;

    if (workflowElement instanceof Template
            && ((Template) workflowElement).getLanguage().equals(RuleSetVO.VELOCITY))
        return true;

    if (workflowElement instanceof WorkflowProcess || workflowElement instanceof ExternalEvent)
        return workflowElement.isUserAuthorized(UserRoleVO.PROCESS_EXECUTION);

    if (workflowElement instanceof AutomatedTestSuite || workflowElement instanceof AutomatedTestCase) {
        if (workflowElement.getProject() == null
                || !workflowElement.getProject().isUserAuthorizedInAnyGroup(UserRoleVO.PROCESS_EXECUTION))
            return false;
        WorkflowPackage pkg = workflowElement.getPackage();
        if (pkg != null && !pkg.isUserAuthorized(UserRoleVO.PROCESS_EXECUTION))
            return false;
        try {
            AutomatedTestView testView = (AutomatedTestView) MdwPlugin.getActivePage()
                    .showView("mdw.views.launch.automatedTest");
            return !testView.isLocked();
        } catch (PartInitException ex) {
            PluginMessages.uiError(ex, "Menu", workflowElement.getProject());
        }
    }

    return false;
}

From source file:com.centurylink.mdw.plugin.designer.views.ProcessExplorerActionGroup.java

License:Apache License

private WorkflowElement[] selectionToElementArray(IStructuredSelection selection) {
    Object[] items = selection.toArray();
    WorkflowElement[] elements = new WorkflowElement[items.length];
    for (int i = 0; i < items.length; i++)
        elements[i] = (WorkflowElement) items[i];
    return elements;
}