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

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

Introduction

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

Prototype

@Override
public Iterator iterator();

Source Link

Document

Returns an iterator over the elements of this selection.

Usage

From source file:com.astra.ses.spell.gui.shared.views.controls.ScopeTab.java

License:Open Source License

/***************************************************************************
 * //  w  ww  .ja v a2s.  co  m
 **************************************************************************/
public ScopeTab(TabFolder parent, ISharedScope table, SharedVariablesView view, boolean monitoringMode) {
    super(parent, SWT.NONE);

    Logger.debug("Created tab: " + table.getScopeName(), Level.GUI, this);

    m_table = table;
    m_view = view;
    m_monitoringMode = monitoringMode;

    Composite top = new Composite(parent, SWT.NONE);
    top.setLayout(new GridLayout(isGlobal() ? 4 : 5, true));
    top.setLayoutData(new GridData(GridData.FILL_BOTH));

    m_viewer = new SharedVariablesTableViewer(top, table, monitoringMode);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = isGlobal() ? 4 : 5;
    m_viewer.getControl().setLayoutData(gd);
    m_viewer.addSelectionChangedListener(this);

    if (isGlobal()) {
        setText("GLOBAL");
    } else {
        setText(m_table.getScopeName());
    }

    m_btnNew = new Button(top, SWT.PUSH);
    m_btnNew.setText("New variable");
    m_btnNew.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    m_btnNew.setEnabled(false);
    m_btnNew.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent ev) {
            SharedVariableDialog dialog = new SharedVariableDialog(m_viewer.getControl().getShell(), true, "",
                    "");
            if (dialog.open() == IDialogConstants.OK_ID) {
                String key = dialog.getKey();
                String value = dialog.getValue();
                if (!key.trim().isEmpty() && !value.trim().isEmpty()) {
                    m_table.set(dialog.getKey(), dialog.getValue());
                    refresh();
                }
            }
        }
    });

    m_btnDel = new Button(top, SWT.PUSH);
    m_btnDel.setText("Delete variable");
    m_btnDel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    m_btnDel.setEnabled(false);
    m_btnDel.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent ev) {
            IStructuredSelection sel = (IStructuredSelection) m_viewer.getSelection();
            if (!sel.isEmpty()) {
                @SuppressWarnings("rawtypes")
                Iterator it = sel.iterator();
                String toDeleteText = "Are you sure to delete the following shared variables?\n\n";
                List<SharedVariable> toDelete = new LinkedList<SharedVariable>();
                while (it.hasNext()) {
                    SharedVariable var = (SharedVariable) it.next();
                    toDelete.add(var);
                    toDeleteText += "  - " + var.name + "\n";
                }
                if (MessageDialog.openConfirm(m_viewer.getControl().getShell(), "Delete shared variables",
                        toDeleteText)) {
                    ClearSharedVariablesJob job = new ClearSharedVariablesJob(m_table, toDelete);
                    CommandHelper.executeInProgress(job, true, true);
                    refresh();
                }
            }
        }
    });

    m_btnClear = new Button(top, SWT.PUSH);
    m_btnClear.setText("Remove all variables");
    m_btnClear.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    m_btnClear.setEnabled(false);
    m_btnClear.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent ev) {
            String text = "This action will remove all shared variables in the scope.\n\nDo you want to proceed?";
            if (MessageDialog.openConfirm(m_viewer.getControl().getShell(), "Delete shared variables", text)) {
                ClearSharedVariablesJob job = new ClearSharedVariablesJob(m_table);
                CommandHelper.executeInProgress(job, true, true);
                refresh();
            }
        }
    });

    Button refreshScope = new Button(top, SWT.PUSH);
    refreshScope.setText("Refresh variables");
    refreshScope.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    refreshScope.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent ev) {
            Logger.debug("Refreshing tab: " + m_table.getScopeName(), Level.GUI, this);
            RefreshSharedVariablesJob job = new RefreshSharedVariablesJob(m_table);
            CommandHelper.executeInProgress(job, true, true);
            refresh();
        }
    });

    if (!isGlobal()) {
        m_btnRemove = new Button(top, SWT.PUSH);
        m_btnRemove.setText("Remove scope");
        m_btnRemove.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        m_btnRemove.setEnabled(false);
        m_btnRemove.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent ev) {
                String text = "This action will completely remove the scope and its variables.\n\nDo you want to proceed?";
                if (MessageDialog.openConfirm(m_viewer.getControl().getShell(), "Delete shared variables",
                        text)) {
                    ISharedDataService svc = (ISharedDataService) ServiceManager.get(ISharedDataService.class);
                    svc.removeSharedScope(m_table.getScopeName());
                    m_view.removeScope(m_table.getScopeName());
                }
            }
        });
    }

    if (!monitoringMode) {
        m_btnNew.setEnabled(true);
        m_btnClear.setEnabled(true);
        if (!isGlobal())
            m_btnRemove.setEnabled(true);
    }

    setControl(top);
}

