Search in sources :

Example 76 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method getAdapter.

@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> required) {
    if (IEditorStatusLine.class.equals(required)) {
        if (fEditorStatusLine == null) {
            IStatusLineManager statusLineManager = getStatusLineManager();
            ISelectionProvider selectionProvider = getSelectionProvider();
            if (statusLineManager != null && selectionProvider != null)
                fEditorStatusLine = new EditorStatusLine(statusLineManager, selectionProvider);
        }
        return (T) fEditorStatusLine;
    }
    if (IVerticalRulerInfo.class.equals(required)) {
        if (fVerticalRuler != null)
            return (T) fVerticalRuler;
    }
    if (IMarkRegionTarget.class.equals(required)) {
        if (fMarkRegionTarget == null) {
            IStatusLineManager manager = getStatusLineManager();
            if (manager != null)
                fMarkRegionTarget = (fSourceViewer == null ? null : new MarkRegionTarget(fSourceViewer, manager));
        }
        return (T) fMarkRegionTarget;
    }
    if (IDeleteLineTarget.class.equals(required)) {
        if (fDeleteLineTarget == null) {
            fDeleteLineTarget = new TextViewerDeleteLineTarget(fSourceViewer);
        }
        return (T) fDeleteLineTarget;
    }
    if (IncrementalFindTarget.class.equals(required)) {
        if (fIncrementalFindTarget == null) {
            IStatusLineManager manager = getStatusLineManager();
            if (manager != null)
                fIncrementalFindTarget = (fSourceViewer == null ? null : new IncrementalFindTarget(fSourceViewer, manager));
        }
        return (T) fIncrementalFindTarget;
    }
    if (IFindReplaceTarget.class.equals(required)) {
        if (fFindReplaceTarget == null) {
            IFindReplaceTarget target = (fSourceViewer == null ? null : fSourceViewer.getFindReplaceTarget());
            if (target != null) {
                fFindReplaceTarget = new FindReplaceTarget(this, target);
                if (fFindScopeHighlightColor != null)
                    fFindReplaceTarget.setScopeHighlightColor(fFindScopeHighlightColor);
            }
        }
        return (T) fFindReplaceTarget;
    }
    if (ITextOperationTarget.class.equals(required))
        return (fSourceViewer == null ? null : (T) fSourceViewer.getTextOperationTarget());
    if (IRewriteTarget.class.equals(required)) {
        if (fSourceViewer instanceof ITextViewerExtension) {
            ITextViewerExtension extension = (ITextViewerExtension) fSourceViewer;
            return (T) extension.getRewriteTarget();
        }
        return null;
    }
    if (Control.class.equals(required))
        return fSourceViewer != null ? (T) fSourceViewer.getTextWidget() : null;
    if (IColumnSupport.class.equals(required)) {
        if (fColumnSupport == null)
            fColumnSupport = createColumnSupport();
        return (T) fColumnSupport;
    }
    return super.getAdapter(required);
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) SWT(org.eclipse.swt.SWT) ST(org.eclipse.swt.custom.ST) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget) IMarkRegionTarget(org.eclipse.jface.text.IMarkRegionTarget)

Example 77 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project eclipse.platform.text by eclipse.

the class FileSearchPage method getAdapter.

@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
    if (IShowInTargetList.class.equals(adapter)) {
        return (T) SHOW_IN_TARGET_LIST;
    }
    if (adapter == IShowInSource.class) {
        ISelectionProvider selectionProvider = getSite().getSelectionProvider();
        if (selectionProvider == null)
            return null;
        ISelection selection = selectionProvider.getSelection();
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = ((StructuredSelection) selection);
            final Set<Object> newSelection = new HashSet<>(structuredSelection.size());
            Iterator<?> iter = structuredSelection.iterator();
            while (iter.hasNext()) {
                Object element = iter.next();
                if (element instanceof LineElement)
                    element = ((LineElement) element).getParent();
                newSelection.add(element);
            }
            return (T) (IShowInSource) () -> new ShowInContext(null, new StructuredSelection(new ArrayList<>(newSelection)));
        }
        return null;
    }
    return null;
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ShowInContext(org.eclipse.ui.part.ShowInContext) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HashSet(java.util.HashSet)

Example 78 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project eclipse.platform.text by eclipse.

the class PaintManager method removeListeners.

/**
 * Removes our set of listeners from the text viewer and widget,
 * respectively.
 */
