Home | History | Annotate | Download | only in repository
      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          * @param init whether this is called on the initial load of the SDK.
     42          */
     43         void onSdkChange(boolean init);
     44     }
     45 
     46     /**
     47      * Creates a new window. Caller must call open(), which will block.
     48      *
     49      * @param parentShell Parent shell.
     50      * @param sdkLog Logger. Cannot be null.
     51      * @param osSdkRoot The OS path to the SDK root.
     52      * @param userCanChangeSdkRoot If true, the window lets the user change the SDK path
     53      *                             being browsed.
     54      */
     55     public UpdaterWindow(Shell parentShell, ISdkLog sdkLog, String osSdkRoot,
     56             boolean userCanChangeSdkRoot) {
     57         mWindow = new UpdaterWindowImpl(parentShell, sdkLog, osSdkRoot, userCanChangeSdkRoot);
     58     }
     59 
     60     /**
     61      * Registers an extra page for the updater window.
     62      * <p/>
     63      * Pages must derive from {@link Composite} and implement a constructor that takes
     64      * a single parent {@link Composite} argument.
     65      * <p/>
     66      * All pages must be registered before the call to {@link #open()}.
     67      *
     68      * @param title The title of the page.
     69      * @param pageClass The {@link Composite}-derived class that will implement the page.
     70      */
     71     public void registerPage(String title, Class<? extends Composite> pageClass) {
     72         mWindow.registerExtraPage(title, pageClass);
     73     }
     74 
     75     /**
     76      * Indicate the initial page that should be selected when the window opens.
     77      * <p/>
     78      * This must be called before the call to {@link #open()}.
     79      * If null or if the page class is not found, the first page will be selected.
     80      */
     81     public void setInitialPage(Class<? extends Composite> pageClass) {
     82         mWindow.setInitialPage(pageClass);
     83     }
     84 
     85     /**
     86      * Sets whether the auto-update wizard will be shown when opening the window.
     87      * <p/>
     88      * This must be called before the call to {@link #open()}.
     89      */
     90     public void setRequestAutoUpdate(boolean requestAutoUpdate) {
     91         mWindow.setRequestAutoUpdate(requestAutoUpdate);
     92     }
     93 
     94     /**
     95      * Adds a new listener to be notified when a change is made to the content of the SDK.
     96      */
     97     public void addListeners(ISdkListener listener) {
     98         mWindow.addListeners(listener);
     99     }
    100 
    101     /**
    102      * Removes a new listener to be notified anymore when a change is made to the content of
    103      * the SDK.
    104      */
    105     public void removeListener(ISdkListener listener) {
    106         mWindow.removeListener(listener);
    107     }
    108 
    109     /**
    110      * Opens the window.
    111      */
    112     public void open() {
    113         mWindow.open();
    114     }
    115 }
    116