Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 45634 Details for
Bug 89806
[API] Add a 'Team' quick diff that delegates to team provider's implementation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch to org.eclipse.team.ui
89806.patch (text/plain), 14.94 KB, created by
Brock Janiczak
on 2006-06-30 23:32:27 EDT
(
hide
)
Description:
patch to org.eclipse.team.ui
Filename:
MIME Type:
Creator:
Brock Janiczak
Created:
2006-06-30 23:32:27 EDT
Size:
14.94 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.team.ui >Index: plugin.xml >=================================================================== >RCS file: /home/eclipse/org.eclipse.team.ui/plugin.xml,v >retrieving revision 1.176 >diff -u -r1.176 plugin.xml >--- plugin.xml 22 Jun 2006 20:11:50 -0000 1.176 >+++ plugin.xml 1 Jul 2006 03:35:31 -0000 >@@ -454,5 +454,13 @@ > value="true"/> > </triggerPoint> > </extension> >+ <extension >+ point="org.eclipse.ui.workbench.texteditor.quickDiffReferenceProvider"> >+ <referenceprovider >+ class="org.eclipse.team.internal.ui.quickdiff.WorkspaceSubscriberQuickDiffProvider" >+ default="true" >+ id="org.eclipse.quickdiff.providers.WorkspaceSubscriberReferenceProvider" >+ label="Team state"/> >+ </extension> > > </plugin> >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /home/eclipse/org.eclipse.team.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.20 >diff -u -r1.20 MANIFEST.MF >--- META-INF/MANIFEST.MF 19 Jun 2006 18:09:13 -0000 1.20 >+++ META-INF/MANIFEST.MF 1 Jul 2006 03:35:31 -0000 >@@ -29,7 +29,9 @@ > org.eclipse.ui.forms;bundle-version="[3.2.0,4.0.0)", > org.eclipse.ui.navigator;bundle-version="[3.2.0,4.0.0)", > org.eclipse.jface.text;bundle-version="[3.2.0,4.0.0)", >- org.eclipse.ui.navigator.resources;bundle-version="[3.2.0,4.0.0) >+ org.eclipse.ui.navigator.resources;bundle-version="[3.2.0,4.0.0)", >+ org.eclipse.ui.workbench.texteditor;bundle-version="[3.2.0,4.0.0)", >+ org.eclipse.ui.editors;bundle-version="[3.2.0,4.0.0)" > Eclipse-LazyStart: true > Import-Package: com.ibm.icu.text, > com.ibm.icu.util >Index: src/org/eclipse/team/internal/ui/quickdiff/WorkspaceSubscriberQuickDiffProvider.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ui/quickdiff/WorkspaceSubscriberQuickDiffProvider.java >diff -N src/org/eclipse/team/internal/ui/quickdiff/WorkspaceSubscriberQuickDiffProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ui/quickdiff/WorkspaceSubscriberQuickDiffProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,360 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.team.internal.ui.quickdiff; >+ >+import java.io.*; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.*; >+import org.eclipse.core.runtime.jobs.Job; >+import org.eclipse.jface.text.Document; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.team.core.RepositoryProvider; >+import org.eclipse.team.core.TeamException; >+import org.eclipse.team.core.subscribers.ISubscriberChangeEvent; >+import org.eclipse.team.core.subscribers.ISubscriberChangeListener; >+import org.eclipse.team.core.subscribers.Subscriber; >+import org.eclipse.team.core.synchronize.SyncInfo; >+import org.eclipse.team.core.variants.IResourceVariant; >+import org.eclipse.ui.IEditorInput; >+import org.eclipse.ui.editors.text.IStorageDocumentProvider; >+import org.eclipse.ui.ide.ResourceUtil; >+import org.eclipse.ui.texteditor.*; >+import org.eclipse.ui.texteditor.quickdiff.IQuickDiffReferenceProvider; >+ >+/** >+ * A QuickDiff provider that provides a reference to the latest revision of a file >+ * in the CVS repository. The provider notifies when the file's sync state changes >+ * and the diff should be recalculated (e.g. commit, update...) or when the file >+ * is changed (e.g. replace with). >+ * >+ * Here are the file states and what this provider does for each: >+ * >+ * 1. File is unmanaged : reference == empty document >+ * 2. Unmanaged file transitions to managed : empty reference updated with new remote revision >+ * 3. A managed file has new remote (commit, refresh remote) : reference updated with new >+ * remote revision >+ * 4. A managed file cleaned, remote is the same (replace with, update) : refresh diff bar >+ * with existing reference >+ * >+ * [Note: Currently an empty document must be returned for an unmanaged file. This >+ * results in the entire document appearing as outgoing changes in the quickdiff bar. >+ * This is required because the quickdiff support relies on IDocument change events >+ * to update the quickdiff, and returning null for the reference document doesn't >+ * allow the transition to later return a IDocument.] >+ * >+ * @since 3.0 >+ */ >+public class WorkspaceSubscriberQuickDiffProvider implements IQuickDiffReferenceProvider { >+ // The editor showing this quickdiff and provides access to the editor input and >+ // ultimatly the IFile. >+ private ITextEditor fEditor = null; >+ >+ // The document containing the remote file. Can be null if the assigned editor doesn't have >+ // a CVS remote resource associated with it. >+ private IDocument fReference = null; >+ >+ // Will be true when the document has been read and initialized. >+ private boolean fReferenceInitialized = false; >+ >+ // Document provider allows us to register/deregister the element state change listener. >+ private IDocumentProvider fDocumentProvider = null; >+ >+ // Unique id for this reference provider as set via setId(). >+ private String fId; >+ >+ // A handle to the remote CVS file for this provider. >+ private SyncInfo fLastSyncState; >+ >+ // Job that re-creates the reference document. >+ private Job fUpdateJob; >+ >+ // currently selected file >+ private IFile fFile = null; >+ >+ private Subscriber fSubscriber = null; >+ >+ private boolean DEBUG = false; >+ >+ /** >+ * Updates the document if a sync changes occurs to the associated CVS file. >+ */ >+ private ISubscriberChangeListener teamChangeListener = new ISubscriberChangeListener() { >+ public void subscriberResourceChanged(ISubscriberChangeEvent[] deltas) { >+ if(fReferenceInitialized) { >+ for (int i = 0; i < deltas.length; i++) { >+ ISubscriberChangeEvent delta = deltas[i]; >+ IResource resource = delta.getResource(); >+ if(resource.getType() == IResource.FILE && >+ fLastSyncState != null && resource.equals(fLastSyncState.getLocal())) { >+ if(delta.getFlags() == ISubscriberChangeEvent.SYNC_CHANGED) { >+ fetchContentsInJob(); >+ } >+ } >+ } >+ } >+ } >+ }; >+ >+ /** >+ * Updates the document if the document is changed (e.g. replace with) >+ */ >+ private IElementStateListener documentListener = new IElementStateListener() { >+ public void elementDirtyStateChanged(Object element, boolean isDirty) { >+ } >+ >+ public void elementContentAboutToBeReplaced(Object element) { >+ } >+ >+ public void elementContentReplaced(Object element) { >+ if(fEditor != null && fEditor.getEditorInput() == element) { >+ fetchContentsInJob(); >+ } >+ } >+ >+ public void elementDeleted(Object element) { >+ } >+ >+ public void elementMoved(Object originalElement, Object movedElement) { >+ } >+ }; >+ >+ /* >+ * @see org.eclipse.test.quickdiff.DocumentLineDiffer.IQuickDiffReferenceProvider#getReference() >+ */ >+ public IDocument getReference(IProgressMonitor monitor) throws CoreException { >+ if(! fReferenceInitialized) return null; >+ if (fReference == null) { >+ readDocument(monitor); >+ } >+ return fReference; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.texteditor.quickdiff.IQuickDiffProviderImplementation#setActiveEditor(org.eclipse.ui.texteditor.ITextEditor) >+ */ >+ public void setActiveEditor(ITextEditor targetEditor) { >+ IEditorInput editorInput = targetEditor.getEditorInput(); >+ if (editorInput == null || ResourceUtil.getFile(editorInput) == null) return; >+ fEditor = targetEditor; >+ fDocumentProvider= fEditor.getDocumentProvider(); >+ >+ if(fDocumentProvider != null) { >+ fFile = getFileFromEditor(); >+ if (fFile != null) { >+ RepositoryProvider provider = RepositoryProvider.getProvider(fFile.getProject()); >+ // During a checkout, the provider is not available until the operation is complete >+ if (provider != null) { >+ fSubscriber = provider.getSubscriber(); >+ if (fSubscriber != null) { >+ fSubscriber.addListener(teamChangeListener); >+ } >+ } >+ } >+ fDocumentProvider.addElementStateListener(documentListener); >+ } >+ fReferenceInitialized= true; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.texteditor.quickdiff.IQuickDiffProviderImplementation#isEnabled() >+ */ >+ public boolean isEnabled() { >+ if (! fReferenceInitialized) >+ return false; >+ try { >+ if(fEditor != null && fSubscriber != null) { >+ return fSubscriber.isSupervised(fFile); >+ } >+ } catch (TeamException e) { >+ return false; >+ } >+ return false; >+ } >+ >+ /* >+ * @see org.eclipse.jface.text.source.diff.DocumentLineDiffer.IQuickDiffReferenceProvider#dispose() >+ */ >+ public void dispose() { >+ fReferenceInitialized = false; >+ // stop update job >+ if(fUpdateJob != null && fUpdateJob.getState() != Job.NONE) { >+ fUpdateJob.cancel(); >+ } >+ >+ // remove listeners >+ if(fDocumentProvider != null) { >+ fDocumentProvider.removeElementStateListener(documentListener); >+ } >+ >+ if (fSubscriber != null) { >+ fSubscriber.removeListener(teamChangeListener); >+ } >+ } >+ >+ /* >+ * @see org.eclipse.quickdiff.QuickDiffTestPlugin.IQuickDiffProviderImplementation#setId(java.lang.String) >+ */ >+ public void setId(String id) { >+ fId= id; >+ } >+ >+ /* >+ * @see org.eclipse.jface.text.source.diff.DocumentLineDiffer.IQuickDiffReferenceProvider#getId() >+ */ >+ public String getId() { >+ return fId; >+ } >+ >+ /** >+ * Determine if the file represented by this quickdiff provider has changed with >+ * respect to it's remote state. Return true if the remote contents should be >+ * refreshed, and false if not. >+ */ >+ private boolean computeChange(IProgressMonitor monitor) throws TeamException { >+ boolean needToUpdateReferenceDocument = false; >+ if(fReferenceInitialized) { >+ SyncInfo info = getSyncState(getFileFromEditor()); >+ if(info == null && fLastSyncState != null) { >+ return true; >+ } else if(info == null) { >+ return false; >+ } >+ >+ if(fLastSyncState == null) { >+ needToUpdateReferenceDocument = true; >+ } else if(! fLastSyncState.equals(info)) { >+ needToUpdateReferenceDocument = true; >+ } >+ if(DEBUG) debug(fLastSyncState, info); >+ fLastSyncState = info; >+ } >+ return needToUpdateReferenceDocument; >+ } >+ >+ private void debug(SyncInfo lastSyncState, SyncInfo info) { >+ String last = "[none]"; //$NON-NLS-1$ >+ if(lastSyncState != null) { >+ last = lastSyncState.toString(); >+ } >+ System.out.println("+ CVSQuickDiff: was " + last + " is " + info.toString()); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ >+ private SyncInfo getSyncState(IResource resource) throws TeamException { >+ if (resource == null) return null; >+ return fSubscriber.getSyncInfo(resource); >+ } >+ >+ /** >+ * Creates a document and initializes it with the contents of a CVS remote >+ * resource. >+ * @param monitor the progress monitor >+ * @throws CoreException >+ */ >+ private void readDocument(IProgressMonitor monitor) throws CoreException { >+ if(! fReferenceInitialized) return; >+ if(fReference == null) >+ fReference = new Document(); >+ if(computeChange(monitor)) { >+ IResourceVariant remoteFile = (IResourceVariant)fLastSyncState.getRemote(); >+ if (fLastSyncState.getRemote() != null && fDocumentProvider instanceof IStorageDocumentProvider) { >+ IStorageDocumentProvider provider= (IStorageDocumentProvider) fDocumentProvider; >+ String encoding= provider.getEncoding(fEditor.getEditorInput()); >+ if (encoding == null) { >+ encoding= provider.getDefaultEncoding(); >+ } >+ if(monitor.isCanceled()) return; >+ InputStream stream= remoteFile.getStorage(monitor).getContents(); >+ if (stream == null || monitor.isCanceled() || ! fReferenceInitialized) { >+ return; >+ } >+ setDocumentContent(fReference, stream, encoding); >+ } else { >+ // the remote is null, so ensure that the document is null >+ if(monitor.isCanceled()) return; >+ fReference.set(""); //$NON-NLS-1$ >+ } >+ if(DEBUG) System.out.println("+ CVSQuickDiff: updating document " + (fReference!=null ? "remote found" : "remote empty")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ } >+ } >+ >+ /** >+ * Intitializes the given document with the given stream using the given encoding. >+ * >+ * @param document the document to be initialized >+ * @param contentStream the stream which delivers the document content >+ * @param encoding the character encoding for reading the given stream >+ * @exception CoreException if the given stream can not be read >+ */ >+ private static void setDocumentContent(IDocument document, InputStream contentStream, String encoding) throws CoreException { >+ Reader in= null; >+ try { >+ final int DEFAULT_FILE_SIZE= 15 * 1024; >+ >+ in= new InputStreamReader(contentStream, encoding); >+ CharArrayWriter caw= new CharArrayWriter(DEFAULT_FILE_SIZE); >+ char[] readBuffer= new char[2048]; >+ int n= in.read(readBuffer); >+ while (n > 0) { >+ caw.write(readBuffer, 0, n); >+ n= in.read(readBuffer); >+ } >+ document.set(caw.toString()); >+ //System.out.println("+ CVSQuickDiff: updating document : " + caw.toString()); >+ } catch (IOException x) { >+ throw new TeamException("Error reading remote file", x); >+ } finally { >+ if (in != null) { >+ try { >+ in.close(); >+ } catch (IOException x) { >+ throw new TeamException("error closing remote file", x); >+ } >+ } >+ } >+ } >+ >+ private IFile getFileFromEditor() { >+ if(fEditor != null) { >+ IEditorInput input= fEditor.getEditorInput(); >+ if (input != null) { >+ IFile file = ResourceUtil.getFile(input); >+ return file; >+ } >+ } >+ return null; >+ } >+ >+ /** >+ * Runs a job that updates the document. If a previous job is already running it >+ * is stopped before the new job can start. >+ */ >+ private void fetchContentsInJob() { >+ if(! fReferenceInitialized) return; >+ if(fUpdateJob != null && fUpdateJob.getState() != Job.NONE) { >+ fUpdateJob.cancel(); >+ } >+ fUpdateJob = new Job("QuickDiff: fetching remote contents") { >+ protected IStatus run(IProgressMonitor monitor) { >+ try { >+ readDocument(monitor); >+ } catch (CoreException e) { >+ // continue and return ok for now. The error will be reported >+ // when the quick diff supports calls getReference() again. >+ // continue >+ } >+ return Status.OK_STATUS; >+ } >+ }; >+ fUpdateJob.schedule(); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 89806
:
45634
|
46341
|
49292