private void removeListeners() {
    ISelectionProvider provider = fTextViewer.getSelectionProvider();
    if (provider != null)
        provider.removeSelectionChangedListener(this);
    fTextViewer.removeTextListener(this);
    StyledText text = fTextViewer.getTextWidget();
    if (text != null && !text.isDisposed()) {
        text.removeKeyListener(this);
        text.removeMouseListener(this);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider)

Example 79 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project linuxtools by eclipse.

the class SpecfileEditorRPMBuildHandler method getResource.

/**
 * Extract the IResource that was selected when the event was fired.
 * @param event The fired execution event.
 * @return The resource that was selected.
 */
private static IResource getResource(ExecutionEvent event) {
    final boolean actOnEditor = Boolean.valueOf(event.getParameter(ON_EDITOR));
    if (actOnEditor) {
        IEditorPart epart = HandlerUtil.getActiveEditor(event);
        if (epart != null) {
            IEditorInput input = epart.getEditorInput();
            if (input instanceof IFileEditorInput) {
                return ((IFileEditorInput) input).getFile();
            }
        }
        return null;
    }
    IWorkbenchPart part = HandlerUtil.getActivePart(event);
    if (part == null) {
        return null;
    }
    if (part instanceof EditorPart) {
        IEditorInput input = ((EditorPart) part).getEditorInput();
        if (input instanceof IFileEditorInput) {
            return ((IFileEditorInput) input).getFile();
        }
        return null;
    }
    IWorkbenchSite site = part.getSite();
    if (site == null) {
        return null;
    }
    ISelectionProvider provider = site.getSelectionProvider();
    if (provider == null) {
        return null;
    }
    ISelection selection = provider.getSelection();
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof IResource) {
            return (IResource) element;
        } else if (element instanceof IAdaptable) {
            IAdaptable adaptable = (IAdaptable) element;
            return adaptable.getAdapter(IResource.class);
        } else {
            return null;
        }
    }
    return null;
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) IAdaptable(org.eclipse.core.runtime.IAdaptable) IEditorPart(org.eclipse.ui.IEditorPart) EditorPart(org.eclipse.ui.part.EditorPart) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IFileEditorInput(org.eclipse.ui.IFileEditorInput) ISelection(org.eclipse.jface.viewers.ISelection) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Example 80 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project linuxtools by eclipse.

the class PrepareChangelogKeyHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    IStructuredSelection tempResult = null;
    // try getting currently selected project
    IWorkbenchPage ref = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    IWorkbenchPart part = HandlerUtil.getActivePart(event);
    if (part instanceof IEditorPart) {
        // If we are in an editor, check if the file being edited is an IResource
        // that belongs to a project in the workspace
        IEditorPart editorPart = (IEditorPart) part;
        IEditorInput input = editorPart.getEditorInput();
        IResource r = input.getAdapter(IResource.class);
        if (r != null) {
            // We have an IResource to work with, so create a selection we can use
            // in PrepareChangeLogAction
            tempResult = new StructuredSelection(r);
        }
    } else {
        // Otherwise, our view is not an editor, see if we have an IResource or something
        // that will lead us to an IResource
        ISelection selected = ref.getSelection();
        if (selected instanceof IStructuredSelection) {
            IResource r = null;
            IStructuredSelection iss = (IStructuredSelection) selected;
            Object o = ((IStructuredSelection) selected).getFirstElement();
            if (o instanceof ISynchronizeModelElement) {
                r = ((ISynchronizeModelElement) o).getResource();
            } else if (o instanceof IAdaptable) {
                r = ((IAdaptable) o).getAdapter(IResource.class);
            }
            if (r != null)
                tempResult = iss;
        }
    }
    if (tempResult == null) {
        // choice to fall back on.
        for (IViewReference view : ref.getViewReferences()) {
            if (view.getId().equals("org.eclipse.team.sync.views.SynchronizeView")) {
                // $NON-NLS-1$
                IViewPart v = view.getView(false);
                ISelection s = null;
                ISelectionProvider sp = v.getViewSite().getSelectionProvider();
                if (sp != null) {
                    s = sp.getSelection();
                }
                if (s instanceof IStructuredSelection) {
                    IStructuredSelection ss = (IStructuredSelection) s;
                    Object element = ss.getFirstElement();
                    IResource r = null;
                    if (element instanceof ISynchronizeModelElement) {
                        r = ((ISynchronizeModelElement) element).getResource();
                    } else if (element instanceof IAdaptable) {
                        r = ((IAdaptable) element).getAdapter(IResource.class);
                    }
                    if (r != null) {
                        tempResult = ss;
                    }
                }
            }
        }
    }
    // If we can't find the project directly, let the user know.
    if (tempResult == null) {
        // $NON-NLS-1$,
        MessageDialog.openInformation(// $NON-NLS-1$,
        getActiveWorkbenchShell(), // $NON-NLS-1$,
        Messages.getString("ChangeLog.PrepareChangeLog"), // $NON-NLS-1$
        Messages.getString("PrepareChangeLog.InfoNoProjectFound"));
        return null;
    }
    final IStructuredSelection result = tempResult;
    IAction exampleAction = new PrepareChangeLogAction() {

        @Override
        public void run() {
            setSelection(result);
            doRun();
        }
    };
    exampleAction.run();
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IViewPart(org.eclipse.ui.IViewPart) IAction(org.eclipse.jface.action.IAction) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISynchronizeModelElement(org.eclipse.team.ui.synchronize.ISynchronizeModelElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IViewReference(org.eclipse.ui.IViewReference) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Aggregations

ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)83 TreeViewer (org.eclipse.jface.viewers.TreeViewer)40 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)25 ISelection (org.eclipse.jface.viewers.ISelection)24 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)21 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)18 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)17 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)15 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)13 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)13 ITextSelection (org.eclipse.jface.text.ITextSelection)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 ArrayList (java.util.ArrayList)10 Shell (org.eclipse.swt.widgets.Shell)10 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)8 IEditorPart (org.eclipse.ui.IEditorPart)8 HashSet (java.util.HashSet)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 StyledText (org.eclipse.swt.custom.StyledText)6 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)6