Home | History | Annotate | Download | only in actions
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      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, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.monitor.actions;
     18 
     19 import com.android.SdkConstants;
     20 import com.android.ide.eclipse.monitor.MonitorPlugin;
     21 
     22 import org.eclipse.core.runtime.Status;
     23 import org.eclipse.jface.action.IAction;
     24 import org.eclipse.jface.dialogs.ErrorDialog;
     25 import org.eclipse.jface.viewers.ISelection;
     26 import org.eclipse.ui.IWorkbenchWindow;
     27 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
     28 import org.eclipse.ui.PlatformUI;
     29 
     30 import java.io.File;
     31 import java.io.IOException;
     32 
     33 public class SdkManagerAction implements IWorkbenchWindowActionDelegate {
     34     @Override
     35     public void run(IAction action) {
     36         File sdk = MonitorPlugin.getDefault().getSdkFolder();
     37         if (sdk != null) {
     38             File tools = new File(sdk, SdkConstants.FD_TOOLS);
     39             File androidBat = new File(tools, SdkConstants.androidCmdName());
     40             if (androidBat.exists()) {
     41                 String[] cmd = new String[] {
     42                         androidBat.getAbsolutePath(),
     43                         getAndroidBatArgument(),
     44                         };
     45                 try {
     46                     Runtime.getRuntime().exec(cmd);
     47                 } catch (IOException e) {
     48                     IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
     49                     if (window != null) {
     50                         ErrorDialog.openError(
     51                             window.getShell(),
     52                             "Monitor",
     53                             "Error while launching SDK Manager",
     54                             new Status(Status.ERROR,
     55                                     MonitorPlugin.PLUGIN_ID,
     56                                     "Error while launching SDK Manager",
     57                                     e));
     58                     }
     59                 }
     60             }
     61         }
     62     }
     63 
     64     protected String getAndroidBatArgument() {
     65         return "sdk";
     66     }
     67 
     68     @Override
     69     public void selectionChanged(IAction action, ISelection selection) {
     70     }
     71 
     72     @Override
     73     public void dispose() {
     74     }
     75 
     76     @Override
     77     public void init(IWorkbenchWindow window) {
     78     }
     79 }
     80