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.mentor.nucleus.bp.debug.ui.propertypages.VerifierExceptionBreakpointPage.java

License:Open Source License

/**
 * @see org.eclipse.jdt.internal.debug.ui.propertypages.JavaBreakpointPage#doStore()
 *///  ww  w  .ja  va 2  s  .  c om
protected void doStore() throws CoreException {
    IStructuredSelection sel = (IStructuredSelection) fBreakpointViewer.getSelection();
    Object[] items = sel.toArray();
    for (int i = 0; i < items.length; ++i) {
        int typeId = VerifierExceptionBreakpoint.getBPTypeId((String) items[i]);
        VerifierExceptionBreakpoint breakpoint = new VerifierExceptionBreakpoint(typeId);
        DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(breakpoint);
    }
}

From source file:com.mercatis.lighthouse3.base.ui.handlers.AbstractDeleteHandler.java

License:Apache License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    preExecution(event);/* w w  w .jav a2s.  c  o m*/

    activePart = HandlerUtil.getActivePart(event);
    currentSelection = HandlerUtil.getCurrentSelection(event);
    if (currentSelection == null || !(currentSelection instanceof IStructuredSelection)) {
        return null;
    }

    IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
    Object[] elements = structuredSelection.toArray();

    if (showDialog(elements)) {
        for (Object element : elements) {
            execute(element);
        }
    } else {
        return null;
    }

    postExecution(event);
    return null;
}

From source file:com.mercatis.lighthouse3.base.ui.handlers.AbstractStructuredSelectionHandler.java

License:Apache License

public Object execute(ExecutionEvent event) throws ExecutionException {
    preExecution(event);//from   ww w  . j  a  va 2  s  .  c o  m

    activePart = HandlerUtil.getActivePart(event);
    currentSelection = HandlerUtil.getCurrentSelection(event);

    if (currentSelection == null || !(currentSelection instanceof IStructuredSelection)) {
        return null;
    }

    IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
    Object[] elements = structuredSelection.toArray();

    for (Object element : elements) {
        execute(element);
    }

    postExecution(event);
    return null;
}

From source file:com.mercatis.lighthouse3.ui.environment.dnd.BaseDropAdapterAssistant.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override//from w w  w .j  a  v  a 2  s. c o m
public IStatus validateDrop(Object target, int operation, TransferData transferType) {
    this.elements = null;
    this.operation = operation;

    ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
    if (selection == null || !(selection instanceof IStructuredSelection))
        return new Status(IStatus.ERROR, CommonUIActivator.PLUGIN_ID,
                "Selection either null or no structured selection.");

    IStructuredSelection sselection = (IStructuredSelection) selection;
    Object[] elements = sselection.toArray();
    for (Object element : elements) {
        if (target == element)
            return new Status(IStatus.ERROR, CommonUIActivator.PLUGIN_ID,
                    "You cannot drop yourself on yourself, dickhead!.");
    }

    DropTargetAdapter adapter = (DropTargetAdapter) adapterManager.getAdapter(target, DropTargetAdapter.class);
    if (adapter == null)
        return new Status(IStatus.ERROR, CommonUIActivator.PLUGIN_ID, "Drop Target ("
                + target.getClass().getName() + ") is not adaptable to " + DropTargetAdapter.class.getName());

    if (!adapter.validateDrop(operation, target, elements))
        return new Status(IStatus.ERROR, CommonUIActivator.PLUGIN_ID,
                "Drop Target (" + target.getClass().getName() + ") does not accept " + elements.toString());

    this.elements = elements;
    return Status.OK_STATUS;
}

From source file:com.microsoft.tfs.client.common.ui.framework.helper.SelectionUtils.java

License:Open Source License

/**
 * Returns the elements contained in the selection as an array. The runtime
 * type of the array is {@link Object}. The array is computed in the
 * following way:/*from w w  w  . java2 s .  c o  m*/
 * <ul>
 * <li>If the selection is <code>null</code>, an empty array is returned
 * </li>
 * <li>If the selection is not an {@link IStructuredSelection}, an
 * {@link IllegalArgumentException} is thrown</li>
 * <li>Otherwise, the selection's elements are converted to an array and
 * returned</li>
 * </ul>
 *
 * @param selection
 *        the {@link ISelection} to get the elements for (can be
 *        <code>null</code> but if non-<code>null</code> must be an
 *        {@link IStructuredSelection})
 * @throws IllegalArgumentException
 *         if the specified {@link ISelection} is not <code>null</code> and
 *         is not an {@link IStructuredSelection}
 * @return the selection elements as an {@link Object} array (never
 *         <code>null</code>)
 */
