/**
 * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
 *
 *  Licensed 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.ui.actions;

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.geronimo.ui.internal.Messages;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.internal.browser.WorkbenchBrowserSupport;
import org.eclipse.wst.server.core.IServer;

/**
 * 
 * 
 */
public class LaunchGeronimoConsoleAction implements IActionDelegate {

    public static final String serverID = "org.eclipse.jst.server.geronimo.10";

    /**
     * 
     */
    public LaunchGeronimoConsoleAction() {
        super();
    }
    
    public URL getConsoleUrl() throws MalformedURLException {
        return new URL("http://localhost:8080/console/login.jsp");
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
     */
    public void run(IAction action) {

        try {
            int style = IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.STATUS;
            IWebBrowser browser = WorkbenchBrowserSupport.getInstance().createBrowser(style, "console", Messages.console, Messages.consoleTooltip);
            browser.openURL(getConsoleUrl());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (PartInitException e) {
            e.printStackTrace();
        }

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
     *      org.eclipse.jface.viewers.ISelection)
     */
    public void selectionChanged(IAction action, ISelection selection) {

        IServer server = (IServer) ((StructuredSelection) selection)
                .getFirstElement();

        boolean enable = server != null
                && serverID.equals(server.getServerType().getId())
                && server.getServerState() == IServer.STATE_STARTED;

        action.setEnabled(enable);

    }

}

@@ -772,24 +772,142 @@
 net.URL;%0D%0A%0D%0A
+import org.apache.geronimo.core.internal.GeronimoSchemaNS;%0D%0Aimport org.apache.geronimo.core.internal.GeronimoServer;%0D%0A
 import org.a
@@ -1526,69 +1526,80 @@
 org.
-eclipse.jst.server.geronimo
+apache.geronimo.generic.server
 .10%22;%0D%0A
-%0D%0A
     
-/**
 %0D%0A    
- * %0D%0A     */
+private IServer server;%0D%0A
 %0D%0A  
@@ -1742,69 +1742,174 @@
     
-    return new URL(%22http://localhost:8080/console/login.jsp%22)
+%09if(server != null ) %7B%0D%0A    %09%09return new URL(%22http://%22 + server.getHost() + %22:%22 + ((GeronimoServer) server).getHTTPPort() + %22/console/%22);%0D%0A    %09%7D%0D%0A        return null
 ;%0D%0A 
@@ -2398,16 +2398,87 @@
         
+URL url = getConsoleUrl();%0D%0A            if(url != null) %0D%0A            %09
 browser.
@@ -2485,31 +2485,19 @@
 openURL(
-getConsoleUrl()
+url
 );%0D%0A    
@@ -2946,24 +2946,16 @@
         
-IServer 
 server =

fix launching console