summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-11-09 13:32:29 (EST)
committerEike Stepper2007-11-09 13:32:29 (EST)
commit71e145d9e68aa84983f5385bb9a51e5c5de5d739 (patch)
treec97623a7485caf4a9fff5335451850ce84ac5d63
parent24bafedaafe707d7cf5896e82fdd176fa9610a7c (diff)
downloadcdo-71e145d9e68aa84983f5385bb9a51e5c5de5d739.zip
cdo-71e145d9e68aa84983f5385bb9a51e5c5de5d739.tar.gz
cdo-71e145d9e68aa84983f5385bb9a51e5c5de5d739.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/BuddiesView.java13
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDTransfer.java96
2 files changed, 109 insertions, 0 deletions
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 b62bc43..62bf9e3 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
@@ -16,6 +16,9 @@ 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.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
public class BuddiesView extends SessionManagerView
{
public BuddiesView()
@@ -29,6 +32,16 @@ public class BuddiesView extends SessionManagerView
}
@Override
+ 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));
+
+ return control;
+ }
+
+ @Override
protected void doubleClicked(Object object)
{
if (getSession() != null && object instanceof IBuddy)
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
new file mode 100644
index 0000000..bee568a
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDTransfer.java
@@ -0,0 +1,96 @@
+/***************************************************************************
+ * 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.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.TransferData;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class DNDTransfer<TYPE> extends ByteArrayTransfer
+{
+ private String typeName;
+
+ private int typeID;
+
+ private DNDTransfer(String typeName)
+ {
+ this.typeName = typeName;
+ typeID = registerType(typeName);
+ }
+
+ @Override
+ protected int[] getTypeIds()
+ {
+ return new int[] { typeID };
+ }
+
+ @Override
+ protected String[] getTypeNames()
+ {
+ return new String[] { typeName };
+ }
+
+ @Override
+ protected void javaToNative(Object object, TransferData transferData)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ExtendedDataOutputStream out = new ExtendedDataOutputStream(baos);
+ byte[] bytes = null;
+
+ try
+ {
+ writeObject(out, ((TYPE)object));
+ out.close();
+ bytes = baos.toByteArray();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+
+ if (bytes != null)
+ {
+ super.javaToNative(bytes, transferData);
+ }
+ }
+
+ @Override
+ protected Object nativeToJava(TransferData transferData)
+ {
+ byte[] bytes = (byte[])super.nativeToJava(transferData);
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ExtendedDataInputStream in = new ExtendedDataInputStream(bais);
+
+ try
+ {
+ return readObject(in);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ return null;
+ }
+ }
+
+ protected abstract void writeObject(ExtendedDataOutputStream out, TYPE object) throws IOException;
+
+ protected abstract TYPE readObject(ExtendedDataInputStream in) throws IOException;
+} \ No newline at end of file