[jbosstools-commits] JBoss Tools SVN: r43550 - in trunk/as/plugins: org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Sep 10 10:03:33 EDT 2012


Author: rob.stryker at jboss.com
Date: 2012-09-10 10:03:33 -0400 (Mon, 10 Sep 2012)
New Revision: 43550

Modified:
   trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/UnitedServerListener.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXProvider.java
Log:
JBIDE-12563 to trunk

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/UnitedServerListener.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/UnitedServerListener.java	2012-09-10 13:12:45 UTC (rev 43549)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/UnitedServerListener.java	2012-09-10 14:03:33 UTC (rev 43550)
@@ -52,7 +52,7 @@
 	}
 	
 	// Utility method
-	public boolean serverSwitchesToState(ServerEvent event, int state) {
+	public static boolean serverSwitchesToState(ServerEvent event, int state) {
 		int eventKind = event.getKind();
 		if ((eventKind & ServerEvent.SERVER_CHANGE) != 0) {
 			// server change event

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXProvider.java	2012-09-10 13:12:45 UTC (rev 43549)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXProvider.java	2012-09-10 14:03:33 UTC (rev 43550)
@@ -36,7 +36,11 @@
 import org.eclipse.ui.views.IViewDescriptor;
 import org.eclipse.ui.views.IViewRegistry;
 import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerLifecycleListener;
+import org.eclipse.wst.server.core.IServerListener;
+import org.eclipse.wst.server.core.ServerEvent;
 import org.eclipse.wst.server.ui.internal.view.servers.AbstractServerAction;
+import org.jboss.ide.eclipse.as.core.server.UnitedServerListener;
 import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
 import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.ServerExtendedProperties;
 import org.jboss.ide.eclipse.as.core.util.ServerUtil;
@@ -101,7 +105,9 @@
 			}
 		}
 		
-		public class ShowInJMXViewAction extends AbstractServerAction {
+		public class ShowInJMXViewAction extends AbstractServerAction { 
+			private IStructuredSelection previousSelection;
+			private IServerListener serverListener;
 			public ShowInJMXViewAction(ISelectionProvider sp) {
 				super(sp, null);
 				
@@ -109,6 +115,24 @@
 				IViewDescriptor desc = reg.find(JMXNavigator.VIEW_ID);
 				setText(desc.getLabel());
 				setImageDescriptor(desc.getImageDescriptor());
+				serverListener = new IServerListener() {
+					public void serverChanged(final ServerEvent event) {
+						// If this is the server that was / is selected
+						if( previousSelection != null && previousSelection.size() > 0 
+								&& previousSelection.getFirstElement().equals(event.getServer())) {
+							// and it switches state, update enablement
+							Display.getDefault().asyncExec(new Runnable() {
+								public void run() {
+									if( UnitedServerListener.serverSwitchesToState(event, IServer.STATE_STARTED)) {
+										setEnabled(true);
+									} else if( UnitedServerListener.serverSwitchesToState(event, IServer.STATE_STOPPED)) {
+										setEnabled(false);
+									}
+								}
+							});
+						}
+					}
+				};
 			}
 
 			public boolean accept(IServer server) {
@@ -118,7 +142,27 @@
 				IConnectionWrapper connection = JBossJMXConnectionProviderModel.getDefault().getConnection(server);
 				return preconditions && connection.isConnected();
 			}
+			
+			public synchronized void selectionChanged(IStructuredSelection sel) {
+				if( sel.size() == 0 || sel.size() > 1 ) {
+					setEnabled(false);
+					return;
+				}
+				// size = 1
+				switchListener(previousSelection, sel);
+				previousSelection = sel;
+				super.selectionChanged(sel);
+			}
 
+			private void switchListener(IStructuredSelection previousSelection, IStructuredSelection newSel) {
+				if( previousSelection != null ) {
+					IServer s = (IServer)previousSelection.getFirstElement();
+					s.removeServerListener(serverListener);
+				}
+				IServer s2 = (IServer)newSel.getFirstElement();
+				s2.addServerListener(serverListener);
+			}
+			
 			public void perform(final IServer server) {
 				IWorkbenchPart part = null;
 				try {



More information about the jbosstools-commits mailing list