From source file:com.astra.ses.spell.gui.views.controls.master.CurrentExecutorsTable.java

License:Open Source License

/***************************************************************************
 * Get the selected procedure/*from w ww.j a  v  a  2  s.co  m*/
 **************************************************************************/
public String[] getSelectedProcedures() {
    ArrayList<String> ids = new ArrayList<String>();
    IStructuredSelection sel = (IStructuredSelection) getSelection();
    if (!sel.isEmpty()) {
        @SuppressWarnings("unchecked")
        Iterator<IProcedure> it = sel.iterator();
        while (it.hasNext()) {
            Object proc = it.next();
            if (proc instanceof IProcedure) {
                ids.add(((IProcedure) proc).getProcId());
            } else if (proc instanceof IExecutorInfo) {
                ids.add(((IExecutorInfo) proc).getProcId());
            }
        }
    }
    return ids.toArray(new String[0]);
}

From source file:com.astra.ses.spell.gui.views.controls.master.executors.ExecutorsTable.java

License:Open Source License

/***************************************************************************
 * Get all selected procedures/*from  w  ww  .  ja v a2 s  .co  m*/
 **************************************************************************/
@Override
public String[] getSelectedProcedures() {
    ArrayList<String> ids = new ArrayList<String>();
    IStructuredSelection sel = (IStructuredSelection) getSelection();
    if (!sel.isEmpty()) {
        @SuppressWarnings("unchecked")
        Iterator<IProcedure> it = sel.iterator();
        while (it.hasNext()) {
            Object proc = it.next();
            if (proc instanceof IProcedure) {
                ids.add(((IProcedure) proc).getProcId());
            } else if (proc instanceof IExecutorInfo) {
                ids.add(((IExecutorInfo) proc).getProcId());
            }
        }
    }
    return ids.toArray(new String[0]);
}

From source file:com.astra.ses.spell.gui.views.controls.master.recovery.RecoveryTable.java

License:Open Source License

/***************************************************************************
 * Get the selected procedure/*ww w .  j  av a 2s  .  c o  m*/
 **************************************************************************/
public ProcedureRecoveryInfo[] getSelectedProcedures() {
    ArrayList<ProcedureRecoveryInfo> ids = new ArrayList<ProcedureRecoveryInfo>();
    IStructuredSelection sel = (IStructuredSelection) getSelection();
    if (!sel.isEmpty()) {
        @SuppressWarnings("unchecked")
        Iterator<ProcedureRecoveryInfo> it = sel.iterator();
        while (it.hasNext()) {
            Object proc = it.next();
            ids.add((ProcedureRecoveryInfo) proc);
        }
    }
    return ids.toArray(new ProcedureRecoveryInfo[0]);
}

From source file:com.astra.ses.spell.gui.views.WatchVariablesView.java

