Revision: 3540
Author: [email protected]
Date: Mon May 17 09:18:03 2010
Log: Added the ability to access any JMenuItem in the ArchitectFrame based
on the action class that is going to be modified.
http://code.google.com/p/power-architect/source/detail?r=3540
Modified:
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
Fri May 7 07:29:39 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
Mon May 17 09:18:03 2010
@@ -1203,5 +1203,30 @@
public FocusToChildOrParentTableAction getFocusToChildAction() {
return focusToChildAction;
}
+
+ /**
+ * Does a depth-first search of the menus for this frame starting at
the
+ * left most menu and moves to the right.
+ *
+ * @param menuAction
+ * The type of action we are looking for in the menus.
+ * @return The first {...@link JMenuItem} object found with the given
action
+ * type or null if no menu item is found to have that action
type.
+ */
+ public JMenuItem getMenuByAction(Class<? extends Action> menuAction) {
+ for (int i = 0; i < menuBar.getMenuCount(); i++) {
+ JMenu innerMenu = menuBar.getMenu(i);
+ for (int j = 0; j < innerMenu.getItemCount(); j++) {
+ JMenuItem item = innerMenu.getItem(j);
+
+ if (item == null || item.getAction() == null) continue;
//separator found or no action
+
+ if
(menuAction.isAssignableFrom(item.getAction().getClass())) {
+ return item;
+ }
+ }
+ }
+ return null;
+ }
}