Author: dmaliarevich
Date: 2010-03-05 02:58:30 -0500 (Fri, 05 Mar 2010)
New Revision: 20679
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/SetupTemplateContributionItem.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5996 -- disabling menu items when there is no
visual 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
02:53:07 UTC (rev 20678)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java 2010-03-05
07:58:30 UTC (rev 20679)
@@ -26,6 +26,7 @@
import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
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.editor.menu.action.ComplexAction;
@@ -42,19 +43,22 @@
*/
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 VpePageContext pageContext;
+ private final JSPMultiPageEditor editor;
+ private final VpeController vpeController;
+
/**
* Creates an {@code InsertContributionItem}
* to make insert actions on the currently selected node.
@@ -70,32 +74,45 @@
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();
+ /*
+ * 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) {
- /*
- * Setting each InsertType to correct position in the menu
- */
- for (final InsertType insertItem : InsertType.values()) {
+ if (null != vpeController) {
/*
- * Use MenuManager to create submenu.
+ * Setting each InsertType to correct position in the menu
*/
- final MenuManager paletteManuManager = new MenuManager(
- insertItem.getMessage());
- final XModelObject model = ModelUtilities.getPreferenceModel()
+ 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++;
+ paletteManuManager.addMenuListener(new InsertMenuListener(
+ model, insertItem));
+ paletteManuManager.setRemoveAllWhenShown(true);
+ paletteManuManager.fill(menu, index);
+ index++;
+ }
+ } else {
+// menu.setVisible(false);
}
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/SetupTemplateContributionItem.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/SetupTemplateContributionItem.java 2010-03-05
02:53:07 UTC (rev 20678)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/SetupTemplateContributionItem.java 2010-03-05
07:58:30 UTC (rev 20679)
@@ -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