License:Open Source License

/***************************************************************************
 * Update actions status/*ww  w  . j a v a  2  s .  c  o  m*/
 **************************************************************************/
private void updateActionState(IStructuredSelection selection) {
    int selectionSize = selection.size();

    boolean refresh = true;
    boolean subscribe = false;
    boolean unsubscribe = false;
    boolean cleanup = false;

    WatchVariablesPage page = (WatchVariablesPage) getCurrentPage();
    boolean registered = page.isShowingRegistered();
    boolean active = page.isActive();

    refresh = active;

    if (selectionSize > 0) {
        subscribe = !registered;
        unsubscribe = true;

        Iterator<VariableData> variableIterator = selection.iterator();
        while (variableIterator.hasNext()) {
            VariableData var = variableIterator.next();
            subscribe = (subscribe && (!var.isRegistered));
            unsubscribe = (unsubscribe && (var.isRegistered));
        }
        cleanup = !subscribe;
    }

    m_refreshAction.setEnabled(refresh);
    m_unsubscribeAction.setEnabled(unsubscribe);
    m_subscribeAction.setEnabled(subscribe);
    m_unsubscribeAllAction.setEnabled(cleanup);
}

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

License:Open Source License

/***************************************************************************
 * Update actions status//from w  w  w .  j ava2s .  com
 **************************************************************************/
private void updateActionState(IStructuredSelection selection) {
    int selectionSize = selection.size();

    boolean refresh = true;
    boolean subscribe = false;
    boolean unsubscribe = false;
    boolean cleanup = false;

    WatchVariablesPage page = (WatchVariablesPage) getCurrentPage();
    boolean registered = page.isShowingRegistered();
    boolean active = page.isActive();

    refresh = active;

    if (selectionSize > 0) {
        subscribe = !registered;
        unsubscribe = true;

        @SuppressWarnings("unchecked")
        Iterator<VariableData> variableIterator = selection.iterator();
        while (variableIterator.hasNext()) {
            VariableData var = variableIterator.next();
            subscribe = (subscribe && (!var.isRegistered));
            unsubscribe = (unsubscribe && (var.isRegistered));
        }
        cleanup = !subscribe;
    }

    m_refreshAction.setEnabled(refresh);
    m_unsubscribeAction.setEnabled(unsubscribe);
    m_subscribeAction.setEnabled(subscribe);
    m_unsubscribeAllAction.setEnabled(cleanup);
}

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

License:Open Source License

protected void updateButtons() {
    IStructuredSelection selection = viewer.getStructuredSelection();
    int size = selection.size();
    boolean single = size == 1;
    boolean any = size > 0;
    editButton.setEnabled(single);//  w ww. ja v  a 2s.  co  m
    removeButton.setEnabled(any);
    int previous = -1;
    boolean join = false;
    if (size > 1) {
        join = true;
        Iterator<?> it = selection.iterator();
        while (it.hasNext()) {
            int index = subtracks.indexOf(it.next());
            if (previous >= 0) {
                if (index - previous > 1) {
                    join = false;
                    break;
                }
            }
            previous = index;
        }
    }
    joinButton.setEnabled(join);
    splitButton.setEnabled(single);
}

From source file:com.bdaum.zoom.ui.internal.actions.RefreshAction.java

License:Open Source License

public List<Asset> getSelectedAssets() {
    AssetSelection selection = adaptable.getAdapter(AssetSelection.class);
    if (selection != null && !selection.isEmpty())
        return selection.getLocalAssets();
    final List<Asset> assets = new ArrayList<Asset>(1000);
    IWorkbenchPage page = adaptable.getAdapter(IWorkbenchPage.class);
    CatalogView catView = (CatalogView) page.findView(CatalogView.ID);
    if (catView != null) {
        final IStructuredSelection sel = (IStructuredSelection) catView.getSelection();
        BusyIndicator.showWhile(shell.getDisplay(), () -> {
            IDbManager dbManager = Core.getCore().getDbManager();
            for (Iterator<?> iterator = sel.iterator(); iterator.hasNext();) {
                Object object = iterator.next();
                if (object instanceof SmartCollectionImpl)
                    assets.addAll(//from   ww  w.j a  v a 2  s  .  com
                            dbManager
                                    .createCollectionProcessor(
                                            Utilities.localizeSmartCollection((SmartCollection) object))
                                    .select(false));
            }
        });
    }
    return assets;
}

