Author: dmaliarevich
Date: 2010-03-05 10:30:58 -0500 (Fri, 05 Mar 2010)
New Revision: 20692
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
Log:
https://jira.jboss.org/jira/browse/JBIDE-5996 -- InsertContributionItem is shown for the
source editor.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java 2010-03-05
15:17:04 UTC (rev 20691)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java 2010-03-05
15:30:58 UTC (rev 20692)
@@ -23,12 +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.VpeController;
-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;
@@ -55,9 +56,7 @@
private final Node node;
private final StructuredTextEditor sourceEditor;
- private final VpePageContext pageContext;
private final JSPMultiPageEditor editor;
- private final VpeController vpeController;
/**
* Creates an {@code InsertContributionItem}
@@ -78,39 +77,26 @@
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getActiveEditor();
this.sourceEditor = editor.getSourceEditor();
- /*
- * 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;
- }
}
@Override
public void fill(Menu menu, int index) {
- if (null != vpeController) {
+ /*
+ * Setting each InsertType to correct position in the menu
+ */
+ for (final InsertType insertItem : InsertType.values()) {
/*
- * Setting each InsertType to correct position in the menu
+ * Use MenuManager to create submenu.
*/
- for (final InsertType insertItem : InsertType.values()) {
- /*
- * Use MenuManager to create submenu.
- */
- final MenuManager paletteManuManager = new MenuManager(
- insertItem.getMessage());
- final XModelObject model = ModelUtilities.getPreferenceModel()
- .getByPath("%Palette%"); //$NON-NLS-1$
- paletteManuManager.addMenuListener(new InsertMenuListener(
- model, insertItem));
- paletteManuManager.setRemoveAllWhenShown(true);
- paletteManuManager.fill(menu, index);
- index++;
- }
+ final MenuManager paletteManuManager = new MenuManager(
+ insertItem.getMessage());
+ final XModelObject model = ModelUtilities.getPreferenceModel()
+ .getByPath("%Palette%"); //$NON-NLS-1$
+ paletteManuManager.addMenuListener(new InsertMenuListener(
+ model, insertItem));
+ paletteManuManager.setRemoveAllWhenShown(true);
+ paletteManuManager.fill(menu, index);
+ index++;
}
}
@@ -195,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:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-03-05
15:17:04 UTC (rev 20691)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-03-05
15:30:58 UTC (rev 20692)
@@ -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:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-03-05
15:17:04 UTC (rev 20691)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-03-05
15:30:58 UTC (rev 20692)
@@ -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!
\ No newline at end of file