diff options
author | Bhupendra Bhusman Bhardwaj <bhupendrab@apache.org> | 2007-04-17 15:07:06 +0000 |
---|---|---|
committer | Bhupendra Bhusman Bhardwaj <bhupendrab@apache.org> | 2007-04-17 15:07:06 +0000 |
commit | 4f278a05876e19dcc60e8150c5ec031ce1267b31 (patch) | |
tree | f4268c570be380563c4ad4175dff77e8dfdd50c0 | |
parent | 876ea6e9fb3e9e475d012509973edc53be3609d0 (diff) | |
download | qpid-python-4f278a05876e19dcc60e8150c5ec031ce1267b31.tar.gz |
QPID-422 : Combined all user configured notifications on one view.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2@529635 13f79535-47bb-0310-9956-ffa450edef68
12 files changed, 703 insertions, 401 deletions
diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ApplicationWorkbenchWindowAdvisor.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ApplicationWorkbenchWindowAdvisor.java index 3d163fb111..e3aedef28e 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ApplicationWorkbenchWindowAdvisor.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ApplicationWorkbenchWindowAdvisor.java @@ -49,7 +49,7 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); int x = Display.getDefault().getBounds().width; int y = Display.getDefault().getBounds().height; - configurer.setInitialSize(new Point(4*x/5, 3*y/4)); + configurer.setInitialSize(new Point(9*x/10, 8*y/10)); configurer.setShowCoolBar(true); configurer.setShowStatusLine(false); diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java index 1875ef0d53..091aa43d79 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java @@ -42,7 +42,7 @@ public class Constants public final static String MBEAN = "mbean"; public final static String ATTRIBUTE = "Attribute"; public final static String ATTRIBUTES = "Attributes"; - public final static String NOTIFICATION = "Notifications"; + public final static String NOTIFICATIONS = "Notifications"; public final static String RESULT = "Result"; public final static String VIRTUAL_HOST = "VirtualHost"; public final static String DEFAULT_VH = "Default"; diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java index fa71ee9bc7..e2a0de9cb1 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java @@ -154,7 +154,7 @@ public abstract class ServerRegistry public abstract boolean hasSubscribedForNotifications(ManagedBean mbean, String name, String type); - public abstract void clearNotifications(ManagedBean mbean); + public abstract void clearNotifications(ManagedBean mbean, List<NotificationObject> list); public ClientListener getNotificationListener() { diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java index 4040f544d1..3aa190b9e0 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java @@ -65,7 +65,7 @@ public class JMXServerRegistry extends ServerRegistry // will add that mbean in this list. private List<ManagedBean> _mbeansToBeRemoved = new ArrayList<ManagedBean>(); - // Map containing all managed beans and ampped with unique mbean name + // Map containing all managed beans and mapped with unique mbean name private HashMap<String, ManagedBean> _mbeansMap = new HashMap<String, ManagedBean>(); // Map containing MBeanInfo for all mbeans and mapped with unique mbean name private HashMap<String, MBeanInfo> _mbeanInfoMap = new HashMap<String, MBeanInfo>(); @@ -282,17 +282,78 @@ public class JMXServerRegistry extends ServerRegistry list.add(obj); } + /** + * Returns all the notification objects for a given mbean. If mbean is null, it returns + * notification objects for all the mbeans. + */ public List<NotificationObject> getNotifications(ManagedBean mbean) { - return _notificationsMap.get(mbean.getUniqueName()); + if (mbean == null) + { + List<NotificationObject> totalList = new ArrayList<NotificationObject>(); + for (List<NotificationObject> list : _notificationsMap.values()) + { + totalList.addAll(list); + } + return totalList; + } + else + { + return _notificationsMap.get(mbean.getUniqueName()); + } } - public void clearNotifications(ManagedBean mbean) + public void clearNotifications(ManagedBean mbean, List<NotificationObject> list) { - if (_notificationsMap.containsKey(mbean.getUniqueName())) - _notificationsMap.get(mbean.getUniqueName()).clear(); + if (mbean == null) + { + if (list == null || list.isEmpty()) + { + // All notifications of all mbeans to be cleared + _notificationsMap.clear(); + } + else + { + // Clear the selected notifications + for (NotificationObject obj : list) + { + mbean = _mbeansMap.get(obj.getSource().toString()); + List<NotificationObject> nList = _notificationsMap.get(mbean.getUniqueName()); + if (nList != null && !nList.isEmpty()) + { + nList.remove(obj); + } + } + } + } + else + { + if (list == null || list.isEmpty()) + { + // All notifications of this mbean to be cleared + List<NotificationObject> nList = _notificationsMap.get(mbean.getUniqueName()); + if (nList != null && !nList.isEmpty()) + { + nList.clear(); + } + } + else + { + // Clear the selected notifications + for (NotificationObject obj : list) + { + List<NotificationObject> nList = _notificationsMap.get(mbean.getUniqueName()); + if (nList != null && !nList.isEmpty()) + { + nList.remove(obj); + } + } + } + } } + + /** * Adds notification name and type to the map. The map contains all the notification names, * subscribed for an mbean. diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/model/NotificationObject.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/model/NotificationObject.java index 8ba74b3ce8..926e5f0a24 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/model/NotificationObject.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/model/NotificationObject.java @@ -24,10 +24,12 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; +import javax.management.ObjectName; + public class NotificationObject { - private long _sequenceNo; + private long _sequenceNo; private Date _timeStamp; private String _message; private Object _source; @@ -52,6 +54,17 @@ public class NotificationObject { this._source = _source; } + + public String getSourceName() + { + if (_source instanceof ObjectName) + { + return ((ObjectName)_source).getKeyProperty("name"); + } + + return null; + } + public String getMessage() { return _message; diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java index 437afeeda1..a7e8bbfc4c 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java @@ -596,7 +596,7 @@ public class AttributesTabControl extends TabControl } // Refresh from the server registry - private void refresh() + public void refresh() { JMXServerRegistry serverRegistry = (JMXServerRegistry)ApplicationRegistry.getServerRegistry(_mbean); ManagedAttributeModel attributesList = serverRegistry.getAttributeModel(_mbean); diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java index 59b9fe3aaa..344c3c4e7f 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java @@ -62,6 +62,7 @@ public class MBeanView extends ViewPart private FormToolkit _toolkit = null; private Form _form = null; + private String _formText = APPLICATION_NAME; private static ManagedServer _server = null; private TreeObject _selectedNode = null; private ManagedBean _mbean = null; @@ -73,6 +74,8 @@ public class MBeanView extends ViewPart // TabFolder to list all the mbeans for a given mbeantype(eg Connection, Queue, Exchange) private TabFolder typeTabFolder = null; + + private TabFolder notificationTabFolder = null; /* * Listener for the selection events in the navigation view */ @@ -91,16 +94,41 @@ public class MBeanView extends ViewPart // an mbeantype. For mbeantype selection(eg Connection, Queue, Exchange) _mbean will remain null. _mbean = null; setInvisible(); - _form.setText(APPLICATION_NAME); - // If a selected node(mbean) gets unregistered from mbena server, mbenaview should should + // If a selected node(mbean) gets unregistered from mbean server, mbeanview should // make the tabfolber for that mbean invisible if (_selectedNode == null) return; setServer(); refreshMBeanView(); + setFormTitle(); + } + } + + private void setFormTitle() + { + if (_mbean != null) + { + _formText = _mbean.getType(); + if ((_mbean.getVirtualHostName() != null) && (!DEFAULT_VH.equals(_mbean.getVirtualHostName())) ) + { + _formText = _formText.replaceFirst(VIRTUAL_HOST, _mbean.getVirtualHostName()); + if (_mbean.getName() != null && _mbean.getName().length() != 0) + { + _formText = _formText + ": " + _mbean.getName(); + } + } + } + else if ((_selectedNode.getVirtualHost() != null) && (!DEFAULT_VH.equals(_selectedNode.getVirtualHost()))) + { + _formText = _selectedNode.getVirtualHost(); } + else + { + _formText = APPLICATION_NAME; + } + _form.setText(_formText); } public void refreshMBeanView() @@ -121,10 +149,16 @@ public class MBeanView extends ViewPart { refreshTypeTabFolder(_selectedNode.getName()); } - else + else if (NOTIFICATIONS.equals(_selectedNode.getType())) + { + refreshNotificationPage(); + } + else if (MBEAN.equals(_selectedNode.getType())) { + _mbean = (ManagedBean)_selectedNode.getManagedObject(); showSelectedMBean(); } + _form.layout(true); _form.getBody().layout(true, true); } @@ -174,20 +208,7 @@ public class MBeanView extends ViewPart } private void showSelectedMBean() throws Exception - { - if (NOTIFICATION.equals(_selectedNode.getType())) - { - _mbean = (ManagedBean)_selectedNode.getParent().getManagedObject(); - } - else if (MBEAN.equals(_selectedNode.getType())) - { - _mbean = (ManagedBean)_selectedNode.getManagedObject(); - } - else - { - return; - } - + { try { MBeanUtility.getMBeanInfo(_mbean); @@ -213,14 +234,8 @@ public class MBeanView extends ViewPart tabFolder = createMBeanTabFolder(); } - String text = _mbean.getType(); - if (_mbean.getName() != null && _mbean.getName().length() != 0) - { - text = text + ": " + _mbean.getName(); - } - _form.setText(text); int tabIndex = 0; - if (NOTIFICATION.equals(_selectedNode.getType())) + if (NOTIFICATIONS.equals(_selectedNode.getType())) { tabIndex = tabFolder.getItemCount() -1; } @@ -247,6 +262,8 @@ public class MBeanView extends ViewPart // Add mbeantype TabFolder. This will list all the mbeans under a mbeantype (eg Queue, Exchange). // Using this list mbeans will be added in the navigation view createMBeanTypeTabFolder(); + + createNotificationsTabFolder(); } private TabFolder createMBeanTabFolder() @@ -345,7 +362,7 @@ public class MBeanView extends ViewPart NotificationsTabControl controller = new NotificationsTabControl(tabFolder); TabItem tab = new TabItem(tabFolder, SWT.NONE); - tab.setText(NOTIFICATION); + tab.setText(NOTIFICATIONS); tab.setData(CONTROLLER, controller); tab.setControl(controller.getControl()); } @@ -432,6 +449,32 @@ public class MBeanView extends ViewPart }); } + private void createNotificationsTabFolder() + { + notificationTabFolder = new TabFolder(_form.getBody(), SWT.NONE); + FormData layoutData = new FormData(); + layoutData.left = new FormAttachment(0); + layoutData.top = new FormAttachment(0); + layoutData.right = new FormAttachment(100); + layoutData.bottom = new FormAttachment(100); + notificationTabFolder.setLayoutData(layoutData); + notificationTabFolder.setVisible(false); + + VHNotificationsTabControl controller = new VHNotificationsTabControl(notificationTabFolder); + TabItem tab = new TabItem(notificationTabFolder, SWT.NONE); + tab.setText(NOTIFICATIONS); + tab.setData(CONTROLLER, controller); + tab.setControl(controller.getControl()); + } + + private void refreshNotificationPage() + { + TabItem tab = notificationTabFolder.getItem(0); + VHNotificationsTabControl controller = (VHNotificationsTabControl)tab.getData(CONTROLLER); + controller.refresh(); + notificationTabFolder.setVisible(true); + } + /** * Refreshes the Selected mbeantype tab. The control lists all the available mbeans * for an mbeantype(eg Queue, Exchange etc) @@ -492,6 +535,11 @@ public class MBeanView extends ViewPart { typeTabFolder.setVisible(false); } + + if (notificationTabFolder != null) + { + notificationTabFolder.setVisible(false); + } } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java index 48fcd35b12..68f95e01f0 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java @@ -504,6 +504,11 @@ public class NavigationView extends ViewPart typeChild = new TreeObject(QUEUE, NODE_TYPE_MBEANTYPE); typeChild.setParent(parent); typeChild.setVirtualHost(parent.getVirtualHost()); + + // Add common notification node for virtual host + TreeObject notificationNode = new TreeObject(NOTIFICATIONS, NOTIFICATIONS); + notificationNode.setParent(parent); + notificationNode.setVirtualHost(parent.getVirtualHost()); } /** @@ -585,7 +590,10 @@ public class NavigationView extends ViewPart // create a node for "type" typeNode = createTypeNode(parentNode, type); - typeNode.setVirtualHost(mbean.getVirtualHostName()); + if (!type.equals(VIRTUAL_HOST)) + { + typeNode.setVirtualHost(mbean.getVirtualHostName()); + } } // now type node create becomes the parent node for next node in hierarchy @@ -641,8 +649,8 @@ public class NavigationView extends ViewPart // Add notification node // TODO: show this only if the mbean sends any notification - TreeObject notificationNode = new TreeObject(NOTIFICATION, NOTIFICATION); - notificationNode.setParent(mbeanNode); + //TreeObject notificationNode = new TreeObject(NOTIFICATION, NOTIFICATION); + //notificationNode.setParent(mbeanNode); } private TreeObject createTypeNode(TreeObject parent, String name) @@ -1044,7 +1052,7 @@ public class NavigationView extends ViewPart public Image getImage(Object element) { TreeObject node = (TreeObject) element; - if (node.getType().equals(NOTIFICATION)) + if (node.getType().equals(NOTIFICATIONS)) { return ApplicationRegistry.getImage(NOTIFICATION_IMAGE); } @@ -1107,8 +1115,11 @@ public class NavigationView extends ViewPart { return 1; } - - return 2; + if (node.getType().equals(NOTIFICATIONS)) + { + return 2; + } + return 3; } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java index 4f0acde1b4..6894080859 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java @@ -20,29 +20,28 @@ */ package org.apache.qpid.management.ui.views; -import java.util.ArrayList; +import static org.apache.qpid.management.ui.Constants.BUTTON_CLEAR; +import static org.apache.qpid.management.ui.Constants.BUTTON_REFRESH; +import static org.apache.qpid.management.ui.Constants.DESCRIPTION; +import static org.apache.qpid.management.ui.Constants.FONT_BOLD; +import static org.apache.qpid.management.ui.Constants.FONT_BUTTON; +import static org.apache.qpid.management.ui.Constants.FONT_ITALIC; +import static org.apache.qpid.management.ui.Constants.SUBSCRIBE_BUTTON; +import static org.apache.qpid.management.ui.Constants.UNSUBSCRIBE_BUTTON; + import java.util.List; -import static org.apache.qpid.management.ui.Constants.*; import org.apache.qpid.management.ui.ApplicationRegistry; import org.apache.qpid.management.ui.ManagedBean; import org.apache.qpid.management.ui.ServerRegistry; import org.apache.qpid.management.ui.jmx.MBeanUtility; import org.apache.qpid.management.ui.model.NotificationInfoModel; import org.apache.qpid.management.ui.model.NotificationObject; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; @@ -52,71 +51,35 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.TabFolder; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.forms.widgets.Form; -import org.eclipse.ui.forms.widgets.FormToolkit; /** * Creates control composite for Notifications tab * @author Bhupendra Bhardwaj */ -public class NotificationsTabControl extends TabControl -{ - private FormToolkit _toolkit; - private Form _form; - private Table table = null; - private TableViewer _tableViewer = null; - - private IStructuredContentProvider contentProvider = new ContentProviderImpl(); - private SelectionListener selectionListener = new SelectionListenerImpl(); - private SelectionListener comboListener = new ComboSelectionListener(); - - private Thread worker = null; - - private List<NotificationObject> _notifications = null; - private static final String COLUMN_SEQ = "Sequence No"; - private static final String COLUMN_TIME = "TimeStamp"; - private static final String COLUMN_TYPE = "Type"; - private static final String COLUMN_MSG = "Notification Message"; - private static final String[] _tableTitles = new String [] { - COLUMN_SEQ, - COLUMN_TIME, - COLUMN_TYPE, - COLUMN_MSG - }; +public class NotificationsTabControl extends VHNotificationsTabControl +{ + private static final String SELECT_NOTIFICATIONNAME = "Select Notification"; + private static final String SELECT_NOTIFICATIONTYPE = "Select Type"; + private SelectionListener selectionListener; + private SelectionListener comboListener; private Combo notificationNameCombo = null; private Combo typesCombo = null; private Label descriptionLabel = null; private Button _subscribeButton = null; private Button _unsubscribeButton = null; - private Button _clearButton = null; - private Button _refreshButton = null; - public NotificationsTabControl(TabFolder tabFolder) { super(tabFolder); - _toolkit = new FormToolkit(_tabFolder.getDisplay()); - _form = _toolkit.createForm(_tabFolder); - GridLayout gridLayout = new GridLayout(); - gridLayout.marginWidth = 0; - gridLayout.marginHeight = 0; - _form.getBody().setLayout(gridLayout); - - createWidgets(); - worker = new Thread(new Worker()); - worker.start(); } - private void createWidgets() + protected void createWidgets() { + selectionListener = new SelectionListenerImpl(); + comboListener = new ComboSelectionListener(); createNotificationInfoComposite(); //addFilterComposite(); addButtons(); @@ -124,14 +87,6 @@ public class NotificationsTabControl extends TabControl } /** - * @see TabControl#getControl() - */ - public Control getControl() - { - return _form; - } - - /** * Creates composite and populates for displaying Notification Information (name, type, description) * and creates buttons for subscribing or unsubscribing for notifications */ @@ -205,7 +160,7 @@ public class NotificationsTabControl extends TabControl /** * Creates clear buttin and refresh button */ - private void addButtons() + protected void addButtons() { Composite composite = _toolkit.createComposite(_form.getBody(), SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); @@ -224,8 +179,9 @@ public class NotificationsTabControl extends TabControl if (_mbean == null) return; + IStructuredSelection ss = (IStructuredSelection)_tableViewer.getSelection(); ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(_mbean); - serverRegistry.clearNotifications(_mbean); + serverRegistry.clearNotifications(_mbean, ss.toList()); refresh(); } }); @@ -247,155 +203,13 @@ public class NotificationsTabControl extends TabControl } }); } - - /** - * Creates table to display notifications - */ - private void createTable() - { - table = _toolkit.createTable(_form.getBody(), SWT.FULL_SELECTION); - table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - - TableColumn column = new TableColumn(table, SWT.NONE); - column.setText(_tableTitles[0]); - column.pack(); //column.setWidth(200); - - column = new TableColumn(table, SWT.NONE); - column.setText(_tableTitles[1]); - column.setWidth(150); - - column = new TableColumn(table, SWT.NONE); - column.setText(_tableTitles[2]); - column.setWidth(100); - - column = new TableColumn(table, SWT.NONE); - column.setText(_tableTitles[3]); - column.setWidth(500); - - table.setHeaderVisible(true); - table.setLinesVisible(true); - } - - /** - * Creates JFace viewer for the notifications table - */ - protected void createTableViewer() - { - createTable(); - _tableViewer = new TableViewer(table); - //_tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - _tableViewer.setUseHashlookup(true); - _tableViewer.setContentProvider(contentProvider); - _tableViewer.setLabelProvider(new LabelProviderImpl()); - _tableViewer.setColumnProperties(_tableTitles); - /* - CellEditor[] cellEditors = new CellEditor[_tableTitles.length]; - TextCellEditor textEditor = new TextCellEditor(table); - cellEditors[0] = textEditor; - textEditor = new TextCellEditor(table); - cellEditors[1] = textEditor; - textEditor = new TextCellEditor(table); - cellEditors[2] = textEditor; - textEditor = new TextCellEditor(table); - cellEditors[3] = textEditor; - - // Assign the cell editors to the viewer - _tableViewer.setCellEditors(cellEditors); - _tableViewer.setCellModifier(new TableCellModifier()); - */ - - addTableListeners(); - - //_tableViewer.addSelectionChangedListener(new ); - - //_notificationDetails = new Composite(_tabControl, SWT.BORDER); - //_notificationDetails.setLayoutData(new GridData(GridData.FILL_BOTH)); - - //_tabControl.layout(); - //viewerComposite.layout(); - } - - /** - * Adds listeners to the viewer for displaying notification details - */ - private void addTableListeners() - { - _tableViewer.addDoubleClickListener(new IDoubleClickListener() - { - Display display = null; - Shell shell = null; - public void doubleClick(DoubleClickEvent event) - { - display = Display.getCurrent(); - shell = new Shell(display, SWT.BORDER | SWT.CLOSE | SWT.MIN | - SWT.MAX | SWT.RESIZE); - shell.setText("Notification"); - - int x = display.getBounds().width; - int y = display.getBounds().height; - shell.setBounds(x/4, y/4, x/2, y/3); - StructuredSelection selection = (StructuredSelection)event.getSelection(); - createPopupContents((NotificationObject)selection.getFirstElement()); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - - //If you create it, you dispose it. - shell.dispose(); - } - - private void createPopupContents(NotificationObject obj) - { - shell.setLayout(new GridLayout()); - - Composite parent = new Composite(shell, SWT.NONE); - parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - GridLayout layout = new GridLayout(4, true); - parent.setLayout(layout); - - Label key = new Label(parent, SWT.TRAIL); - key.setText(COLUMN_SEQ); - GridData layoutData = new GridData(SWT.TRAIL, SWT.TOP, false, false,1,1); - key.setLayoutData(layoutData); - Text value = new Text(parent, SWT.BEGINNING | SWT.BORDER |SWT.READ_ONLY); - value.setText(""+obj.getSequenceNo()); - value.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,3,1)); - - // Time row - key = new Label(parent, SWT.TRAIL); - key.setText(COLUMN_TIME); - key.setLayoutData(new GridData(SWT.TRAIL, SWT.TOP, true, false,1,1)); - value = new Text(parent, SWT.BEGINNING | SWT.BORDER | SWT.READ_ONLY); - value.setText(""+obj.getTimeStamp()); - value.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,3,1)); - - key = new Label(parent, SWT.TRAIL); - key.setText(COLUMN_TYPE); - key.setLayoutData(new GridData(SWT.TRAIL, SWT.TOP, true, false,1,1)); - value = new Text(parent, SWT.BEGINNING | SWT.BORDER | SWT.READ_ONLY); - value.setText(""+obj.getType()); - value.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,3,1)); - - key = new Label(parent, SWT.TRAIL); - key.setText(COLUMN_MSG); - key.setLayoutData(new GridData(SWT.TRAIL, SWT.TOP, true, false,1,1)); - value = new Text(parent, SWT.MULTI | SWT.WRAP| SWT.BORDER | SWT.V_SCROLL | SWT.READ_ONLY); - value.setText(""+obj.getMessage()); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1); - gridData.heightHint = 100; - value.setLayoutData(gridData); - } - }); - } - + @Override public void refresh(ManagedBean mbean) { _mbean = mbean; _notifications = null; + _table.deselectAll(); _tableViewer.getTable().clearAll(); if (_mbean == null) @@ -431,9 +245,10 @@ public class NotificationsTabControl extends TabControl _form.getBody().layout(true, true); } - private void refresh() + public void refresh() { _notifications = null; + _table.deselectAll(); _tableViewer.getTable().clearAll(); } @@ -444,7 +259,11 @@ public class NotificationsTabControl extends TabControl { notificationNameCombo.removeAll(); NotificationInfoModel[] items = MBeanUtility.getNotificationInfo(_mbean); - notificationNameCombo.add("Select Notification"); + if (items.length > 1) + { + notificationNameCombo.add(SELECT_NOTIFICATIONNAME); + } + for (int i = 0; i < items.length; i++) { notificationNameCombo.add(items[i].getName()); @@ -457,6 +276,7 @@ public class NotificationsTabControl extends TabControl typesCombo.select(0); typesCombo.setEnabled(false); + populateNotificationType(notificationNameCombo.getItem(0)); checkForEnablingButtons(); } @@ -466,7 +286,8 @@ public class NotificationsTabControl extends TabControl private void checkForEnablingButtons() { int nameIndex = notificationNameCombo.getSelectionIndex(); - if (nameIndex == 0) + int itemCount = notificationNameCombo.getItems().length; + if ((itemCount > 1) && (nameIndex == 0)) { _subscribeButton.setEnabled(false); _unsubscribeButton.setEnabled(false); @@ -475,7 +296,8 @@ public class NotificationsTabControl extends TabControl } int typeIndex = typesCombo.getSelectionIndex(); - if (typeIndex == 0) + itemCount = typesCombo.getItems().length; + if ((itemCount > 1) && (typeIndex == 0)) { _subscribeButton.setEnabled(false); _unsubscribeButton.setEnabled(false); @@ -560,164 +382,38 @@ public class NotificationsTabControl extends TabControl Combo combo = (Combo)e.getSource(); if (combo == notificationNameCombo) { - if (combo.getSelectionIndex() == 0) - { - descriptionLabel.setText(""); - typesCombo.select(0); - typesCombo.setEnabled(false); - return; - } - String index = combo.getItem(combo.getSelectionIndex()); - NotificationInfoModel data = (NotificationInfoModel)combo.getData(index); - descriptionLabel.setText(data.getDescription()); - typesCombo.removeAll(); - typesCombo.setItems(data.getTypes()); - typesCombo.add("Select Type", 0); - typesCombo.select(0); - typesCombo.setEnabled(true); + String selectedItem = combo.getItem(combo.getSelectionIndex()); + populateNotificationType(selectedItem); } checkForEnablingButtons(); } } - /** - * Content provider class for the table viewer - */ - private class ContentProviderImpl implements IStructuredContentProvider, INotificationViewer + private void populateNotificationType(String notificationName) { - public void inputChanged(Viewer v, Object oldInput, Object newInput) + NotificationInfoModel data = (NotificationInfoModel)notificationNameCombo.getData(notificationName); + if (data == null) { - - } - public void dispose() - { - - } - public Object[] getElements(Object parent) - { - return _notifications.toArray(new NotificationObject[0]); - } - public void addNotification(NotificationObject notification) - { - _tableViewer.add(notification); - } - - public void addNotification(List<NotificationObject> notificationList) - { - _tableViewer.add(notificationList.toArray(new NotificationObject[0])); - } - } - - /** - * Label provider for the table viewer - */ - private class LabelProviderImpl implements ITableLabelProvider - { - List<ILabelProviderListener> listeners = new ArrayList<ILabelProviderListener>(); - public void addListener(ILabelProviderListener listener) - { - listeners.add(listener); - } - - public void dispose(){ - - } - - public Image getColumnImage(Object element, int columnIndex) - { - return null; - } - - public String getColumnText(Object element, int columnIndex) - { - String result = null; - NotificationObject t = (NotificationObject)element; - switch(columnIndex) - { - case 0 : - result = String.valueOf(t.getSequenceNo()); - break; - case 1 : - result = String.valueOf(t.getTimeStamp()); - break; - case 2 : - result = t.getType(); - break; - case 3 : - result = t.getMessage(); - break; - default : - result = ""; - } - - return result; - } - - public boolean isLabelProperty(Object element, String property) - { - return false; - } - - public void removeListener(ILabelProviderListener listener) - { - listeners.remove(listener); - } - } // end of LabelProviderImpl - - private boolean workerRunning = false; - private void setWorkerRunning(boolean running) - { - workerRunning = running; - } - - /** - * Worker class which keeps looking if there are new notifications coming from server for the selected mbean - */ - private class Worker implements Runnable - { - public void run() - { - Display display = _tabFolder.getDisplay(); - while(true) - { - if (!workerRunning || _mbean == null || display == null) - { - sleep(); - continue; - } - - display.syncExec(new Runnable() - { - public void run() - { - setWorkerRunning(_form.isVisible()); - if (!workerRunning) return; - - updateTableViewer(); - } - }); - - sleep(); - } + descriptionLabel.setText(""); + typesCombo.select(0); + typesCombo.setEnabled(false); + return; } - - private void sleep() + descriptionLabel.setText(data.getDescription()); + typesCombo.removeAll(); + typesCombo.setItems(data.getTypes()); + if (typesCombo.getItemCount() > 1) { - try - { - Thread.sleep(2000); - } - catch(Exception ex) - { - - } + typesCombo.add(SELECT_NOTIFICATIONTYPE, 0); } + typesCombo.select(0); + typesCombo.setEnabled(true); } /** * Updates the table with new notifications received from mbean server for the selected mbean */ - private void updateTableViewer() + protected void updateTableViewer() { ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(_mbean); List<NotificationObject> newList = serverRegistry.getNotifications(_mbean); diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java index da7d9f94d6..76e84e7684 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java @@ -76,7 +76,7 @@ public class OperationTabControl extends TabControl private SelectionListener operationExecutionListener = new OperationExecutionListener(); private SelectionListener refreshListener = new RefreshListener(); private SelectionListener parameterSelectionListener = new ParameterSelectionListener(); - private SelectionListener bolleanSelectionListener = new BooleanSelectionListener(); + private SelectionListener booleanSelectionListener = new BooleanSelectionListener(); private VerifyListener verifyListener = new VerifyListenerImpl(); private KeyListener keyListener = new KeyListenerImpl(); private KeyListener headerBindingListener = new HeaderBindingKeyListener(); @@ -297,7 +297,7 @@ public class OperationTabControl extends TabControl Button booleanButton = _toolkit.createButton(_paramsComposite, "", SWT.CHECK); booleanButton.setLayoutData(formData); booleanButton.setData(param); - booleanButton.addSelectionListener(bolleanSelectionListener); + booleanButton.addSelectionListener(booleanSelectionListener); valueInCombo = true; } else diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/TabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/TabControl.java index 0793e33538..c13c92066c 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/TabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/TabControl.java @@ -69,7 +69,18 @@ public abstract class TabControl return null; } - public abstract void refresh(ManagedBean mbean); + public void refresh(ManagedBean mbean) + { + if (mbean == null) + { + refresh(); + } + } + + public void refresh() + { + + } public void refresh(ManagedBean mbean, OperationData opData) { diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/VHNotificationsTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/VHNotificationsTabControl.java new file mode 100644 index 0000000000..258f5ce02a --- /dev/null +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/VHNotificationsTabControl.java @@ -0,0 +1,462 @@ +package org.apache.qpid.management.ui.views; + +import static org.apache.qpid.management.ui.Constants.BUTTON_CLEAR; +import static org.apache.qpid.management.ui.Constants.BUTTON_REFRESH; +import static org.apache.qpid.management.ui.Constants.CONSOLE_IMAGE; +import static org.apache.qpid.management.ui.Constants.FONT_BUTTON; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.qpid.management.ui.ApplicationRegistry; +import org.apache.qpid.management.ui.ServerRegistry; +import org.apache.qpid.management.ui.model.NotificationObject; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.widgets.Form; +import org.eclipse.ui.forms.widgets.FormToolkit; + +public class VHNotificationsTabControl extends TabControl +{ + protected FormToolkit _toolkit; + protected Form _form; + protected Table _table = null; + protected TableViewer _tableViewer = null; + + protected Thread worker = null; + + protected List<NotificationObject> _notifications = null; + + private static final String COLUMN_OBJ = "Object Name"; + private static final String COLUMN_SEQ = "Sequence No"; + private static final String COLUMN_TIME = "TimeStamp"; + private static final String COLUMN_TYPE = "Type"; + private static final String COLUMN_MSG = "Notification Message"; + protected static final String[] _tableTitles = new String [] { + COLUMN_OBJ, + COLUMN_SEQ, + COLUMN_TIME, + COLUMN_TYPE, + COLUMN_MSG + }; + + protected Button _clearButton = null; + protected Button _refreshButton = null; + + public VHNotificationsTabControl(TabFolder tabFolder) + { + super(tabFolder); + _toolkit = new FormToolkit(_tabFolder.getDisplay()); + _form = _toolkit.createForm(_tabFolder); + GridLayout gridLayout = new GridLayout(); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + _form.getBody().setLayout(gridLayout); + + worker = new Thread(new Worker()); + worker.start(); + } + + protected void createWidgets() + { + addButtons(); + createTableViewer(); + } + + /** + * @see TabControl#getControl() + */ + public Control getControl() + { + if (_table == null) + { + createWidgets(); + } + return _form; + } + + /** + * Creates clear buttin and refresh button + */ + protected void addButtons() + { + Composite composite = _toolkit.createComposite(_form.getBody(), SWT.NONE); + composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + composite.setLayout(new GridLayout(2, true)); + + // Add Clear Button + _clearButton = _toolkit.createButton(composite, BUTTON_CLEAR, SWT.PUSH | SWT.CENTER); + _clearButton.setFont(ApplicationRegistry.getFont(FONT_BUTTON)); + GridData gridData = new GridData(SWT.LEAD, SWT.TOP, true, false); + gridData.widthHint = 80; + _clearButton.setLayoutData(gridData); + _clearButton.addSelectionListener(new SelectionAdapter() + { + public void widgetSelected(SelectionEvent e) + { + //TODO : Get selected rows and clear those + IStructuredSelection ss = (IStructuredSelection)_tableViewer.getSelection(); + ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(MBeanView.getServer()); + serverRegistry.clearNotifications(null, ss.toList()); + refresh(); + } + }); + + // Add Refresh Button + _refreshButton = _toolkit.createButton(composite, BUTTON_REFRESH, SWT.PUSH | SWT.CENTER); + _refreshButton.setFont(ApplicationRegistry.getFont(FONT_BUTTON)); + gridData = new GridData(SWT.TRAIL, SWT.TOP, true, false); + gridData.widthHint = 80; + _refreshButton.setLayoutData(gridData); + _refreshButton.addSelectionListener(new SelectionAdapter() + { + public void widgetSelected(SelectionEvent e) + { + refresh(); + } + }); + } + + /** + * Creates table to display notifications + */ + private void createTable() + { + _table = _toolkit.createTable(_form.getBody(), SWT.MULTI | SWT.FULL_SELECTION); + _table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + TableColumn column = new TableColumn(_table, SWT.NONE); + column.setText(_tableTitles[0]); + column.setWidth(100); + + column = new TableColumn(_table, SWT.NONE); + column.setText(_tableTitles[1]); + column.setWidth(100); + + column = new TableColumn(_table, SWT.NONE); + column.setText(_tableTitles[2]); + column.setWidth(130); + + column = new TableColumn(_table, SWT.NONE); + column.setText(_tableTitles[3]); + column.setWidth(100); + + column = new TableColumn(_table, SWT.NONE); + column.setText(_tableTitles[4]); + column.setWidth(500); + + _table.setHeaderVisible(true); + _table.setLinesVisible(true); + } + + /** + * Creates JFace viewer for the notifications table + */ + protected void createTableViewer() + { + createTable(); + _tableViewer = new TableViewer(_table); + //_tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + _tableViewer.setUseHashlookup(true); + _tableViewer.setContentProvider(new ContentProviderImpl()); + _tableViewer.setLabelProvider(new LabelProviderImpl()); + _tableViewer.setColumnProperties(_tableTitles); + /* + CellEditor[] cellEditors = new CellEditor[_tableTitles.length]; + TextCellEditor textEditor = new TextCellEditor(table); + cellEditors[0] = textEditor; + textEditor = new TextCellEditor(table); + cellEditors[1] = textEditor; + textEditor = new TextCellEditor(table); + cellEditors[2] = textEditor; + textEditor = new TextCellEditor(table); + cellEditors[3] = textEditor; + + // Assign the cell editors to the viewer + _tableViewer.setCellEditors(cellEditors); + _tableViewer.setCellModifier(new TableCellModifier()); + */ + + addTableListeners(); + + //_tableViewer.addSelectionChangedListener(new ); + + //_notificationDetails = new Composite(_tabControl, SWT.BORDER); + //_notificationDetails.setLayoutData(new GridData(GridData.FILL_BOTH)); + + //_tabControl.layout(); + //viewerComposite.layout(); + } + + /** + * Adds listeners to the viewer for displaying notification details + */ + protected void addTableListeners() + { + _tableViewer.addDoubleClickListener(new IDoubleClickListener() + { + Display display = null; + Shell shell = null; + public void doubleClick(DoubleClickEvent event) + { + display = Display.getCurrent(); + shell = new Shell(display, SWT.BORDER | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.RESIZE); + shell.setText("Notification"); + shell.setImage(ApplicationRegistry.getImage(CONSOLE_IMAGE)); + + int x = display.getBounds().width; + int y = display.getBounds().height; + shell.setBounds(x/4, y/4, x/2, y/3); + StructuredSelection selection = (StructuredSelection)event.getSelection(); + createPopupContents((NotificationObject)selection.getFirstElement()); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + //If you create it, you dispose it. + shell.dispose(); + } + + private void createPopupContents(NotificationObject obj) + { + shell.setLayout(new GridLayout()); + + Composite parent = _toolkit.createComposite(shell, SWT.NONE); + parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayout layout = new GridLayout(4, true); + parent.setLayout(layout); + + // Object name record + Label key = _toolkit.createLabel(parent, COLUMN_OBJ, SWT.TRAIL); + GridData layoutData = new GridData(SWT.TRAIL, SWT.TOP, false, false,1,1); + key.setLayoutData(layoutData); + Text value = _toolkit.createText(parent, obj.getSourceName(), SWT.BEGINNING | SWT.BORDER |SWT.READ_ONLY); + value.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,3,1)); + + // Sequence no record + key = _toolkit.createLabel(parent, COLUMN_SEQ, SWT.TRAIL); + layoutData = new GridData(SWT.TRAIL, SWT.TOP, false, false,1,1); + key.setLayoutData(layoutData); + value = _toolkit.createText(parent, ""+obj.getSequenceNo(), SWT.BEGINNING | SWT.BORDER |SWT.READ_ONLY); + value.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,3,1)); + + // Time row + key = _toolkit.createLabel(parent, COLUMN_TIME, SWT.TRAIL); + key.setLayoutData(new GridData(SWT.TRAIL, SWT.TOP, true, false,1,1)); + value = _toolkit.createText(parent, obj.getTimeStamp(), SWT.BEGINNING | SWT.BORDER | SWT.READ_ONLY); + value.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,3,1)); + + key = _toolkit.createLabel(parent, COLUMN_TYPE, SWT.TRAIL); + key.setLayoutData(new GridData(SWT.TRAIL, SWT.TOP, true, false,1,1)); + value = _toolkit.createText(parent, obj.getType(), SWT.BEGINNING | SWT.BORDER | SWT.READ_ONLY); + value.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,3,1)); + + key = _toolkit.createLabel(parent, COLUMN_MSG, SWT.TRAIL); + key.setLayoutData(new GridData(SWT.TRAIL, SWT.TOP, true, false,1,1)); + value = _toolkit.createText(parent, obj.getMessage(), SWT.MULTI | SWT.WRAP| SWT.BORDER | SWT.V_SCROLL | SWT.READ_ONLY); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1); + gridData.heightHint = 100; + value.setLayoutData(gridData); + } + }); + } + + public void refresh() + { + _notifications = null; + _table.deselectAll(); + _tableViewer.getTable().clearAll(); + + Control[] children = _form.getBody().getChildren(); + for (int i = 0; i < children.length; i++) + { + children[i].setVisible(true); + } + + workerRunning = true; + _form.layout(true); + _form.getBody().layout(true, true); + } + + /** + * Content provider class for the table viewer + */ + protected class ContentProviderImpl implements IStructuredContentProvider, INotificationViewer + { + public void inputChanged(Viewer v, Object oldInput, Object newInput) + { + + } + public void dispose() + { + + } + public Object[] getElements(Object parent) + { + return _notifications.toArray(new NotificationObject[0]); + } + public void addNotification(NotificationObject notification) + { + _tableViewer.add(notification); + } + + public void addNotification(List<NotificationObject> notificationList) + { + _tableViewer.add(notificationList.toArray(new NotificationObject[0])); + } + } + + /** + * Label provider for the table viewer + */ + protected class LabelProviderImpl implements ITableLabelProvider + { + List<ILabelProviderListener> listeners = new ArrayList<ILabelProviderListener>(); + public void addListener(ILabelProviderListener listener) + { + listeners.add(listener); + } + + public void dispose(){ + + } + + public Image getColumnImage(Object element, int columnIndex) + { + return null; + } + + public String getColumnText(Object element, int columnIndex) + { + String result = null; + NotificationObject t = (NotificationObject)element; + switch(columnIndex) + { + case 0 : + result = t.getSourceName(); + break; + case 1 : + result = String.valueOf(t.getSequenceNo()); + break; + case 2 : + result = String.valueOf(t.getTimeStamp()); + break; + case 3 : + result = t.getType(); + break; + case 4 : + result = t.getMessage(); + break; + default : + result = ""; + } + + return result; + } + + public boolean isLabelProperty(Object element, String property) + { + return false; + } + + public void removeListener(ILabelProviderListener listener) + { + listeners.remove(listener); + } + } // end of LabelProviderImpl + + protected boolean workerRunning = false; + protected void setWorkerRunning(boolean running) + { + workerRunning = running; + } + + /** + * Worker class which keeps looking if there are new notifications coming from server for the selected mbean + */ + private class Worker implements Runnable + { + public void run() + { + Display display = _tabFolder.getDisplay(); + while(true) + { + if (!workerRunning || display == null) + { + sleep(); + continue; + } + + display.syncExec(new Runnable() + { + public void run() + { + if (_form == null || _form.isDisposed()) + return; + setWorkerRunning(_form.isVisible()); + if (!workerRunning) return; + + updateTableViewer(); + } + }); + + sleep(); + } + } + + private void sleep() + { + try + { + Thread.sleep(2000); + } + catch(Exception ex) + { + + } + } + } + + /** + * Updates the table with new notifications received from mbean server for all mbeans + */ + protected void updateTableViewer() + { + ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(MBeanView.getServer()); + List<NotificationObject> newList = serverRegistry.getNotifications(null); + if (newList == null) + return; + + _notifications = newList; + _tableViewer.setInput(_notifications); + _tableViewer.refresh(); + } + +} |