@Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { if (oldInput != null) { IDocument document = documentProvider.getDocument(oldInput); if (document != null) { try { document.removePositionCategory(CLASS_POSITIONS); } catch (BadPositionCategoryException x) { } document.removePositionUpdater(positionUpdater); } } editorInput = (IEditorInput) newInput; if (newInput != null) { IDocument document = documentProvider.getDocument(newInput); if (document != null) { document.addPositionCategory(CLASS_POSITIONS); document.addPositionUpdater(positionUpdater); editorPageChanged(viewer); } } viewer.refresh(); }
@Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { if (oldInput != null) { IDocument document = fDocumentProvider.getDocument(oldInput); if (document != null) { try { document.removePositionCategory(JSON_ELEMENTS); } catch (BadPositionCategoryException x) { } document.removePositionUpdater(fPositionUpdater); } } rootObject = null; if (newInput != null) { IDocument document = fDocumentProvider.getDocument(newInput); if (document != null) { document.addPositionCategory(JSON_ELEMENTS); document.addPositionUpdater(fPositionUpdater); parse(document); } } }
@Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { clearAnnotations(); if (oldInput != null) { IDocument document = documentProvider.getDocument(oldInput); if (document != null) { try { document.removePositionCategory(SEGMENTS); } catch (BadPositionCategoryException e) { // Do Nothing } document.removePositionUpdater(positionUpdater); } } if (newInput != null) { IDocument document = documentProvider.getDocument(newInput); if (document != null) { document.addPositionCategory(SEGMENTS); document.addPositionUpdater(positionUpdater); tree = parser.parse(document.get()); addAnnotations(document.get()); } } }
/** * Provides manipulation of browser open status due to implement <code>IWindowListener</code>. * This method must not be called by client because it is called by platform. Do nothing for * Eclipse sensor so far. * * @param window An IWorkbenchWindow instance to be triggered when a window is activated. */ public void windowActivated(IWorkbenchWindow window) { IEditorPart activeEditorPart = window.getActivePage().getActiveEditor(); if (activeEditorPart instanceof ITextEditor) { EclipseSensor.this.activeTextEditor = (ITextEditor) activeEditorPart; ITextEditor editor = EclipseSensor.this.activeTextEditor; IDocumentProvider provider = editor.getDocumentProvider(); IDocument document = provider.getDocument(editor.getEditorInput()); document.addDocumentListener(new DocumentListenerAdapter()); int activeBufferSize = provider.getDocument(editor.getEditorInput()).getLength(); // BuffTrans: Copy the new active file size to the threshold buffer size . EclipseSensor.this.thresholdBufferSize = activeBufferSize; EclipseSensor.this.activeBufferSize = activeBufferSize; } }
/** * Returns the variable and function names at the current line, or <code>null</code> if none. * * @param part text editor * @param selection text selection * @return the variable and function names at the current line, or <code>null</code> if none. The * array has two elements, the first is the variable name, the second is the function name. */ protected String[] getVariableAndFunctionName(IWorkbenchPart part, ISelection selection) { ITextEditor editor = getEditor(part); if (editor != null && selection instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection) selection; IDocumentProvider documentProvider = editor.getDocumentProvider(); try { documentProvider.connect(this); IDocument document = documentProvider.getDocument(editor.getEditorInput()); IRegion region = document.getLineInformationOfOffset(textSelection.getOffset()); String string = document.get(region.getOffset(), region.getLength()).trim(); if (string.startsWith("var ")) { // $NON-NLS-1$ String varName = string.substring(4).trim(); String fcnName = getFunctionName( document, varName, document.getLineOfOffset(textSelection.getOffset())); return new String[] {varName, fcnName}; } } catch (CoreException e) { } catch (BadLocationException e) { } finally { documentProvider.disconnect(this); } } return null; }
private boolean openFileImpl(IProject project, IPath sourceLoc, int lineNumber) { if (sourceLoc == null || "??".equals(sourceLoc.toString())) return false; try { IEditorInput editorInput = getEditorInput(sourceLoc, project); IWorkbenchPage p= CUIPlugin.getActivePage(); if (p != null) { if (editorInput == null) { p.openEditor( new STCSourceNotFoundEditorInput(project, sourceLoc, lineNumber), "org.eclipse.linuxtools.binutils.link2source.STCSourceNotFoundEditor", true); } else { IEditorPart editor = p.openEditor(editorInput, CUIPlugin.EDITOR_ID, true); if (lineNumber > 0 && editor instanceof ITextEditor){ IDocumentProvider provider= ((ITextEditor)editor).getDocumentProvider(); IDocument document= provider.getDocument(editor.getEditorInput()); try { int start = document.getLineOffset(lineNumber-1); ((ITextEditor)editor).selectAndReveal(start, 0); IWorkbenchPage page= editor.getSite().getPage(); page.activate(editor); return true; } catch (BadLocationException x) { // ignore } } } } } catch (Exception _) { } return false; }
/** * Attaches a coverage annotation model for the given editor if the editor can be annotated. Does * nothing if the model is already attached. * * @param editor Editor to attach a annotation model to */ public static boolean attach(ITextEditor editor) { IDocumentProvider provider = editor.getDocumentProvider(); IEditorInput input = editor.getEditorInput(); if (provider != null && input instanceof FileEditorInput) { IAnnotationModel model = provider.getAnnotationModel(input); if (model instanceof IAnnotationModelExtension) { IAnnotationModelExtension modelex = (IAnnotationModelExtension) model; ColorAnnotationModel colormodel = (ColorAnnotationModel) modelex.getAnnotationModel(KEY); if (colormodel == null) { IFile file = ((FileEditorInput) input).getFile(); IFeatureProject project = CorePlugin.getFeatureProject(file); if (project != null && project.getComposer() != null && project.getComposer().needColor()) { IDocument document = provider.getDocument(input); colormodel = new ColorAnnotationModel(document, file, project, editor); modelex.addAnnotationModel(KEY, colormodel); return true; } } else { colormodel.updateAnnotations(!editor.isDirty()); } } } return false; }
public void apply(final IDocument document) { IProject p = marker.getResource().getProject(); IFile f = BuildWrapperPlugin.getCabalFile(p); IDocumentProvider prov = new TextFileDocumentProvider(); try { prov.connect(f); IDocument doc = prov.getDocument(f); PackageDescription pd = PackageDescriptionLoader.load(f); int length = pd.getStanzas().size(); for (int a = 0; a < length; a++) { PackageDescriptionStanza pds = pd.getStanzas().get(a); CabalSyntax cs = pds.getType(); if (CabalSyntax.SECTION_EXECUTABLE.equals(cs) || CabalSyntax.SECTION_LIBRARY.equals(cs) || CabalSyntax.SECTION_TESTSUITE.equals(cs)) { RealValuePosition rvp = pds.addToPropertyList(CabalSyntax.FIELD_BUILD_DEPENDS, pkg); if (rvp != null) { rvp.updateDocument(doc); pd = PackageDescriptionLoader.load(doc.get()); } } } prov.saveDocument(new NullProgressMonitor(), f, doc, true); } catch (CoreException ce) { HaskellUIPlugin.log(ce); } }
public static IWorkbench getMockWorkbench(String file) { IWorkbench workbench = mock(IWorkbench.class); IWorkbenchWindow window = mock(IWorkbenchWindow.class); IWorkbenchPage page = mock(IWorkbenchPage.class); ITextEditor editor = mock(ITextEditor.class); IDocumentProvider docProvider = mock(IDocumentProvider.class); IDocument doc = mock(IDocument.class); IPath ipath = mock(IPath.class); File afile = mock(File.class); IFile inputFile = mock(IFile.class); IFileEditorInput editorInput = mock(IFileEditorInput.class); when(workbench.getWorkbenchWindows()).thenReturn(new IWorkbenchWindow[] {window}); when(window.getActivePage()).thenReturn(page); when(page.getActiveEditor()).thenReturn(editor); when(editor.getEditorInput()).thenReturn(editorInput); when(editor.getDocumentProvider()).thenReturn(docProvider); when(editorInput.getFile()).thenReturn(inputFile); when(docProvider.getDocument(any())).thenReturn(doc); when(inputFile.getLocation()).thenReturn(ipath); when(inputFile.getName()).thenReturn(file); when(ipath.toFile()).thenReturn(afile); when(afile.length()).thenReturn(33l); return workbench; }
/** * Provide the initialization of the listeners additions. The Window, Part, and Document Listener * are added. Note that sensor shell should be instantiated before this method is called because * <code>processActivity()</code> method uses sensor shell instance. */ private void registerListeners() { IWorkbench workbench = EclipseSensorPlugin.getInstance().getWorkbench(); // :RESOLVED: JULY 1, 2003 // Supports the multiple window for sensor collection. IWorkbenchWindow[] activeWindows = workbench.getWorkbenchWindows(); // Check if window listener is not added yet. Otherwise multi instances are notified. if (this.windowListener == null) { this.windowListener = new WindowListenerAdapter(); workbench.addWindowListener(new WindowListenerAdapter()); } for (int i = 0; i < activeWindows.length; i++) { IWorkbenchPage activePage = activeWindows[i].getActivePage(); activePage.addPartListener(new PartListenerAdapter()); IEditorPart activeEditorPart = activePage.getActiveEditor(); // Adds this EclipseSensorPlugin instance to IDocumentListener // only when activeEditorPart is the instance of ITextEditor // so that null case is also ignored. if (activeEditorPart instanceof ITextEditor) { // Sets activeTextEditor. Otherwise a first activated file would not be recorded. this.activeTextEditor = (ITextEditor) activeEditorPart; // Gets opened file since the initial opened file is not notified from IPartListener. URI fileResource = EclipseSensor.this.getFileResource(this.activeTextEditor); Map<String, String> keyValueMap = new HashMap<String, String>(); keyValueMap.put(EclipseSensorConstants.SUBTYPE, "Open"); keyValueMap.put(EclipseSensorConstants.UNIT_TYPE, EclipseSensorConstants.FILE); keyValueMap.put( EclipseSensorConstants.UNIT_NAME, EclipseSensor.this.extractFileName(fileResource)); this.addDevEvent( EclipseSensorConstants.DEVEVENT_EDIT, fileResource, keyValueMap, "Opened " + fileResource.toString()); IDocumentProvider provider = this.activeTextEditor.getDocumentProvider(); IDocument document = provider.getDocument(activeEditorPart.getEditorInput()); // Initially sets active buffer and threshold buffer. // Otherwise a first activated buffer would not be recorded. this.activeBufferSize = document.getLength(); this.thresholdBufferSize = document.getLength(); document.addDocumentListener(new DocumentListenerAdapter()); } } // Handles breakpoint set/unset event. IBreakpointManager bpManager = DebugPlugin.getDefault().getBreakpointManager(); bpManager.addBreakpointListener(new BreakPointerSensor(this)); // Listens to debug event. DebugPlugin.getDefault().addDebugEventListener(new DebugSensor(this)); // Creates instance to handle build error. this.buildErrorSensor = new BuildErrorSensor(this); }
/** * Provides manipulation of browser part activation status due to implement <code>IPartListener * </code>. This method must not be called by client because it is called by platform. Do * nothing for Eclipse sensor so far. * * @param part An IWorkbenchPart instance to be triggered when a part is activated. */ public void partActivated(IWorkbenchPart part) { if (part instanceof ITextEditor) { // System.out.println("Sensor : " + part); EclipseSensor.this.isActivatedWindow = true; EclipseSensor.this.activeTextEditor = (ITextEditor) part; ITextEditor editor = EclipseSensor.this.activeTextEditor; IDocumentProvider provider = editor.getDocumentProvider(); IDocument document = provider.getDocument(editor.getEditorInput()); document.addDocumentListener(new DocumentListenerAdapter()); int activeBufferSize = provider.getDocument(editor.getEditorInput()).getLength(); // BuffTrans: Copy the new active file size to the threshold buffer size . EclipseSensor.this.thresholdBufferSize = activeBufferSize; EclipseSensor.this.activeBufferSize = activeBufferSize; } }
private void setXMLOutlineInput() { IDocumentProvider provider = fEditor.getDocumentProvider(); // force creation of the document & the model. IDocument document = provider.getDocument(fEditor.getEditorInput()); IXMLModelProvider modelProvider = UIPlugin.getDefault().getXMLModelProvider(); XMLReconciler model = (modelProvider).getModel(document); fXMLOutlinePage.setInput(model.getRoot()); }
public void uninstall() { ISourceViewer sourceViewer = editor.getISourceViewer(); if (sourceViewer != null) sourceViewer.removeTextInputListener(this); IDocumentProvider documentProvider = editor.getDocumentProvider(); if (documentProvider != null) { IDocument document = documentProvider.getDocument(editor.getEditorInput()); if (document != null) document.removeDocumentListener(this); } }
/** * the command has been executed, so extract extract the needed information from the application * context. */ public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); ITextSelection content = (ITextSelection) window .getActivePage() .getActiveEditor() .getEditorSite() .getSelectionProvider() .getSelection(); String texto = content.getText(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); String sqlFormatado = formatSQL(texto); StringSelection textoFormatado = new StringSelection(sqlFormatado); clipboard.setContents(textoFormatado, null); if (isBlank(texto)) { MessageDialog.openInformation(window.getShell(), "SQLCopy", "Você não selecionou nada!"); } else { if (isConvertToJava( texto)) { // Realizar a substituição do texto selecionado apenas quando estiver // convertendo um SQL para Java. IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); ITextEditor editor = (ITextEditor) part; IDocumentProvider prov = editor.getDocumentProvider(); IDocument doc = prov.getDocument(editor.getEditorInput()); ISelection sel = editor.getSelectionProvider().getSelection(); if (sel instanceof TextSelection) { final TextSelection textSel = (TextSelection) sel; try { // IRegion region = doc.getLineInformationOfOffset(textSel.getOffset()); // doc.replace( textSel.getOffset(), textSel.getLength(), // identingCode(region.getLength(), sqlFormatado)); doc.replace(textSel.getOffset(), textSel.getLength(), sqlFormatado); } catch (BadLocationException e) { e.printStackTrace(); } } } // MessageDialog.openInformation( // window.getShell(), // "SQLCopy", // sqlFormatado.toString()); CustomMessageDialog dialog = new CustomMessageDialog(window.getShell(), sqlFormatado.toString()); dialog.open(); } return null; }
private static IRegion getRegionOfInterest(ITextEditor editor, int invocationLocation) throws BadLocationException { IDocumentProvider documentProvider = editor.getDocumentProvider(); if (documentProvider == null) { return null; } IDocument document = documentProvider.getDocument(editor.getEditorInput()); if (document == null) { return null; } return document.getLineInformationOfOffset(invocationLocation); }
public static IDocument getDocument(IEditorReference er) { IEditorPart ep = er.getEditor(false); if (!(ep instanceof ITextEditor)) return null; ITextEditor te = (ITextEditor) ep; IDocumentProvider dp = te.getDocumentProvider(); if (dp == null) return null; IEditorInput input = getEditorInput(er); if (input == null) return null; return dp.getDocument(input); }
private IDocument getDocument(IDocumentProvider provider, IEditorInput input) { if (input == null) { return null; } IDocument result = null; try { provider.connect(input); result = provider.getDocument(input); } catch (CoreException e) { } finally { provider.disconnect(input); } return result; }
public void uninstall() { final ISourceViewer sourceViewer = erlangEditor.getViewer(); if (sourceViewer != null) { sourceViewer.removeTextInputListener(this); } final IDocumentProvider documentProvider = erlangEditor.getDocumentProvider(); if (documentProvider != null) { final IDocument document = documentProvider.getDocument(erlangEditor.getEditorInput()); if (document != null) { document.removeDocumentListener(this); } } }
/** * Attaches a coverage annotation model for the given editor if the editor can be annotated. Does * nothing if the model is already attached. * * @param editor Editor to attach a annotation model to */ public static void attach(ITextEditor editor) { IDocumentProvider provider = editor.getDocumentProvider(); // there may be text editors without document providers (SF #1725100) if (provider == null) return; IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput()); if (!(model instanceof IAnnotationModelExtension)) return; IAnnotationModelExtension modelex = (IAnnotationModelExtension) model; IDocument document = provider.getDocument(editor.getEditorInput()); CoverageAnnotationModel coveragemodel = (CoverageAnnotationModel) modelex.getAnnotationModel(KEY); if (coveragemodel == null) { coveragemodel = new CoverageAnnotationModel(editor, document); modelex.addAnnotationModel(KEY, coveragemodel); } }
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { super.init(site, input); sourcePage.init(site, input); setPartNameForInput(input); IResource resource = ResourceUtil.getResource(input); if (resource != null) { resource.getWorkspace().addResourceChangeListener(this); } final IDocumentProvider docProvider = sourcePage.getDocumentProvider(); IDocument document = docProvider.getDocument(input); try { model.loadFrom(new IDocumentWrapper(document)); model.setProjectFile(Project.BNDFILE.equals(input.getName())); if (resource != null) { model.setBndResource(resource.getLocation().toFile()); } // model.addPropertyChangeListener(modelListener); } catch (IOException e) { throw new PartInitException("Error reading editor input.", e); } // Ensure the field values are updated if the file content is replaced docProvider.addElementStateListener( new IElementStateListener() { public void elementMoved(Object originalElement, Object movedElement) {} public void elementDirtyStateChanged(Object element, boolean isDirty) {} public void elementDeleted(Object element) {} public void elementContentReplaced(Object element) { try { model.loadFrom(new IDocumentWrapper(docProvider.getDocument(element))); } catch (IOException e) { logger.logError("Error loading model from document.", e); } } public void elementContentAboutToBeReplaced(Object element) {} }); }
/** * Provides manipulation of browser deactivation status due to implement <code>IWindowListener * </code>. This method must not be called by client because it is called by platform. Do * nothing for Eclipse sensor so far. * * @param window An IWorkbenchWindow instance to be triggered when a window is deactivated. */ public void windowDeactivated(IWorkbenchWindow window) { EclipseSensor.this.isActivatedWindow = false; IEditorPart activeEditorPart = window.getActivePage().getActiveEditor(); if (activeEditorPart instanceof ITextEditor) { ITextEditor editor = (ITextEditor) activeEditorPart; IDocumentProvider provider = editor.getDocumentProvider(); // provider could be null if the text editor is closed before this method is called. EclipseSensor.this.previousTextEditor = editor; int fromFileBufferSize = provider.getDocument(editor.getEditorInput()).getLength(); // Check if a threshold buffer is either dirty or // not the same as the current from file buffer size; EclipseSensor.this.isModifiedFromFile = (editor.isDirty() || (EclipseSensor.this.thresholdBufferSize != fromFileBufferSize)); } }
public String getText(Node node) throws BadLocationException { IDocument document = (editorInput == null) ? null : documentProvider.getDocument(editorInput); if ((document == null) || (node.position == null)) { return null; } int len = document.getLength(); int offset = node.position.offset; int length = len - offset; if (length > 0) { return document.get(offset, length); } return null; }
public void editorPageChanged(Viewer viewer) { if (editorInput != null) { IDocument document = documentProvider.getDocument(editorInput); if (document != null) { RMLDocument d = Studio.getSelectedDocument(); DesignPane pane = d == null ? null : d.getDesignPane(); if (pane == null || pane.getRootWidget() == null) { rootElement = parseNodes(document); } else { rootElement = new Node(pane.getRootWidget()); } viewer.refresh(); } } }
/** * The action has been activated. The argument of the method represents the 'real' action sitting * in the workbench UI. * * @see IWorkbenchWindowActionDelegate#run */ @Override public void run(final IAction action) { final IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if (!(part instanceof AbstractTextEditor)) { return; } final ITextEditor editor = (ITextEditor) part; final IDocumentProvider dp = editor.getDocumentProvider(); final IDocument doc = dp.getDocument(editor.getEditorInput()); try { impexClient.validateImpex(doc.get(0, doc.getLength())); } catch (final BadLocationException e) { logger.log( new Status(Status.ERROR, Activator.PLUGIN_ID, Status.ERROR, "Bad Location Exception", e)); } }
protected void fireActivity(TextEditActivity activity) { expectedActivities.add(activity); List<ITextOperation> textOps = activity.toOperation().getTextOperations(); IFile file = ((EclipseFileImpl) currentActiveEditor.getFile()).getDelegate(); FileEditorInput input = new FileEditorInput(file); IDocumentProvider provider = EditorManager.getDocumentProvider(input); try { provider.connect(input); } catch (CoreException e) { log.error("Could not connect to a document provider on file '" + file.toString() + "':", e); return; } try { IDocument doc = provider.getDocument(input); if (doc == null) { log.error( "Could not connect to a document provider on file '" + file.toString() + "':", new StackTrace()); return; } for (ITextOperation textOp : textOps) { try { if (textOp instanceof DeleteOperation) doc.replace(textOp.getPosition(), textOp.getTextLength(), ""); if (textOp instanceof InsertOperation) doc.replace(textOp.getPosition(), 0, textOp.getText()); } catch (BadLocationException e) { log.error("Invalid location for " + textOp); } } } finally { provider.disconnect(input); } }
/** * Returns a selection of the member in the given text selection, or the original selection if * none. * * @param part * @param selection * @return a structured selection of the member in the given text selection, or the original * selection if none * @exception CoreException if an exception occurs */ protected ISelection translateToMembers(IWorkbenchPart part, ISelection selection) throws CoreException { ITextEditor textEditor = getTextEditor(part); if (textEditor != null && selection instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection) selection; IEditorInput editorInput = textEditor.getEditorInput(); IDocumentProvider documentProvider = textEditor.getDocumentProvider(); if (documentProvider == null) { throw new CoreException(Status.CANCEL_STATUS); } IDocument document = documentProvider.getDocument(editorInput); int offset = textSelection.getOffset(); if (document != null) { try { IRegion region = document.getLineInformationOfOffset(offset); int end = region.getOffset() + region.getLength(); while (Character.isWhitespace(document.getChar(offset)) && offset < end) { offset++; } } catch (BadLocationException e) { } } IMember m = null; IRubyScript root = getTypeRoot(editorInput); if (root != null) { synchronized (root) { root.reconcile(false, null, null); } IRubyElement e = root.getElementAt(offset); if (e instanceof IMember) { m = (IMember) e; } } if (m != null) { return new StructuredSelection(m); } } return selection; }
private void initializeSourceViewer(IEditorInput input) { IDocumentProvider documentProvider = getDocumentProvider(); IAnnotationModel model = documentProvider.getAnnotationModel(input); IDocument document = documentProvider.getDocument(input); if (document != null) { fSourceViewer.setDocument(document, model); fSourceViewer.setEditable(isEditable()); fSourceViewer.showAnnotations(model != null); } if (fElementStateListener instanceof IElementStateListenerExtension) { boolean isStateValidated = false; if (documentProvider instanceof IDocumentProviderExtension) isStateValidated = ((IDocumentProviderExtension) documentProvider).isStateValidated(input); IElementStateListenerExtension extension = (IElementStateListenerExtension) fElementStateListener; extension.elementStateValidationChanged(input, isStateValidated); } }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event); final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext()); try { if (workbenchPart instanceof ITextEditor && selection instanceof ITextSelection) { final ITextEditor editor = (ITextEditor) workbenchPart; final IDocumentProvider documentProvider = editor.getDocumentProvider(); if (documentProvider == null) { return null; } final IDocument document = documentProvider.getDocument(editor.getEditorInput()); if (document == null) { return null; } final List<String> lines = LaunchShortcutUtil.getSelectedCodeLines(event); if (lines != null) { RCodeLaunching.runRCodeDirect(lines, false, null); final int newOffset = getNextLineOffset(document, ((ITextSelection) selection).getEndLine()); if (newOffset >= 0) { editor.selectAndReveal(newOffset, 0); } } return null; } } catch (final CoreException e) { LaunchShortcutUtil.handleRLaunchException( e, RLaunchingMessages.RSelectionLaunch_error_message, event); return null; } LaunchShortcutUtil.handleUnsupportedExecution(event); return null; }
/** * Provides manipulation of browser part deactivation status due to implement <code> * IPartListener</code>. This method must not be called by client because it is called by * platform. Sets active text editor to be null when the text editor part is deactivated. * * @param part An IWorkbenchPart instance to be triggered when a part is deactivated. */ public void partDeactivated(IWorkbenchPart part) { if (part instanceof ITextEditor && !part.equals(EclipseSensor.this.deactivatedTextEditor)) { EclipseSensor.this.deactivatedTextEditor = (ITextEditor) part; if (EclipseSensor.this.isActivatedWindow) { IEditorPart activeEditorPart = part.getSite().getPage().getActiveEditor(); // Sets activeTextEdtior to be null only when there is no more active editor. // Otherwise the case that the non text editor part is active causes the activeTextEditor // to be null so that sensor is not collected after that. if (activeEditorPart == null) { EclipseSensor.this.activeTextEditor = null; } // BuffTrans to get the toFrom buffer size. ITextEditor editor = (ITextEditor) part; IDocumentProvider provider = editor.getDocumentProvider(); // provider could be null if the text editor is closed before this method is called. EclipseSensor.this.isModifiedFromFile = false; EclipseSensor.this.previousTextEditor = null; if (provider != null) { EclipseSensor.this.previousTextEditor = editor; int fromFileBufferSize = provider.getDocument(editor.getEditorInput()).getLength(); // Check if a threshold buffer is either dirty or // not the same as the current from file buffer size; EclipseSensor.this.isModifiedFromFile = (editor.isDirty() || (EclipseSensor.this.thresholdBufferSize != fromFileBufferSize)); } } else { EclipseSensor.this.isActivatedWindow = true; } } }
public static void checkRegions( IProject project, String fileName, List<TestRegion> regionList, AbstractHyperlinkDetector elDetector) throws Exception { IFile file = project.getFile(fileName); assertNotNull("The file \"" + fileName + "\" is not found", file); assertTrue("The file \"" + fileName + "\" is not found", file.isAccessible()); FileEditorInput editorInput = new FileEditorInput(file); IDocumentProvider documentProvider = null; try { documentProvider = DocumentProviderRegistry.getDefault().getDocumentProvider(editorInput); } catch (Exception x) { x.printStackTrace(); fail("An exception caught: " + x.getMessage()); } assertNotNull( "The document provider for the file \"" + fileName + "\" is not loaded", documentProvider); try { documentProvider.connect(editorInput); } catch (Exception x) { x.printStackTrace(); fail( "The document provider is not able to be initialized with the editor input\nAn exception caught: " + x.getMessage()); } IDocument document = documentProvider.getDocument(editorInput); assertNotNull("The document for the file \"" + fileName + "\" is not loaded", document); if (regionList.get(0).region == null) loadRegions(regionList, document); int expected = 0; for (TestRegion testRegion : regionList) expected += testRegion.region.getLength() + 1; IEditorPart part = openFileInEditor(file); ISourceViewer viewer = null; if (part instanceof JavaEditor) { viewer = ((JavaEditor) part).getViewer(); elDetector.setContext(new TestContext((ITextEditor) part)); } else if (part instanceof EditorPartWrapper) { if (((EditorPartWrapper) part).getEditor() instanceof WebCompoundEditor) { WebCompoundEditor wce = (WebCompoundEditor) ((EditorPartWrapper) part).getEditor(); viewer = wce.getSourceEditor().getTextViewer(); elDetector.setContext(new TestContext(wce.getSourceEditor())); } else if (((EditorPartWrapper) part).getEditor() instanceof XMLTextEditorStandAlone) { XMLTextEditorStandAlone xtesa = (XMLTextEditorStandAlone) ((EditorPartWrapper) part).getEditor(); viewer = xtesa.getTextViewer(); elDetector.setContext(new TestContext(xtesa)); } else fail("unsupported editor type - " + ((EditorPartWrapper) part).getEditor().getClass()); } else if (part instanceof JSPMultiPageEditor) { viewer = ((JSPMultiPageEditor) part).getJspEditor().getTextViewer(); elDetector.setContext(new TestContext(((JSPMultiPageEditor) part).getJspEditor())); } else fail("unsupported editor type - " + part.getClass()); int counter = 0; for (int i = 0; i < document.getLength(); i++) { int lineNumber = document.getLineOfOffset(i); int position = i - document.getLineOffset(lineNumber) + 1; lineNumber++; TestData testData = new TestData(document, i); IHyperlink[] links = elDetector.detectHyperlinks(viewer, testData.getHyperlinkRegion(), true); boolean recognized = links != null; if (recognized) { counter++; TestRegion testRegion = findOffsetInRegions(i, regionList); if (testRegion == null) { String information = findRegionInformation(document, i, regionList); fail( "Wrong detection for offset - " + i + " (line - " + lineNumber + " position - " + position + ") " + information); } else { checkTestRegion(links, testRegion); } } else { for (TestRegion testRegion : regionList) { if (i >= testRegion.region.getOffset() && i <= testRegion.region.getOffset() + testRegion.region.getLength()) { fail( "Wrong detection for region - " + getRegionInformation(document, testRegion) + " offset - " + i + " (line - " + lineNumber + " position - " + position + ")"); } } } } assertEquals("Wrong recognized region count: ", expected, counter); documentProvider.disconnect(editorInput); }