You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ha...@apache.org on 2011/09/20 10:25:41 UTC

svn commit: r1173019 - in /geronimo/devtools/eclipse-plugin/trunk/plugins: org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/ org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ org.apache.geronimo.st.v30....

Author: hanhongfang
Date: Tue Sep 20 08:25:41 2011
New Revision: 1173019

URL: http://svn.apache.org/viewvc?rev=1173019&view=rev
Log:
GERONIMODEVTOOLS-706 Consider enabling Karaf shell in Eclipse console. Patch from Yi Xiao.

Added:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/ServerIdentifier.java   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/actions/SSHTerminalConnectAction.java   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellKeepAliveCommand.java   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellPortCommand.java   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellTimeoutCommand.java   (with props)
Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/META-INF/MANIFEST.MF
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/plugin.properties
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/plugin.xml
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/Activator.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/internal/Messages.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/internal/Messages.properties
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/sections/ServerEditorKarafShellSection.java

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/ServerIdentifier.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/ServerIdentifier.java?rev=1173019&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/ServerIdentifier.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/ServerIdentifier.java Tue Sep 20 08:25:41 2011
@@ -0,0 +1,69 @@
+/**
+ *  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.geronimo.st.core;
+
+import org.eclipse.wst.server.core.IServer;
+
+/**
+ * 
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServerIdentifier {
+    private IServer server;
+    private String serverName;
+    
+    public ServerIdentifier(IServer serever) {
+        this.server = serever;
+        this.serverName = server.getId();
+    }
+
+    public IServer getServer() {
+        return server;
+    }
+
+    public void setServer(IServer server) {
+        this.server = server;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((serverName == null) ? 0 : serverName.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        ServerIdentifier other = (ServerIdentifier) obj;
+        if (serverName == null) {
+            if (other.serverName != null)
+                return false;
+        } else if (!serverName.equals(other.serverName))
+            return false;
+        return true;
+    }
+    
+    
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/ServerIdentifier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/ServerIdentifier.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/ServerIdentifier.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java?rev=1173019&r1=1173018&r2=1173019&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java Tue Sep 20 08:25:41 2011
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
@@ -71,8 +72,8 @@ import org.eclipse.wst.web.internal.depl
  * 
  * @version $Rev$ $Date$
  */
+@SuppressWarnings("restriction")
 public class GeronimoServerDelegate extends ServerDelegate implements IGeronimoServer {
-
     public static final List<String> DEFAULT_NOREDEPLOY_INCLUDE_PATTERNS = 
         Arrays.asList("**/*.html", "**/*.xhtml", "**/*.css", "**/*.js", "**/*.jsp", "**/*.jspx", "**/*.gif", "**/*.jpg", "**/*.png", "**/*.swt", "**/*.properties", "**/*.xml");
     
@@ -95,6 +96,12 @@ public class GeronimoServerDelegate exte
     
     public static final String PROPERTY_KARAF_SHELL = "karafShell";
     
+    public static final String PROPERTY_KARAF_SHELL_TIMEOUT = "karafTimeout";
+    
+    public static final String PROPERTY_KARAF_SHELL_KEEPALIVE = "karafKeepAlive";
+    
+    public static final String PROPERTY_KARAF_SHELL_PORT = "karafPort";
+    
     public static final String PROPERTY_PROGRAM_ARGS = "ProgramArgs";
     
     public static final String PROPERTY_VM_ARGS = "VMArgs";
@@ -118,7 +125,7 @@ public class GeronimoServerDelegate exte
     public static final String PROPERTY_RUN_FROM_WORKSPACE = "runFromWorkspace";
 
     public static final String PROPERTY_SELECT_CLASSPATH_CONTAINERS = "selectClasspathContainers";
-
+    
     public static final String PROPERTY_CLASSPATH_CONTAINERS = "classpathContainers";
 
     public static final String CONSOLE_INFO = "--long";
@@ -127,12 +134,19 @@ public class GeronimoServerDelegate exte
     
     public static final String CLEAN_OSGI_BUNDLE_CACHE = "--clean";
     
-    public static final String DISABLE_KARAF_SHELL = "-Dkaraf.startLocalConsole=false";
+    public static final String DISABLE_LOCAL_KARAF_SHELL = "-Dkaraf.startLocalConsole=false";
+    
+    public static final String ENABLE_LOCAL_KARAF_SHELL = "-Dkaraf.startLocalConsole=true";
     
-    public static final String ENABLE_KARAF_SHELL = "-Dkaraf.startLocalConsole=true";
+    public static final String DISABLE_REMOTE_KARAF_SHELL = "-Dkaraf.startRemoteShell=false";
     
-    // required to avoid error start, and work nicely on windows, when Karaf shell is enabled.
-    public static final String JLINE_UNSUPPORTED_TERMINAL = "-Djline.terminal=jline.UnsupportedTerminal";
+    public static final String ENABLE_REMOTE_KARAF_SHELL = "-Dkaraf.startRemoteShell=true";
+    
+    public static final int KARAF_SHELL_DEFAULT_TIMEOUT = 0;
+    
+    public static final int KARAF_SHELL_DEFAULT_KEEPALIVE = 300;
+    
+    public static final int KARAF_SHELL_DEFAULT_PORT = 8101;
 
     private static IGeronimoVersionHandler versionHandler = null;
 
@@ -523,8 +537,6 @@ public class GeronimoServerDelegate exte
         Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerDelegate.setDefaults", monitor);
     }
 
