Author: robbie
Date: Mon Jul 27 23:54:54 2009
New Revision: 798337

URL: http://svn.apache.org/viewvc?rev=798337&view=rev
Log:
QPID-1977: add back buton to the mbean view toolbar to navigate back after 
opening mbeans in the mbean view (eg opening a queue directly from the Queues 
selection area, or from an Exchange mbean)

Added:
    qpid/trunk/qpid/java/management/eclipse-plugin/icons/back.gif
    
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/BackAction.java
Modified:
    
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java

Added: qpid/trunk/qpid/java/management/eclipse-plugin/icons/back.gif
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/eclipse-plugin/icons/back.gif?rev=798337&view=auto
==============================================================================
Files qpid/trunk/qpid/java/management/eclipse-plugin/icons/back.gif (added) and 
qpid/trunk/qpid/java/management/eclipse-plugin/icons/back.gif Mon Jul 27 
23:54:54 2009 differ

Added: 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/BackAction.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/BackAction.java?rev=798337&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/BackAction.java
 (added)
+++ 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/BackAction.java
 Mon Jul 27 23:54:54 2009
@@ -0,0 +1,59 @@
+/*
+ *
+ * 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.actions;
+
+import org.apache.qpid.management.ui.jmx.MBeanUtility;
+import org.apache.qpid.management.ui.views.MBeanView;
+import org.eclipse.jface.action.Action;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
+
+
+public class BackAction extends Action implements IWorkbenchAction
+{
+    private static final String ID = 
"org.apache.qpid.management.ui.actions.back";
+
+    public BackAction()
+    {
+        setText("Back");
+        
setImageDescriptor(org.apache.qpid.management.ui.Activator.getImageDescriptor("/icons/back.gif"));
+        setId(ID);
+    }
+
+    public void run()
+    {
+        MBeanView mbeanview = 
(MBeanView)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(MBeanView.ID);
+        try
+        {
+            mbeanview.back();
+        }
+        catch (Exception ex)
+        {
+            MBeanUtility.handleException(ex);
+        }
+
+    }
+
+    public void dispose()
+    {
+
+    }
+}

Modified: 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java?rev=798337&r1=798336&r2=798337&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java
 (original)
+++ 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java
 Mon Jul 27 23:54:54 2009
@@ -20,6 +20,8 @@
  */
 package org.apache.qpid.management.ui.views;
 
+import java.util.LinkedList;
+
 import javax.management.MBeanServerConnection;
 
 import static org.apache.qpid.management.ui.Constants.*;
@@ -29,6 +31,7 @@
 import org.apache.qpid.management.ui.ManagedBean;
 import org.apache.qpid.management.ui.ManagedServer;
 import org.apache.qpid.management.ui.ServerRegistry;
+import org.apache.qpid.management.ui.actions.BackAction;
 import org.apache.qpid.management.ui.jmx.JMXManagedObject;
 import org.apache.qpid.management.ui.jmx.JMXServerRegistry;
 import org.apache.qpid.management.ui.jmx.MBeanUtility;
@@ -71,6 +74,10 @@
     private TabFolder _typeTabFolder = null;
     
     private TabFolder _notificationTabFolder = null;
+
+    private LinkedList<Object> _backHistory;
+    private BackAction _backAction;
+    
     /*
      * Listener for the selection events in the navigation view
      */ 
@@ -90,6 +97,10 @@
             _mbean = null;
             clearView();
             
+            //clear the back history, it is only for use when opening 
subsequent mbeans not in the nav tree
+            _backHistory.clear();
+            _backAction.setEnabled(false);
+            
             // If a selected node(mbean) gets unregistered from mbean server, 
mbeanview should 
             // make the tabfolber for that mbean invisible
             if (_selectedNode == null)
@@ -111,22 +122,48 @@
     
     public void openMBean(ManagedBean mbean)
     {
+        openMBean(mbean, false);
+    }
+    
+    private void openMBean(ManagedBean mbean, boolean undoing)
+    {
         if(mbean == null)
         {
             return;
         }
         
+        //if an mbean is about to be opened (but not returning to using back) 
from the mbean view,
+        //then record the current viewed area/object as a means of back history
+        if(!undoing)
+        {
+            if(_backHistory.isEmpty())
+            {
+                //ensure the button is enabled if this is to be the first 
history item
+                _backAction.setEnabled(true);
+            }
+            
+            if(_mbean == null)
+            {
+                //queue etc selection area is open, record the tree object
+                _backHistory.addLast(_selectedNode);
+            }
+            else
+            {
+                _backHistory.addLast(_mbean); 
+            }
+        }
+        
         _mbean = mbean;
         
         try
         {
             clearView();
+            
+            setFormTitle();
             showMBean(mbean);
             
             _form.layout(true);
             _form.getBody().layout(true, true);
-            
-            setFormTitle();
         }
         catch(Exception ex)
         {
@@ -311,6 +348,11 @@
         createNotificationsTabFolder();
         
         ViewUtility.setMBeanView(this);
+        
+        _backAction = new BackAction();
+        getViewSite().getActionBars().getToolBarManager().add(_backAction);
+        _backAction.setEnabled(false);
+        _backHistory = new LinkedList<Object>();
     }
     
     private void refreshTab(TabItem tab)
@@ -433,10 +475,12 @@
     
     public void mbeanUnregistered(ManagedBean mbean)
     {
-        //if the mbean is actually open, clear the view
+        //if the mbean is actually open, clear the view and empty the Back 
history
         if(mbean == _mbean)
         {
             clearView();
+            _backHistory.clear();
+            _backAction.setEnabled(false);
             ViewUtility.popupInfoMessage("MBean Unregistered", 
                     "The open MBean was unregistered from the server.");
         }
@@ -502,4 +546,45 @@
         IActionBars bars = getViewSite().getActionBars();
         bars.getStatusLineManager().setMessage(message);
     }
+
+    public void back() throws Exception
+    {
+        if(_backHistory.isEmpty())
+        {
+            return;
+        }
+        
+        Object previous = _backHistory.removeLast();
+        if(_backHistory.isEmpty())
+        {
+            //if this is the last history item, disable the action button
+            _backAction.setEnabled(false);
+        }
+        
+        if(previous instanceof ManagedBean)
+        {
+            openMBean((ManagedBean)previous, true);
+        }
+        else if (previous instanceof TreeObject)
+        {
+            _mbean = null;
+            clearView();
+            setFormTitle();
+            
+            TreeObject node = (TreeObject) previous;
+            String mbeanType = node.getType();
+            
+            if (NODE_TYPE_TYPEINSTANCE.equals(mbeanType))
+            {
+                generateTypeTabFolder();
+            }
+            else if (NODE_TYPE_MBEANTYPE.equals(mbeanType))
+            {
+                showTypeTabFolder(node.getName());
+            }
+        }
+        
+        _form.layout(true);
+        _form.getBody().layout(true, true);
+    }
 }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to