public static final Object[] selectionToArray(final ISelection selection) {
    final IStructuredSelection ss = getStructuredSelection(selection);
    return (ss == null ? new Object[0] : ss.toArray());
}

From source file:com.microsoft.tfs.client.common.ui.framework.table.TableControl.java

License:Open Source License

/**
 * <p>/*from w w w.  j a  v a2 s.  co m*/
 * This method computes the currently selected elements in this
 * {@link TableControl} and caches them. The selected elements can be
 * retrieved by calling {@link #getSelectedElements()}. As a result of
 * calling this method, any registered {@link ISelectionChangedListener}s
 * are notified of a change in the selected elements collection.
 * </p>
 *
 * <p>
 * Normally, there is no reason for subclasses to call this method. Changes
 * to the selected elements are detected automatically by this base class.
 * </p>
 */
protected final void computeSelectedElements(final boolean fireEvent) {
    final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    final Object[] elements = selection.toArray();

    selectedElements = computeElementCollectionInternal(elements, ElementCollectionType.SELECTED_ELEMENTS);

    if (fireEvent) {
        notifySelectionChangedListeners();
    }
}

From source file:com.microsoft.tfs.client.common.ui.views.PendingChangesView.java

License:Open Source License

@Override
public ShowInContext getShowInContext() {
    final IStructuredSelection selection = (IStructuredSelection) getViewSite().getSelectionProvider()
            .getSelection();//from   www.  ja v  a 2s. c o  m

    final Object[] elements = selection.toArray();

    for (int i = 0; i < elements.length; i++) {
        if (elements[i] instanceof ChangeItem) {
            final ChangeItem changeItem = (ChangeItem) elements[i];
            if (changeItem.getType() == ChangeItemType.PENDING) {
                final PendingChange pendingChange = changeItem.getPendingChange();
                final IResource resource = getResourceForPendingChange(pendingChange);

                if (resource != null) {
                    elements[i] = resource;
                }
            }
        }
    }

    return new ShowInContext(null, new StructuredSelection(elements));
}

From source file:com.microsoft.tfs.client.common.ui.wit.qe.BaseResultOptionsControl.java

License:Open Source License

private void select() {
    final IStructuredSelection selection = (IStructuredSelection) availableColumnsList.getSelection();
    final Object[] objArray = selection.toArray();
    final FieldDefinition[] fieldDefinitionArray = new FieldDefinition[objArray.length];
    for (int i = 0; i < objArray.length; i++) {
        fieldDefinitionArray[i] = (FieldDefinition) objArray[i];
    }//from   w  w  w. j  a  v  a  2 s .  c o  m

    final Object[] selectedObjects = select(fieldDefinitionArray, resultOptions);

    refreshAvailableColumns();
    refreshSelectedColumns();

    selectedColumnsTable.setSelection(new StructuredSelection(selectedObjects));
}

From source file:com.microsoft.tfs.client.common.ui.wit.qe.BaseResultOptionsControl.java

License:Open Source License

private void deselect() {
    final IStructuredSelection selection = (IStructuredSelection) selectedColumnsTable.getSelection();
    final Object[] objArray = selection.toArray();

    final String[] fieldNames = deselect(objArray, resultOptions);

    refreshAvailableColumns();/*from   w w  w .  j a v a 2s  .c o  m*/
    refreshSelectedColumns();

    final FieldDefinition[] fieldDefinitionArray = new FieldDefinition[fieldNames.length];

    for (int i = 0; i < fieldNames.length; i++) {
        fieldDefinitionArray[i] = fieldDefinitions.get(fieldNames[i]);
    }

    availableColumnsList.setSelection(new StructuredSelection(fieldDefinitionArray));
}

From source file:com.microsoft.tfs.client.eclipse.ui.actions.sync.SynchronizeActionGroup.java

License:Open Source License

public IResource[] getSelection() {
    final ISelection baseSelection = site.getSelectionProvider().getSelection();

    if (!(baseSelection instanceof IStructuredSelection)) {
        return null;
    }//  w  w  w . j av a  2  s . c  om

    final IStructuredSelection selection = (IStructuredSelection) baseSelection;

    // exactly one file must be selected for this functionality to exist
    if (selection == null || selection.size() == 0 || !(selection instanceof IStructuredSelection)) {
        return null;
    }

    final Object[] elements = selection.toArray();
    final IResource resources[] = Utils.getResources(elements);

    return resources;
}