Coverage Report - org.seasar.eclipse.common.util.WorkbenchUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
WorkbenchUtil
0%
0/27
0%
0/12
2.25
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.eclipse.common.util;
 17  
 
 18  
 import java.net.URL;
 19  
 
 20  
 import org.eclipse.ui.IWorkbench;
 21  
 import org.eclipse.ui.IWorkbenchWindow;
 22  
 import org.eclipse.ui.PlatformUI;
 23  
 import org.eclipse.ui.browser.IWebBrowser;
 24  
 import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
 25  
 import org.seasar.eclipse.common.CommonPlugin;
 26  
 import org.seasar.framework.util.StringUtil;
 27  
 
 28  
 /**
 29  
  * @author taichi
 30  
  * 
 31  
  */
 32  0
 public class WorkbenchUtil {
 33  
 
 34  
     public static void openUrl(String url) {
 35  
         try {
 36  0
             openUrl(new URL(url), false);
 37  0
         } catch (Exception e) {
 38  0
             CommonPlugin.log(e);
 39  0
         }
 40  0
     }
 41  
 
 42  
     public static void openUrl(URL url, boolean maybeInternal) {
 43  0
         openUrl(url, maybeInternal, "");
 44  0
     }
 45  
 
 46  
     public static void openUrl(URL url, boolean maybeInternal, String browserId) {
 47  
         try {
 48  0
             IWorkbenchBrowserSupport support = PlatformUI.getWorkbench()
 49  
                     .getBrowserSupport();
 50  0
             IWebBrowser browser = null;
 51  0
             if (maybeInternal && support.isInternalWebBrowserAvailable()) {
 52  0
                 int flag = IWorkbenchBrowserSupport.AS_EDITOR
 53  
                         | IWorkbenchBrowserSupport.LOCATION_BAR
 54  
                         | IWorkbenchBrowserSupport.NAVIGATION_BAR
 55  
                         | IWorkbenchBrowserSupport.STATUS
 56  
                         | IWorkbenchBrowserSupport.PERSISTENT;
 57  0
                 browser = support.createBrowser(flag, StringUtil
 58  
                         .isEmpty(browserId) ? "" : browserId, null, null);
 59  0
             } else {
 60  0
                 browser = support.getExternalBrowser();
 61  
             }
 62  0
             if (browser != null) {
 63  0
                 browser.openURL(url);
 64  
             }
 65  0
         } catch (Exception e) {
 66  0
             CommonPlugin.log(e);
 67  0
         }
 68  0
     }
 69  
 
 70  
     public static IWorkbenchWindow getWorkbenchWindow() {
 71  0
         IWorkbench workbench = PlatformUI.getWorkbench();
 72  0
         IWorkbenchWindow result = workbench.getActiveWorkbenchWindow();
 73  0
         if (result == null && 0 < workbench.getWorkbenchWindowCount()) {
 74  0
             IWorkbenchWindow[] ws = workbench.getWorkbenchWindows();
 75  0
             result = ws[0];
 76  
         }
 77  0
         return result;
 78  
     }
 79  
 
 80  
 }