Example usage for org.eclipse.jface.viewers StructuredSelection toArray

List of usage examples for org.eclipse.jface.viewers StructuredSelection toArray

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection toArray.

Prototype

@Override
    public Object[] toArray() 

Source Link

Usage

From source file:org.jboss.tools.jst.css.dialog.selector.CSSSelectorPartComposite.java

License:Open Source License

private void handleMoveDown() {
    StructuredSelection selection = (StructuredSelection) selectedClassesTableViewer.getSelection();
    Object[] selectedItems = selection.toArray();
    int[] selectedIndices = selectedClassesTableViewer.getTable().getSelectionIndices();
    int itemsCount = selectedClassesTableViewer.getTable().getItemCount();
    int selectionLength = selectedIndices.length;
    for (int i = 0; i < selectionLength; i++) {
        CSSSelectionEventManager.getInstance().setHandleSelection(false);
        selectedClassesTableViewer.remove(selectedItems[selectionLength - 1 - i]);
        if (selectedIndices[selectionLength - 1 - i] == itemsCount - 1) {
            TableItem item = new TableItem(selectedClassesTableViewer.getTable(),
                    selectedClassesTableViewer.getTable().getStyle(), itemsCount - 1);
            item.setData(selectedItems[selectionLength - 1 - i]);
            itemsCount--;//from   ww w  . j a  va  2 s.  c  o m
        } else {
            TableItem item = new TableItem(selectedClassesTableViewer.getTable(),
                    selectedClassesTableViewer.getTable().getStyle(),
                    selectedIndices[selectionLength - 1 - i] + 1);
            item.setData(selectedItems[selectionLength - 1 - i]);
        }
    }
    selectedClassesTableViewer.refresh();
    selectedClassesTableViewer.setSelection(new StructuredSelection(selectedItems));
    updateStyles();
}

From source file:org.jboss.tools.jst.css.dialog.selector.CSSSelectorPartComposite.java

License:Open Source License

private void handleMoveUp() {
    StructuredSelection selection = (StructuredSelection) selectedClassesTableViewer.getSelection();
    Object[] selectedItems = selection.toArray();
    int[] selectedIndices = selectedClassesTableViewer.getTable().getSelectionIndices();
    CSSSelectionEventManager.getInstance().setHandleSelection(false);
    selectedClassesTableViewer.remove(selection.toArray());
    for (int i = 0; i < selectedIndices.length; i++) {
        if (selectedIndices[i] == i) {
            TableItem item = new TableItem(selectedClassesTableViewer.getTable(),
                    selectedClassesTableViewer.getTable().getStyle(), i);
            item.setData(selectedItems[i]);
        } else {/*  www.j av a  2 s .co m*/
            TableItem item = new TableItem(selectedClassesTableViewer.getTable(),
                    selectedClassesTableViewer.getTable().getStyle(), selectedIndices[i] - 1);
            item.setData(selectedItems[i]);
        }
    }
    selectedClassesTableViewer.refresh();
    selectedClassesTableViewer.setSelection(new StructuredSelection(selectedItems));
    updateStyles();
}

From source file:org.jboss.tools.jst.css.dialog.selector.selection.CSSTableSelectionChangedEvent.java

License:Open Source License

@Override
public String[] getSelectedClassNames() {
    StructuredSelection structuredSelection = (StructuredSelection) selection;
    Object[] selectedObjects = structuredSelection.toArray();
    String[] selectedNames = new String[selectedObjects.length];
    for (int i = 0; i < selectedObjects.length; i++) {
        selectedNames[i] = selectedObjects[i].toString();
    }/*from  w  ww . ja  va 2 s  .  co m*/
    return selectedNames;
}

From source file:org.jkiss.dbeaver.ui.editors.binary.BinaryEditor.java

License:Open Source License

@Override
public void setSelection(ISelection selection) {
    if (selection.isEmpty())
        return;/*from   ww w .j a  v a  2 s . c  om*/
    StructuredSelection aSelection = (StructuredSelection) selection;
    long[] startEnd = (long[]) aSelection.getFirstElement();
    long start = startEnd[0];
    long end = start;
    if (startEnd.length > 1) {
        end = startEnd[1];
    }
    if (aSelection.size() > 1) {
        startEnd = (long[]) aSelection.toArray()[1];
        end = startEnd[0];
        if (startEnd.length > 1) {
            end = startEnd[1];
        }
    }
    manager.setSelection(start, end);
}

