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.aptana.ide.ui.io.navigator.actions.FileSystemCopyAction.java

License:Open Source License

@Override
protected boolean updateSelection(IStructuredSelection selection) {
    fFileStores.clear();/*from  ww  w  .  j ava2s .c  o  m*/
    if (!super.updateSelection(selection)) {
        return false;
    }

    if (selection == null || selection.isEmpty()) {
        return false;
    }
    Object[] elements = selection.toArray();

    IFileStore fileStore;
    for (Object element : elements) {
        fileStore = getFileStore(element);
        if (fileStore != null) {
            fFileStores.add(fileStore);
        }
    }
    if (fFileStores.size() == 0) {
        return false;
    }

    // must have a common parent
    IFileStore firstParent = fFileStores.get(0).getParent();
    if (firstParent == null) {
        return false;
    }

    for (IFileStore store : fFileStores) {
        if (!store.getParent().equals(firstParent)) {
            return false;
        }
    }

    return true;
}

From source file:com.aptana.ide.ui.io.navigator.actions.FileSystemEditActionGroup.java

License:Open Source License

@Override
public void fillContextMenu(IMenuManager menu) {
    IStructuredSelection selection = getSelection();
    fCopyAction.selectionChanged(selection);
    menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, fCopyAction);
    fPasteAction.selectionChanged(selection);
    menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, fPasteAction);

    if (selection != null && !selection.isEmpty()) {
        Object[] elements = selection.toArray();
        boolean allFileSystemObjects = true;
        for (Object element : elements) {
            if (element instanceof LocalRoot || element instanceof IConnectionPoint) {
                allFileSystemObjects = false;
                break;
            }/*from  w  w  w  .  j  a  va  2 s .  co m*/
        }
        if (allFileSystemObjects) {
            menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, fDeleteAction);
        }
    }
}

From source file:com.aptana.ide.ui.io.navigator.actions.FileSystemPasteAction.java

License:Open Source License

@Override
protected boolean updateSelection(IStructuredSelection selection) {
    fDestFileStores.clear();//from  w w w .  j  a  v a  2  s  .  c  o m
    selectedFiles.clear();
    fClipboardData = NO_FILES;
    if (!super.updateSelection(selection)) {
        return false;
    }

    if (selection == null || selection.isEmpty()) {
        return false;
    }
    Object[] elements = selection.toArray();

    IFileStore fileStore;
    for (Object element : elements) {
        fileStore = getFileStore(element);
        if (fileStore != null) {
            if (!Utils.isDirectory(fileStore)) {
                fileStore = fileStore.getParent();
            }
            fDestFileStores.add(fileStore);

            if (element instanceof IAdaptable) {
                IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class);
                if (resource != null) {
                    selectedFiles.add((resource instanceof IContainer) ? resource : resource.getParent());
                } else {
                    selectedFiles.add(new FileSystemObject(fileStore, FileSystemUtils.getFileInfo(fileStore)));
                }
            }
        }
    }
    if (fDestFileStores.size() == 0) {
        return false;
    }

    fShell.getDisplay().syncExec(new Runnable() {

        public void run() {
            // clipboard must have files
            LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
            Object contents = fClipboard.getContents(transfer);
            if (contents instanceof StructuredSelection) {
                Object[] elements = ((StructuredSelection) contents).toArray();
                List<IFileStore> fileStores = new ArrayList<IFileStore>();
                for (Object element : elements) {
                    if (element instanceof IFileStore) {
                        fileStores.add((IFileStore) element);
                    }
                }
                fClipboardData = fileStores.toArray(new IFileStore[fileStores.size()]);
            }
        }
    });
    if (fClipboardData.length > 0) {
        return true;
    }

    TransferData[] transfers = fClipboard.getAvailableTypes();
    FileTransfer fileTransfer = FileTransfer.getInstance();
    for (int i = 0; i < transfers.length; ++i) {
        if (fileTransfer.isSupportedType(transfers[i])) {
            return true;
        }
    }
    return false;
}

From source file:com.aptana.ide.ui.io.navigator.actions.FileSystemRefreshAction.java

License:Open Source License

protected boolean updateSelection(IStructuredSelection selection) {
    fSelectedElements = null;/*from  w  w  w  .ja v  a2s.  com*/
    if (selection != null && !selection.isEmpty()) {
        fSelectedElements = selection.toArray();
    }
    return super.updateSelection(selection) && fSelectedElements != null;
}

From source file:com.aptana.ide.ui.io.navigator.actions.OpenFileAction.java

License:Open Source License

public boolean updateSelection(IStructuredSelection selection) {
    fFileStores.clear();//from  w ww  . j a va2  s .  co  m

    if (selection != null && !selection.isEmpty()) {
        Object[] elements = selection.toArray();
        IFileStore fileStore;
        for (Object element : elements) {
            if (element instanceof IAdaptable) {
                fileStore = Utils.getFileStore((IAdaptable) element);
                if (fileStore != null) {
                    fFileStores.add(fileStore);
                }
            }
        }
    }

    return super.updateSelection(selection) && fFileStores.size() > 0;
}

From source file:com.aptana.ide.ui.io.navigator.resources.FileDragAdapterAssistant.java

License:Open Source License

