Save This Page
Home » geronimo-eclipse-plugin-2.2-source-release » org.apache.geronimo.st.ui.actions » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *    http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.geronimo.st.ui.actions;
   18   
   19   import java.net.MalformedURLException;
   20   import java.net.URL;
   21   
   22   import org.apache.geronimo.st.core.GeronimoServerDelegate;
   23   import org.apache.geronimo.st.ui.internal.Messages;
   24   import org.apache.geronimo.st.ui.internal.Trace;
   25   import org.eclipse.core.runtime.IConfigurationElement;
   26   import org.eclipse.core.runtime.IExtensionRegistry;
   27   import org.eclipse.core.runtime.Platform;
   28   import org.eclipse.jface.action.IAction;
   29   import org.eclipse.jface.viewers.ISelection;
   30   import org.eclipse.jface.viewers.StructuredSelection;
   31   import org.eclipse.ui.IActionDelegate;
   32   import org.eclipse.ui.PartInitException;
   33   import org.eclipse.ui.browser.IWebBrowser;
   34   import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
   35   import org.eclipse.ui.internal.browser.WorkbenchBrowserSupport;
   36   import org.eclipse.wst.server.core.IServer;
   37   
   38   /**
   39    * @version $Rev: 688899 $ $Date: 2008-08-26 06:10:55 +0800 (Tue, 26 Aug 2008) $
   40    */
   41   public class LaunchGeronimoConsoleAction implements IActionDelegate {
   42   
   43   	private IServer server;
   44   
   45   	private String serverPrefix;
   46   
   47   	public LaunchGeronimoConsoleAction() {
   48           super();
   49           IExtensionRegistry reg = Platform.getExtensionRegistry();
   50           IConfigurationElement[] extensions = reg
   51                   .getConfigurationElementsFor("org.apache.geronimo.st.ui.actionURLs");
   52           for (IConfigurationElement element : extensions) {
   53               Trace.trace(Trace.INFO, element.getName() + " = "
   54                       + element.getValue() + ".");
   55               if (element.getName().equals("server_prefix")) {
   56                   serverPrefix = element.getValue();
   57                   Trace
   58                           .trace(Trace.INFO, "server_prefix = " + serverPrefix
   59                                   + ".");
   60               }
   61           }
   62       }
   63   
   64   	public URL getConsoleUrl() throws MalformedURLException {
   65   		if (server != null) {
   66   			GeronimoServerDelegate gs = (GeronimoServerDelegate) server.getAdapter(GeronimoServerDelegate.class);
   67   			return new URL("http://" + server.getHost() + ":"
   68   					+ gs.getHTTPPort() + "/console/");
   69   		}
   70   		return null;
   71   	}
   72   
   73   	/*
   74   	 * (non-Javadoc)
   75   	 * 
   76   	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
   77   	 */
   78   	public void run(IAction action) {
   79   
   80   		try {
   81   			int style = IWorkbenchBrowserSupport.AS_EDITOR
   82   					| IWorkbenchBrowserSupport.STATUS;
   83   			IWebBrowser browser = WorkbenchBrowserSupport.getInstance().createBrowser(style, "console", 
   84                                   Messages.bind(Messages.console, server.getName()),
   85                                   Messages.bind(Messages.consoleTooltip, server
   86                                                   .getName()));
   87   			URL url = getConsoleUrl();
   88   			if (url != null)
   89   				browser.openURL(url);
   90   		} catch (MalformedURLException e) {
   91   			e.printStackTrace();
   92   		} catch (PartInitException e) {
   93   			e.printStackTrace();
   94   		}
   95   
   96   	}
   97   
   98   	/*
   99   	 * (non-Javadoc)
  100   	 * 
  101   	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
  102   	 *      org.eclipse.jface.viewers.ISelection)
  103   	 */
  104   	public void selectionChanged(IAction action, ISelection selection) {
  105   
  106   		server = (IServer) ((StructuredSelection) selection).getFirstElement();
  107   
  108   		boolean enable = server != null
  109   				&& server.getServerType().getId().startsWith(serverPrefix)
  110   				&& server.getServerState() == IServer.STATE_STARTED;
  111   
  112   		action.setEnabled(enable);
  113   
  114   	}
  115   
  116   }

Save This Page
Home » geronimo-eclipse-plugin-2.2-source-release » org.apache.geronimo.st.ui.actions » [javadoc | source]