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

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

Introduction

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

Prototype

@Override
    public Object getFirstElement() 

Source Link

Usage

From source file:com.nokia.carbide.cpp.internal.pi.wizards.ui.views.PIView.java

License:Open Source License

private void hookDoubleClickAction() {
    viewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof StructuredSelection) {
                StructuredSelection structuredSelection = (StructuredSelection) selection;
                openProfilerDataFile(((TraceFile) structuredSelection.getFirstElement()));
            }/*from   w  w w .j av a2  s. co m*/
        }
    });
}

From source file:com.nokia.cdt.internal.debug.launch.ui.ChooseProcessDialog.java

License:Open Source License

@Override
protected void okPressed() {
    StructuredSelection selectedItems = (StructuredSelection) viewer.getSelection();
    Check.checkState(!selectedItems.isEmpty());
    Object object = selectedItems.getFirstElement();
    Check.checkState(object instanceof ParsedProcess);
    selectedProcess = parsedProcessMap.get(object);
    super.okPressed();
}

From source file:com.nokia.s60tools.testdrop.actions.BindingAction.java

License:Open Source License

/**
 * Selection in the workbench has been changed. We can change the state of
 * the 'real' action here if we want, but this can only happen after the
 * delegate has been created.//from   w ww  . j a v a 2  s.c o m
 * 
 * @see IWorkbenchWindowActionDelegate#selectionChanged
 */
public void selectionChanged(IAction action, ISelection selection) {
    validTestDropItemSelected = false; //we assume first that selection is invalid
    if (selection instanceof StructuredSelection) {
        StructuredSelection strSel = (StructuredSelection) selection;
        Object res = strSel.getFirstElement();
        if (res instanceof IProject) {
            IProject project = (IProject) res;
            validTestDropItemSelected = project.isOpen(); //if project is open then this is a valid selection
        } else if (res instanceof IFile) {
            IFile file = (IFile) res;
            String extension = file.getFileExtension();
            if (extension.equals("cfg")) {
                validTestDropItemSelected = true; //if this is a cfg file then this is a valid selection
            }
        }
    }
}

From source file:com.nokia.s60tools.testdrop.actions.SendTestDropAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    if (selection instanceof StructuredSelection) {
        StructuredSelection strSel = (StructuredSelection) selection;
        Object res = strSel.getFirstElement();
        if (res instanceof IProject) {
            IProject project = ((IResource) res).getProject();
            StartUp.setSelectedProject(project);
            LogExceptionHandler.log(project.getName());
        } else if (res instanceof IFile) {
            Object[] cfgObjects = strSel.toArray();
            IFile[] cfgFiles = new IFile[cfgObjects.length];
            for (int i = 0; i < cfgObjects.length; i++) {
                cfgFiles[i] = (IFile) cfgObjects[i];
            }/*from   ww w  .ja va2 s .co m*/
            StartUp.setSelectedCfgFiles(cfgFiles);
        }
    }
}

From source file:com.nokia.tools.s60.cheatsheet.actions.OpenGraphicsEditorAction.java

License:Open Source License

private boolean isSupportedForSelection() {

    IconView iw = (IconView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .findView(IconView.ID);
    ISelection selection = iw.getSelection();

    if (selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        Object contentData = structuredSelection.getFirstElement();

        if (contentData instanceof IContentData) {

            IContentData data = (IContentData) contentData;

            if (data != null) {
                IToolBoxAdapter toolBoxAdapter = (IToolBoxAdapter) data.getAdapter(IToolBoxAdapter.class);
                if (toolBoxAdapter != null && toolBoxAdapter.isMultipleLayersSupport())
                    return true;

                IImageAdapter imageAdapter = (IImageAdapter) data.getAdapter(IImageAdapter.class);
                if (imageAdapter != null)
                    if (imageAdapter.isAnimated())
                        return true;
                MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Information",
                        "Selected element(" + data.toString()
                                + ") cannot be animated. Frames can be animated only for animated icons.");
            }//from   w ww . java 2 s.  co  m
        }

    }

    return false;
}

