Commits

Anonymous committed 59ae231

Add an action to start SDK and AVD Manager directly from IDE.

  • Participants
  • Parent commits 6ce0123

Comments (0)

Files changed (6)

File core/manifest.mf

 OpenIDE-Module: org.netbeans.modules.android.core/2
 OpenIDE-Module-Layer: org/netbeans/modules/android/core/layer.xml
 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/android/core/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.12
+OpenIDE-Module-Specification-Version: 1.13
 OpenIDE-Module-Java-Dependencies: Java > 1.6
 AutoUpdate-Show-In-Client: false
 

File core/nbproject/genfiles.properties

-build.xml.data.CRC32=78d8bfc9
+build.xml.data.CRC32=4c349452
 build.xml.script.CRC32=a161fe02
 build.xml.stylesheet.CRC32=a56c6a5b@1.45.1
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=78d8bfc9
+nbproject/build-impl.xml.data.CRC32=4c349452
 nbproject/build-impl.xml.script.CRC32=9daee64d
 nbproject/build-impl.xml.stylesheet.CRC30=261c4bef@1.31.1.7
 nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.45.1

File core/nbproject/project.xml

                     </run-dependency>
                 </dependency>
                 <dependency>
+                    <code-name-base>org.netbeans.modules.extexecution</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>2</release-version>
+                        <specification-version>1.21.1</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
                     <code-name-base>org.netbeans.modules.options.api</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>

File core/src/org/netbeans/modules/android/core/layer.xml

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
 <filesystem>
+    <folder name="Actions">
+        <folder name="Tools">
+            <file name="org-netbeans-modules-android-core-ui-SdkManagerAction.instance">
+                <attr name="delegate" newvalue="org.netbeans.modules.android.core.ui.SdkManagerAction"/>
+                <attr name="displayName" bundlevalue="org.netbeans.modules.android.core.ui.Bundle#CTL_SdkManagerAction"/>
+                <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
+                <attr name="noIconInMenu" boolvalue="false"/>
+            </file>
+        </folder>
+    </folder>
+    <folder name="Menu">
+        <folder name="Tools">
+            <file name="org-netbeans-modules-android-core-ui-SdkManagerAction.shadow">
+                <attr name="originalFile" stringvalue="Actions/Tools/org-netbeans-modules-android-core-ui-SdkManagerAction.instance"/>
+                <attr name="position" intvalue="387"/>
+            </file>
+        </folder>
+    </folder>
     <folder name="OptionsDialog">
         <folder name="Advanced">
             <file name="org-netbeans-modules-android-core-ui-AndroidPlatformAdvancedOption.instance">

File core/src/org/netbeans/modules/android/core/ui/Bundle.properties

 AdvancedOption_DisplayName_AndroidPlatform=Android
 AdvancedOption_Keywords_AndroidPlatform=Android
+CTL_SdkManagerAction=Android SDK and AVD Manager
 # To change this template, choose Tools | Templates
 # and open the template in the editor.
 TXT_Devices=Android Devices

File core/src/org/netbeans/modules/android/core/ui/SdkManagerAction.java

+/*
+ *  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.
+ *  under the License.
+ */
+package org.netbeans.modules.android.core.ui;
+
+import com.android.sdklib.SdkConstants;
+import com.google.common.base.Strings;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+import org.netbeans.api.extexecution.ExternalProcessBuilder;
+import org.netbeans.api.options.OptionsDisplayer;
+import org.netbeans.modules.android.core.sdk.DalvikPlatformManager;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
+import org.openide.util.Exceptions;
+
+public final class SdkManagerAction implements ActionListener {
+
+  @Override
+  public void actionPerformed(ActionEvent e) {
+    String sdkLocation = DalvikPlatformManager.getDefault().getSdkLocation();
+    if (Strings.isNullOrEmpty(sdkLocation)) {
+      NotifyDescriptor notifyDescriptor = 
+          new NotifyDescriptor("Android SDK location has to be set before you can start SDK and AVD manager. "
+                + "Do you want to set it now?", 
+              "Android SDK and AVD Manager", 
+              NotifyDescriptor.OK_CANCEL_OPTION, 
+              NotifyDescriptor.QUESTION_MESSAGE, 
+              new Object[] {NotifyDescriptor.OK_OPTION, NotifyDescriptor.CANCEL_OPTION}, 
+              NotifyDescriptor.OK_OPTION);
+      if (DialogDisplayer.getDefault().notify(notifyDescriptor) == NotifyDescriptor.OK_OPTION) {
+        OptionsDisplayer.getDefault().open(
+            "Advanced/org-netbeans-modules-android-core-ui-AndroidPlatformAdvancedOption");
+      }
+    } else {
+      runSdkManager(sdkLocation);
+    }
+  }
+
+  private void runSdkManager(String sdkLocation) {
+    try {
+      Process process = new ExternalProcessBuilder(
+          sdkLocation + File.separatorChar + SdkConstants.OS_SDK_TOOLS_FOLDER + SdkConstants.androidCmdName())
+          .call();
+      // TODO do I need to read stderr/out?
+    } catch (IOException ex) {
+      Exceptions.printStackTrace(ex);
+    }
+  }
+}