From source file:org.multicore_association.shim.edit.gui.jface.wizard.AddressSpaceEditorWizardPage.java

License:MIT License

/**
 * Refreshes the table viewers on this page.
 *//*ww w. j a va2  s . com*/
private void tableRefresh() {
    Object data = null;
    if (selectedItem == null || selectedItem.isDisposed()) {
        StructuredSelection selection = (StructuredSelection) addressSpaceTreeViewer.getSelection();
        Object[] selectionArray = selection.toArray();
        for (Object o : selectionArray) {
            data = o;
        }
    } else {
        data = selectedItem.getData();
    }

    // When using AddressSpaceTree From Wizard.
    if (data instanceof AddressSpace) {
        AddressSpace as = (AddressSpace) data;

        inputPanelAddressSpace.setInput(as);
        inputPanelAddressSpace.updateNameAttributeChecker();
    }
}

From source file:org.multicore_association.shim.edit.gui.swt.panel.CacheInputPanel.java

License:MIT License

/**
 * Constructs a new instance of CacheInputPanel.
 * /*from w  w w .j  ava2s .  c om*/
 * @param parent
 *            parent composite
 * @param style
 *            SWT style bits
 */
public CacheInputPanel(Composite parent, int style) {

    super(parent, SWT.NO_REDRAW_RESIZE);
    setLayout(new BorderLayout(0, 0));

    setLblTitleText("Cache");

    Composite composite = new Composite(this, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
    composite.setLayout(new GridLayout(3, false));

    Label lblNewLabel_2 = new Label(composite, SWT.NONE);
    lblNewLabel_2.setText("Name");
    new Label(composite, SWT.NONE);

    textName = new Text(composite, SWT.BORDER);
    textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblNewLabel_3 = new Label(composite, SWT.NONE);
    lblNewLabel_3.setText("cacheType");
    new Label(composite, SWT.NONE);

    comboCacheType = new ComboFactory(composite).createCombo(CacheType.class,
            ShimModelAdapter.isRequired(getApiClass(), "cacheType"));
    comboCacheType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lbl_Coherency = new Label(composite, SWT.NONE);
    lbl_Coherency.setText("Coherency");
    new Label(composite, SWT.NONE);

    comboCoherencyType = new ComboFactory(composite).createCombo(CacheCoherencyType.class,
            ShimModelAdapter.isRequired(getApiClass(), "cacheCoherency"));
    comboCoherencyType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblNewLabel_5 = new Label(composite, SWT.NONE);
    lblNewLabel_5.setText("Size");
    new Label(composite, SWT.NONE);

    Composite composite_4 = new Composite(composite, SWT.NONE);
    composite_4.setLayout(new GridLayout(2, false));

    textCacheSize = new Text(composite_4, SWT.BORDER);
    textCacheSize.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));

    comboCacheSizeUnit = new ComboFactory(composite_4).createCombo(SizeUnitType.class,
            ShimModelAdapter.isRequired(getApiClass(), "sizeUnit"));

    Label lblNewLabel_6 = new Label(composite, SWT.NONE);
    lblNewLabel_6.setText("nWay");
    new Label(composite, SWT.NONE);

    textNWay = new Text(composite, SWT.BORDER);
    textNWay.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lbl_lineSize = new Label(composite, SWT.NONE);
    lbl_lineSize.setText("lineSize (byte)");
    new Label(composite, SWT.NONE);

    textLineSize = new Text(composite, SWT.BORDER);
    textLineSize.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lbl_lockDownType = new Label(composite, SWT.NONE);
    lbl_lockDownType.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
    lbl_lockDownType.setText("LockDownType");
    new Label(composite, SWT.NONE);

    comboLockDownType = new ComboFactory(composite).createCombo(LockDownType.class,
            ShimModelAdapter.isRequired(getApiClass(), "lockDownType"));
    comboLockDownType.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));

    Label lblCacheref = new Label(composite, SWT.NONE);
    lblCacheref.setText("CacheRef");
    new Label(composite, SWT.NONE);

    Composite composite_cachButton = new Composite(composite, SWT.NONE);
    composite_cachButton.setLayout(new GridLayout(2, false));

    Button btnNewButton = new Button(composite_cachButton, SWT.NONE);
    btnNewButton.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent event) {
            setErrorMessage(null);

            if (cachetList.size() == 0) {
                Object rootInstance = ShimModelManager.getCurrentScd();
                cachetList = ShimModelAdapter.getObjectsList(Cache.class, rootInstance);
            }

            int beforeSize = cachetList.size();
            for (int i = 0; i < cachetList.size(); i++) {
                Object obj = cachetList.get(i).getObj();
                if (!obj.equals(cache)) {
                    ShimObject so = new ShimObject(obj);
                    if (!ShimObjectUtils.contains(objectList, so)) { //
                        objectList.add(so);
                        cacheRefTableViewer.setInput(objectList);
                        cacheRefTableViewer.refresh();
                        break;
                    }
                } else {
                    beforeSize = beforeSize - 1;
                }
            }

            if (beforeSize == 0) {
                setErrorMessage("There is no cache to set.");
            } else if (beforeSize <= objectList.size()) {
                setErrorMessage("All of Caches have been set in CacheRef.");
            }
        }
    });
    btnNewButton.setText("Add");

    Button btnNewButton_1 = new Button(composite_cachButton, SWT.NONE);
    btnNewButton_1.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent event) {
            setErrorMessage(null);

            if (objectList.size() > 0) {
                StructuredSelection selection = (StructuredSelection) cacheRefTableViewer.getSelection();
                Object[] selectionArray = selection.toArray();
                List<Object> newObjects = new ArrayList<Object>();
                for (Object o : selectionArray) {
                    ShimObject so = (ShimObject) o;
                    int idx = objectList.indexOf(so);
                    objectList.remove(so);
                    cacheRefTableViewer.setInput(objectList);
                    if (objectList.size() <= idx) {
                        idx = objectList.size() - 1;
                    }
                    if (idx < 0) {
                        idx = 0;
                    }
                    if (objectList.size() > 0) {
                        newObjects.add(objectList.get(idx));
                    }
                }
                StructuredSelection newSelection = new StructuredSelection(newObjects.toArray(new Object[0]));
                cacheRefTableViewer.setSelection(newSelection);
                cacheRefTableViewer.refresh();
            }
        }
    });
    btnNewButton_1.setText("Delete");

    Composite composite_cacheRef = new Composite(composite, SWT.NONE);
    composite_cacheRef.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 3, 1));
    composite_cacheRef.setLayout(new GridLayout(1, true));

    cacheRefTableViewer = new ShimRefTableViewer(composite_cacheRef, SWT.FILL, this, "CacheRef");
    table = cacheRefTableViewer.getTable();
    table.setLayoutData(new GridData(GridData.FILL_BOTH));
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    cacheRefTableViewer.initTabeleViewer(new CacheRefForDisplay().getClass(), false);

    // Checking Required.
    textName.addModifyListener(new TextModifyListener("name"));
    textNWay.addModifyListener(new TextModifyListener("nWay"));
    textNWay.addModifyListener(new NumberModifyListener("nWay"));
    textLineSize.addModifyListener(new TextModifyListener("blockSize"));
    textLineSize.addModifyListener(new NumberModifyListener("blockSize"));
    textCacheSize.addModifyListener(new TextModifyListener("size"));
    textCacheSize.addModifyListener(new NumberModifyListener("size"));
}