From source file:com.nokia.tools.s60.editor.dnd.S60BaseDropListener.java

License:Open Source License

public static Object getDropData(DropTargetEvent evt) {
    Transfer t = null;/*from  w w w.j  ava 2s  .com*/

    if (FileTransfer.getInstance().isSupportedType(evt.currentDataType))
        t = FileTransfer.getInstance();
    else if (TextTransfer.getInstance().isSupportedType(evt.currentDataType))
        t = TextTransfer.getInstance();
    else if (LocalSelectionTransfer.getInstance().isSupportedType(evt.currentDataType))
        t = LocalSelectionTransfer.getInstance();

    if (t.isSupportedType(evt.currentDataType)) {

        if (t instanceof LocalSelectionTransfer) {

            // this is just for dropping colors
            LocalSelectionTransfer tempT = (LocalSelectionTransfer) t;

            StructuredSelection selection = (StructuredSelection) tempT.getSelection();
            if (selection != null && !selection.isEmpty()) {
                Object data = selection.getFirstElement();
                if (data instanceof DraggedColorObject) {
                    return data;
                }
            }
            // end for dropping color

            Object data = evt.data;
            if (data == null) {
                data = ((LocalSelectionTransfer) t).nativeToJava(evt.currentDataType);
            }
            if (data != null) {
                Object imageData = ((IStructuredSelection) data).getFirstElement();
                return imageData;
            }
        }

        if (t instanceof FileTransfer) {
            Object data = evt.data;
            if (data == null) {
                data = ((FileTransfer) t).nativeToJava(evt.currentDataType);
            }
            return (String[]) data;
        }

        if (t instanceof TextTransfer) {
            Object data = evt.data;
            if (data == null) {
                data = ((TextTransfer) t).nativeToJava(evt.currentDataType);
            }
            String text = (String) data;
            return text;
        }

    }

    return null;
}

From source file:com.nokia.tools.s60.editor.Series60EditorPart.java

License:Open Source License

public void selectReveal(ISelection selection) {
    if (!selection.isEmpty()) {
        StructuredSelection select = (StructuredSelection) selection;
        if (select.getFirstElement() instanceof IContentData) {
            List<Object> data = new ArrayList<Object>();
            for (Iterator iter = select.iterator(); iter.hasNext();) {
                Object obj = iter.next();
                if (obj instanceof IContentData) {
                    data.add(obj);/*  w  w w  .  j  a  va2 s .c  o m*/
                }
            }

            if (!selectAndRevealData(data.toArray(new IContentData[0]), null))
                throw new RuntimeException(EditorMessages.Editor_Error_NoPreviewScreen);
        }
    } else {
        getEditPartViewer().deselectAll();
    }
}

From source file:com.nokia.tools.s60ct.confml.editor.popup.actions.OpenEditorHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {

    window = HandlerUtil.getActiveWorkbenchWindow(event);

    ISelection sel = HandlerUtil.getCurrentSelection(event);

    Object element = null;/*from  w  w  w  .  ja  v a2  s  .  com*/

    if (sel instanceof ITreeSelection) {
        ITreeSelection ts = (ITreeSelection) sel;
        element = ts.getFirstElement();
    } else if (sel instanceof StructuredSelection) {
        StructuredSelection ss = (StructuredSelection) sel;
        element = ss.getFirstElement();
    }

    if (element instanceof EAppFeature) {
        URI uri;
        EAppFeature feature = (EAppFeature) element;
        String editorId = getEditorId();
        EConfMLLayer layer = getLayer(feature);
        uri = searchDataFile(layer);
        if (uri == null) {
            uri = getDataConfMLFileURI(layer);
        }
        if (editorId != null && uri != null) {
            uri = uri.appendFragment(feature.getRef());
            URIEditorInput input = new ValueEditorInputAppFeature(uri, feature);
            openEditor(input, editorId);
        }
    } else if (element instanceof EAppGroup) {
        EAppGroup group = (EAppGroup) element;

        EConfMLLayer layer = getLayer(group);
        String editorId = getEditorId();

        URI baseUri = searchDataFile(layer);
        if (baseUri == null) {
            baseUri = getDataConfMLFileURI(layer);
        }

        URI uri = baseUri.appendFragment(getGroupFragment(group));
        URIEditorInput input = new ValueEditorInputAppGroup(uri, group);

        openEditor(input, editorId);
    } else if (element instanceof EAppView) {
        URI uri = ArrayUtils.getLast(((EAppView) element).getUri());
        if (uri != null) {
            uri = uri.trimFragment();
            String editorId = ConfmlUI.VIEW_EDITOR_ID;
            EditorUtils.openEditor(uri, editorId);
        }
    } else {
    }

    return null;

}

