[Mc4j-cvs] mc4j/src/org/mc4j/console/bean/notification NotificationNode.java,1.12,1.13 NotificationS
Brought to you by:
ghinkl
From: Greg H. <gh...@us...> - 2006-04-12 19:14:29
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/bean/notification In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20162/src/org/mc4j/console/bean/notification Modified Files: NotificationNode.java NotificationSetNode.java NotificationSetChildren.java Removed Files: NotificationNameComparator.java Log Message: Merging EMS into head for the 2.0 release work Index: NotificationSetChildren.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/bean/notification/NotificationSetChildren.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** NotificationSetChildren.java 5 Oct 2004 05:15:56 -0000 1.5 --- NotificationSetChildren.java 12 Apr 2006 19:13:52 -0000 1.6 *************** *** 17,27 **** package org.mc4j.console.bean.notification; ! import java.util.Collections; ! import java.util.LinkedList; ! import java.util.List; ! import org.openide.nodes.Children; import org.openide.nodes.Node; /** * --- 17,27 ---- package org.mc4j.console.bean.notification; ! import org.mc4j.ems.connection.bean.EmsBean; ! import org.mc4j.ems.connection.bean.notification.EmsNotification; import org.openide.nodes.Children; import org.openide.nodes.Node; + import java.util.SortedSet; + /** * *************** *** 29,83 **** * @version $Revision$($Author$ / $Date$) */ ! public class NotificationSetChildren extends Children.Keys { /** Optional holder for the keys, to be used when changing them dynamically. */ ! protected List myKeys; ! public NotificationSetChildren() { ! myKeys = null; } protected void addNotify() { super.addNotify(); - if (myKeys != null) return; - myKeys = new LinkedList(); - // add whatever keys you need - setKeys(myKeys); - } - - protected void removeNotify() { - myKeys = null; - setKeys(Collections.EMPTY_SET); - super.removeNotify(); - } ! protected Node[] createNodes(Object key) { ! // interpret your key here...usually one node generated, but could be zero or more ! return new Node[] { /*new MyNode((MyParameter)key) */}; ! } ! ! /** Optional accessor method for the keys, for use by the container node or maybe subclasses. */ ! /* ! protected addKey(Object newKey) { ! // Make sure some keys already exist: ! addNotify(); ! myKeys.add(newKey); ! // Ensure that the node(s) is displayed: ! refreshKey(newKey); ! } ! */ ! /** Optional accessor method for keys, for use by the container node or maybe subclasses. */ ! /* ! protected void setKeys(Collection keys) { ! myKeys = new LinkedList(); ! myKeys.addAll(keys); ! super.setKeys(keys); } - */ - - // Could also write e.g. removeKey to be used by the nodes in this children. - // Or, could listen to changes in their status (NodeAdapter.nodeDestroyed) - // and automatically remove them from the keys list here. Etc. - } --- 29,54 ---- * @version $Revision$($Author$ / $Date$) */ ! public class NotificationSetChildren extends Children.SortedArray { /** Optional holder for the keys, to be used when changing them dynamically. */ ! protected EmsBean emsBean; ! ! public NotificationSetChildren(EmsBean emsBean) { ! this.emsBean = emsBean; } protected void addNotify() { super.addNotify(); ! SortedSet<EmsNotification> notifications = emsBean.getNotifications(); ! Node[] newNodes = new Node[notifications.size()]; ! int i = 0; ! for (EmsNotification notification : notifications) { ! NotificationNode node = new NotificationNode(notification); ! newNodes[i++] = node; ! } ! add(newNodes); } } --- NotificationNameComparator.java DELETED --- Index: NotificationSetNode.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/bean/notification/NotificationSetNode.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** NotificationSetNode.java 5 Oct 2004 05:15:56 -0000 1.6 --- NotificationSetNode.java 12 Apr 2006 19:13:52 -0000 1.7 *************** *** 24,27 **** --- 24,28 ---- import org.openide.util.HelpCtx; import org.openide.util.actions.SystemAction; + import org.mc4j.ems.connection.bean.EmsBean; /** *************** *** 34,47 **** public static final String NAME = "Notifications"; ! public NotificationSetNode() { ! super(new NotificationSetChildren()); ! setIconBase("org/mc4j/console/bean/notification/NotificationSetNodeIcon"); ! // Set FeatureDescriptor stuff: setName(NAME); // or, super.setName if needed setDisplayName(java.util.ResourceBundle.getBundle("org/mc4j/console/bean/notification/Bundle").getString("LBL_NotificationSetNode")); setShortDescription(java.util.ResourceBundle.getBundle("org/mc4j/console/bean/notification/Bundle").getString("DESCRIPTION_NotificationSetNode")); ! } --- 35,48 ---- public static final String NAME = "Notifications"; ! public NotificationSetNode(EmsBean emsBean) { ! super(new NotificationSetChildren(emsBean)); ! setIconBase("org/mc4j/console/bean/notification/NotificationSetNodeIcon"); ! // Set FeatureDescriptor stuff: setName(NAME); // or, super.setName if needed setDisplayName(java.util.ResourceBundle.getBundle("org/mc4j/console/bean/notification/Bundle").getString("LBL_NotificationSetNode")); setShortDescription(java.util.ResourceBundle.getBundle("org/mc4j/console/bean/notification/Bundle").getString("DESCRIPTION_NotificationSetNode")); ! } Index: NotificationNode.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/bean/notification/NotificationNode.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** NotificationNode.java 5 Oct 2004 05:15:56 -0000 1.12 --- NotificationNode.java 12 Apr 2006 19:13:52 -0000 1.13 *************** *** 17,44 **** package org.mc4j.console.bean.notification; ! import java.beans.IntrospectionException; ! import java.io.Serializable; ! import java.util.Arrays; ! import java.util.Date; ! import java.util.Vector; ! ! import javax.management.AttributeChangeNotification; ! import javax.management.AttributeChangeNotificationFilter; ! import javax.management.InstanceNotFoundException; ! import javax.management.MBeanNotificationInfo; ! import javax.management.MBeanServer; ! import javax.management.MBeanServerNotification; ! import javax.management.Notification; ! import javax.management.NotificationFilter; ! import javax.management.NotificationListener; ! import javax.management.ObjectInstance; ! import javax.management.ObjectName; ! import javax.management.ReflectionException; ! import javax.management.relation.MBeanServerNotificationFilter; ! ! import org.openide.ErrorManager; ! import org.openide.actions.CustomizeAction; import org.openide.nodes.AbstractNode; - import org.openide.nodes.BeanNode; import org.openide.nodes.Children; import org.openide.nodes.Node; --- 17,22 ---- package org.mc4j.console.bean.notification; ! import org.mc4j.ems.connection.bean.notification.EmsNotification; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; *************** *** 47,52 **** import org.openide.util.actions.SystemAction; - import org.mc4j.console.bean.notification.tracker.NotificationTracker; - /** * --- 25,28 ---- *************** *** 54,93 **** * @version $Revision$($Author$ / $Date$) */ ! public class NotificationNode extends AbstractNode { ! ! ! protected MBeanServer server; ! protected ObjectInstance objectInstance; ! protected ObjectName objectName; ! protected MBeanNotificationInfo notificationInfo; ! protected NotificationListener listener; - /** - * @deprecated Just pass object name - * @param server - * @param objectInstance - * @param notificationInfo - */ - public NotificationNode(MBeanServer server, ObjectInstance objectInstance, MBeanNotificationInfo notificationInfo) { - this(server, objectInstance.getObjectName(), notificationInfo); - } ! public NotificationNode(MBeanServer server, ObjectName objectName, MBeanNotificationInfo notificationInfo) { super(new Children.Array()); ! ! this.server = server; ! this.notificationInfo = notificationInfo; ! this.objectName = objectName; ! ! setIconBase("org/mc4j/console/bean/notification/NotificationNodeNLIcon"); ! // Whatever is most relevant to a user: ! setDefaultAction(SystemAction.get(CustomizeAction.class)); ! // Set FeatureDescriptor stuff: ! setName(this.notificationInfo.getName()); // or, super.setName if needed ! setDisplayName(this.notificationInfo.getName()); //NbBundle.getMessage(NotificationNode.class, "LBL_node")); ! setShortDescription(Arrays.asList(this.notificationInfo.getNotifTypes()).toString()); ! } --- 30,45 ---- * @version $Revision$($Author$ / $Date$) */ ! public class NotificationNode extends AbstractNode implements Comparable { ! protected EmsNotification notification; ! public NotificationNode(EmsNotification notification) { super(new Children.Array()); + this.notification = notification; ! setName(notification.getName()); ! setDisplayName(notification.getName()); ! setShortDescription(notification.getDescription()); } *************** *** 107,110 **** --- 59,69 ---- public void toggleNotification() { + if (!notification.isListening()) + notification.startListening(); + else + notification.stopListening(); + } + + /* if (this.listener == null) { this.listener = new CustomNotificationListener(this); *************** *** 114,122 **** for(int i = 0; i < filters.length; i++) //for every filter available { ! this.server.addNotificationListener( ! this.objectName, ! this.listener, ! filters[i], ! null); } } catch (Exception e) { --- 73,81 ---- for(int i = 0; i < filters.length; i++) //for every filter available { ! this.server.addNotificationListener( ! this.objectName, ! this.listener, ! filters[i], ! null); } } catch (Exception e) { *************** *** 138,141 **** --- 97,101 ---- } } + */ /** *************** *** 147,151 **** * @return array of notification filters */ ! private NotificationFilter[] getNotificationFilters() { NotificationFilter [] result = new NotificationFilter[]{null}; --- 107,111 ---- * @return array of notification filters */ ! /*private NotificationFilter[] getNotificationFilters() { NotificationFilter [] result = new NotificationFilter[]{null}; *************** *** 153,157 **** try { ! Vector raw = new Vector(10); MBeanNotificationInfo [] notifyInfo = (MBeanNotificationInfo[]) server.getMBeanInfo(objectName).getNotifications(); for(int i = 0; i < notifyInfo.length && !uncrecognisedNotifiationFound; i++) --- 113,117 ---- try { ! Vector raw = new Vector(10); MBeanNotificationInfo [] notifyInfo = (MBeanNotificationInfo[]) server.getMBeanInfo(objectName).getNotifications(); for(int i = 0; i < notifyInfo.length && !uncrecognisedNotifiationFound; i++) *************** *** 159,199 **** if(notifyInfo[i].getName().equals(getName())) //fetch notification specific to this node... { ! String [] notifyTypes = notifyInfo[i].getNotifTypes(); ! ! NotificationFilter filter = null; ! for(int j = 0; j < notifyTypes.length && !uncrecognisedNotifiationFound; j++) ! { ! //TODO in the future add more filter support here, if nessesary.... ! if(notifyTypes[j].equals(AttributeChangeNotification.ATTRIBUTE_CHANGE)) ! { ! filter = new AttributeChangeNotificationFilter(); ! ((AttributeChangeNotificationFilter) filter).enableAttribute(getName()); ! } ! else if(notifyTypes[j].equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) ! { ! filter = new MBeanServerNotificationFilter(); ! ((MBeanServerNotificationFilter) filter).disableAllTypes(); ! ((MBeanServerNotificationFilter) filter).enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION); ! ((MBeanServerNotificationFilter) filter).enableAllObjectNames(); ! } ! else if(notifyTypes[j].equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) ! { ! filter = new MBeanServerNotificationFilter(); ! ((MBeanServerNotificationFilter) filter).disableAllTypes(); ! ((MBeanServerNotificationFilter) filter).enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION); ! ((MBeanServerNotificationFilter) filter).enableAllObjectNames(); ! } ! else //unrecognised notification type, set filter to null.... ! { ! filter = null; ! uncrecognisedNotifiationFound = true; //break the loop... ! //once we have a null filter there is no point of ! //having any other filters as all of the notifications will have to be ! //coming through (in other words we don't know how to filer, so dont' filter at all). ! raw.removeAllElements(); ! } ! raw.add(filter); ! } ! } } if(raw.size() > 0) //do we have anything other than a default result? --- 119,159 ---- if(notifyInfo[i].getName().equals(getName())) //fetch notification specific to this node... { ! String [] notifyTypes = notifyInfo[i].getNotifTypes(); ! ! NotificationFilter filter = null; ! for(int j = 0; j < notifyTypes.length && !uncrecognisedNotifiationFound; j++) ! { ! //TODO in the future add more filter support here, if nessesary.... ! if(notifyTypes[j].equals(AttributeChangeNotification.ATTRIBUTE_CHANGE)) ! { ! filter = new AttributeChangeNotificationFilter(); ! ((AttributeChangeNotificationFilter) filter).enableAttribute(getName()); ! } ! else if(notifyTypes[j].equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) ! { ! filter = new MBeanServerNotificationFilter(); ! ((MBeanServerNotificationFilter) filter).disableAllTypes(); ! ((MBeanServerNotificationFilter) filter).enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION); ! ((MBeanServerNotificationFilter) filter).enableAllObjectNames(); ! } ! else if(notifyTypes[j].equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) ! { ! filter = new MBeanServerNotificationFilter(); ! ((MBeanServerNotificationFilter) filter).disableAllTypes(); ! ((MBeanServerNotificationFilter) filter).enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION); ! ((MBeanServerNotificationFilter) filter).enableAllObjectNames(); ! } ! else //unrecognised notification type, set filter to null.... ! { ! filter = null; ! uncrecognisedNotifiationFound = true; //break the loop... ! //once we have a null filter there is no point of ! //having any other filters as all of the notifications will have to be ! //coming through (in other words we don't know how to filer, so dont' filter at all). ! raw.removeAllElements(); ! } ! raw.add(filter); ! } ! } } if(raw.size() > 0) //do we have anything other than a default result? *************** *** 210,223 **** { //DO NOTHING object is not a Notification Broadcaster... ! } catch(InstanceNotFoundException e) { ErrorManager.getDefault().notify(e); ! } ! return result; } ! ! public static class CustomNotificationListener implements NotificationListener, Serializable { private transient NotificationNode notificationNode; --- 170,183 ---- { //DO NOTHING object is not a Notification Broadcaster... ! } catch(InstanceNotFoundException e) { ErrorManager.getDefault().notify(e); ! } ! return result; } ! */ ! /*public static class CustomNotificationListener implements EmsNotificationListener { private transient NotificationNode notificationNode; *************** *** 227,233 **** } ! public void handleNotification(Notification notification, Object obj) { ! //org.openide.windows.IOProvider.getDefault().getStdOut().println( ! // "Handling notification: " + notification); try { Node notifNode = new BeanNode(notification); --- 187,193 ---- } ! public void handleNotification(EmsNotificationEvent notification) { ! org.openide.windows.IOProvider.getDefault().getStdOut().println( ! "Handling notification: " + notification); try { Node notifNode = new BeanNode(notification); *************** *** 244,251 **** } ! public boolean isListening() { ! return (this.listener != null); } --- 204,211 ---- } ! */ public boolean isListening() { ! return this.notification.isListening(); } *************** *** 254,264 **** protected boolean enable(org.openide.nodes.Node[] nodes) { ! if ((nodes.length == 1) ! && (nodes[0] instanceof NotificationNode) ! && (!((NotificationNode)nodes[0]).isListening())) { ! return true; ! } else { ! return false; ! } } public org.openide.util.HelpCtx getHelpCtx() { --- 214,220 ---- protected boolean enable(org.openide.nodes.Node[] nodes) { ! return (nodes.length == 1) ! && (nodes[0] instanceof NotificationNode) ! && (!((NotificationNode) nodes[0]).isListening()); } public org.openide.util.HelpCtx getHelpCtx() { *************** *** 276,286 **** protected boolean enable(org.openide.nodes.Node[] nodes) { ! if ((nodes.length == 1) ! && (nodes[0] instanceof NotificationNode) ! && (((NotificationNode)nodes[0]).isListening())) { ! return true; ! } else { ! return false; ! } } public org.openide.util.HelpCtx getHelpCtx() { --- 232,238 ---- protected boolean enable(org.openide.nodes.Node[] nodes) { ! return (nodes.length == 1) ! && (nodes[0] instanceof NotificationNode) ! && (((NotificationNode) nodes[0]).isListening()); } public org.openide.util.HelpCtx getHelpCtx() { *************** *** 296,298 **** --- 248,257 ---- + public int compareTo(Object o) { + Node otherNode = (Node) o; + return this.getDisplayName().compareTo(otherNode.getDisplayName()); + } + + + } |