Java 类org.eclipse.ui.part.AbstractMultiEditor 实例源码

项目:Eclipse-Postfix-Code-Completion    文件:JavaBrowsingPart.java   
private void setSelectionFromEditor(IWorkbenchPart part, ISelection selection) {
    if (part instanceof IEditorPart) {
        IJavaElement element= null;
        if (selection instanceof IStructuredSelection) {
            Object obj= getSingleElementFromSelection(selection);
            if (obj instanceof IJavaElement)
                element= (IJavaElement)obj;
        }
        IEditorInput ei;
        if (part instanceof AbstractMultiEditor)
            ei= ((AbstractMultiEditor)part).getActiveEditor().getEditorInput();
        else
            ei= ((IEditorPart)part).getEditorInput();
        if (selection instanceof ITextSelection) {
            int offset= ((ITextSelection)selection).getOffset();
            element= getElementAt(ei, offset);
        }
        if (element != null) {
            adjustInputAndSetSelection(element);
            return;
        }
        if (ei instanceof IFileEditorInput) {
            IFile file= ((IFileEditorInput)ei).getFile();
            IJavaElement je= (IJavaElement)file.getAdapter(IJavaElement.class);
            IContainer container= null;
            if (je == null) {
                container= ((IFileEditorInput)ei).getFile().getParent();
                if (container != null)
                    je= (IJavaElement)container.getAdapter(IJavaElement.class);
            }
            if (je == null && container == null) {
                setSelection(null, false);
                return;
            }
            adjustInputAndSetSelection(je);
        } else if (ei instanceof IClassFileEditorInput) {
            IClassFile cf= ((IClassFileEditorInput)ei).getClassFile();
            adjustInputAndSetSelection(cf);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaBrowsingPart.java   
private void setSelectionFromEditor(IWorkbenchPart part, ISelection selection) {
    if (part instanceof IEditorPart) {
        IJavaElement element= null;
        if (selection instanceof IStructuredSelection) {
            Object obj= getSingleElementFromSelection(selection);
            if (obj instanceof IJavaElement)
                element= (IJavaElement)obj;
        }
        IEditorInput ei;
        if (part instanceof AbstractMultiEditor)
            ei= ((AbstractMultiEditor)part).getActiveEditor().getEditorInput();
        else
            ei= ((IEditorPart)part).getEditorInput();
        if (selection instanceof ITextSelection) {
            int offset= ((ITextSelection)selection).getOffset();
            element= getElementAt(ei, offset);
        }
        if (element != null) {
            adjustInputAndSetSelection(element);
            return;
        }
        if (ei instanceof IFileEditorInput) {
            IFile file= ((IFileEditorInput)ei).getFile();
            IJavaElement je= (IJavaElement)file.getAdapter(IJavaElement.class);
            IContainer container= null;
            if (je == null) {
                container= ((IFileEditorInput)ei).getFile().getParent();
                if (container != null)
                    je= (IJavaElement)container.getAdapter(IJavaElement.class);
            }
            if (je == null && container == null) {
                setSelection(null, false);
                return;
            }
            adjustInputAndSetSelection(je);
        } else if (ei instanceof IClassFileEditorInput) {
            IClassFile cf= ((IClassFileEditorInput)ei).getClassFile();
            adjustInputAndSetSelection(cf);
        }
    }
}