Author: rob.stryker(a)jboss.com
Date: 2010-02-22 06:56:48 -0500 (Mon, 22 Feb 2010)
New Revision: 20411
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/extensions/XPathActionProvider.java
Log:
JBIDE-5887
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/extensions/XPathActionProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/extensions/XPathActionProvider.java 2010-02-22
09:56:44 UTC (rev 20410)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/extensions/XPathActionProvider.java 2010-02-22
11:56:48 UTC (rev 20411)
@@ -6,6 +6,8 @@
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
@@ -44,7 +46,7 @@
public Action newXPathCategoryAction, deleteXPathCategoryAction,
newXPathAction, editXPathAction, deleteXPathAction, editFileAction;
private XPathChangeValueAction xpathChangeValueAction;
- private Object selectedNode;
+ private CommonViewer cv;
public void init(ICommonActionExtensionSite aSite) {
super.init(aSite);
@@ -53,12 +55,33 @@
if( site instanceof ICommonViewerWorkbenchSite ) {
StructuredViewer v = aSite.getStructuredViewer();
if( v instanceof CommonViewer ) {
- CommonViewer cv = (CommonViewer)v;
+ cv = (CommonViewer)v;
ICommonViewerWorkbenchSite wsSite = (ICommonViewerWorkbenchSite)site;
createActions(cv, wsSite.getSelectionProvider());
+ addDoubleClickHandler(cv);
}
}
}
+ public void dispose() {
+ super.dispose();
+ removeDoubleClickHandler();
+ }
+
+ private IDoubleClickListener doubleClickListener;
+ protected void addDoubleClickHandler(CommonViewer cv) {
+ doubleClickListener = new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ Object o = getSelection();
+ if((o instanceof XPathResultNode) || (o instanceof XPathFileResult) || (o instanceof
XPathQuery))
+ editFileAction.run();
+ }
+ };
+ cv.addDoubleClickListener(doubleClickListener);
+ }
+
+ protected void removeDoubleClickHandler() {
+ cv.removeDoubleClickListener(doubleClickListener);
+ }
public void createActions(CommonViewer tableViewer, ISelectionProvider provider) {
Shell shell = tableViewer.getTree().getShell();
@@ -87,7 +110,7 @@
.setMessage(Messages.DescriptorXPathRemoveCategoryDesc);
if (messageBox.open() == SWT.YES) {
XPathModel.getDefault().removeCategory(getServer(),
- ((XPathCategory) selectedNode).getName());
+ ((XPathCategory) getSelection()).getName());
XPathModel.getDefault().save(getServer());
refreshViewer();
}
@@ -99,6 +122,7 @@
newXPathAction = new Action() {
public void run() {
XPathCategory category = null;
+ Object selectedNode = getSelection();
if(selectedNode instanceof XPathCategory) {
category = (XPathCategory) selectedNode;
} else if( selectedNode instanceof XPathQuery) {
@@ -134,7 +158,7 @@
editXPathAction = new Action() {
public void run() {
- Object o = selectedNode;
+ Object o = getSelection();
if (o != null && o instanceof XPathQuery) {
XPathQuery original = (XPathQuery) o;
XPathCategory category = original.getCategory();
@@ -158,7 +182,7 @@
deleteXPathAction = new Action() {
public void run() {
- Object o = selectedNode;
+ Object o = getSelection();
if (o instanceof XPathQuery) {
XPathCategory cat = ((XPathQuery) o).getCategory();
cat.removeQuery((XPathQuery) o);
@@ -172,7 +196,7 @@
editFileAction = new Action() {
public void run() {
try {
- Object o = selectedNode;
+ Object o = getSelection();
Path p = null;
if (o instanceof XPathQuery
&& ((XPathQuery) o).getResults().length == 1) {
@@ -211,7 +235,8 @@
xpathChangeValueAction = new XPathChangeValueAction(shell, tableViewer, provider);
}
- public void fillContextMenu(IMenuManager menu) {
+
+ protected Object getSelection() {
ICommonViewerSite site = actionSite.getViewSite();
IStructuredSelection selection = null;
if (site instanceof ICommonViewerWorkbenchSite) {
@@ -219,41 +244,43 @@
selection = (IStructuredSelection) wsSite.getSelectionProvider()
.getSelection();
Object first = selection.getFirstElement();
- if (first == null)
- return;
+ return first;
+ }
+ return null;
+ }
+
+ public void fillContextMenu(IMenuManager menu) {
+ Object first = getSelection();
+ if (first == null)
+ return;
- if (first instanceof ServerWrapper) {
- selectedNode = first;
- menu.add(newXPathCategoryAction);
- menu.add(new Separator());
- return;
- }
+ if (first instanceof ServerWrapper) {
+ menu.add(newXPathCategoryAction);
+ menu.add(new Separator());
+ return;
+ }
- if (first instanceof XPathCategory) {
- selectedNode = first;
- menu.add(newXPathAction);
- menu.add(deleteXPathCategoryAction);
- menu.add(new Separator());
- return;
- }
+ if (first instanceof XPathCategory) {
+ menu.add(newXPathAction);
+ menu.add(deleteXPathCategoryAction);
+ menu.add(new Separator());
+ return;
+ }
- if (first instanceof XPathQuery) {
- selectedNode = first;
- menu.add(newXPathAction);
- menu.add(editXPathAction);
- menu.add(deleteXPathAction);
- }
-
- if( xpathChangeValueAction.shouldRun())
- menu.add(xpathChangeValueAction);
-
- if ((first instanceof XPathResultNode || first instanceof XPathFileResult)
- || (first instanceof XPathQuery && ((XPathQuery) first)
- .getResults().length == 1)) {
- selectedNode = first;
- menu.add(editFileAction);
- }
+ if (first instanceof XPathQuery) {
+ menu.add(newXPathAction);
+ menu.add(editXPathAction);
+ menu.add(deleteXPathAction);
}
+
+ if( xpathChangeValueAction.shouldRun())
+ menu.add(xpathChangeValueAction);
+
+ if ((first instanceof XPathResultNode || first instanceof XPathFileResult)
+ || (first instanceof XPathQuery && ((XPathQuery) first)
+ .getResults().length == 1)) {
+ menu.add(editFileAction);
+ }
}
protected void refreshViewer() {
@@ -261,7 +288,7 @@
}
protected IServer getServer() {
- Object o = selectedNode;
+ Object o = getSelection();
if (o instanceof ServerWrapper)
return ((ServerWrapper) o).server;
if (o instanceof XPathCategory)