From source file:org.mwc.debrief.core.editors.PlotOutlinePage.java

License:Open Source License

void fillContextMenu(final IMenuManager manager) {
    // get the selected item
    final StructuredSelection sel = (StructuredSelection) _treeViewer.getSelection();

    // right, we only worry about primary, secondary, hide, reveal if something
    // is selected
    if (sel.size() > 0) {
        // ok, allow hide/reveal
        manager.add(_hideAction);/*from www .  ja v  a  2  s  . c om*/
        manager.add(_revealAction);

        // have a look at the data-types to sort out whether to primary/secondary
        if (isValidPrimary(sel))
            manager.add(_makePrimary);
        if (isValidSecondary(sel)) {
            manager.add(_makeSecondary);
            manager.add(_addAsSecondary);
        }

        // now stick in the separator anyway
        manager.add(new Separator());
    }

    // drillDownAdapter.addNavigationActions(manager);
    // Other plug-ins can contribute there actions here
    manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));

    // hey, sort out the data-specific items
    // build up a list of menu items

    // create some lists to store our selected items
    final Editable[] eList = new Editable[sel.size()];
    final Layer[] parentLayers = new Layer[sel.size()];
    final Layer[] updateLayers = new Layer[sel.size()];

    // right, now populate them
    final Object[] oList = sel.toArray();
    for (int i = 0; i < oList.length; i++) {
        final EditableWrapper wrapper = (EditableWrapper) oList[i];
        eList[i] = wrapper.getEditable();

        // sort out the parent layer
        final EditableWrapper theParent = wrapper.getParent();

        // hmm, did we find one?
        if (theParent != null)
            // yes, store it
            parentLayers[i] = (Layer) wrapper.getParent().getEditable();
        else
            // nope - store a null (to indicate it's a top-level layer)
            parentLayers[i] = null;

        updateLayers[i] = wrapper.getTopLevelLayer();
    }

    // ok, sort out what we can do with all of this...
    RightClickSupport.getDropdownListFor(manager, eList, updateLayers, parentLayers, _myLayers, false);

}

