Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Michel-Lemieux2003-08-21 09:26:00 -0400
committerJean Michel-Lemieux2003-08-21 09:26:00 -0400
commitbb68c8c1727610908ebb057bd952c0f1149bcabc (patch)
tree4c878098fd62d3fa4c4ba53d56a473cee089c845
parent600b503d45cde972b8660803da29686a223dc9aa (diff)
downloadeclipse.platform.team-bb68c8c1727610908ebb057bd952c0f1149bcabc.tar.gz
eclipse.platform.team-bb68c8c1727610908ebb057bd952c0f1149bcabc.tar.xz
eclipse.platform.team-bb68c8c1727610908ebb057bd952c0f1149bcabc.zip
*** empty log message ***
-rw-r--r--bundles/org.eclipse.team.cvs.ui/plugin.properties1
-rw-r--r--bundles/org.eclipse.team.cvs.ui/plugin.xml11
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/RemoteRevisionQuickDiffProvider.java189
3 files changed, 201 insertions, 0 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/plugin.properties b/bundles/org.eclipse.team.cvs.ui/plugin.properties
index 2cae29824..b23ea563d 100644
--- a/bundles/org.eclipse.team.cvs.ui/plugin.properties
+++ b/bundles/org.eclipse.team.cvs.ui/plugin.properties
@@ -188,3 +188,4 @@ CVSWorkspaceSubscriber.merge.label=&Update
CVSWorkspaceSubscriber.merge.tooltip=Perform an update merge on the visible resources
WorkInProgress.name=Work In Progress
+CVSRemoteQuickDiffProvider=CVS Remote Revision \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.ui/plugin.xml b/bundles/org.eclipse.team.cvs.ui/plugin.xml
index 8d79739e8..ecb437886 100644
--- a/bundles/org.eclipse.team.cvs.ui/plugin.xml
+++ b/bundles/org.eclipse.team.cvs.ui/plugin.xml
@@ -882,4 +882,15 @@
</description>
</fontDefinition>
</extension>
+
+ <!-- ********** QuickDiff text editor support ************** -->
+ <extension
+ point="org.eclipse.ui.editors.quickDiffReferenceProvider">
+ <referenceprovider
+ label="%CVSRemoteQuickDiffProvider.label"
+ class="org.eclipse.team.internal.ccvs.ui.RemoteRevisionQuickDiffProvider"
+ id="org.eclipse.quickdiff.providers.CVSReferenceProvider">
+ </referenceprovider>
+ </extension>
+
</plugin>
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/RemoteRevisionQuickDiffProvider.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/RemoteRevisionQuickDiffProvider.java
new file mode 100644
index 000000000..316158e20
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/RemoteRevisionQuickDiffProvider.java
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ccvs.ui;
+
+import java.io.BufferedReader;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.team.core.sync.IRemoteResource;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.editors.quickdiff.IQuickDiffProviderImplementation;
+import org.eclipse.ui.editors.text.StorageDocumentProvider;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * Quick and dirty cvs reference provider. No background, no hourglass cursor, no nothing.
+ * @since 3.0
+ */
+public class RemoteRevisionQuickDiffProvider implements IQuickDiffProviderImplementation {
+
+ private boolean fDocumentRead= false;
+ private ITextEditor fEditor= null;
+ private IDocument fReference= null;
+ private String fId;
+
+ /*
+ * @see org.eclipse.test.quickdiff.DocumentLineDiffer.IQuickDiffReferenceProvider#getReference()
+ */
+ public IDocument getReference() {
+ if (!fDocumentRead)
+ readDocument();
+ if (fDocumentRead)
+ return fReference;
+ else
+ return null;
+ }
+
+ /**
+ * 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 BufferedReader(new InputStreamReader(contentStream, encoding), DEFAULT_FILE_SIZE);
+ 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());
+ } catch (IOException x) {
+ String msg= x.getMessage() == null ? "" : x.getMessage(); //$NON-NLS-1$
+ IStatus s= new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, msg, x);
+ throw new CoreException(s);
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException x) {
+ }
+ }
+ }
+ }
+
+ private void readDocument() {
+ // TODO this is quick&dirty
+ if (!initialized())
+ return;
+ fDocumentRead= false;
+ IEditorInput input= fEditor.getEditorInput();
+ if (fReference == null)
+ fReference= new Document();
+ if (input instanceof IFileEditorInput) {
+ IFile file= ((IFileEditorInput)input).getFile();
+ IRemoteResource remote= null;
+ try {
+ remote= CVSWorkspaceRoot.getRemoteResourceFor(file);
+ } catch (CVSException e) {
+ return;
+ }
+ if (remote == null)
+ return;
+
+ IDocumentProvider provider= fEditor.getDocumentProvider();
+ if (provider instanceof StorageDocumentProvider) {
+ StorageDocumentProvider sProvider= (StorageDocumentProvider)provider;
+ String encoding= sProvider.getEncoding(input);
+ if (encoding == null)
+ encoding= sProvider.getDefaultEncoding();
+ try {
+ InputStream stream= remote.getContents(new NullProgressMonitor());
+ if (stream == null)
+ return;
+ setDocumentContent(fReference, stream, encoding);
+ } catch (CoreException e1) {
+ // TODO Auto-generated catch block
+ MessageDialog.openError(fEditor.getSite().getShell(), "CoreException", "Error when retrieving remote version");
+ return;
+ }
+ }
+ }
+ fDocumentRead= true;
+ }
+
+ private boolean initialized() {
+ return fEditor != null;
+ }
+
+ public void setActiveEditor(ITextEditor targetEditor) {
+ if (targetEditor != fEditor) {
+ dispose();
+ fEditor= targetEditor;
+ }
+ }
+
+ /*
+ * @see org.eclipse.quickdiff.QuickDiffTestPlugin.IQuickDiffProviderImplementation#isEnabled()
+ */
+ public boolean isEnabled() {
+ if (!initialized())
+ return false;
+ IEditorInput input= fEditor.getEditorInput();
+ if (input instanceof IFileEditorInput) {
+ IFile file= ((IFileEditorInput)input).getFile();
+ try {
+ return CVSWorkspaceRoot.isSharedWithCVS(file);
+ } catch (CVSException e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ }
+ return false;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.source.diff.DocumentLineDiffer.IQuickDiffReferenceProvider#dispose()
+ */
+ public void dispose() {
+ fReference= null;
+ fDocumentRead= false;
+ }
+
+ /*
+ * @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;
+ }
+}

Back to the top