Author: yradtsevich
Date: 2009-05-19 16:03:51 -0400 (Tue, 19 May 2009)
New Revision: 15355
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DndUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
Log:
RESOLVED - issue JBIDE-4225: Drag and Drop facelet tag in Visual part of VPE
https://jira.jboss.org/jira/browse/JBIDE-4225
- now the add new tag wizard is shown when a user drag&drops a tag from the palette
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DndUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DndUtil.java 2009-05-19
19:42:14 UTC (rev 15354)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DndUtil.java 2009-05-19
20:03:51 UTC (rev 15355)
@@ -12,9 +12,13 @@
package org.jboss.tools.vpe.dnd;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.swt.events.TypedEvent;
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.editor.VpeController;
import org.jboss.tools.vpe.editor.util.VpeDebugUtil;
import org.jboss.tools.vpe.xulrunner.XPCOM;
import org.mozilla.interfaces.nsIComponentManager;
@@ -84,9 +88,25 @@
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 };
+ public static final String[] FLAVORS = {
+ VpeController.MODEL_FLAVOR,
+ kTextMime,
+ kUnicodeMime,
+ kHTMLMime,
+ kAOLMailMime,
+ kPNGImageMime,
+ kJPEGImageMime,
+ kGIFImageMime,
+ kFileMime,
+ kURLMime,
+ kURLDataMime,
+ kURLDescriptionMime,
+ kNativeImageMime,
+ kNativeHTMLMime,
+ kFilePromiseURLMime,
+ kFilePromiseMime,
+ kFilePromiseDirectoryMime
+ };
/**
* The Constructor.
@@ -102,39 +122,91 @@
* @param event the event
* @param textEditor the text editor
*/
- public static void fireDnDEvent(DropContext dropContext, IDNDTextEditor textEditor,
TypedEvent event) {
-
+ 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
+ * Returns an instance of {@link DragTransferData}
+ * for the current DnD session.
*/
- public static nsISupports getDnDValue(nsIDOMEvent event) {
- 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();
+ public static DragTransferData getDragTransferData() {
+ final nsIDragSession dragSession = getCurrentDragSession();
+ final List<String> supportedDataFlavors
+ = getSupportedDataFlavors(dragSession);
- final nsITransferable iTransferable = (nsITransferable)
componentManager.createInstanceByContractID(
- XPCOM.NS_TRANSFERABLE_CONTRACTID, null,
nsITransferable.NS_ITRANSFERABLE_IID);
+ final nsITransferable iTransferable
+ = createTransferable(supportedDataFlavors);
- for (String flavor1 : FLAVORS) {
- if (dragSession.isDataFlavorSupported(flavor1)) {
- iTransferable.addDataFlavor(flavor1);
- }
- }
- String[] aFlavor = { "" }; //$NON-NLS-1$
- long[] aDataLen = { 0 };
- nsISupports[] aData = { null };
+ String[] aFlavor = new String[1];
+ nsISupports[] aValue = new nsISupports[1];
+ long[] aDataLen = new long[1];
dragSession.getData(iTransferable, 0);
- iTransferable.getAnyTransferData(aFlavor, aData, aDataLen);
- return aData[0];
+ iTransferable.getAnyTransferData(aFlavor, aValue, aDataLen);
+ return new DragTransferData(aFlavor[0], aValue[0], aDataLen[0]);
}
+
+ public static nsITransferable createTransferable(
+ final List<String> supportedDataFlavors) {
+ final nsIComponentManager componentManager
+ = Mozilla.getInstance().getComponentManager();
+
+ final nsITransferable iTransferable = (nsITransferable)
+ componentManager.createInstanceByContractID(
+ XPCOM.NS_TRANSFERABLE_CONTRACTID, null,
+ nsITransferable.NS_ITRANSFERABLE_IID);
+
+ for (final String flavor : supportedDataFlavors) {
+ iTransferable.addDataFlavor(flavor);
+ }
+
+ return iTransferable;
+ }
+
+ private static List<String> getSupportedDataFlavors(
+ final nsIDragSession dragSession) {
+ final List<String> supportedDataFlavors = new ArrayList<String>();
+ for (final String flavor : FLAVORS) {
+ if (dragSession.isDataFlavorSupported(flavor)) {
+ supportedDataFlavors.add(flavor);
+ }
+ }
+ return supportedDataFlavors;
+ }
+
+ public static nsIDragSession getCurrentDragSession() {
+ nsIServiceManager serviceManager = Mozilla.getInstance()
+ .getServiceManager();
+ nsIDragService dragService = (nsIDragService) serviceManager
+ .getServiceByContractID(
+ "(a)mozilla.org/widget/dragservice;1", //$NON-NLS-1$
+ nsIDragService.NS_IDRAGSERVICE_IID);
+ final nsIDragSession dragSession = dragService.getCurrentSession();
+ return dragSession;
+ }
+
+ public static class DragTransferData {
+ private final String flavor;
+ private final long dataLen;
+ private final nsISupports value;
+
+ public DragTransferData(final String flavor, final nsISupports value,
+ final long dataLen) {
+ this.flavor = flavor;
+ this.value = value;
+ this.dataLen = dataLen;
+ }
+
+ public String getFlavor() {
+ return flavor;
+ }
+ public nsISupports getValue() {
+ return value;
+ }
+ public long getDataLen() {
+ return dataLen;
+ }
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2009-05-19
19:42:14 UTC (rev 15354)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2009-05-19
20:03:51 UTC (rev 15355)
@@ -104,6 +104,7 @@
import org.jboss.tools.vpe.VpeDebug;
import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.dnd.DndUtil;
+import org.jboss.tools.vpe.dnd.DndUtil.DragTransferData;
import org.jboss.tools.vpe.editor.bundle.BundleMap;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
@@ -2093,7 +2094,7 @@
.queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
Node sourceNode = domMapping.getNearSourceNode(visualNode);
if (sourceNode != null) {
- if (ModelTransfer.MODEL.equals(flavor)) { //$NON-NLS-1$
+ if (ModelTransfer.MODEL.equals(flavor)) {
// XModelObject object =
// PreferenceModelUtilities.getPreferenceModel().
// getModelBuffer().source();
@@ -2225,8 +2226,10 @@
// .getModelBuffer().source();
// if(object == null)
- nsISupports aValue = DndUtil.getDnDValue(mouseEvent);
- String aFlavor = ""; //$NON-NLS-1$
+ final DragTransferData dragTransferData = DndUtil.getDragTransferData();
+ final nsISupports aValue = dragTransferData.getValue();
+
+ String aFlavor = "";
if (VpeDndUtil.isNsIFileInstance(aValue)) {
nsIFile aFile = (nsIFile) aValue.queryInterface(nsIFile.NS_IFILE_IID);
@@ -2245,7 +2248,11 @@
} else if (VpeDndUtil.isNsIStringInstance(aValue)) {
nsISupportsString aString = (nsISupportsString)
aValue.queryInterface(nsISupportsString.NS_ISUPPORTSSTRING_IID);
data = aString.getData();
- aFlavor = DndUtil.kURLMime;
+ if (MODEL_FLAVOR.equals( dragTransferData.getFlavor() )) {
+ aFlavor = dragTransferData.getFlavor();
+ } else {
+ aFlavor = DndUtil.kURLMime;
+ }
}
// if (object.getFileType() == XModelObject.FILE
@@ -2603,7 +2610,6 @@
}
public void dragDrop(nsIDOMEvent domEvent) {
-
visualBuilder.getDnd().dragDrop(domEvent, this);
}