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

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

Introduction

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

Prototype

public Object getFirstElement();

Source Link

Document

Returns the first element in this selection, or null if the selection is empty.

Usage

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.actions.ReplyToCommentAction.java

License:Open Source License

@Override
protected boolean updateSelection(IStructuredSelection selection) {
    this.review = null;

    Object element = selection.getFirstElement();
    if (element instanceof Comment && selection.size() == 1) {
        this.review = getActiveReview();
        if (this.review != null && CrucibleUtil.canAddCommentToReview(review)) {
            return true;
        }/*from w  w w  .  jav  a 2s. c  om*/
    }
    return false;
}

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.wizards.SelectChangesetsFromCruciblePage.java

License:Open Source License

private void createChangesViewer(Composite parent) {
    Tree tree = new Tree(parent, SWT.MULTI | SWT.BORDER);
    availableTreeViewer = new TreeViewer(tree);

    GridDataFactory.fillDefaults().grab(true, true).hint(300, 220).applyTo(tree);
    availableTreeViewer.setLabelProvider(new ChangesetLabelProvider());
    availableTreeViewer.setContentProvider(new ChangesetContentProvider());
    availableTreeViewer.setComparator(new ResourceComparator(ResourceComparator.NAME));
    availableTreeViewer.setComparator(new ViewerComparator() {
        @Override//from  w w w  .j  a  v a2 s.c  om
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof Change && e2 instanceof Change) {
                return ((Change) e2).getDate().compareTo(((Change) e1).getDate());
            }
            return super.compare(viewer, e1, e2);
        }
    });

    tree.setMenu(createChangesContextMenu());

    tree.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            updateButtonEnablement();
        }
    });
    availableTreeViewer.addTreeListener(new ITreeViewerListener() {
        public void treeCollapsed(TreeExpansionEvent event) {
            // ignore
        }

        public void treeExpanded(TreeExpansionEvent event) {
            // first time of expanding: retrieve first 10 changesets
            final Object object = event.getElement();
            if (object instanceof Repository) {
                refreshRepository((Repository) object);
            }

        }
    });
    availableTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            Object object = selection.getFirstElement();
            if (availableTreeViewer.isExpandable(object)) {
                if (!availableTreeViewer.getExpandedState(object) && object instanceof Repository) {
                    refreshRepository((Repository) object);
                    return;
                }
                availableTreeViewer.setExpandedState(object, !availableTreeViewer.getExpandedState(object));
            }
        }
    });
}

From source file:com.atlassian.connector.eclipse.ui.actions.AbstractResourceAction.java

License:Open Source License

private List<ResourceEditorBean> getData(ISelection selection) {
    List<ResourceEditorBean> ret = new ArrayList<ResourceEditorBean>();
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structuredSelection = (IStructuredSelection) selection;

        Object[] selectedObjects = structuredSelection.toArray();

        for (Object selectedObject : selectedObjects) {

            if (selectedObject instanceof IEditorResource) {
                IEditorResource a = (IEditorResource) selectedObject;
                ret.add(new ResourceEditorBean(a.getResource(), a.getLineRange()));

            } else if (structuredSelection.getFirstElement() instanceof IAdaptable) {
                IResource resource = null;
                LineRange lineRange = null;
                resource = (IResource) ((IAdaptable) structuredSelection.getFirstElement())
                        .getAdapter(IResource.class);
                lineRange = getJavaEditorSelection(structuredSelection);
                ret.add(new ResourceEditorBean(resource, lineRange));
            }//from  w  w  w . java  2  s . com
        }
    } else {
        IEditorPart activeEditor = getActiveEditor();
        if (activeEditor != null) {
            IEditorInput editorInput = getEditorInputFromSelection(selection);
            if (editorInput != null) {
                IResource resource = null;
                LineRange lineRange = null;
                resource = (IResource) editorInput.getAdapter(IResource.class);
                // such call:
                //            lineRange = new LineRange(textSelection.getStartLine(), textSelection.getEndLine()
                //                  - textSelection.getStartLine());
                // does not work (i.e. it returns previously selected text region rather than selected now ?!?
                lineRange = AtlassianUiUtil.getSelectedLineNumberRangeFromEditorInput(activeEditor,
                        activeEditor.getEditorInput());
                ret.add(new ResourceEditorBean(resource, lineRange));
            }
        }
    }
    return ret;
}

