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.ui.internal.Messages;
   23   import org.apache.geronimo.st.ui.internal.Trace;
   24   import org.eclipse.core.runtime.IConfigurationElement;
   25   import org.eclipse.core.runtime.IExtensionRegistry;
   26   import org.eclipse.core.runtime.Platform;
   27   import org.eclipse.jface.action.IAction;
   28   import org.eclipse.jface.viewers.ISelection;
   29   import org.eclipse.jface.viewers.StructuredSelection;
   30   import org.eclipse.ui.IActionDelegate;
   31   import org.eclipse.ui.PartInitException;
   32   import org.eclipse.ui.browser.IWebBrowser;
   33   import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
   34   import org.eclipse.ui.internal.browser.WorkbenchBrowserSupport;
   35   import org.eclipse.wst.server.core.IServer;
   36   
   37   /**
   38    * @version $Rev: 688899 $ $Date: 2006-11-05 17:47:11 -0500 (Sun, 05 Nov 2006) $
   39    */
   40   public class LaunchGeronimoSupportAction implements IActionDelegate {
   41       
   42       private String serverPrefix;
   43       
   44       private String supportURL;
   45       
   46       private IServer server;
   47       
   48       public LaunchGeronimoSupportAction() {
   49           super();
   50           IExtensionRegistry reg = Platform.getExtensionRegistry();
   51           IConfigurationElement[] extensions = reg
   52                   .getConfigurationElementsFor("org.apache.geronimo.st.ui.actionURLs");
   53           for (IConfigurationElement element : extensions) {
   54               Trace.trace(Trace.INFO, element.getName() + " = "
   55                       + element.getValue() + ".");
   56               if (element.getName().equals("server_prefix")) {
   57                   serverPrefix = element.getValue();
   58                   Trace
   59                           .trace(Trace.INFO, "server_prefix = " + serverPrefix
   60                                   + ".");
   61               } else if (element.getName().equals("action_URL")
   62                       && element
   63                               .getAttribute("class")
   64                               .equals(
   65                                       "org.apache.geronimo.st.ui.actions.LaunchGeronimoSupportAction")) {
   66                   supportURL = element.getAttribute("URL");
   67                   Trace.trace(Trace.INFO, "support URL = " + supportURL + ".");
   68               }
   69           }
   70       }
   71   
   72       public URL getConsoleUrl() throws MalformedURLException {
   73           if (server != null) {
   74               return new URL(supportURL);
   75           }
   76           return null;
   77       }
   78   
   79       /*
   80        * (non-Javadoc)
   81        * 
   82        * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
   83        */
   84       public void run(IAction action) {
   85   
   86           try {
   87               int style = IWorkbenchBrowserSupport.AS_EXTERNAL
   88                       | IWorkbenchBrowserSupport.STATUS;
   89               IWebBrowser browser = WorkbenchBrowserSupport.getInstance()
   90                       .createBrowser(
   91                               style,
   92                               "supportWebPage",
   93                               supportURL,
   94                               Messages.bind(Messages.supportWebPageTooltip, server
   95                                       .getName()));
   96               URL url = getConsoleUrl();
   97               if (url != null)
   98                   browser.openURL(url);
   99           } catch (MalformedURLException e) {
  100               e.printStackTrace();
  101           } catch (PartInitException e) {
  102               e.printStackTrace();
  103           }
  104   
  105       }
  106       
  107       /*
  108        * (non-Javadoc)
  109        * 
  110        * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
  111        *      org.eclipse.jface.viewers.ISelection)
  112        */
  113       public void selectionChanged(IAction action, ISelection selection) {
  114   
  115           server = (IServer) ((StructuredSelection) selection).getFirstElement();
  116   
  117           boolean enable = server != null
  118                            && server.getServerType().getId().startsWith(serverPrefix);
  119   
  120           action.setEnabled(enable);
  121   
  122       }
  123   
  124   }

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