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.internal.repository; 18 19 import com.android.sdklib.ISdkLog; 20 21 import org.eclipse.swt.widgets.Composite; 22 23 import java.lang.reflect.Constructor; 24 25 26 27 /** 28 * Base class for pages shown in the updater. 29 */ 30 public abstract class UpdaterPage extends Composite { 31 32 public enum Purpose { 33 /** A generic page with is neither of the other specific purposes. */ 34 GENERIC, 35 /** A page that displays the about box for the SDK Manager. */ 36 ABOUT_BOX, 37 /** A page that displays the settings for the SDK Manager. */ 38 SETTINGS 39 } 40 41 public UpdaterPage(Composite parent, int swtStyle) { 42 super(parent, swtStyle); 43 } 44 45 /** 46 * The title of the page. Default is null. 47 * <p/> 48 * Useful for SdkManager1 when it displays a list of pages using 49 * a vertical page selector. 50 * Default implement for SdkManager2 is to return null. 51 */ 52 public String getPageTitle() { 53 return null; 54 } 55 56 public static UpdaterPage newInstance( 57 Class<? extends UpdaterPage> clazz, 58 Composite parent, 59 int swtStyle, 60 ISdkLog log) { 61 62 try { 63 Constructor<? extends UpdaterPage> cons = 64 clazz.getConstructor(new Class<?>[] { Composite.class, int.class }); 65 66 return cons.newInstance(new Object[] { parent, swtStyle }); 67 68 } catch (NoSuchMethodException e) { 69 // There is no such constructor. 70 log.error(e, 71 "Failed to instanciate page %1$s. Constructor args must be (Composite,int).", 72 clazz.getSimpleName()); 73 74 } catch (Exception e) { 75 // Log this instead of crashing the whole app. 76 log.error(e, 77 "Failed to instanciate page %1$s.", 78 clazz.getSimpleName()); 79 } 80 81 return null; 82 } 83 } 84