Author: scabanovich
Date: 2009-07-20 12:46:21 -0400 (Mon, 20 Jul 2009)
New Revision: 16685
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/DefaultDropCommandRunner.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPDialogContentProposalProvider.java
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/JSPDialogCellEditor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPPropertySourceAdapter.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/ValueHelper.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-1826
Drop wizard is switched to new kb.
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-07-20 16:42:31 UTC (rev
16684)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-07-20 16:46:21 UTC (rev
16685)
@@ -394,6 +394,8 @@
class="org.jboss.tools.jst.jsp.outline.JSPCellEditorProviderImpl"/>
<xclass id="org.jboss.tools.jst.jsp.outline.VpeProperties"
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"/>
</extension>
<extension
@@ -438,7 +440,6 @@
</contenttype>
</contentAssistProcessor>
- <!--
<contentAssistProcessor
class="org.jboss.tools.jst.jsp.contentassist.JspContentAssistProcessor"
id="org.jboss.tools.jst.jsp.contentassist.JspContentAssistProcessor">
@@ -453,6 +454,7 @@
</contenttype>
</contentAssistProcessor>
+ <!--
<contentAssistProcessor
class="org.jboss.tools.jst.jsp.contentassist.XmlContentAssistProcessor"
id="org.jboss.tools.jst.jsp.contentassist.XmlContentAssistProcessor">
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPDialogContentProposalProvider.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPDialogContentProposalProvider.java 2009-07-20
16:42:31 UTC (rev 16684)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPDialogContentProposalProvider.java 2009-07-20
16:46:21 UTC (rev 16685)
@@ -72,9 +72,14 @@
if(valueHelper == null) {
valueHelper = new ValueHelper();
}
-// pageContext = (IPageContext)context.get("pageContext");
- processor = valueHelper.createContentAssistProcessor();
- pageContext = valueHelper.createPageContext(processor, offset);
+ pageContext = (IPageContext)context.get("pageContext");
+ processor = (JspContentAssistProcessor)context.get("processor");
+ if(processor == null) {
+ processor = valueHelper.createContentAssistProcessor();
+ }
+ if(pageContext == null) {
+ pageContext = valueHelper.createPageContext(processor, offset);
+ }
context.put("pageContext", pageContext); //$NON-NLS-1$
context.put("kbQuery", createKbQuery(Type.ATTRIBUTE_VALUE,
"", "", offset, false)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
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-07-20
16:42:31 UTC (rev 16684)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java 2009-07-20
16:46:21 UTC (rev 16685)
@@ -12,7 +12,10 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
import java.util.Properties;
import org.eclipse.core.runtime.CoreException;
@@ -22,6 +25,7 @@
import org.eclipse.jface.text.ITextListener;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextEvent;
import org.eclipse.jface.text.formatter.IContentFormatter;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
@@ -100,6 +104,10 @@
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.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;
import org.jboss.tools.common.model.ui.editors.dnd.context.DropContext;
import org.jboss.tools.common.model.ui.editors.dnd.context.InnerDragBuffer;
import org.jboss.tools.common.model.ui.texteditors.TextMerge;
@@ -121,11 +129,21 @@
import org.jboss.tools.jst.jsp.editor.IVisualController;
import org.jboss.tools.jst.jsp.outline.JSPContentOutlineConfiguration;
import org.jboss.tools.jst.jsp.outline.JSPPropertySheetConfiguration;
+import org.jboss.tools.jst.jsp.outline.ValueHelper;
import org.jboss.tools.jst.jsp.preferences.VpePreference;
import org.jboss.tools.jst.jsp.text.xpl.IStructuredTextOccurrenceStructureProvider;
import
org.jboss.tools.jst.jsp.text.xpl.StructuredTextOccurrenceStructureProviderRegistry;
import org.jboss.tools.jst.jsp.ui.action.ExtendedFormatAction;
import org.jboss.tools.jst.jsp.ui.action.IExtendedAction;
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.KbQuery;
+import org.jboss.tools.jst.web.kb.PageProcessor;
+import org.jboss.tools.jst.web.kb.KbQuery.Type;
+import org.jboss.tools.jst.web.kb.internal.JspContextImpl;
+import org.jboss.tools.jst.web.kb.taglib.IAttribute;
+import org.jboss.tools.jst.web.kb.taglib.IComponent;
+import org.jboss.tools.jst.web.kb.taglib.ICustomTagLibComponent;
+import org.jboss.tools.jst.web.kb.taglib.INameSpace;
import org.jboss.tools.jst.web.tld.VpeTaglibManager;
import org.jboss.tools.jst.web.tld.VpeTaglibManagerProvider;
import org.w3c.dom.DocumentType;
@@ -719,6 +737,8 @@
DropData dropData = new DropData(flavor, data,
getEditorInput(), getSourceViewer(),
getSelectionProvider());
+ dropData.setValueProvider(new AttributeDescriptorValueProviderImpl());
+
dropData.setAttributeName(dropContext.getAttributeName());
IDropCommand dropCommand = DropCommandFactory.getInstance()
.getDropCommand(flavor,
@@ -738,6 +758,111 @@
});
}
+ class AttributeDescriptorValueProviderImpl implements AttributeDescriptorValueProvider
{
+ TagProposal proposal;
+ KbQuery query;
+ JspContentAssistProcessor processor;
+ IPageContext pageContext;
+
+ public void setProposal(TagProposal proposal) {
+ if(this.proposal == proposal) return;
+ this.proposal = proposal;
+ query = createQuery(proposal);
+ ValueHelper valueHelper = new ValueHelper();
+ processor = valueHelper.createContentAssistProcessor();
+ pageContext = valueHelper.createPageContext(processor, query.getOffset());
+ Map<String,INameSpace> ns = pageContext.getNameSpaces(query.getOffset());
+ INameSpace n = ns.get(query.getUri());
+ if(n == null && pageContext instanceof JspContextImpl) {
+ IRegion r = new Region(query.getOffset(), 0);
+ ((JspContextImpl)pageContext).addNameSpace(r, new INameSpace(){
+ public String getURI() {
+ return query.getUri();
+ }
+ public String getPrefix() {
+ return query.getPrefix();
+ }
+ });
+ }
+ }
+
+ public void initContext(Properties context) {
+ if(context != null) {
+ context.put("processor", processor);
+ context.put("pageContext", pageContext);
+ }
+ }
+ public IPageContext getPageContext() {
+ return pageContext;
+ }
+
+ public String getTag() {
+ IComponent c = findComponent(query);
+ if(c == null) return null;
+ String prefix = getPrefix(query);
+ if(prefix == null) return c.getName();
+ return prefix + ":" + c.getName();
+ }
+
+ public boolean canHaveBody() {
+ IComponent c = findComponent(query);
+ return c != null && c.canHaveBody();
+ }
+
+ public AttributeDescriptorValue[] getValues() {
+ return createDescriptors(query);
+ }
+
+ KbQuery createQuery(TagProposal proposal) {
+ KbQuery kbQuery = new KbQuery();
+ String name = proposal.getPrefix() + ":" + proposal.getName();
+ kbQuery.setPrefix(proposal.getPrefix());
+ kbQuery.setUri(proposal.getUri());
+ kbQuery.setParentTags(new String[]{name});
+ kbQuery.setParent(name);
+ kbQuery.setMask(false);
+ kbQuery.setType(Type.ATTRIBUTE_NAME);
+ kbQuery.setOffset(JSPTextEditor.this.getTextViewer().getTextWidget().getCaretOffset());
+ kbQuery.setValue("");
+ kbQuery.setStringQuery("");
+ return kbQuery;
+ }
+
+ public IComponent findComponent(KbQuery query) {
+ IComponent[] cs = PageProcessor.getInstance().getComponents(query, pageContext,
true);
+ if(cs == null || cs.length == 0) return null;
+ IComponent s = null;
+ for (IComponent c: cs) {
+ if(c instanceof ICustomTagLibComponent) {
+ s = c;
+ break;
+ }
+ }
+ if(s == null) s = cs[0];
+ return s;
+ }
+
+ public String getPrefix(KbQuery query) {
+ Map<String,INameSpace> ns = pageContext.getNameSpaces(query.getOffset());
+ INameSpace n = ns.get(query.getUri());
+ return n == null ? null : n.getPrefix();
+ }
+
+ public TagAttributesComposite.AttributeDescriptorValue[] createDescriptors(KbQuery
query) {
+ IComponent s = findComponent(query);
+ if(s == null) return new TagAttributesComposite.AttributeDescriptorValue[0];
+
+ List<AttributeDescriptorValue> attributesValues = new
ArrayList<AttributeDescriptorValue>();
+ IAttribute[] as = s.getAttributes();
+ for (IAttribute a: as) {
+ AttributeDescriptorValue value = new AttributeDescriptorValue(a.getName(),
a.isRequired(), a.isPreferable());
+ attributesValues.add(value);
+ }
+
+ return attributesValues.toArray(new
AttributeDescriptorValue[attributesValues.size()]);
+ }
+ }
+
private void createDrop() {
DropTarget target = new DropTarget(getSourceViewer().getTextWidget(),
DND.DROP_MOVE | DND.DROP_COPY);
Added:
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
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/DefaultDropCommandRunner.java 2009-07-20
16:46:21 UTC (rev 16685)
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * 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.outline;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Properties;
+
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+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;
+
+public class DefaultDropCommandRunner implements SpecialWizard {
+ String flavor;
+ String data;
+ ITextEditor textEditor;
+
+ public boolean runDropCommand(final String flavor, final String data, ITextEditor te) {
+ if(te instanceof JSPTextEditor) {
+ ((JSPTextEditor)te).runDropCommand(flavor, data);
+ return true;
+ }
+ //TODO create valueProvider?
+ final IEditorInput ei = te.getEditorInput();
+ final ISelectionProvider sp = te.getSelectionProvider();
+ final ISourceViewer sv = getSourceViewer(te);
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+// if(parentEditor.getVisualEditor().getController()!=null ) {
+ DropCommandFactory.getInstance()
+ .getDropCommand(flavor, JSPTagProposalFactory.getInstance())
+ .execute(
+ new DropData(
+ flavor,
+ data,
+ ei,
+ sv,
+ sp
+ )
+ );
+// }
+ }
+ });
+ return true;
+ }
+
+ ISourceViewer getSourceViewer(ITextEditor editor) {
+ if(!(editor instanceof AbstractTextEditor)) return null;
+ AbstractTextEditor ae = (AbstractTextEditor)editor;
+ try {
+ Method m = AbstractTextEditor.class.getDeclaredMethod("getSourceViewer", new
Class[0]);
+ m.setAccessible(true);
+ return (ISourceViewer)m.invoke(ae, new Object[0]);
+ } catch (NoSuchMethodException e1) {
+ return null;
+ } catch (InvocationTargetException e2) {
+ return null;
+ } catch (IllegalAccessException e2) {
+ return null;
+ }
+ }
+
+ public int execute() {
+ boolean result = runDropCommand(flavor, data, textEditor);
+ return result ? 0 : 1;
+ }
+
+ public void setObject(Object object) {
+ Properties p = (Properties)object;
+ flavor = p.getProperty("flavor");
+ data = p.getProperty("data");
+ textEditor = (ITextEditor)p.get("textEditor");
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/DefaultDropCommandRunner.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java 2009-07-20
16:42:31 UTC (rev 16684)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java 2009-07-20
16:46:21 UTC (rev 16685)
@@ -86,7 +86,6 @@
JSPDialogContentProposalProvider cpp = new JSPDialogContentProposalProvider();
cpp.setContext(context);
IContentProposal[] ps = cpp.getProposals("#{}", 2); //$NON-NLS-1$
- System.out.println(ps.length);
hasProposals = ((ps != null) && (ps.length > 0));
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPPropertySourceAdapter.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPPropertySourceAdapter.java 2009-07-20
16:42:31 UTC (rev 16684)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPPropertySourceAdapter.java 2009-07-20
16:46:21 UTC (rev 16685)
@@ -77,6 +77,7 @@
private IPropertyDescriptor[] fDescriptors = null;
private ValueHelper valueHelper = new ValueHelper();
IPageContext pageContext;
+ JspContentAssistProcessor processor;
int offset = 0;
KbQuery kbQuery, kbQueryAttr;
private Set attributeNames = new HashSet();
@@ -103,7 +104,7 @@
fCaseSensitive = adapter.getTagNameCase() == DocumentTypeAdapter.STRICT_CASE;
offset = ((IDOMElement)fNode).getStartOffset() + ("" +
fNode.getNodeType()).length(); //$NON-NLS-1$
}
- JspContentAssistProcessor processor = valueHelper.isFacetets() ? new
FaceletPageContectAssistProcessor() : new JspContentAssistProcessor();
+ processor = valueHelper.isFacetets() ? new FaceletPageContectAssistProcessor() : new
JspContentAssistProcessor();
processor.createContext(getTextViewer(), offset);
pageContext = processor.getContext();
kbQuery = createKbQuery(processor);
@@ -405,6 +406,7 @@
context.setProperty("attributeName", attributeName);
context.put("valueHelper", valueHelper);
context.put("pageContext", pageContext);
+ context.put("processor", processor);
JSPPropertyDescriptor descriptor = new JSPPropertyDescriptor(context, attributeName,
attributeName);
descriptor.setCategory(getCategory(null));
descriptor.setDescription(attributeName);
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/ValueHelper.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/ValueHelper.java 2009-07-20
16:42:31 UTC (rev 16684)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/ValueHelper.java 2009-07-20
16:46:21 UTC (rev 16685)
@@ -10,16 +10,18 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController;
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.jboss.tools.common.kb.TagDescriptor;
import org.jboss.tools.common.model.project.IPromptingProvider;
@@ -99,17 +101,14 @@
}
public JspContentAssistProcessor createContentAssistProcessor() {
- JSPTextEditor jspEditor = getJSPTextEditor();
- if(jspEditor == null) return null;
return isFacetets() ? new FaceletPageContectAssistProcessor() : new
JspContentAssistProcessor();
}
public IPageContext createPageContext(JspContentAssistProcessor processor, int offset)
{
- JSPTextEditor jspEditor = getJSPTextEditor();
- if(jspEditor == null) return null;
- processor.createContext(jspEditor.getTextViewer(), offset);
+ ISourceViewer sv = getSourceViewer();
+ if(sv == null) return null;
+ processor.createContext(sv, offset);
return processor.getContext();
-
}
protected JSPTextEditor getJSPTextEditor() {
@@ -162,9 +161,7 @@
}
public IEditorInput getEditorInput() {
-
IEditorPart editor =
ModelUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
-
return editor.getEditorInput();
}
@@ -193,19 +190,6 @@
}
}
- public IDocument getDocument() {
- IEditorPart editor =
ModelUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- if(editor instanceof JSPMultiPageEditor) {
- JSPTextEditor jspEditor = ((JSPMultiPageEditor)editor).getJspEditor();
- return jspEditor.getDocumentProvider().getDocument(editor.getEditorInput());
- } else if(editor instanceof StructuredTextEditor) {
- StructuredTextEditor jspEditor = ((StructuredTextEditor)editor);
- return jspEditor.getDocumentProvider().getDocument(editor.getEditorInput());
- }
-
- return null;
- }
-
//Support of StructuredTextEditor
boolean init2() {
if(isVisualContextInitialized) return true;
@@ -229,7 +213,6 @@
List<TaglibData> list = tldManager.getTagLibs();
if(list == null) return;
isFacelets = false;
- IDocument document = getDocument();
for(int i = 0; i < list.size(); i++) {
TaglibData data = list.get(i);
isFacelets = isFacelets ||
data.getUri().equals(FaceletsHtmlContentAssistProcessor.faceletUri);
@@ -252,4 +235,22 @@
}
return null;
}
+
+ public ISourceViewer getSourceViewer() {
+ JSPTextEditor jspEditor = getJSPTextEditor();
+ if(jspEditor != null) return jspEditor.getTextViewer();
+ IEditorPart editor =
ModelUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if (editor == null) return null;
+ if(editor instanceof AbstractTextEditor) {
+ try {
+ Method m = AbstractTextEditor.class.getDeclaredMethod("getSourceViewer",
new Class[0]);
+ m.setAccessible(true);
+ return (ISourceViewer)m.invoke(editor, new Object[0]);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
}