• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
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 package com.android.ide.eclipse.adt.internal.wizards.templates;
17 
18 import org.eclipse.jface.wizard.WizardPage;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.events.SelectionListener;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Button;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Label;
27 
28 class UpdateToolsPage extends WizardPage implements SelectionListener {
29     private Button mInstallButton;
UpdateToolsPage()30     UpdateToolsPage() {
31         super("update");
32         setTitle("Update Tools");
33         validatePage();
34     }
35 
36     @Override
createControl(Composite parent)37     public void createControl(Composite parent) {
38         Composite container = new Composite(parent, SWT.NULL);
39         setControl(container);
40         container.setLayout(new GridLayout(1, false));
41 
42         Label label = new Label(container, SWT.WRAP);
43         GridData layoutData = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
44         layoutData.widthHint = NewTemplatePage.WIZARD_PAGE_WIDTH - 50;
45         label.setLayoutData(layoutData);
46         label.setText(
47                 "Your tools installation appears to be out of date (or not yet installed).\n" +
48                 "\n" +
49                 "This wizard depends on templates distributed with the Android SDK Tools.\n" +
50                 "\n" +
51                 "Please update the tools first (via Window > Android SDK Manager, or by " +
52                 "using the \"android\" command in a terminal window). Note that on Windows " +
53                 "you may need to restart the IDE, since there are some known problems where " +
54                 "Windows locks the files held open by the running IDE, so the updater is " +
55                 "unable to delete them in order to upgrade them.");
56 
57         mInstallButton = new Button(container, SWT.NONE);
58         mInstallButton.setText("Check Again");
59         mInstallButton.addSelectionListener(this);
60     }
61 
62     @Override
isPageComplete()63     public boolean isPageComplete() {
64         return isUpToDate();
65     }
66 
isUpToDate()67     static boolean isUpToDate() {
68         return TemplateManager.getTemplateRootFolder() != null;
69     }
70 
validatePage()71     private void validatePage() {
72         boolean ok = isUpToDate();
73         setPageComplete(ok);
74         if (ok) {
75             setErrorMessage(null);
76             setMessage(null);
77         } else {
78             setErrorMessage("The tools need to be updated via the SDK Manager");
79         }
80     }
81 
82     // ---- Implements SelectionListener ----
83 
84     @Override
widgetSelected(SelectionEvent e)85     public void widgetSelected(SelectionEvent e) {
86         if (e.getSource() == mInstallButton) {
87             validatePage();
88         }
89     }
90 
91     @Override
widgetDefaultSelected(SelectionEvent e)92     public void widgetDefaultSelected(SelectionEvent e) {
93     }
94 }
95