From source file:org.opentravel.schemas.views.ContextsView.java

License:Apache License

public List<ContextNode> getSelectedContextNodes() {
    if (viewer == null)
        return null; // In case the view is not activated.
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    List<ContextNode> nodes = new ArrayList<ContextNode>();
    for (Object object : selection.toArray()) {
        if (object != null && object instanceof ContextNode) {
            nodes.add((ContextNode) object);
        }//ww w . j  ava  2 s  .  c  o  m
    }
    return nodes;
}

From source file:org.opentravel.schemas.views.DocumentationView.java

License:Apache License

public List<DocumentationNode> getSelectedDocumentationNodes() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    List<DocumentationNode> nodes = new ArrayList<DocumentationNode>();
    for (Object object : selection.toArray()) {
        if (object != null && object instanceof DocumentationNode) {
            nodes.add((DocumentationNode) object);
        }/*w w  w .jav  a  2s.  com*/
    }
    return nodes;
}

From source file:org.rssowl.ui.internal.dialogs.CustomizeToolbarDialog.java

License:Open Source License

private void onMove(StructuredSelection selection, ToolBarItem destination, int location) {

    /* Determine Moved Items */
    List<ToolBarItem> movedItems = new ArrayList<ToolBarItem>();
    Object[] selectedElements = selection.toArray();
    for (Object element : selectedElements) {
        movedItems.add((ToolBarItem) element);
    }/*  www  .  j  a  va2s  . c  om*/

    /* Determine Visible Items */
    List<ToolBarItem> visibleItems = new ArrayList<ToolBarItem>();
    TableItem[] items = fItemViewer.getTable().getItems();
    for (TableItem item : items) {
        visibleItems.add((ToolBarItem) item.getData());
    }

    /* Return in these unlikely cases */
    if (movedItems.isEmpty() || visibleItems.isEmpty())
        return;

    /* Remove all Moved Items from Visible */
    visibleItems.removeAll(movedItems);

    /* Put Moved Items to Destination Index if possible */
    int destinationIndex = visibleItems.indexOf(destination);
    if (destinationIndex >= 0) {

        /* Adjust Destination */
        if (location == ViewerDropAdapter.LOCATION_ON || location == ViewerDropAdapter.LOCATION_AFTER)
            destinationIndex++;

        /* Add to Visible */
        visibleItems.addAll(destinationIndex, movedItems);

        /* Save Visible */
        int[] newToolBarItems = new int[visibleItems.size()];
        for (int i = 0; i < visibleItems.size(); i++)
            newToolBarItems[i] = visibleItems.get(i).item.ordinal();
        fPreferences.putIntegers(DefaultPreferences.TOOLBAR_ITEMS, newToolBarItems);

        /* Show Updates */
        fItemViewer.refresh();

        /* Restore Selection */
        fItemViewer.getTable().setSelection(destinationIndex, destinationIndex + movedItems.size() - 1);

        /* Update Buttons */
        updateButtonEnablement();
    }
}