Author: scabanovich
Date: 2009-09-18 11:03:39 -0400 (Fri, 18 Sep 2009)
New Revision: 17663
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/FileDropCommand.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/FileTagProposalLoader.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/JSPTagProposalFactory.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/PaletteDropCommand.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/TagProposal.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/DefaultDropCommandRunner.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4913
Initial moving jsp related dnd to jst.jsp
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2009-09-18 15:02:38 UTC
(rev 17662)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2009-09-18 15:03:39 UTC
(rev 17663)
@@ -16,6 +16,7 @@
org.jboss.tools.jst.jsp.editor,
org.jboss.tools.jst.jsp.format,
org.jboss.tools.jst.jsp.jspeditor,
+ org.jboss.tools.jst.jsp.jspeditor.dnd,
org.jboss.tools.jst.jsp.messages,
org.jboss.tools.jst.jsp.outline,
org.jboss.tools.jst.jsp.outline.cssdialog,
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-09-18 15:02:38 UTC (rev
17662)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-09-18 15:03:39 UTC (rev
17663)
@@ -396,6 +396,10 @@
class="org.jboss.tools.jst.jsp.outline.VpeProperties"/>
<xclass id="org.jboss.tools.jst.jsp.outline.DefaultDropCommandRunner"
class="org.jboss.tools.jst.jsp.outline.DefaultDropCommandRunner"/>
+ <xclass id="org.jboss.tools.jst.jsp.jspeditor.dnd.PaletteDropCommand"
+ class="org.jboss.tools.jst.jsp.jspeditor.dnd.PaletteDropCommand"/>
+ <xclass id="org.jboss.tools.jst.jsp.jspeditor.dnd.FileDropCommand"
+ class="org.jboss.tools.jst.jsp.jspeditor.dnd.FileDropCommand"/>
</extension>
<extension
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java 2009-09-18
15:02:38 UTC (rev 17662)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java 2009-09-18
15:03:39 UTC (rev 17663)
@@ -103,8 +103,7 @@
import org.jboss.tools.common.model.ui.editors.dnd.DropCommandFactory;
import org.jboss.tools.common.model.ui.editors.dnd.DropData;
import org.jboss.tools.common.model.ui.editors.dnd.IDropCommand;
-import org.jboss.tools.common.model.ui.editors.dnd.JSPTagProposalFactory;
-import org.jboss.tools.common.model.ui.editors.dnd.TagProposal;
+import org.jboss.tools.common.model.ui.editors.dnd.ITagProposal;
import
org.jboss.tools.common.model.ui.editors.dnd.DropUtils.AttributeDescriptorValueProvider;
import org.jboss.tools.common.model.ui.editors.dnd.composite.TagAttributesComposite;
import
org.jboss.tools.common.model.ui.editors.dnd.composite.TagAttributesComposite.AttributeDescriptorValue;
@@ -127,6 +126,8 @@
import org.jboss.tools.jst.jsp.editor.ITextFormatter;
import org.jboss.tools.jst.jsp.editor.IVisualContext;
import org.jboss.tools.jst.jsp.editor.IVisualController;
+import org.jboss.tools.jst.jsp.jspeditor.dnd.JSPTagProposalFactory;
+import org.jboss.tools.jst.jsp.jspeditor.dnd.TagProposal;
import org.jboss.tools.jst.jsp.outline.JSPContentOutlineConfiguration;
import org.jboss.tools.jst.jsp.outline.JSPPropertySheetConfiguration;
import org.jboss.tools.jst.jsp.outline.ValueHelper;
@@ -768,10 +769,10 @@
JspContentAssistProcessor processor;
IPageContext pageContext;
- public void setProposal(TagProposal proposal) {
+ public void setProposal(ITagProposal proposal) {
if(this.proposal == proposal) return;
- this.proposal = proposal;
- query = createQuery(proposal);
+ this.proposal = (TagProposal)proposal;
+ query = createQuery(this.proposal);
ValueHelper valueHelper = new ValueHelper();
processor = valueHelper.createContentAssistProcessor();
pageContext = valueHelper.createPageContext(processor, query.getOffset());
@@ -897,6 +898,7 @@
event.detail = DND.DROP_NONE;
return;
}
+ JSPTagProposalFactory.getInstance();
dropContext.setDropTargetEvent(event);
if (dropContext.getFlavor() == null) {
event.detail = DND.DROP_NONE;
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/FileDropCommand.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/FileDropCommand.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/FileDropCommand.java 2009-09-18
15:03:39 UTC (rev 17663)
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.jspeditor.dnd;
+
+import java.io.File;
+import java.util.Properties;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.jboss.tools.common.meta.action.XActionInvoker;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
+import org.jboss.tools.common.model.ui.editors.dnd.DefaultDropCommand;
+import org.jboss.tools.common.model.ui.editors.dnd.DropCommandFactory;
+import org.jboss.tools.common.model.ui.editors.dnd.DropData;
+import org.jboss.tools.common.model.ui.editors.dnd.ElementGeneratorFactory;
+import org.jboss.tools.common.model.ui.editors.dnd.ExternalDropWizardModel;
+import org.jboss.tools.common.model.ui.editors.dnd.IDropWizardModel;
+import org.jboss.tools.common.model.ui.editors.dnd.IElementGenerator;
+import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
+
+/**
+ *
+ * @author eskimo
+ */
+
+// TODO - Eskimo - Think about inserting different type of tags
+// - HTML
+// - XML(XHTML,JSP)
+
+public class FileDropCommand extends DefaultDropCommand {
+
+ IElementGenerator generator;
+
+ public void run(IProgressMonitor monitor) throws CoreException {
+ String uri = ((TagProposal)getDefaultModel().getTagProposal()).getUri();
+
+ generator = ElementGeneratorFactory.getInstance().getElementGenerator(uri);
+ generator.setDataModel(getDefaultModel());
+
+ Properties properties = new Properties();
+ properties.put(PaletteInsertHelper.PROPOPERTY_TAG_NAME,getDefaultModel().getTagProposal().getName());
+ properties.put(PaletteInsertHelper.PROPOPERTY_START_TEXT, generateStartText());
+ properties.put(PaletteInsertHelper.PROPOPERTY_END_TEXT, generateEndText());
+ properties.put(PaletteInsertHelper.PROPOPERTY_REFORMAT_BODY,
getReformatBodyProperty());
+ properties.put(PaletteInsertHelper.PROPOPERTY_TAGLIBRARY_URI, uri);
+ String version =
((TagProposal)getDefaultModel().getTagProposal()).getLibraryVersion();
+ properties.put(PaletteInsertHelper.PROPOPERTY_TAGLIBRARY_VERSION, version);
+ properties.put(PaletteInsertHelper.PROPOPERTY_DEFAULT_PREFIX,getDefaultModel().getTagProposal().getPrefix());
+ properties.put(PaletteInsertHelper.PROPOPERTY_SELECTION_PROVIDER,
getDefaultModel().getDropData().getSelectionProvider());
+ properties.put(PaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, "true");
//$NON-NLS-1$
+ addCustomProperties(properties);
+ PaletteInsertHelper.insertIntoEditor(
+ getDefaultModel().getDropData().getSourceViewer(),
+ properties
+ );
+ }
+
+ protected void executeUnknownTag() {
+ DropData data = getDefaultModel().getDropData();
+ String type = data.getMimeType();
+ String mime = data.getMimeData();
+ /*nsITransferable.kFileMime*/
+ if("application/x-moz-file".equals(type) && mime != null) {
//$NON-NLS-1$
+ if(mime.startsWith("file:")) mime = mime.substring(5); //$NON-NLS-1$
+ File f = new File(mime);
+ IFile file = EclipseResourceUtil.getFile(f.getAbsolutePath());
+ if(file == null) return;
+ XModelObject o = EclipseResourceUtil.getObjectByResource(file);
+ if(o == null) return;
+ XActionInvoker.invoke("CopyActions.Copy", o, null); //$NON-NLS-1$
+ data.setMimeType(ModelTransfer.MODEL);
+ data.setMimeData(""); //$NON-NLS-1$
+ DropCommandFactory.getInstance().getDropCommand(ModelTransfer.MODEL,
tagProposalFactory).execute(data);
+ }
+ }
+
+ protected void addCustomProperties(Properties properties) {}
+
+ protected String getReformatBodyProperty() {
+ return "yes"; //$NON-NLS-1$
+ }
+
+ protected IDropWizardModel createSpecificModel() {
+ return new ExternalDropWizardModel(tagProposalFactory);
+ }
+
+ protected String generateStartText() {
+ return generator.generateStartTag();
+ }
+
+ protected String generateEndText() {
+ return generator.generateEndTag();
+ }
+}
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/FileTagProposalLoader.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/FileTagProposalLoader.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/FileTagProposalLoader.java 2009-09-18
15:03:39 UTC (rev 17663)
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.jspeditor.dnd;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.tools.common.model.ui.editors.dnd.AbsoluteFilePathAttributeValueLoader;
+import org.jboss.tools.common.model.ui.editors.dnd.CssLinkAttributeValueLoader;
+import org.jboss.tools.common.model.ui.editors.dnd.DropURI;
+import org.jboss.tools.common.model.ui.editors.dnd.IAttributeValueLoader;
+import org.jboss.tools.common.model.ui.editors.dnd.IDropWizardModel;
+import org.jboss.tools.common.model.ui.editors.dnd.ITagProposal;
+import org.jboss.tools.common.model.ui.editors.dnd.ITagProposalLoader;
+import
org.jboss.tools.common.model.ui.editors.dnd.LoadBundleBaseNameAttributeValueLoader;
+import org.jboss.tools.common.model.ui.editors.dnd.context.DropContext;
+import org.jboss.tools.common.model.ui.views.palette.PaletteTaglibInserter;
+
+public class FileTagProposalLoader implements ITagProposalLoader {
+
+ private static final Map<String,TagProposal[]> extensionMap = new
HashMap<String,TagProposal[]>();
+
+ static TagProposal[] IMG_TAG_PROPOSALS = new TagProposal[]{
+ new TagProposal(
+ DropURI.JSF_HTML_URI,
+ "h", //$NON-NLS-1$
+ "graphicImage", //$NON-NLS-1$
+ new AbsoluteFilePathAttributeValueLoader("value","","")
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ),
+ new TagProposal(
+ DropURI.HTML_4_0_URI,
+ ITagProposal.EMPTY_PREFIX,
+ "img", //$NON-NLS-1$
+ new AbsoluteFilePathAttributeValueLoader("src","","")
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ),
+ new TagProposal(
+ DropURI.STRUTS_HTML_URI,
+ "html", //$NON-NLS-1$
+ "img", //$NON-NLS-1$
+ new AbsoluteFilePathAttributeValueLoader("page","","")
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ),
+ new TagProposal(
+ DropURI.SEAM_URI,
+ "s", //$NON-NLS-1$
+ "graphicImage", //$NON-NLS-1$
+ new AbsoluteFilePathAttributeValueLoader("url","","")
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ )
+// yradtsevich: fix of JBIDE-3984: Exclude t:graphicImage option from Insert tag dialog
+// ,
+// new TagProposal(
+// DropURI.TOMOHAWK_URI,
+// "t",
+// "graphicImage",
+// new AbsoluteFilePathAttributeValueLoader("url","","")
+// )
+ };
+
+ static TagProposal[] CSS_TAG_PROPOSALS = new TagProposal[]{
+ new TagProposal(
+ DropURI.HTML_4_0_URI,
+ ITagProposal.EMPTY_PREFIX,
+ "link", //$NON-NLS-1$
+ new CssLinkAttributeValueLoader("href") //$NON-NLS-1$
+ ),
+ };
+
+ static TagProposal JSP_INCLUDE = new TagProposal(
+ DropURI.JSP_URI,
+ "jsp", //$NON-NLS-1$
+ "include", //$NON-NLS-1$
+ new
AbsoluteFilePathAttributeValueLoader("page","","")
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ );
+
+ static TagProposal JSP_FORWARD = new TagProposal(
+ DropURI.JSP_URI,
+ "jsp", //$NON-NLS-1$
+ "forward", //$NON-NLS-1$
+ new AbsoluteFilePathAttributeValueLoader("page","","")
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ );
+
+ static TagProposal UI_INCLUDE = new TagProposal(
+ PaletteTaglibInserter.faceletUri,
+ "ui", //$NON-NLS-1$
+ "include", //$NON-NLS-1$
+ new
AbsoluteFilePathAttributeValueLoader("src","","")
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ );
+
+ static TagProposal S_DECORATE = new TagProposal(
+ DropURI.SEAM_URI,
+ "s", //$NON-NLS-1$
+ "decorate", //$NON-NLS-1$
+ new
AbsoluteFilePathAttributeValueLoader("template","","")
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ );
+
+ static TagProposal[] PAGE_TAG_PROPOSALS = new TagProposal[]{
+ JSP_INCLUDE,
+ JSP_FORWARD
+ };
+
+ static TagProposal[] XHTML_PAGE_TAG_PROPOSALS = new TagProposal[]{
+ JSP_INCLUDE,
+ JSP_FORWARD,
+ UI_INCLUDE,
+ S_DECORATE
+ };
+
+ static {
+ // There is the question here what store HTML or TLD will been asked about
TagDescription
+ extensionMap.put("jpg", IMG_TAG_PROPOSALS); //$NON-NLS-1$
+
+ extensionMap.put("jpeg", IMG_TAG_PROPOSALS); //$NON-NLS-1$
+
+ extensionMap.put("gif",IMG_TAG_PROPOSALS); //$NON-NLS-1$
+
+ extensionMap.put("bmp",IMG_TAG_PROPOSALS); //$NON-NLS-1$
+
+ extensionMap.put("png",IMG_TAG_PROPOSALS); //$NON-NLS-1$
+
+ extensionMap.put("jsp",PAGE_TAG_PROPOSALS); //$NON-NLS-1$
+ extensionMap.put("html",PAGE_TAG_PROPOSALS); //$NON-NLS-1$
+ extensionMap.put("xhtml",XHTML_PAGE_TAG_PROPOSALS); //$NON-NLS-1$
+
+ extensionMap.put(
+ "properties",new TagProposal[]{ //$NON-NLS-1$
+ new TagProposal(
+ DropURI.JSF_CORE_URI,
+ "f", //$NON-NLS-1$
+ "loadBundle", //$NON-NLS-1$
+ new LoadBundleBaseNameAttributeValueLoader()
+ )
+ }
+ );
+ extensionMap.put("css",CSS_TAG_PROPOSALS); //$NON-NLS-1$
+ extensionMap.put(
+ "inc", new TagProposal[]{ //$NON-NLS-1$
+ new TagProposal(
+ DropURI.JSP_URI,
+ "jsp", //$NON-NLS-1$
+ "include", //$NON-NLS-1$
+ new
AbsoluteFilePathAttributeValueLoader("page","","")
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ )
+ }
+ );
+
+ DropContext.mappedExtensions.addAll(extensionMap.keySet());
+ }
+
+ public static boolean isExtensionMapped(String extension) {
+ return extension != null && extensionMap.containsKey(extension.toLowerCase());
+ }
+
+ public TagProposal[] getTagProposals(Object data) {
+ String fileName = data.toString();
+ String extension = fileName.substring(fileName.lastIndexOf(".")+1);
//$NON-NLS-1$
+ TagProposal[] tagProposals = (TagProposal[])extensionMap.get(extension.toLowerCase());
+ if(tagProposals==null) {
+ tagProposals = new TagProposal[0];
+ }
+ return tagProposals;
+ }
+
+ public boolean isTagProposalExists(Object data) {
+ return true;
+ }
+
+ public static class ImageFileAttributesValuesLoader implements IAttributeValueLoader {
+
+ public void fillTagAttributes(IDropWizardModel model) {
+ }
+
+ }
+
+ public static class JspFileAttributesValuesLoader implements IAttributeValueLoader {
+
+ public void fillTagAttributes(IDropWizardModel model) {
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/JSPTagProposalFactory.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/JSPTagProposalFactory.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/JSPTagProposalFactory.java 2009-09-18
15:03:39 UTC (rev 17663)
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.jspeditor.dnd;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.editors.dnd.DropCommandFactory;
+import org.jboss.tools.common.model.ui.editors.dnd.ITagProposalFactory;
+import org.jboss.tools.common.model.ui.editors.dnd.ITagProposalLoader;
+
+public class JSPTagProposalFactory implements ITagProposalFactory {
+ private static final JSPTagProposalFactory INSTANCE = new JSPTagProposalFactory();
+ public static Map<String,String> loaderMap = new HashMap<String,String>();
+
+ static {
+ loaderMap.put(DropCommandFactory.kFileMime, FileTagProposalLoader.class.getName());
+ loaderMap.put(DropCommandFactory.kURLMime, FileTagProposalLoader.class.getName());
+ new FileTagProposalLoader();
+ }
+
+ public static JSPTagProposalFactory getInstance() {
+ return INSTANCE;
+ }
+
+ private JSPTagProposalFactory() {
+ }
+
+ public ITagProposalLoader getProposalLoader(String mimeType) {
+ ITagProposalLoader fInstance = DEFAULT_PROPOSAL_LOADER;
+ try {
+ String fClassName = (String)loaderMap.get(mimeType);
+ if(fClassName == null) {
+ //No need to report, just there is no specific proposal loader for this myme type.
+ return fInstance;
+ }
+ Class newClass = this.getClass().getClassLoader().loadClass(fClassName);
+ fInstance = (ITagProposalLoader)newClass.newInstance();
+ } catch (InstantiationException e) {
+ ModelUIPlugin.getPluginLog().logError(e);
+ } catch (IllegalAccessException e) {
+ ModelUIPlugin.getPluginLog().logError(e);
+ } catch (ClassNotFoundException e) {
+ ModelUIPlugin.getPluginLog().logError(e);
+ }
+ return fInstance;
+ }
+}
+
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/PaletteDropCommand.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/PaletteDropCommand.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/PaletteDropCommand.java 2009-09-18
15:03:39 UTC (rev 17663)
@@ -0,0 +1,335 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.jspeditor.dnd;
+
+import java.util.Properties;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.options.PreferenceModelUtilities;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.dnd.DnDUtil;
+import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
+import org.jboss.tools.common.model.ui.editors.dnd.DropData;
+import org.jboss.tools.common.model.ui.editors.dnd.DropWizard;
+import org.jboss.tools.common.model.ui.editors.dnd.IDropWizard;
+import org.jboss.tools.common.model.ui.editors.dnd.IDropWizardModel;
+import org.jboss.tools.common.model.ui.editors.dnd.PaletteDropWizardModel;
+import
org.jboss.tools.common.model.ui.editors.dnd.composite.TagAttributesComposite.AttributeDescriptorValue;
+import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
+import org.jboss.tools.common.model.ui.views.palette.PaletteInsertManager;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.jst.web.tld.IWebProject;
+import org.jboss.tools.jst.web.tld.TLDToPaletteHelper;
+import org.jboss.tools.jst.web.tld.URIConstants;
+import org.jboss.tools.jst.web.tld.WebProjectFactory;
+
+/**
+ *
+ * @author eskimo
+ */
+public class PaletteDropCommand extends FileDropCommand {
+ Properties initialValues = new Properties();
+ String startText;
+ String endText;
+ String newLine;
+ String reformat = "no"; //$NON-NLS-1$
+
+ Properties properties = new Properties();
+ boolean callPaletteWizard = false;
+
+ /**
+ *
+ */
+ protected IDropWizardModel createSpecificModel() {
+ return new PaletteDropWizardModel(tagProposalFactory);
+ }
+
+ protected void addCustomProperties(Properties runningProperties) {
+ newLine = properties.getProperty(PaletteInsertHelper.PROPOPERTY_NEW_LINE);
+ if (newLine == null) newLine="true"; //$NON-NLS-1$
+ runningProperties.setProperty(PaletteInsertHelper.PROPOPERTY_NEW_LINE, newLine);
+ String addTaglib = properties.getProperty(PaletteInsertHelper.PROPOPERTY_ADD_TAGLIB);
+ if(addTaglib == null) addTaglib = "true"; //$NON-NLS-1$
+ runningProperties.setProperty(PaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, addTaglib);
+ }
+
+ public void execute() {
+ if(getDefaultModel().getTagProposal() == IDropWizardModel.UNDEFINED_TAG_PROPOSAL) {
+ if(startText == null && endText == null) return;
+ int pos =
((ITextSelection)getDefaultModel().getDropData().getSelectionProvider().getSelection()).getOffset();
+ getDefaultModel().getDropData().getSourceViewer().setSelectedRange(pos, 0);
+ if(startText != null)
properties.setProperty(PaletteInsertHelper.PROPOPERTY_START_TEXT, startText);
+ if(endText != null) properties.setProperty(PaletteInsertHelper.PROPOPERTY_END_TEXT,
endText);
+ if(reformat != null)
properties.setProperty(PaletteInsertHelper.PROPOPERTY_REFORMAT_BODY, reformat);
+ if(newLine != null) properties.setProperty(PaletteInsertHelper.PROPOPERTY_NEW_LINE,
newLine);
+ PaletteInsertHelper.insertIntoEditor(
+ getDefaultModel().getDropData().getSourceViewer(),
+ properties
+ );
+ } else {
+ DropData data = getDefaultModel().getDropData();
+ ISourceViewer viewer = data.getSourceViewer();
+ if(data.getContainer() != null){
+ if (data.getContainer() instanceof ElementImpl) {
+ ElementImpl container = (ElementImpl)data.getContainer();
+ if(!container.hasEndTag()){
+ try{
+ IDocument document = viewer.getDocument();
+ int containerOffset = container.getStartOffset();
+ int containerLenght = container.getStartEndOffset()-containerOffset;
+ String containerString = document.get(containerOffset, containerLenght);
+ int slashPosition = containerString.lastIndexOf("/"); //$NON-NLS-1$
+ if(slashPosition >= 0){
+ int deltaOffset = (containerString.length()-1)-slashPosition;
+ String text = ""; //$NON-NLS-1$
+ for(int i=0; i < deltaOffset;i++) text += " "; //$NON-NLS-1$
+ text += "></"+container.getNodeName()+">";
//$NON-NLS-1$ //$NON-NLS-2$
+ document.replace(containerOffset+slashPosition,
containerString.length()-slashPosition, text);
+ }
+ }catch(BadLocationException ex){
+ ModelUIPlugin.getPluginLog().logError(ex);
+ }
+ }
+ }
+ }
+ super.execute();
+ }
+ }
+
+ public void initialize() {
+ DropData data = getDefaultModel().getDropData();
+
+ IEditorInput input = data.getEditorInput();
+ XModelObject target = null;
+ IFile f = null;
+ if(input instanceof IFileEditorInput) {
+ f = ((IFileEditorInput)input).getFile();
+ target = EclipseResourceUtil.getObjectByResource(f);
+ if(target == null && f.exists()) {
+ target = EclipseResourceUtil.createObjectForResource(f);
+ }
+ } else if(input instanceof IModelObjectEditorInput) {
+ target = ((IModelObjectEditorInput)input).getXModelObject();
+ }
+ if(target == null) {
+ initialize2();
+ } else {
+ ISourceViewer viewer = data.getSourceViewer();
+
+ properties = new Properties();
+ properties.put("viewer", viewer); //$NON-NLS-1$
+ properties.setProperty("text", viewer.getDocument().get()); //$NON-NLS-1$
+ properties.setProperty("isDrop", "true"); //$NON-NLS-1$
//$NON-NLS-2$
+ properties.setProperty("actionSourceGUIComponentID", "editor");
//$NON-NLS-1$ //$NON-NLS-2$
+ properties.setProperty("accepsAsString", "true"); //$NON-NLS-1$
//$NON-NLS-2$
+
+ if(f != null) {
+ properties.put("file", f); //$NON-NLS-1$
+ }
+ ISelection selection = data.getSelectionProvider().getSelection();
+
+ int offset = 0;
+ //int length = 0;
+ if(selection instanceof ITextSelection) {
+ offset = ((ITextSelection)selection).getOffset();
+ //length = ((ITextSelection)selection).getLength();
+ } else {
+ offset = viewer.getTextWidget().getCaretOffset();
+ }
+ properties.setProperty("pos", "" + offset); //$NON-NLS-1$
//$NON-NLS-2$
+ if(selection instanceof IStructuredSelection && !selection.isEmpty()) {
+ Object so = ((IStructuredSelection)selection).getFirstElement();
+ if(so instanceof IDOMElement) {
+ String en = ((IDOMElement)so).getNodeName();
+ properties.setProperty("context:tagName", en); //$NON-NLS-1$
+ String attrName = data.getAttributeName();
+ if(attrName != null) {
+ properties.setProperty("context:attrName", attrName); //$NON-NLS-1$
+ }
+ }
+ }
+ try {
+ if(DnDUtil.isPasteEnabled(target)) {
+ DnDUtil.paste(target, properties);
+ } else {
+ XModelObject s =
PreferenceModelUtilities.getPreferenceModel().getModelBuffer().source();
+ if(s != null) {
+ properties.setProperty("start text", "" + getDefaultText(s));
//$NON-NLS-1$ //$NON-NLS-2$
+ properties.setProperty("end text", ""); //$NON-NLS-1$
//$NON-NLS-2$
+ properties.setProperty("new line", "newLine"); //$NON-NLS-1$
//$NON-NLS-2$
+ }
+ }
+ } catch (CoreException e) {
+ ModelUIPlugin.getPluginLog().logError(e);
+ }
+ startText = properties.getProperty(TLDToPaletteHelper.START_TEXT);
+ endText = properties.getProperty(TLDToPaletteHelper.END_TEXT);
+ reformat = properties.getProperty(TLDToPaletteHelper.REFORMAT);
+ String uri = properties.getProperty(URIConstants.LIBRARY_URI);
+ String libraryVersion = properties.getProperty(URIConstants.LIBRARY_VERSION);
+ String defaultPrefix = properties.getProperty(URIConstants.DEFAULT_PREFIX);
+ String tagname = properties.getProperty("tag name"); //$NON-NLS-1$
+
+ callPaletteWizard = PaletteInsertManager.getInstance().getWizardName(properties) !=
null;
+
+ boolean isWizardEnabled =
(!"FileJAVA".equals(target.getModelEntity().getName())); //$NON-NLS-1$
+ if(getDefaultModel() instanceof PaletteDropWizardModel) {
+ ((PaletteDropWizardModel)getDefaultModel()).setWizardEnabled(isWizardEnabled);
+ }
+
+ if(uri == null || tagname == null) {
+ getDefaultModel().setTagProposal(IDropWizardModel.UNDEFINED_TAG_PROPOSAL);
+ } else {
+ getDefaultModel().setTagProposal(new TagProposal(uri, libraryVersion, defaultPrefix,
tagname));
+ insertInitialValues();
+ }
+ }
+ }
+
+ private void initialize2() {
+ XModelObject object =
PreferenceModelUtilities.getPreferenceModel().getModelBuffer().source();
+ String tagname = object.getAttributeValue("name"); //$NON-NLS-1$
+ XModelObject parent = object.getParent();
+ String uri = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
+ String libraryVersion = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_VERSION); //$NON-NLS-1$
+ String defaultPrefix = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
+ this.getDefaultModel().setTagProposal(new TagProposal(uri,
libraryVersion,defaultPrefix,tagname));
+ startText = object.getAttributeValue("start text"); //$NON-NLS-1$
+ endText = object.getAttributeValue("end text"); //$NON-NLS-1$
+ }
+
+ private void insertInitialValues() {
+ parseInitialValues(startText);
+ AttributeDescriptorValue[] vs = getDefaultModel().getAttributeValueDescriptors();
+ for (int i = 0; i < vs.length; i++) {
+ String v = initialValues.getProperty(vs[i].getName());
+ if(v != null) vs[i].setValue(v);
+ }
+ }
+
+ private void parseInitialValues(String startText) {
+ if(startText == null || startText.length() == 0) return;
+ int bi = startText.indexOf('<');
+ if(bi < 0) return;
+ int ei = startText.indexOf('>', bi);
+ if(ei < 0) return;
+ String header = startText.substring(bi + 1, ei);
+ int NOTHING = 0;
+ int ATT_NAME = 1;
+ int ATT_VALUE = 2;
+ char quote = '\0';
+ int state = NOTHING;
+ String name = null;
+ String value = null;
+ for (int i = 0; i < header.length(); i++) {
+ char c = header.charAt(i);
+ if(state == NOTHING) {
+ if(Character.isJavaIdentifierStart(c)) {
+ name = "" + c; //$NON-NLS-1$
+ state = ATT_NAME;
+ }
+ } else if(state == ATT_NAME) {
+ if(Character.isJavaIdentifierPart(c) || c == ':') {
+ name += c;
+ } else if(c == '=') {
+ state = ATT_VALUE;
+ quote = '\0';
+ }
+ } else if(state == ATT_VALUE) {
+ if(c == quote) {
+ initialValues.setProperty(name, value);
+ name = null;
+ value = null;
+ state = NOTHING;
+ quote = '\0';
+ } else if(c == '"' || c == '\'') {
+ quote = c;
+ value = ""; //$NON-NLS-1$
+ } else if(quote != '\0') {
+ value += c;
+ }
+ }
+ }
+ }
+
+ protected String generateStartText() {
+ startText = properties.getProperty("start text"); //$NON-NLS-1$
+ if(getDefaultModel().getTagProposal()==IDropWizardModel.UNDEFINED_TAG_PROPOSAL
+ || getDefaultModel().getTagProposal().getDetails().length() == 0) {
+ return startText;
+ }
+ String s1 = super.generateStartText();
+ String s2 = startText;
+ if(s2 == null) return s1;
+ if(s1.indexOf('=') < 0) return s2; // no input
+ int bi1 = s1.indexOf('<');
+ int bi2 = s2.indexOf('<');
+ if(bi2 < 0 || bi1 < 0) return s2;
+ int ei1 = s1.indexOf('>', bi1);
+ int ei2 = s2.indexOf('>', bi2);
+ if(ei1 < 0 || ei2 < 0) return s1;
+ boolean slash1 = s1.charAt(ei1 - 1) == '/';
+ boolean slash2 = s2.charAt(ei2 - 1) == '/';
+ if(slash1 && !slash2) {
+ s2 = s2.substring(0, bi2) + s1.substring(bi1, ei1 - 1) + s2.substring(ei2);
+ } else if(!slash1 && slash2) {
+ s2 = s2.substring(0, bi2) + s1.substring(bi1, ei1) + s2.substring(ei2 - 1);
+ } else {
+ s2 = s2.substring(0, bi2) + s1.substring(bi1, ei1) + s2.substring(ei2);
+ }
+ return s2;
+ }
+
+ protected String generateEndText() {
+ endText = properties.getProperty("end text"); //$NON-NLS-1$
+ return (endText != null) ? endText : ""; //$NON-NLS-1$
+ }
+
+ protected String getReformatBodyProperty() {
+ return reformat;
+ }
+
+ protected IDropWizard createDropWizard() {
+ String wizardName = PaletteInsertManager.getInstance().getWizardName(properties);
+
+ IDropWizard wizard = null;
+ if(wizardName != null) {
+ wizard =
(IDropWizard)PaletteInsertManager.getInstance().createWizardInstance(properties);
+ }
+ if(wizard == null) wizard = new DropWizard();
+ wizard.setCommand(this);
+ return wizard;
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ private String getDefaultText(XModelObject o) {
+ if(o == null) return ""; //$NON-NLS-1$
+ if(o.getFileType() != XModelObject.FILE) return o.getPresentationString();
+ IWebProject p = WebProjectFactory.instance.getWebProject(o.getModel());
+ String path = p.getPathInWebRoot(o);
+ return path == null ? o.getPresentationString() : path;
+ }
+}
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/TagProposal.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/TagProposal.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/dnd/TagProposal.java 2009-09-18
15:03:39 UTC (rev 17663)
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.jspeditor.dnd;
+
+import org.jboss.tools.common.model.ui.editors.dnd.IAttributeValueLoader;
+import org.jboss.tools.common.model.ui.editors.dnd.IDropWizardModel;
+import org.jboss.tools.common.model.ui.editors.dnd.ITagProposal;
+
+public class TagProposal implements ITagProposal {
+
+ public static final String EMPTY_URI = ""; //$NON-NLS-1$
+
+ String uri;
+ String libraryVersion = ""; //$NON-NLS-1$
+ String prefix;
+ String name;
+ IAttributeValueLoader attributeValueLoader = EMPTY_ATTRIBUTE_VALUE_LOADER;
+
+ /**
+ * TagProposal with empty attribute value loader
+ *
+ */
+ public TagProposal(
+ String uri,
+ String prefix,
+ String name
+ ) {
+ this(uri, "", prefix, name); //$NON-NLS-1$
+ }
+
+ public TagProposal(
+ String uri,
+ String libraryVersion,
+ String prefix,
+ String name
+ ) {
+ this.uri = uri;
+ this.libraryVersion = (libraryVersion == null) ? "" : libraryVersion;
//$NON-NLS-1$
+ this.prefix = prefix;
+ this.name = name;
+ }
+
+ /**
+ *
+ *
+ */
+ public TagProposal(
+ String uri,
+ String prefix,
+ String name,
+ IAttributeValueLoader loader
+ ) {
+ this.uri = uri;
+ this.prefix = prefix;
+ this.name = name;
+ this.attributeValueLoader = loader;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getUri() {
+ return uri;
+ }
+
+ public String getLibraryVersion() {
+ return libraryVersion;
+ }
+
+ public IAttributeValueLoader getAttributesValueLoader() {
+ return attributeValueLoader;
+ }
+
+ public String getDisplayString() {
+ return getPrefix() == ITagProposal.EMPTY_PREFIX ? getName() : getPrefix() +
":" + getName(); //$NON-NLS-1$
+ }
+
+ public String getDetails() {
+ return getUri();
+ }
+
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/DefaultDropCommandRunner.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/DefaultDropCommandRunner.java 2009-09-18
15:02:38 UTC (rev 17662)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/DefaultDropCommandRunner.java 2009-09-18
15:03:39 UTC (rev 17663)
@@ -24,8 +24,8 @@
import org.jboss.tools.common.meta.action.SpecialWizard;
import org.jboss.tools.common.model.ui.editors.dnd.DropCommandFactory;
import org.jboss.tools.common.model.ui.editors.dnd.DropData;
-import org.jboss.tools.common.model.ui.editors.dnd.JSPTagProposalFactory;
import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor;
+import org.jboss.tools.jst.jsp.jspeditor.dnd.JSPTagProposalFactory;
public class DefaultDropCommandRunner implements SpecialWizard {
String flavor;