improving the performance of popup menu.
instead of using Instance cookie, use the Instance.Of cookie to prevent creating of unnessesary instances.
1.1 --- a/vcscore/src/org/netbeans/modules/vcscore/actions/ClusteringAction.java Mon Feb 04 14:33:57 2002 +0000
1.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/actions/ClusteringAction.java Mon Feb 04 20:37:59 2002 +0000
1.3 @@ -43,8 +43,7 @@
1.4 * Action that displays a submenu of actions when presented in a menu or popup.
1.5 * It reads the menu structure from the default filesystem.
1.6 * Example of layer definition:
1.7 - * <html>
1.8 - * <pre>
1.9 + * <PRE>
1.10 <folder name="PopupMenu">
1.11 <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.cvsclient.Bundle"/>
1.12
1.13 @@ -62,8 +61,7 @@
1.14 <attr name="CommandActionDefinition" stringvalue="org.netbeans.modules.cvsclient.actions.JRecRefreshCommandAction"/>
1.15 <attr name="instanceOf" stringvalue="org.openide.util.SystemAction, org.openide.util.actions.NodeAction, org.netbeans.modules.vcscore.actions.ClusterItemVisualizer"/>
1.16 </file>
1.17 - *</pre>
1.18 - * </html>
1.19 + *</PRE>
1.20 *
1.21 * @author mkleint
1.22 */
1.23 @@ -218,6 +216,7 @@
1.24 }
1.25 DataObject[] children = dataFolder.getChildren();
1.26 if (children != null && children.length > 0) {
1.27 + boolean lastWasSeparator = false;
1.28 for (int i = 0; i < children.length; i++) {
1.29 if (children[i] instanceof DataFolder) {
1.30 submenu = new JMenu();
1.31 @@ -229,23 +228,26 @@
1.32 // submenu.setIcon(null);
1.33 menu.add(submenu);
1.34 }
1.35 + lastWasSeparator = false;
1.36 }
1.37 - InstanceCookie cookie = (InstanceCookie)children[i].getCookie(InstanceCookie.Of.class);
1.38 + InstanceCookie.Of cookie = (InstanceCookie.Of)children[i].getCookie(InstanceCookie.Of.class);
1.39 if (cookie != null) {
1.40 try {
1.41 - if (cookie.instanceClass().equals(JSeparator.class)) {
1.42 - menu.addSeparator();
1.43 - }
1.44 - else {
1.45 + if (cookie.instanceOf(ClusterItemVisualizer.class)) {
1.46 Object obj = cookie.instanceCreate();
1.47 - if (obj != null && obj instanceof ClusterItemVisualizer) {
1.48 + if (obj != null) {
1.49 ClusterItemVisualizer act = (ClusterItemVisualizer)obj;
1.50 if (checkItemEnable(act)) {
1.51 item = createItem(act);
1.52 menu.add(item);
1.53 + lastWasSeparator = false;
1.54 }
1.55 }
1.56 }
1.57 + if (cookie.instanceOf(JSeparator.class) && !lastWasSeparator) {
1.58 + menu.addSeparator();
1.59 + lastWasSeparator = true;
1.60 + }
1.61 } catch (Exception exc) {
1.62 TopManager.getDefault().getErrorManager().notify(ErrorManager.ERROR, exc);
1.63 }