@Override public void elementContentReplaced(Object element) { if (!checkState()) return; IEditorInput input = getDocumentKey(); if (input != null && input.equals(element)) { this.fViewer.updateDirtyState(input, getDocumentProvider(), fLeg); // recalculate diffs and update controls new UIJob(CompareMessages.DocumentMerger_0) { @Override public IStatus runInUIThread(IProgressMonitor monitor) { update(true); updateStructure(fLeg); return Status.OK_STATUS; } }.schedule(); } } @Override
newDocument= ((IDocumentRange) fElement).getDocument(); range= ((IDocumentRange) fElement).getRange(); connectToSharedDocument(); newDocument= DocumentManager.get(fElement); if (newDocument == null) { newDocument = createDocument(); DocumentManager.put(fElement, newDocument); setupDocument(newDocument); } else if (fDocumentProvider == null) { connectToSharedDocument(); updateViewerDocument(tp, newDocument, range); } else { // same document but different range updateViewerDocumentRange(tp, range);
newDocument= ((IDocumentRange)fElement).getDocument(); range= ((IDocumentRange)fElement).getRange(); connectToSharedDocument(); newDocument= DocumentManager.get(fElement); if (newDocument == null) { newDocument = createDocument(); DocumentManager.put(fElement, newDocument); setupDocument(newDocument); } else if (fDocumentProvider == null) { connectToSharedDocument(); updateViewerDocument(tp, newDocument, range); } else { // same document but different range updateViewerDocumentRange(tp, range);
IEditorInput key = getDocumentKey(); if (key != null) { if (fDocumentProvider != null) { IDocumentProvider documentProvider = getDocumentProvider(); if (documentProvider != null) { try { connect(documentProvider, key); setCachedDocumentProvider(key, documentProvider); IDocument newDoc = documentProvider.getDocument(key);
public void disconnect() { IDocumentProvider provider = null; IEditorInput input = getDocumentKey(); synchronized(this) { if (fDocumentProvider != null) { provider = fDocumentProvider; fDocumentProvider = null; fDocumentKey = null; } } if (provider != null) { disconnect(provider, input); provider.removeElementStateListener(this); } // If we have a listener registered with the widget, remove it if (fSourceViewer != null) { StyledText textWidget = fSourceViewer.getSourceViewer().getTextWidget(); if (textWidget != null && !textWidget.isDisposed()) { if (fNeedsValidation) { textWidget.removeVerifyListener(this); fNeedsValidation = false; } IDocument oldDoc= internalGetDocument(fSourceViewer); if (oldDoc != null) { oldDoc.removeDocumentListener(this); } } } clearCachedDocument(); }
/** * Connect to a shared document if possible. Return <code>null</code> * if the connection was not possible. * @return the shared document or <code>null</code> if connection to a * shared document was not possible */ private IDocument connectToSharedDocument() { IEditorInput key = getDocumentKey(); if (key != null) { if (fDocumentProvider != null) { // We've already connected and setup the document return fDocumentProvider.getDocument(key); } IDocumentProvider documentProvider = getDocumentProvider(); if (documentProvider != null) { try { connect(documentProvider, key); setCachedDocumentProvider(key, documentProvider); IDocument newDoc = documentProvider.getDocument(key); this.fViewer.updateDirtyState(key, documentProvider, fLeg); return newDoc; } catch (CoreException e) { // Connection failed. Log the error and continue without a shared document CompareUIPlugin.log(e); } } } return null; }
public void disconnect() { IDocumentProvider provider = null; IEditorInput input = getDocumentKey(); synchronized(this) { if (fDocumentProvider != null) { provider = fDocumentProvider; fDocumentProvider = null; fDocumentKey = null; } } if (provider != null) { disconnect(provider, input); provider.removeElementStateListener(this); } // If we have a listener registered with the widget, remove it if (fSourceViewer != null && !fSourceViewer.getTextWidget().isDisposed()) { if (fNeedsValidation) { fSourceViewer.getTextWidget().removeVerifyListener(this); fNeedsValidation = false; } IDocument oldDoc= internalGetDocument(fSourceViewer); if (oldDoc != null) { oldDoc.removeDocumentListener(this); } } clearCachedDocument(); }
/** * 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; }
/** * 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 = Adapters.adapt(fElement, ISharedDocumentAdapter.class); if (sda != null) { return sda.getDocumentKey(fElement); } } return null; }
public void setDocument(MergeSourceViewer viewer, boolean isEditable) { // Ensure that this method is only called once Assert.isTrue(fSourceViewer == null); fSourceViewer = viewer; try { internalSetDocument(viewer); } catch (RuntimeException e) { // The error may be due to a stale entry in the DocumentManager (see bug 184489) clearCachedDocument(); throw e; } setEditable(viewer.getSourceViewer(), isEditable); // Verify changes if the document is editable if (isEditable) { fNeedsValidation = true; viewer.getSourceViewer().getTextWidget().addVerifyListener(this); } }
private IDocument createDocument() { // If the content provider is a text content provider, attempt to obtain // a shared document (i.e. file buffer) IDocument newDoc = connectToSharedDocument(); if (newDoc == null) { IStreamContentAccessor sca= (IStreamContentAccessor) fElement; String s= null; try { String encoding = getEncoding(); s = Utilities.readString(sca, encoding); } catch (CoreException ex) { this.fViewer.setError(fLeg, ex.getMessage()); } newDoc= new Document(s != null ? s : ""); //$NON-NLS-1$ } return newDoc; }
public void setDocument(MergeSourceViewer viewer, boolean isEditable) { // Ensure that this method is only called once Assert.isTrue(fSourceViewer == null); fSourceViewer = viewer; try { internalSetDocument(viewer); } catch (RuntimeException e) { // The error may be due to a stale entry in the DocumentManager (see bug 184489) clearCachedDocument(); throw e; } viewer.setEditable(isEditable); // Verify changes if the document is editable if (isEditable) { fNeedsValidation = true; viewer.getTextWidget().addVerifyListener(this); } }
private IDocument createDocument() { // If the content provider is a text content provider, attempt to obtain // a shared document (i.e. file buffer) IDocument newDoc = connectToSharedDocument(); if (newDoc == null) { IStreamContentAccessor sca= (IStreamContentAccessor) fElement; String s= null; try { String encoding = internalGetEncoding(); s = Utilities.readString(sca, encoding); } catch (CoreException ex) { this.fViewer.setError(fLeg, ex.getMessage()); } newDoc= new Document(s != null ? s : ""); //$NON-NLS-1$ } return newDoc; }
private ContributorInfo createLegInfoFor(Object element, char leg) { return new ContributorInfo(this, element, leg); }
private ContributorInfo createLegInfoFor(Object element, char leg) { return new ContributorInfo(this, element, leg); }
private boolean canHaveSharedDocument() { return fViewer.canHaveSharedDocument(); }
private void disconnect(ContributorInfo legInfo) { if (legInfo != null) legInfo.disconnect(); }
private boolean canHaveSharedDocument() { return fViewer.canHaveSharedDocument(); }
@Override public void elementDirtyStateChanged(Object element, boolean isDirty) { if (!checkState()) return; IEditorInput input = getDocumentKey(); if (input != null && input.equals(element)) { this.fViewer.updateDirtyState(input, getDocumentProvider(), fLeg); } }
private void beginRefresh() { isRefreshing = true; fLeftContributor.cacheSelection(fLeft); fRightContributor.cacheSelection(fRight); fAncestorContributor.cacheSelection(fAncestor); if (fSynchronizedScrolling) { fSynchronziedScrollPosition = fVScrollBar.getSelection(); } }