Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2005-02-10 21:13:06 +0000
committerMichael Valenta2005-02-10 21:13:06 +0000
commit7e3f96b5d6db52e1eeebe04fcca0624a7aae894f (patch)
treecb4df0c00f203d4a4c0248820799977041855d40
parenteaccd197b8ef1c193ce2885eea37eb0a9ce21dab (diff)
downloadeclipse.platform.team-7e3f96b5d6db52e1eeebe04fcca0624a7aae894f.tar.gz
eclipse.platform.team-7e3f96b5d6db52e1eeebe04fcca0624a7aae894f.tar.xz
eclipse.platform.team-7e3f96b5d6db52e1eeebe04fcca0624a7aae894f.zip
Bug 82939 Enable drag-n-drop from cvs repository view to cvs resource history view
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSResourceTransfer.java102
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/HistoryDropAdapter.java23
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/HistoryView.java2
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesView.java52
4 files changed, 171 insertions, 8 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSResourceTransfer.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSResourceTransfer.java
new file mode 100644
index 000000000..928e2f84e
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSResourceTransfer.java
@@ -0,0 +1,102 @@
+
+package org.eclipse.team.internal.ccvs.ui;
+
+import java.io.*;
+
+import org.eclipse.swt.dnd.*;
+import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
+import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
+import org.eclipse.team.internal.ccvs.core.resources.RemoteFile;
+import org.eclipse.team.internal.ccvs.core.util.KnownRepositories;
+
+
+/**
+ *
+ * @author Eugene Kuleshov
+ */
+public final class CVSResourceTransfer extends ByteArrayTransfer {
+
+ public static final String TYPE_NAME = "CVS-resource-transfer-format"; //$NON-NLS-1$
+
+ public static int TYPE = registerType(TYPE_NAME);
+
+ private static CVSResourceTransfer instance = new CVSResourceTransfer();
+
+
+ private CVSResourceTransfer() {
+ }
+
+ public static CVSResourceTransfer getInstance() {
+ return instance;
+ }
+
+
+ protected int[] getTypeIds() {
+ return new int[] { TYPE };
+ }
+
+ protected String[] getTypeNames() {
+ return new String[] { TYPE_NAME };
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.Transfer#javaToNative(java.lang.Object,org.eclipse.swt.dnd.TransferData)
+ */
+ public void javaToNative(Object object, TransferData transferData) {
+ if (!isSupportedType(transferData)) {
+ DND.error(DND.ERROR_INVALID_DATA);
+ }
+
+ final byte[] bytes = toByteArray((ICVSRemoteFile) object);
+ if (bytes != null) {
+ super.javaToNative(bytes, transferData);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.dnd.Transfer#nativeToJava(org.eclipse.swt.dnd.TransferData)
+ */
+ protected Object nativeToJava(TransferData transferData) {
+ byte[] bytes = (byte[]) super.nativeToJava(transferData);
+ return fromByteArray(bytes);
+ }
+
+
+ private Object fromByteArray(byte[] bytes) {
+ final DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
+
+ try {
+ String location = in.readUTF();
+ String filePath = in.readUTF();
+ String fileRevision = in.readUTF();
+
+ ICVSRepositoryLocation repositoryLocation = KnownRepositories.getInstance().getRepository(location);
+ RemoteFile file = RemoteFile.create( filePath, repositoryLocation);
+ file.setRevision(fileRevision);
+ file.setReadOnly(true);
+ return file;
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ private byte[] toByteArray(ICVSRemoteFile file) {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(bos);
+ try {
+ dos.writeUTF(file.getRepository().getLocation(false));
+ dos.writeUTF(file.getRepositoryRelativePath());
+ dos.writeUTF(file.getRevision());
+ return bos.toByteArray();
+ } catch (Exception ex) {
+ // ex.printStackTrace();
+ return null;
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/HistoryDropAdapter.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/HistoryDropAdapter.java
index 1e3fe6ee5..598b0bed8 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/HistoryDropAdapter.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/HistoryDropAdapter.java
@@ -18,6 +18,7 @@ import org.eclipse.jface.viewers.ViewerDropAdapter;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
import org.eclipse.ui.part.ResourceTransfer;
public class HistoryDropAdapter extends ViewerDropAdapter {
@@ -49,15 +50,23 @@ public class HistoryDropAdapter extends ViewerDropAdapter {
}
public boolean performDrop(Object data) {
if (data == null) return false;
- IResource[] sources = (IResource[])data;
- if (sources.length == 0) return false;
- IResource resource = sources[0];
- if (!(resource instanceof IFile)) return false;
- view.showHistory(resource, true /* fetch */);
- return true;
+ if(data instanceof IResource[]) {
+ IResource[] sources = (IResource[])data;
+ if (sources.length == 0) return false;
+ IResource resource = sources[0];
+ if (!(resource instanceof IFile)) return false;
+ view.showHistory(resource, true /* fetch */);
+ return true;
+ } else if( data instanceof ICVSRemoteFile) {
+ view.showHistory((ICVSRemoteFile) data, true /* fetch */);
+ return true;
+ }
+ return false;
}
public boolean validateDrop(Object target, int operation, TransferData transferType) {
- if (transferType != null && ResourceTransfer.getInstance().isSupportedType(transferType)) {
+ if (transferType != null &&
+ (ResourceTransfer.getInstance().isSupportedType(transferType) ||
+ CVSResourceTransfer.getInstance().isSupportedType(transferType))) {
return true;
}
return false;
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/HistoryView.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/HistoryView.java
index 5590b484e..39fff7aa6 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/HistoryView.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/HistoryView.java
@@ -573,7 +573,7 @@ public class HistoryView extends ViewPart {
*/
void initDragAndDrop() {
int ops = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
- Transfer[] transfers = new Transfer[] {ResourceTransfer.getInstance()};
+ Transfer[] transfers = new Transfer[] {ResourceTransfer.getInstance(), CVSResourceTransfer.getInstance()};
tableViewer.addDropSupport(ops, transfers, new HistoryDropAdapter(tableViewer, this));
}
private void fillTableMenu(IMenuManager manager) {
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesView.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesView.java
index d53918971..49deec9eb 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesView.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesView.java
@@ -26,6 +26,10 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.DragSourceListener;
+import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Composite;
@@ -37,6 +41,7 @@ import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource;
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.ICVSResource;
import org.eclipse.team.internal.ccvs.core.util.KnownRepositories;
+import org.eclipse.team.internal.ccvs.ui.CVSResourceTransfer;
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
import org.eclipse.team.internal.ccvs.ui.IHelpContextIds;
@@ -97,6 +102,45 @@ public class RepositoriesView extends RemoteViewPart {
});
}
};
+
+ private static final class RepositoryDragSourceListener implements DragSourceListener {
+ private IStructuredSelection selection;
+
+ public void dragStart(DragSourceEvent event) {
+ if(selection!=null) {
+ final Object[] array = selection.toArray();
+ // event.doit = Utils.getResources(array).length > 0;
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] instanceof ICVSRemoteFile) {
+ event.doit = true;
+ return;
+ }
+ }
+ event.doit = false;
+ }
+ }
+
+ public void dragSetData(DragSourceEvent event) {
+ if (selection!=null && CVSResourceTransfer.getInstance().isSupportedType(event.dataType)) {
+ final Object[] array = selection.toArray();
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] instanceof ICVSRemoteFile) {
+ event.data = array[i];
+ return;
+ }
+ }
+ }
+ }
+
+ public void dragFinished( DragSourceEvent event) {
+ }
+
+ public void updateSelection( IStructuredSelection selection) {
+ this.selection = selection;
+ }
+ }
+
+ RepositoryDragSourceListener repositoryDragSourceListener;
/**
* Constructor for RepositoriesView.
@@ -247,6 +291,11 @@ public class RepositoriesView extends RemoteViewPart {
handleChange(selection);
}
});
+
+ repositoryDragSourceListener = new RepositoryDragSourceListener();
+ viewer.addDragSupport( DND.DROP_LINK | DND.DROP_DEFAULT,
+ new Transfer[] { CVSResourceTransfer.getInstance()},
+ repositoryDragSourceListener);
}
/**
@@ -323,5 +372,8 @@ public class RepositoriesView extends RemoteViewPart {
removeRootAction.updateSelection(selection);
removeDateTagAction.updateSelection(selection);
removeAction.setEnabled(removeRootAction.isEnabled() || removeDateTagAction.isEnabled());
+
+ repositoryDragSourceListener.updateSelection(selection);
}
+
}

Back to the top