summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-11-09 14:44:28 (EST)
committerEike Stepper2007-11-09 14:44:28 (EST)
commit0c94aa3b7a54ff5f1037f6bcd96603b0ef6ab9b6 (patch)
tree22d047dc93b59a330cf62818ea5624db7df07b63
parent094a76cc5b5f8210d7bdce68921141c482ae2573 (diff)
downloadcdo-0c94aa3b7a54ff5f1037f6bcd96603b0ef6ab9b6.zip
cdo-0c94aa3b7a54ff5f1037f6bcd96603b0ef6ab9b6.tar.gz
cdo-0c94aa3b7a54ff5f1037f6bcd96603b0ef6ab9b6.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/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDragListener.java48
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDropAdapter.java43
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java5
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java9
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/IBuddyCollaboration.java4
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java24
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDragListener.java61
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDropAdapter.java63
8 files changed, 210 insertions, 47 deletions
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
index b96fbfd..e495e2d 100644
--- 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
@@ -12,47 +12,29 @@ 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.net4j.util.ui.dnd.DNDDragListener;
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.Collection;
import java.util.Iterator;
-import java.util.List;
/**
* @author Eike Stepper
*/
-public class BuddiesDragListener extends DragSourceAdapter
+public class BuddiesDragListener extends DNDDragListener<IBuddy[]>
{
- 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();
- }
+ super(BuddiesTransfer.INSTANCE, viewer);
}
@Override
- public void dragStart(DragSourceEvent event)
- {
- event.doit = !viewer.getSelection().isEmpty();
- }
-
- protected IBuddy[] getBuddies()
+ protected IBuddy[] getObject(IStructuredSelection selection)
{
- IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
- List<IBuddy> buddies = new ArrayList<IBuddy>();
+ Collection<IBuddy> buddies = new ArrayList<IBuddy>();
for (Iterator<Object> it = selection.iterator(); it.hasNext();)
{
Object element = it.next();
@@ -62,23 +44,7 @@ public class BuddiesDragListener extends DragSourceAdapter
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/BuddiesDropAdapter.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDropAdapter.java
new file mode 100644
index 0000000..89d02e5
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDropAdapter.java
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * 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.IBuddyCollaboration;
+import org.eclipse.net4j.buddies.internal.ui.dnd.BuddiesTransfer;
+import org.eclipse.net4j.buddies.protocol.IBuddy;
+import org.eclipse.net4j.util.ui.dnd.DNDDropAdapter;
+
+import org.eclipse.jface.viewers.StructuredViewer;
+
+/**
+ * @author Eike Stepper
+ */
+public class BuddiesDropAdapter extends DNDDropAdapter<IBuddy[]>
+{
+ public BuddiesDropAdapter(StructuredViewer viewer)
+ {
+ super(BuddiesTransfer.INSTANCE, viewer);
+ }
+
+ @Override
+ protected boolean performDrop(IBuddy[] buddies, Object target)
+ {
+ IBuddyCollaboration collaboration = (IBuddyCollaboration)target;
+ collaboration.invite(buddies);
+ return true;
+ }
+
+ @Override
+ protected boolean validateTarget(Object target)
+ {
+ return target instanceof IBuddyCollaboration;
+ }
+} \ 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 d7d1447..294d6e4 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
@@ -17,6 +17,7 @@ import org.eclipse.net4j.buddies.protocol.ICollaboration;
import org.eclipse.net4j.util.container.ContainerUtil;
import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Composite;
@@ -38,9 +39,9 @@ public class BuddiesView extends SessionManagerView
protected Control createControl(Composite parent)
{
Control control = super.createControl(parent);
+ TreeViewer viewer = getViewer();
Transfer[] transfers = new Transfer[] { BuddiesTransfer.INSTANCE };
- getViewer().addDragSupport(DND.DROP_LINK, transfers, new BuddiesDragListener(getViewer()));
-
+ viewer.addDragSupport(DND.DROP_LINK, transfers, new BuddiesDragListener(viewer));
return control;
}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java
index 4b942e9..521e402 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.buddies.internal.ui.views;
import org.eclipse.net4j.buddies.IBuddyCollaboration;
import org.eclipse.net4j.buddies.internal.ui.bundle.OM;
+import org.eclipse.net4j.buddies.internal.ui.dnd.BuddiesTransfer;
import org.eclipse.net4j.buddies.ui.IFacilityPaneCreator;
import org.eclipse.net4j.internal.buddies.ClientBuddy;
import org.eclipse.net4j.util.StringUtil;
@@ -31,7 +32,10 @@ import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -84,6 +88,11 @@ public class CollaborationsView extends SessionManagerView
bars.getMenuManager().add(new Separator());
bars.getToolBarManager().add(new Separator());
getCollaborationsPane().fillActionBars(bars);
+
+ TreeViewer viewer = getViewer();
+ Transfer[] transfers = new Transfer[] { BuddiesTransfer.INSTANCE };
+ viewer.addDropSupport(DND.DROP_LINK, transfers, new BuddiesDropAdapter(viewer));
+
return sashComposite;
}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/IBuddyCollaboration.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/IBuddyCollaboration.java
index 252e436..b6cb8a8 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/IBuddyCollaboration.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/IBuddyCollaboration.java
@@ -23,7 +23,9 @@ public interface IBuddyCollaboration extends ICollaboration
public IFacility installFacility(String type);
- public IBuddy invite(String userID);
+ public IBuddy[] invite(String... userIDs);
+
+ public void invite(IBuddy... buddies);
public void leave();
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java
index 8e2f023..8d957b6 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java
@@ -26,6 +26,8 @@ import org.eclipse.net4j.internal.buddies.protocol.InstallFacilityRequest;
import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.container.IPluginContainer;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
/**
@@ -94,10 +96,26 @@ public class BuddyCollaboration extends Collaboration implements IBuddyCollabora
}
}
- public IBuddy invite(String userID)
+ public IBuddy[] invite(String... userIDs)
{
- // TODO Implement method BuddyCollaboration.invite()
- throw new UnsupportedOperationException("Not yet implemented");
+ List<IBuddy> buddies = new ArrayList<IBuddy>();
+ for (String userID : userIDs)
+ {
+ IBuddy buddy = session.getBuddy(userID);
+ buddies.add(buddy);
+ }
+
+ IBuddy[] array = buddies.toArray(new IBuddy[buddies.size()]);
+ invite(array);
+ return array;
+ }
+
+ public void invite(IBuddy... buddies)
+ {
+ for (IBuddy buddy : buddies)
+ {
+ System.out.println("INVITING: " + buddy);
+ }
}
public void leave()
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDragListener.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDragListener.java
new file mode 100644
index 0000000..1586f73
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDragListener.java
@@ -0,0 +1,61 @@
+/***************************************************************************
+ * 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.util.ui.dnd;
+
+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 org.eclipse.swt.dnd.Transfer;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class DNDDragListener<TYPE> extends DragSourceAdapter
+{
+ private Transfer transfer;
+
+ private StructuredViewer viewer;
+
+ public DNDDragListener(Transfer transfer, StructuredViewer viewer)
+ {
+ this.transfer = transfer;
+ this.viewer = viewer;
+ }
+
+ public Transfer getTransfer()
+ {
+ return transfer;
+ }
+
+ public StructuredViewer getViewer()
+ {
+ return viewer;
+ }
+
+ @Override
+ public void dragSetData(DragSourceEvent event)
+ {
+ if (transfer.isSupportedType(event.dataType))
+ {
+ IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ event.data = getObject(selection);
+ }
+ }
+
+ @Override
+ public void dragStart(DragSourceEvent event)
+ {
+ event.doit = !viewer.getSelection().isEmpty();
+ }
+
+ protected abstract TYPE getObject(IStructuredSelection selection);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDropAdapter.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDropAdapter.java
new file mode 100644
index 0000000..52ccc65
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDropAdapter.java
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * 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.util.ui.dnd;
+
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.ViewerDropAdapter;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class DNDDropAdapter<TYPE> extends ViewerDropAdapter
+{
+ private Transfer transfer;
+
+ protected DNDDropAdapter(Transfer transfer, StructuredViewer viewer)
+ {
+ super(viewer);
+ this.transfer = transfer;
+ }
+
+ public Transfer getTransfer()
+ {
+ return transfer;
+ }
+
+ @Override
+ public StructuredViewer getViewer()
+ {
+ return (StructuredViewer)super.getViewer();
+ }
+
+ @Override
+ public boolean performDrop(Object data)
+ {
+ Object target = getCurrentTarget();
+ if (target == null)
+ {
+ target = getViewer().getInput();
+ }
+
+ return performDrop((TYPE)data, target);
+ }
+
+ @Override
+ public boolean validateDrop(Object target, int op, TransferData type)
+ {
+ return transfer.isSupportedType(type) && validateTarget(target);
+ }
+
+ protected abstract boolean performDrop(TYPE data, Object target);
+
+ protected abstract boolean validateTarget(Object target);
+} \ No newline at end of file