From source file:com.bdaum.zoom.ui.internal.dialogs.ConfigureColumnsDialog.java

License:Open Source License

private void updateButtons() {
    boolean fieldSelected = false;
    IStructuredSelection selection = (IStructuredSelection) metaViewer.getSelection();
    Iterator<?> iterator = selection.iterator();
    while (iterator.hasNext()) {
        QueryField qfield = (QueryField) iterator.next();
        if (!qfield.hasChildren()) {
            fieldSelected = true;//from   www . j  av  a 2 s.  c om
            break;
        }
    }
    addButton.setEnabled(fieldSelected);
    selection = columnsViewer.getStructuredSelection();
    boolean colSelected = !selection.isEmpty();
    removeButton.setEnabled(colSelected);
    if (colSelected) {
        int min = Integer.MAX_VALUE;
        int max = -1;
        iterator = selection.iterator();
        while (iterator.hasNext()) {
            int index = columnFields.indexOf(iterator.next());
            min = Math.min(min, index);
            max = Math.max(max, index);
        }
        upButton.setEnabled(min > 0);
        downButton.setEnabled(max < columnFields.size() - 1);
    } else {
        upButton.setEnabled(false);
        downButton.setEnabled(false);
    }
}

From source file:com.bdaum.zoom.ui.internal.dialogs.ConfigureColumnsDialog.java

License:Open Source License

public void widgetSelected(SelectionEvent e) {
    if (e.widget == addButton) {
        IStructuredSelection selection = (IStructuredSelection) metaViewer.getSelection();
        for (@SuppressWarnings("rawtypes")
        Iterator iterator = selection.iterator(); iterator.hasNext();) {
            QueryField qfield = (QueryField) iterator.next();
            if (!qfield.hasChildren())
                columnFields.add(qfield);
        }//ww w .j a  v a  2 s  . co m
        columnsViewer.setInput(columnFields);
        columnsViewer.setSelection(selection);
        metaViewer.refresh();
    } else if (e.widget == removeButton) {
        IStructuredSelection selection = columnsViewer.getStructuredSelection();
        columnFields.removeAll(selection.toList());
        columnsViewer.setInput(columnFields);
        metaViewer.refresh();
        metaViewer.setSelection(selection);
    } else if (e.widget == upButton) {
        IStructuredSelection selection = columnsViewer.getStructuredSelection();
        for (@SuppressWarnings("rawtypes")
        Iterator iterator = selection.iterator(); iterator.hasNext();) {
            QueryField qfield = (QueryField) iterator.next();
            int index = columnFields.indexOf(qfield);
            if (index > 0) {
                columnFields.set(index, columnFields.get(index - 1));
                columnFields.set(index - 1, qfield);
            }
        }
        columnsViewer.setInput(columnFields);
    } else if (e.widget == downButton) {
        IStructuredSelection selection = columnsViewer.getStructuredSelection();
        for (@SuppressWarnings("rawtypes")
        Iterator iterator = selection.iterator(); iterator.hasNext();) {
            QueryField qfield = (QueryField) iterator.next();
            int index = columnFields.indexOf(qfield);
            if (index < columnFields.size() - 1) {
                columnFields.set(index, columnFields.get(index + 1));
                columnFields.set(index + 1, qfield);
            }
        }
        columnsViewer.setInput(columnFields);
    }
    updateButtons();
}