Author: scabanovich
Date: 2009-10-19 10:01:47 -0400 (Mon, 19 Oct 2009)
New Revision: 18162
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/editor/XModelObjectTreeViewComponent.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/action/ModelContributionManager.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/action/XMenuInvoker.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/navigator/NavigatorViewPart.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5041
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/editor/XModelObjectTreeViewComponent.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/editor/XModelObjectTreeViewComponent.java 2009-10-19
13:54:09 UTC (rev 18161)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/editor/XModelObjectTreeViewComponent.java 2009-10-19
14:01:47 UTC (rev 18162)
@@ -11,12 +11,18 @@
package org.jboss.tools.common.editor;
import java.util.*;
+
+import org.jboss.tools.common.meta.XModelEntity;
+import org.jboss.tools.common.meta.action.XActionList;
import org.jboss.tools.common.model.util.*;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.action.ModelContributionManager;
import org.jboss.tools.common.model.ui.dnd.ControlDragDrop;
import org.jboss.tools.common.model.ui.navigator.*;
import org.jboss.tools.common.model.ui.outline.*;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.*;
-import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.jboss.tools.common.model.*;
@@ -38,7 +44,7 @@
}
public void setMenuInvoker(TreeViewerMenuInvoker menu) {
- this.menu = menu;
+// this.menu = menu;
}
protected XModelObjectTreeViewComponent(TreeViewerModelListenerImpl listener) {
@@ -79,8 +85,11 @@
treeViewer.setLabelProvider(label = LabelDecoratorImpl.decorateLabelProvider(new
NavigatorLabelProvider()));
treeViewer.setContentProvider(content);
treeViewer.setInput(cache == null ? null : cache);
+
+ initContextMenu();
menu.setViewer(treeViewer);
treeViewer.getTree().addMouseListener(menu);
+
listener.setViewer(treeViewer);
dnd.setProvider(dndProvider);
dndProvider.setTree(treeViewer.getTree());
@@ -99,6 +108,44 @@
selectionProvider.setTreeViewer(getViewer());
return treeViewer.getTree();
}
+
+ protected void initContextMenu() {
+ final ModelContributionManager menuMgr = new ModelContributionManager(null) {
+ public XActionList getActionList(XModelObject o) {
+ if(o.getFileType() != XModelObject.FILE) return super.getActionList(o);
+ String ent = o.getModelEntity().getName() + "_EditorActionList";
//$NON-NLS-1$
+ XModelEntity entity = o.getModel().getMetaData().getEntity(ent);
+ return (entity != null) ? entity.getActionList() : super.getActionList(o);
+ }
+ };
+ menu.setStandardInvoker(menuMgr);
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ fillContextMenu(manager);
+ }
+ });
+ final TreeViewer treeViewer = getViewer();
+ Menu menu = menuMgr.createContextMenu(treeViewer.getTree());
+ treeViewer.getTree().setMenu(menu);
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ ModelUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().getActiveEditor().getSite()
+ .registerContextMenu(menuMgr, treeViewer);
+ }
+ });
+
+ }
+ protected void fillContextMenu(IMenuManager menu) {
+ IStructuredSelection selection =
+ (IStructuredSelection) getViewer().getSelection();
+ if(menu instanceof ModelContributionManager) {
+ ((ModelContributionManager)menu).setSelection(selection);
+ }
+ menu.update(true);
+ }
+
public Control createControl(Composite parent) {
return createControl(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
}
@@ -119,7 +166,7 @@
listener = null;
if (selectionProvider!=null) selectionProvider.dispose();
selectionProvider = null;
- menu = null;
+// menu = null;
if(label != null) {
label.dispose();
label = null;
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/action/ModelContributionManager.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/action/ModelContributionManager.java 2009-10-19
13:54:09 UTC (rev 18161)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/action/ModelContributionManager.java 2009-10-19
14:01:47 UTC (rev 18162)
@@ -16,10 +16,12 @@
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.actions.ActionContext;
+import org.jboss.tools.common.meta.action.XActionList;
import org.jboss.tools.common.model.XModelObject;
public class ModelContributionManager extends MenuManager {
ActionContext context;
+ ISelection selection;
Shell shell;
public ModelContributionManager(Shell shell) {
@@ -30,6 +32,10 @@
public void setContext(ActionContext context) {
this.context = context;
}
+
+ public void setSelection(ISelection s) {
+ selection = s;
+ }
protected void update(boolean force, boolean recursive) {
if (isDirty() || force) {
@@ -41,16 +47,20 @@
if(os.length == 0) return;
XModelObject o = os[0];
if(os.length == 1) os = null;
- XModelObjectActionList l = new
XModelObjectActionList(o.getModelEntity().getActionList(), o, os, new Object[]{o});
+ XModelObjectActionList l = new XModelObjectActionList(getActionList(o), o, os, new
Object[]{o});
l.setShell(shell);
l.createMenu(menu);
l.removeLastSeparator(menu);
}
}
}
-
+
+ public XActionList getActionList(XModelObject o) {
+ return o.getModelEntity().getActionList();
+ }
+
public XModelObject[] getSelectedModelObjects() {
- ISelection s = context.getSelection();
+ ISelection s = context != null ? context.getSelection() : selection;
if(s.isEmpty() || !(s instanceof StructuredSelection)) return new XModelObject[0];
StructuredSelection ss = (StructuredSelection)s;
Iterator it = ss.iterator();
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/action/XMenuInvoker.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/action/XMenuInvoker.java 2009-10-19
13:54:09 UTC (rev 18161)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/action/XMenuInvoker.java 2009-10-19
14:01:47 UTC (rev 18162)
@@ -12,8 +12,8 @@
import java.util.*;
-import org.jboss.tools.common.model.ui.ModelUIPlugin;
import org.jboss.tools.common.model.ui.dnd.DnDUtil;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
@@ -27,6 +27,14 @@
protected Viewer viewer;
protected boolean onKeyRelease = false;
+ ModelContributionManager standardInvoker;
+
+ public XMenuInvoker() {}
+
+ public void setStandardInvoker(ModelContributionManager standardInvoker) {
+ this.standardInvoker = standardInvoker;
+ }
+
public void setViewer(Viewer viewer) {
this.viewer = viewer;
}
@@ -39,6 +47,23 @@
}
public void mouseDown(MouseEvent e) {
+ if(standardInvoker != null) {
+ XModelObject eo = getModelObjectAt(new Point(e.x, e.y));
+ XModelObject o = getSelectedModelObject();
+ if(o == null && eo == null) return;
+ XModelObject[] os = getSelectedModelObjects();
+ if(eo != null && (o == null || os == null || os.length < 2)) {
+ o = eo;
+ os = null;
+ } else if(isIncluded(eo, os)) {
+ o = eo;
+ }
+ if(os != null && os.length > 0) {
+ standardInvoker.setSelection(new StructuredSelection(os));
+ } else if(o != null) {
+ standardInvoker.setSelection(new StructuredSelection(o));
+ }
+ }
}
public void mouseUp(MouseEvent e) {
@@ -46,7 +71,7 @@
}
protected void handleMouseUp(MouseEvent e) {
- if(e.button == 3) {
+ if(e.button == 3 && standardInvoker == null) {
XModelObject eo = getModelObjectAt(new Point(e.x, e.y));
XModelObject o = getSelectedModelObject();
if(o == null && eo == null) return;
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/navigator/NavigatorViewPart.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/navigator/NavigatorViewPart.java 2009-10-19
13:54:09 UTC (rev 18161)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/views/navigator/NavigatorViewPart.java 2009-10-19
14:01:47 UTC (rev 18162)
@@ -78,6 +78,7 @@
import org.jboss.tools.common.model.plugin.ModelPlugin;
import org.jboss.tools.common.model.project.IModelNature;
import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.action.ModelContributionManager;
import org.jboss.tools.common.model.ui.dnd.ControlDragDrop;
import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
import org.jboss.tools.common.model.ui.navigator.NavigatorLabelProvider;
@@ -242,7 +243,7 @@
}
});
//@S_CHECK@
- TreeViewerMenuInvoker listener = createMenuInvoker();
+ listener = createMenuInvoker();
listener.setViewer(viewer);
if(useModelMenu) {
viewer.getTree().addMouseListener(listener);
@@ -474,22 +475,22 @@
// MenuManager
- MenuManager menuMgr;
+ ModelContributionManager menuMgr;
+ TreeViewerMenuInvoker listener;
protected void initContextMenu() {
- menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
+ menuMgr = new ModelContributionManager(getSite().getShell());
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
fillContextMenu(manager);
}
});
- if(!useModelMenu) {
- TreeViewer treeViewer = getViewer();
- Menu menu = menuMgr.createContextMenu(treeViewer.getTree());
- treeViewer.getTree().setMenu(menu);
- getSite().registerContextMenu(menuMgr, treeViewer);
- }
+ TreeViewer treeViewer = getViewer();
+ Menu menu = menuMgr.createContextMenu(treeViewer.getTree());
+ treeViewer.getTree().setMenu(menu);
+ getSite().registerContextMenu(menuMgr, treeViewer);
+ listener.setStandardInvoker(menuMgr);
}
@@ -500,10 +501,12 @@
}
protected void fillContextMenu(IMenuManager menu) {
- IStructuredSelection selection =
- (IStructuredSelection) getViewer().getSelection();
- getActionGroup().setContext(new ActionContext(selection));
- getActionGroup().fillContextMenu(menu);
+// IStructuredSelection selection =
+// (IStructuredSelection) getViewer().getSelection();
+// if(menu instanceof ModelContributionManager) {
+// ((ModelContributionManager)menu).setSelection(selection);
+// }
+ menu.update(true);
}
// linking