public static Object getAdapter(Object element, Class adapterType) { return getAdapter(element, adapterType, false); }
/** * Helper method that returns the shared document adapter for the * given typed element or <code>null</code> if there isn't one. * @param element the typed element * @return the shared document adapter for the given typed element * or <code>null</code> */ public static ISharedDocumentAdapter getAdapter(Object element) { return (ISharedDocumentAdapter)Utilities.getAdapter(element, ISharedDocumentAdapter.class, true); }
/** * Return the {@link INavigatable} for the given object. * If the object implements {@link INavigatable}, then * the object is returned. Otherwise, if the object * implements {@link IAdaptable}, the object is * adapted to {@link INavigatable}. * @param object the object * @return the {@link INavigatable} for the given object or <code>null</code> */ protected final INavigatable getNavigator(Object object) { if (object == null) return null; Object data= Utilities.getAdapter(object, INavigatable.class); if (data instanceof INavigatable) return (INavigatable) data; return null; }
private IFile getFile(Object element) { if (element instanceof IResourceProvider) { IResourceProvider rp = (IResourceProvider) element; IResource resource = rp.getResource(); if (resource instanceof IFile) { return (IFile) resource; } } IFile file = (IFile)Utilities.getAdapter(element, IFile.class); if (file != null) { return file; } IResource resource = (IResource)Utilities.getAdapter(element, IResource.class); if (resource instanceof IFile) { return (IFile) resource; } return null; }
private boolean canShowAsText(CompareConfiguration cc) { if (cc == null) return false; return Utilities.getAdapter(cc.getContainer(), ICompareAsText.class) != null; }
public OutlineViewerCreator getCreator() { if (fCreator == null) { fCreator = (OutlineViewerCreator)Utilities.getAdapter(fCompareEditor, OutlineViewerCreator.class); if (fCreator != null) fCreator.addPropertyChangeListener(this); } return fCreator; }
private OutlineViewerCreator getWrappedCreator() { if (fContentInputPane != null) { Viewer v = fContentInputPane.getViewer(); if (v != null) { return (OutlineViewerCreator)Utilities.getAdapter(v, OutlineViewerCreator.class); } } return null; } public Viewer findStructureViewer(Viewer oldViewer,
private static void flushViewer(CompareViewerPane pane, IProgressMonitor pm) { if (pane != null) { IFlushable flushable = (IFlushable)Utilities.getAdapter(pane, IFlushable.class); if (flushable != null) flushable.flush(pm); } }
/** * Return whether either the left or right sides of the given input * represents a hunk. A hunk is a portion of a file. * @param input the compare input * @return whether the left or right side of the input represents a hunk */ public static boolean isHunk(Object input) { if (input != null && input instanceof DiffNode){ ITypedElement right = ((DiffNode) input).getRight(); if (right != null) { Object element = Utilities.getAdapter(right, IHunk.class); if (element instanceof IHunk) return true; } ITypedElement left = ((DiffNode) input).getLeft(); if (left != null) { Object element = Utilities.getAdapter(left, IHunk.class); if (element instanceof IHunk) return true; } } return false; }
private void connect(IDocumentProvider documentProvider, IEditorInput input) throws CoreException { final ISharedDocumentAdapter sda = (ISharedDocumentAdapter) Utilities.getAdapter(fElement, ISharedDocumentAdapter.class); if (sda != null) { sda.connect(documentProvider, input); } else { documentProvider.connect(input); } }
private void disconnect(IDocumentProvider provider, IEditorInput input) { final ISharedDocumentAdapter sda = (ISharedDocumentAdapter) Utilities.getAdapter(fElement, ISharedDocumentAdapter.class); if (sda != null) { sda.disconnect(provider, input); } else { provider.disconnect(input); } }
public Viewer createViewer(Viewer currentViewer, Composite parent, CompareConfiguration mp) { if (currentViewer != null && currentViewer.getClass() == fViewerClass) { //System.out.println("reused viewer: " + currentViewer.getClass().getName()); return currentViewer; } if (fViewerCreator == null) { try { fViewerCreator= (IViewerCreator) fConfiguration.createExecutableExtension(CLASS_ATTRIBUTE); } catch (CoreException e) { CompareUIPlugin.log(e); } } if (fViewerCreator != null) { // If we are going to return a new viewer, we want to preemptively deregister // any handlers to avoid the logging of conflict warnings if (currentViewer != null) { CompareHandlerService compareHandlerService = (CompareHandlerService)Utilities.getAdapter(currentViewer, CompareHandlerService.class); if (compareHandlerService != null) compareHandlerService.dispose(); } Viewer viewer= fViewerCreator.createViewer(parent, mp); if (viewer != null) fViewerClass= viewer.getClass(); return viewer; } return null; }
protected void handleShowAsText(CompareConfiguration cc) { ICompareAsText comparer = (ICompareAsText)Utilities.getAdapter(cc.getContainer(), ICompareAsText.class); comparer.compareAsText(getInput()); }
/** * Return the provided start position of the hunk in the target file. * @return the provided start position of the hunk in the target file */ private int getHunkStart() { Object input = getInput(); if (input != null && input instanceof DiffNode){ ITypedElement right = ((DiffNode) input).getRight(); if (right != null) { Object element = Utilities.getAdapter(right, IHunk.class); if (element instanceof IHunk) return ((IHunk)element).getStartPosition(); } ITypedElement left = ((DiffNode) input).getLeft(); if (left != null) { Object element = Utilities.getAdapter(left, IHunk.class); if (element instanceof IHunk) return ((IHunk)element).getStartPosition(); } } return 0; }
/** * Return the document key used to obtain a shared document. A <code>null</code> * is returned in the following cases: * <ol> * <li>This contributor does not have a shared document adapter.</li> * <li>This text merge viewer has a document partitioner but uses the default partitioning.</li> * <li>This text merge viewer does not use he default content provider.</li> * </ol> * @return the document key used to obtain a shared document or <code>null</code> */ private IEditorInput getDocumentKey() { if (fDocumentKey != null) return fDocumentKey; if (isUsingDefaultContentProvider() && fElement != null && canHaveSharedDocument()) { ISharedDocumentAdapter sda = (ISharedDocumentAdapter)Utilities.getAdapter(fElement, ISharedDocumentAdapter.class, true); if (sda != null) { return sda.getDocumentKey(fElement); } } return null; }
public boolean flush() throws CoreException { if (fDocumentProvider != null) { IEditorInput input = getDocumentKey(); IDocument document = fDocumentProvider.getDocument(input); if (document != null) { final ISharedDocumentAdapter sda = (ISharedDocumentAdapter) Utilities.getAdapter(fElement, ISharedDocumentAdapter.class); if (sda != null) { sda.flushDocument(fDocumentProvider, input, document, false); return true; } try { fDocumentProvider.aboutToChange(input); fDocumentProvider.saveDocument(new NullProgressMonitor(), input, document, false); return true; } finally { fDocumentProvider.changed(input); } } } return false; }
public Object getAdapter(Class key) { if (key.equals(IContentOutlinePage.class)) { Object object= getCompareConfiguration().getProperty(CompareConfiguration.USE_OUTLINE_VIEW); if (object instanceof Boolean && ((Boolean)object).booleanValue()) { if (fOutlinePage != null) { if (fOutlinePage.getControl() != null && fOutlinePage.getControl().isDisposed()) { fOutlinePage = null; } else { return fOutlinePage; } } fOutlinePage= new CompareOutlinePage(this); return fOutlinePage; } } if (key == IShowInSource.class || key == OutlineViewerCreator.class || key == IFindReplaceTarget.class) { Object input = getEditorInput(); if (input != null) { return Utilities.getAdapter(input, key); } } return super.getAdapter(key); }
/** * {@inheritDoc} * @since 3.3 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) */ public Object getAdapter(Class adapter) { if (adapter == INavigatable.class) { if (isEmpty()) return null; Viewer viewer= getViewer(); if (viewer == null) return null; Control control= viewer.getControl(); if (control == null) return null; Object data= control.getData(INavigatable.NAVIGATOR_PROPERTY); if (data instanceof INavigatable) return data; } if (adapter == IFlushable.class) { Viewer v= getViewer(); if (v != null) { IFlushable flushable = (IFlushable)Utilities.getAdapter(v, IFlushable.class); if (flushable != null) return flushable; } } return super.getAdapter(adapter); }
public static IDocument getDocument(char type, Object element, boolean isUsingDefaultContentProvider, boolean canHaveSharedDocument) { ITypedElement te= getLeg(type, element); if (te == null) return null; if (te instanceof IDocument) return (IDocument) te; if (te instanceof IDocumentRange) return ((IDocumentRange) te).getDocument(); if (te instanceof IStreamContentAccessor) return DocumentManager.get(te); if (isUsingDefaultContentProvider && canHaveSharedDocument) { ISharedDocumentAdapter sda = (ISharedDocumentAdapter)Utilities.getAdapter(te, ISharedDocumentAdapter.class, true); if (sda != null) { IEditorInput input = sda.getDocumentKey(element); if (input != null) { IDocumentProvider provider = SharedDocumentAdapter.getDocumentProvider(input); if (provider != null) return provider.getDocument(input); } } } return null; }
IEditableContentExtension ext = (IEditableContentExtension)Utilities.getAdapter(fElement, IEditableContentExtension.class); if (ext != null) { if (ext.isReadOnly()) {