summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-11-09 13:52:41 (EST)
committerEike Stepper2007-11-09 13:52:41 (EST)
commit094a76cc5b5f8210d7bdce68921141c482ae2573 (patch)
treeae0a11428d6bf180c2b689a6b83726a13bd3784a
parent71e145d9e68aa84983f5385bb9a51e5c5de5d739 (diff)
downloadcdo-094a76cc5b5f8210d7bdce68921141c482ae2573.zip
cdo-094a76cc5b5f8210d7bdce68921141c482ae2573.tar.gz
cdo-094a76cc5b5f8210d7bdce68921141c482ae2573.tar.bz2
[209346] Provide Fileshare example
https://bugs.eclipse.org/bugs/show_bug.cgi?id=209346
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/dnd/BuddiesTransfer.java77
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDragListener.java84
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java7
-rw-r--r--plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDTransfer.java2
6 files changed, 169 insertions, 3 deletions
diff --git a/plugins/org.eclipse.net4j.buddies.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.buddies.ui/META-INF/MANIFEST.MF
index aa834b3..3f1a54f 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.buddies.ui/META-INF/MANIFEST.MF
@@ -17,6 +17,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)",
org.eclipse.net4j.chat;bundle-version="[0.8.0,0.9.0)";resolution:=optional
Export-Package: org.eclipse.net4j.buddies.internal.ui;version="0.8.0",
org.eclipse.net4j.buddies.internal.ui.actions;version="0.8.0",
+ org.eclipse.net4j.buddies.internal.ui.dnd;version="0.8.0",
org.eclipse.net4j.buddies.internal.ui.preferences;version="0.8.0",
org.eclipse.net4j.buddies.internal.ui.views;version="0.8.0",
org.eclipse.net4j.buddies.ui;version="0.8.0"
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/dnd/BuddiesTransfer.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/dnd/BuddiesTransfer.java
new file mode 100644
index 0000000..7b62c32
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/dnd/BuddiesTransfer.java
@@ -0,0 +1,77 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.buddies.internal.ui.dnd;
+
+import org.eclipse.net4j.buddies.IBuddySession;
+import org.eclipse.net4j.buddies.internal.ui.SessionManager;
+import org.eclipse.net4j.buddies.internal.ui.bundle.OM;
+import org.eclipse.net4j.buddies.protocol.IBuddy;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.ui.dnd.DNDTransfer;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class BuddiesTransfer extends DNDTransfer<IBuddy[]>
+{
+ public static final String TYPE_NAME = "buddies-transfer-format";
+
+ public static final BuddiesTransfer INSTANCE = new BuddiesTransfer();
+
+ public BuddiesTransfer()
+ {
+ super(TYPE_NAME);
+ }
+
+ @Override
+ protected void writeObject(ExtendedDataOutputStream out, IBuddy[] buddies) throws IOException
+ {
+ out.writeInt(buddies.length);
+ for (IBuddy buddy : buddies)
+ {
+ out.writeString(buddy.getUserID());
+ }
+ }
+
+ @Override
+ protected IBuddy[] readObject(ExtendedDataInputStream in) throws IOException
+ {
+ IBuddySession session = SessionManager.INSTANCE.getSession();
+ if (session == null)
+ {
+ OM.LOG.warn("Buddy session is not available");
+ return null;
+ }
+
+ List<IBuddy> buddies = new ArrayList<IBuddy>();
+ int size = in.readInt();
+ for (int i = 0; i < size; i++)
+ {
+ String userID = in.readString();
+ IBuddy buddy = session.getBuddy(userID);
+ if (buddy != null)
+ {
+ buddies.add(buddy);
+ }
+ else
+ {
+ OM.LOG.warn("Buddy is not available: " + userID);
+ }
+ }
+
+ return buddies.toArray(new IBuddy[buddies.size()]);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDragListener.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDragListener.java
new file mode 100644
index 0000000..b96fbfd
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDragListener.java
@@ -0,0 +1,84 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.buddies.internal.ui.views;
+
+import org.eclipse.net4j.buddies.internal.ui.dnd.BuddiesTransfer;
+import org.eclipse.net4j.buddies.protocol.IBuddy;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.swt.dnd.DragSourceAdapter;
+import org.eclipse.swt.dnd.DragSourceEvent;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class BuddiesDragListener extends DragSourceAdapter
+{
+ private StructuredViewer viewer;
+
+ public BuddiesDragListener(StructuredViewer viewer)
+ {
+ this.viewer = viewer;
+ }
+
+ @Override
+ public void dragSetData(DragSourceEvent event)
+ {
+ if (BuddiesTransfer.INSTANCE.isSupportedType(event.dataType))
+ {
+ event.data = getBuddies();
+ }
+ }
+
+ @Override
+ public void dragStart(DragSourceEvent event)
+ {
+ event.doit = !viewer.getSelection().isEmpty();
+ }
+
+ protected IBuddy[] getBuddies()
+ {
+ IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ List<IBuddy> buddies = new ArrayList<IBuddy>();
+ for (Iterator<Object> it = selection.iterator(); it.hasNext();)
+ {
+ Object element = it.next();
+ if (element instanceof IBuddy)
+ {
+ IBuddy buddy = (IBuddy)element;
+ buddies.add(buddy);
+ }
+ }
+
+ return buddies.toArray(new IBuddy[buddies.size()]);
+ }
+
+ // @Override
+ // public void dragFinished(DragSourceEvent event)
+ // {
+ // if (!event.doit) return;
+ // // if the gadget was moved, remove it from the source viewer
+ // if (event.detail == DND.DROP_MOVE)
+ // {
+ // IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ // for (Iterator it = selection.iterator(); it.hasNext();)
+ // {
+ // ((Gadget)it.next()).setParent(null);
+ // }
+ // viewer.refresh();
+ // }
+ // }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java
index 62bf9e3..d7d1447 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java
@@ -11,11 +11,14 @@
package org.eclipse.net4j.buddies.internal.ui.views;
import org.eclipse.net4j.buddies.IBuddyCollaboration;
+import org.eclipse.net4j.buddies.internal.ui.dnd.BuddiesTransfer;
import org.eclipse.net4j.buddies.protocol.IBuddy;
import org.eclipse.net4j.buddies.protocol.ICollaboration;
import org.eclipse.net4j.util.container.ContainerUtil;
import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -35,8 +38,8 @@ public class BuddiesView extends SessionManagerView
protected Control createControl(Composite parent)
{
Control control = super.createControl(parent);
- // Transfer[] transfers = new Transfer[] { GadgetTransfer.getInstance() };
- // getViewer().addDragSupport(DND.DROP_LINK, transfers, new GadgetDragListener(viewer));
+ Transfer[] transfers = new Transfer[] { BuddiesTransfer.INSTANCE };
+ getViewer().addDragSupport(DND.DROP_LINK, transfers, new BuddiesDragListener(getViewer()));
return control;
}
diff --git a/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF
index 353a819..4212d41 100644
--- a/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF
@@ -16,6 +16,7 @@ Export-Package: org.eclipse.net4j.util.internal.ui;version="0.8.0",
org.eclipse.net4j.util.internal.ui.views;version="0.8.0",
org.eclipse.net4j.util.ui;version="0.8.0",
org.eclipse.net4j.util.ui.actions;version="0.8.0",
+ org.eclipse.net4j.util.ui.dnd;version="0.8.0",
org.eclipse.net4j.util.ui.prefs;version="0.8.0",
org.eclipse.net4j.util.ui.proposals;version="0.8.0",
org.eclipse.net4j.util.ui.views;version="0.8.0",
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDTransfer.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDTransfer.java
index bee568a..c5ca4b6 100644
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDTransfer.java
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDTransfer.java
@@ -30,7 +30,7 @@ public abstract class DNDTransfer<TYPE> extends ByteArrayTransfer
private int typeID;
- private DNDTransfer(String typeName)
+ protected DNDTransfer(String typeName)
{
this.typeName = typeName;
typeID = registerType(typeName);