Home | History | Annotate | Download | only in repository
      1 /*
      2  * Copyright (C) 2011 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.UpdaterPage;
     21 import com.android.sdkuilib.internal.repository.sdkman2.AvdManagerWindowImpl1;
     22 
     23 import org.eclipse.swt.widgets.Composite;
     24 import org.eclipse.swt.widgets.Shell;
     25 
     26 /**
     27  * Opens an AVD Manager Window.
     28  *
     29  * This is the public entry point for using the window.
     30  */
     31 public class AvdManagerWindow {
     32 
     33     /** The actual window implementation to which this class delegates. */
     34     private AvdManagerWindowImpl1 mWindow;
     35 
     36     /**
     37      * Enum giving some indication of what is invoking this window.
     38      * The behavior and UI will change slightly depending on the context.
     39      * <p/>
     40      * Note: if you add Android support to your specific IDE, you might want
     41      * to specialize this context enum.
     42      */
     43     public enum AvdInvocationContext {
     44         /**
     45          * The AVD Manager is invoked from the stand-alone 'android' tool.
     46          * In this mode, we present an about box, a settings page.
     47          * For SdkMan2, we also have a menu bar and link to the SDK Manager 2.
     48          */
     49         STANDALONE,
     50 
     51         /**
     52          * The AVD Manager is invoked from the SDK Manager.
     53          * This is similar to the {@link #STANDALONE} mode except we don't need
     54          * to display a menu bar at all since we don't want a menu item linking
     55          * back to the SDK Manager and we don't need to redisplay the options
     56          * and about which are already on the root window.
     57          */
     58         SDK_MANAGER,
     59 
     60         /**
     61          * The AVD Manager is invoked from an IDE.
     62          * In this mode, we do not modify the menu bar.
     63          * There is no about box and no settings.
     64          */
     65         IDE,
     66     }
     67 
     68 
     69     /**
     70      * Creates a new window. Caller must call open(), which will block.
     71      *
     72      * @param parentShell Parent shell.
     73      * @param sdkLog Logger. Cannot be null.
     74      * @param osSdkRoot The OS path to the SDK root.
     75      * @param context The {@link AvdInvocationContext} to change the behavior depending on who's
     76      *  opening the SDK Manager.
     77      */
     78     public AvdManagerWindow(
     79             Shell parentShell,
     80             ISdkLog sdkLog,
     81             String osSdkRoot,
     82             AvdInvocationContext context) {
     83         mWindow = new AvdManagerWindowImpl1(
     84                 parentShell,
     85                 sdkLog,
     86                 osSdkRoot,
     87                 context);
     88     }
     89 
     90     /**
     91      * Registers an extra page for the updater window.
     92      * <p/>
     93      * Pages must derive from {@link Composite} and implement a constructor that takes
     94      * a single parent {@link Composite} argument.
     95      * <p/>
     96      * All pages must be registered before the call to {@link #open()}.
     97      *
     98      * @param pageClass The {@link Composite}-derived class that will implement the page.
     99      * @param purpose The purpose of this page, e.g. an about box, settings page or generic.
    100      */
    101     public void registerPage(Class<? extends UpdaterPage> pageClass,
    102             UpdaterPage.Purpose purpose) {
    103         mWindow.registerPage(pageClass, purpose);
    104     }
    105 
    106     /**
    107      * Opens the window.
    108      */
    109     public void open() {
    110         mWindow.open();
    111     }
    112 }
    113