private IFileStore[] getSelectedFiles(IStructuredSelection aSelection) {
    Set<IFileStore> files = new LinkedHashSet<IFileStore>();
    IFileStore file;//from  w  w  w. ja va  2 s.c o  m
    Object[] selectedElements = aSelection.toArray();
    for (Object selected : selectedElements) {
        file = FileSystemUtils.getFileStore(selected);
        if (file != null) {
            files.add(file);
        }
    }
    return files.toArray(new IFileStore[files.size()]);
}

From source file:com.aptana.index.core.ui.handlers.BaseHandler.java

License:Open Source License

@Override
public void setEnabled(Object evaluationContext) {
    // clear cached selection
    this.clearFileStores();

    if (evaluationContext instanceof IEvaluationContext) {
        IEvaluationContext context = (IEvaluationContext) evaluationContext;
        Object value = context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);

        if (value instanceof ISelection) {
            ISelection selection = (ISelection) value;

            if (selection instanceof IStructuredSelection && selection.isEmpty() == false) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;

                for (Object object : structuredSelection.toArray()) {
                    if (object instanceof IProject || object instanceof IFolder || object instanceof IFile) {
                        IResource resource = (IResource) object;
                        IFileStore fileStore = EFSUtils.getFileStore(resource);

                        if (this.isValid(fileStore)) {
                            this.addFileStore(fileStore);
                        }//from  ww  w.  ja v a 2 s  . c o  m
                    }
                }
            }
        }
    }
}

From source file:com.aptana.ui.widgets.CListTable.java

License:Open Source License

/**
 * @param parent//from  w w  w .  j a  v a  2  s  .  c  om
 *            the parent composite
 * @param style
 *            the style bits
 */
public CListTable(Composite parent, int style) {
    super(parent, style);
    items = new ArrayList<Object>();
    listeners = new ArrayList<Listener>();

    setLayout(GridLayoutFactory.fillDefaults().create());

    descriptionLabel = new Label(this, SWT.WRAP);
    descriptionLabel.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    Composite buttons = new Composite(this, SWT.NONE);
    buttons.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).create());
    buttons.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    addButton = new Button(buttons, SWT.PUSH);
    addButton.setToolTipText(StringUtil.ellipsify(CoreStrings.ADD));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean itemAdded = false;
            Object newItem = null;
            for (Listener listener : listeners) {
                newItem = listener.addItem();
                if (newItem != null) {
                    items.add(newItem);
                    itemAdded = true;
                }
            }
            if (itemAdded) {
                tableViewer.refresh();
                tableViewer.setSelection(new StructuredSelection(newItem));
                for (Listener listener : listeners) {
                    listener.itemsChanged(getItems());
                }
            }
        }
    });
    addButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/add.gif")); //$NON-NLS-1$

    editButton = new Button(buttons, SWT.PUSH);
    editButton.setToolTipText(StringUtil.ellipsify(CoreStrings.EDIT));
    editButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            if (!selection.isEmpty()) {
                Object element = selection.getFirstElement();
                items.remove(element);
                Object newElement = null;
                boolean changed = false;
                for (Listener listener : listeners) {
                    newElement = listener.editItem(element);
                    if (newElement != null) {
                        items.add(newElement);
                        changed = true;
                    }
                }
                if (changed) {
                    tableViewer.refresh();
                    tableViewer.setSelection(new StructuredSelection(newElement));
                    for (Listener listener : listeners) {
                        listener.itemsChanged(getItems());
                    }
                }
            }
        }

    });
    editButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/edit.png")); //$NON-NLS-1$

    removeButton = new Button(buttons, SWT.PUSH);
    removeButton.setToolTipText(CoreStrings.REMOVE);
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            Object[] elements = selection.toArray();
            for (Object element : elements) {
                items.remove(element);
            }
            tableViewer.refresh();
            updateStates();
            for (Listener listener : listeners) {
                listener.itemsChanged(getItems());
            }
        }
    });
    removeButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/delete.gif")); //$NON-NLS-1$

    createTable(this);
}

From source file:com.arc.cdt.debug.seecode.internal.ui.action.AbstractDebugActionDelegate.java

License:Open Source License

/**
 * Runs this action in a background job.
 *///w ww  . j  a  v a  2s  .  co m
private void runInBackground(IAction action, IStructuredSelection selection) {
    if (fBackgroundJob == null) {
        fBackgroundJob = new DebugRequestJob(action.getText());
    }
    fBackgroundJob.setTargets(selection.toArray());
    fBackgroundJob.schedule();
}

From source file:com.archimatetool.editor.diagram.dnd.AbstractDiagramTransferDropTargetListener.java

License:Open Source License

/**
 * Check that the dragged selection is being dragged into the same model
 *///  w  ww  .j av  a 2 s  .c om
protected boolean isSelectionFromSameModel(IStructuredSelection selection) {
    IArchimateModel targetArchimateModel = getTargetDiagramModel().getArchimateModel();

    for (Object object : selection.toArray()) {
        if (object instanceof IArchimateModelElement) {
            IArchimateModel sourceArchimateModel = ((IArchimateModelElement) object).getArchimateModel();
            if (sourceArchimateModel != targetArchimateModel) {
                return false;
            }
        }
    }

    return true;
}