Java Code Examples for org.eclipse.ui.IEditorPart#getAdapter()
The following examples show how to use
org.eclipse.ui.IEditorPart#getAdapter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XsltQuickFix.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * Returns {@link IDocument} in the open editor, or null if the editor * is not open. */ static IDocument getCurrentDocument(IFile file) { try { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); IEditorPart editorPart = ResourceUtil.findEditor(activePage, file); if (editorPart != null) { IDocument document = editorPart.getAdapter(IDocument.class); return document; } return null; } catch (IllegalStateException ex) { //If workbench does not exist return null; } }
Example 2
Source File: EditorSearchHyperlink.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public void open() { try { final IFileStore store = EFS.getStore(document); // Now open an editor to this file (and highlight the occurrence if possible) IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart part = IDE.openEditorOnFileStore(page, store); // Now select the occurrence if we can IFindReplaceTarget target = (IFindReplaceTarget) part.getAdapter(IFindReplaceTarget.class); if (target != null && target.canPerformFind()) { target.findAndSelect(0, searchString, true, caseSensitive, wholeWord); } } catch (Exception e) { IdeLog.logError(CommonEditorPlugin.getDefault(), e); } }
Example 3
Source File: UndoCommandHandler.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Override public boolean isEnabled() { final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() ; if(editor != null){ final IOperationHistory history = (IOperationHistory) editor.getAdapter(IOperationHistory.class); final IUndoContext context = (IUndoContext) editor.getAdapter(IUndoContext.class); if(history != null && context != null){ final IUndoableOperation[] undoHistory = history.getUndoHistory(context); if (undoHistory != null && undoHistory.length != 0) { final IUndoableOperation ctxt = undoHistory[undoHistory.length - 1]; final String ctxtLabel = ctxt.getLabel(); if(ctxtLabel != null && ctxtLabel.contains("Lane")){//Avoid Exception on undo //$NON-NLS-1$ return false ; } else { return ctxt.canUndo(); } } } else { return false; } } return false; }
Example 4
Source File: QuickXFind.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
public static void findPrevious(IEditorPart editorPart) { IFindReplaceTarget target = (IFindReplaceTarget) editorPart.getAdapter(IFindReplaceTarget.class); if (target == null) return; StatusLine statusLine = new StatusLine(editorPart.getEditorSite()); statusLine.cleanStatusLine(); SearchRegion region = getSearchRegion(target, editorPart); if (region == null) return; int offset = Math.max(region.offset - 1, 0); offset = findAndSelect(target, offset, region.text, false); if (offset < 0) { String message = String.format(Messages.QuickFind_Status_FirstOccurence, region.text); statusLine.showMessage(message, ImageUtils.getImage(ImageUtils.FIND_STATUS)); } }
Example 5
Source File: TMPresentationReconciler.java From tm4e with Eclipse Public License 1.0 | 5 votes |
public static TMPresentationReconciler getTMPresentationReconciler(IEditorPart editorPart) { if (editorPart == null) { return null; } @Nullable ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class); if (target instanceof ITextViewer) { ITextViewer textViewer = ((ITextViewer) target); return TMPresentationReconciler.getTMPresentationReconciler(textViewer); } return null; }
Example 6
Source File: LocalWSDLEditor.java From tesb-studio-se with Apache License 2.0 | 5 votes |
@Override protected void createActions() { super.createActions(); ActionRegistry registry = getActionRegistry(); BaseSelectionAction action = new OpenInNewEditor(this) { @Override public void run() { if (getSelectedObjects().size() > 0) { Object o = getSelectedObjects().get(0); // should make this generic and be able to get the owner from a facade object if (o instanceof WSDLBaseAdapter) { WSDLBaseAdapter baseAdapter = (WSDLBaseAdapter) o; IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor(); Object object = editorPart.getAdapter(org.eclipse.wst.wsdl.Definition.class); if (object instanceof org.eclipse.wst.wsdl.Definition) { EObject eObject = (EObject) baseAdapter.getTarget(); OpenOnSelectionHelper openHelper = new OpenOnSelectionHelper( (org.eclipse.wst.wsdl.Definition) object); openHelper.openEditor(eObject); } } } } }; action.setSelectionProvider(getSelectionManager()); registry.registerAction(action); }
Example 7
Source File: StatechartValidationDecorationProvider.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected boolean shouldInstall(IEditorPart part) { if (part instanceof StatechartDiagramEditor) { issueStore = (IValidationIssueStore) part.getAdapter(IValidationIssueStore.class); return true; } // This is required for OffscreenEditPartFactory to render problem markers into // the preview image if (part == null) { issueStore = new IValidationIssueStore.NullImpl(); return true; } return false; }
Example 8
Source File: TestUndoRedoStackLimit.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private int retrieveLimit(SWTBotEditor botEditor) { IEditorPart editor = botEditor.getReference().getEditor(false); IOperationHistory history = editor.getAdapter(IOperationHistory.class); IUndoContext context = editor.getAdapter(IUndoContext.class); if (history != null && context != null) { return history.getLimit(context); } return -1; }
Example 9
Source File: EditorPool.java From saros with GNU General Public License v2.0 | 5 votes |
private static void findAndLogDocumentProviderIssues(final IEditorPart editorPart) { final IDocumentProvider defaultDocumentProvider = EditorAPI.getDocumentProvider(editorPart.getEditorInput()); if (!(defaultDocumentProvider instanceof TextFileDocumentProvider)) { log.warn( "The default document provider " + defaultDocumentProvider + " for editor with title '" + editorPart.getTitle() + "' might not support shared access. It is likely that the editor content is not properly synchronized!"); return; } final ITextEditor textEditor = editorPart.getAdapter(ITextEditor.class); if (textEditor == null) return; final IDocumentProvider editorDocumentProvider = textEditor.getDocumentProvider(); if (!(editorDocumentProvider instanceof TextFileDocumentProvider)) { log.warn( "The document provider " + editorDocumentProvider + " for editor with title '" + editorPart.getTitle() + "' might not support shared access. It is likely that the editor content is not properly synchronized!"); } }
Example 10
Source File: SseUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * @return the active structured text viewer, or null */ public static StructuredTextViewer getActiveTextViewer() { // Need to get the workbench window from the UI thread final IWorkbenchWindow[] windowHolder = new IWorkbenchWindow[1]; Display.getDefault().syncExec(new Runnable() { public void run() { windowHolder[0] = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); } }); IWorkbenchWindow window = windowHolder[0]; if (window == null) { return null; } IWorkbenchPage page = window.getActivePage(); if (page == null) { return null; } IEditorPart editor = page.getActiveEditor(); if (editor == null) { return null; } /* * TODO: change the following to use AdapterUtilities.getAdapter() * and either a) have GWTD register an adapter factory or b) add a direct * IAdaptable.getAdapter() call to AdapterUtilities.getAdapter(). */ StructuredTextEditor structuredEditor = (StructuredTextEditor) editor.getAdapter(StructuredTextEditor.class); if (structuredEditor == null) { return null; } return structuredEditor.getTextViewer(); }
Example 11
Source File: UIUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
public static IModelEventManager getModelEventManager( ) { IEditorPart input = null; for ( int i = 0; i < EDITOR_IDS.length; i++ ) { input = getActiveEditor( EDITOR_IDS[i] ); if ( input != null ) { break; } } if ( input == null ) { IEditorPart part = getActiveEditor( true ); if ( part instanceof IReportEditor ) { input = part; } } if ( input == null ) { return null; } Object adapter = input.getAdapter( IModelEventManager.class ); if ( adapter instanceof IModelEventManager ) { return (IModelEventManager) adapter; } return null; }
Example 12
Source File: ApplicationLaunchShortcut2.java From sarl with Apache License 2.0 | 5 votes |
@Override public void launch(IEditorPart editor, String mode) { final SarlJavaElementDelegateMainLaunch javaElementDelegate = editor.getAdapter(SarlJavaElementDelegateMainLaunch.class); if (javaElementDelegate != null) { super.launch(new StructuredSelection(javaElementDelegate), mode); } else { super.launch(editor, mode); } }
Example 13
Source File: ValidationTestUtils.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
static ITextViewer getViewer(IFile file) { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); IEditorPart editorPart = ResourceUtil.findEditor(activePage, file); ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class); if (target instanceof ITextViewer) { return (ITextViewer) target; } return null; }
Example 14
Source File: LanguageConfigurationAutoEditStrategy.java From tm4e with Eclipse Public License 1.0 | 5 votes |
private void installViewer() { if (viewer == null) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart editorPart = page.getActiveEditor(); viewer = editorPart.getAdapter(ITextViewer.class); } }
Example 15
Source File: EditorUtilities.java From ContentAssist with MIT License | 5 votes |
/** * Obtains the source viewer of an editor. * @param editor the editor * @return the source viewer of the editor */ public static ISourceViewer getSourceViewer(IEditorPart editor) { if (editor == null) { return null; } ISourceViewer viewer = (ISourceViewer)editor.getAdapter(ITextOperationTarget.class); return viewer; }
Example 16
Source File: XFindPanel.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
public XFindPanel(final Composite parent, IEditorPart editorPart) { super(parent, SWT.NONE); statusLine = new StatusLine(editorPart.getEditorSite()); setVisible(false); if (editorPart != null) { target = (IFindReplaceTarget) editorPart.getAdapter(IFindReplaceTarget.class); isRegExSupported = (target instanceof IFindReplaceTargetExtension3); } final IPreferenceStore store = XFindPlugin.getDefault().getPreferenceStore(); if (!store.contains(XFIND_PANEL_PLACEMENT)) { store.setDefault(XFIND_PANEL_PLACEMENT, XFIND_PANEL_PLACEMENT_TOP); } if (store.getInt(XFIND_PANEL_PLACEMENT) == XFIND_PANEL_PLACEMENT_BOTTOM) { moveBelow(null); } else { moveAbove(null); } createContents(); loadHistory(store); store.addPropertyChangeListener(new IPropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent event) { Display.getDefault().syncExec(new Runnable() { @Override public void run() { if (XFIND_PANEL_PLACEMENT.equals(event.getProperty())) { if (store.getInt(XFIND_PANEL_PLACEMENT) == XFIND_PANEL_PLACEMENT_BOTTOM) { moveBelow(null); } else { moveAbove(null); } parent.layout(); } } }); } }); parent.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { saveHistory(store); } }); }
Example 17
Source File: AddBlockCommentHandler.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
/** * {@inheritDoc} */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { try { ITextSelection selection = WorkbenchUtils.getActiveTextSelection(); IDocument doc = WorkbenchUtils.getActiveDocument(); IEditorInput input = WorkbenchUtils.getActiveInput(); IEditorPart editor = WorkbenchUtils.getActiveEditor(false); boolean isTextOperationAllowed = (selection != null) && (doc != null) && (input != null) && (editor != null) && (editor instanceof ModulaEditor); if (isTextOperationAllowed) { ITextEditor iTextEditor = (ITextEditor)editor; final ITextOperationTarget operationTarget = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); String commentPrefix = ((SourceCodeTextEditor)editor).getEOLCommentPrefix(); isTextOperationAllowed = (operationTarget != null) && (operationTarget instanceof TextViewer) && (validateEditorInputState(iTextEditor)) && (commentPrefix != null); if ((isTextOperationAllowed)) { int startLine = selection.getStartLine(); int endLine = selection.getEndLine(); int selOffset = selection.getOffset(); int selLen = selection.getLength(); int realEndLine = doc.getLineOfOffset(selOffset + selLen); // for selection end at pos=0 (endLine is line before here) // Are cursor and anchor at 0 positions? boolean is0pos = false; if (doc.getLineOffset(startLine) == selOffset) { if ((doc.getLineOffset(endLine) + doc.getLineLength(endLine) == selOffset + selLen)) { is0pos = true; } } ArrayList<ReplaceEdit> edits = null; int offsAfter[] = {0}; if (is0pos || selLen == 0) { edits = commentWholeLines(startLine, (selLen == 0) ? startLine : endLine, realEndLine, doc, offsAfter); } else { edits = commentRange(selOffset, selLen, "(*", "*)", offsAfter); //$NON-NLS-1$ //$NON-NLS-2$ } if (edits != null && !edits.isEmpty()) { DocumentRewriteSession drws = null; try { if (doc instanceof IDocumentExtension4) { drws = ((IDocumentExtension4)doc).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED); } MultiTextEdit edit= new MultiTextEdit(0, doc.getLength()); edit.addChildren((TextEdit[]) edits.toArray(new TextEdit[edits.size()])); edit.apply(doc, TextEdit.CREATE_UNDO); iTextEditor.getSelectionProvider().setSelection(new TextSelection(offsAfter[0], 0)); } finally { if (doc instanceof IDocumentExtension4 && drws != null) { ((IDocumentExtension4)doc).stopRewriteSession(drws); } } } } } } catch (Exception e) { e.printStackTrace(); } return null; }
Example 18
Source File: RemoteDatasetPluginTest.java From dawnsci with Eclipse Public License 1.0 | 4 votes |
@Test public void testHDF5FileMonitoring() throws Exception { try { testIsRunning = true; final File h5File = startHDF5WritingThread(); // This is an HDF5 file which is growing as a thread writes it. Thread.sleep(2000); IRemoteDatasetService service = new RemoteDatasetServiceImpl(); final IDatasetConnector data = service.createRemoteDataset("localhost", 8080); data.setPath(h5File.getAbsolutePath()); data.setDatasetName("/entry/data/image"); // We just get the first image in the PNG file. data.connect(); try { // We open a random part then // 1. copy in the remote dataset which we are currently writing to // 2. plot data from it IEditorPart editor = TestUtils.openExternalEditor(testDir+"/export.h5"); ITransferableDataManager man = (ITransferableDataManager)editor.getAdapter(ITransferableDataManager.class); TestUtils.delay(1000); // Wait while plot sorts itself out TransferableLazyDataset trans = new TransferableLazyDataset(data.getDataset()); trans.setChecked(true); man.addData(trans); final ISliceSystem system = (ISliceSystem)editor.getAdapter(ISliceSystem.class); for (int i = 0; i < 20; i++) { TestUtils.delay(1000); // We set the slice to the current end, so that the image refreshes. Display.getDefault().syncExec(new Runnable() { @Override public void run() { system.setSliceIndex(0, data.getDataset().getShape()[0]-1, true); } }); } } finally { data.disconnect(); } } finally { testIsRunning = false; } }
Example 19
Source File: EditorAPI.java From saros with GNU General Public License v2.0 | 2 votes |
/** * Gets a {@link ITextViewer} instance for the given editor part. * * @param editorPart for which we want a {@link TextViewer}. * @return {@link ITextViewer} or <code>null</code> if there is no {@link TextViewer} for the * editorPart. */ public static ITextViewer getViewer(IEditorPart editorPart) { Object viewer = editorPart.getAdapter(ITextOperationTarget.class); return (viewer instanceof ITextViewer) ? (ITextViewer) viewer : null; }
Example 20
Source File: JavaElementImplementationHyperlink.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 2 votes |
/** * Opens the quick type hierarchy for the given editor. * * @param editor the editor for which to open the quick hierarchy */ private static void openQuickHierarchy(IEditorPart editor) { ITextOperationTarget textOperationTarget= (ITextOperationTarget)editor.getAdapter(ITextOperationTarget.class); textOperationTarget.doOperation(JavaSourceViewer.SHOW_HIERARCHY); }