From source file:com.atlassian.connector.eclipse.ui.actions.AbstractResourceAction.java

License:Open Source License

private IEditorInput getEditorInputFromSelection(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = ((IStructuredSelection) selection);
        if (structuredSelection.getFirstElement() instanceof IEditorInput) {
            return (IEditorInput) structuredSelection.getFirstElement();
        }//ww  w  .j a va2 s .c  om
    }
    return null;
}

From source file:com.axmor.eclipse.typescript.editor.preferences.TypescriptSyntaxColoringPage.java

License:Open Source License

/**
 * Returns the current highlighting color list item.
 * /*from  w  ww  . ja  v a  2s . c om*/
 * @return the current highlighting color list item
 * @since 3.0
 */
private HighlightingColorListItem getHighlightingColorListItem() {
    IStructuredSelection selection = (IStructuredSelection) fHighlightingColorListViewer.getSelection();
    return (HighlightingColorListItem) selection.getFirstElement();
}

From source file:com.axmor.eclipse.typescript.editor.preferences.TypescriptTemplatePreferencePage.java

License:Open Source License

protected void updateViewerInput() {
    IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
    SourceViewer viewer = getViewer();/*  w  w w.  java  2s .c o  m*/

    if (selection.size() == 1 && selection.getFirstElement() instanceof TemplatePersistenceData) {
        TemplatePersistenceData data = (TemplatePersistenceData) selection.getFirstElement();
        Template template = data.getTemplate();
        viewer.getDocument().set(template.getPattern());
    } else {
        viewer.getDocument().set(""); //$NON-NLS-1$
    }
}

From source file:com.axmor.eclipse.typescript.editor.wizards.NewClassWizardPage.java

License:Open Source License

private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() > 1)
            return;
        Object obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            IContainer container;//from   w w w  .  j av  a2 s. com
            if (obj instanceof IContainer)
                container = (IContainer) obj;
            else
                container = ((IResource) obj).getParent();
            containerText.setText(container.getFullPath().toString());
        }
    }
    fileText.setText("new_file.ts");
    //TODO focus
    fileText.setFocus();
}

From source file:com.baremetalstudios.mapleide.ui.ResourceViewerControl.java

License:Open Source License

public IResource getResource() {
    if (viewer.getSelection().isEmpty()) {
        return null;
    } else {/*  w  w  w .  j  a v a2  s . c  o  m*/
        IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
        return (IResource) s.getFirstElement();
    }
}

From source file:com.bb.extensions.plugin.unittests.internal.actions.CodeCoverageOpenAction.java

License:Open Source License

@Override
protected boolean updateSelection(IStructuredSelection selection) {
    boolean result = false;

    _selectedElement = null;//w ww  .  j  a v  a  2  s. c om

    if (!selection.isEmpty()) {
        Object selected = selection.getFirstElement();
        if (selected instanceof CodeCoverageUnitTestsNavigatorElement) {
            _selectedElement = (CodeCoverageUnitTestsNavigatorElement) selected;
            result = true;
        }
    }

    _openAction.selectionChanged(selection);
    result = result || _openAction.isEnabled();

    return result;
}

From source file:com.bb.extensions.plugin.unittests.internal.actions.TestFileOpenAction.java

License:Open Source License

@Override
protected boolean updateSelection(IStructuredSelection selection) {
    boolean result = false;

    _selectedElement = null;//  w w  w. ja  v a2s  .  c  o m

    if (!selection.isEmpty()) {
        Object selected = selection.getFirstElement();
        if (selected instanceof TestFileUnitTestsNavigatorElement) {
            _selectedElement = (TestFileUnitTestsNavigatorElement) selected;
            result = true;
        }
    }

    _openAction.selectionChanged(selection);
    result = result || _openAction.isEnabled();

    return result;
}