diff options
| author | Robert Gemmell <robbie@apache.org> | 2009-07-21 09:58:18 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2009-07-21 09:58:18 +0000 |
| commit | d19993e687876d9a7baab81c41deff0f9dc7600a (patch) | |
| tree | 39cb9b3b7653ecb42e882075f0e675e4018b65e2 | |
| parent | c5ba9150ce644b96779c0707332f9da5749dace8 (diff) | |
| download | qpid-python-d19993e687876d9a7baab81c41deff0f9dc7600a.tar.gz | |
QPID-1995 and QPID-1996: Rework the refresh mechanism to stop it clearing all notifications from table and forcing deselection unecessarily. Update the worker thread to only start when the tab is in view and die when it isnt.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@796227 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 106 insertions, 208 deletions
diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java index bd808922f4..a185467e2d 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java @@ -233,7 +233,7 @@ public class MBeanTabFolderFactory return; } - NotificationsTabControl controller = new NotificationsTabControl(tabFolder); + NotificationsTabControl controller = new NotificationsTabControl(tabFolder, mbean); TabItem tab = new TabItem(tabFolder, SWT.NONE); tab.setText(NOTIFICATIONS); 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 6894080859..516b0b3bbf 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 @@ -21,7 +21,6 @@ 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.DESCRIPTION; import static org.apache.qpid.management.ui.Constants.FONT_BOLD; import static org.apache.qpid.management.ui.Constants.FONT_BUTTON; @@ -50,7 +49,6 @@ import org.eclipse.swt.layout.GridLayout; 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.Label; import org.eclipse.swt.widgets.TabFolder; @@ -65,23 +63,25 @@ public class NotificationsTabControl extends VHNotificationsTabControl 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 Combo _notificationNameCombo; + private Combo _typesCombo; + private Label _descriptionLabel; + private Button _subscribeButton; + private Button _unsubscribeButton; - public NotificationsTabControl(TabFolder tabFolder) + public NotificationsTabControl(TabFolder tabFolder, ManagedBean mbean) { super(tabFolder); + _mbean = mbean; + + populateNotificationInfo(); } protected void createWidgets() - { + { selectionListener = new SelectionListenerImpl(); comboListener = new ComboSelectionListener(); createNotificationInfoComposite(); - //addFilterComposite(); addButtons(); createTableViewer(); } @@ -103,21 +103,21 @@ public class NotificationsTabControl extends VHNotificationsTabControl formData.left = new FormAttachment(0, 10); label.setLayoutData(formData); - notificationNameCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN); + _notificationNameCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN); formData = new FormData(); formData.top = new FormAttachment(label, 10); formData.left = new FormAttachment(0, 10); formData.right = new FormAttachment(40); - notificationNameCombo.setLayoutData(formData); - notificationNameCombo.addSelectionListener(comboListener); + _notificationNameCombo.setLayoutData(formData); + _notificationNameCombo.addSelectionListener(comboListener); - typesCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN); + _typesCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN); formData = new FormData(); formData.top = new FormAttachment(label, 10); - formData.left = new FormAttachment(notificationNameCombo, 5); + formData.left = new FormAttachment(_notificationNameCombo, 5); formData.right = new FormAttachment(65); - typesCombo.setLayoutData(formData); - typesCombo.addSelectionListener(comboListener); + _typesCombo.setLayoutData(formData); + _typesCombo.addSelectionListener(comboListener); _subscribeButton = new Button(composite, SWT.PUSH | SWT.CENTER); _subscribeButton.setFont(ApplicationRegistry.getFont(FONT_BUTTON)); @@ -141,30 +141,30 @@ public class NotificationsTabControl extends VHNotificationsTabControl Label fixedLabel = _toolkit.createLabel(composite, ""); formData = new FormData(); - formData.top = new FormAttachment(notificationNameCombo, 5); + formData.top = new FormAttachment(_notificationNameCombo, 5); formData.left = new FormAttachment(0, 10); fixedLabel.setLayoutData(formData); fixedLabel.setText(DESCRIPTION + " : "); fixedLabel.setFont(ApplicationRegistry.getFont(FONT_BOLD)); - descriptionLabel = _toolkit.createLabel(composite, ""); + _descriptionLabel = _toolkit.createLabel(composite, ""); formData = new FormData(); - formData.top = new FormAttachment(notificationNameCombo, 5); + formData.top = new FormAttachment(_notificationNameCombo, 5); formData.left = new FormAttachment(fixedLabel, 10); formData.right = new FormAttachment(100); - descriptionLabel.setLayoutData(formData); - descriptionLabel.setText(" "); - descriptionLabel.setFont(ApplicationRegistry.getFont(FONT_ITALIC)); + _descriptionLabel.setLayoutData(formData); + _descriptionLabel.setText(" "); + _descriptionLabel.setFont(ApplicationRegistry.getFont(FONT_ITALIC)); } /** - * Creates clear buttin and refresh button + * Creates clear 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)); + composite.setLayout(new GridLayout()); // Add Clear Button _clearButton = _toolkit.createButton(composite, BUTTON_CLEAR, SWT.PUSH | SWT.CENTER); @@ -182,74 +182,14 @@ public class NotificationsTabControl extends VHNotificationsTabControl IStructuredSelection ss = (IStructuredSelection)_tableViewer.getSelection(); ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(_mbean); serverRegistry.clearNotifications(_mbean, 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) - { - if (_mbean == null) - return; - - refresh(); } }); } - + @Override public void refresh(ManagedBean mbean) { - _mbean = mbean; - _notifications = null; - _table.deselectAll(); - _tableViewer.getTable().clearAll(); - - if (_mbean == null) - { - _tableViewer.getTable().clearAll(); - _subscribeButton.setEnabled(false); - _unsubscribeButton.setEnabled(false); - return; - } - - if (!doesMBeanSendsNotification()) - { - Control[] children = _form.getBody().getChildren(); - for (int i = 0; i < children.length; i++) - { - children[i].setVisible(false); - } - - String name = (_mbean.getName() != null) ? _mbean.getName() : _mbean.getType(); - _form.setText(name + " does not send any notification"); - return; - } - - Control[] children = _form.getBody().getChildren(); - for (int i = 0; i < children.length; i++) - { - children[i].setVisible(true); - } - - populateNotificationInfo(); - workerRunning = true; - _form.layout(true); - _form.getBody().layout(true, true); - } - - public void refresh() - { - _notifications = null; - _table.deselectAll(); - _tableViewer.getTable().clearAll(); + refresh(); } /** @@ -257,26 +197,26 @@ public class NotificationsTabControl extends VHNotificationsTabControl */ private void populateNotificationInfo() { - notificationNameCombo.removeAll(); + _notificationNameCombo.removeAll(); NotificationInfoModel[] items = MBeanUtility.getNotificationInfo(_mbean); if (items.length > 1) { - notificationNameCombo.add(SELECT_NOTIFICATIONNAME); + _notificationNameCombo.add(SELECT_NOTIFICATIONNAME); } for (int i = 0; i < items.length; i++) { - notificationNameCombo.add(items[i].getName()); - notificationNameCombo.setData(items[i].getName(), items[i]); + _notificationNameCombo.add(items[i].getName()); + _notificationNameCombo.setData(items[i].getName(), items[i]); } - notificationNameCombo.select(0); + _notificationNameCombo.select(0); - typesCombo.removeAll(); - typesCombo.add("Select Type", 0); - typesCombo.select(0); - typesCombo.setEnabled(false); + _typesCombo.removeAll(); + _typesCombo.add("Select Type", 0); + _typesCombo.select(0); + _typesCombo.setEnabled(false); - populateNotificationType(notificationNameCombo.getItem(0)); + populateNotificationType(_notificationNameCombo.getItem(0)); checkForEnablingButtons(); } @@ -285,18 +225,18 @@ public class NotificationsTabControl extends VHNotificationsTabControl */ private void checkForEnablingButtons() { - int nameIndex = notificationNameCombo.getSelectionIndex(); - int itemCount = notificationNameCombo.getItems().length; + int nameIndex = _notificationNameCombo.getSelectionIndex(); + int itemCount = _notificationNameCombo.getItems().length; if ((itemCount > 1) && (nameIndex == 0)) { _subscribeButton.setEnabled(false); _unsubscribeButton.setEnabled(false); - descriptionLabel.setText(""); + _descriptionLabel.setText(""); return; } - int typeIndex = typesCombo.getSelectionIndex(); - itemCount = typesCombo.getItems().length; + int typeIndex = _typesCombo.getSelectionIndex(); + itemCount = _typesCombo.getItems().length; if ((itemCount > 1) && (typeIndex == 0)) { _subscribeButton.setEnabled(false); @@ -304,8 +244,8 @@ public class NotificationsTabControl extends VHNotificationsTabControl return; } - String type = typesCombo.getItem(typeIndex); - String name = notificationNameCombo.getItem(nameIndex); + String type = _typesCombo.getItem(typeIndex); + String name = _notificationNameCombo.getItem(nameIndex); ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(_mbean); if (serverRegistry.hasSubscribedForNotifications(_mbean, name, type)) @@ -320,15 +260,6 @@ public class NotificationsTabControl extends VHNotificationsTabControl } } - private boolean doesMBeanSendsNotification() - { - NotificationInfoModel[] items = MBeanUtility.getNotificationInfo(_mbean); - if (items == null || items.length == 0) - return false; - else - return true; - } - /** * Selection listener for subscribing or unsubscribing the notifications */ @@ -340,8 +271,8 @@ public class NotificationsTabControl extends VHNotificationsTabControl return; Button source = (Button)e.getSource(); - String type = typesCombo.getItem(typesCombo.getSelectionIndex()); - String name = notificationNameCombo.getItem(notificationNameCombo.getSelectionIndex()); + String type = _typesCombo.getItem(_typesCombo.getSelectionIndex()); + String name = _notificationNameCombo.getItem(_notificationNameCombo.getSelectionIndex()); if (source == _unsubscribeButton) { try @@ -380,7 +311,7 @@ public class NotificationsTabControl extends VHNotificationsTabControl return; Combo combo = (Combo)e.getSource(); - if (combo == notificationNameCombo) + if (combo == _notificationNameCombo) { String selectedItem = combo.getItem(combo.getSelectionIndex()); populateNotificationType(selectedItem); @@ -391,23 +322,23 @@ public class NotificationsTabControl extends VHNotificationsTabControl private void populateNotificationType(String notificationName) { - NotificationInfoModel data = (NotificationInfoModel)notificationNameCombo.getData(notificationName); + NotificationInfoModel data = (NotificationInfoModel)_notificationNameCombo.getData(notificationName); if (data == null) { - descriptionLabel.setText(""); - typesCombo.select(0); - typesCombo.setEnabled(false); + _descriptionLabel.setText(""); + _typesCombo.select(0); + _typesCombo.setEnabled(false); return; } - descriptionLabel.setText(data.getDescription()); - typesCombo.removeAll(); - typesCombo.setItems(data.getTypes()); - if (typesCombo.getItemCount() > 1) + _descriptionLabel.setText(data.getDescription()); + _typesCombo.removeAll(); + _typesCombo.setItems(data.getTypes()); + if (_typesCombo.getItemCount() > 1) { - typesCombo.add(SELECT_NOTIFICATIONTYPE, 0); + _typesCombo.add(SELECT_NOTIFICATIONTYPE, 0); } - typesCombo.select(0); - typesCombo.setEnabled(true); + _typesCombo.select(0); + _typesCombo.setEnabled(true); } /** @@ -417,11 +348,8 @@ public class NotificationsTabControl extends VHNotificationsTabControl { ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(_mbean); List<NotificationObject> newList = serverRegistry.getNotifications(_mbean); - if (newList == null) - return; - _notifications = newList; + _tableViewer.setInput(_notifications); - _tableViewer.refresh(); } } 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 index b937c9b29a..0b32da5a29 100644 --- 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 @@ -22,7 +22,6 @@ 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; @@ -35,7 +34,6 @@ 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; @@ -68,7 +66,8 @@ public class VHNotificationsTabControl extends TabControl protected Table _table = null; protected TableViewer _tableViewer = null; - protected Thread worker = null; + protected Thread _worker = null; + protected boolean _workerRunning = false; protected List<NotificationObject> _notifications = null; @@ -86,7 +85,6 @@ public class VHNotificationsTabControl extends TabControl }; protected Button _clearButton = null; - protected Button _refreshButton = null; public VHNotificationsTabControl(TabFolder tabFolder) { @@ -98,8 +96,7 @@ public class VHNotificationsTabControl extends TabControl gridLayout.marginHeight = 0; _form.getBody().setLayout(gridLayout); - worker = new Thread(new Worker()); - worker.start(); + createWidgets(); } protected void createWidgets() @@ -113,10 +110,6 @@ public class VHNotificationsTabControl extends TabControl */ public Control getControl() { - if (_table == null) - { - createWidgets(); - } return _form; } @@ -127,7 +120,7 @@ public class VHNotificationsTabControl extends TabControl { Composite composite = _toolkit.createComposite(_form.getBody(), SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); - composite.setLayout(new GridLayout(2, true)); + composite.setLayout(new GridLayout()); // Add Clear Button _clearButton = _toolkit.createButton(composite, BUTTON_CLEAR, SWT.PUSH | SWT.CENTER); @@ -146,20 +139,6 @@ public class VHNotificationsTabControl extends TabControl 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(); - } - }); } /** @@ -201,36 +180,12 @@ public class VHNotificationsTabControl extends TabControl { 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(); } /** @@ -311,17 +266,19 @@ public class VHNotificationsTabControl extends TabControl public void refresh() { - _notifications = null; - _table.deselectAll(); - _tableViewer.getTable().clearAll(); - - Control[] children = _form.getBody().getChildren(); - for (int i = 0; i < children.length; i++) + if(_workerRunning) + { + //perform an single immediate-update + updateTableViewer(); + } + else { - children[i].setVisible(true); + //start a worker to do the update and keep going as required + _workerRunning = true; + _worker = new Thread(new Worker()); + _worker.start(); } - - workerRunning = true; + _form.layout(true); _form.getBody().layout(true, true); } @@ -413,10 +370,10 @@ public class VHNotificationsTabControl extends TabControl } } // end of LabelProviderImpl - protected boolean workerRunning = false; + protected void setWorkerRunning(boolean running) { - workerRunning = running; + _workerRunning = running; } /** @@ -424,31 +381,45 @@ public class VHNotificationsTabControl extends TabControl */ private class Worker implements Runnable { + private boolean keepGoing = true; + public void run() { - Display display = _tabFolder.getDisplay(); - while(true) + final Display display = _tabFolder.getDisplay(); + if (display == null) + { + setWorkerRunning(false); + return; //stop the thread + } + + while(keepGoing) { - 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(); + { + setWorkerRunning(false); + keepGoing = false; //exit the loop and stop the thread + } + else + { + keepGoing = _form.isVisible(); + setWorkerRunning(keepGoing); + } + + if (keepGoing) + { + updateTableViewer(); + } } - }); + }); - sleep(); + if (keepGoing) + { + sleep(); + } } } @@ -477,7 +448,6 @@ public class VHNotificationsTabControl extends TabControl _notifications = newList; _tableViewer.setInput(_notifications); - _tableViewer.refresh(); } } |
