[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[gef3d-commits] r581 - trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd

Author: jvonpilgrim
Date: 2011-06-11 11:17:05 -0400 (Sat, 11 Jun 2011)
New Revision: 581

Added:
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorCommand.java
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorPolicy.java
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorRequest.java
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorTargetListener.java
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropCommand.java
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceDropPolicy.java
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceDropRequest.java
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceTransferDropTargetListener.java
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourcesDropCommand.java
Removed:
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputAddCommand.java
Modified:
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropPolicy.java
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropRequest.java
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputTransferDropTargetListener.java
   trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/package-info.java
Log:
added drop support for resources, refactored package.

Added: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorCommand.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorCommand.java	                        (rev 0)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorCommand.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Jens von Pilgrim and others.
+ * 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:
+ *    Jens von Pilgrim - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.gef3d.ext.multieditor.dnd;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef3d.ext.multieditor.IMultiEditor;
+
+/**
+ * Base class for drop commands for dropping something onto a multi editor.
+ * 
+ * @author Jens von Pilgrim (developer@xxxxxxxxx)
+ * @version $Revision$
+ * @since Jun 11, 2011
+ */
+public class AbstractDropOnMultiEditorCommand extends Command {
+
+	private IMultiEditor multiEditor;
+
+	private Point location;
+
+	/**
+	 * @param i_multiEditor must not be null
+	 * @param i_location may be null
+	 */
+	public AbstractDropOnMultiEditorCommand(IMultiEditor i_multiEditor, Point i_location) {
+		if (i_multiEditor == null) // parameter precondition
+			throw new NullPointerException("i_multiEditor must not be null");
+
+		multiEditor = i_multiEditor;
+		location = i_location;
+	}
+
+	/**
+	 * Getter for multi editor property, property is immutable and set in
+	 * constructor.
+	 * 
+	 * @return the multiEditor
+	 */
+	protected IMultiEditor getMultiEditor() {
+		return multiEditor;
+	}
+
+	/**
+	 * Getter for location property, property is immutable and set in
+	 * constructor.
+	 * 
+	 * @return the location, may be null
+	 */
+	protected Point getLocation() {
+		return location;
+	}
+
+	/**
+	 * Always returns false, as drop command usually lead to opening an editor
+	 * and this cannot be undone yet.
+	 * 
+	 * @see org.eclipse.gef.commands.Command#canUndo()
+	 */
+	@Override
+	public boolean canUndo() {
+		return false;
+	}
+
+}


Property changes on: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorCommand.java
___________________________________________________________________
Added: svn:keywords
   + Date Revision Author HeadURL Id

Added: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorPolicy.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorPolicy.java	                        (rev 0)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorPolicy.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Jens von Pilgrim and others.
+ * 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:
+ *    Jens von Pilgrim - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.gef3d.ext.multieditor.dnd;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.editpolicies.AbstractEditPolicy;
+
+/**
+ * AbstractDropOnMultiEditorPolicy There should really be more documentation here.
+ * 
+ * @author Jens von Pilgrim (developer@xxxxxxxxx)
+ * @version $Revision$
+ * @since Jun 11, 2011
+ */
+public class AbstractDropOnMultiEditorPolicy extends AbstractEditPolicy {
+
+	/**
+	 * {@inheritDoc}.
+	 * <p>
+	 * If the given request is an instance of
+	 * {@link AbstractDropOnMultiEditorRequest}, the host of this policy is
+	 * returned as target edit part.
+	 * 
+	 * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#getTargetEditPart(org.eclipse.gef.Request)
+	 */
+	@Override
+	public EditPart getTargetEditPart(Request i_request) {
+		if (i_request instanceof AbstractDropOnMultiEditorRequest) {
+			return this.getHost();
+		}
+		return super.getTargetEditPart(i_request);
+	}
+
+}


Property changes on: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorPolicy.java
___________________________________________________________________
Added: svn:keywords
   + Date Revision Author HeadURL Id

Added: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorRequest.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorRequest.java	                        (rev 0)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorRequest.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Jens von Pilgrim and others.
+ * 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:
+ *    Jens von Pilgrim - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.gef3d.ext.multieditor.dnd;
+
+import org.eclipse.gef.requests.DropRequest;
+import org.eclipse.gef.requests.LocationRequest;
+import org.eclipse.gef3d.ext.multieditor.IMultiEditor;
+import org.eclipse.ui.IEditorInput;
+
+/**
+ * Base class for requests indicating a drop onto a multi editor, e.g., for
+ * opening new files in the 3D scene.
+ * 
+ * @author Jens von Pilgrim (developer@xxxxxxxxx)
+ * @version $Revision$
+ * @since Jun 11, 2011
+ */
+public abstract class AbstractDropOnMultiEditorRequest extends LocationRequest
+		implements DropRequest {
+
+	/**
+	 * The multi editor, set in constructor, get via getter.
+	 */
+	private IMultiEditor multiEditor;
+
+	/**
+	 * @param i_multiEditor must not be null
+	 */
+	public AbstractDropOnMultiEditorRequest(IMultiEditor i_multiEditor) {
+		if (i_multiEditor == null) // parameter precondition
+			throw new NullPointerException("i_multiEditor must not be null");
+
+		multiEditor = i_multiEditor;
+	}
+
+	/**
+	 * @param i_type
+	 * @param i_multiEditor must not be null
+	 */
+	public AbstractDropOnMultiEditorRequest(IMultiEditor i_multiEditor,
+			Object i_type) {
+		super(i_type);
+		if (i_multiEditor == null) // parameter precondition
+			throw new NullPointerException("i_multiEditor must not be null");
+
+		multiEditor = i_multiEditor;
+	}
+
+	/**
+	 * Returns the multi editor in which context this request has been created,
+	 * that is on which the {@link IEditorInput} was been dropped. This property
+	 * is immutable and set in constructor.
+	 * 
+	 * @return the dropableMultiEditor
+	 */
+	public IMultiEditor getMultiEditor() {
+		return multiEditor;
+	}
+
+}


Property changes on: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorRequest.java
___________________________________________________________________
Added: svn:keywords
   + Date Revision Author HeadURL Id

Added: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorTargetListener.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorTargetListener.java	                        (rev 0)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorTargetListener.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Jens von Pilgrim and others.
+ * 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:
+ *    Jens von Pilgrim - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.gef3d.ext.multieditor.dnd;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.dnd.AbstractTransferDropTargetListener;
+import org.eclipse.gef.requests.LocationRequest;
+import org.eclipse.gef.ui.parts.GraphicalEditor;
+import org.eclipse.gef3d.ext.multieditor.IMultiEditor;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.Transfer;
+
+/**
+ * Base listener implementation of listeners attached to a multi editor. This
+ * base class can be used for listeners handling drag and drop of a multi
+ * editor, in which the content or elements visualized (and edited) in the
+ * editor are added to the editor by drag and drop gestures.
+ * 
+ * @author Jens von Pilgrim (developer@xxxxxxxxx)
+ * @version $Revision$
+ * @since Jun 11, 2011
+ */
+public abstract class AbstractDropOnMultiEditorTargetListener extends
+		AbstractTransferDropTargetListener {
+
+	/**
+	 * The multi editor associated with this listener. The editor is set in the
+	 * constructor and must not be change.
+	 */
+	private IMultiEditor multiEditor;
+
+	/**
+	 * Constructs this listener and sets the multi editor, the transfer type,
+	 * and the graphical viewer. The viewer is retrieved by calling
+	 * {@link IAdaptable#getAdapter(Class)} of the multi editor with type
+	 * {@link GraphicalViewer}; all editors derived from {@link GraphicalEditor}
+	 * support this adapter type.
+	 * 
+	 * @param i_multiEditor the multi editor
+	 * @param i_xfer the transfer type, must not be null
+	 */
+	public AbstractDropOnMultiEditorTargetListener(IMultiEditor i_multiEditor,
+			Transfer i_xfer) {
+		super(
+			(GraphicalViewer) i_multiEditor.getAdapter(GraphicalViewer.class),
+			i_xfer);
+		if (getViewer() == null) {
+			throw new NullPointerException(
+				"Editor's viewer (retrieved via getAdapter(GraphicalViewer.class)) must not be null.");
+		}
+		multiEditor = i_multiEditor;
+	}
+
+	/**
+	 * @return the multiEditor
+	 */
+	public IMultiEditor getMultiEditor() {
+		return multiEditor;
+	}
+
+	/**
+	 * {@inheritDoc}. Default implementation for multi editor related listeners
+	 * is to set the location of the request. Of course, this is only possible
+	 * if the request is of type {@link LocationRequest}, as this request
+	 * provides a location property.
+	 * 
+	 * @see org.eclipse.gef.dnd.AbstractTransferDropTargetListener#updateTargetRequest()
+	 */
+	@Override
+	protected void updateTargetRequest() {
+
+		Request request = getTargetRequest();
+		if (request instanceof LocationRequest) {
+			DropTargetEvent event = getCurrentEvent();
+			if (event != null)
+				((LocationRequest) request).setLocation(new Point(event.x,
+					event.y));
+		}
+	}
+
+	/**
+	 * Returns drag and drop operation type, if event is not accepted, 0 (
+	 * {@link DND#DROP_NONE}) is returned.
+	 * 
+	 * @param i_event
+	 * @return
+	 */
+	protected abstract int acceptEvent(DropTargetEvent i_event);
+
+	/**
+	 * Retrieves the event data and set appropriate (target) request properties.
+	 * 
+	 * @param i_event, must not be null
+	 * @return returns true if event data were successfully evaluated
+	 */
+	protected abstract boolean retrieveEventData(DropTargetEvent i_event);
+
+	/**
+	 * {@inheritDoc}
+	 * 
+	 * @see org.eclipse.gef.dnd.AbstractTransferDropTargetListener#handleDragOver()
+	 */
+	@Override
+	protected void handleDragOver() {
+		DropTargetEvent event = getCurrentEvent();
+		if (event != null) {
+			event.detail = acceptEvent(event);
+		}
+
+		super.handleDragOver();
+	}
+
+	/**
+	 * {@inheritDoc}.
+	 * 
+	 * @see org.eclipse.gef.dnd.AbstractTransferDropTargetListener#handleDrop()
+	 */
+	@Override
+	protected void handleDrop() {
+
+		DropTargetEvent event = getCurrentEvent();
+		if (event != null) {
+			event.detail = acceptEvent(event);
+			if (event.detail == DND.DROP_NONE) {
+				return;
+			}
+
+			if (!retrieveEventData(event)) {
+				event.detail = DND.DROP_NONE;
+				return;
+			}
+		}
+		try {
+			super.handleDrop();
+		} catch (Exception ex) {
+			// TODO Implement catch block for Exception
+			ex.printStackTrace();
+		}
+	}
+
+}


Property changes on: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/AbstractDropOnMultiEditorTargetListener.java
___________________________________________________________________
Added: svn:keywords
   + Date Revision Author HeadURL Id

Deleted: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputAddCommand.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputAddCommand.java	2011-06-10 14:59:13 UTC (rev 580)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputAddCommand.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -1,102 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Jens von Pilgrim and others.
- * 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:
- *    Jens von Pilgrim - initial API and implementation
- ******************************************************************************/
-package org.eclipse.gef3d.ext.multieditor.dnd;
-
-import java.util.List;
-import java.util.logging.Logger;
-
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef3d.ext.multieditor.IMultiEditor;
-import org.eclipse.ui.IEditorInput;
-
-/**
- * This command causes a multi editor to open a new editor input. This command
- * cannot be undone.
- *
- * @author 	Jens von Pilgrim
- * @version	$Revision$
- * @since 	Apr 15, 2009
- */
-public class EditorInputAddCommand extends Command {
-	/**
-	 * Logger for this class
-	 */
-	private static final Logger log = Logger.getLogger(EditorInputAddCommand.class.getName());
-
-	List<IEditorInput> editorInputs;
-
-	private IMultiEditor multiEditor;
-	
-	/**
-	 * @param i_request
-	 */
-	public EditorInputAddCommand() {
-	}
-	
-	
-
-	/** 
-	 * Returns true if multi editor is set and at least one editor input
-	 * is set. This is usually the case when this command has been created by
-	 * the {@link EditorInputDropPolicy}.
-	 * @see org.eclipse.gef.commands.Command#canExecute()
-	 */
-	@Override
-	public boolean canExecute() {
-		return multiEditor!=null && editorInputs!=null && editorInputs.size()>0;
-	}
-
-
-
-	/** 
-	 * Always returns false, this command cannot be undone.
-	 * @see org.eclipse.gef.commands.Command#canUndo()
-	 */
-	@Override
-	public boolean canUndo() {
-		return false;
-	}
-
-
-
-	/** 
-	 * {@inheritDoc}
-	 * @see org.eclipse.gef.commands.Command#execute()
-	 */
-	@Override
-	public void execute() {
-		if (editorInputs==null) return;
-		for (IEditorInput editorInput: editorInputs) {
-			multiEditor.addEditor(editorInput);
-		}
-		
-		
-	}
-
-	/**
-	 * @param i_editorInputs
-	 */
-	public void setEditorInputs(List<IEditorInput> i_editorInputs) {
-		editorInputs = i_editorInputs;
-		
-	}
-
-	/**
-	 * @param i_dropableMultiEditor
-	 */
-	public void setMultiEditor(IMultiEditor i_dropableMultiEditor) {
-		multiEditor = i_dropableMultiEditor;
-		
-	}
-	
-	
-
-}

Copied: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropCommand.java (from rev 522, trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputAddCommand.java)
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropCommand.java	                        (rev 0)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropCommand.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Jens von Pilgrim and others.
+ * 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:
+ *    Jens von Pilgrim - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.gef3d.ext.multieditor.dnd;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef3d.ext.multieditor.IMultiEditor;
+import org.eclipse.ui.IEditorInput;
+
+/**
+ * This command causes a multi editor to open a new editor input. This command
+ * cannot be undone.
+ * 
+ * @author Jens von Pilgrim
+ * @version $Revision$
+ * @since Apr 15, 2009
+ */
+public class EditorInputDropCommand extends AbstractDropOnMultiEditorCommand {
+	/**
+	 * Logger for this class
+	 */
+	@SuppressWarnings("unused")
+	private static final Logger log = Logger
+		.getLogger(EditorInputDropCommand.class.getName());
+
+	List<IEditorInput> editorInputs;
+
+	/**
+	 * @param i_multiEditor must not be null
+	 * @param i_location may be null
+	 * @param i_editorInputs must not be null
+	 */
+	public EditorInputDropCommand(IMultiEditor i_multiEditor, Point i_location,
+			List<IEditorInput> i_editorInputs) {
+		super(i_multiEditor, i_location);
+		if (i_editorInputs == null) // parameter precondition
+			throw new NullPointerException("i_editorInputs must not be null");
+
+		editorInputs = i_editorInputs;
+	}
+
+	/**
+	 * Getter for editor inputs property, property is immutable and set in
+	 * constructor.
+	 * 
+	 * @return the editorInputs
+	 */
+	protected List<IEditorInput> getEditorInputs() {
+		return editorInputs;
+	}
+
+	/**
+	 * Returns true if at least one editor input is accepted by the editor.
+	 * 
+	 * @see org.eclipse.gef.commands.Command#canExecute()
+	 */
+	@Override
+	public boolean canExecute() {
+		for (IEditorInput editorInput : editorInputs) {
+			if (getMultiEditor().acceptsInput(editorInput))
+				return true;
+		}
+		return false;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 * 
+	 * @see org.eclipse.gef.commands.Command#execute()
+	 */
+	@Override
+	public void execute() {
+		for (IEditorInput editorInput : editorInputs) {
+			if (getMultiEditor().acceptsInput(editorInput))
+				getMultiEditor().addEditor(editorInput);
+		}
+	}
+
+}

Modified: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropPolicy.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropPolicy.java	2011-06-10 14:59:13 UTC (rev 580)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropPolicy.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -10,16 +10,11 @@
  ******************************************************************************/
 package org.eclipse.gef3d.ext.multieditor.dnd;
 
-import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalViewer;
 import org.eclipse.gef.Request;
 import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.editpolicies.AbstractEditPolicy;
 import org.eclipse.gef.ui.parts.GraphicalEditor;
-import org.eclipse.gef3d.ext.multieditor.MultiEditorModelContainer;
 import org.eclipse.gef3d.ext.multieditor.MultiEditorModelContainerEditPart;
 import org.eclipse.ui.IEditorInput;
 
@@ -51,47 +46,46 @@
  * @version $Revision$
  * @since Apr 15, 2009
  */
-public class EditorInputDropPolicy extends AbstractEditPolicy {
+public class EditorInputDropPolicy extends AbstractDropOnMultiEditorPolicy {
 	/**
 	 * Logger for this class
 	 */
-	private static final Logger log = Logger.getLogger(EditorInputDropPolicy.class.getName());
+	@SuppressWarnings("unused")
+	private static final Logger log = Logger
+		.getLogger(EditorInputDropPolicy.class.getName());
 
+	/**
+	 * Role name used to install this policy.
+	 */
 	public static final Object EDITOR_INPUT_ROLE = "EDITOR_INPUT_ROLE";
 
 	/**
-	 * {@inheritDoc}
+	 * Returns true if the request is an {@link EditorInputDropRequest}.
 	 * 
-	 * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#getTargetEditPart(org.eclipse.gef.Request)
+	 * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#understandsRequest(org.eclipse.gef.Request)
 	 */
 	@Override
-	public EditPart getTargetEditPart(Request i_request) {
-//		if (log.isLoggable(Level.INFO)) {
-//			log.info("getTargetEditPart - i_req=" + i_request); //$NON-NLS-1$
-//		}
-		if (i_request instanceof EditorInputDropRequest) {
-			return this.getHost();
-		}
-		return super.getTargetEditPart(i_request);
+	public boolean understandsRequest(Request i_req) {
+		return i_req instanceof EditorInputDropRequest;
 	}
 
 	/**
-	 * if the request is an {@link EditorInputDropRequest}, a new
-	 * {@link EditorInputAddCommand} is created.
+	 * If the request is an {@link EditorInputDropRequest}, a new
+	 * {@link EditorInputDropCommand} is created.
 	 * 
 	 * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#getCommand(org.eclipse.gef.Request)
 	 */
 	@Override
 	public Command getCommand(Request i_request) {
-//		if (log.isLoggable(Level.INFO)) {
-//			log.info("getCommand - i_req=" + i_request); //$NON-NLS-1$
-//		}
+		// if (log.isLoggable(Level.INFO)) {
+		//			log.info("getCommand - i_req=" + i_request); //$NON-NLS-1$
+		// }
 		if (i_request instanceof EditorInputDropRequest) {
 			EditorInputDropRequest dor = (EditorInputDropRequest) i_request;
 
-			EditorInputAddCommand cmd = new EditorInputAddCommand();
-			cmd.setEditorInputs(dor.getEditorInputs());
-			cmd.setMultiEditor(dor.getMultiEditor());
+			EditorInputDropCommand cmd =
+				new EditorInputDropCommand(dor.getMultiEditor(),
+					dor.getLocation(), dor.getEditorInputs());
 
 			return cmd;
 
@@ -100,19 +94,4 @@
 		return super.getCommand(i_request);
 	}
 
-	/** 
-	 * {@inheritDoc}
-	 * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#understandsRequest(org.eclipse.gef.Request)
-	 */
-	@Override
-	public boolean understandsRequest(Request i_req) {
-//		if (log.isLoggable(Level.INFO)) {
-//			log.info("understandsRequest - i_req=" + i_req); //$NON-NLS-1$
-//		}
-
-		return super.understandsRequest(i_req);
-	}
-	
-	
-
 }

Modified: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropRequest.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropRequest.java	2011-06-10 14:59:13 UTC (rev 580)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputDropRequest.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -12,9 +12,6 @@
 
 import java.util.List;
 
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.requests.DropRequest;
 import org.eclipse.gef3d.ext.multieditor.IMultiEditor;
 import org.eclipse.ui.IEditorInput;
 
@@ -29,39 +26,37 @@
  * @version $Revision$
  * @since Apr 15, 2009
  */
-public class EditorInputDropRequest extends Request implements DropRequest {
+public class EditorInputDropRequest extends AbstractDropOnMultiEditorRequest {
 
-	protected Point location;
-
+	/**
+	 * The editor inputs, get/set via getter/setter.
+	 */
 	protected List<IEditorInput> editorInputs;
 
-	protected IMultiEditor multiEditor;
-
 	public static String UNDEF_TYPE = "UNDEF_TYPE";
-	
+
 	/**
-	 * Consructs this request and set type to {@link #UNDEF_TYPE}.
+	 * Constructs this request and set type to {@link #UNDEF_TYPE}.
 	 */
-	public EditorInputDropRequest() {
-		this(UNDEF_TYPE);
+	public EditorInputDropRequest(IMultiEditor i_multiEditor) {
+		this(i_multiEditor, UNDEF_TYPE);
 	}
 
 	/**
-	 * Constructs this request and set s type.
-	 * The type should not be null since some policies may throw
-	 * a {@link NullPointerException} in that case.
+	 * Constructs this request and set s type. The type should not be null since
+	 * some policies may throw a {@link NullPointerException} in that case.
 	 * 
 	 * @param type type of this request, should not be null.
 	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=285741
 	 */
-	public EditorInputDropRequest(Object type) {
-		super(type);
+	public EditorInputDropRequest(IMultiEditor i_multiEditor, Object type) {
+		super(i_multiEditor, type);
 	}
 
 	/**
-	 * Returns the {@link IEditorInput}s which were dropped onto the
-	 * editor, i.e. the figure. This value is set after the mouse has been
-	 * released and the drop actually occurred.
+	 * Returns the {@link IEditorInput}s which were dropped onto the editor,
+	 * i.e. the figure. This value is set after the mouse has been released and
+	 * the drop actually occurred.
 	 * 
 	 * @return the editorInputs
 	 */
@@ -80,63 +75,23 @@
 	}
 
 	/**
-	 * Returns the multi editor in which context this request has been created,
-	 * that is on which the {@link IEditorInput} was been dropped.
-	 * 
-	 * @return the dropableMultiEditor
-	 */
-	public IMultiEditor getMultiEditor() {
-		return multiEditor;
-	}
-
-	/**
-	 * Called by {@link EditorInputTransferDropTargetListener} when the request
-	 * is created.
-	 * 
-	 * @param i_multiEditor the dropableMultiEditor to set
-	 */
-	protected void setMultiEditor(IMultiEditor i_multiEditor) {
-		multiEditor = i_multiEditor;
-	}
-
-	/**
 	 * {@inheritDoc}
 	 * 
-	 * @see org.eclipse.gef.requests.DropRequest#getLocation()
-	 */
-	public Point getLocation() {
-		return location;
-	}
-
-	/**
-	 * Called by {@link EditorInputTransferDropTargetListener} when the request
-	 * is created or updated.
-	 * 
-	 * @param i_location the location to set
-	 */
-	protected void setLocation(Point i_location) {
-		location = i_location;
-	}
-
-	/** 
-	 * {@inheritDoc}
 	 * @see java.lang.Object#toString()
 	 */
 	@Override
 	public String toString() {
 		StringBuilder result = new StringBuilder();
 		result.append("EditorInputRequest");
-		if (location!=null) {
-			result.append(" at ").append(location.toString());
+		if (getLocation() != null) {
+			result.append(" at ").append(getLocation().toString());
 		}
-		if (editorInputs!=null) {
+		if (editorInputs != null) {
 			result.append(" with input ").append(editorInputs.toString());
 		} else {
 			result.append(" w/o input information");
 		}
 		return result.toString();
 	}
-	
-	
 
 }

Modified: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputTransferDropTargetListener.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputTransferDropTargetListener.java	2011-06-10 14:59:13 UTC (rev 580)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/EditorInputTransferDropTargetListener.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -11,15 +11,11 @@
 package org.eclipse.gef3d.ext.multieditor.dnd;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
+import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.gef.EditPartViewer;
 import org.eclipse.gef.Request;
-import org.eclipse.gef.dnd.AbstractTransferDropTargetListener;
 import org.eclipse.gef.ui.parts.GraphicalEditor;
 import org.eclipse.gef3d.ext.multieditor.IMultiEditor;
 import org.eclipse.swt.dnd.DND;
@@ -30,152 +26,105 @@
 
 /**
  * Drop target listener to be used by a multi editor to enable opening new
- * diagrams (or models) in the editor by simply droping the editor input onto
+ * diagrams (or models) in the editor by simply dropping the editor input onto
  * the 3D scene. This listener is to be added to the viewer during
  * configuration, i.e. in {@link GraphicalEditor#configureGraphicalViewer()}
  * just like that:
  * <p>
  * <code><pre>
  * getGraphicalViewer().addDropTargetListener(
- * 		new EditorInputTransferDropTargetListener(this,
- * 		getGraphicalViewer()));
+ * 		new EditorInputTransferDropTargetListener(this));
  * </pre></code>
  * </p>
  * 
  * @author Jens von Pilgrim
  * @version $Revision$
  * @since Apr 15, 2009
+ * @see ResourceTransferDropTargetListener
  */
 public class EditorInputTransferDropTargetListener extends
-		AbstractTransferDropTargetListener {
-	/**
-	 * Logger for this class
-	 */
-	private static final Logger log =
-		Logger.getLogger(EditorInputTransferDropTargetListener.class.getName());
+		AbstractDropOnMultiEditorTargetListener {
 
-	private IMultiEditor graphicalEditor;
-
 	/**
-	 * @param i_graphicalEditor
-	 * @param i_viewer
+	 * @param i_multiEditor, viewer is retrieved via
+	 *            {@link IAdaptable#getAdapter(Class)}
 	 */
-	public EditorInputTransferDropTargetListener(
-			IMultiEditor i_graphicalEditor, EditPartViewer i_viewer) {
-		super(i_viewer, EditorInputTransfer.getInstance());
-		graphicalEditor = i_graphicalEditor;
+	public EditorInputTransferDropTargetListener(IMultiEditor i_multiEditor) {
+		super(i_multiEditor, EditorInputTransfer.getInstance());
 	}
 
 	/**
-	 * {@inheritDoc}
+	 * {@inheritDoc}. Creates an {@link EditorInputDropRequest} and sets
+	 * location of event if possible.
 	 * 
-	 * @see org.eclipse.gef.dnd.AbstractTransferDropTargetListener#updateTargetRequest()
+	 * @see org.eclipse.gef.dnd.AbstractTransferDropTargetListener#createTargetRequest()
 	 */
 	@Override
-	protected void updateTargetRequest() {
+	protected Request createTargetRequest() {
 		EditorInputDropRequest request =
-			(EditorInputDropRequest) getTargetRequest();
+			new EditorInputDropRequest(getMultiEditor());
 		DropTargetEvent event = getCurrentEvent();
-		request.setLocation(new Point(event.x, event.y));
+		if (event != null) {
+			request.setLocation(new Point(event.x, event.y));
+		}
+		return request;
 	}
 
 	/**
 	 * {@inheritDoc}
 	 * 
-	 * @see org.eclipse.gef.dnd.AbstractTransferDropTargetListener#createTargetRequest()
+	 * @see org.eclipse.gef3d.ext.multieditor.dnd.AbstractDropOnMultiEditorTargetListener#acceptEvent(org.eclipse.swt.dnd.DropTargetEvent)
 	 */
 	@Override
-	protected Request createTargetRequest() {
-		EditorInputDropRequest request = new EditorInputDropRequest();
-		DropTargetEvent event = getCurrentEvent();
-		request.setLocation(new Point(event.x, event.y));
-		request.setMultiEditor(graphicalEditor);
-		return request;
-	}
+	protected int acceptEvent(DropTargetEvent i_event) {
 
-	private boolean editorAccepts(DropTargetEvent i_event) {
-
 		if (i_event.data instanceof EditorInputTransfer.EditorInputData[]) {
 			EditorInputTransfer.EditorInputData[] editorInputsData =
 				(EditorInputData[]) i_event.data;
 
 			for (EditorInputTransfer.EditorInputData data : editorInputsData)
-				if (!graphicalEditor.acceptsInput(data.input))
-					return false;
-		} else
-			return false;
+				if (!getMultiEditor().acceptsInput(data.input)) {
+					return DND.DROP_NONE;
+				}
+		} else {
+			return DND.DROP_NONE;
+		}
 
-		return true;
+		return DND.DROP_COPY;
 	}
 
 	/**
-	 * {@inheritDoc}
+	 * {@inheritDoc}.
+	 * <p>
+	 * Returns true if at least one editor input could be retrieved from the
+	 * given event.
 	 * 
-	 * @see org.eclipse.gef.dnd.AbstractTransferDropTargetListener#handleDragOver()
+	 * @see org.eclipse.gef3d.ext.multieditor.dnd.AbstractDropOnMultiEditorTargetListener#retrieveEventData(org.eclipse.swt.dnd.DropTargetEvent)
 	 */
 	@Override
-	protected void handleDragOver() {
-		// if (log.isLoggable(Level.INFO)) {
-		//			log.info("handleDragOver"); //$NON-NLS-1$
-		// }
-
-		DropTargetEvent event = getCurrentEvent();
-		event.detail = DND.DROP_COPY;
-
-		super.handleDragOver();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 * 
-	 * @see org.eclipse.gef.dnd.AbstractTransferDropTargetListener#handleDrop()
-	 */
-	@Override
-	protected void handleDrop() {
-		if (log.isLoggable(Level.INFO)) {
-			log.info("handleDrop"); //$NON-NLS-1$
-		}
-
-		DropTargetEvent event = getCurrentEvent();
-
-		boolean accept = editorAccepts(event);
-		event.detail = accept ? DND.DROP_COPY : DND.DROP_NONE;
-
-		if (!accept)
-			return;
-
+	protected boolean retrieveEventData(DropTargetEvent i_event) {
 		EditorInputDropRequest request =
 			(EditorInputDropRequest) getTargetRequest();
 
-		List<IEditorInput> editorInputs = retrieveEditorInput(event);
-		if (!editorInputs.isEmpty())
-			request.setEditorInputs(editorInputs);
+		List<IEditorInput> editorInputs = null;
 
-		try {
-			super.handleDrop();
-		} catch (Exception ex) {
-			// TODO Implement catch block for Exception
-			ex.printStackTrace();
-		}
-
-	}
-
-	/**
-	 * @param event
-	 */
-	private List<IEditorInput> retrieveEditorInput(DropTargetEvent event) {
-		if (event.data instanceof EditorInputTransfer.EditorInputData[]) {
-			List<IEditorInput> editorInputs = new ArrayList<IEditorInput>();
+		if (i_event.data instanceof EditorInputTransfer.EditorInputData[]) {
+			editorInputs = new ArrayList<IEditorInput>();
 			EditorInputTransfer.EditorInputData[] editorInputsData =
-				(EditorInputData[]) event.data;
+				(EditorInputData[]) i_event.data;
 			for (EditorInputTransfer.EditorInputData data : editorInputsData) {
 				editorInputs.add(data.input);
 
 			}
-			return editorInputs;
 		}
-		return Collections.emptyList();
+
+		if (editorInputs == null || editorInputs.isEmpty()) {
+			return false;
+		}
+
+		request.setEditorInputs(editorInputs);
+		return true;
+
 	}
 
-	
 }

Added: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceDropPolicy.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceDropPolicy.java	                        (rev 0)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceDropPolicy.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Jens von Pilgrim and others.
+ * 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:
+ *    Jens von Pilgrim - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.gef3d.ext.multieditor.dnd;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * Enables native drop of {@link IResource}s ointo the 3D scene.
+ * 
+ * @author Jens von Pilgrim (developer@xxxxxxxxx)
+ * @version $Revision$
+ * @since Jun 11, 2011
+ */
+public class ResourceDropPolicy extends AbstractDropOnMultiEditorPolicy {
+
+	/**
+	 * Role name used to install this policy.
+	 */
+	public static final Object RESOURCE_DROP_ROLE = "RESOURCE_DROP_ROLE";
+
+	/**
+	 * Returns true if the request is an {@link ResourceDropRequest}.
+	 * 
+	 * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#understandsRequest(org.eclipse.gef.Request)
+	 */
+	@Override
+	public boolean understandsRequest(Request i_req) {
+		return i_req instanceof ResourceDropRequest;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 * 
+	 * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#getCommand(org.eclipse.gef.Request)
+	 */
+	@Override
+	public Command getCommand(Request i_request) {
+
+		if (i_request instanceof ResourceDropRequest) {
+			ResourceDropRequest rdr = (ResourceDropRequest) i_request;
+
+			ResourcesDropCommand cmd =
+				new ResourcesDropCommand(rdr.getMultiEditor(),
+					rdr.getLocation(), rdr.getResources());
+			
+			if (cmd.canExecute())
+				return cmd;
+
+		}
+
+		return super.getCommand(i_request);
+	}
+}


Property changes on: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceDropPolicy.java
___________________________________________________________________
Added: svn:keywords
   + Date Revision Author HeadURL Id

Added: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceDropRequest.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceDropRequest.java	                        (rev 0)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceDropRequest.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Jens von Pilgrim and others.
+ * 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:
+ *    Jens von Pilgrim - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.gef3d.ext.multieditor.dnd;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.gef3d.ext.multieditor.IMultiEditor;
+
+/**
+ * ResourceDropRequest There should really be more documentation here.
+ * 
+ * @author Jens von Pilgrim (developer@xxxxxxxxx)
+ * @version $Revision$
+ * @since Jun 11, 2011
+ */
+public class ResourceDropRequest extends AbstractDropOnMultiEditorRequest {
+
+	/**
+	 * The resources dropped onto the multi editor, get/set via getter/setter.
+	 */
+	List<IResource> resources;
+
+	/**
+	 * @param i_multiEditor
+	 */
+	public ResourceDropRequest(IMultiEditor i_multiEditor) {
+		super(i_multiEditor);
+	}
+
+	/**
+	 * @return the resources
+	 */
+	public List<IResource> getResources() {
+		return resources;
+	}
+
+	/**
+	 * Called by {@link ResourceTransferDropTargetListener} when the drop
+	 * actually occurred (that is after the mouse button has been released).
+	 * 
+	 * @param i_resources the resources to set
+	 */
+	public void setResources(List<IResource> i_resources) {
+		resources = i_resources;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 * 
+	 * @see java.lang.Object#toString()
+	 */
+	@Override
+	public String toString() {
+		StringBuilder result = new StringBuilder();
+		result.append("ResourceDropRequest");
+		if (getLocation() != null) {
+			result.append(" at ").append(getLocation().toString());
+		}
+		if (resources != null) {
+			result.append(" with input ").append(resources.toString());
+		} else {
+			result.append(" w/o resource information");
+		}
+		return result.toString();
+	}
+
+}


Property changes on: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceDropRequest.java
___________________________________________________________________
Added: svn:keywords
   + Date Revision Author HeadURL Id

Added: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceTransferDropTargetListener.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceTransferDropTargetListener.java	                        (rev 0)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceTransferDropTargetListener.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -0,0 +1,110 @@
+package org.eclipse.gef3d.ext.multieditor.dnd;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.logging.Logger;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.ui.parts.GraphicalEditor;
+import org.eclipse.gef3d.ext.multieditor.IMultiEditor;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.ui.part.ResourceTransfer;
+
+/**
+ * Drop target listener to be used by a multi editor to enable opening new
+ * diagrams (or models) in the editor by simply dropping a resource onto the 3D
+ * scene. This listener is to be added to the viewer during configuration, i.e.
+ * in {@link GraphicalEditor#configureGraphicalViewer()} just like that:
+ * <p>
+ * <code><pre>
+ * getGraphicalViewer().addDropTargetListener(
+ * 		new ResourceTransferDropTargetListener(this));
+ * </pre></code>
+ * </p>
+ * 
+ * @author Jens von Pilgrim (developer@xxxxxxxxx)
+ * @version $Revision$
+ * @since Jun 11, 2011
+ * @see EditorInputTransferDropTargetListener
+ */
+public class ResourceTransferDropTargetListener extends
+		AbstractDropOnMultiEditorTargetListener {
+	/**
+	 * Logger for this class
+	 */
+	// @SuppressWarnings("unused") //$NON-NLS-1$
+	private static final Logger log = Logger.getLogger(ResourceTransferDropTargetListener.class.getName());
+
+	/**
+	 * @param i_multiEditor, viewer is retrieved via
+	 *            {@link IAdaptable#getAdapter(Class)}
+	 */
+	public ResourceTransferDropTargetListener(IMultiEditor i_multiEditor) {
+		super(i_multiEditor, ResourceTransfer.getInstance());
+	}
+
+	/**
+	 * {@inheritDoc}. Creates an {@link ResourceDropRequest} and sets location
+	 * of event if possible.
+	 * 
+	 * @see org.eclipse.gef.dnd.AbstractTransferDropTargetListener#createTargetRequest()
+	 */
+	@Override
+	protected Request createTargetRequest() {
+		ResourceDropRequest request = new ResourceDropRequest(getMultiEditor());
+		DropTargetEvent event = getCurrentEvent();
+		if (event != null) {
+			request.setLocation(new Point(event.x, event.y));
+		}
+		return request;
+	}
+	
+	/** 
+	 * {@inheritDoc}
+	 * @see org.eclipse.gef3d.ext.multieditor.dnd.AbstractDropOnMultiEditorTargetListener#acceptEvent(org.eclipse.swt.dnd.DropTargetEvent)
+	 */
+	@Override
+	protected int acceptEvent(DropTargetEvent i_event) {
+		
+		TransferData[] transferDatas = i_event.dataTypes;
+		if (transferDatas==null || transferDatas.length==0) {
+			return DND.DROP_NONE;
+		}
+		for (TransferData td: transferDatas) {
+			if (! ResourceTransfer.getInstance().isSupportedType(td)) {
+				return DND.DROP_NONE;
+			}
+		}
+		return DND.DROP_COPY;
+	}
+	
+	/** 
+	 * {@inheritDoc}
+	 * @see org.eclipse.gef3d.ext.multieditor.dnd.AbstractDropOnMultiEditorTargetListener#retrieveEventData(org.eclipse.swt.dnd.DropTargetEvent)
+	 */
+	@Override
+	protected boolean retrieveEventData(DropTargetEvent i_event) {
+		if (! (getTargetRequest() instanceof ResourceDropRequest) ) {
+			log.warning("Wrong request type " + getTargetRequest().getClass());
+			return false;
+		}
+		ResourceDropRequest request = (ResourceDropRequest) getTargetRequest();
+		
+		Object data = i_event.data;
+		
+		if (data instanceof IResource[]) {
+			request.setResources(Arrays.asList((IResource[]) data));
+		} else if (data instanceof IResource) {
+			request.setResources(Collections.singletonList((IResource) data));
+		} else {
+			return false;
+		}
+		return true;
+	}
+
+}
\ No newline at end of file


Property changes on: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourceTransferDropTargetListener.java
___________________________________________________________________
Added: svn:keywords
   + Date Revision Author HeadURL Id

Added: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourcesDropCommand.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourcesDropCommand.java	                        (rev 0)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourcesDropCommand.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Jens von Pilgrim and others.
+ * 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:
+ *    Jens von Pilgrim - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.gef3d.ext.multieditor.dnd;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef3d.ext.multieditor.IMultiEditor;
+import org.eclipse.gef3d.ext.multieditor.ResourceEditorInput;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+
+/**
+ * This command causes a multi editor to open a new editor input based on a
+ * {@link ResourceEditorInput}. This command cannot be undone.
+ * <p>
+ * The dropped resources are encapsulated into either {@link FileEditorInput}
+ * or {@link ResourceEditorInput} objects.
+ * 
+ * @author Jens von Pilgrim (developer@xxxxxxxxx)
+ * @version $Revision$
+ * @since Jun 11, 2011
+ * @see ResourceEditorInput
+ */
+public class ResourcesDropCommand extends AbstractDropOnMultiEditorCommand {
+
+	private List<IResource> resources;
+
+	/**
+	 * @param i_multiEditor must not be null
+	 * @param i_location may be null
+	 * @param i_resources must not be null
+	 */
+	public ResourcesDropCommand(IMultiEditor i_multiEditor, Point i_location,
+			List<IResource> i_resources) {
+		super(i_multiEditor, i_location);
+		if (i_resources == null) // parameter precondition
+			throw new NullPointerException("i_resources must not be null");
+
+		resources = i_resources;
+	}
+
+	/**
+	 * Getter for resources property, property is immutable and set in
+	 * constructor.
+	 * 
+	 * @return the resources
+	 */
+	protected List<IResource> getResources() {
+		return resources;
+	}
+
+	/**
+	 * Returns true if at least one editor input is accepted by the editor.
+	 * 
+	 * @see org.eclipse.gef.commands.Command#canExecute()
+	 */
+	@Override
+	public boolean canExecute() {
+		for (IResource resource : resources) {
+			IEditorInput editorInput =
+				(resource instanceof IFile) ? new FileEditorInput((IFile) resource)
+					: new ResourceEditorInput(resource);
+			if (getMultiEditor().acceptsInput(editorInput))
+				return true;
+		}
+		return false;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 * 
+	 * @see org.eclipse.gef.commands.Command#execute()
+	 */
+	@Override
+	public void execute() {
+		for (IResource resource : resources) {
+			IEditorInput editorInput =
+				(resource instanceof IFile) ? new FileEditorInput((IFile) resource)
+					: new ResourceEditorInput(resource);
+			if (getMultiEditor().acceptsInput(editorInput))
+				getMultiEditor().addEditor(editorInput);
+		}
+	}
+
+}


Property changes on: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/ResourcesDropCommand.java
___________________________________________________________________
Added: svn:keywords
   + Date Revision Author HeadURL Id

Modified: trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/package-info.java
===================================================================
--- trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/package-info.java	2011-06-10 14:59:13 UTC (rev 580)
+++ trunk/org.eclipse.gef3d.ext/src/java/org/eclipse/gef3d/ext/multieditor/dnd/package-info.java	2011-06-11 15:17:05 UTC (rev 581)
@@ -11,18 +11,19 @@
 
 /**
  * Drag-n-drop support for multi editors. The classes provided by this package
- * enable opening new diagrams in a mutli editor by simply droping the file
+ * enable opening new diagrams in a mutli editor by simply dropping the file
  * (from the eclipse package view) onto the 3D scene of the multi editor.
  * Several tasks are necessary to achieve that:
  * <ol> 
- * <li>Install listener, see {@link EditorInputTransferDropTargetListener} on how
- * to do that</li>
- * <li>Install the {@link EditorInputDropPolicy} at the content edit part of the
+ * <li>Install listener, see {@link EditorInputTransferDropTargetListener} and 
+ * {@link org.eclipse.gef3d.ext.multieditor.dnd.ResourceTransferDropTargetListener} 
+ * on how to do that</li>
+ * <li>Install the {@link EditorInputDropPolicy} and/or {@link ResourceDropProlicy} the content edit part of the
  * multi editor, see policy on details</li>
  * <li>The multi editor has to implement the interface 
  * {@link org.eclipse.gef3d.ext.multieditor.IMultiEditor}, this interface
  * is used by the created request and command to pass the 
- * {@link org.eclipse.ui.IEditorInput} to the editor.
+ * editor input or resources to the editor or viewer.
  * </ol>
  *  
  * @see <a href="http://www.eclipse.org/articles/Article-GEF-dnd/GEF-dnd.html";>