Author: estherbin
Date: 2008-08-20 10:34:55 -0400 (Wed, 20 Aug 2008)
New Revision: 9831
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/dnd/VpeDnDEvent.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/dnd/DnDUtil.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java
Log:
Implements JBIDE-2443 issue.
Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/META-INF/MANIFEST.MF 2008-08-20
13:36:48 UTC (rev 9830)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/META-INF/MANIFEST.MF 2008-08-20
14:34:55 UTC (rev 9831)
@@ -113,6 +113,8 @@
org.eclipse.ant.ui,
org.eclipse.core.expressions,
org.eclipse.core.filesystem,
- org.eclipse.wst.html.core
+ org.jboss.tools.vpe.xulrunner,
+ org.eclipse.wst.html.core,
+ org.mozilla.xpcom
Bundle-Version: 2.0.0
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/dnd/DnDUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/dnd/DnDUtil.java 2008-08-20
13:36:48 UTC (rev 9830)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/dnd/DnDUtil.java 2008-08-20
14:34:55 UTC (rev 9831)
@@ -7,61 +7,255 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
+
+
package org.jboss.tools.common.model.ui.dnd;
-import java.util.*;
-import org.jboss.tools.common.model.*;
-import org.jboss.tools.common.meta.action.*;
+import java.util.Properties;
+
+import org.eclipse.swt.events.TypedEvent;
+import org.jboss.tools.common.meta.action.XAction;
+import org.jboss.tools.common.model.XModelException;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.ui.editors.dnd.context.DropContext;
+import org.jboss.tools.common.model.ui.editors.dnd.context.IDNDTextEditor;
+import org.jboss.tools.vpe.xulrunner.XPCOM;
+import org.mozilla.interfaces.nsIComponentManager;
+import org.mozilla.interfaces.nsIDOMEvent;
+import org.mozilla.interfaces.nsIDragService;
+import org.mozilla.interfaces.nsIDragSession;
+import org.mozilla.interfaces.nsIFile;
+import org.mozilla.interfaces.nsIServiceManager;
+import org.mozilla.interfaces.nsISupports;
+import org.mozilla.interfaces.nsITransferable;
+import org.mozilla.xpcom.Mozilla;
+
+
+/**
+ * The Class DnDUtil.
+ */
public class DnDUtil {
-
- public static XAction getEnabledAction(XModelObject object, XModelObject[] targets,
String actionpath) {
- if(object == null) return null;
- XAction action = object.getModelEntity().getActionList().getAction(actionpath);
- if(action == null) return null;
- return (targets == null)
- ? ((!action.isEnabled(object)) ? null : action)
- : ((!action.isEnabled(object, targets)) ? null : action);
- }
-
- public static boolean isCopyEnabled(XModelObject object, XModelObject[] targets) {
- return getEnabledCopyAction(object, targets) != null;
- }
-
- public static XAction getEnabledCopyAction(XModelObject object, XModelObject[] targets)
{
- return getEnabledAction(object, targets, "CopyActions.Copy");
- }
-
- public static boolean copy(XModelObject object, XModelObject[] targets) {
- XAction copy = getEnabledCopyAction(object, targets);
- if(copy == null) return false;
- try {
- Properties p = new Properties();
- p.setProperty("isDrag", "true");
- if(targets == null) {
- copy.executeHandler(object, p);
- } else {
- copy.executeHandler(object, targets, p);
- }
- return true;
- } catch (Exception e) {
- return false;
- }
- }
-
- public static boolean isPasteEnabled(XModelObject object) {
- return getEnabledPasteAction(object) != null;
- }
-
- public static XAction getEnabledPasteAction(XModelObject object) {
- XAction action = getEnabledAction(object, null, "CopyActions.Paste");
- return (action != null) ? action : getEnabledAction(object, null,
"MoveActions.Move");
- }
-
- public static void paste(XModelObject object, Properties properties) throws
XModelException {
- XAction paste = getEnabledPasteAction(object);
- if(paste != null) paste.executeHandler(object, properties);
- }
+ /** The Constant kTextMime. */
+ public static final String kTextMime = "text/plain"; //$NON-NLS-1$
+
+ /** The Constant kUnicodeMime. */
+ public static final String kUnicodeMime = "text/unicode"; //$NON-NLS-1$
+
+ /** The Constant kHTMLMime. */
+ public static final String kHTMLMime = "text/html"; //$NON-NLS-1$
+
+ /** The Constant kAOLMailMime. */
+ public static final String kAOLMailMime = "AOLMAIL"; //$NON-NLS-1$
+
+ /** The Constant kPNGImageMime. */
+ public static final String kPNGImageMime = "image/png"; //$NON-NLS-1$
+
+ /** The Constant kJPEGImageMime. */
+ public static final String kJPEGImageMime = "image/jpg"; //$NON-NLS-1$
+
+ /** The Constant kGIFImageMime. */
+ public static final String kGIFImageMime = "image/gif"; //$NON-NLS-1$
+
+ /** The Constant kFileMime. */
+ public static final String kFileMime = "application/x-moz-file";
//$NON-NLS-1$
+
+ /** The Constant kURLMime. */
+ public static final String kURLMime = "text/x-moz-url"; //$NON-NLS-1$
+
+ /** The Constant kURLDataMime. */
+ public static final String kURLDataMime = "text/x-moz-url-data";
//$NON-NLS-1$
+
+ /** The Constant kURLDescriptionMime. */
+ public static final String kURLDescriptionMime = "text/x-moz-url-desc";
//$NON-NLS-1$
+
+ /** The Constant kNativeImageMime. */
+ public static final String kNativeImageMime =
"application/x-moz-nativeimage"; //$NON-NLS-1$
+
+ /** The Constant kNativeHTMLMime. */
+ public static final String kNativeHTMLMime =
"application/x-moz-nativehtml"; //$NON-NLS-1$
+
+ /** The Constant kFilePromiseURLMime. */
+ public static final String kFilePromiseURLMime =
"application/x-moz-file-promise-url"; //$NON-NLS-1$
+
+ /** The Constant kFilePromiseMime. */
+ public static final String kFilePromiseMime =
"application/x-moz-file-promise"; //$NON-NLS-1$
+
+ /** The Constant kFilePromiseDirectoryMime. */
+ public static final String kFilePromiseDirectoryMime =
"application/x-moz-file-promise-dir"; //$NON-NLS-1$
+
+ /** The Constant FLAVORS. */
+ public static final String[] FLAVORS = { kTextMime, kUnicodeMime, kHTMLMime,
kAOLMailMime, kPNGImageMime, kJPEGImageMime,
+ kGIFImageMime, kFileMime, kURLMime, kURLDataMime, kURLDescriptionMime,
kNativeImageMime, kNativeHTMLMime, kFilePromiseURLMime,
+ kFilePromiseMime, kFilePromiseDirectoryMime };
+
+ /**
+ * Gets the enabled action.
+ *
+ * @param actionpath the actionpath
+ * @param object the object
+ * @param targets the targets
+ *
+ * @return the enabled action
+ */
+ public static XAction getEnabledAction(XModelObject object, XModelObject[] targets,
String actionpath) {
+ if (object == null)
+ return null;
+ XAction action = object.getModelEntity().getActionList().getAction(actionpath);
+ if (action == null)
+ return null;
+ return (targets == null) ? ((!action.isEnabled(object)) ? null : action) :
((!action.isEnabled(object, targets)) ? null : action);
+ }
+
+ /**
+ * Checks if is copy enabled.
+ *
+ * @param object the object
+ * @param targets the targets
+ *
+ * @return true, if is copy enabled
+ */
+ public static boolean isCopyEnabled(XModelObject object, XModelObject[] targets) {
+ return getEnabledCopyAction(object, targets) != null;
+ }
+
+ /**
+ * Gets the enabled copy action.
+ *
+ * @param object the object
+ * @param targets the targets
+ *
+ * @return the enabled copy action
+ */
+ public static XAction getEnabledCopyAction(XModelObject object, XModelObject[]
targets) {
+ return getEnabledAction(object, targets, "CopyActions.Copy");
//$NON-NLS-1$
+ }
+
+ /**
+ * Copy.
+ *
+ * @param object the object
+ * @param targets the targets
+ *
+ * @return true, if copy
+ */
+ public static boolean copy(XModelObject object, XModelObject[] targets) {
+ XAction copy = getEnabledCopyAction(object, targets);
+ if (copy == null)
+ return false;
+ try {
+ Properties p = new Properties();
+ p.setProperty("isDrag", "true"); //$NON-NLS-1$
//$NON-NLS-2$
+ if (targets == null) {
+ copy.executeHandler(object, p);
+ } else {
+ copy.executeHandler(object, targets, p);
+ }
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /**
+ * Checks if is paste enabled.
+ *
+ * @param object the object
+ *
+ * @return true, if is paste enabled
+ */
+ public static boolean isPasteEnabled(XModelObject object) {
+ return getEnabledPasteAction(object) != null;
+ }
+
+ /**
+ * Gets the enabled paste action.
+ *
+ * @param object the object
+ *
+ * @return the enabled paste action
+ */
+ public static XAction getEnabledPasteAction(XModelObject object) {
+ XAction action = getEnabledAction(object, null, "CopyActions.Paste");
//$NON-NLS-1$
+ return (action != null) ? action : getEnabledAction(object, null,
"MoveActions.Move"); //$NON-NLS-1$
+ }
+
+ /**
+ * Paste.
+ *
+ * @param object the object
+ * @param properties the properties
+ *
+ * @throws XModelException the X model exception
+ */
+ public static void paste(XModelObject object, Properties properties) throws
XModelException {
+ XAction paste = getEnabledPasteAction(object);
+ if (paste != null)
+ paste.executeHandler(object, properties);
+ }
+
+ /**
+ * Convert2 vpe dn D event.
+ *
+ * @param event the event
+ *
+ * @return the vpe dn D event
+ */
+ public static VpeDnDEvent convert2VpeDnDEvent(nsIDOMEvent event) {
+ return null;
+
+ }
+
+ /**
+ * Fire dn D event.
+ *
+ * @param dropContext the drop context
+ * @param event the event
+ * @param textEditor the text editor
+ */
+ public static void fireDnDEvent(DropContext dropContext, IDNDTextEditor textEditor,
TypedEvent event) {
+
+ dropContext.runDropCommand(textEditor, event);
+ }
+
+ /**
+ * Gets the dn D file.
+ *
+ * @param event the event
+ *
+ * @return the dn D file
+ */
+ public static nsIFile getDnDFile(nsIDOMEvent event) {
+ nsIFile aFile = null;
+ nsIServiceManager serviceManager = Mozilla.getInstance().getServiceManager();
+ nsIComponentManager componentManager =
Mozilla.getInstance().getComponentManager();
+ nsIDragService dragService = (nsIDragService)
serviceManager.getServiceByContractID("(a)mozilla.org/widget/dragservice;1",
//$NON-NLS-1$
+ nsIDragService.NS_IDRAGSERVICE_IID);
+ final nsIDragSession dragSession = dragService.getCurrentSession();
+
+ final nsITransferable iTransferable = (nsITransferable)
componentManager.createInstanceByContractID(
+ XPCOM.NS_TRANSFERABLE_CONTRACTID, null,
nsITransferable.NS_ITRANSFERABLE_IID);
+
+ for (String flavor1 : FLAVORS) {
+ if (dragSession.isDataFlavorSupported(flavor1)) {
+ iTransferable.addDataFlavor(flavor1);
+ System.out.println("\n->" + flavor1); //$NON-NLS-1$
+ }
+ }
+ String[] aFlavor = { "" }; //$NON-NLS-1$
+ long[] aDataLen = { 0 };
+ nsISupports[] aData = { null };
+
+ dragSession.getData(iTransferable, 0);
+
+ iTransferable.getAnyTransferData(aFlavor, aData, aDataLen);
+ System.out.println("aData[0] className = " +
aData[0].getClass().getName()); //$NON-NLS-1$
+
+
+ aFile = (nsIFile) aData[0].queryInterface(nsIFile.NS_IFILE_IID);
+ return aFile;
+ }
+
}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/dnd/VpeDnDEvent.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/dnd/VpeDnDEvent.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/dnd/VpeDnDEvent.java 2008-08-20
14:34:55 UTC (rev 9831)
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+
+package org.jboss.tools.common.model.ui.dnd;
+
+
+import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.swt.events.TypedEvent;
+
+
+/**
+ * The Class VpeDnDEvent.
+ *
+ * @author Evgenij Stherbin
+ */
+public class VpeDnDEvent extends TypedEvent {
+
+ /** The Constant serialVersionUID. */
+ private static final long serialVersionUID = 4032394561953756746L;
+
+ /** The x-cordinate of the cursor relative to the <code>Display</code>.
*/
+ private int x;
+
+ /** The y-cordinate of the cursor relative to the <code>Display</code>.
*/
+ private int y;
+
+ /** A list of the types of data that the DragSource is capable of providing. The
currentDataType must be a member of this list. */
+ private TransferData[] dataTypes;
+
+ /** The type of data that will be dropped. */
+ public TransferData currentDataType;
+
+ /**
+ * Gets the current data type.
+ *
+ * @return the current data type
+ */
+ public TransferData getCurrentDataType() {
+ return currentDataType;
+ }
+
+ /**
+ * Sets the current data type.
+ *
+ * @param currentDataType the current data type
+ */
+ public void setCurrentDataType(TransferData currentDataType) {
+ this.currentDataType = currentDataType;
+ }
+
+ /**
+ * Gets the data types.
+ *
+ * @return the data types
+ */
+ public TransferData[] getDataTypes() {
+ return dataTypes;
+ }
+
+ /**
+ * Sets the data types.
+ *
+ * @param dataTypes the data types
+ */
+ public void setDataTypes(TransferData[] dataTypes) {
+ this.dataTypes = dataTypes;
+ }
+
+ /**
+ * The Constructor.
+ *
+ * @param source the source
+ */
+ public VpeDnDEvent(Object source) {
+ super(source);
+
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/dnd/VpeDnDEvent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java 2008-08-20
13:36:48 UTC (rev 9830)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/DropUtils.java 2008-08-20
14:34:55 UTC (rev 9831)
@@ -171,7 +171,7 @@
// VpePlugin.reportProblem(e);
ModelUIPlugin.getPluginLog().logError(e);
}
- IFile file = EclipseResourceUtil.getFile(newUrl.getPath());
+ IFile file = EclipseResourceUtil.getFile(newUrl == null ? dropData.getMimeData() :
newUrl.getPath());
if(file != null && file.exists()) return file;
file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(
new Path(newUrl.getPath())
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java 2008-08-20
13:36:48 UTC (rev 9830)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/dnd/context/DropContext.java 2008-08-20
14:34:55 UTC (rev 9831)
@@ -20,21 +20,22 @@
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.jboss.tools.common.model.ui.ModelUIPlugin;
-import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.HTMLTransfer;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.swt.events.TypedEvent;
import org.eclipse.wst.sse.ui.internal.TextDropAction;
-
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.XModelTransferBuffer;
import org.jboss.tools.common.model.options.PreferenceModelUtilities;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
+import org.jboss.tools.common.model.ui.dnd.VpeDnDEvent;
+import org.jboss.tools.common.model.ui.editors.dnd.FileTagProposalLoader;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.common.model.ui.editors.dnd.FileTagProposalLoader;
import org.jboss.tools.jst.web.tld.TLDUtil;
/**
@@ -46,9 +47,17 @@
private String attributeName = null;
private String flavor = null;
private String mimeData = null;
- private DropTargetEvent event;
+ private TypedEvent event;
- public void clean() {
+ public void setFlavor(String flavor) {
+ this.flavor = flavor;
+ }
+
+ public void setMimeData(String mimeData) {
+ this.mimeData = mimeData;
+ }
+
+ public void clean() {
isOverAttributeValue = false;
flavor = null;
mimeData = null;
@@ -87,19 +96,28 @@
new TransferHolder(TextTransfer.getInstance(), new TextTransferProcessor()),
};
- public void setDropTargetEvent(DropTargetEvent event) {
+ public void setDropTargetEvent(TypedEvent event) {
this.event = event;
- TransferData[] ds = event.dataTypes;
+
+ TransferData[] ds = null;
+ if(this.event instanceof DropTargetEvent){
+ ds = ((DropTargetEvent)event).dataTypes;
+ }else if(this.event instanceof VpeDnDEvent){
+ ds = ((VpeDnDEvent)this.event).getDataTypes();
+ }
+ if(ds!=null){
for (int i = 0; i < TRANSFERS.length; i++) {
TransferData data = TRANSFERS[i].getSupportedData(ds);
if(data != null) {
TRANSFERS[i].process(data);
break;
- }
+ }
+
}
+ }
}
- private String getURL(DropTargetEvent event) {
+ private String getURL(TypedEvent event) {
String[] s = (String[])event.data;
if(s == null || s.length == 0) return null;
File f = new File(s[0]);
@@ -109,7 +127,7 @@
return s[0];
}
}
- private File getFile(DropTargetEvent event) {
+ private File getFile(TypedEvent event) {
String[] s = (String[])event.data;
return(s == null || s.length == 0) ? null : new File(s[0]);
}
@@ -127,7 +145,7 @@
return null;
}
- public void runDropCommand(IDNDTextEditor editor, DropTargetEvent event) {
+ public void runDropCommand(IDNDTextEditor editor, TypedEvent event) {
setDropTargetEvent(event);
runDropCommand(editor);
}
@@ -135,8 +153,9 @@
public void runDropCommand(IDNDTextEditor editor) {
if(event == null) return;
if(getFlavor() == null) {
- } else if (getFlavor().equals("text/html")) {
- new TextDropAction().run(event, editor);
+ return;
+ } else if (getFlavor().equals("text/html") && this.event instanceof
DropTargetEvent) {
+ new TextDropAction().run((DropTargetEvent) event, editor);
} else {
editor.runDropCommand(getFlavor(), getMimeData());
}
@@ -191,7 +210,14 @@
class HTMLTransferProcessor extends TransferProcessor {
public void process(TransferData data) {
flavor = "text/html";
- Object ooo = HTMLTransfer.getInstance().nativeToJava(event.currentDataType);
+ TransferData currentDataType = null;
+ if(event instanceof DropTargetEvent){
+ currentDataType = (( DropTargetEvent)event).currentDataType;
+ }else if(event instanceof VpeDnDEvent){
+ currentDataType = ((VpeDnDEvent)event).currentDataType;
+ }
+ Object ooo = HTMLTransfer.getInstance().nativeToJava(currentDataType);
+
mimeData = ooo == null ? null : ooo.toString();
if(mimeData == null) {
flavor = null;