Author: yradtsevich
Date: 2009-05-13 14:39:30 -0400 (Wed, 13 May 2009)
New Revision: 15245
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/ComplexAction.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/EditAttributesAction.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/SelectThisTagAction.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/StripTagAction.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.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/MenuCreationHelper.java
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/action/InsertAction2.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:
issue JBIDE-4226: Two different implementations of the VPE context menu
https://jira.jboss.org/jira/browse/JBIDE-4226
- the implementations have been merged and some actions have been rewritten
- some bugs have been fixed
- cut/add/paste items have been added to the menu of parent tag
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2009-05-13
16:28:09 UTC (rev 15244)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -16,12 +16,10 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.bindings.Binding;
@@ -110,7 +108,7 @@
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
-import org.jboss.tools.vpe.editor.menu.MenuCreationHelper;
+import org.jboss.tools.vpe.editor.menu.VpeMenuCreator;
import org.jboss.tools.vpe.editor.mozilla.EditorDomEventListener;
import org.jboss.tools.vpe.editor.mozilla.MozillaDropInfo;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
@@ -246,8 +244,7 @@
domMapping = new VpeDomMapping(pageContext);
sourceBuilder = new VpeSourceDomBuilder(domMapping, this,
VpeTemplateManager.getInstance(), sourceEditor, pageContext);
- visualBuilder = new VpeVisualDomBuilder(domMapping, this, visualEditor,
- pageContext);
+ visualBuilder = new VpeVisualDomBuilder(domMapping, this, visualEditor, pageContext);
pageContext.setSourceDomBuilder(sourceBuilder);
pageContext.setVisualDomBuilder(visualBuilder);
IDOMModel sourceModel = (IDOMModel) getModel();
@@ -272,8 +269,7 @@
}
IDOMDocument sourceDocument = sourceModel.getDocument();
- // FIXED FOR JBIDE-3799 by sdzmitrovich, moved calling of
- // this method to buid dom
+ // FIXED FOR JBIDE-3799 by sdzmitrovich, moved calling of this method to buid dom
// visualBuilder.refreshExternalLinks();
visualBuilder.buildDom(sourceDocument);
@@ -284,8 +280,7 @@
// presShell = browser.getPresShell();
//initialization visual selection controller
- visualSelectionController = new VpeSelectionController(
- visualEditor.getEditor().getSelectionController());
+ visualSelectionController = new
VpeSelectionController(visualEditor.getEditor().getSelectionController());
selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder,
visualBuilder, visualSelectionController);
@@ -350,8 +345,7 @@
vpeUpdateDelayTime = 400;
// pageContext.fireTaglibsChanged();
- // yradtsevich: we have to refresh VPE selection on init
- // (fix of JBIDE-4037)
+ // yradtsevich: we have to refresh VPE selection on init (fix of JBIDE-4037)
sourceSelectionChanged(true);
}
@@ -373,8 +367,7 @@
}
if (optionsListener != null) {
- XModelObject optionsObject = ModelUtilities.getPreferenceModel()
- .getByPath(VpePreference.EDITOR_PATH);
+ XModelObject optionsObject =
ModelUtilities.getPreferenceModel().getByPath(VpePreference.EDITOR_PATH);
optionsObject.getModel().removeModelTreeListener(optionsListener);
optionsListener.dispose();
optionsListener = null;
@@ -463,7 +456,7 @@
if (PlatformUI.isWorkbenchRunning())
display = PlatformUI.getWorkbench().getDisplay();
- if (display != null && Thread.currentThread() == display.getThread()) {
+ if (display != null && (Thread.currentThread() == display.getThread())) {
getChangeEvents().addLast(
new VpeEventBean(notifier, eventType, feature, oldValue,
newValue, pos));
@@ -471,22 +464,18 @@
uiJob = new UIJob(VpeUIMessages.VPE_UPDATE_JOB_TITLE) {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
- monitor.beginTask(VpeUIMessages.VPE_UPDATE_JOB_TITLE,
- 100);
+ monitor.beginTask(VpeUIMessages.VPE_UPDATE_JOB_TITLE, 100);
while (getChangeEvents().size() > 0) {
- monitor.worked(
- (int) (100 / getChangeEvents().size()));
- VpeEventBean eventBean = getChangeEvents()
- .getFirst();
+ monitor.worked((int) (100 / getChangeEvents().size()));
+ VpeEventBean eventBean = getChangeEvents().getFirst();
if (monitor.isCanceled()) {
- /* Yahor Radtsevich: the following line is
- * commented as the fix of JBIDE-3758:
- * VPE autorefresh is broken in some cases.
- * Now if the change events queue should be
- * cleared, the programmer have to do it
- * explicitly.
+ /*
+ * Yahor Radtsevich: the following line is commented
+ * as fix of JBIDE-3758: VPE autorefresh is broken in some cases.
+ * Now if the change events queue should be cleared, the user have to do it
explicitly.
*/
// getChangeEvents().clear();
+
return Status.CANCEL_STATUS;
}
try {
@@ -501,7 +490,8 @@
// JBIDE-675 we will get this exception if user
// close editor,
// when update visual editor job is running, we
- // should ignore this exception
+ // shoud ignore this
+ // exception
break;
} catch (NullPointerException ex) {
if (switcher != null) {
@@ -517,22 +507,18 @@
}
// cause is to lock calls others events
if (switcher != null &&
- switcher.startActiveEditor(ActiveEditorSwitcher
- .ACTIVE_EDITOR_SOURCE))
+ switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE))
try {
sourceSelectionChanged();
/*
*
https://jira.jboss.org/jira/browse/JBIDE-3619
- * VpeViewUpdateJob takes place after toolbar
- * selection have been updated.
+ * VpeViewUpdateJob takes place after toolbar selection have been updated.
* New nodes haven't been put into dom mapping
* thus toolbar becomes desabled.
- * Updating toolbar state here takes into
- * account updated vpe nodes.
+ * Updating toolbar state here takes into account updated vpe nodes.
*/
if (toolbarFormatControllerManager != null) {
- toolbarFormatControllerManager
- .selectionChanged();
+ toolbarFormatControllerManager.selectionChanged();
}
} finally {
switcher.stopActiveEditor();
@@ -563,12 +549,11 @@
job = new UIJob("NotifyChangedJob") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
- // we check if job was canceled and if is it true cancel the job
+ // we checks is job was canceled and if is it true we cancel job
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
} else {
- notifyChangedInUiThread(notifier, eventType, feature,
- oldValue, newValue, pos);
+ notifyChangedInUiThread(notifier, eventType, feature, oldValue, newValue, pos);
}
return Status.OK_STATUS;
}
@@ -580,14 +565,12 @@
public void notifyChangedInUiThread(INodeNotifier notifier, int eventType,
Object feature, Object oldValue, Object newValue, int pos) {
if (switcher == null ||
- !switcher.startActiveEditor(ActiveEditorSwitcher
- .ACTIVE_EDITOR_SOURCE)) {
+ !switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
}
try {
if (VpeDebug.PRINT_SOURCE_MUTATION_EVENT) {
- printSourceEvent(notifier, eventType, feature,
- oldValue, newValue, pos);
+ printSourceEvent(notifier, eventType, feature, oldValue, newValue, pos);
}
if (visualBuilder == null) {
return;
@@ -606,28 +589,25 @@
if (!update)
visualBuilder.updateNode((Node) notifier);
} else if (type == Node.COMMENT_NODE) {
- if ("yes".equals( //$NON-NLS-1$
- VpePreference.SHOW_COMMENTS.getValue())) {
+ if ("yes".equals(VpePreference.SHOW_COMMENTS.getValue())) { //$NON-NLS-1$
visualBuilder.setSelectionRectangle(null);
visualBuilder.updateNode((Node) notifier);
}
} else if (feature != null
- && ((Node)feature).getNodeType()==Node.ATTRIBUTE_NODE) {
+ && ((Node) feature).getNodeType() == Node.ATTRIBUTE_NODE) {
if (newValue != null) {
String attrName = ((Attr) feature).getName();
if ((Attr) feature == lastRemovedAttr
&& !attrName.equals(lastRemovedAttrName)) {
lastRemovedAttr = null;
- visualBuilder.removeAttribute((Element) notifier,
- lastRemovedAttrName);
+ visualBuilder.removeAttribute((Element) notifier, lastRemovedAttrName);
}
visualBuilder.setAttribute((Element) notifier,
((Attr) feature).getName(), (String) newValue);
} else {
lastRemovedAttr = (Attr) feature;
lastRemovedAttrName = ((Attr) feature).getName();
- visualBuilder.removeAttribute((Element) notifier,
- lastRemovedAttrName);
+ visualBuilder.removeAttribute((Element) notifier, lastRemovedAttrName);
}
}
visualEditor.showResizer();
@@ -651,8 +631,7 @@
case INodeNotifier.CONTENT_CHANGED:
if (!sourceChangeFlag) {
if (feature != null
- && ((Node) feature).getNodeType()
- == Node.TEXT_NODE) {
+ && ((Node) feature).getNodeType() == Node.TEXT_NODE) {
// if
// (((Node)notifier).getNodeName().equalsIgnoreCase(
// "style"))
@@ -681,8 +660,7 @@
// INodeSelectionListener implementation
public void nodeSelectionChanged(NodeSelectionChangedEvent event) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
}
try {
@@ -690,11 +668,8 @@
if (nodes != null && nodes.size() > 0) {
Node sourceNode = (Node) nodes.get(0);
if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>>
" //$NON-NLS-1$
- + "nodeSelectionChanged " //$NON-NLS-1$
- + "sourceNode: " //$NON-NLS-1$
- + sourceNode.getNodeName()
- + " " + event.getCaretPosition()); //$NON-NLS-1$
+ System.out.println(">>>>>>>>>>>>>>
nodeSelectionChanged sourceNode: " + //$NON-NLS-1$
+ sourceNode.getNodeName() + Constants.WHITE_SPACE + event.getCaretPosition());
}
if (event.getSource() instanceof IContentOutlinePage) {
sourceSelectionChanged();
@@ -708,15 +683,12 @@
// ITextSelectionListener implementation
// TODO Max Areshau looks like this method don't used
public void textSelectionChanged(TextSelectionChangedEvent event) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
}
try {
if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>>
" //$NON-NLS-1$
- + "textSelectionChanged " //$NON-NLS-1$
- + event.getSource());
+ System.out.println(">>>>>>>>>>>>>>
textSelectionChanged " + event.getSource()); //$NON-NLS-1$
}
// if (event.getSource() instanceof StyledText) {
sourceSelectionChanged();
@@ -728,14 +700,12 @@
// SelectionListener implementation
public void widgetSelected(SelectionEvent event) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
}
try {
if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>>
" //$NON-NLS-1$
- + "widgetSelected"); //$NON-NLS-1$
+ System.out.println(">>>>>>>>>>>>>>
widgetSelected"); //$NON-NLS-1$
}
if (event.getSource() instanceof StyledText) {
sourceSelectionChanged();
@@ -747,8 +717,7 @@
public void widgetDefaultSelected(SelectionEvent event) {
if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>>
" //$NON-NLS-1$
- + "widgetDefaultSelected"); //$NON-NLS-1$
+ System.out.println(">>>>>>>>>>>>>>
widgetDefaultSelected"); //$NON-NLS-1$
}
}
@@ -810,15 +779,9 @@
// if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
// System.out.println("sourceSelectionChanged"); //$NON-NLS-1$
// System.out
- // .println(" anchorNode: " //$NON-NLS-1$
- // + anchorNode.getNodeName()
- // + " anchorOffset: " //$NON-NLS-1$
- // + anchorOffset);
+ // .println(" anchorNode: " + anchorNode.getNodeName() +
" anchorOffset: " + anchorOffset); //$NON-NLS-1$ //$NON-NLS-2$
// System.out
- // .println(" focusNode: " //$NON-NLS-1$
- // + focusNode.getNodeName()
- // + " focusOffset: " + focusOffset //$NON-NLS-1$
- // + " focusPosition: " + focusPosition); //$NON-NLS-1$
+ // .println(" focusNode: " + focusNode.getNodeName() +
" focusOffset: " + focusOffset + " focusPosition: " +
focusPosition); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// }
// try {
// if (anchorNode.getNodeType() == Node.TEXT_NODE
@@ -856,8 +819,7 @@
}
public void sourceSelectionToVisualSelection(boolean showCaret) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
}
try {
@@ -872,17 +834,15 @@
}
public void processPostModelEvent(ModelLifecycleEvent event) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
}
try {
/*
* Added by Max Areshkau JBIDE-1457
- * ModelLifecycleEvent.MODEL_RELEASED is generated
- * when model in model calls methods releaseFromRead()
- * or releaseFromEdit(). When editor is open he has only
- * when href on model, so nothing can generated
+ * ModelLifecycleEvent.MODEL_RELEASED is generated when model in model
+ * calls methods releaseFromRead() or releaseFromEdit(). When editor
+ * is open he has only when href on model, so nothing can generated
* this event.When editor closes generation of this event depends
* from containing any service href on model or not. It's can be a
* reason of problems on reopen file.
@@ -891,12 +851,9 @@
*/
if (event.getType() == ModelLifecycleEvent.MODEL_RELEASED) {
if (VpeDebug.PRINT_SOURCE_MODEL_LIFECYCLE_EVENT) {
- System.out.println(">>> " //$NON-NLS-1$
- + "processPostModelEvent: " //$NON-NLS-1$
- + event.toString());
+ System.out.println(">>> processPostModelEvent: " +
event.toString()); //$NON-NLS-1$
}
- // commented to fix org.mozilla.xpcom.XPCOMException: The
- // function "repaint" returned an error condition (0x8000ffff)
+ // commented to fix org.mozilla.xpcom.XPCOMException: The function
"repaint" returned an error condition (0x8000ffff)
//visualBuilder.setSelectionRectangle(null);
IStructuredModel model = event.getModel();
model.removeModelLifecycleListener(this);
@@ -917,8 +874,7 @@
// EditorDomEventListener implementation
public void subtreeModified(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -931,8 +887,7 @@
}
public void nodeInserted(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -950,8 +905,7 @@
}
public void nodeRemoved(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -970,8 +924,7 @@
}
public void nodeRemovedFromDocument(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -984,8 +937,7 @@
}
public void nodeInsertedIntoDocument(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -998,8 +950,7 @@
}
public void attrModified(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -1012,8 +963,7 @@
}
public void characterDataModified(nsIDOMMutationEvent mutationEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -1028,13 +978,10 @@
}
}
- public void notifySelectionChanged(nsIDOMDocument doc,
- nsISelection selection, short reason) {
- if (switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ public void notifySelectionChanged(nsIDOMDocument doc, nsISelection selection, short
reason) {
+ if (switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
try {
- mouseUpSelectionReasonFlag
- = (reason & nsISelectionListener.MOUSEUP_REASON) > 0;
+ mouseUpSelectionReasonFlag = (reason & nsISelectionListener.MOUSEUP_REASON) >
0;
if (mouseUpSelectionReasonFlag
// commited by Dzmitrovich - experimental
// TODO check selection and if are appear errors then
@@ -1042,11 +989,9 @@
// || reason == nsISelectionListener.NO_REASON
|| reason == nsISelectionListener.KEYPRESS_REASON
|| reason == nsISelectionListener.SELECTALL_REASON
- || (reason&nsISelectionListener.MOUSEDOWN_REASON) > 0) {
+ || (reason & nsISelectionListener.MOUSEDOWN_REASON) > 0) {
if (VpeDebug.PRINT_VISUAL_SELECTION_EVENT) {
- System.out.println("<<< " //$NON-NLS-1$
- + "notifySelectionChanged: " //$NON-NLS-1$
- + reason);
+ System.out.println("<<< notifySelectionChanged: " + reason);
//$NON-NLS-1$
}
nsIDOMNode node = SelectionUtil.getSelectedNode(selection);
/*
@@ -1067,8 +1012,7 @@
}
public void mouseDown(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -1085,22 +1029,22 @@
// .getDragElement(mouseEvent);
if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- System.out.println("<<< mouseDown targetNode: " //$NON-NLS-1$
- /* +visualNode.
- * getNodeName()
- * + " (" +
- * visualNode +
- * ") selectedElement: "
- * +(
- * visualDragElement
- * != null ?
- * visualDragElement
- * .
- * getNodeName()
- * + " (" +
- * visualDragElement
- * + ")" : null)
- */);
+ System.out.println("<<< mouseDown targetNode: " /* //$NON-NLS-1$
+ * +visualNode.
+ * getNodeName()
+ * + " (" +
+ * visualNode +
+ * ") selectedElement: "
+ * +(
+ * visualDragElement
+ * != null ?
+ * visualDragElement
+ * .
+ * getNodeName()
+ * + " (" +
+ * visualDragElement
+ * + ")" : null)
+ */);
}
//
// if (visualDragElement != null) {
@@ -1135,8 +1079,7 @@
}
public void mouseUp(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -1155,8 +1098,7 @@
}
public void mouseClick(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -1164,11 +1106,8 @@
if (visualNode != null) {
if (!mouseUpSelectionReasonFlag) {
if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- System.out.println("<<< " //$NON-NLS-1$
- + "mouseClick visualNode: " //$NON-NLS-1$
- + visualNode.getNodeName()
- + " (" //$NON-NLS-1$
- + visualNode + ")"); //$NON-NLS-1$
+ System.out.println("<<< mouseClick visualNode: " +
visualNode.getNodeName() + //$NON-NLS-1$
+ " (" + visualNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$
}
if (visualBuilder.isContentArea(visualNode)) {
// selectionBuilder.setClickContentAreaSelection();
@@ -1177,8 +1116,7 @@
mouseUpSelectionReasonFlag = false;
}
- if (visualBuilder.doToggle(
- VisualDomUtil.getTargetNode(mouseEvent))) {
+ if (visualBuilder.doToggle(VisualDomUtil.getTargetNode(mouseEvent))) {
// selectionBuilder.setClickContentAreaSelection();
}
}
@@ -1188,8 +1126,7 @@
}
public void mouseDblClick(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -1199,11 +1136,8 @@
sourceBuilder.openIncludeEditor(visualNode);
}
if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
- System.out.println("<<< " //$NON-NLS-1$
- + "mouseDblClick visualNode: " //$NON-NLS-1$
- + visualNode.getNodeName()
- + " (" //$NON-NLS-1$
- + visualNode + ")"); //$NON-NLS-1$
+ System.out.println("<<< mouseDblClick visualNode: " +
visualNode.getNodeName() + //$NON-NLS-1$
+ " (" + visualNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
} finally {
@@ -1212,8 +1146,7 @@
}
public void mouseMove(nsIDOMMouseEvent mouseEvent) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -1233,15 +1166,11 @@
public void keyPress(nsIDOMKeyEvent keyEvent) {
if (VpeDebug.PRINT_VISUAL_KEY_EVENT) {
- System.out.println("<<< keyPress type: " //$NON-NLS-1$
- + keyEvent.getType()
- + " Ctrl: " + keyEvent.getCtrlKey()
- + " Shift: " + keyEvent.getShiftKey() //$NON-NLS-1$
- + " CharCode: " + keyEvent.getCharCode() //$NON-NLS-1$
- + " KeyCode: " + keyEvent.getKeyCode()); //$NON-NLS-1$
+ System.out.println("<<< keyPress type: " + keyEvent.getType() +
//$NON-NLS-1$
+ " Ctrl: " + keyEvent.getCtrlKey() + " Shift: " +
keyEvent.getShiftKey() + //$NON-NLS-1$ //$NON-NLS-2$
+ " CharCode: " + keyEvent.getCharCode() + " KeyCode: " +
keyEvent.getKeyCode()); //$NON-NLS-1$ //$NON-NLS-2$
}
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
switcher.stopActiveEditor();
return;
}
@@ -1287,19 +1216,14 @@
KeySequence sequenceBeforeKeyStroke = KeySequence.getInstance();
- Iterator<KeyStroke> iterator = possibleKeyStrokes.iterator();
- while (iterator.hasNext()) {
+ for (Iterator<KeyStroke> iterator = possibleKeyStrokes.iterator();
iterator.hasNext();) {
KeySequence sequenceAfterKeyStroke =
- KeySequence.getInstance(sequenceBeforeKeyStroke,
- iterator.next());
- if (iBindingService.isPerfectMatch(
- sequenceAfterKeyStroke)) {
- final Binding binding = iBindingService
- .getPerfectMatch(sequenceAfterKeyStroke);
+ KeySequence.getInstance(sequenceBeforeKeyStroke, iterator.next());
+ if (iBindingService.isPerfectMatch(sequenceAfterKeyStroke)) {
+ final Binding binding = iBindingService.getPerfectMatch(sequenceAfterKeyStroke);
if ((binding != null)
&& (binding.getParameterizedCommand() != null)
- && (binding.getParameterizedCommand()
- .getCommand() != null)) {
+ && (binding.getParameterizedCommand().getCommand() != null)) {
keyBindingPressed = true;
}
}
@@ -1326,8 +1250,8 @@
* JBIDE-2670
*/
keyEvent.preventDefault();
-// switcher.startActiveEditor(
-// ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
+// switcher
+// .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL);
// try {
/*
* Edward
@@ -1348,8 +1272,7 @@
public void elementResized(nsIDOMElement element, int constrains,
int top, int left, int width, int height) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
return;
}
try {
@@ -1363,8 +1286,7 @@
public void dragGesture(nsIDOMEvent domEvent) {
nsIDOMMouseEvent mouseEvent =
- (nsIDOMMouseEvent) domEvent.queryInterface(
- nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
+ (nsIDOMMouseEvent) domEvent.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
boolean canDragFlag = canInnerDrag(mouseEvent);
// start drag sessionvpe-element
if (canDragFlag) {
@@ -1383,23 +1305,20 @@
* @param node
* where this event are occur
*/
- public void onShowContextMenu(long contextFlags, nsIDOMEvent event,
- nsIDOMNode node) {
+ public void onShowContextMenu(long contextFlags, nsIDOMEvent event, nsIDOMNode node) {
//FIXED FOR JBIDE-3072 by sdzmitrovich
// nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
// if (visualNode != null) {
Node selectedSourceNode = null;
- VpeNodeMapping nodeMapping = SelectionUtil
- .getNodeMappingBySourceSelection(sourceEditor, domMapping);
+ VpeNodeMapping nodeMapping =
SelectionUtil.getNodeMappingBySourceSelection(sourceEditor, domMapping);
if (nodeMapping != null) {
selectedSourceNode = nodeMapping.getSourceNode();
}
MenuManager menuManager = new MenuManager("#popup"); //$NON-NLS-1$
- final Menu contextMenu = menuManager.createContextMenu(visualEditor
- .getControl());
+ final Menu contextMenu = menuManager.createContextMenu(visualEditor.getControl());
contextMenu.addMenuListener(new MenuListener() {
Menu menu = contextMenu;
public void menuHidden(MenuEvent e) {
@@ -1414,14 +1333,11 @@
});
// create context menu
- MenuCreationHelper menuCreationHelper =
- new MenuCreationHelper(domMapping, pageContext,
- sourceEditor, visualEditor);
- menuCreationHelper.createMenuForNode(selectedSourceNode,
- menuManager, true);
-
+// MenuCreationHelper menuCreationHelper =
+// new MenuCreationHelper(domMapping, pageContext, sourceEditor, visualEditor);
+// menuCreationHelper.createMenuForNode(selectedSourceNode, menuManager, true);
+ new VpeMenuCreator(menuManager, selectedSourceNode).createMenu();
contextMenu.setVisible(true);
-// }
}
// VpeTemplateListener implementation
@@ -1437,21 +1353,18 @@
if (uiJob != null && uiJob.getState() != Job.NONE) {
return;
}
- if (visualRefreshJob == null
- || visualRefreshJob.getState() == Job.NONE) {
+ if (visualRefreshJob == null || visualRefreshJob.getState() == Job.NONE) {
visualRefreshJob = new UIJob(VpeUIMessages.VPE_VISUAL_REFRESH_JOB) {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return Status.CANCEL_STATUS;
}
try {
- monitor.beginTask(VpeUIMessages.VPE_VISUAL_REFRESH_JOB,
- IProgressMonitor.UNKNOWN);
+ monitor.beginTask(VpeUIMessages.VPE_VISUAL_REFRESH_JOB, IProgressMonitor.UNKNOWN);
visualRefreshImpl();
monitor.done();
setSynced(true);
@@ -1474,7 +1387,7 @@
return Status.OK_STATUS;
}
};
- visualRefreshJob.setRule(new VisualTreeChangingRule(this));
+
visualRefreshJob.setPriority(Job.SHORT);
visualRefreshJob.schedule();
}
@@ -1483,8 +1396,7 @@
void visualRefreshImpl() {
visualEditor.hideResizer();
- String currentDoctype = DocTypeUtil.getDoctype(
- visualEditor.getEditorInput());
+ String currentDoctype = DocTypeUtil.getDoctype(visualEditor.getEditorInput());
/*
*
https://jira.jboss.org/jira/browse/JBIDE-3591
* Avoid using missing resource.
@@ -1519,38 +1431,30 @@
// for debug
private void printSourceEvent(INodeNotifier notifier, int eventType,
Object feature, Object oldValue, Object newValue, int pos) {
- System.out.println(">>> eventType: " //$NON-NLS-1$
- + INodeNotifier.EVENT_TYPE_STRINGS[eventType]
- + " pos: " + pos //$NON-NLS-1$
- + " notifier: " //$NON-NLS-1$
- + ((Node) notifier).getNodeName()
- + " hashCode: " + notifier.hashCode()); //$NON-NLS-1$
+ System.out.println(">>> eventType: " +
INodeNotifier.EVENT_TYPE_STRINGS[eventType] + //$NON-NLS-1$
+ " pos: " + pos + " notifier: " + ((Node)
notifier).getNodeName() + //$NON-NLS-1$ //$NON-NLS-2$
+ " hashCode: " + notifier.hashCode()); //$NON-NLS-1$
if (feature != null) {
if (feature instanceof Node) {
- System.out.println(" feature: " //$NON-NLS-1$
- + ((Node) feature).getNodeType()
- + Constants.WHITE_SPACE + ((Node) feature).getNodeName()
- + " hashCode: " + feature.hashCode()); //$NON-NLS-1$
+ System.out.println(" feature: " + ((Node) feature).getNodeType() +
//$NON-NLS-1$
+ Constants.WHITE_SPACE + ((Node) feature).getNodeName() +
+ " hashCode: " + feature.hashCode()); //$NON-NLS-1$
} else {
System.out.println(" feature: " + feature); //$NON-NLS-1$
}
}
if (oldValue != null) {
if (oldValue instanceof Node) {
- System.out.println(" oldValue: " //$NON-NLS-1$
- + ((Node) oldValue).getNodeName()
- + " hashCode: " + oldValue.hashCode());//$NON-NLS-1$
+ System.out.println(" oldValue: " + ((Node) oldValue).getNodeName() +
//$NON-NLS-1$
+ " hashCode: " + oldValue.hashCode()); //$NON-NLS-1$
} else {
- System.out.println(" oldValue: " + oldValue);//$NON-NLS-1$
+ System.out.println(" oldValue: " + oldValue); //$NON-NLS-1$
}
}
if (newValue != null) {
if (newValue instanceof Node) {
- System.out.println(" newValue: " //$NON-NLS-1$
- + ((Node) newValue).getNodeName()
- + " hashCode: " + newValue.hashCode() //$NON-NLS-1$
- + Constants.WHITE_SPACE
- + ((Node) newValue).getNodeType());
+ System.out.println(" newValue: " + ((Node) newValue).getNodeName() +
//$NON-NLS-1$
+ " hashCode: " + newValue.hashCode() + Constants.WHITE_SPACE + ((Node)
newValue).getNodeType()); //$NON-NLS-1$
} else {
System.out.println(" newValue: " + newValue); //$NON-NLS-1$
}
@@ -1563,22 +1467,17 @@
if (event instanceof nsIDOMMutationEvent) {
nsIDOMMutationEvent mutationEvent = (nsIDOMMutationEvent) event;
- System.out.print(" EventPhase: " //$NON-NLS-1$
- + mutationEvent.getEventPhase());
+ System.out.print(" EventPhase: " + mutationEvent.getEventPhase());
//$NON-NLS-1$
nsIDOMNode relatedNode = mutationEvent.getRelatedNode();
- System.out.print(" RelatedNode: " //$NON-NLS-1$
- + (relatedNode == null ? null : relatedNode.getNodeName()));
+ System.out.print(" RelatedNode: " + (relatedNode == null ? null :
relatedNode.getNodeName())); //$NON-NLS-1$
nsIDOMNode targetNode = VisualDomUtil.getTargetNode(mutationEvent);
String name = targetNode != null ? targetNode.getNodeName() : null;
- System.out.print(" TargetNode: " + name //$NON-NLS-1$
- + " (" + targetNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ System.out.print(" TargetNode: " + name + " (" + targetNode +
")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- System.out.print(" PrevValue: " //$NON-NLS-1$
- + mutationEvent.getPrevValue().trim());
- System.out.print(" NewValue: " //$NON-NLS-1$
- + mutationEvent.getNewValue().trim());
+ System.out.print(" PrevValue: " + mutationEvent.getPrevValue().trim());
//$NON-NLS-1$
+ System.out.print(" NewValue: " + mutationEvent.getNewValue().trim());
//$NON-NLS-1$
}
System.out.println();
}
@@ -1602,8 +1501,7 @@
private boolean startActiveEditor(int newType) {
if (type == ACTIVE_EDITOR_NONE) {
if (newType == ACTIVE_EDITOR_SOURCE
- && editPart.getVisualMode()
- == VpeEditorPart.SOURCE_MODE) {
+ && editPart.getVisualMode() == VpeEditorPart.SOURCE_MODE) {
return false;
}
type = newType;
@@ -1620,8 +1518,7 @@
}
// void refreshBundleValues() {
-// if (!switcher.startActiveEditor(
-// ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+// if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
// return;
// }
// try {
@@ -1646,8 +1543,7 @@
if (bundle != null) {
bundle.refresh();
if (pageContext != null) {
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
}
try {
@@ -1682,18 +1578,12 @@
// if (attrs != null) {
// for (int i = 0; i < attrs.getLength(); i++) {
// if (attrs.item(i) instanceof AttrImpl) {
-// AttrImpl attr = (AttrImpl)attrs.item(i);
-// if (getSourceAttributeOffset(attr,
-// offset) != -1) {
-// String[] atributeNames
-// = elementMapping
-// .getTemplate()
-// .getOutputAtributeNames();
+// AttrImpl attr = (AttrImpl) attrs.item(i);
+// if (getSourceAttributeOffset(attr, offset) != -1) {
+// String[] atributeNames =
elementMapping.getTemplate().getOutputAtributeNames();
// if (atributeNames != null
// && atributeNames.length > 0
-// && attr.getName()
-// .equalsIgnoreCase(
-// atributeNames[0])) {
+// && attr.getName().equalsIgnoreCase(atributeNames[0])) {
// return attr;
// }
// }
@@ -1845,12 +1735,10 @@
selection = new VpeSelection(offset, length);
}
- public void addSelectionChangedListener(
- ISelectionChangedListener listener) {
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
}
- public void removeSelectionChangedListener(
- ISelectionChangedListener listener) {
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
}
public ISelection getSelection() {
@@ -1876,8 +1764,8 @@
if (length > 0) {
try {
- text = sourceEditor.getTextViewer().getDocument()
- .get(offset, length);
+ text = sourceEditor.getTextViewer().getDocument().get(
+ offset, length);
} catch (BadLocationException e) {
VpePlugin.getPluginLog().logError(e);
}
@@ -1889,8 +1777,8 @@
offset = region.getStartOffset();
length = region.getEndOffset() - offset;
try {
- text = sourceEditor.getTextViewer().getDocument()
- .get(offset, length);
+ text = sourceEditor.getTextViewer().getDocument().get(offset,
+ length);
} catch (BadLocationException ex) {
VpePlugin.reportProblem(ex);
}
@@ -1948,13 +1836,13 @@
public void dragEnter(nsIDOMEvent event) {
if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<<<<<<<<<<<<<<<<<<
DragEnter"); //$NON-NLS-1$
+ System.out.println("<<<<<<<<<<<<<<<<<<<<
DragEnter"); //$NON-NLS-1$
}
}
public void dragExit(nsIDOMEvent event) {
if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<<<<<<<<<<<<<<<<<<
dragExit"); //$NON-NLS-1$
+ System.out.println("<<<<<<<<<<<<<<<<<<<<
dragExit"); //$NON-NLS-1$
}
// TODO Sergey Vasilyev figure out with drag caret
// xulRunnerEditor.hideDragCaret();
@@ -1971,14 +1859,13 @@
}
try {
if (VpeDebug.PRINT_VISUAL_DRAGDROP_EVENT) {
- System.out.println("<<<<<<<<<<<<<<<<<<<
dragOver");//$NON-NLS-1$
+ System.out.println("<<<<<<<<<<<<<<<<<<<<
dragOver"); //$NON-NLS-1$
}
// browser.computeDropPosition(event);
boolean canDrop = !xulRunnerEditor.isMozillaDragFlavor();
if (canDrop) {
Clipboard clipboard = new Clipboard(Display.getCurrent());
- canDrop = clipboard.getContents(ModelTransfer.getInstance())
- != null;
+ canDrop = clipboard.getContents(ModelTransfer.getInstance()) != null;
}
if (canDrop) {
canDrop = VpeDndUtil
@@ -2027,9 +1914,8 @@
if (dragInfo != null) {
nsIDOMNode dragNode = dragInfo.getNode();
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print(" dragNode: " //$NON-NLS-1$
- + dragNode.getNodeName()
- + "(" + dragNode + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ System.out
+ .print(" dragNode: " + dragNode.getNodeName() + "(" + dragNode
+ ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
switch (dragNode.getNodeType()) {
case nsIDOMNode.ELEMENT_NODE:
@@ -2108,8 +1994,7 @@
+ "(" //$NON-NLS-1$
+ visualDropInfo.getDropContainer()
+ ") parent: " //$NON-NLS-1$
- + visualDropInfo.getDropContainer().getParentNode()
- .getNodeName()
+ + visualDropInfo.getDropContainer().getParentNode().getNodeName()
+ "(" //$NON-NLS-1$
+ visualDropInfo.getDropContainer().getParentNode()
+ ") offset: " //$NON-NLS-1$
@@ -2152,17 +2037,16 @@
.getInnerDropInfo(event);
if (visualDropInfo.getDropContainer() != null) {
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print(" container: " //$NON-NLS-1$
- + visualDropInfo.getDropContainer().getNodeName()
- + "(" //$NON-NLS-1$
- + visualDropInfo.getDropContainer()
- + ")" //$NON-NLS-1$
- + " offset: " //$NON-NLS-1$
- + visualDropInfo.getDropOffset());
+ System.out
+ .print(" container: " + visualDropInfo.getDropContainer().getNodeName()
+ //$NON-NLS-1$
+ "(" + visualDropInfo.getDropContainer()
+ + ")" + //$NON-NLS-1$ //$NON-NLS-2$
+ " offset: "
+ + visualDropInfo.getDropOffset()); //$NON-NLS-1$
}
- VpeSourceInnerDragInfo sourceInnerDragInfo
- = visualBuilder.getSourceInnerDragInfo(innerDragInfo);
+ VpeSourceInnerDragInfo sourceInnerDragInfo = visualBuilder
+ .getSourceInnerDragInfo(innerDragInfo);
VpeSourceInnerDropInfo sourceDropInfo = visualBuilder
.getSourceInnerDropInfo(sourceInnerDragInfo.getNode(),
visualDropInfo, true);
@@ -2218,8 +2102,8 @@
dropWindow.flavor = flavor;
}
dropWindow.active = true;
- dropWindow.setEventPosition(mouseEvent.getScreenX(),
- mouseEvent.getScreenY());
+ dropWindow.setEventPosition(mouseEvent.getScreenX(), mouseEvent
+ .getScreenY());
dropWindow.setInitialTargetNode(sourceNode);
dropWindow.open();
mouseEvent.stopPropagation();
@@ -2244,9 +2128,7 @@
caretOffset = visualDropInfo.getDropOffset();
} else {
String tagname = getTagName(object);
- if (tagname.indexOf("taglib") >= 0) { //$NON-NLS-1$
- tagname = "taglib"; //$NON-NLS-1$
- }
+ if (tagname.indexOf("taglib") >= 0)tagname = "taglib";
//$NON-NLS-1$ //$NON-NLS-2$
Node sourceDragNode = ((Document) getModel().getAdapter(
Document.class)).createElement(tagname);
VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
@@ -2257,8 +2139,8 @@
visualDropInfo, true);
canDrop = sourceDropInfo.canDrop();
if (canDrop) {
- VpeVisualInnerDropInfo newVisualDropInfo
- = visualBuilder.getInnerDropInfo(
+ VpeVisualInnerDropInfo newVisualDropInfo = visualBuilder
+ .getInnerDropInfo(
sourceDropInfo.getContainer(),
sourceDropInfo.getOffset());
if (newVisualDropInfo != null) {
@@ -2281,15 +2163,11 @@
}
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" canDrop: " + canDrop //$NON-NLS-1$
- + (canDrop
- ? " container: " //$NON-NLS-1$
- + caretParent.getNodeName()
- + " offset: " //$NON-NLS-1$
- + caretOffset
- : "")); //$NON-NLS-1$
+ System.out
+ .println(" canDrop: " + canDrop + (canDrop ? " container: " +
caretParent.getNodeName() + " offset: " + caretOffset : ""));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
return new MozillaDropInfo(canDrop, caretParent, caretOffset);
+
}
public VpeSourceInnerDropInfo canExternalDropMacro(XModelObject object,
@@ -2326,15 +2204,10 @@
String tagname = object.getAttributeValue("name"); //$NON-NLS-1$
XModelObject parent = object.getParent();
- String uri = (parent == null)
- ? "" //$NON-NLS-1$
- : parent.getAttributeValue(URIConstants.LIBRARY_URI);
- String defaultPrefix = (parent == null)
- ? "" //$NON-NLS-1$
- : parent.getAttributeValue(URIConstants.DEFAULT_PREFIX);
+ String uri = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.LIBRARY_URI); //$NON-NLS-1$
+ String defaultPrefix = (parent == null) ? "" :
parent.getAttributeValue(URIConstants.DEFAULT_PREFIX); //$NON-NLS-1$
- String[] texts = new String[] {
- "<" + tagname + ">" }; //$NON-NLS-1$ //$NON-NLS-2$
+ String[] texts = new String[] { "<" + tagname + ">" };
//$NON-NLS-1$ //$NON-NLS-2$
PaletteInsertHelper.applyPrefix(texts, sourceEditor, tagname, uri,
defaultPrefix);
tagname = texts[0].substring(1, texts[0].length() - 1);
@@ -2342,15 +2215,12 @@
return tagname;
}
- public void externalDrop(nsIDOMMouseEvent mouseEvent, String flavor,
- String data) {
+ public void externalDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
onHideTooltip();
- VpeVisualInnerDropInfo visualDropInfo
- = selectionBuilder.getInnerDropInfo(mouseEvent);
- Point range = selectionBuilder.getSourceSelectionRangeAtVisualNode(
- visualDropInfo.getDropContainer(),
- (int) visualDropInfo.getDropOffset());
+ VpeVisualInnerDropInfo visualDropInfo =
selectionBuilder.getInnerDropInfo(mouseEvent);
+ Point range =
selectionBuilder.getSourceSelectionRangeAtVisualNode(visualDropInfo.getDropContainer(),
(int) visualDropInfo
+ .getDropOffset());
VpeSourceInnerDropInfo sourceDropInfo = null;
// if (MODEL_FLAVOR.equals(flavor)) {
@@ -2361,8 +2231,7 @@
nsISupports aValue = DndUtil.getDnDValue(mouseEvent);
String aFlavor = ""; //$NON-NLS-1$
if (VpeDndUtil.isNsIFileInstance(aValue)) {
- nsIFile aFile
- = (nsIFile) aValue.queryInterface(nsIFile.NS_IFILE_IID);
+ nsIFile aFile = (nsIFile) aValue.queryInterface(nsIFile.NS_IFILE_IID);
if (aValue != null) {
data = aFile.getPath();
@@ -2370,15 +2239,11 @@
}
} else if (VpeDndUtil.isNsICStringInstance(aValue)) {
- nsISupportsCString aString
- = (nsISupportsCString) aValue.queryInterface(
- nsISupportsCString.NS_ISUPPORTSCSTRING_IID);
+ nsISupportsCString aString = (nsISupportsCString)
aValue.queryInterface(nsISupportsCString.NS_ISUPPORTSCSTRING_IID);
data = aString.getData();
aFlavor = DndUtil.kHTMLMime;
} else if (VpeDndUtil.isNsIStringInstance(aValue)) {
- nsISupportsString aString
- = (nsISupportsString) aValue.queryInterface(
- nsISupportsString.NS_ISUPPORTSSTRING_IID);
+ nsISupportsString aString = (nsISupportsString)
aValue.queryInterface(nsISupportsString.NS_ISUPPORTSSTRING_IID);
data = aString.getData();
aFlavor = DndUtil.kURLMime;
}
@@ -2394,9 +2259,7 @@
// }
// } else {
// String tagname = getTagName(object);
- // if (tagname.indexOf("taglib") >= 0) {//$NON-NLS-1$
- // tagname = "taglib";//$NON-NLS-1$
- // }
+ // if (tagname.indexOf("taglib") >= 0)tagname =
"taglib"; //$NON-NLS-1$ //$NON-NLS-2$
// Node sourceDragNode = ((Document) getModel().getAdapter(
// Document.class)).createElement(tagname);
// if (visualDropInfo.getDropContainer() != null) {
@@ -2410,16 +2273,12 @@
if (visualDropInfo.getDropContainer() != null && data != null) {
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" drop! container: " //$NON-NLS-1$
- + visualDropInfo.getDropContainer().getNodeName());
+ System.out.println(" drop! container: " +
visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
}
- externalDropAny(aFlavor, data, range, sourceDropInfo == null
- ? null
- : sourceDropInfo.getContainer());
+ externalDropAny(aFlavor, data, range, sourceDropInfo == null ? null :
sourceDropInfo.getContainer());
DropContext dropContext = new DropContext();
- IDNDTextEditor textEditor = (IDNDTextEditor)
- VpeController.this.editPart.getSourceEditor();
+ IDNDTextEditor textEditor = (IDNDTextEditor)
VpeController.this.editPart.getSourceEditor();
// TypedEvent tEvent = new TypedEvent(mouseEvent);
// tEvent.data = data;
@@ -2466,8 +2325,8 @@
*/
String[] attributeString = formatText.split("\n"); //$NON-NLS-1$
/**
- * buffer string containing the attribute and
- * the value in the different succeding string
+ * buffer string containing the attribute and the value in the different
+ * succeding string
*/
String[] buffer = attributeString[0].split(" "); //$NON-NLS-1$
@@ -2502,19 +2361,12 @@
buffer = attributeString[i].split(" ", 2); //$NON-NLS-1$
if (i == 1) {
tempAttr.append(buffer[0] + " "); //$NON-NLS-1$
- tempValue.append(
- (buffer.length >= 2
- ? buffer[1]
- : "") //$NON-NLS-1$
- + " "); //$NON-NLS-1$
+ tempValue
+ .append((buffer.length >= 2 ? buffer[1] : "") + " ");
//$NON-NLS-1$ //$NON-NLS-2$
} else {
- tempAttr.append(
- "\n" + buffer[0] + " "); //$NON-NLS-1$ //$NON-NLS-2$
- tempValue.append(" \n" //$NON-NLS-1$
- + (buffer.length >= 2
- ? buffer[1]
- : "") //$NON-NLS-1$
- + " "); //$NON-NLS-1$
+ tempAttr.append("\n" + buffer[0] + " "); //$NON-NLS-1$
//$NON-NLS-2$
+ tempValue
+ .append(" \n" + (buffer.length >= 2 ? buffer[1] : "") +
" "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
@@ -2562,8 +2414,8 @@
*/
Point point = display.getCursorLocation();
/*
- * Assuming cursor is 21x21 because this is
- * the size of the arrow cursor on Windows
+ * Assuming cursor is 21x21 because this is the size of the arrow cursor
+ * on Windows
*/
point.y += 21;
tip.setLocation(point);
@@ -2636,16 +2488,13 @@
toolbarFormatControllerManager.selectionChanged();
}
- if (!switcher.startActiveEditor(
- ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
}
try {
if (VpeDebug.PRINT_SOURCE_SELECTION_EVENT) {
- System.out.println(">>>>>>>>>>>>>>
" //$NON-NLS-1$
- + "selectionChanged " //$NON-NLS-1$
- + event.getSource());
+ System.out.println(">>>>>>>>>>>>>>
selectionChanged " + event.getSource()); //$NON-NLS-1$
}
sourceSelectionChanged();
} finally {
@@ -2654,8 +2503,7 @@
}
// nsIClipboardDragDropHooks implementation
- public void onPasteOrDrop(nsIDOMMouseEvent mouseEvent,
- String flavor, String data) {
+ public void onPasteOrDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
onHideTooltip();
VpeVisualInnerDropInfo visualDropInfo = selectionBuilder
@@ -2669,9 +2517,7 @@
.getModelBuffer().source();
String tagname = getTagName(object);
- if (tagname.indexOf("taglib") >= 0) { //$NON-NLS-1$
- tagname = "taglib"; //$NON-NLS-1$
- }
+ if (tagname.indexOf("taglib") >= 0)tagname = "taglib";
//$NON-NLS-1$ //$NON-NLS-2$
Node sourceDragNode = ((Document) getModel().getAdapter(Document.class))
.createElement(tagname);
if (visualDropInfo.getDropContainer() != null) {
@@ -2683,8 +2529,7 @@
if (visualDropInfo.getDropContainer() != null) {
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" drop! container: " //$NON-NLS-1$
- + visualDropInfo.getDropContainer().getNodeName());
+ System.out.println(" drop! container: " +
visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
}
final String finalFlavor = flavor;
final String finalData = data;
@@ -2819,7 +2664,6 @@
return Status.OK_STATUS;
}
};
- reinitJob.setRule(new VisualTreeChangingRule(this));
reinitJob.schedule();
}
@@ -2840,12 +2684,11 @@
}
//reinits selection controller+ controller
visualEditor.reinitDesignMode();
- visualSelectionController = new VpeSelectionController(
- visualEditor.getEditor().getSelectionController());
+ visualSelectionController = new
VpeSelectionController(visualEditor.getEditor().getSelectionController());
- selectionBuilder = new VpeSelectionBuilder(domMapping,
- sourceBuilder, visualBuilder, visualSelectionController);
-
+ selectionBuilder = new VpeSelectionBuilder(domMapping, sourceBuilder,
+ visualBuilder, visualSelectionController);
+
selectionManager = new SelectionManager(pageContext,
sourceEditor, visualSelectionController);
@@ -2908,40 +2751,5 @@
public ISelectionManager getSelectionManager() {
return selectionManager;
}
-
- /**
- * Jobs with the same instances of {@code VisualTreeChangingRule}
- * but different {@code vpeController} are
- * never run concurrently. Any resource-changing rule can
- * be nested inside this rule.
- *
- * @author yradtsevich
- */
- private static final class VisualTreeChangingRule
- implements ISchedulingRule {
- private VpeController vpeController;
- public VisualTreeChangingRule(VpeController vpeController) {
- this.vpeController = vpeController;
- }
- public boolean contains(ISchedulingRule rule) {
- if (this == rule) {
- return true;
- } else if (rule instanceof IResource) {
- /* can contain any resource-changing rule
- * (it is needed during preferences-saving operations) */
- return true;
- } else {
- return false;
- }
- }
- public boolean isConflicting(ISchedulingRule rule) {
- if (rule instanceof VisualTreeChangingRule
- && ((VisualTreeChangingRule) rule).vpeController
- == this.vpeController) {
- return true;
- } else {
- return false;
- }
- }
- }
+
}
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-05-13
16:28:09 UTC (rev 15244)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -60,18 +60,18 @@
.getController().getPageContext();
}
- public InsertContributionItem(StructuredTextEditor sourceEditor,
- VpePageContext pageContext) {
- this.sourceEditor = sourceEditor;
- this.pageContext = pageContext;
- }
-
@Override
public void fill(Menu menu, int index) {
for (final InsertType insertItem : InsertType.values()) {
+ final MenuItem item;
+ if (index < 0) {
+ item = new MenuItem(menu, SWT.CASCADE);
+ } else {
+ item = new MenuItem(menu, SWT.CASCADE,
+ index + insertItem.ordinal());
+ }
+
final String itemName = insertItem.getMessage();
- final MenuItem item = new MenuItem(menu,
- SWT.CASCADE, index + insertItem.ordinal());
item.setText(itemName);
final Menu paletteManu = new Menu(menu);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/MenuCreationHelper.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/MenuCreationHelper.java 2009-05-13
16:28:09 UTC (rev 15244)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/MenuCreationHelper.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -17,8 +17,6 @@
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
@@ -66,6 +64,7 @@
* This is helper class is used to create context menu for VPE.
*
* @author Igor Zhukov (izhukov(a)exadel.com)
+ * @deprecated use {@link VpeMenuCreator} instead
*/
public class MenuCreationHelper {
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 2009-05-13
16:28:09 UTC (rev 15244)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/SetupTemplateContributionItem.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -25,7 +25,6 @@
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;
@@ -44,26 +43,15 @@
*/
public SetupTemplateContributionItem() {
super(new SetupTemplateAction());
- JSPMultiPageEditor editor = (JSPMultiPageEditor) PlatformUI
+ final JSPMultiPageEditor editor = (JSPMultiPageEditor) PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
this.sourceEditor = editor.getSourceEditor();
this.pageContext = ((VpeEditorPart) editor.getVisualEditor())
.getController().getPageContext();
- ((SetupTemplateAction) getAction()).setPageContext(pageContext);
+ 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) {
@@ -77,14 +65,14 @@
.getDomMapping().getNodeMapping(element);
if (elementMapping != null
&& elementMapping.getTemplate() != null
- && elementMapping.getTemplate().getType() == VpeHtmlTemplate.TYPE_ANY) {
+ && elementMapping.getTemplate().getType()
+ == VpeHtmlTemplate.TYPE_ANY) {
- ((SetupTemplateAction) getAction()).setText(NLS.bind(
+ getAction().setText(NLS.bind(
VpeUIMessages.SETUP_TEMPLATE_FOR_MENU,
element.getNodeName()));
- ((SetupTemplateAction) getAction()).setActionNode(element);
- ((SetupTemplateAction) getAction()).setData(elementMapping
- .getTemplate().getAnyData());
+ getAction().setActionNode(element);
+ getAction().setData(elementMapping.getTemplate().getAnyData());
MenuItem item = new MenuItem(menu, SWT.SEPARATOR, index );
super.fill(menu, index+1);
}
@@ -92,4 +80,8 @@
}
+ @Override
+ public SetupTemplateAction getAction() {
+ return (SetupTemplateAction) super.getAction();
+ }
}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -0,0 +1,282 @@
+/*******************************************************************************
+ * 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.text.MessageFormat;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.vpe.VpeDebug;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.editor.menu.action.EditAttributesAction;
+import org.jboss.tools.vpe.editor.menu.action.SelectThisTagAction;
+import org.jboss.tools.vpe.editor.menu.action.StripTagAction;
+import org.jboss.tools.vpe.editor.menu.action.ComplexAction;
+import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
+import org.jboss.tools.vpe.editor.util.SelectionUtil;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+import org.jboss.tools.vpe.xulrunner.browser.util.DOMTreeDumper;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * This class is used to create context menu for VPE.
+ *
+ * @author yradtsevich
+ * (based on the implementation of MenuCreationHelper)
+ */
+public class VpeMenuCreator {
+ private final MenuManager menuManager;
+ private final VpeMenuUtil vpeMenuUtil;
+ private final Node node;
+
+ public VpeMenuCreator(final MenuManager menuManager, final Node node) {
+ this.node = node;
+ this.menuManager = menuManager;
+ this.vpeMenuUtil = new VpeMenuUtil();
+ }
+
+ /**
+ * Inserts new menu items into {@link #menuManager}.
+ */
+ public void createMenu() {
+ createMenu(true);
+ }
+
+ /**
+ * Inserts new menu items into {@link #menuManager}.
+ *
+ * @param topLevelMenu if it is {@code true} then the menu will contain
+ * elements for the top level variant of the VPE menu, otherwise - elements
+ * for the sub menu variant.
+ *
+ * @see #addParentTagMenuItem(Element)
+ */
+ private void createMenu(boolean topLevelMenu) {
+ addIfEnabled(new EditAttributesAction(node));
+ menuManager.add(new SetupTemplateContributionItem());
+
+ if (!topLevelMenu) {
+ menuManager.add(new SelectThisTagAction(node));
+ }
+
+ final Node parent = node == null ? null : node.getParentNode();
+ if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
+ addParentTagMenuItem((Element) parent);
+ }
+ addSeparator();
+
+ menuManager.add(new InsertContributionItem());
+ addIfEnabled(new StripTagAction(node));
+ addSeparator();
+
+ if (topLevelMenu) {
+ addIfEnabled(new DumpSourceAction());
+ addIfEnabled(new DumpSelectedElementAction());
+ addIfEnabled(new DumpMappingAction());
+ addIfEnabled(new TestAction());
+ }
+ addSeparator();
+ addCutCopyPasteActions(topLevelMenu);
+ }
+
+ /**
+ * Creates the Cut, Copy and Paste actions.
+ */
+ private void addCutCopyPasteActions(boolean topLevelMenu) {
+ final IAction cutAction = getSourceEditorAction(ActionFactory.CUT);
+ final IAction copyAction = getSourceEditorAction(ActionFactory.COPY);
+ final IAction pasteAction = getSourceEditorAction(ActionFactory.PASTE);
+ if (topLevelMenu) {
+ if (node != null) {
+ menuManager.add(cutAction);
+ menuManager.add(copyAction);
+ }
+ menuManager.add(pasteAction);
+ } else {
+ final IAction selectAction = new SelectThisTagAction(node);
+ if (selectAction.isEnabled()) {
+ menuManager.add(new ComplexAction(cutAction.getText(),
+ selectAction, cutAction));
+ menuManager.add(new ComplexAction(copyAction.getText(),
+ selectAction, copyAction));
+ menuManager.add(new ComplexAction(pasteAction.getText(),
+ selectAction, pasteAction));
+ }
+ }
+ }
+
+ /**
+ * If the {@code action} is enabled, adds it to
+ * the {@link #menuManager}.
+ */
+ private void addIfEnabled(IAction action) {
+ if (action.isEnabled()) {
+ menuManager.add(action);
+ }
+ }
+
+ /**
+ * Adds a menu item for operations on {@code parent} element.
+ *
+ * @param parent the parent element
+ */
+ private void addParentTagMenuItem(final Element parent) {
+ final String itemName = MessageFormat.format(
+ VpeUIMessages.PARENT_TAG_MENU_ITEM, parent.getNodeName());
+
+ final MenuManager parentMenuManager = new MenuManager(itemName);
+ parentMenuManager.setParent(menuManager);
+ parentMenuManager.setRemoveAllWhenShown(true);
+ parentMenuManager.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(final IMenuManager manager) {
+ new VpeMenuCreator(parentMenuManager, parent).createMenu(false);
+ }
+ });
+
+ menuManager.add(parentMenuManager);
+ }
+
+ /**
+ * Adds a separator. If {@link #menuManager} is empty or the last
+ * item already is a separator, does nothing.
+ */
+ private void addSeparator() {
+ final int size = menuManager.getSize();
+ if (size > 0) {
+ final IContributionItem lastItem = menuManager.getItems()[size - 1];
+ if (!lastItem.isSeparator()) {
+ menuManager.add(new Separator());
+ }
+ }
+ }
+
+ /**
+ * Returns an action of the source editor.
+ *
+ * @param actionFactory instance of {@link ActionFactory}
+ * which identifies the action of the item.
+ */
+ private IAction getSourceEditorAction(final ActionFactory actionFactory) {
+ final AbstractTextEditor sourceEditor = vpeMenuUtil.getSourceEditor();
+ final IAction action = sourceEditor.getAction(actionFactory.getId());
+ return action;
+ }
+
+
+ /**
+ * Test action. For the debugging purposes only.
+ */
+ public class TestAction extends Action {
+ public TestAction() {
+ setText("Test Action"); //$NON-NLS-1$
+ }
+
+ public void run() {
+ // test code
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return VpeDebug.VISUAL_CONTEXTMENU_TEST;
+ }
+ }
+
+ /**
+ * Action to dump source of VPE.
+ * For debugging purposes only.
+ */
+ public class DumpSourceAction extends Action {
+ public DumpSourceAction() {
+ setText("Dump Source"); //$NON-NLS-1$
+ }
+
+ @Override
+ public void run() {
+ final MozillaEditor visualEditor
+ = vpeMenuUtil.getMozillaEditor();
+ DOMTreeDumper dumper = new DOMTreeDumper(
+ VpeDebug.VISUAL_DUMP_PRINT_HASH);
+ dumper.setIgnoredAttributes(
+ VpeDebug.VISUAL_DUMP_IGNORED_ATTRIBUTES);
+ dumper.dumpToStream(System.out, visualEditor.getDomDocument());
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return VpeDebug.VISUAL_CONTEXTMENU_DUMP_SOURCE;
+ }
+ }
+
+ /**
+ * Action to dump source of the selected VPE element.
+ * For debugging purposes only.
+ */
+ public class DumpSelectedElementAction extends Action {
+ public DumpSelectedElementAction() {
+ setText("Dump Selected Element"); //$NON-NLS-1$
+ }
+
+ @Override
+ public void run() {
+ final StructuredTextEditor sourceEditor
+ = vpeMenuUtil.getSourceEditor();
+ final VpeDomMapping domMapping
+ = vpeMenuUtil.getDomMapping();
+ final VpeNodeMapping nodeMapping
+ = SelectionUtil.getNodeMappingBySourceSelection(
+ sourceEditor, domMapping);
+ if (nodeMapping != null) {
+ DOMTreeDumper dumper = new DOMTreeDumper(
+ VpeDebug.VISUAL_DUMP_PRINT_HASH);
+ dumper.setIgnoredAttributes(
+ VpeDebug.VISUAL_DUMP_IGNORED_ATTRIBUTES);
+ dumper.dumpNode(nodeMapping.getVisualNode());
+ }
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return VpeDebug.VISUAL_CONTEXTMENU_DUMP_SELECTED_ELEMENT;
+ }
+ }
+
+ /**
+ * Action to print the {@link #domMapping}.
+ * For debugging purposes only.
+ */
+ public class DumpMappingAction extends Action {
+ public DumpMappingAction() {
+ setText("Dump Mapping"); //$NON-NLS-1$
+ }
+
+ @Override
+ public void run() {
+ final VpeDomMapping domMapping
+ = vpeMenuUtil.getDomMapping();
+ domMapping.printMapping();
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return VpeDebug.VISUAL_CONTEXTMENU_DUMP_MAPPING;
+ }
+ }
+}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuUtil.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuUtil.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * 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.eclipse.jface.viewers.IStructuredSelection;
+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.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
+import org.w3c.dom.Node;
+
+/**
+ * An utility class that allows easily and quickly get
+ * some environment variables.
+ * <P>IMPORTANT: If an environment variable changes
+ * between the constructor call and the variable's getter call, the method
+ * could return an incorrect result. You must create a new instance to
+ * get correct result!
+ * </P>
+ *
+ * @author yradtsevich
+ */
+public class VpeMenuUtil {
+ private JSPMultiPageEditor editor;
+ private boolean editorInitialized = false;
+ private StructuredTextEditor sourceEditor;
+ private boolean sourceEditorInitialized = false;
+ private VpeDomMapping domMapping;
+ private boolean domMappingInitialized = false;
+ private VpePageContext pageContext;
+ private boolean pageContextInitialized = false;
+ private Node selectedNode;
+ private boolean selectedNodeInitialized = false;
+ private IStructuredSelection selection;
+ private boolean selectionInitialized = false;
+ private MozillaEditor mozillaEditor;
+ private boolean mozillaEditorInitialized = false;
+
+ /**
+ * Returns active {@code JSPMultiPageEditor}
+ */
+ public JSPMultiPageEditor getEditor() {
+ if (!editorInitialized) {
+ editor = (JSPMultiPageEditor) PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getActivePage().getActiveEditor();
+ editorInitialized = true;
+ }
+ return editor;
+ }
+ /**
+ * Returns active {@code StructuredTextEditor}
+ */
+ public StructuredTextEditor getSourceEditor() {
+ if (!sourceEditorInitialized) {
+ sourceEditor = getEditor().getSourceEditor();
+ sourceEditorInitialized = true;
+ }
+ return sourceEditor;
+ }
+ /**
+ * Returns active {@code StructuredTextEditor}
+ */
+ public VpeDomMapping getDomMapping() {
+ if (!domMappingInitialized) {
+ domMapping = getPageContext().getDomMapping();
+ domMappingInitialized = true;
+ }
+ return domMapping;
+ }
+ /**
+ * Returns {@code VpePageContext} of
+ * the active editor
+ */
+ public VpePageContext getPageContext() {
+ if (!pageContextInitialized) {
+ pageContext = ((VpeEditorPart) getEditor().getVisualEditor())
+ .getController().getPageContext();
+ pageContextInitialized = true;
+ }
+ return pageContext;
+ }
+ /**
+ * Returns active source selection
+ */
+ public IStructuredSelection getSelection() {
+ if (!selectionInitialized) {
+ selection = (IStructuredSelection) getSourceEditor()
+ .getSelectionProvider().getSelection();
+ selectionInitialized = true;
+ }
+ return selection;
+ }
+ /**
+ * Returns selected node.
+ */
+ public Node getSelectedNode() {
+ if (!selectedNodeInitialized) {
+ selection = getSelection();
+ if (selection != null
+ && selection.getFirstElement() instanceof Node) {
+ selectedNode = (Node) selection.getFirstElement();
+ }
+ selectedNodeInitialized = true;
+ }
+ return selectedNode;
+ }
+ /**
+ * Returns active {@code MozillaEditor}
+ */
+ public MozillaEditor getMozillaEditor() {
+ if (!mozillaEditorInitialized) {
+ mozillaEditor = ((VpeEditorPart) getEditor().getVisualEditor())
+ .getVisualEditor();
+ mozillaEditorInitialized = true;
+ }
+ return mozillaEditor;
+ }
+}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/ComplexAction.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/ComplexAction.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/ComplexAction.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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 org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+
+/**
+ * Allows to create an action which composed of multiple actions.
+ *
+ * @author yradtsevich
+ */
+public class ComplexAction extends Action {
+ private final IAction[] actions;
+
+ public ComplexAction(final String name, final IAction... actions) {
+ super(name);
+ this.actions = actions;
+ }
+
+ @Override
+ public void run() {
+ for (final IAction action : actions) {
+ action.run();
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/EditAttributesAction.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/EditAttributesAction.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/EditAttributesAction.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * 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.lang.reflect.InvocationTargetException;
+import java.text.MessageFormat;
+
+import org.eclipse.jface.action.Action;
+import org.jboss.tools.common.model.ui.objecteditor.ExtendedProperties;
+import org.jboss.tools.common.model.ui.objecteditor.ExtendedPropertiesWizard;
+import org.jboss.tools.common.model.util.ModelFeatureFactory;
+import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
+import org.jboss.tools.vpe.editor.menu.VpeMenuUtil;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+import org.w3c.dom.Node;
+
+/**
+ * Action to edit attributes of the {@link #node}.
+ *
+ * @author yradtsevich
+ * (based on the implementation of MenuCreationHelper)
+ */
+public class EditAttributesAction extends Action {
+ final Node node;
+ final VpeMenuUtil menuUtil = new VpeMenuUtil();
+
+ public EditAttributesAction() {
+ this.node = menuUtil.getSelectedNode();
+ init();
+ }
+ public EditAttributesAction(final Node node) {
+ this.node = node;
+ init();
+ }
+
+ private void init() {
+ final String name = MessageFormat.format(
+ VpeUIMessages.ATTRIBUTES_MENU_ITEM,
+ node != null ? node.getNodeName() : "");
+ setText(name);
+ }
+
+ @Override
+ public void run() {
+ showProperties(node);
+ }
+
+ /**
+ * Indicates if editing of attributes of {@link #node}
+ * should be enabled.
+ */
+ @Override
+ public boolean isEnabled() {
+ final VpeDomMapping domMapping = menuUtil.getDomMapping();
+ if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
+ final VpeElementMapping elementMapping
+ = (VpeElementMapping) domMapping.getNodeMapping(node);
+ if (elementMapping != null
+ && elementMapping.getTemplate() != null) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Method is used to show properties of the node.
+ *
+ * @param node the Node object
+ */
+ private void showProperties(Node node) {
+ ExtendedProperties p = createExtendedProperties(node);
+ if (p != null) {
+ ExtendedPropertiesWizard.run(p);
+ }
+ }
+
+ /**
+ * Create extended properties list for the node.
+ *
+ * @param node the Node to be processed
+ * @return an extended properties
+ */
+ private ExtendedProperties createExtendedProperties(Node node) {
+ final Class<?> c = ModelFeatureFactory.getInstance().getFeatureClass(
+ "org.jboss.tools.jst.jsp.outline.VpeProperties"); //$NON-NLS-1$
+ try {
+ return (ExtendedProperties) c.getDeclaredConstructor(
+ new Class[] {Node.class}).newInstance(new Object[] {node});
+ } catch (IllegalArgumentException e) {
+ VpePlugin.getPluginLog().logError(e);
+ } catch (SecurityException e) {
+ VpePlugin.getPluginLog().logError(e);
+ } catch (InstantiationException e) {
+ VpePlugin.getPluginLog().logError(e);
+ } catch (IllegalAccessException e) {
+ VpePlugin.getPluginLog().logError(e);
+ } catch (InvocationTargetException e) {
+ VpePlugin.getPluginLog().logError(e);
+ } catch (NoSuchMethodException e) {
+ VpePlugin.getPluginLog().logError(e);
+ }
+ return null;
+ }
+}
Modified:
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 2009-05-13
16:28:09 UTC (rev 15244)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/InsertAction2.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -14,9 +14,6 @@
import org.eclipse.jface.action.Action;
import org.eclipse.jface.text.IUndoManager;
-import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.swt.graphics.Point;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/SelectThisTagAction.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/SelectThisTagAction.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/SelectThisTagAction.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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 org.eclipse.jface.action.Action;
+import org.jboss.tools.vpe.editor.menu.VpeMenuUtil;
+import org.jboss.tools.vpe.editor.util.NodesManagingUtil;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+import org.w3c.dom.Node;
+
+/**
+ * Action to select {@link #node}.
+ *
+ * @author yradtsevich
+ * (based on the implementation of MenuCreationHelper)
+ */
+public class SelectThisTagAction extends Action {
+ final Node node;
+ final VpeMenuUtil menuUtil = new VpeMenuUtil();
+
+ public SelectThisTagAction() {
+ this.node = menuUtil.getSelectedNode();
+ init();
+ }
+ public SelectThisTagAction(final Node node) {
+ this.node = node;
+ init();
+ }
+
+ private void init() {
+ setText(VpeUIMessages.SELECT_THIS_TAG_MENU_ITEM);
+ }
+
+ @Override
+ public void run() {
+ final int start = NodesManagingUtil.getStartOffsetNode(node);
+ final int end = NodesManagingUtil.getEndOffsetNode(node);
+ menuUtil.getSourceEditor().getTextViewer().setSelectedRange(
+ start, end - start);
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return node != null;
+ }
+}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/StripTagAction.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/StripTagAction.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/StripTagAction.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * 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 org.eclipse.jface.action.Action;
+import org.eclipse.jface.text.IUndoManager;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.vpe.editor.menu.VpeMenuUtil;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Action to "strip tag" - replace the node by its children.
+ *
+ * @author yradtsevich
+ * (based on the implementation of MenuCreationHelper)
+ */
+public class StripTagAction extends Action {
+ final Node node;
+ final VpeMenuUtil menuUtil = new VpeMenuUtil();
+
+ public StripTagAction() {
+ this.node = menuUtil.getSelectedNode();
+ init();
+ }
+ public StripTagAction(final Node node) {
+ this.node = node;
+ init();
+ }
+
+ private void init() {
+ setText(VpeUIMessages.STRIP_TAG_MENU_ITEM);
+ }
+
+ @Override
+ public void run() {
+ final Node parent = node.getParentNode();
+ if (parent != null) {
+ final IUndoManager undoManager = menuUtil.getSourceEditor()
+ .getTextViewer().getUndoManager();
+ try {
+ undoManager.beginCompoundChange();
+ moveNodeChildrenInto(parent);
+ parent.removeChild(node);
+ } finally {
+ undoManager.endCompoundChange();
+ }
+ }
+ }
+
+ private void moveNodeChildrenInto(final Node parent) {
+ final NodeList children = node.getChildNodes();
+ final int childrenLength = children.getLength();
+ for (int i = 0; i < childrenLength; i++) {
+ final Node child = children.item(0);
+ node.removeChild(child);
+ parent.insertBefore(child, node);
+ }
+ }
+
+ @Override
+ public boolean isEnabled() {
+ if (node == null) {
+ return false;
+ }
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
+ return false;
+ }
+
+ final NodeList children = node.getChildNodes();
+ final int childrenLength = children.getLength();
+ if (childrenLength <= 0) {
+ return false;
+ }
+ if (childrenLength == 1
+ && children.item(0).getNodeValue().trim().isEmpty()) {
+ return false;
+ }
+
+ return true;
+ }
+}
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-05-13
16:28:09 UTC (rev 15244)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2009-05-13
18:39:30 UTC (rev 15245)
@@ -13,13 +13,18 @@
import org.eclipse.osgi.util.NLS;
public class VpeUIMessages extends NLS {
- private static final String BUNDLE_NAME =
"org.jboss.tools.vpe.messages.messages";//$NON-NLS-1$
+ private static final String BUNDLE_NAME
+ = "org.jboss.tools.vpe.messages.messages";//$NON-NLS-1$
static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, VpeUIMessages.class);
}
private VpeUIMessages(){}
+ public static String ATTRIBUTES_MENU_ITEM;
+ public static String SELECT_THIS_TAG_MENU_ITEM;
+ public static String STRIP_TAG_MENU_ITEM;
+ public static String PARENT_TAG_MENU_ITEM;
public static String NAMESPACE_NOT_DEFINED;
public static String PREFERENCES;
public static String REFRESH;
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-05-13
16:28:09 UTC (rev 15244)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2009-05-13
18:39:30 UTC (rev 15245)
@@ -1,3 +1,7 @@
+ATTRIBUTES_MENU_ITEM=<{0}> Attributes
+SELECT_THIS_TAG_MENU_ITEM=Select This Tag
+STRIP_TAG_MENU_ITEM=Strip Tag
+PARENT_TAG_MENU_ITEM=Parent Tag ({0})
NAMESPACE_NOT_DEFINED=Namespace is not defined. Template could not be edited.
PREFERENCES=Preferences
REFRESH=Refresh