@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()); } } }
@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); } } }
private void rewriteImports() { if (fImportRewrite == null) return; if (isReadOnly()) return; ICompilationUnit cu = getCompilationUnit(); if (cu == null) return; try { Position position = new Position(getCompletionOffset(), 0); IDocument document = getDocument(); final String category = "__template_position_importer" + System.currentTimeMillis(); // $NON-NLS-1$ IPositionUpdater updater = new DefaultPositionUpdater(category); document.addPositionCategory(category); document.addPositionUpdater(updater); document.addPosition(position); try { JavaModelUtil.applyEdit(cu, fImportRewrite.rewriteImports(null), false, null); setCompletionOffset(position.getOffset()); } catch (CoreException e) { handleException(null, e); } finally { document.removePosition(position); document.removePositionUpdater(updater); document.removePositionCategory(category); } } catch (BadLocationException e) { handleException(null, e); } catch (BadPositionCategoryException e) { handleException(null, e); } }
private void ensurePositionCategoryRemoved(IDocument document) { if (document.containsPositionCategory(getCategory())) { try { document.removePositionCategory(getCategory()); } catch (BadPositionCategoryException e) { // ignore } document.removePositionUpdater(fUpdater); } }
/** * Called after the document changed occurred. It must be preceded by a call to preReplace(). * * @param document the document on which to track the reference position. * @return offset after the replace */ public int postReplace(IDocument document) { try { document.removePosition(CATEGORY, fPosition); document.removePositionUpdater(fPositionUpdater); document.removePositionCategory(CATEGORY); } catch (BadPositionCategoryException e) { // should not happen DartToolsPlugin.log(e); } return fPosition.getOffset(); }
/** * Uninstalls this position manager form the given document. If the position manager has no been * installed on this document, this method is without effect. * * @param document the document form which to uninstall */ public void uninstall(IDocument document) { if (document == fDocument && document != null) { try { fDocument.removePositionUpdater(fPositionUpdater); fDocument.removePositionCategory(fCategory); } catch (BadPositionCategoryException x) { // should not happen EmbeddedCALPlugin.logError("Error managing document:\n" + document.get(), x); } fDocument = null; } }
protected void clearRememberedSelection() { if (!fSelections.isEmpty()) fSelections.clear(); IDocument document = getDocument(); if (document != null && fSelectionUpdater != null) { document.removePositionUpdater(fSelectionUpdater); try { document.removePositionCategory(fSelectionCategory); } catch (BadPositionCategoryException e) { // ignore } } fSelectionUpdater = null; fSelectionCategory = null; }
/* * @see org.eclipse.swt.dnd.DragSourceListener#dragFinished(org.eclipse.swt.dnd.DragSourceEvent) */ @Override public void dragFinished(DragSourceEvent event) { IDocument doc = fViewer.getDocument(); try { doc.removePositionCategory(DRAG_SELECTION_CATEGORY); doc.removePositionUpdater(fPositionUpdater); } catch (BadPositionCategoryException e1) { // cannot happen } if (event.doit && event.detail == DND.DROP_MOVE && isDocumentEditable()) { try { doc.replace(fSelectionPosition.offset, fSelectionPosition.length, null); } catch (BadLocationException e) { // ignore } } if (fViewer instanceof ITextViewerExtension) { ((ITextViewerExtension) fViewer).getRewriteTarget().endCompoundChange(); } }