From source file:com.nokia.tools.s60ct.confml.viewer.NotesView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {

    tv = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    table = tv.getTable();//  w ww  .j av  a2s .c  om

    table.setLayoutData(new GridData(GridData.FILL_BOTH));

    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    GridData layoutData = (GridData) table.getLayoutData();
    layoutData.horizontalSpan = 1;
    layoutData.grabExcessHorizontalSpace = true;
    layoutData.horizontalAlignment = SWT.FILL;

    table.setLayoutData(layoutData);

    addColumn(new Column(NOTES_COLUMN_1_NAME, COLUMN_1_WIDTH));
    addColumn(new Column(NOTES_COLUMN_2_NAME, COLUMN_2_WIDTH));

    tv.setContentProvider(new NotesContentProvider());
    tv.setLabelProvider(new NotesLabelProvider());

    tv.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            Entry entry = (Entry) selection.getFirstElement();
            Object eAppObject = entry.getKey();

            EAppFeature feature = null;
            String ref = null;
            if (eAppObject instanceof EAppSetting) {
                EAppSetting setting = (EAppSetting) entry.getKey();
                if (setting.eContainer().eContainer() instanceof EAppFeature) {
                    feature = (EAppFeature) setting.eContainer().eContainer();
                    ref = feature.getRef() + "/" + setting.getRef();
                }
            } else if (eAppObject instanceof EAppSettingType) {
                EAppSettingType sType = (EAppSettingType) eAppObject;

                if (sType.eContainer().eContainer().eContainer().eContainer()
                        .eContainer() instanceof EAppFeature)
                    feature = (EAppFeature) sType.eContainer().eContainer().eContainer().eContainer()
                            .eContainer(); //LOL!!!
            }

            if (feature != null) {
                OpenEditorHandler handler = new OpenEditorHandler();
                handler.externalExecute(feature, getSite().getPage().getWorkbenchWindow(), ref);
            }
        }
    });
    loadNotes();
}

From source file:com.nokia.tools.s60ct.report.popup.actions.GenerateReportPopupAction.java

License:Open Source License

/**
 * @see IActionDelegate#selectionChanged(IAction, ISelection)
 *///from w w w  .j  a v  a  2 s. co  m
public void selectionChanged(IAction action, ISelection selection) {
    try {
        if (selection instanceof StructuredSelection) {
            StructuredSelection ss = (StructuredSelection) selection;

            if (ss == null) {
                return;
            }
            IFile element = (IFile) ss.getFirstElement();
            if (element == null)
                return;

            IProject project = element.getProject();
            if (project == null)
                return;

            EConfigurationProject model = ConfMLCore.getProjectModel(project);
            URI rootConfml = model.getRootConfml();

            boolean match = true;
            if ((rootConfml.segments().length - 2) == element.getProjectRelativePath().segments().length) {

                for (int i = 2; i < rootConfml.segments().length; i++) {
                    if (!rootConfml.segments()[i].equals(element.getProjectRelativePath().segments()[i - 2])) {
                        match = false;
                    }
                }
            } else {
                match = false;
            }

            System.out.println("Root congml selected: " + match);

            action.setEnabled(match);
            ReportPlugin.setSelectedProject(project);
        } else {
            action.setEnabled(false);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}