summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2009-06-26 16:20:34 +0000
committerRobert Gemmell <robbie@apache.org>2009-06-26 16:20:34 +0000
commit4aa0cbe5273955b91437297b45c23218cc149c94 (patch)
tree4e93596403efd608c2718cb7600b553e92e342b5
parent6d75cbc8cd29cd33cfd4abc77cdecf4873c001fc (diff)
downloadqpid-python-4aa0cbe5273955b91437297b45c23218cc149c94.tar.gz
QPID-1942: initial Queue/Exchange/Connection selection work.
Only remove items from the navigation tree config file if removal initiated by the user, not if caused by mbean unregistration. Notify MBeanView explicitly when mbeans are unregistered because new Queue etc selection allows opening Queues etc without adding to the navigation tree, so the previous tree selectionListener is no longer sufficient on its own. Add new refresh method to MBeanView to decouple it from the display of new mbeans based on tree selection, to allow viewing and refreshing mbeans not in the navigation tree. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/jmx_mc_gsoc09@788755 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java2
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java55
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java341
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java191
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java24
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/QueueTypeTabControl.java333
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ConnectionTypeTabControl.java (renamed from qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ConnectionTypeTabControl.java)36
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ExchangeTypeTabControl.java (renamed from qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ExchangeTypeTabControl.java)36
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/MBeanTypeTabControl.java406
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java306
10 files changed, 929 insertions, 801 deletions
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java
index 34251c12d7..dd4cbffd84 100644
--- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java
+++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java
@@ -42,7 +42,7 @@ public class Refresh extends AbstractAction implements IWorkbenchWindowActionDel
MBeanView mbeanview = (MBeanView)_window.getActivePage().findView(MBeanView.ID);
try
{
- mbeanview.refreshMBeanView();
+ mbeanview.refresh();
}
catch (Exception ex)
{
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java
index 08ffffd4ae..46e4426fb8 100644
--- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java
+++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java
@@ -21,7 +21,10 @@
package org.apache.qpid.management.ui.views;
import static org.apache.qpid.management.ui.Constants.ATTRIBUTES;
+import static org.apache.qpid.management.ui.Constants.CONNECTION;
+import static org.apache.qpid.management.ui.Constants.EXCHANGE;
import static org.apache.qpid.management.ui.Constants.NOTIFICATIONS;
+import static org.apache.qpid.management.ui.Constants.QUEUE;
import java.util.EnumSet;
import java.util.HashMap;
@@ -37,6 +40,9 @@ import org.apache.qpid.management.ui.model.NotificationInfoModel;
import org.apache.qpid.management.ui.model.OperationData;
import org.apache.qpid.management.ui.model.OperationDataModel;
import org.apache.qpid.management.ui.views.queue.QueueOperationsTabControl;
+import org.apache.qpid.management.ui.views.type.ConnectionTypeTabControl;
+import org.apache.qpid.management.ui.views.type.ExchangeTypeTabControl;
+import org.apache.qpid.management.ui.views.type.QueueTypeTabControl;
import org.apache.qpid.management.ui.views.users.UserManagementTabControl;
import org.apache.qpid.management.ui.views.logging.ConfigurationFileTabControl;
import org.apache.qpid.management.ui.views.logging.RuntimeTabControl;
@@ -205,6 +211,55 @@ public class MBeanTabFolderFactory
tab.setControl(controller.getControl());
}
+ /**
+ * Creates TabFolder and tabs for each mbeantype (eg Connection, Queue, Exchange)
+ */
+ public static TabFolder generateMBeanTypeTabFolder(final Composite parent)
+ {
+ TabFolder tabFolder = new TabFolder(parent, 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);
+ tabFolder.setLayoutData(layoutData);
+
+ TabItem tab;
+ TabControl controller;
+
+ tab = new TabItem(tabFolder, SWT.NONE);
+ tab.setText(CONNECTION);
+ controller = new ConnectionTypeTabControl(tabFolder);
+ tab.setData(TabControl.CONTROLLER, controller);
+ tab.setControl(controller.getControl());
+
+ tab = new TabItem(tabFolder, SWT.NONE);
+ tab.setText(EXCHANGE);
+ controller = new ExchangeTypeTabControl(tabFolder);
+ tab.setData(TabControl.CONTROLLER, controller);
+ tab.setControl(controller.getControl());
+
+ tab = new TabItem(tabFolder, SWT.NONE);
+ tab.setText(QUEUE);
+ controller = new QueueTypeTabControl(tabFolder);
+ tab.setData(TabControl.CONTROLLER, controller);
+ tab.setControl(controller.getControl());
+
+ tabFolder.addListener(SWT.Selection, new Listener()
+ {
+ public void handleEvent(Event evt)
+ {
+ TabItem tab = (TabItem)evt.item;
+ TabControl controller = (TabControl)tab.getData(TabControl.CONTROLLER);
+ if(controller != null)
+ {
+ controller.refresh(null);
+ }
+ }
+ });
+
+ return tabFolder;
+ }
private enum QpidMBeanType
{
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java
deleted file mode 100644
index 7e04e9ac7a..0000000000
--- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.qpid.management.ui.views;
-
-import static org.apache.qpid.management.ui.Constants.BUTTON_REFRESH;
-import static org.apache.qpid.management.ui.Constants.FONT_BOLD;
-import static org.apache.qpid.management.ui.Constants.FONT_ITALIC;
-import static org.apache.qpid.management.ui.Constants.FONT_NORMAL;
-
-import java.util.Collections;
-import java.util.HashMap;
-
-import org.apache.qpid.management.ui.ApplicationRegistry;
-import org.apache.qpid.management.ui.ManagedBean;
-import org.apache.qpid.management.ui.jmx.MBeanUtility;
-import org.apache.qpid.management.ui.model.AttributeData;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-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.Label;
-import org.eclipse.swt.widgets.List;
-import org.eclipse.swt.widgets.TabFolder;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.forms.widgets.Form;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-
-/**
- * Abstract class to be extended by the Controller classes for different MBean types (Connection, Queue, Exchange)
- */
-public abstract class MBeanTypeTabControl
-{
- private FormToolkit _toolkit = null;
- private Form _form = null;
- private TabFolder _tabFolder = null;
- private Composite _composite = null;
- private Composite _headerComposite = null;
- private Composite _listComposite = null;
- private Label _labelName = null;
- private Label _labelDesc = null;
- private Label _labelList = null;
-
- private org.eclipse.swt.widgets.List _list = null;
- private Button _refreshButton = null;
- private Button _addButton = null;
-
- private String _type = null;
-
- // maps an mbean name with the mbean object. Required to get mbean object when an mbean
- // is to be added to the navigation view.
- private HashMap<String, ManagedBean> _objectsMap = new HashMap<String, ManagedBean>();
- private Sorter _sorterByName = new Sorter();
-
- public MBeanTypeTabControl(TabFolder tabFolder, String type)
- {
- _type = type;
- _tabFolder = tabFolder;
- _toolkit = new FormToolkit(_tabFolder.getDisplay());
- _form = _toolkit.createForm(_tabFolder);
- createFormComposite();
- }
-
- public FormToolkit getToolkit()
- {
- return _toolkit;
- }
-
- public Control getControl()
- {
- return _form;
- }
-
- public String getType()
- {
- return _type;
- }
-
- protected List getListWidget()
- {
- return _list;
- }
-
- protected HashMap<String, ManagedBean> getMBeansMap()
- {
- return _objectsMap;
- }
-
- public Sorter getMBeanNameSorter()
- {
- return _sorterByName;
- }
-
- public Button getAddButton()
- {
- return _addButton;
- }
-
- public Button getRefreshButton()
- {
- return _refreshButton;
- }
-
- /**
- * Creates the main Composite, which will contain all other Composites and Widgets
- */
- protected void createFormComposite()
- {
- _form.getBody().setLayout(new GridLayout());
- _composite = _toolkit.createComposite(_form.getBody(), SWT.NONE);
- _composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- GridLayout layout = new GridLayout();
- layout.verticalSpacing = 10;
- layout.horizontalSpacing = 0;
- _composite.setLayout(layout);
- }
-
- protected Composite getFormComposite()
- {
- return _composite;
- }
-
- /**
- * Creates the header composite, which has MBean type name and description
- * @param parentComposite
- */
- protected void createHeaderComposite(Composite parentComposite)
- {
- _headerComposite = _toolkit.createComposite(parentComposite);
- _headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
- GridLayout layout = new GridLayout();
- layout.verticalSpacing = 10;
- layout.horizontalSpacing = 0;
- _headerComposite.setLayout(layout);
-
- _labelName = _toolkit.createLabel(_headerComposite, "Type:", SWT.NONE);
- GridData gridData = new GridData(SWT.CENTER, SWT.TOP, true, false);
- _labelName.setLayoutData(gridData);
- _labelName.setFont(ApplicationRegistry.getFont(FONT_BOLD));
-
- _labelDesc = _toolkit.createLabel(_headerComposite, " ", SWT.NONE);
- _labelDesc.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false));
- _labelDesc.setFont(ApplicationRegistry.getFont(FONT_ITALIC));
-
- _headerComposite.layout();
- }
-
- /**
- * Creates Composite, which contains the common buttons - Add and Refresh.
- * @param parentComposite
- */
- protected void createButtonsComposite(Composite parentComposite)
- {
- Composite composite = _toolkit.createComposite(parentComposite);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
- GridLayout layout = new GridLayout(2, true);
- layout.verticalSpacing = 10;
- layout.horizontalSpacing = 20;
- composite.setLayout(layout);
-
- createAddButton(composite);
- createRefreshButton(composite);
- }
-
- /**
- * Creates the Add button, which adds the selected item to the navigation view
- * @param parentComposite
- */
- protected void createAddButton(Composite parentComposite)
- {
- Button _addButton = _toolkit.createButton(parentComposite, "<- Add selected " + _type + "(s) to navigation tree", SWT.PUSH);
- GridData gridData = new GridData(SWT.CENTER, SWT.CENTER, false, false);
- _addButton.setLayoutData(gridData);
- _addButton.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e)
- {
- if (_list.getSelectionCount() == 0)
- return;
-
- String[] selectedItems = _list.getSelection();
- for (int i = 0; i < selectedItems.length; i++)
- {
- String name = selectedItems[i];
- int nameEnd = name.indexOf(" (");
- if (nameEnd != -1)
- {
- name = name.substring(0, nameEnd);
- }
- // pass the ManagedBean to the navigation view to be added
- ManagedBean mbean = _objectsMap.get(name);
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- NavigationView view = (NavigationView)window.getActivePage().findView(NavigationView.ID);
- try
- {
- view.addManagedBean(mbean);
- }
- catch (Exception ex)
- {
- MBeanUtility.handleException(mbean, ex);
- }
- }
- }
- });
- }
-
- /**
- * Creates the Refresh button, which gets syncs the items with the broker server
- * @param parentComposite
- */
- protected void createRefreshButton(Composite parentComposite)
- {
- Button _refreshButton = _toolkit.createButton(parentComposite, BUTTON_REFRESH, SWT.PUSH);
- GridData gridData = new GridData(SWT.CENTER, SWT.CENTER, false, false);
- gridData.widthHint = 120;
- _refreshButton.setLayoutData(gridData);
- _refreshButton.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e)
- {
- try
- {
- // refresh the list from the broker server
- populateList();
- }
- catch (Exception ex)
- {
- MBeanUtility.handleException(ex);
- }
- }
- });
- }
-
- /**
- * Creates the Composite, which contains the items ( Connections, Exchanges or Queues)
- * @param parentComposite
- */
- protected void createListComposite(Composite parentComposite)
- {
- // Composite to contain the item list
- _listComposite = _toolkit.createComposite(parentComposite);
- GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- _listComposite.setLayoutData(gridData);
- GridLayout layout = new GridLayout();
- layout.verticalSpacing = 0;
- _listComposite.setLayout(layout);
-
- // Label for item name
- _labelList = _toolkit.createLabel(_listComposite, " ", SWT.CENTER);
- gridData = new GridData(SWT.CENTER, SWT.TOP, true, false, 1, 1);
- _labelList.setLayoutData(gridData);
- _labelList.setFont(ApplicationRegistry.getFont(FONT_NORMAL));
-
- _list = new List(_listComposite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
- gridData = new GridData(SWT.FILL, SWT.FILL, true, true,1, 1);
- _list.setLayoutData(gridData);
-
- }
-
- /**
- * This is called from MBean View to refresh the tab contents
- * @throws Exception
- */
- public void refresh() throws Exception
- {
- setLabelValues();
- populateList();
- layout();
- }
-
- protected void setLabelValues()
- {
- _labelName.setText("Type : " + _type);
- _labelDesc.setText("Select the " + _type + "(s) to add to the navigation tree for further interaction.");
- _labelList.setText("-- List of " + _type + "s --");
- }
-
- protected abstract void populateList() throws Exception;
-
- public void layout()
- {
- _form.layout(true);
- _form.getBody().layout(true, true);
- }
-
- // sets the map with appropriate mbean and name
- protected String[] getItems(java.util.List<ManagedBean> list)
- {
- if (list == null)
- return new String[0];
-
- Collections.sort(list, _sorterByName);
- String[] items = new String[list.size()];
- int i = 0;
- for (ManagedBean mbean : list)
- {
- items[i++] = mbean.getName();
- _objectsMap.put(mbean.getName(), mbean);
- }
- return items;
- }
-
- protected class ComparatorImpl implements java.util.Comparator<AttributeData>
- {
- public int compare(AttributeData data1, AttributeData data2)
- {
- Integer int1 = Integer.parseInt(data1.getValue().toString());
- Integer int2 = Integer.parseInt(data2.getValue().toString());
- return int1.compareTo(int2) * -1;
- }
- }
-
- protected class Sorter implements java.util.Comparator<ManagedBean>
- {
- public int compare(ManagedBean mbean1, ManagedBean mbean2)
- {
- return mbean1.getName().compareTo(mbean2.getName());
- }
- }
-}
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java
index 897b566835..5801b142bd 100644
--- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java
+++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java
@@ -36,8 +36,6 @@ import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.ISelectionListener;
@@ -85,16 +83,43 @@ public class MBeanView extends ViewPart
// mbean should be set to null. A selection done on the navigation view can be either an mbean or
// an mbeantype. For mbeantype selection(eg Connection, Queue, Exchange) _mbean will remain null.
_mbean = null;
- setInvisible();
+ clearView();
// If a selected node(mbean) gets unregistered from mbean server, mbeanview should
// make the tabfolber for that mbean invisible
- if (_selectedNode == null)
+ if (_selectedNode == null)
+ {
return;
+ }
setServer();
- refreshMBeanView();
- setFormTitle();
+ showRelevantTabView();
+ setFormTitle();
+ }
+ }
+
+ public void openMBean(ManagedBean mbean)
+ {
+ if(mbean == null)
+ {
+ return;
+ }
+
+ _mbean = mbean;
+
+ try
+ {
+ clearView();
+ showMBean(mbean);
+
+ _form.layout(true);
+ _form.getBody().layout(true, true);
+
+ setFormTitle();
+ }
+ catch(Exception ex)
+ {
+ MBeanUtility.handleException(mbean, ex);
}
}
@@ -123,7 +148,7 @@ public class MBeanView extends ViewPart
_form.setText(_formText);
}
- public void refreshMBeanView()
+ public void showRelevantTabView()
{
try
{
@@ -131,23 +156,26 @@ public class MBeanView extends ViewPart
{
return;
}
- else if (NODE_TYPE_TYPEINSTANCE.equals(_selectedNode.getType()))
+
+ String mbeanType = _selectedNode.getType();
+
+ if (NODE_TYPE_TYPEINSTANCE.equals(mbeanType))
{
// An virtual host instance is selected
refreshTypeTabFolder(_typeTabFolder.getItem(0));
}
- else if (NODE_TYPE_MBEANTYPE.equals(_selectedNode.getType()))
+ else if (NODE_TYPE_MBEANTYPE.equals(mbeanType))
{
refreshTypeTabFolder(_selectedNode.getName());
}
- else if (NOTIFICATIONS.equals(_selectedNode.getType()))
+ else if (NOTIFICATIONS.equals(mbeanType))
{
refreshNotificationPage();
}
- else if (MBEAN.equals(_selectedNode.getType()))
+ else if (MBEAN.equals(mbeanType))
{
_mbean = (ManagedBean)_selectedNode.getManagedObject();
- showSelectedMBean();
+ showMBean(_mbean);
}
_form.layout(true);
@@ -202,15 +230,15 @@ public class MBeanView extends ViewPart
return _virtualHostName;
}
- private void showSelectedMBean() throws Exception
+ private void showMBean(ManagedBean mbean) throws Exception
{
try
{
- MBeanUtility.getMBeanInfo(_mbean);
+ MBeanUtility.getMBeanInfo(mbean);
}
catch(Exception ex)
{
- MBeanUtility.handleException(_mbean, ex);
+ MBeanUtility.handleException(mbean, ex);
return;
}
@@ -219,7 +247,7 @@ public class MBeanView extends ViewPart
_tabFolder.dispose();
}
- _tabFolder = MBeanTabFolderFactory.generateMBeanTabFolder(_form.getBody(),(JMXManagedObject)_mbean,_mbsc);
+ _tabFolder = MBeanTabFolderFactory.generateMBeanTabFolder(_form.getBody(),(JMXManagedObject)mbean,_mbsc);
int tabIndex = 0;
if (NOTIFICATIONS.equals(_selectedNode.getType()))
@@ -247,7 +275,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();
+ _typeTabFolder = MBeanTabFolderFactory.generateMBeanTypeTabFolder(_form.getBody());
+ _typeTabFolder.setVisible(false);
createNotificationsTabFolder();
}
@@ -260,7 +289,8 @@ public class MBeanView extends ViewPart
}
TabControl controller = (TabControl)tab.getData(TabControl.CONTROLLER);
- if(controller != null){
+ if(controller != null)
+ {
controller.refresh(_mbean);
}
}
@@ -276,54 +306,6 @@ public class MBeanView extends ViewPart
super.dispose();
}
- /**
- * Creates TabFolder and tabs for each mbeantype (eg Connection, Queue, Exchange)
- */
- private void createMBeanTypeTabFolder()
- {
- _typeTabFolder = 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);
- _typeTabFolder.setLayoutData(layoutData);
- _typeTabFolder.setVisible(false);
-
- TabItem tab = new TabItem(_typeTabFolder, SWT.NONE);
- tab.setText(CONNECTION);
- MBeanTypeTabControl controller = new ConnectionTypeTabControl(_typeTabFolder);
- tab.setData(TabControl.CONTROLLER, controller);
- tab.setControl(controller.getControl());
-
- tab = new TabItem(_typeTabFolder, SWT.NONE);
- tab.setText(EXCHANGE);
- controller = new ExchangeTypeTabControl(_typeTabFolder);
- tab.setData(TabControl.CONTROLLER, controller);
- tab.setControl(controller.getControl());
-
- tab = new TabItem(_typeTabFolder, SWT.NONE);
- tab.setText(QUEUE);
- controller = new QueueTypeTabControl(_typeTabFolder);
- tab.setData(TabControl.CONTROLLER, controller);
- tab.setControl(controller.getControl());
-
- _typeTabFolder.addListener(SWT.Selection, new Listener()
- {
- public void handleEvent(Event evt)
- {
- TabItem tab = (TabItem)evt.item;
- try
- {
- refreshTypeTabFolder(tab);
- }
- catch (Exception ex)
- {
- MBeanUtility.handleException(ex);
- }
- }
- });
- }
private void createNotificationsTabFolder()
{
@@ -359,13 +341,8 @@ public class MBeanView extends ViewPart
*/
private void refreshTypeTabFolder(TabItem tab) throws Exception
{
- if (tab == null)
- {
- return;
- }
+ refreshTab(tab);
_typeTabFolder.setSelection(tab);
- MBeanTypeTabControl controller = (MBeanTypeTabControl)tab.getData(TabControl.CONTROLLER);
- controller.refresh();
_typeTabFolder.setVisible(true);
}
@@ -385,22 +362,84 @@ public class MBeanView extends ViewPart
}
}
- private void setInvisible()
+ private void clearView()
{
- if (_tabFolder != null)
+ if (_tabFolder != null && !_tabFolder.isDisposed())
{
_tabFolder.setVisible(false);
}
- if (_typeTabFolder != null)
+ if (_typeTabFolder != null && !_typeTabFolder.isDisposed())
{
_typeTabFolder.setVisible(false);
}
- if (_notificationTabFolder != null)
+ if (_notificationTabFolder != null && !_notificationTabFolder.isDisposed())
{
_notificationTabFolder.setVisible(false);
}
+
+ _form.setText(APPLICATION_NAME);
+ }
+
+ public void mbeanUnregistered(ManagedBean mbean)
+ {
+ //if the mbean is actually open, clear the view
+ if(mbean == _mbean)
+ {
+ clearView();
+ ViewUtility.popupInfoMessage("MBean Unregistered",
+ "The open MBean was been unregistered from the server.");
+ }
+ }
+
+ public void refresh()
+ {
+ if (_tabFolder != null && !_tabFolder.isDisposed())
+ {
+ if(_tabFolder.getVisible())
+ {
+ int selectedTab = _tabFolder.getSelectionIndex();
+ TabItem tab = _tabFolder.getItem(selectedTab);
+ TabControl controller = (TabControl) tab.getData(TabControl.CONTROLLER);
+ if(controller != null)
+ {
+ controller.refresh(_mbean);
+ }
+ return;
+ }
+ }
+
+ if (_typeTabFolder != null && !_typeTabFolder.isDisposed())
+ {
+
+ if(_typeTabFolder.getVisible())
+ {
+ int selectedTab = _typeTabFolder.getSelectionIndex();
+ TabItem tab = _typeTabFolder.getItem(selectedTab);
+ TabControl controller = (TabControl) tab.getData(TabControl.CONTROLLER);
+ if(controller != null)
+ {
+ controller.refresh(_mbean);
+ }
+ return;
+ }
+ }
+
+ if (_notificationTabFolder != null && !_notificationTabFolder.isDisposed())
+ {
+ if(_notificationTabFolder.getVisible())
+ {
+ int selectedTab = _notificationTabFolder.getSelectionIndex();
+ TabItem tab = _notificationTabFolder.getItem(selectedTab);
+ TabControl controller = (TabControl) tab.getData(TabControl.CONTROLLER);
+ if(controller != null)
+ {
+ controller.refresh(_mbean);
+ }
+ return;
+ }
+ }
}
}
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java
index b3caf5e415..08a3563899 100644
--- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java
+++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java
@@ -62,6 +62,8 @@ import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
/**
@@ -190,7 +192,7 @@ public class NavigationView extends ViewPart
{
public void handleEvent(Event e)
{
- removeManagedObject(parentNode, (ManagedBean) selectedNode.getManagedObject());
+ removeManagedObject(parentNode, (ManagedBean) selectedNode.getManagedObject(), true);
_treeViewer.refresh();
// set the selection to the parent node
_treeViewer.setSelection(new StructuredSelection(parentNode));
@@ -675,7 +677,7 @@ public class NavigationView extends ViewPart
* @param parent
* @param mbean
*/
- private void removeManagedObject(TreeObject parent, ManagedBean mbean)
+ private void removeManagedObject(TreeObject parent, ManagedBean mbean, boolean removeFromConfigFile)
{
List<TreeObject> list = parent.getChildren();
TreeObject objectToRemove = null;
@@ -693,14 +695,17 @@ public class NavigationView extends ViewPart
}
else
{
- removeManagedObject(child, mbean);
+ removeManagedObject(child, mbean, removeFromConfigFile);
}
}
if (objectToRemove != null)
{
list.remove(objectToRemove);
- removeItemFromConfigFile(objectToRemove);
+ if(removeFromConfigFile)
+ {
+ removeItemFromConfigFile(objectToRemove);
+ }
}
}
@@ -1201,11 +1206,20 @@ public class NavigationView extends ViewPart
{
public void run()
{
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ final MBeanView view = (MBeanView)window.getActivePage().findView(MBeanView.ID);
+
for (ManagedBean mbean : removalList)
{
TreeObject treeServerObject = _managedServerMap.get(mbean.getServer());
- removeManagedObject(treeServerObject, mbean);
+ if(view != null)
+ {
+ //notify the MBeanView in case the unregistered mbean is being viewed
+ view.mbeanUnregistered(mbean);
+ }
+
+ removeManagedObject(treeServerObject, mbean, false);
}
_treeViewer.refresh();
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/QueueTypeTabControl.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/QueueTypeTabControl.java
deleted file mode 100644
index 6e37e96695..0000000000
--- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/QueueTypeTabControl.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.qpid.management.ui.views;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.apache.qpid.management.ui.ApplicationRegistry;
-import org.apache.qpid.management.ui.Constants;
-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.AttributeData;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-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.Group;
-import org.eclipse.swt.widgets.TabFolder;
-
-/**
- * Controller class, which takes care of displaying appropriate information and widgets for Queues.
- * This allows user to select Queues and add those to the navigation view
- */
-public class QueueTypeTabControl extends MBeanTypeTabControl
-{
- private boolean _showTempQueues = false;
- private Button _sortBySizeButton = null;
- private Button _sortByConsumercountButton = null;
- private Button _sortByNameButton = null;
- private Button _showTempQueuesButton = null;
-
- private ComparatorImpl _sorterByAttribute = new ComparatorImpl();
-
- // Map required for sorting queues based on attribute values
- private Map<AttributeData, ManagedBean> _queueDepthMap = new LinkedHashMap<AttributeData, ManagedBean>();
- // Map used for sorting Queues based on consumer count
- private Map<AttributeData, ManagedBean> _queueConsumerCountMap = new LinkedHashMap<AttributeData, ManagedBean>();
-
-
- public QueueTypeTabControl(TabFolder tabFolder)
- {
- super(tabFolder, Constants.QUEUE);
- createWidgets();
- }
-
- protected void createWidgets()
- {
- createHeaderComposite(getFormComposite());
- createButtonsComposite(getFormComposite());
- createListComposite();
- }
-
- @Override
- public void refresh() throws Exception
- {
- setLabelValues();
- selectDefaultSortingButton();
- populateList();
- layout();
- }
-
- /**
- * populates the map with mbean name and the mbean object.
- * @throws Exception
- */
- protected void populateList() throws Exception
- {
- // map should be cleared before populating it with new values
- getMBeansMap().clear();
- _queueDepthMap.clear();
- _queueConsumerCountMap.clear();
-
- ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(MBeanView.getServer());
- String[] items = null;
- java.util.List<ManagedBean> list = null;
-
- // populate the map and list with appropriate mbeans
- list = serverRegistry.getQueues(MBeanView.getVirtualHost());
- items = getQueueItems(list);
- // sort the refreshed list in the selected order
- if (_sortBySizeButton.getSelection())
- {
- sortQueuesByQueueDepth();
- }
- else if (_sortByConsumercountButton.getSelection())
- {
- sortQueuesByConsumerCount();
- }
- else
- {
- getListWidget().setItems(items);
- }
- }
-
- private void selectDefaultSortingButton()
- {
- _sortByNameButton.setSelection(true);
- _sortBySizeButton.setSelection(false);
- _sortByConsumercountButton.setSelection(false);
-
- _showTempQueues = false;
- _showTempQueuesButton.setSelection(_showTempQueues);
- }
-
- protected void createListComposite()
- {
- // Composite to contain the item list
- Composite composite = getToolkit().createComposite(getFormComposite());
- GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- composite.setLayoutData(gridData);
- GridLayout layout = new GridLayout(2, true);
- layout.verticalSpacing = 0;
- composite.setLayout(layout);
-
- createListComposite(composite);
-
- // Composite to contain buttons like - Sort by size
- Composite _sortingComposite = getToolkit().createComposite(composite);
- gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- _sortingComposite.setLayoutData(gridData);
- GridLayout gridLayout = new GridLayout();
- gridLayout.verticalSpacing = 20;
- _sortingComposite.setLayout(gridLayout);
-
- Group sortingGroup = new Group(_sortingComposite, SWT.SHADOW_NONE);
- sortingGroup.setBackground(_sortingComposite.getBackground());
- sortingGroup.setText(" Sort List By ");
- sortingGroup.setFont(ApplicationRegistry.getFont(Constants.FONT_BOLD));
- gridData = new GridData(SWT.CENTER, SWT.TOP, true, false);
- sortingGroup.setLayoutData(gridData);
- sortingGroup.setLayout(new GridLayout());
-
- _sortByNameButton = getToolkit().createButton(sortingGroup, Constants.QUEUE_SORT_BY_NAME, SWT.RADIO);
- gridData = new GridData(SWT.LEAD, SWT.CENTER, true, false);
- _sortByNameButton.setLayoutData(gridData);
- _sortByNameButton.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e)
- {
- try
- {
- // sort the stored list of items
- java.util.List<String> list = new ArrayList<String>(getMBeansMap().keySet());
- Collections.sort(list);
- getListWidget().setItems(list.toArray(new String[0]));
- }
- catch (Exception ex)
- {
- MBeanUtility.handleException(ex);
- }
- }
- });
-
- _sortBySizeButton = getToolkit().createButton(sortingGroup, Constants.QUEUE_SORT_BY_DEPTH, SWT.RADIO);
- gridData = new GridData(SWT.LEAD, SWT.CENTER, true, false);
- _sortBySizeButton.setLayoutData(gridData);
- _sortBySizeButton.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e)
- {
- try
- {
- // sort the stored list of items
- sortQueuesByQueueDepth();
- }
- catch (Exception ex)
- {
- MBeanUtility.handleException(ex);
- }
- }
- });
-
- _sortByConsumercountButton = getToolkit().createButton(sortingGroup, Constants.QUEUE_SORT_BY_CONSUMERCOUNT, SWT.RADIO);
- gridData = new GridData(SWT.LEAD, SWT.CENTER, true, false);
- _sortByConsumercountButton.setLayoutData(gridData);
- _sortByConsumercountButton.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e)
- {
- try
- {
- sortQueuesByConsumerCount();
- }
- catch (Exception ex)
- {
- MBeanUtility.handleException(ex);
- }
- }
- });
-
- _showTempQueuesButton = getToolkit().createButton(_sortingComposite, Constants.QUEUE_SHOW_TEMP_QUEUES, SWT.CHECK);
- _showTempQueuesButton.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false));
- _showTempQueuesButton.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e)
- {
- Button button = (Button)e.widget;
- _showTempQueues = button.getSelection();
- try
- {
- populateList();
- }
- catch (Exception ex)
- {
- MBeanUtility.handleException(ex);
- }
- }
- });
- }
-
-
- private String[] getQueueItems(java.util.List<ManagedBean> list) throws Exception
- {
- if (list == null)
- return new String[0];
-
- // Sort the list. It will keep the mbeans in sorted order in the _queueMap, which is required for
- // sorting the queue according to size etc
- Collections.sort(list, getMBeanNameSorter());
- java.util.List<String> items = new ArrayList<String>();;
- int i = 0;
- for (ManagedBean mbean : list)
- {
- if ((!_showTempQueues && mbean.isTempQueue()))
- {
- continue;
- }
- String value = mbean.getName();
- items.add(value);
- getMBeansMap().put(value, mbean);
- AttributeData data = MBeanUtility.getAttributeData(mbean, Constants.ATTRIBUTE_QUEUE_DEPTH);
- _queueDepthMap.put(data, mbean);
- data = MBeanUtility.getAttributeData(mbean, Constants.ATTRIBUTE_QUEUE_CONSUMERCOUNT);
- _queueConsumerCountMap.put(data, mbean);
- i++;
- }
-
- return items.toArray(new String[0]);
- }
-
-
- private void sortQueuesByQueueDepth()
- {
- // Queues are already in the alphabetically sorted order in _queueMap, now sort for queueDepth
- java.util.List<AttributeData> list = new ArrayList<AttributeData>(_queueDepthMap.keySet());
- Collections.sort(list, _sorterByAttribute);
-
- String[] items = new String[list.size()];
- int i = 0;
- for (AttributeData data : list)
- {
- ManagedBean mbean = _queueDepthMap.get(data);
- items[i++] = mbean.getName() + " (" + getQueueDepthString(mbean, data) + ")";
- }
- getListWidget().setItems(items);
- }
-
- private String getQueueDepthString(ManagedBean mbean, AttributeData data)
- {
- if (mbean.getVersion() == 1) //mbean returns KB
- {
- Long value = (Long)data.getValue();
-
- Double mb = 1024.0;
-
- if(value > mb) //MB
- {
- return String.format("%.3f", (Double)(value / mb)) + " MB";
- }
- else //KB
- {
- return data.getValue().toString() + " KB";
- }
- }
- else //mbean returns Bytes
- {
- Long value = (Long)data.getValue();
-
- double mb = 1024.0 * 1024.0;
- double kb = 1024.0;
-
- if(value >= mb) //MB
- {
- return String.format("%.3f", (Double)(value / mb)) + " MB";
- }
- else if (value >= kb) //KB
- {
- return String.format("%.3f", (Double)(value / kb)) + " KB";
- }
- else //Bytes
- {
- return data.getValue().toString() + " Bytes";
- }
- }
- }
-
- private void sortQueuesByConsumerCount()
- {
- java.util.List<AttributeData> list = new ArrayList<AttributeData>(_queueConsumerCountMap.keySet());
- Collections.sort(list, _sorterByAttribute);
-
- String[] items = new String[list.size()];
- int i = 0;
- for (AttributeData data : list)
- {
- ManagedBean mbean = _queueConsumerCountMap.get(data);
- String value = data.getValue().toString();
- items[i++] = mbean.getName() + " (" + value + ")";
- }
- getListWidget().setItems(items);
- }
-}
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ConnectionTypeTabControl.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ConnectionTypeTabControl.java
index d891a45210..e0d850bd1e 100644
--- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ConnectionTypeTabControl.java
+++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ConnectionTypeTabControl.java
@@ -18,42 +18,36 @@
* under the License.
*
*/
+package org.apache.qpid.management.ui.views.type;
-package org.apache.qpid.management.ui.views;
+import java.util.List;
+
+import static org.apache.qpid.management.ui.Constants.CONNECTION;
import org.apache.qpid.management.ui.ApplicationRegistry;
-import org.apache.qpid.management.ui.Constants;
import org.apache.qpid.management.ui.ManagedBean;
import org.apache.qpid.management.ui.ServerRegistry;
+import org.apache.qpid.management.ui.views.MBeanView;
import org.eclipse.swt.widgets.TabFolder;
/**
* Controller class, which takes care of displaying appropriate information and widgets for Connections.
* This allows user to select Connections and add those to the navigation view
*/
+
public class ConnectionTypeTabControl extends MBeanTypeTabControl
{
public ConnectionTypeTabControl(TabFolder tabFolder)
{
- super(tabFolder, Constants.CONNECTION);
- createWidgets();
- }
-
- protected void createWidgets()
- {
- createHeaderComposite(getFormComposite());
- createButtonsComposite(getFormComposite());
- createListComposite(getFormComposite());
- }
-
- protected void populateList() throws Exception
- {
- // map should be cleared before populating it with new values
- getMBeansMap().clear();
-
- ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(MBeanView.getServer());
- java.util.List<ManagedBean> list = serverRegistry.getConnections(MBeanView.getVirtualHost());
- getListWidget().setItems(getItems(list));
+ super(tabFolder,CONNECTION);
}
+
+ @Override
+ protected List<ManagedBean> getMbeans()
+ {
+ ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(MBeanView.getServer());
+ return serverRegistry.getConnections(MBeanView.getVirtualHost());
+ }
+
}
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ExchangeTypeTabControl.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ExchangeTypeTabControl.java
index ee55b251ee..710422ab6e 100644
--- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ExchangeTypeTabControl.java
+++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ExchangeTypeTabControl.java
@@ -18,43 +18,31 @@
* under the License.
*
*/
+package org.apache.qpid.management.ui.views.type;
-package org.apache.qpid.management.ui.views;
+import java.util.List;
+
+import static org.apache.qpid.management.ui.Constants.EXCHANGE;
import org.apache.qpid.management.ui.ApplicationRegistry;
-import org.apache.qpid.management.ui.Constants;
import org.apache.qpid.management.ui.ManagedBean;
import org.apache.qpid.management.ui.ServerRegistry;
+import org.apache.qpid.management.ui.views.MBeanView;
import org.eclipse.swt.widgets.TabFolder;
-/**
- * Controller class, which takes care of displaying appropriate information and widgets for Exchanges.
- * This allows user to select Exchanges and add those to the navigation view
- * @author Bhupendra Bhardwaj
- */
public class ExchangeTypeTabControl extends MBeanTypeTabControl
{
-
+
public ExchangeTypeTabControl(TabFolder tabFolder)
{
- super(tabFolder, Constants.EXCHANGE);
- createWidgets();
+ super(tabFolder,EXCHANGE);
}
-
- protected void createWidgets()
- {
- createHeaderComposite(getFormComposite());
- createButtonsComposite(getFormComposite());
- createListComposite(getFormComposite());
- }
-
- protected void populateList() throws Exception
+
+ @Override
+ protected List<ManagedBean> getMbeans()
{
- // map should be cleared before populating it with new values
- getMBeansMap().clear();
-
ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(MBeanView.getServer());
- java.util.List<ManagedBean> list = serverRegistry.getExchanges(MBeanView.getVirtualHost());
- getListWidget().setItems(getItems(list));
+ return serverRegistry.getExchanges(MBeanView.getVirtualHost());
}
+
}
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/MBeanTypeTabControl.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/MBeanTypeTabControl.java
new file mode 100644
index 0000000000..53ed86901b
--- /dev/null
+++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/MBeanTypeTabControl.java
@@ -0,0 +1,406 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.management.ui.views.type;
+
+
+import java.util.List;
+
+import org.apache.qpid.management.ui.ManagedBean;
+import org.apache.qpid.management.ui.jmx.MBeanUtility;
+import org.apache.qpid.management.ui.views.MBeanView;
+import org.apache.qpid.management.ui.views.NavigationView;
+import org.apache.qpid.management.ui.views.TabControl;
+
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+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.TabFolder;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.widgets.Form;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+public abstract class MBeanTypeTabControl extends TabControl
+{
+ private FormToolkit _toolkit;
+ private Form _form;
+ protected Table _table = null;
+ protected TableViewer _tableViewer = null;
+
+ private List<ManagedBean> _mbeans = null;
+ private String _type;
+
+
+ public MBeanTypeTabControl(TabFolder tabFolder, String type)
+ {
+ super(tabFolder);
+ _type = type;
+ _toolkit = new FormToolkit(_tabFolder.getDisplay());
+ _form = _toolkit.createForm(_tabFolder);
+ _form.getBody().setLayout(new GridLayout());
+ createWidgets();
+ }
+
+ /**
+ * @see TabControl#getControl()
+ */
+ public Control getControl()
+ {
+ return _form;
+ }
+
+ /**
+ * @see TabControl#setFocus()
+ */
+ public void setFocus()
+ {
+ _table.setFocus();
+ }
+
+ public void refresh()
+ {
+ refresh(null);
+ }
+
+
+ @Override
+ public void refresh(ManagedBean mbean)
+ {
+ _mbeans = getMbeans();
+ _form.setVisible(false);
+ _tableViewer.setInput(_mbeans);
+ _form.setVisible(true);
+ layout();
+ }
+
+ public void layout()
+ {
+ _form.layout(true);
+ _form.getBody().layout(true, true);
+ }
+
+ protected abstract List<ManagedBean> getMbeans();
+
+ protected void createTable(Composite tableComposite)
+ {
+ _table = new Table (tableComposite, SWT.SINGLE | SWT.SCROLL_LINE | SWT.BORDER | SWT.FULL_SELECTION);
+ _table.setLinesVisible (true);
+ _table.setHeaderVisible (true);
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ _table.setLayoutData(data);
+
+ _tableViewer = new TableViewer(_table);
+ final TableSorter tableSorter = new TableSorter();
+
+ String[] titles = { "Name"};
+ int[] bounds = { 310};
+ for (int i = 0; i < titles.length; i++)
+ {
+ final int index = i;
+ final TableViewerColumn viewerColumn = new TableViewerColumn(_tableViewer, SWT.NONE);
+ final TableColumn column = viewerColumn.getColumn();
+
+ column.setText(titles[i]);
+ column.setWidth(bounds[i]);
+ column.setResizable(true);
+
+ //Setting the right sorter
+ column.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ tableSorter.setColumn(index);
+ final TableViewer viewer = _tableViewer;
+ int dir = viewer .getTable().getSortDirection();
+ if (viewer.getTable().getSortColumn() == column)
+ {
+ dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
+ }
+ else
+ {
+ dir = SWT.UP;
+ }
+ viewer.getTable().setSortDirection(dir);
+ viewer.getTable().setSortColumn(column);
+ viewer.refresh();
+ }
+ });
+
+ }
+
+ _tableViewer.setContentProvider(new ContentProviderImpl());
+ _tableViewer.setLabelProvider(new LabelProviderImpl());
+ _tableViewer.setSorter(tableSorter);
+ _table.setSortColumn(_table.getColumn(0));
+ _table.setSortDirection(SWT.UP);
+ }
+
+
+
+ private void createWidgets()
+ {
+ Composite mainComposite = _toolkit.createComposite(_form.getBody(), SWT.NONE);
+ mainComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ mainComposite.setLayout(new GridLayout());
+
+ Composite buttonComposite = _toolkit.createComposite(mainComposite, SWT.NONE);
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ buttonComposite.setLayoutData(gridData);
+ buttonComposite.setLayout(new GridLayout(2,true));
+
+ final Button favouritesButton = _toolkit.createButton(buttonComposite,
+ "<-- Add " + _type + " to favourites", SWT.PUSH);
+ gridData = new GridData(SWT.LEFT, SWT.CENTER, true, false);
+ favouritesButton.setLayoutData(gridData);
+ favouritesButton.addSelectionListener(new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent e)
+ {
+ int selectionIndex = _table.getSelectionIndex();
+
+ if (selectionIndex != -1)
+ {
+ final ManagedBean selectedMBean = (ManagedBean)_table.getItem(selectionIndex).getData();
+
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ NavigationView view = (NavigationView)window.getActivePage().findView(NavigationView.ID);
+ try
+ {
+ view.addManagedBean(selectedMBean);
+ }
+ catch (Exception ex)
+ {
+ MBeanUtility.handleException(selectedMBean, ex);
+ }
+
+ }
+ }
+ });
+
+ final Button openButton = _toolkit.createButton(buttonComposite, "Open selected " + _type, SWT.PUSH);
+ gridData = new GridData(SWT.RIGHT, SWT.CENTER, true, false);
+ openButton.setLayoutData(gridData);
+ openButton.addSelectionListener(new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent e)
+ {
+ int selectionIndex = _table.getSelectionIndex();
+
+ if (selectionIndex != -1)
+ {
+ final ManagedBean selectedMBean = (ManagedBean)_table.getItem(selectionIndex).getData();
+
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ MBeanView view = (MBeanView) window.getActivePage().findView(MBeanView.ID);
+ try
+ {
+ view.openMBean(selectedMBean);
+ }
+ catch (Exception ex)
+ {
+ MBeanUtility.handleException(selectedMBean, ex);
+ }
+ }
+ }
+ });
+
+ Composite tableComposite = _toolkit.createComposite(mainComposite);
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ tableComposite.setLayoutData(gridData);
+ tableComposite.setLayout(new GridLayout(1,false));
+
+ createTable(tableComposite);
+
+ favouritesButton.setEnabled(false);
+ openButton.setEnabled(false);
+
+ _tableViewer.addSelectionChangedListener(new ISelectionChangedListener(){
+ public void selectionChanged(SelectionChangedEvent evt)
+ {
+ int selectionIndex = _table.getSelectionIndex();
+
+ if (selectionIndex != -1)
+ {
+ favouritesButton.setEnabled(true);
+ openButton.setEnabled(true);
+ }
+ else
+ {
+ favouritesButton.setEnabled(false);
+ openButton.setEnabled(false);
+ }
+ }
+ });
+
+ _table.addMouseListener(new MouseListener()
+ {
+ // MouseListener implementation
+ public void mouseDoubleClick(MouseEvent event)
+ {
+ int selectionIndex = _table.getSelectionIndex();
+
+ if (selectionIndex != -1)
+ {
+ final ManagedBean selectedMBean = (ManagedBean)_table.getItem(selectionIndex).getData();
+
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ MBeanView view = (MBeanView) window.getActivePage().findView(MBeanView.ID);
+ try
+ {
+ view.openMBean(selectedMBean);
+ }
+ catch (Exception ex)
+ {
+ MBeanUtility.handleException(selectedMBean, ex);
+ }
+ }
+ }
+
+ public void mouseDown(MouseEvent e){}
+ public void mouseUp(MouseEvent e){}
+ });
+ }
+
+ /**
+ * Content Provider class for the table viewer
+ */
+ private class ContentProviderImpl implements IStructuredContentProvider
+ {
+
+ public void inputChanged(Viewer v, Object oldInput, Object newInput)
+ {
+
+ }
+
+ public void dispose()
+ {
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object[] getElements(Object parent)
+ {
+ return ((List<ManagedBean>) parent).toArray();
+ }
+ }
+
+ /**
+ * Label Provider class for the table viewer
+ */
+ private class LabelProviderImpl extends LabelProvider implements ITableLabelProvider
+ {
+ @Override
+ public String getColumnText(Object element, int columnIndex)
+ {
+ switch (columnIndex)
+ {
+ case 0 : // name column
+ return ((ManagedBean) element).getName();
+ default:
+ return "-";
+ }
+ }
+
+ @Override
+ public Image getColumnImage(Object element, int columnIndex)
+ {
+ return null;
+ }
+
+ }
+
+ /**
+ * Sorter class for the table viewer.
+ *
+ */
+ private class TableSorter extends ViewerSorter
+ {
+ private int column;
+ private static final int ASCENDING = 0;
+ private static final int DESCENDING = 1;
+
+ private int direction;
+
+ public TableSorter()
+ {
+ this.column = 0;
+ direction = ASCENDING;
+ }
+
+ public void setColumn(int column)
+ {
+ if(column == this.column)
+ {
+ // Same column as last sort; toggle the direction
+ direction = 1 - direction;
+ }
+ else
+ {
+ // New column; do an ascending sort
+ this.column = column;
+ direction = ASCENDING;
+ }
+ }
+
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2)
+ {
+ ManagedBean mbean1 = (ManagedBean) e1;
+ ManagedBean mbean2 = (ManagedBean) e2;
+
+ int comparison = 0;
+ switch(column)
+ {
+ case 0:
+ comparison = mbean1.getName().compareTo(mbean2.getName());
+ break;
+ default:
+ comparison = 0;
+ }
+ // If descending order, flip the direction
+ if(direction == DESCENDING)
+ {
+ comparison = -comparison;
+ }
+ return comparison;
+ }
+ }
+}
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java
new file mode 100644
index 0000000000..0e48c80a79
--- /dev/null
+++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java
@@ -0,0 +1,306 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.management.ui.views.type;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import static org.apache.qpid.management.ui.Constants.QUEUE;
+
+import org.apache.qpid.management.ui.ApplicationRegistry;
+import org.apache.qpid.management.ui.Constants;
+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.AttributeData;
+import org.apache.qpid.management.ui.views.MBeanView;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+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.widgets.Composite;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+public class QueueTypeTabControl extends MBeanTypeTabControl
+{
+ private HashMap<ManagedBean, Long> _queueDepths = new HashMap<ManagedBean, Long>();
+ private HashMap<ManagedBean, Long> _activeConsumerCounts = new HashMap<ManagedBean, Long>();
+
+
+ public QueueTypeTabControl(TabFolder tabFolder)
+ {
+ super(tabFolder,QUEUE);
+ }
+
+ @Override
+ protected List<ManagedBean> getMbeans()
+ {
+ ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(MBeanView.getServer());
+ try
+ {
+ return extractQueueDetails(serverRegistry.getQueues(MBeanView.getVirtualHost()));
+ }
+ catch(Exception e)
+ {
+ MBeanUtility.handleException(null, e);
+ return null;
+ }
+
+ }
+
+ private List<ManagedBean> extractQueueDetails(List<ManagedBean> list) throws Exception
+ {
+ _queueDepths.clear();
+ _activeConsumerCounts.clear();
+
+ List<ManagedBean> items = new ArrayList<ManagedBean>();
+ for (ManagedBean mbean : list)
+ {
+ AttributeData data = MBeanUtility.getAttributeData(mbean, Constants.ATTRIBUTE_QUEUE_DEPTH);
+ _queueDepths.put(mbean, Long.valueOf(data.getValue().toString()));
+ data = MBeanUtility.getAttributeData(mbean, Constants.ATTRIBUTE_QUEUE_CONSUMERCOUNT);
+ _activeConsumerCounts.put(mbean, Long.valueOf(data.getValue().toString()));
+
+ items.add(mbean);
+ }
+
+ return items;
+ }
+
+ @Override
+ protected void createTable(Composite tableComposite)
+ {
+ _table = new Table (tableComposite, SWT.SINGLE | SWT.SCROLL_LINE | SWT.BORDER | SWT.FULL_SELECTION);
+ _table.setLinesVisible (true);
+ _table.setHeaderVisible (true);
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ _table.setLayoutData(data);
+
+ _tableViewer = new TableViewer(_table);
+ final TableSorter tableSorter = new TableSorter();
+
+ String[] titles = { "Name", "QueueDepth", "Active Consumer Count"};
+ int[] bounds = { 250, 175, 175};
+ for (int i = 0; i < titles.length; i++)
+ {
+ final int index = i;
+ final TableViewerColumn viewerColumn = new TableViewerColumn(_tableViewer, SWT.NONE);
+ final TableColumn column = viewerColumn.getColumn();
+
+ column.setText(titles[i]);
+ column.setWidth(bounds[i]);
+ column.setResizable(true);
+
+ //Setting the right sorter
+ column.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ tableSorter.setColumn(index);
+ final TableViewer viewer = _tableViewer;
+ int dir = viewer .getTable().getSortDirection();
+ if (viewer.getTable().getSortColumn() == column)
+ {
+ dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
+ }
+ else
+ {
+ dir = SWT.UP;
+ }
+ viewer.getTable().setSortDirection(dir);
+ viewer.getTable().setSortColumn(column);
+ viewer.refresh();
+ }
+ });
+
+ }
+
+ _tableViewer.setContentProvider(new ContentProviderImpl());
+ _tableViewer.setLabelProvider(new LabelProviderImpl());
+ _tableViewer.setSorter(tableSorter);
+ _table.setSortColumn(_table.getColumn(0));
+ _table.setSortDirection(SWT.UP);
+ }
+
+ /**
+ * Content Provider class for the table viewer
+ */
+ private class ContentProviderImpl implements IStructuredContentProvider
+ {
+
+ public void inputChanged(Viewer v, Object oldInput, Object newInput)
+ {
+
+ }
+
+ public void dispose()
+ {
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object[] getElements(Object parent)
+ {
+ return ((List<ManagedBean>) parent).toArray();
+ }
+ }
+
+ /**
+ * Label Provider class for the table viewer
+ */
+ private class LabelProviderImpl extends LabelProvider implements ITableLabelProvider
+ {
+ @Override
+ public String getColumnText(Object element, int columnIndex)
+ {
+ ManagedBean mbean = (ManagedBean) element;
+
+ switch (columnIndex)
+ {
+ case 0 : // name column
+ return mbean.getName();
+ case 1 : // queue depth column
+ return getQueueDepthString(mbean, _queueDepths.get(mbean));
+ case 2 : // consumer count column
+ return String.valueOf(_activeConsumerCounts.get(mbean));
+ default:
+ return "-";
+ }
+ }
+
+ @Override
+ public Image getColumnImage(Object element, int columnIndex)
+ {
+ return null;
+ }
+ }
+
+ private String getQueueDepthString(ManagedBean mbean, Long value)
+ {
+ if (mbean.getVersion() == 1) //mbean is v1 and returns KB
+ {
+ Double mb = 1024.0;
+
+ if(value > mb) //MB
+ {
+ return String.format("%.3f", (Double)(value / mb)) + " MB";
+ }
+ else //KB
+ {
+ return value + " KB";
+ }
+ }
+ else //mbean is v2+ and returns Bytes
+ {
+ double mb = 1024.0 * 1024.0;
+ double kb = 1024.0;
+
+ if(value >= mb) //MB
+ {
+ return String.format("%.3f", (Double)(value / mb)) + " MB";
+ }
+ else if (value >= kb) //KB
+ {
+ return String.format("%.3f", (Double)(value / kb)) + " KB";
+ }
+ else //Bytes
+ {
+ return value + " Bytes";
+ }
+ }
+ }
+
+ /**
+ * Sorter class for the table viewer.
+ *
+ */
+ private class TableSorter extends ViewerSorter
+ {
+ private int column;
+ private static final int ASCENDING = 0;
+ private static final int DESCENDING = 1;
+
+ private int direction;
+
+ public TableSorter()
+ {
+ this.column = 0;
+ direction = ASCENDING;
+ }
+
+ public void setColumn(int column)
+ {
+ if(column == this.column)
+ {
+ // Same column as last sort; toggle the direction
+ direction = 1 - direction;
+ }
+ else
+ {
+ // New column; do an ascending sort
+ this.column = column;
+ direction = ASCENDING;
+ }
+ }
+
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2)
+ {
+ ManagedBean mbean1 = (ManagedBean) e1;
+ ManagedBean mbean2 = (ManagedBean) e2;
+
+ int comparison = 0;
+ switch(column)
+ {
+ case 0: //name
+ comparison = mbean1.getName().compareTo(mbean2.getName());
+ break;
+ case 1: //queue depth
+ comparison = _queueDepths.get(mbean1).compareTo(_queueDepths.get(mbean2));
+ break;
+ case 2: //active consumer count
+ comparison = _activeConsumerCounts.get(mbean1).compareTo(_activeConsumerCounts.get(mbean2));
+ break;
+ default:
+ comparison = 0;
+ }
+ // If descending order, flip the direction
+ if(direction == DESCENDING)
+ {
+ comparison = -comparison;
+ }
+ return comparison;
+ }
+ }
+
+}