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.repository; 18 19 import com.android.sdklib.ISdkLog; 20 import com.android.sdkuilib.internal.repository.ISdkUpdaterWindow; 21 import com.android.sdkuilib.internal.repository.UpdaterPage; 22 import com.android.sdkuilib.internal.repository.sdkman1.SdkUpdaterWindowImpl1; 23 import com.android.sdkuilib.internal.repository.sdkman2.SdkUpdaterWindowImpl2; 24 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Shell; 27 28 /** 29 * Opens an SDK Manager Window. 30 * 31 * This is the public entry point for using the window. 32 */ 33 public class SdkUpdaterWindow { 34 35 /** The actual window implementation to which this class delegates. */ 36 private ISdkUpdaterWindow mWindow; 37 38 /** 39 * Enum giving some indication of what is invoking this window. 40 * The behavior and UI will change slightly depending on the context. 41 * <p/> 42 * Note: if you add Android support to your specific IDE, you might want 43 * to specialize this context enum. 44 */ 45 public enum SdkInvocationContext { 46 /** 47 * The SDK Manager is invoked from the stand-alone 'android' tool. 48 * In this mode, we present an about box, a settings page. 49 * For SdkMan2, we also have a menu bar and link to the AVD manager. 50 */ 51 STANDALONE, 52 53 /** 54 * The SDK Manager is invoked from the standalone AVD Manager. 55 * This is similar to the standalone mode except that in this case we 56 * don't display a menu item linking to the AVD Manager. 57 */ 58 AVD_MANAGER, 59 60 /** 61 * The SDK Manager is invoked from an IDE. 62 * In this mode, we do not modify the menu bar. There is no about box 63 * and no settings (e.g. HTTP proxy settings are inherited from Eclipse.) 64 */ 65 IDE, 66 67 /** 68 * The SDK Manager is invoked from the AVD Selector. 69 * For SdkMan1, this means the AVD page will be displayed first. 70 * For SdkMan2, we won't be using this. 71 */ 72 AVD_SELECTOR 73 } 74 75 /** 76 * Creates a new window. Caller must call open(), which will block. 77 * 78 * @param parentShell Parent shell. 79 * @param sdkLog Logger. Cannot be null. 80 * @param osSdkRoot The OS path to the SDK root. 81 * @param context The {@link SdkInvocationContext} to change the behavior depending on who's 82 * opening the SDK Manager. 83 */ 84 public SdkUpdaterWindow( 85 Shell parentShell, 86 ISdkLog sdkLog, 87 String osSdkRoot, 88 SdkInvocationContext context) { 89 90 // The new PackagesPage is not activated by default, 91 // this offers a way to fallback on the old one 92 if (System.getenv("ANDROID_OLD_SDKMAN") == null) { //$NON-NLS-1$ 93 mWindow = new SdkUpdaterWindowImpl2(parentShell, sdkLog, osSdkRoot, context); 94 } else { 95 mWindow = new SdkUpdaterWindowImpl1(parentShell, sdkLog, osSdkRoot, context); 96 } 97 } 98 99 /** 100 * Registers an extra page for the updater window. 101 * <p/> 102 * Pages must derive from {@link Composite} and implement a constructor that takes 103 * a single parent {@link Composite} argument. 104 * <p/> 105 * All pages must be registered before the call to {@link #open()}. 106 * 107 * @param pageClass The {@link Composite}-derived class that will implement the page. 108 * @param purpose The purpose of this page, e.g. an about box, settings page or generic. 109 */ 110 public void registerPage(Class<? extends UpdaterPage> pageClass, 111 UpdaterPage.Purpose purpose) { 112 mWindow.registerPage(pageClass, purpose); 113 } 114 115 /** 116 * Indicate the initial page that should be selected when the window opens. 117 * <p/> 118 * This must be called before the call to {@link #open()}. 119 * If null or if the page class is not found, the first page will be selected. 120 */ 121 public void setInitialPage(Class<? extends Composite> pageClass) { 122 mWindow.setInitialPage(pageClass); 123 } 124 125 /** 126 * Sets whether the auto-update wizard will be shown when opening the window. 127 * <p/> 128 * This must be called before the call to {@link #open()}. 129 */ 130 public void setRequestAutoUpdate(boolean requestAutoUpdate) { 131 mWindow.setRequestAutoUpdate(requestAutoUpdate); 132 } 133 134 /** 135 * Adds a new listener to be notified when a change is made to the content of the SDK. 136 * This should be called before {@link #open()}. 137 */ 138 public void addListener(ISdkChangeListener listener) { 139 mWindow.addListener(listener); 140 } 141 142 /** 143 * Removes a new listener to be notified anymore when a change is made to the content of 144 * the SDK. 145 */ 146 public void removeListener(ISdkChangeListener listener) { 147 mWindow.removeListener(listener); 148 } 149 150 /** 151 * Opens the window. 152 */ 153 public void open() { 154 mWindow.open(); 155 } 156 } 157