• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.UpdaterWindowImpl;
21 
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Shell;
24 
25 /**
26  * Opens an SDK Updater Window.
27  *
28  * This is the public interface for using the window.
29  */
30 public class UpdaterWindow {
31 
32     private UpdaterWindowImpl mWindow;
33 
34     /**
35      * Interface for listeners on SDK modifications (ie new installed compoments, or deleted
36      * components)
37      */
38     public interface ISdkListener {
39         /**
40          * Sent when the content of the SDK changed
41          */
onSdkChange()42         void onSdkChange();
43     }
44 
45     /**
46      * Creates a new window. Caller must call open(), which will block.
47      * @param sdkLog
48      * @param osSdkRoot The OS path to the SDK root.
49      * @param userCanChangeSdkRoot If true, the window lets the user change the SDK path
50      *                             being browsed.
51      */
UpdaterWindow(Shell parentShell, ISdkLog sdkLog, String osSdkRoot, boolean userCanChangeSdkRoot)52     public UpdaterWindow(Shell parentShell, ISdkLog sdkLog, String osSdkRoot,
53             boolean userCanChangeSdkRoot) {
54         mWindow = new UpdaterWindowImpl(parentShell, sdkLog, osSdkRoot, userCanChangeSdkRoot);
55     }
56 
57     /**
58      * Registers an extra page for the updater window.
59      * <p/>
60      * Pages must derive from {@link Composite} and implement a constructor that takes
61      * a single parent {@link Composite} argument.
62      * <p/>
63      * All pages must be registered before the call to {@link #open()}.
64      *
65      * @param title The title of the page.
66      * @param pageClass The {@link Composite}-derived class that will implement the page.
67      */
registerPage(String title, Class<? extends Composite> pageClass)68     public void registerPage(String title, Class<? extends Composite> pageClass) {
69         mWindow.registerExtraPage(title, pageClass);
70     }
71 
72     /**
73      * Indicate the initial page that should be selected when the window opens.
74      * <p/>
75      * This must be called before the call to {@link #open()}.
76      * If null or if the page class is not found, the first page will be selected.
77      */
setInitialPage(Class<? extends Composite> pageClass)78     public void setInitialPage(Class<? extends Composite> pageClass) {
79         mWindow.setInitialPage(pageClass);
80     }
81 
82     /**
83      * Sets whether the auto-update wizard will be shown when opening the window.
84      * <p/>
85      * This must be called before the call to {@link #open()}.
86      */
setRequestAutoUpdate(boolean requestAutoUpdate)87     public void setRequestAutoUpdate(boolean requestAutoUpdate) {
88         mWindow.setRequestAutoUpdate(requestAutoUpdate);
89     }
90 
91     /**
92      * Adds a new listener to be notified when a change is made to the content of the SDK.
93      */
addListeners(ISdkListener listener)94     public void addListeners(ISdkListener listener) {
95         mWindow.addListeners(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      */
removeListener(ISdkListener listener)102     public void removeListener(ISdkListener listener) {
103         mWindow.removeListener(listener);
104     }
105 
106     /**
107      * Opens the window.
108      */
open()109     public void open() {
110         mWindow.open();
111     }
112 }
113