Author: yradtsevich
Date: 2009-04-25 14:40:08 -0400 (Sat, 25 Apr 2009)
New Revision: 14926
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertType.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/InsertAction2.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/AbstractActionManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/BaseActionManager.java
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/action/InsertAction.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:
CODING IN PROGRESS - issue JBIDE-3819: Create action 'Insert Into' in the context
menu of VPE
https://jira.jboss.org/jira/browse/JBIDE-3819
- the action has been created for the text editor context menu.
- code of the context menu has been refactored.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/AbstractActionManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/AbstractActionManager.java 2009-04-25
15:59:55 UTC (rev 14925)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/AbstractActionManager.java 2009-04-25
18:40:08 UTC (rev 14926)
@@ -413,17 +413,6 @@
}
}
- public void fillContextMenu(IMenuManager menuManager, ISelection selection) {
- List selectionList = new ArrayList();
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection es = (IStructuredSelection) selection;
- for (Iterator i = es.iterator(); i.hasNext();) {
- selectionList.add(i.next());
- }
- }
- contributeActions(menuManager, selectionList);
- }
-
public void fillContextMenuForVpe(IMenuManager menuManager,
ISelection selection) {
List selectionList = new ArrayList();
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/BaseActionManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/BaseActionManager.java 2009-04-25
15:59:55 UTC (rev 14925)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/BaseActionManager.java 2009-04-25
18:40:08 UTC (rev 14926)
@@ -30,7 +30,6 @@
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction;
import
org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.ModelQueryActionHelper;
import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.ModelQueryImpl;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.ui.internal.actions.MenuBuilder;
import org.eclipse.wst.xml.ui.internal.util.XMLCommonResources;
import org.w3c.dom.Attr;
@@ -53,9 +52,8 @@
public static final String INSERT_AROUND_MENU = "Insert Around";
public static final String INSERT_BEFORE_MENU = "Insert Before";
public static final String INSERT_AFTER_MENU = "Insert After";
+ public static final String REPLACE_TAG_MENU = "Replace With";
public static final String INSERT_TAG_MENU = "Insert Tag";
- public static final String REPLACE_TAG_MENU = XMLCommonResources
- .getInstance().getString("_UI_MENU_REPLACE_WITH"); //$NON-NLS-1$
private ActionHelper actionHelper;
@@ -100,54 +98,12 @@
abstract protected Action createDeleteAction(List selection);
- public void contributeActions(IMenuManager menu, List selection) {
- int editMode = modelQuery.getEditMode();
- int ic = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ?
ModelQuery.INCLUDE_CHILD_NODES
- | ModelQuery.INCLUDE_SEQUENCE_GROUPS
- : ModelQuery.INCLUDE_CHILD_NODES;
- int vc = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ?
ModelQuery.VALIDITY_STRICT
- : ModelQuery.VALIDITY_NONE;
-
- List implicitlySelectedNodeList = null;
-
- if (selection.size() > 0) {
- implicitlySelectedNodeList = getSelectedNodes(selection, true);
-
- // contribute delete actions
- contributeDeleteActions(menu, implicitlySelectedNodeList, ic, vc);
- }
-
- if (selection.size() == 1) {
- Node node = (Node) selection.get(0);
-
- // contribute edit actions
- contributeEditActions(menu, node);
-
- // contribute add child actions
- contributeAddChildActions(menu, node, ic, vc);
-
- // contribute add before actions
- contributeAddSiblingActions(menu, node, ic, vc, false);
- }
-
- if (selection.size() > 0) {
- // contribute replace actions
- contributeReplaceActions(menu, implicitlySelectedNodeList, ic, vc);
- }
-
- if (selection.size() == 0) {
- Document document = ((IDOMModel) model).getDocument();
- contributeAddDocumentChildActions(menu, document, ic, vc);
- contributeEditGrammarInformationActions(menu, document);
- }
- }
-
public void contributeActionsForVpe(IMenuManager menu, List selection) {
int editMode = modelQuery.getEditMode();
- int ic = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ?
ModelQuery.INCLUDE_CHILD_NODES
+ int includeOptions = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ?
ModelQuery.INCLUDE_CHILD_NODES
| ModelQuery.INCLUDE_SEQUENCE_GROUPS
: ModelQuery.INCLUDE_CHILD_NODES;
- int vc = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ?
ModelQuery.VALIDITY_STRICT
+ int validityChecking = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ?
ModelQuery.VALIDITY_STRICT
: ModelQuery.VALIDITY_NONE;
List implicitlySelectedNodeList = null;
@@ -158,12 +114,12 @@
Node node = (Node) selection.get(0);
// contribute add before actions
- contributeAddSiblingActions(menu, node, ic, vc, true);
+ contributeAddSiblingActions(menu, node, true);
}
// contribute replace actions
- contributeReplaceActions(menu, implicitlySelectedNodeList, ic, vc);
- } else if (selection.size() == 0) {
+ contributeReplaceActions(menu, implicitlySelectedNodeList, includeOptions,
validityChecking);
+ } else {
IMenuManager addTagMenu = new MyMenuManager(INSERT_TAG_MENU, true);
menu.add(addTagMenu);
}
@@ -171,10 +127,10 @@
public void contributeDeleteActionForVpe(IMenuManager menu, List selection) {
int editMode = modelQuery.getEditMode();
- int ic = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ?
ModelQuery.INCLUDE_CHILD_NODES
+ int includeOptions = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ?
ModelQuery.INCLUDE_CHILD_NODES
| ModelQuery.INCLUDE_SEQUENCE_GROUPS
: ModelQuery.INCLUDE_CHILD_NODES;
- int vc = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ?
ModelQuery.VALIDITY_STRICT
+ int validityChecking = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ?
ModelQuery.VALIDITY_STRICT
: ModelQuery.VALIDITY_NONE;
List implicitlySelectedNodeList = null;
@@ -184,7 +140,7 @@
menu.add(new Separator());
// contribute delete actions
- contributeDeleteActions(menu, implicitlySelectedNodeList, ic, vc);
+ contributeDeleteActions(menu, implicitlySelectedNodeList, includeOptions,
validityChecking);
}
}
@@ -227,7 +183,7 @@
}
protected void contributeAddChildActions(IMenuManager menu, Node node,
- int ic, int vc) {
+ int includeOptions, int validityChecking) {
int nodeType = node.getNodeType();
if (nodeType == Node.ELEMENT_NODE) {
@@ -251,14 +207,14 @@
List modelQueryActionList = new ArrayList();
modelQuery
.getInsertActions(element, ed, -1,
- ModelQuery.INCLUDE_ATTRIBUTES, vc,
+ ModelQuery.INCLUDE_ATTRIBUTES, validityChecking,
modelQueryActionList);
addActionHelper(addAttributeMenu, modelQueryActionList, 2);
// add insert child node actions
//
modelQueryActionList = new ArrayList();
- modelQuery.getInsertActions(element, ed, -1, ic, vc,
+ modelQuery.getInsertActions(element, ed, -1, includeOptions, validityChecking,
modelQueryActionList);
addActionHelper(addChildMenu, modelQueryActionList, 2);
}
@@ -280,87 +236,17 @@
}
protected void contributeAddSiblingActions(IMenuManager menu, Node node,
- int ic, int vc, boolean visible) {
+ boolean visible) {
IMenuManager addAroundMenu = new MyMenuManager(INSERT_AROUND_MENU, visible);
IMenuManager addBeforeMenu = new MyMenuManager(INSERT_BEFORE_MENU, visible);
IMenuManager addAfterMenu = new MyMenuManager(INSERT_AFTER_MENU, visible);
menu.add(addAroundMenu);
menu.add(addBeforeMenu);
menu.add(addAfterMenu);
-
-// Node parentNode = node.getParentNode();
-// if (parentNode != null) {
-// int index = getIndex(parentNode, node);
-// if (textNodeSplitter != null)
-// index = textNodeSplitter.getSplitIndex(index);
-// if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
-// Element parentElement = (Element) parentNode;
-// CMElementDeclaration parentED = modelQuery
-// .getCMElementDeclaration(parentElement);
-// if (parentED != null) {
-// // 'Add Before...' and 'Add After...' actions
-// //
-//
-// List modelQueryActionList = new ArrayList();
-// modelQuery.getInsertActions(parentElement, parentED, index,
-// ic, vc, modelQueryActionList);
-// modelQueryActionList = actionHelper
-// .modifyActionList(modelQueryActionList);
-// addActionHelper(addAroundMenu, modelQueryActionList, 1);
-//
-// modelQueryActionList = new ArrayList();
-// modelQuery.getInsertActions(parentElement, parentED, index,
-// ic, vc, modelQueryActionList);
-// addActionHelper(addBeforeMenu, modelQueryActionList, 2);
-//
-// modelQueryActionList = new ArrayList();
-// ActionHelper helper = new ActionHelper(
-// (ModelQueryImpl) modelQuery);
-// if (textNodeSplitter != null)
-// helper.getInsertActions(parentElement, parentED, index,
-// ic, vc, modelQueryActionList);
-// else
-// helper.getInsertActions(parentElement, parentED,
-// index + 1, ic, vc, modelQueryActionList);
-// addActionHelper(addAfterMenu, modelQueryActionList, 3);
-// }
-// contributeUnconstrainedAddElementAction(addBeforeMenu,
-// parentElement, parentED, index);
-// contributeUnconstrainedAddElementAction(addAfterMenu,
-// parentElement, parentED, index + 1);
-// } else if (parentNode.getNodeType() == Node.DOCUMENT_NODE) {
-// Document document = (Document) parentNode;
-// CMDocument cmDocument = modelQuery
-// .getCorrespondingCMDocument(parentNode);
-// if (cmDocument != null) {
-// // add possible root element insertions
-// //
-// List modelQueryActionList = new ArrayList();
-// modelQuery.getInsertActions(document, cmDocument, index,
-// ic, vc, modelQueryActionList);
-// modelQueryActionList = actionHelper
-// .modifyActionList(modelQueryActionList);
-// addActionHelper(addAroundMenu, modelQueryActionList, 1);
-//
-// modelQueryActionList = new ArrayList();
-// modelQuery.getInsertActions(document, cmDocument, index,
-// ic, vc, modelQueryActionList);
-// addActionHelper(addAfterMenu, modelQueryActionList, 2);
-//
-// modelQueryActionList = new ArrayList();
-// modelQuery.getInsertActions(document, cmDocument,
-// index + 1, ic, vc, modelQueryActionList);
-// addActionHelper(addAfterMenu, modelQueryActionList, 3);
-// }
-//
-// contributeUnconstrainedAddElementAction(addBeforeMenu, document, index);
-// contributeUnconstrainedAddElementAction(addAfterMenu, document, index + 1);
-// }
-// }
}
protected void contributeAddDocumentChildActions(IMenuManager menu,
- Document document, int ic, int vc) {
+ Document document) {
IMenuManager addChildMenu = new MyMenuManager(XMLCommonResources
.getInstance().getString("_UI_MENU_ADD_CHILD")); //$NON-NLS-1$
menu.add(addChildMenu);
@@ -373,7 +259,7 @@
}
protected void contributeReplaceActions(IMenuManager menu,
- List selectedNodeList, int ic, int vc) {
+ List selectedNodeList, int includeOptions, int validityChecking) {
// 'Replace With...' actions
//
//Fix for JBIDE-3428
@@ -393,7 +279,8 @@
if (parentED != null) {
List replaceActionList = new Vector();
modelQuery.getReplaceActions(parentElement, parentED,
- selectedNodeList, ic, vc, replaceActionList);
+ selectedNodeList, includeOptions, validityChecking,
+ replaceActionList);
addActionHelper(replaceWithMenu, replaceActionList, 2);
}
}
@@ -407,8 +294,8 @@
}
protected void contributeDeleteActions(IMenuManager menu, List list,
- int ic, int vc) {
- boolean canRemove = modelQuery.canRemove(list, vc);
+ int includeOptions, int validityChecking) {
+ boolean canRemove = modelQuery.canRemove(list, validityChecking);
// a delete action with an empty list will produce a disabled menu item
//
@@ -451,7 +338,9 @@
Element parentElement, CMElementDeclaration parentEd, int index) {
if (isUnconstrainedActionAllowed()) {
if (parentEd == null
- || parentEd.getProperty("isInferred") == Boolean.TRUE ||
(modelQuery.getEditMode() != ModelQuery.EDIT_MODE_CONSTRAINED_STRICT &&
isElementAllowed(parentEd))) { //$NON-NLS-1$
+ || parentEd.getProperty("isInferred") == Boolean.TRUE
+ || ( modelQuery.getEditMode() != ModelQuery.EDIT_MODE_CONSTRAINED_STRICT
+ && isElementAllowed(parentEd) )) { //$NON-NLS-1$
contributeAction(menu, createAddElementAction(parentElement,
null, index, 2));
}
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 2009-04-25
15:59:55 UTC (rev 14925)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java 2009-04-25
18:40:08 UTC (rev 14926)
@@ -1,17 +1,13 @@
/*******************************************************************************
- * 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
+ * Copyright (c) 2007-2009 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 java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.action.ContributionItem;
@@ -32,7 +28,7 @@
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.editor.menu.action.InsertAction;
+import org.jboss.tools.vpe.editor.menu.action.InsertAction2;
import org.jboss.tools.vpe.editor.util.Constants;
import org.jboss.tools.vpe.editor.util.NodesManagingUtil;
import org.jboss.tools.vpe.editor.util.SelectionUtil;
@@ -42,46 +38,24 @@
/**
* @author Sergey Dzmitrovich
- *
+ *
*/
public class InsertContributionItem extends ContributionItem {
- private StructuredTextEditor sourceEditor;
-
- private 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$
-
- 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 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$
+ 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 static String LEFT_ANGLE_BRACKET = "<"; //$NON-NLS-1$
- private final static String RIGHT_ANGLE_BRACKET = ">"; //$NON-NLS-1$
-
- private static List<String> INSERT_ITEMS;
- static {
- INSERT_ITEMS = new ArrayList<String>();
- INSERT_ITEMS.add(VpeUIMessages.INSERT_AROUND); // id = 0
- INSERT_ITEMS.add(VpeUIMessages.INSERT_BEFORE); // id = 1
- INSERT_ITEMS.add(VpeUIMessages.INSERT_AFTER); // id = 2
- INSERT_ITEMS.add(VpeUIMessages.REPLACE_WITH); // id = 3
- }
-
- // ids correspond to order of items in INSERT_ITEMS
- private int INSERT_AROUND = 0;
- private int INSERT_BEFORE = 1;
- private int INSERT_AFTER = 2;
- private int REPLACE_WITH = 3;
-
public InsertContributionItem() {
- JSPMultiPageEditor editor = (JSPMultiPageEditor) PlatformUI
+ final JSPMultiPageEditor editor = (JSPMultiPageEditor) PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
this.sourceEditor = editor.getSourceEditor();
@@ -97,199 +71,133 @@
@Override
public void fill(Menu menu, int index) {
-
- for (int i = 0; i < INSERT_ITEMS.size(); i++) {
-
- String itemName = INSERT_ITEMS.get(i);
-
- MenuItem item = new MenuItem(menu, SWT.CASCADE, index + i);
+ for (final InsertType insertItem : InsertType.values()) {
+ final String itemName = insertItem.getMessage();
+ final MenuItem item = new MenuItem(menu,
+ SWT.CASCADE, index + insertItem.ordinal());
item.setText(itemName);
- Menu paletteManu = new Menu(menu);
-
+ final Menu paletteManu = new Menu(menu);
item.setMenu(paletteManu);
- MenuManager paletteManuManager = new MenuManager(
+ final MenuManager paletteManuManager = new MenuManager(
VpeUIMessages.FROM_PALETTE);
+ final XModelObject model = ModelUtilities.getPreferenceModel()
+ .getByPath("%Palette%"); //$NON-NLS-1$
- XModelObject model = ModelUtilities.getPreferenceModel().getByPath(
- "%Palette%"); //$NON-NLS-1$
-
- paletteManuManager.addMenuListener(new InsertMenuListener(model, i,
- getSelectionRange(sourceEditor)));
-
+ paletteManuManager.addMenuListener(
+ new InsertMenuListener(model, insertItem));
paletteManuManager.setRemoveAllWhenShown(true);
-
paletteManuManager.fill(paletteManu, -1);
-
}
-
}
/**
- *
- * @param sourceEditor
- * @return
- */
- private Point getSelectionRange(StructuredTextEditor sourceEditor) {
-
- // IStructuredSelection selection = (IStructuredSelection) sourceEditor
- // .getSelectionProvider().getSelection();
-
- // Object[] selectedObjects = selection.toArray();
-
- // Node firstElement = (Node) selectedObjects[0];
- // Node endElement = (Node) selectedObjects[selectedObjects.length - 1];
-
- Point selectionRange = SelectionUtil
- .getSourceSelectionRange(sourceEditor);
-
- int start = selectionRange.x;
- int length = selectionRange.y;
-
- Node firstElement = SelectionUtil.getNodeBySourcePosition(sourceEditor,
- selectionRange.x);
- Node endElement = SelectionUtil.getNodeBySourcePosition(sourceEditor,
- selectionRange.x + selectionRange.y);
-
- if (firstElement != null)
- if (firstElement.getNodeType() == Node.TEXT_NODE)
- start = selectionRange.x;
- else
- start = NodesManagingUtil.getStartOffsetNode(firstElement);
-
- if (endElement != null)
- if (endElement.getNodeType() == Node.TEXT_NODE)
- length = selectionRange.x + selectionRange.y - start;
- else
- length = NodesManagingUtil.getEndOffsetNode(endElement) - start;
-
- return new Point(start, length);
-
- }
-
- /**
+ * Fills contextMenu at run-time.
+ *
* @author Sergey Dzmitrovich
- *
- * fill contextMenu run-time
- *
*/
public class InsertMenuListener implements IMenuListener {
- private XModelObject modelObject;
- private int typeAction;
- private Point selectionRange;
+ private final XModelObject modelObject;
+ private final InsertType insertionType;
- public InsertMenuListener(XModelObject modelObject, int typeAction,
- Point selectionRange) {
+ public InsertMenuListener(XModelObject modelObject,
+ InsertType insertionType) {
this.modelObject = modelObject;
- this.typeAction = typeAction;
- this.selectionRange = selectionRange;
+ this.insertionType = insertionType;
}
public void menuAboutToShow(IMenuManager manager) {
+ final XModelObject[] modelObjectChildren
+ = modelObject.getChildren();
- XModelObject[] modelObjects = modelObject.getChildren();
-
String prefix = null;
- if (TAGLIB_ELEMENT_TYPE.equals(modelObject
- .getAttributeValue(ELEMENT_TYPE_PROPERTY))) {
+ if (TAGLIB_ELEMENT_TYPE.equals(
+ modelObject.getAttributeValue(ELEMENT_TYPE_PROPERTY))) {
prefix = getPrefix(modelObject);
}
- for (int i = 0; i < modelObjects.length; i++) {
- if (Constants.YES_STRING.equals(modelObjects[i]
- .getAttributeValue(HIDDEN_PROPERTY))) {
+ for (final XModelObject modelObjectChild : modelObjectChildren) {
+ if (Constants.YES_STRING.equals(
+ modelObjectChild.getAttributeValue(HIDDEN_PROPERTY))) {
continue;
}
- if (TAG_ELEMENT_TYPE.equals(modelObjects[i]
+ if (TAG_ELEMENT_TYPE.equals(modelObjectChild
.getAttributeValue(ELEMENT_TYPE_PROPERTY))) {
- String endText = modelObjects[i]
+ final String endText = modelObjectChild
.getAttributeValue(END_TEXT_PROPERTY);
- if (!((typeAction == INSERT_AROUND) && ((endText == null) || (endText
- .length() == 0)))) {
+ if (insertionType != InsertType.INSERT_AROUND
+ || (endText != null && endText.length() > 0)) {
- if (typeAction == INSERT_BEFORE) {
- selectionRange.y = 0;
- } else if (typeAction == INSERT_AFTER) {
- selectionRange.x += selectionRange.y;
- selectionRange.y = 0;
- }
-
- String name = LEFT_ANGLE_BRACKET
- + (prefix == null || prefix.length() == 0 ? Constants.EMPTY
+ final String name = LEFT_ANGLE_BRACKET
+ + (prefix == null || prefix.length() == 0
+ ? Constants.EMPTY
: prefix + Constants.COLON)
- + modelObjects[i]
+ + modelObjectChild
.getAttributeValue(NAME_PROPERTY)
+ RIGHT_ANGLE_BRACKET;
- manager.add(new InsertAction(name, selectionRange,
- modelObjects[i], pageContext, sourceEditor,
- REPLACE_WITH == this.typeAction));
+ manager.add(new InsertAction2(name, modelObjectChild,
+ pageContext, sourceEditor, insertionType));
}
- }
-
- else {
- MenuManager subMenu = new InsertSubMenuManager(
- modelObjects[i].getAttributeValue(NAME_PROPERTY));
+ } else {
+ final MenuManager subMenu = new InsertSubMenuManager(
+ modelObjectChild.getAttributeValue(NAME_PROPERTY));
subMenu.setRemoveAllWhenShown(true);
subMenu.addMenuListener(new InsertMenuListener(
- modelObjects[i], typeAction, selectionRange));
+ modelObjectChild, insertionType));
manager.add(subMenu);
- subMenu.fill(((MenuManager) manager).getMenu(), -1);
-
+ subMenu.fill(( (MenuManager) manager).getMenu(), -1);
}
-
}
-
}
private String getPrefix(XModelObject modelObject) {
-
- List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(
+ final List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(
(Node) ((IStructuredSelection) sourceEditor
.getSelectionProvider().getSelection())
.getFirstElement(), pageContext);
- String uri = modelObject
+ final String uri = modelObject
.getAttributeValue(URIConstants.LIBRARY_URI);
String prefix = null;
- TaglibData sourceNodeTaglib = XmlUtil.getTaglibForURI(uri, taglibs);
+ final TaglibData sourceNodeTaglib = XmlUtil
+ .getTaglibForURI(uri, taglibs);
- if (sourceNodeTaglib == null)
+ if (sourceNodeTaglib == null) {
prefix = modelObject
.getAttributeValue(URIConstants.DEFAULT_PREFIX);
- else
+ } else {
prefix = sourceNodeTaglib.getPrefix();
+ }
return prefix;
}
-
}
/**
- * @author Sergey Dzmitrovich
+ * This class was created to override method isVisible.
+ * Because of it there is a possibility to fill context
+ * menu at run-time).
*
- * class was created to override method isVisible ( because of it
- * there is possibility to fill context menu run-time )
+ * @author Sergey Dzmitrovich
*/
public class InsertSubMenuManager extends MenuManager {
- @Override
- public boolean isVisible() {
- return true;
- }
-
public InsertSubMenuManager(String text) {
super(text);
}
+ @Override
+ public boolean isVisible() {
+ return true;
+ }
}
-
}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertType.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertType.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertType.java 2009-04-25
18:40:08 UTC (rev 14926)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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.jboss.tools.vpe.messages.VpeUIMessages;
+
+/**
+ * Contains items for the VPE context menu.
+ *
+ * @author yradtsevich
+ */
+public enum InsertType {
+ INSERT_AROUND(VpeUIMessages.INSERT_AROUND),
+ INSERT_BEFORE(VpeUIMessages.INSERT_BEFORE),
+ INSERT_AFTER(VpeUIMessages.INSERT_AFTER),
+ REPLACE_WITH(VpeUIMessages.REPLACE_WITH),
+ INSERT_INTO(VpeUIMessages.INSERT_INTO);
+
+ private String message;
+
+ private InsertType(String message) {
+ this.message = message;
+ }
+ public String getMessage() {
+ return message;
+ }
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/InsertAction.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/InsertAction.java 2009-04-25
15:59:55 UTC (rev 14925)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/InsertAction.java 2009-04-25
18:40:08 UTC (rev 14926)
@@ -28,7 +28,9 @@
* Class is used to handle insert action.
*
* @author Igor Zhukov (izhukov(a)exadel.com)
+ * @deprecated use {@link InsertAction2} instead.
*/
+@Deprecated
public class InsertAction extends Action {
private XModelObject item;
private Point region;
@@ -45,8 +47,8 @@
* @param pageContext the VpePageContext element
* @param sourceEditor the StructuredTextEditor element
*/
- public InsertAction(String title, Point region, XModelObject item, VpePageContext
pageContext,
- StructuredTextEditor sourceEditor) {
+ public InsertAction(String title, Point region, XModelObject item,
+ VpePageContext pageContext, StructuredTextEditor sourceEditor) {
this(title, region, item, pageContext, sourceEditor, false);
}
@@ -59,7 +61,8 @@
* @param pageContext the VpePageContext element
* @param sourceEditor the StructuredTextEditor element
*/
- public InsertAction(String title, Point region, XModelObject item, VpePageContext
pageContext,
+ public InsertAction(String title, Point region,
+ XModelObject item, VpePageContext pageContext,
StructuredTextEditor sourceEditor, boolean replace) {
super(title);
this.item = item;
@@ -78,8 +81,12 @@
XModelObject parent = item.getParent();
String uri = (parent == null) ? Constants.EMPTY :
parent.getAttributeValue(URIConstants.LIBRARY_URI);
- String libraryVersion = (parent == null) ? Constants.EMPTY :
parent.getAttributeValue(URIConstants.LIBRARY_VERSION);
- String defaultPrefix = (parent == null) ? Constants.EMPTY :
parent.getAttributeValue(URIConstants.DEFAULT_PREFIX);
+ String libraryVersion = (parent == null)
+ ? Constants.EMPTY
+ : parent.getAttributeValue(URIConstants.LIBRARY_VERSION);
+ String defaultPrefix = (parent == null)
+ ? Constants.EMPTY
+ : parent.getAttributeValue(URIConstants.DEFAULT_PREFIX);
/*
* Fixes
https://jira.jboss.org/jira/browse/JBIDE-1363. Fixes
@@ -88,8 +95,10 @@
* instead of VpeSelectionProvider. It helps automatically update
* selection range after taglib insertion.
*/
- String startText = Constants.EMPTY + item.getAttributeValue("start text");
//$NON-NLS-1$
- String endText = Constants.EMPTY + item.getAttributeValue("end text");
//$NON-NLS-1$
+ String startText = Constants.EMPTY
+ + item.getAttributeValue("start text"); //$NON-NLS-1$
+ String endText = Constants.EMPTY
+ + item.getAttributeValue("end text"); //$NON-NLS-1$
if (region != null) {
if (this.replace) {
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/InsertAction2.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/InsertAction2.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/InsertAction2.java 2009-04-25
18:40:08 UTC (rev 14926)
@@ -0,0 +1,222 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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 java.util.Properties;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
+import org.jboss.tools.jst.web.tld.TLDToPaletteHelper;
+import org.jboss.tools.jst.web.tld.URIConstants;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.menu.InsertType;
+import org.jboss.tools.vpe.editor.util.Constants;
+import org.jboss.tools.vpe.editor.util.NodesManagingUtil;
+import org.jboss.tools.vpe.editor.util.SelectionUtil;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Class is used to handle insert action.
+ *
+ * @author Igor Zhukov (izhukov(a)exadel.com)
+ * @author yradtsevich
+ */
+public class InsertAction2 extends Action {
+
+ private final XModelObject item;
+ private final VpePageContext pageContext;
+ private final StructuredTextEditor sourceEditor;
+ private final InsertType insertType;
+
+ /**
+ * Constructor.
+ *
+ * @param title the name of the action
+ * @param region the Point object
+ * @param item XModelObject object
+ * @param pageContext the VpePageContext element
+ * @param sourceEditor the StructuredTextEditor element
+ * @param insertType the type of the action
+ */
+ public InsertAction2(String title, XModelObject item,
+ VpePageContext pageContext, StructuredTextEditor sourceEditor,
+ InsertType insertType) {
+ super(title);
+ this.item = item;
+ this.pageContext = pageContext;
+ this.sourceEditor = sourceEditor;
+ this.insertType = insertType;
+ }
+
+ /**
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ prepareInsertion();
+ doInsertion();
+ }
+
+ /**
+ * Sets the cursor to an appropriate position.
+ * If REPLACE_WITH action is selected, it removes the selected text.
+ */
+ private void prepareInsertion() {
+ final Point selectionRange = SelectionUtil
+ .getSourceSelectionRange(sourceEditor);
+ int start = selectionRange.x;
+ int length = selectionRange.y;
+
+ final Node firstNode = SelectionUtil
+ .getNodeBySourcePosition(sourceEditor, selectionRange.x);
+ final Node endNode = SelectionUtil
+ .getNodeBySourcePosition(sourceEditor,
+ selectionRange.x + selectionRange.y);
+
+ if (firstNode != null) {
+ if (firstNode.getNodeType() == Node.TEXT_NODE) {
+ start = selectionRange.x;
+ } else {
+ start = NodesManagingUtil.getStartOffsetNode(firstNode);
+ }
+ }
+
+ if (endNode != null) {
+ if (endNode.getNodeType() == Node.TEXT_NODE) {
+ length = (selectionRange.x - start) + selectionRange.y;
+ } else {
+ length = NodesManagingUtil.getEndOffsetNode(endNode) - start;
+ }
+ }
+
+ final int insertionStart;
+ final int insertionLength;
+ switch (insertType) {
+ case INSERT_BEFORE:
+ insertionStart = start;
+ insertionLength = 0;
+ break;
+ case INSERT_AFTER:
+ insertionStart = start + length;
+ insertionLength = 0;
+ break;
+ case INSERT_INTO:
+ if (endNode.getNodeType() == Node.ELEMENT_NODE) {
+ final Element endElement = (Element) endNode;
+ Node prevNode = endElement
+ .getOwnerDocument().createTextNode(""); //$NON-NLS-1$
+ try {
+ endElement.appendChild(prevNode);
+ } catch(DOMException e) {
+ prevNode = endElement;
+ }
+
+ insertionStart
+ = NodesManagingUtil.getEndOffsetNode(prevNode);
+ insertionLength = 0;
+ } else {
+ insertionStart = start + length;
+ insertionLength = 0;
+ }
+ break;
+ default:
+ insertionStart = start;
+ insertionLength = length;
+ break;
+ }
+
+ if (insertType == InsertType.REPLACE_WITH) {
+ getSourceEditor().getTextViewer().getTextWidget()
+ .replaceTextRange(insertionStart, insertionLength,
+ ""); //$NON-NLS-1$
+ } else {
+ // set source selection
+ SelectionUtil.setSourceSelection(pageContext,
+ insertionStart, insertionLength);
+ }
+ }
+
+ /**
+ * Inserts selected tag at the cursor.
+ */
+ private void doInsertion() {
+ String tagName = item.getAttributeValue("name"); //$NON-NLS-1$
+
+ XModelObject parent = item.getParent();
+ String uri = (parent == null)
+ ? Constants.EMPTY
+ : parent.getAttributeValue(URIConstants.LIBRARY_URI);
+ String libraryVersion = (parent == null)
+ ? Constants.EMPTY
+ : parent.getAttributeValue(URIConstants.LIBRARY_VERSION);
+ String defaultPrefix = (parent == null)
+ ? Constants.EMPTY
+ : parent.getAttributeValue(URIConstants.DEFAULT_PREFIX);
+
+ /*
+ * Fixes
https://jira.jboss.org/jira/browse/JBIDE-1363. Fixes
+ *
https://jira.jboss.org/jira/browse/JBIDE-2442. author:
+ * dmaliarevich StructuredSelectionProvider from source view is used
+ * instead of VpeSelectionProvider. It helps automatically update
+ * selection range after taglib insertion.
+ */
+ String startText = Constants.EMPTY
+ + item.getAttributeValue("start text"); //$NON-NLS-1$
+ String endText = Constants.EMPTY
+ + item.getAttributeValue("end text"); //$NON-NLS-1$
+
+
+ // Gets source editor's selection provider with updated text selection.
+ ISelectionProvider selProvider = sourceEditor.getSelectionProvider();
+
+ Properties p = new Properties();
+ p.setProperty("tag name", tagName); //$NON-NLS-1$
+ p.setProperty("start text", startText); //$NON-NLS-1$
+ p.setProperty("end text", endText); //$NON-NLS-1$
+ p.setProperty("automatically reformat tag body", //$NON-NLS-1$
+ item.getAttributeValue(
+ "automatically reformat tag body")); //$NON-NLS-1$
+ p.setProperty(URIConstants.LIBRARY_URI, uri);
+ p.setProperty(URIConstants.LIBRARY_VERSION, libraryVersion);
+ String addTaglib = item.getParent().getAttributeValue(
+ TLDToPaletteHelper.ADD_TAGLIB);
+ p.setProperty(URIConstants.DEFAULT_PREFIX, defaultPrefix);
+ p.setProperty(PaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, addTaglib);
+ /*
+ * Added by Dzmitry Sakovich Fix for JBIDE-1626
+ */
+ // if(((Node)region).getNodeType() == Node.ELEMENT_NODE)
+ p.put("selectionProvider", selProvider); //$NON-NLS-1$
+ PaletteInsertHelper.insertIntoEditor(sourceEditor.getTextViewer(), p);
+ }
+
+ /**
+ * @return the pageContext
+ */
+ protected VpePageContext getPageContext() {
+ return pageContext;
+ }
+
+ /**
+ * @return the sourceEditor
+ */
+ protected StructuredTextEditor getSourceEditor() {
+ return sourceEditor;
+ }
+
+
+}
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 2009-04-25
15:59:55 UTC (rev 14925)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2009-04-25
18:40:08 UTC (rev 14926)
@@ -83,6 +83,7 @@
public static String INSERT_AROUND;
public static String INSERT_BEFORE;
public static String INSERT_AFTER;
+ public static String INSERT_INTO;
public static String REPLACE_WITH;
public static String FROM_PALETTE;
public static String PAGE_DESIGN_OPTIONS_ABOUT;
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 2009-04-25
15:59:55 UTC (rev 14925)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2009-04-25
18:40:08 UTC (rev 14926)
@@ -64,6 +64,7 @@
INSERT_BEFORE=Insert Before
INSERT_AFTER=Insert After
REPLACE_WITH=Replace With
+INSERT_INTO=Insert Into
FROM_PALETTE=From Palette
PAGE_DESIGN_OPTIONS_ABOUT=Here you can configure Visual Page Editor options, which will
be used for generating a preview
ACTUAL_RUN_TIME_FOLDERS_ABOUT=These options will be used by Visual Page Editor for
replacing absolute and relative path values when generating a preview