-    
-
     @Override
     public void saveConfiguration(IProgressMonitor monitor) throws CoreException {
         Trace.tracePoint("Enter", Activator.traceCore, "GeronimoServerDelegate.saveConfiguration", monitor);
@@ -532,8 +544,6 @@ public class GeronimoServerDelegate exte
         Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerDelegate.saveConfiguration", monitor);
     }
     
-    
-
     @Override
     public void configurationChanged() {
         Trace.tracePoint("Enter", Activator.traceCore, "GeronimoServerDelegate.configurationChanged");
@@ -807,7 +817,7 @@ public class GeronimoServerDelegate exte
             Matcher matcher = PARAMETER_PATTERN.matcher(existingVMArgs);
             while (matcher.find()) {
                 String parm = matcher.group();
-                if (parm.equals(ENABLE_KARAF_SHELL)) {
+                if (parm.equals(ENABLE_REMOTE_KARAF_SHELL)) {
                     karafShell = true;
                 }
             }
@@ -843,11 +853,35 @@ public class GeronimoServerDelegate exte
         updateVMArgsFromProperties();
     }
     
+    public int getKarafShellTimeout() {
+        return getAttribute(PROPERTY_KARAF_SHELL_TIMEOUT, KARAF_SHELL_DEFAULT_TIMEOUT);
+    }
+    
+    public int getKarafShellKeepAlive() {
+        return getAttribute(PROPERTY_KARAF_SHELL_KEEPALIVE, KARAF_SHELL_DEFAULT_KEEPALIVE);
+    }
+    
+    public int getKarafShellPort() {
+        return getAttribute(PROPERTY_KARAF_SHELL_PORT, KARAF_SHELL_DEFAULT_PORT);
+    }
+    
+    public void setKarafShellTimeout(int value) {
+        setAttribute(PROPERTY_KARAF_SHELL_TIMEOUT, value);
+    }
+    
+    public void setKarafShellKeepAlive(int value) {
+        setAttribute(PROPERTY_KARAF_SHELL_KEEPALIVE, value);
+    }
+    
+    public void setKarafShellPort(int value) {
+        setAttribute(PROPERTY_KARAF_SHELL_PORT, value);
+    }
+    
     public List<String> getKarafShellArgs(boolean enable) {
         if (enable)
-            return Arrays.asList(ENABLE_KARAF_SHELL, JLINE_UNSUPPORTED_TERMINAL);
+            return Arrays.asList(DISABLE_LOCAL_KARAF_SHELL, ENABLE_REMOTE_KARAF_SHELL);
         else
-            return Arrays.asList(DISABLE_KARAF_SHELL);
+            return Arrays.asList(DISABLE_LOCAL_KARAF_SHELL, DISABLE_REMOTE_KARAF_SHELL);
     }
 
     public String getKarafShellArgs() {
@@ -915,7 +949,6 @@ public class GeronimoServerDelegate exte
                
         // Karaf arguments
         addParm(args, getKarafShellArgs());
-        addParm(args, "-Dkaraf.startRemoteShell=true");
         
         String vmArgs = args.toString();
         Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServer.getVMArgs", vmArgs);
@@ -1113,4 +1146,5 @@ public class GeronimoServerDelegate exte
         setAttribute(GeronimoRuntimeDelegate.SERVER_INSTANCE_PROPERTIES, map);
     }
 
+    
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/META-INF/MANIFEST.MF?rev=1173019&r1=1173018&r2=1173019&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/META-INF/MANIFEST.MF (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/META-INF/MANIFEST.MF Tue Sep 20 08:25:41 2011
@@ -36,6 +36,10 @@ Require-Bundle: 
  org.eclipse.wst.xml.ui,
  org.eclipse.core.variables,
  org.eclipse.pde.core,
- org.eclipse.core.expressions
+ org.eclipse.core.expressions,
+ org.eclipse.tm.terminal.view;bundle-version="[2.1.0,4.0.0)",
+ org.eclipse.tm.terminal;bundle-version="[3.0.100,4.0.0)",
+ org.eclipse.tm.terminal.ssh;bundle-version="[2.0.200,4.0.0)",
+ org.eclipse.tm.terminal.telnet;bundle-version="[2.0.101,4.0.0)"
 Bundle-ActivationPolicy: lazy
 Bundle-Vendor: Apache Software Foundation

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/plugin.properties
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/plugin.properties?rev=1173019&r1=1173018&r2=1173019&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/plugin.properties (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/plugin.properties Tue Sep 20 08:25:41 2011
@@ -25,3 +25,5 @@ PopupMenus.launchSupport=Launch Geronimo
 deploymentPlanEditorName=Geronimo Deployment Plan Editor
 BlueprintEditorName=Geronimo Blueprint Editor
 changeBundleStartLevel=Change Start Level
+geronimo.views.category.name=Geronimo terminal
+karafShellTerminal=Karaf Shell Terminal

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/plugin.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/plugin.xml?rev=1173019&r1=1173018&r2=1173019&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/plugin.xml (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/plugin.xml Tue Sep 20 08:25:41 2011
@@ -126,6 +126,14 @@
     </extension>
     
     <extension point="org.eclipse.wst.server.ui.editorPageSections">
+        <section id="org.apache.server.geronimo.karafShell" order="21"
+            insertionId="org.eclipse.wst.server.editor.overview.left"
+            typeIds="org.apache.geronimo.server.30"
+            class="org.apache.geronimo.st.v30.ui.sections.ServerEditorKarafShellSection">
+        </section>
+    </extension>
+    
+    <extension point="org.eclipse.wst.server.ui.editorPageSections">
         <section id="org.apache.server.geronimo.publishAdvanced" order="10"
             insertionId="org.eclipse.wst.server.editor.overview.right"
             typeIds="org.apache.geronimo.server.30"
@@ -161,14 +169,6 @@
     </extension>
     
     <extension point="org.eclipse.wst.server.ui.editorPageSections">
-        <section id="org.apache.server.geronimo.karafShell" order="22"
-            insertionId="org.eclipse.wst.server.editor.overview.right"
-            typeIds="org.apache.geronimo.server.30"
-            class="org.apache.geronimo.st.v30.ui.sections.ServerEditorKarafShellSection">
-        </section>
-    </extension>
-    
-    <extension point="org.eclipse.wst.server.ui.editorPageSections">
         <section id="org.apache.server.geronimo.loglevel" order="23"
             insertionId="org.eclipse.wst.server.editor.overview.right"
             typeIds="org.apache.geronimo.server.30"
@@ -404,8 +404,38 @@
 
     <extension point="org.eclipse.ui.startup">
         <startup class="org.apache.geronimo.st.v30.ui.Startup"/>
-    </extension>
-    
+    </extension>    
+    	
+    <!-- the karaf shell view -->
+    <extension
+         point="org.eclipse.ui.views">
+      <category
+            name="%geronimo.views.category.name"
+            id="GeronimoViews">
+      </category>
+      <view
+            allowMultiple="true"
+            class="org.apache.geronimo.st.v30.ui.view.KarafShellSSHTerminalView"
+            icon="icons/obj16/littleG.gif"
+            category="GeronimoViews"
+            name="%karafShellTerminal"
+            id="org.apache.geronimo.st.v30.ui.view.KarafShellSSHTerminalView">
+      </view>
+    </extension>
+    <extension
+         point="org.eclipse.ui.perspectiveExtensions">
+      <perspectiveExtension
+            targetID="%karafShellTerminal">
+         <viewShortcut id="org.apache.geronimo.st.v30.ui.view.KarafShellSSHTerminalView"/>
+         <view id="org.apache.geronimo.st.v30.ui.view.KarafShellSSHTerminalView"
+            relationship="stack">
+         </view> 
+      </perspectiveExtension>
+    </extension>  
+
+    <!--
+        The pop up menu of changing the bundle's startup level
+    -->    
     <extension point="org.eclipse.core.expressions.propertyTesters">
        <propertyTester
           id="org.apache.geronimo.st.v30.ui.propertyTester"
@@ -423,9 +453,6 @@
        </propertyTester>
     </extension>
    
-    <!--
-        The pop up menu of changing the bundle's startup level
-    -->
     <extension point="org.eclipse.ui.popupMenus">
       <objectContribution
         id="org.apache.geronimo.st.v30.ui.change.osgi.bundle.startlevel"

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/Activator.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/Activator.java?rev=1173019&r1=1173018&r2=1173019&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/Activator.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/Activator.java Tue Sep 20 08:25:41 2011
@@ -18,9 +18,13 @@ package org.apache.geronimo.st.v30.ui;
 
 import java.io.IOException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
 
+import org.apache.geronimo.st.core.ServerIdentifier;
 import org.apache.geronimo.st.v30.ui.internal.Trace;
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Platform;
@@ -28,6 +32,8 @@ import org.eclipse.jface.resource.ImageD
 import org.eclipse.jface.resource.ImageRegistry;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerListener;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -61,7 +67,9 @@ public class Activator extends AbstractU
     public static boolean traceSections;
     public static boolean traceBlueprint;
     public static boolean traceHandlers;
-
+    
+    private static Map<ServerIdentifier, List<IServerListener>> serverListenersMap = new HashMap<ServerIdentifier, List<IServerListener>>();
+    
     static {
         try {
             console = Boolean.parseBoolean(Platform.getDebugOption(PLUGIN_ID + "/console"));
@@ -99,6 +107,7 @@ public class Activator extends AbstractU
 
     private static String iconLocation;
 
+    @SuppressWarnings("rawtypes")
     private Map imageDescriptors = new HashMap();
 
     public static final String ICONS_DIRECTORY = "icons/";
@@ -120,7 +129,7 @@ public class Activator extends AbstractU
     public void start(BundleContext context) throws Exception {
         super.start(context);
     }
-
+    
     /*
      * (non-Javadoc)
      * 
@@ -129,8 +138,20 @@ public class Activator extends AbstractU
     public void stop(BundleContext context) throws Exception {
         plugin = null;
         super.stop(context);
+        clearServerListeners();
+    }
+    
+    private void clearServerListeners() {
+        Iterator<Map.Entry<ServerIdentifier, List<IServerListener>>> iter = serverListenersMap.entrySet().iterator();
+        while(iter.hasNext()) {
+            Map.Entry<ServerIdentifier, List<IServerListener>> entry = iter.next();
+            IServer server = entry.getKey().getServer();
+            List<IServerListener> listeners = entry.getValue();
+            for(IServerListener ls : listeners) {
+                server.removeServerListener(ls);
+            }
+        }
     }
-
     /**
      * Returns the shared instance
      * 
@@ -163,6 +184,7 @@ public class Activator extends AbstractU
         }
         return iconLocation;
     }
+    
 
     /**
      * Return the image with the given key from the image registry.
@@ -185,6 +207,7 @@ public class Activator extends AbstractU
         registerImage(reg, IMG_PORT, "obj16/port.gif");
     }
 
+    @SuppressWarnings("unchecked")
     private void registerImage(ImageRegistry registry, String key,
             String partialURL) {
 
@@ -198,6 +221,14 @@ public class Activator extends AbstractU
             Trace.trace(Trace.WARNING, "Error registering image", e, Activator.logUi);
         }
     }
-
     
+    public static void addServerListener(ServerIdentifier serverId, IServerListener ls) {
+        List<IServerListener> listeners = serverListenersMap.get(serverId);
+        if(listeners == null) {
+            listeners = new ArrayList<IServerListener>();
+            serverListenersMap.put(serverId, listeners);
+        }
+        serverId.getServer().addServerListener(ls);
+        listeners.add(ls);
+    }
 }

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/actions/SSHTerminalConnectAction.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/actions/SSHTerminalConnectAction.java?rev=1173019&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/actions/SSHTerminalConnectAction.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/actions/SSHTerminalConnectAction.java Tue Sep 20 08:25:41 2011
@@ -0,0 +1,63 @@
+/**
+ *  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.geronimo.st.v30.ui.actions;
+
+import org.apache.geronimo.st.v30.core.GeronimoServerDelegate;
+import org.apache.geronimo.st.v30.ui.internal.Messages;
+import org.apache.geronimo.st.v30.ui.view.KarafShellSSHTerminalView;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.tm.internal.terminal.actions.ActionMessages;
+import org.eclipse.tm.internal.terminal.actions.TerminalAction;
+import org.eclipse.tm.internal.terminal.view.ImageConsts;
+
+/**
+ * 
+ *
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings("restriction")
+public class SSHTerminalConnectAction extends TerminalAction {
+    
+    public SSHTerminalConnectAction(KarafShellSSHTerminalView target)
+    {
+        super(target,
+                SSHTerminalConnectAction.class.getName());
+
+        setupAction(ActionMessages.CONNECT,
+                    ActionMessages.CONNECT,
+                    ImageConsts.IMAGE_CLCL_CONNECT,
+                    ImageConsts.IMAGE_ELCL_CONNECT,
+                    ImageConsts.IMAGE_DLCL_CONNECT,
+                    true);
+    }
+    /* (non-Javadoc)
+     * @see org.eclipse.tm.internal.terminal.actions.TerminalAction#run()
+     */
+    @Override
+    public void run() {
+        KarafShellSSHTerminalView terminalView = (KarafShellSSHTerminalView)fTarget;
+        GeronimoServerDelegate serverDelegate = terminalView.getCurrentServerDelegate();
+        if(serverDelegate != null) {
+            terminalView.doConnect(serverDelegate);
+        } else {
+            MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.karafShellErrorConnect, Messages.karafShellNoConfigExisted);
+        }
+
+    }
+
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/actions/SSHTerminalConnectAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/actions/SSHTerminalConnectAction.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/actions/SSHTerminalConnectAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellKeepAliveCommand.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellKeepAliveCommand.java?rev=1173019&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellKeepAliveCommand.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellKeepAliveCommand.java Tue Sep 20 08:25:41 2011
@@ -0,0 +1,63 @@
+/**
+ *  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.geronimo.st.v30.ui.commands;
+
+import org.apache.geronimo.st.v30.core.GeronimoServerDelegate;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+
+/**
+ * 
+ *
+ * @version $Rev$ $Date$
+ */
+public class SetKarafShellKeepAliveCommand extends ServerCommand {
+    int value;
+    int oldValue;
+    Text text;
+    GeronimoServerDelegate serverDelegate;
+    /**
+     * @param server
+     * @param name
+     */
+    public SetKarafShellKeepAliveCommand(IServerWorkingCopy server, Text text, int value) {
+        super(server, "SetKarafShellKeepAliveCommand");
+        this.text = text;
+        this.value = value;
+        this.serverDelegate = (GeronimoServerDelegate) server.getOriginal().getAdapter(GeronimoServerDelegate.class);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.geronimo.st.v30.ui.commands.ServerCommand#execute()
+     */
+    public void execute() {
+        oldValue = serverDelegate.getKarafShellKeepAlive();
+        server.setAttribute(GeronimoServerDelegate.PROPERTY_KARAF_SHELL_KEEPALIVE, value);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.geronimo.st.v30.ui.commands.ServerCommand#undo()
+     */
+    public void undo() {
+        text.setText(Integer.toString(oldValue));
+        server.setAttribute(GeronimoServerDelegate.PROPERTY_KARAF_SHELL_KEEPALIVE, oldValue);
+    }
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellKeepAliveCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellKeepAliveCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellKeepAliveCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellPortCommand.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellPortCommand.java?rev=1173019&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellPortCommand.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellPortCommand.java Tue Sep 20 08:25:41 2011
@@ -0,0 +1,63 @@
+/**
+ *  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.geronimo.st.v30.ui.commands;
+
+import org.apache.geronimo.st.v30.core.GeronimoServerDelegate;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+
+/**
+ * 
+ *
+ * @version $Rev$ $Date$
+ */
+public class SetKarafShellPortCommand extends ServerCommand{
+    int value;
+    int oldValue;
+    Text text;
+    GeronimoServerDelegate serverDelegate;
+    /**
+     * @param server
+     * @param name
+     */
+    public SetKarafShellPortCommand(IServerWorkingCopy server, Text text, int value) {
+        super(server, "SetKarafShellPortCommand");
+        this.text = text;
+        this.value = value;
+        this.serverDelegate = (GeronimoServerDelegate) server.getOriginal().getAdapter(GeronimoServerDelegate.class);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.geronimo.st.v30.ui.commands.ServerCommand#execute()
+     */
+    public void execute() {
+        oldValue = serverDelegate.getKarafShellPort();
+        server.setAttribute(GeronimoServerDelegate.PROPERTY_KARAF_SHELL_PORT, value);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.geronimo.st.v30.ui.commands.ServerCommand#undo()
+     */
+    public void undo() {
+        text.setText(Integer.toString(oldValue));
+        server.setAttribute(GeronimoServerDelegate.PROPERTY_KARAF_SHELL_PORT, oldValue);
+    }
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellPortCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellPortCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellPortCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellTimeoutCommand.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellTimeoutCommand.java?rev=1173019&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellTimeoutCommand.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellTimeoutCommand.java Tue Sep 20 08:25:41 2011
@@ -0,0 +1,63 @@
+/**
+ *  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.geronimo.st.v30.ui.commands;
+
+import org.apache.geronimo.st.v30.core.GeronimoServerDelegate;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+
+/**
+ * 
+ *
+ * @version $Rev$ $Date$
+ */
+public class SetKarafShellTimeoutCommand extends ServerCommand {
+    int value;
+    int oldValue;
+    Text text;
+    GeronimoServerDelegate serverDelegate;
+    /**
+     * @param server
+     * @param name
+     */
+    public SetKarafShellTimeoutCommand(IServerWorkingCopy server, Text text, int value) {
+        super(server, "SetKarafShellTimeoutCommand");
+        this.text = text;
+        this.value = value;
+        this.serverDelegate = (GeronimoServerDelegate) server.getOriginal().getAdapter(GeronimoServerDelegate.class);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.geronimo.st.v30.ui.commands.ServerCommand#execute()
+     */
+    public void execute() {
+        oldValue = serverDelegate.getKarafShellTimeout();
+        server.setAttribute(GeronimoServerDelegate.PROPERTY_KARAF_SHELL_TIMEOUT, value);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.geronimo.st.v30.ui.commands.ServerCommand#undo()
+     */
+    public void undo() {
+        text.setText(Integer.toString(oldValue));
+        server.setAttribute(GeronimoServerDelegate.PROPERTY_KARAF_SHELL_TIMEOUT, oldValue);
+    }
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellTimeoutCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellTimeoutCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/commands/SetKarafShellTimeoutCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/internal/Messages.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/internal/Messages.java?rev=1173019&r1=1173018&r2=1173019&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/internal/Messages.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/internal/Messages.java Tue Sep 20 08:25:41 2011
@@ -56,6 +56,16 @@ public class Messages extends NLS {
     public static String editorSectionKarafShellTitle;
     public static String editorSectionKarafShellDescription;
     public static String enableKarafShell;
+    public static String karafShellTimeout;
+    public static String karafShellkeepAlive;
+    public static String karafShellPort;
+    public static String karafShellLaunch;
+    public static String karafShellNoConnection;
+    public static String karafShellNoConfigExisted;
+    public static String karafShellTerminalTitle;
+    public static String karafShellErrorConnect;
+    public static String karafShellChangeEnableProblem;
+    public static String karafShellMustChangeBeforeServerStart;
 
     public static String editorSectionTestEnvTitle;
     public static String editorSectionTestEnvDescription;
@@ -629,5 +639,6 @@ public class Messages extends NLS {
     public static String restoreDefaults;
     
     public static String serverLocationVariableDescription;
+    public static String wantToContinue;
 	
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/internal/Messages.properties
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/internal/Messages.properties?rev=1173019&r1=1173018&r2=1173019&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/internal/Messages.properties (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/internal/Messages.properties Tue Sep 20 08:25:41 2011
@@ -111,6 +111,16 @@ changeOSGIBundleStartLevelDescOnError=Th
 editorSectionKarafShellTitle=Karaf Shell in Eclipse Console
 editorSectionKarafShellDescription=Select whether to enable the Karaf shell in Eclipse console window.
 enableKarafShell=Enable
+karafShellTimeout=Timeout(sec):
+karafShellkeepAlive=Keep alive(sec):
+karafShellPort=Port:
+karafShellLaunch=Launch Karaf Shell
+karafShellNoConnection=Karaf Shell No Connection
+karafShellErrorConnect=Karaf Shell Connection Error
+karafShellNoConfigExisted=The Karaf shell configuration does not exist, please launch Karaf shell from the Server Page first time.
+karafShellTerminalTitle=Karaf Shell Terminal
+karafShellChangeEnableProblem=Change Karaf Shell Enablement
+karafShellMustChangeBeforeServerStart =The change of Karaf shell enablement will only be effective after server restart.
 
 editorSectionVMArgsTitle=Server VM Arguments
 editorSectionVMArgsDescription=Specify the Java VM arguments to be provided on server startup.
@@ -622,3 +632,4 @@ wizardPageDescription_ExcludeFilePattern
 restoreDefaults=Restore defaults
 
 serverLocationVariableDescription=The server location of Apache Geronimo 3.0
+wantToContinue=Do you want to continue?

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/sections/ServerEditorKarafShellSection.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/sections/ServerEditorKarafShellSection.java?rev=1173019&r1=1173018&r2=1173019&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/sections/ServerEditorKarafShellSection.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.ui/src/main/java/org/apache/geronimo/st/v30/ui/sections/ServerEditorKarafShellSection.java Tue Sep 20 08:25:41 2011
@@ -16,27 +16,56 @@
  */
 package org.apache.geronimo.st.v30.ui.sections;
 
+import org.apache.geronimo.st.core.ServerIdentifier;
 import org.apache.geronimo.st.v30.core.GeronimoServerDelegate;
+import org.apache.geronimo.st.v30.ui.Activator;
+import org.apache.geronimo.st.v30.ui.CommonMessages;
 import org.apache.geronimo.st.v30.ui.commands.SetKarafShellCommand;
+import org.apache.geronimo.st.v30.ui.commands.SetKarafShellKeepAliveCommand;
+import org.apache.geronimo.st.v30.ui.commands.SetKarafShellPortCommand;
+import org.apache.geronimo.st.v30.ui.commands.SetKarafShellTimeoutCommand;
 import org.apache.geronimo.st.v30.ui.internal.Messages;
+import org.apache.geronimo.st.v30.ui.internal.Trace;
+import org.apache.geronimo.st.v30.ui.view.KarafShellSSHTerminalView;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 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.Display;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.forms.widgets.ExpandableComposite;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerListener;
+import org.eclipse.wst.server.core.ServerEvent;
+import org.eclipse.wst.server.core.util.SocketUtil;
 
 /**
  * @version $Rev$ $Date$
  */
 public class ServerEditorKarafShellSection extends AbstractServerEditorSection {
-
     Button enable;
-
+    
+    Text timeout;
+    Text keepAlive;
+    Text port;
+    Button launchBtn;
+    
+    protected static final String terminalViewId = "org.apache.geronimo.st.v30.ui.view.KarafShellSSHTerminalView";
+    protected static KarafShellSSHTerminalView terminalView;
+    
     public ServerEditorKarafShellSection() {
         super();
     }
@@ -65,23 +94,179 @@ public class ServerEditorKarafShellSecti
         composite.setLayout(layout);
         composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
         section.setClient(composite);
+        
+        Composite subComp0 = toolkit.createComposite(composite);
+        layout = new GridLayout();
+        layout.numColumns = 1;
+        layout.marginHeight = 5;
+        layout.marginWidth = 10;
+        layout.verticalSpacing = 5;
+        layout.horizontalSpacing = 15;
+        subComp0.setLayout(layout);
+        subComp0.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+        
+        Composite subComp1 = toolkit.createComposite(composite);
+        layout = new GridLayout();
+        layout.numColumns = 2;
+        layout.marginHeight = 5;
+        layout.marginWidth = 10;
+        layout.verticalSpacing = 5;
+        layout.horizontalSpacing = 15;
+        subComp1.setLayout(layout);
+        subComp1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+        
+        enable = toolkit.createButton(subComp0, Messages.enableKarafShell, SWT.CHECK);
 
-        enable = toolkit.createButton(composite, Messages.enableKarafShell, SWT.CHECK);
-
-        GeronimoServerDelegate gsd = (GeronimoServerDelegate) server.getAdapter(GeronimoServerDelegate.class);
+        final GeronimoServerDelegate gsdCopy = (GeronimoServerDelegate) server.getAdapter(GeronimoServerDelegate.class);
         
-        boolean karafShell = gsd.isKarafShell();
+        boolean karafShell = gsdCopy.isKarafShell();
         enable.setSelection(karafShell);
 
         enable.addSelectionListener(new SelectionListener() {
 
             public void widgetSelected(SelectionEvent e) {
-                execute(new SetKarafShellCommand(server, enable.getSelection()));
+                int serverState = server.getOriginal().getServerState();
+                if(serverState != IServer.STATE_STOPPED && serverState != IServer.STATE_STOPPING) {
+                    if(MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), Messages.karafShellChangeEnableProblem, 
+                            Messages.karafShellMustChangeBeforeServerStart + "\r\n\r\n" + Messages.wantToContinue)) {
+                        executeAndEnableWidgets();
+                    } else {
+                        enable.setSelection(! enable.getSelection());
+                    }
+                } else {
+                    executeAndEnableWidgets();
+                }
             }
 
             public void widgetDefaultSelected(SelectionEvent e) {
             }
+            
+            private void executeAndEnableWidgets() {
+                execute(new SetKarafShellCommand(server, enable.getSelection()));
+                timeout.setEnabled(enable.getSelection());
+                keepAlive.setEnabled(enable.getSelection());
+                port.setEnabled(enable.getSelection());
+                launchBtn.setEnabled(enable.getSelection() && server.getOriginal().getServerState() == IServer.STATE_STARTED);
+            }
 
         });
+        // create timeout field
+        createLabel(subComp1, Messages.karafShellTimeout, toolkit);
+        timeout = toolkit.createText(subComp1, Integer.toString(gsdCopy.getKarafShellTimeout()), SWT.BORDER);
+        timeout.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+        timeout.setToolTipText(Messages.karafShellTimeout);
+        timeout.addModifyListener(new ModifyListener() {
+            public void modifyText(ModifyEvent e) {
+                Integer value = Integer.valueOf(timeout.getText());
+                execute(new SetKarafShellTimeoutCommand(server, timeout, value));
+            }
+        });
+        // create keep alive field
+        createLabel(subComp1, Messages.karafShellkeepAlive, toolkit);
+        keepAlive = toolkit.createText(subComp1, Integer.toString(gsdCopy.getKarafShellKeepAlive()), SWT.BORDER);
+        keepAlive.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+        keepAlive.setToolTipText(Messages.karafShellkeepAlive);
+        keepAlive.addModifyListener(new ModifyListener() {
+            public void modifyText(ModifyEvent e) {
+                Integer value = Integer.valueOf(keepAlive.getText());
+                execute(new SetKarafShellKeepAliveCommand(server, keepAlive, value));
+            }
+        });
+        // create port field
+        createLabel(subComp1, Messages.karafShellPort, toolkit);
+        port = toolkit.createText(subComp1, Integer.toString(gsdCopy.getKarafShellPort()), SWT.BORDER);
+        port.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+        port.setToolTipText(Messages.karafShellPort);
+        port.addModifyListener(new ModifyListener() {
+            public void modifyText(ModifyEvent e) {
+                Integer value = Integer.valueOf(port.getText());
+                execute(new SetKarafShellPortCommand(server, port, value));
+            }
+        });
+        // create launch ssh terminal button
+        launchBtn = toolkit.createButton(subComp1, Messages.karafShellLaunch, SWT.PUSH);
+        GridData buttonData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
+        launchBtn.setLayoutData(buttonData);
+        launchBtn.setEnabled(enable.getSelection() && server.getOriginal().getServerState() == IServer.STATE_STARTED);
+        
+        launchBtn.addSelectionListener(new SelectionAdapter() {
+
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                if(! isLocalHost()) {
+                    MessageDialog.openError(Display.getCurrent().getActiveShell(), CommonMessages.errorOpenWizard, CommonMessages.isNotLocalHost);
+                } else {
+                    connectToTerminal();
+                }
+            }
+            
+        });
+        Activator.addServerListener(new ServerIdentifier(server.getOriginal()), new IServerListener() {
+            @Override
+            public void serverChanged(ServerEvent event) {
+                Display.getDefault().asyncExec(new Runnable() {
+                    @Override
+                    public void run() {
+                        int state = server.getOriginal().getServerState();
+                        if(state > 4 || launchBtn.isDisposed()) return;
+                        launchBtn.setEnabled(enable.getSelection() && server.getOriginal().getServerState() == IServer.STATE_STARTED);
+                    }
+                });
+                
+            }
+        });
+        
+    }
+    
+    private boolean isLocalHost() {
+        return !(server.getServerType().supportsRemoteHosts()
+                && !SocketUtil.isLocalhost(server.getHost()));
+    }
+    
+    private void connectToTerminal() {
+        final IWorkbenchWindow activeWKBench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+        Display.getDefault().asyncExec(new Runnable() {
+            @Override
+            public void run() {
+                    IWorkbenchPage activePage = getActivePage(activeWKBench);
+                    try {
+                        terminalView = (KarafShellSSHTerminalView) activePage.showView(terminalViewId);
+                        connect();
+                    } catch (PartInitException e) {
+                        e.printStackTrace();
+                    }
+            }
+        });    
+    }
+    
+    private void connect() {
+        GeronimoServerDelegate serverDelegate = (GeronimoServerDelegate) server.getOriginal().getAdapter(GeronimoServerDelegate.class);
+        terminalView.doConnect(serverDelegate);
+    }
+    
+    private IWorkbenchPage getActivePage(IWorkbenchWindow activeWKBench) {
+        try {
+            IWorkbenchPage activePage = activeWKBench.getActivePage();
+            while(activePage == null) {
+                Thread.sleep(100);
+                activePage = activeWKBench.getActivePage();
+            }
+            return activePage;
+        } catch (InterruptedException e) {
+            Trace.trace(Trace.ERROR, "Can not getActivePage", e, Activator.logCommands);
+            throw new RuntimeException(e);
+        } catch (Exception e) {
+            Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.logCommands);
+            throw new RuntimeException(e);
+        }
     }
 }
+
+
+
+
+
+
+
+
+