Index: plugin.xml
===================================================================
--- plugin.xml (revision 14211)
+++ plugin.xml (working copy)
@@ -92,6 +92,13 @@
id="org.jboss.tools.vpe.editor.menu.InsertContributionItem">
+
+
+
@@ -105,5 +112,12 @@
id="org.jboss.tools.vpe.editor.menu.InsertContributionItem">
+
+
+
Index: src/org/jboss/tools/vpe/editor/menu/MenuCreationHelper.java
===================================================================
--- src/org/jboss/tools/vpe/editor/menu/MenuCreationHelper.java (revision 14211)
+++ src/org/jboss/tools/vpe/editor/menu/MenuCreationHelper.java (working copy)
@@ -214,7 +214,7 @@
&& elementMapping.getTemplate().getType() == VpeHtmlTemplate.TYPE_ANY) {
final VpeTemplate selectedTemplate = elementMapping.getTemplate();
manager.add(new VpeAction(NLS.bind(VpeUIMessages.SETUP_TEMPLATE_FOR_MENU,
- "<" + node.getNodeName() + ">"), node) { //$NON-NLS-1$ //$NON-NLS-2$
+ node.getNodeName() ), node) { //$NON-NLS-1$ //$NON-NLS-2$
public void run() {
boolean isCorrectNS = pageContext.isCorrectNS(actionNode);
VpeAnyData data = null;
Index: src/org/jboss/tools/vpe/editor/menu/SetupTemplateContributionItem.java
===================================================================
--- src/org/jboss/tools/vpe/editor/menu/SetupTemplateContributionItem.java (revision 0)
+++ src/org/jboss/tools/vpe/editor/menu/SetupTemplateContributionItem.java (revision 0)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.vpe.editor.menu;
+
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+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.VpeEditorPart;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
+import org.jboss.tools.vpe.editor.menu.action.SetupTemplateAction;
+import org.jboss.tools.vpe.editor.template.VpeHtmlTemplate;
+import org.jboss.tools.vpe.editor.util.Constants;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+import org.w3c.dom.Element;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public class SetupTemplateContributionItem extends ActionContributionItem {
+
+ private VpePageContext pageContext;
+
+ private StructuredTextEditor sourceEditor;
+
+ /**
+ *
+ */
+ public SetupTemplateContributionItem() {
+ super(new SetupTemplateAction());
+ JSPMultiPageEditor editor = (JSPMultiPageEditor) PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getActiveEditor();
+ this.sourceEditor = editor.getSourceEditor();
+ this.pageContext = ((VpeEditorPart) editor.getVisualEditor())
+ .getController().getPageContext();
+ ((SetupTemplateAction) getAction()).setPageContext(pageContext);
+ }
+
+ /**
+ *
+ */
+ public SetupTemplateContributionItem(VpePageContext pageContext,
+ StructuredTextEditor sourceEditor) {
+ super(new SetupTemplateAction(pageContext));
+ this.pageContext = pageContext;
+ this.sourceEditor = sourceEditor;
+
+ }
+
+ @Override
+ public void fill(Menu menu, int index) {
+
+ 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) {
+
+ ((SetupTemplateAction) getAction()).setText(NLS.bind(
+ VpeUIMessages.SETUP_TEMPLATE_FOR_MENU, element
+ .getNodeName()));
+ ((SetupTemplateAction) getAction()).setActionNode(element);
+ ((SetupTemplateAction) getAction()).setData(elementMapping
+ .getTemplate().getAnyData());
+ MenuItem item = new MenuItem(menu, SWT.SEPARATOR, index );
+ super.fill(menu, index+1);
+ }
+ }
+
+ }
+
+}
Index: src/org/jboss/tools/vpe/editor/menu/action/SetupTemplateAction.java
===================================================================
--- src/org/jboss/tools/vpe/editor/menu/action/SetupTemplateAction.java (revision 0)
+++ src/org/jboss/tools/vpe/editor/menu/action/SetupTemplateAction.java (revision 0)
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.vpe.editor.menu.action;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.VpeAnyData;
+import org.jboss.tools.vpe.editor.template.VpeEditAnyDialog;
+import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+import org.w3c.dom.Node;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public class SetupTemplateAction extends Action {
+
+ private Node actionNode;
+
+ private VpePageContext pageContext;
+
+ public void setActionNode(Node actionNode) {
+ this.actionNode = actionNode;
+ }
+
+ public void setPageContext(VpePageContext pageContext) {
+ this.pageContext = pageContext;
+ }
+
+ public void setData(VpeAnyData data) {
+ this.data = data;
+ }
+
+ private VpeAnyData data;
+
+ /**
+ * @param text
+ */
+ public SetupTemplateAction(String title, Node actionNode, VpeAnyData data,
+ VpePageContext pageContext) {
+ super(title);
+ this.actionNode = actionNode;
+ this.pageContext = pageContext;
+ this.data = data;
+
+ }
+
+ public SetupTemplateAction(VpePageContext pageContext) {
+ this.pageContext = pageContext;
+ }
+
+ public SetupTemplateAction() {
+ }
+
+ @Override
+ public void run() {
+ boolean isCorrectNS = pageContext.isCorrectNS(actionNode);
+ if (isCorrectNS) {
+ data.setUri(pageContext.getSourceTaglibUri(actionNode));
+ data.setName(actionNode.getNodeName());
+ }
+
+ Shell shell = PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow().getShell();
+
+ if (isCorrectNS) {
+ VpeEditAnyDialog editDialog = new VpeEditAnyDialog(shell, data);
+ editDialog.open();
+ } else {
+ MessageBox message = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
+ message.setMessage(VpeUIMessages.NAMESPACE_NOT_DEFINED);
+ message.open();
+ }
+ if (data != null && data.isChanged())
+ VpeTemplateManager.getInstance().setAnyTemplate(data);
+ }
+}
Index: src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
--- src/org/jboss/tools/vpe/messages/messages.properties (revision 14211)
+++ src/org/jboss/tools/vpe/messages/messages.properties (working copy)
@@ -73,7 +73,7 @@
MAX_VISUAL_PANE=Maximize Visual Pane
RESTORE_PREVIOUS_LOCATION=Restore Previous Location
BACKGROUND_COLOR_TIP=Choose background color
-SETUP_TEMPLATE_FOR_MENU=Setup Template for {0}
+SETUP_TEMPLATE_FOR_MENU=Setup Template for <{0}>
INSERT_AROUND=Insert Around
INSERT_BEFORE=Insert Before
INSERT_AFTER=Insert After