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

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

Introduction

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

Prototype

public List toList();

Source Link

Document

Returns the elements in this selection as a List.

Usage

From source file:com.nextep.designer.vcs.ui.handlers.NewContainerBasedTypedInstanceHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection s = HandlerUtil.getCurrentSelection(event);
    IVersionContainer parentContainer = null;
    if (s instanceof IStructuredSelection) {
        final IStructuredSelection sel = (IStructuredSelection) s;
        for (Object o : sel.toList()) {
            parentContainer = findContainer(o);
            if (parentContainer != null) {
                break;
            }//from w  w  w.  ja v a  2  s  .  c o  m
        }
    }
    if (parentContainer == null) {
        parentContainer = getViewService().getCurrentWorkspace();
    }

    // Creating our new object
    Object o = newInstance(event, parentContainer);
    String noEditionAfterCreation = event.getParameter("com.neXtep.designer.core.noEdition"); //$NON-NLS-1$
    if (noEditionAfterCreation == null || "".equals(noEditionAfterCreation)) { //$NON-NLS-1$
        // Calling default editing action
        UIControllerFactory.getController(o).defaultOpen((ITypedObject) o);
    }
    return null;
}

From source file:com.nokia.carbide.cpp.internal.project.ui.editors.common.ControlHandler.java

License:Open Source License

public static Object getControlValue(Control control) {
    Object result = null;/*from   ww  w  . ja  v a2  s .  c  om*/
    ControlHandler handler = getHandlerForControl(control);
    if (handler != null && handler.viewer != null) {
        ISelection selection = handler.viewer.getSelection();
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection ss = (IStructuredSelection) selection;
            List list = ss.toList();
            if (list.size() == 1) {
                result = list.get(0);
            } else {
                result = list;
            }
        }
    } else if (control instanceof Text) {
        result = ((Text) control).getText();
    } else if (control instanceof Combo) {
        result = ((Combo) control).getText();
    } else if (control instanceof Button) {
        result = ((Button) control).getSelection();
    }
    return result;
}

From source file:com.nokia.carbide.cpp.internal.project.ui.editors.images.AIFEditorListPage.java

License:Open Source License

/**
 * Refresh the selection after the list changes.
 *///from   w ww  . j  a  v a 2s. c o m
public void refreshSelection() {
    IStructuredSelection selection = (IStructuredSelection) imageSourceTable.getTableViewer().getSelection();
    IMMPAIFInfo mis = AIFEditorListPage.this.editorContext.getMMPAIFInfo();
    imageSourceReferences.clear();
    imageIndices.clear();
    for (Object obj : selection.toList()) {
        if (obj instanceof IImageSourceReference) {
            imageSourceReferences.add((IImageSourceReference) obj);
            imageIndices.add(mis.getSourceBitmaps().indexOf(obj));
        }
    }
    Collections.sort(imageIndices);
    imageSourceTable.refresh();
    imagePropertiesComposite.refresh();

}

From source file:com.nokia.carbide.cpp.internal.project.ui.editors.images.MultiImageListPage.java

License:Open Source License

/**
 * Refresh the selection after the list changes.
 *//*from w w w .ja  v  a  2  s .c o m*/
public void refreshSelection() {
    IStructuredSelection selection = (IStructuredSelection) imageSourceTable.getTableViewer().getSelection();
    IMultiImageSource mis = MultiImageListPage.this.editorContext.getMultiImageSource();
    imageSources.clear();
    imageIndices.clear();
    for (Object obj : selection.toList()) {
        if (obj instanceof IImageSource) {
            imageSources.add((IImageSource) obj);
            imageIndices.add(mis.getSources().indexOf(obj));
        }
    }
    Collections.sort(imageIndices);
    imageSourceTable.refresh();
    selectedImagePropertiesPane.refresh();
}

From source file:com.nokia.carbide.cpp.internal.project.ui.editors.images.SelectOrAddImagesDialogBase.java

License:Open Source License

