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
17package com.android.sdkuilib.repository;
18
19import com.android.sdkuilib.internal.repository.ISdkUpdaterWindow;
20import com.android.sdkuilib.internal.repository.ui.SdkUpdaterWindowImpl2;
21import com.android.utils.ILogger;
22
23import org.eclipse.swt.widgets.Shell;
24
25/**
26 * Opens an SDK Manager Window.
27 *
28 * This is the public entry point for using the window.
29 */
30public class SdkUpdaterWindow {
31
32    /** The actual window implementation to which this class delegates. */
33    private ISdkUpdaterWindow mWindow;
34
35    /**
36     * Enum giving some indication of what is invoking this window.
37     * The behavior and UI will change slightly depending on the context.
38     * <p/>
39     * Note: if you add Android support to your specific IDE, you might want
40     * to specialize this context enum.
41     */
42    public enum SdkInvocationContext {
43        /**
44         * The SDK Manager is invoked from the stand-alone 'android' tool.
45         * In this mode, we present an about box, a settings page.
46         * For SdkMan2, we also have a menu bar and link to the AVD manager.
47         */
48        STANDALONE,
49
50        /**
51         * The SDK Manager is invoked from the standalone AVD Manager.
52         * This is similar to the standalone mode except that in this case we
53         * don't display a menu item linking to the AVD Manager.
54         */
55        AVD_MANAGER,
56
57        /**
58         * The SDK Manager is invoked from an IDE.
59         * In this mode, we do not modify the menu bar. There is no about box
60         * and no settings (e.g. HTTP proxy settings are inherited from Eclipse.)
61         */
62        IDE,
63
64        /**
65         * The SDK Manager is invoked from the AVD Selector.
66         * For SdkMan1, this means the AVD page will be displayed first.
67         * For SdkMan2, we won't be using this.
68         */
69        AVD_SELECTOR
70    }
71
72    /**
73     * Creates a new window. Caller must call open(), which will block.
74     *
75     * @param parentShell Parent shell.
76     * @param sdkLog Logger. Cannot be null.
77     * @param osSdkRoot The OS path to the SDK root.
78     * @param context The {@link SdkInvocationContext} to change the behavior depending on who's
79     *  opening the SDK Manager.
80     */
81    public SdkUpdaterWindow(
82            Shell parentShell,
83            ILogger sdkLog,
84            String osSdkRoot,
85            SdkInvocationContext context) {
86
87        mWindow = new SdkUpdaterWindowImpl2(parentShell, sdkLog, osSdkRoot, context);
88    }
89
90    /**
91     * Adds a new listener to be notified when a change is made to the content of the SDK.
92     * This should be called before {@link #open()}.
93     */
94    public void addListener(ISdkChangeListener listener) {
95        mWindow.addListener(listener);
96    }
97
98    /**
99     * Removes a new listener to be notified anymore when a change is made to the content of
100     * the SDK.
101     */
102    public void removeListener(ISdkChangeListener listener) {
103        mWindow.removeListener(listener);
104    }
105
106    /**
107     * Opens the window.
108     */
109    public void open() {
110        mWindow.open();
111    }
112}
113