Author: mareshkau
Date: 2010-05-27 03:31:36 -0400 (Thu, 27 May 2010)
New Revision: 22360
Modified:
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/SetupTemplateContributionItem.java
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
Log:
https://jira.jboss.org/browse/JBIDE-5996 patch for 3.1 has been applied
Modified:
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java
===================================================================
---
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java 2010-05-27
06:55:17 UTC (rev 22359)
+++
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java 2010-05-27
07:31:36 UTC (rev 22360)
@@ -23,11 +23,13 @@
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.ui.util.ModelUtilities;
+import org.jboss.tools.jst.jsp.editor.IVisualContext;
import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor;
+import org.jboss.tools.jst.jsp.jspeditor.SourceEditorPageContext;
import org.jboss.tools.jst.web.tld.TaglibData;
import org.jboss.tools.jst.web.tld.URIConstants;
-import org.jboss.tools.vpe.editor.VpeEditorPart;
-import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.menu.action.ComplexAction;
import org.jboss.tools.vpe.editor.menu.action.InsertAction2;
import org.jboss.tools.vpe.editor.menu.action.SelectThisTagAction;
@@ -42,19 +44,20 @@
*/
public class InsertContributionItem extends ContributionItem {
- private final Node node;
- private final StructuredTextEditor sourceEditor;
- private final VpePageContext pageContext;
private final static String NAME_PROPERTY = "name"; //$NON-NLS-1$
private final static String HIDDEN_PROPERTY = "hidden"; //$NON-NLS-1$
private final static String ELEMENT_TYPE_PROPERTY
- = "element type"; //$NON-NLS-1$
+ = "element type"; //$NON-NLS-1$
private final static String END_TEXT_PROPERTY = "end text"; //$NON-NLS-1$
private final static String TAG_ELEMENT_TYPE = "macro"; //$NON-NLS-1$
private final static String TAGLIB_ELEMENT_TYPE = "sub-group"; //$NON-NLS-1$
private final static String LEFT_ANGLE_BRACKET = "<"; //$NON-NLS-1$
private final static String RIGHT_ANGLE_BRACKET = ">"; //$NON-NLS-1$
-
+
+ private final Node node;
+ private final StructuredTextEditor sourceEditor;
+ private final JSPMultiPageEditor editor;
+
/**
* Creates an {@code InsertContributionItem}
* to make insert actions on the currently selected node.
@@ -70,12 +73,10 @@
public InsertContributionItem(final Node node) {
this.node = node;
- final JSPMultiPageEditor editor = (JSPMultiPageEditor)
+ editor = (JSPMultiPageEditor)
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getActiveEditor();
this.sourceEditor = editor.getSourceEditor();
- this.pageContext = ((VpeEditorPart) editor.getVisualEditor())
- .getController().getPageContext();
}
@Override
@@ -90,7 +91,7 @@
final MenuManager paletteManuManager = new MenuManager(
insertItem.getMessage());
final XModelObject model = ModelUtilities.getPreferenceModel()
- .getByPath("%Palette%"); //$NON-NLS-1$
+ .getByPath("%Palette%"); //$NON-NLS-1$
paletteManuManager.addMenuListener(new InsertMenuListener(
model, insertItem));
paletteManuManager.setRemoveAllWhenShown(true);
@@ -180,24 +181,37 @@
}
private String getPrefix(XModelObject modelObject) {
- final List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(
- (Node) ((IStructuredSelection) sourceEditor
- .getSelectionProvider().getSelection())
- .getFirstElement(), pageContext);
-
- final String uri = modelObject
- .getAttributeValue(URIConstants.LIBRARY_URI);
- String prefix = null;
- final TaglibData sourceNodeTaglib = XmlUtil
- .getTaglibForURI(uri, taglibs);
-
- if (sourceNodeTaglib == null) {
- prefix = modelObject
- .getAttributeValue(URIConstants.DEFAULT_PREFIX);
+ String prefix = Constants.EMPTY;
+ List<TaglibData> taglibs = null;
+ /*
+ * Fixes
https://jira.jboss.org/jira/browse/JBIDE-5996
+ * Get taglibs from the SourceEditorPageContext.
+ */
+ if (sourceEditor instanceof JSPTextEditor) {
+ IVisualContext context = ((JSPTextEditor) sourceEditor).getPageContext();
+ if (context instanceof SourceEditorPageContext) {
+ SourceEditorPageContext sourcePageContext = (SourceEditorPageContext) context;
+ taglibs = sourcePageContext.getTagLibs();
+ }
+ }
+
+ if (null == taglibs) {
+ VpePlugin.getDefault().logError(
+ VpeUIMessages.CANNOT_LOAD_TAGLIBS_FROM_PAGE_CONTEXT);
} else {
- prefix = sourceNodeTaglib.getPrefix();
+ final String uri = modelObject
+ .getAttributeValue(URIConstants.LIBRARY_URI);
+
+ final TaglibData sourceNodeTaglib = XmlUtil
+ .getTaglibForURI(uri, taglibs);
+
+ if (sourceNodeTaglib == null) {
+ prefix = modelObject
+ .getAttributeValue(URIConstants.DEFAULT_PREFIX);
+ } else {
+ prefix = sourceNodeTaglib.getPrefix();
+ }
}
-
return prefix;
}
}
Modified:
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/SetupTemplateContributionItem.java
===================================================================
---
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/SetupTemplateContributionItem.java 2010-05-27
06:55:17 UTC (rev 22359)
+++
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/SetupTemplateContributionItem.java 2010-05-27
07:31:36 UTC (rev 22360)
@@ -20,6 +20,7 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.vpe.editor.VpeController;
import org.jboss.tools.vpe.editor.VpeEditorPart;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
@@ -35,52 +36,61 @@
public class SetupTemplateContributionItem extends ActionContributionItem {
private VpePageContext pageContext;
-
private StructuredTextEditor sourceEditor;
+ private final JSPMultiPageEditor editor;
+ private final VpeController vpeController;
/**
- *
+ * Constructor
*/
public SetupTemplateContributionItem() {
super(new SetupTemplateAction());
- final JSPMultiPageEditor editor = (JSPMultiPageEditor) PlatformUI
+ editor = (JSPMultiPageEditor) PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
this.sourceEditor = editor.getSourceEditor();
- this.pageContext = ((VpeEditorPart) editor.getVisualEditor())
- .getController().getPageContext();
+ /*
+ * Fixes
https://jira.jboss.org/jira/browse/JBIDE-5996
+ * When VisualEditor is not initialized it is impossible
+ * to fill this menu item.
+ */
+ this.vpeController = ((VpeEditorPart) editor.getVisualEditor()).getController();
+ if (null != vpeController) {
+ this.pageContext = vpeController.getPageContext();
+ } else {
+ this.pageContext = null;
+ }
getAction().setPageContext(pageContext);
}
@Override
public void fill(Menu menu, int index) {
-
- IStructuredSelection selection = (IStructuredSelection) sourceEditor
+ if (null != vpeController) {
+ IStructuredSelection selection = (IStructuredSelection) sourceEditor
.getSelectionProvider().getSelection();
-
- if (selection != null && selection.size() == 1
- && selection.getFirstElement() instanceof Element) {
- Element element = (Element) selection.getFirstElement();
- VpeElementMapping elementMapping = (VpeElementMapping) pageContext
- .getDomMapping().getNodeMapping(element);
- if (elementMapping != null
- && elementMapping.getTemplate() != null
- && elementMapping.getTemplate().getType()
- == VpeHtmlTemplate.TYPE_ANY) {
-
- getAction().setText(NLS.bind(
- VpeUIMessages.SETUP_TEMPLATE_FOR_MENU,
- element.getNodeName()));
- getAction().setActionNode(element);
- getAction().setData(elementMapping.getTemplate().getAnyData());
- /*
- *
https://jira.jboss.org/jira/browse/JBIDE-4541
- * Index should be used as is.
- */
- super.fill(menu, index);
+ if (selection != null && selection.size() == 1
+ && selection.getFirstElement() instanceof Element) {
+ Element element = (Element) selection.getFirstElement();
+ VpeElementMapping elementMapping = (VpeElementMapping) pageContext
+ .getDomMapping().getNodeMapping(element);
+ if (elementMapping != null
+ && elementMapping.getTemplate() != null
+ && elementMapping.getTemplate().getType()
+ == VpeHtmlTemplate.TYPE_ANY) {
+
+ getAction().setText(NLS.bind(
+ VpeUIMessages.SETUP_TEMPLATE_FOR_MENU,
+ element.getNodeName()));
+ getAction().setActionNode(element);
+ getAction().setData(elementMapping.getTemplate().getAnyData());
+ /*
+ *
https://jira.jboss.org/jira/browse/JBIDE-4541
+ * Index should be used as is.
+ */
+ super.fill(menu, index);
+ }
}
}
-
}
@Override
Modified:
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
===================================================================
---
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-05-27
06:55:17 UTC (rev 22359)
+++
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-05-27
07:31:36 UTC (rev 22360)
@@ -154,5 +154,6 @@
public static String BROWSE_BUTTON_TEXT;
public static String NONE_TEMPLATES_WERE_ADDED;
public static String COULD_NOT_SET_TABLE_SELECTION;
+ public static String CANNOT_LOAD_TAGLIBS_FROM_PAGE_CONTEXT;
}
Modified:
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
---
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-05-27
06:55:17 UTC (rev 22359)
+++
branches/jbosstools-3.1.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-05-27
07:31:36 UTC (rev 22360)
@@ -140,4 +140,7 @@
IMPORT_UNKNOWN_TAGS_PAGE_TITLE=Unknown tags templates
IMPORT_UNKNOWN_TAGS_PAGE_DESCRIPTION=Import unknown tags templates from external file
NONE_TEMPLATES_WERE_ADDED=None of the templates were added.
-COULD_NOT_SET_TABLE_SELECTION=Could not set table selection.
\ No newline at end of file
+COULD_NOT_SET_TABLE_SELECTION=Could not set table selection.
+
+# Other messages
+CANNOT_LOAD_TAGLIBS_FROM_PAGE_CONTEXT=Cannot load taglibs from PageContext!