/**
 * Handle the change of selection inside the thumbnail viewer.
 * @param selection//from  w  w w  .j a v  a2 s  . co  m
 */
protected void handleThumbnailViewerSelectionChanged(IStructuredSelection selection) {
    selectedImages = selection.toList();
    Button okButton = getButton(IDialogConstants.OK_ID);
    if (okButton != null)
        okButton.setEnabled(selection != null && !selection.isEmpty());
}

From source file:com.nokia.carbide.cpp.internal.project.ui.mmpEditor.MissingSourcesSectionPart.java

License:Open Source License

protected void removeButtonPressed() {
    List<Integer> indices = new ArrayList<Integer>();
    List sourceList = EMMPListSelector.SOURCES.fetchList(editorContext.mmpView);
    IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        int index = sourceList.indexOf(iter.next());
        if (index >= 0) {
            indices.add(index);//from w ww.  j a  v  a 2s.c o  m
        }
    }

    RemoveListValueOperation command = new RemoveListValueOperation(editorContext.mmpView,
            new FormEditorEditingContext(editorContext.editor, tableViewer.getControl()),
            ControlHandler.getHandlerForViewer(tableViewer), EMMPListSelector.SOURCES, indices);
    editorContext.executeOperation(command);

    missingFilePaths.removeAll(selection.toList());
    tableViewer.refresh();
}

From source file:com.nokia.carbide.cpp.uiq.ui.vieweditor.CommandElementDragListener.java

License:Open Source License

/**
 * Method declared on DragSourceListener
 *///from   w ww . j  a v  a 2s.c o  m
public void dragSetData(DragSourceEvent event) {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Object[] elements = (Object[]) selection.toList().toArray(new Object[selection.size()]);
    if (CommandElementTransfer.getInstance().isSupportedType(event.dataType)) {
        event.data = elements;
    }
}

From source file:com.nokia.carbide.cpp.uiq.ui.vieweditor.CommandElementDragListener.java

License:Open Source License

/**
 * Method declared on DragSourceListener
 *//* w ww  .j a va 2s.  c  o  m*/
public void dragStart(DragSourceEvent event) {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Object[] elements = (Object[]) selection.toList().toArray(new Object[selection.size()]);
    if (elements[0] instanceof CommandList) {
        event.detail = DND.DROP_NONE;
        event.doit = false;
        return;
    }
    event.doit = !viewer.getSelection().isEmpty();
}

From source file:com.nokia.carbide.cpp.uiq.ui.vieweditor.ControlHandlerCommands.java

License:Open Source License

public static Object getControlValue(Control control) {
    Object result = null;//  w  w w. j a  v  a2  s.c  om
    ControlHandlerCommands handler = getHandlerForControl(control);
    if (handler != null && handler.viewer != null) {
        ISelection selection = handler.viewer.getSelection();
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection ss = (IStructuredSelection) selection;
            List list = ss.toList();
            if (list.size() == 1) {
                result = list.get(0);
            } else {
                result = list;
            }
        }
    } else if (control instanceof Text) {
        result = ((Text) control).getText();
    } else if (control instanceof CCombo) {
        result = ((CCombo) control).getText();
    } else if (control instanceof Button) {
        result = ((Button) control).getSelection();
    }
    return result;
}

From source file:com.nokia.s60ct.actions.EnableLiveValidationDelegate.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    this.selectedEObjects = null;
    try {// w w w  .j a v a 2s.co m
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            this.selectedEObjects = structuredSelection.toList();
        }
    } catch (Exception e) {
        // Exceptions are not expected
        MessageDialog.openInformation(shell, title, MESSAGE_EXCEPTION);
        throw new RuntimeException(e);
    } finally {
        action.setEnabled((null != selectedEObjects));
    }

    for (Iterator i = selectedEObjects.iterator(); i.hasNext();) {
        Object o = i.next();
        if (!(o instanceof Feature) && !(o instanceof Setting)) {
            action.setEnabled(false);
        } else if (resourceHasAdapter((EObject) o)) {
            action.setEnabled(false);
        }
    }

}