1 /* 2 * Copyright (C) 2009 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.sdkuilib.internal.repository.sdkman1; 18 19 import com.android.prefs.AndroidLocation.AndroidLocationException; 20 import com.android.sdkuilib.internal.repository.UpdaterData; 21 import com.android.sdkuilib.internal.repository.UpdaterPage; 22 import com.android.sdkuilib.internal.widgets.AvdSelector; 23 import com.android.sdkuilib.internal.widgets.AvdSelector.DisplayMode; 24 import com.android.sdkuilib.repository.ISdkChangeListener; 25 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.layout.GridLayout; 29 import org.eclipse.swt.widgets.Composite; 30 import org.eclipse.swt.widgets.Label; 31 32 public class AvdManagerPage extends UpdaterPage implements ISdkChangeListener { 33 34 private AvdSelector mAvdSelector; 35 36 private final UpdaterData mUpdaterData; 37 38 /** 39 * Create the composite. 40 * @param parent The parent of the composite. 41 * @param updaterData An instance of {@link UpdaterData}. 42 */ 43 public AvdManagerPage(Composite parent, int swtStyle, UpdaterData updaterData) { 44 super(parent, swtStyle); 45 46 mUpdaterData = updaterData; 47 mUpdaterData.addListeners(this); 48 49 createContents(this); 50 postCreate(); //$hide$ 51 } 52 53 private void createContents(Composite parent) { 54 parent.setLayout(new GridLayout(1, false)); 55 56 Label label = new Label(parent, SWT.NONE); 57 label.setLayoutData(new GridData()); 58 59 try { 60 if (mUpdaterData != null && mUpdaterData.getAvdManager() != null) { 61 label.setText(String.format( 62 "List of existing Android Virtual Devices located at %s", 63 mUpdaterData.getAvdManager().getBaseAvdFolder())); 64 } else { 65 label.setText("Error: cannot find the AVD folder location.\r\n Please set the 'ANDROID_SDK_HOME' env variable."); 66 } 67 } catch (AndroidLocationException e) { 68 label.setText(e.getMessage()); 69 } 70 71 mAvdSelector = new AvdSelector(parent, 72 mUpdaterData.getOsSdkRoot(), 73 mUpdaterData.getAvdManager(), 74 DisplayMode.MANAGER, 75 mUpdaterData.getSdkLog()); 76 mAvdSelector.setSettingsController(mUpdaterData.getSettingsController()); 77 } 78 79 @Override 80 public void dispose() { 81 mUpdaterData.removeListener(this); 82 super.dispose(); 83 } 84 85 @Override 86 protected void checkSubclass() { 87 // Disable the check that prevents subclassing of SWT components 88 } 89 90 // -- Start of internal part ---------- 91 // Hide everything down-below from SWT designer 92 //$hide>>$ 93 94 /** 95 * Called by the constructor right after {@link #createContents(Composite)}. 96 */ 97 private void postCreate() { 98 // nothing to be done for now. 99 } 100 101 // --- Implementation of ISdkChangeListener --- 102 103 public void onSdkLoaded() { 104 onSdkReload(); 105 } 106 107 public void onSdkReload() { 108 mAvdSelector.refresh(false /*reload*/); 109 } 110 111 public void preInstallHook() { 112 // nothing to be done for now. 113 } 114 115 public void postInstallHook() { 116 // nothing to be done for now. 117 } 118 119 // End of hiding from SWT Designer 120 //$hide<<$ 121 } 122