aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/UpdateToolsPage.java
blob: 5bbf449d4dcc122049ec1423503bae9f9f3f7a64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.eclipse.org/org/documents/epl-v10.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.ide.eclipse.adt.internal.wizards.templates;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

class UpdateToolsPage extends WizardPage implements SelectionListener {
    private Button mInstallButton;
    UpdateToolsPage() {
        super("update");
        setTitle("Update Tools");
        validatePage();
    }

    @Override
    public void createControl(Composite parent) {
        Composite container = new Composite(parent, SWT.NULL);
        setControl(container);
        container.setLayout(new GridLayout(1, false));

        Label label = new Label(container, SWT.WRAP);
        GridData layoutData = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
        layoutData.widthHint = NewTemplatePage.WIZARD_PAGE_WIDTH - 50;
        label.setLayoutData(layoutData);
        label.setText(
                "Your tools installation appears to be out of date (or not yet installed).\n" +
                "\n" +
                "This wizard depends on templates distributed with the Android SDK Tools.\n" +
                "\n" +
                "Please update the tools first (via Window > Android SDK Manager, or by " +
                "using the \"android\" command in a terminal window). Note that on Windows " +
                "you may need to restart the IDE, since there are some known problems where " +
                "Windows locks the files held open by the running IDE, so the updater is " +
                "unable to delete them in order to upgrade them.");

        mInstallButton = new Button(container, SWT.NONE);
        mInstallButton.setText("Check Again");
        mInstallButton.addSelectionListener(this);
    }

    @Override
    public boolean isPageComplete() {
        return isUpToDate();
    }

    static boolean isUpToDate() {
        return TemplateManager.getTemplateRootFolder() != null;
    }

    private void validatePage() {
        boolean ok = isUpToDate();
        setPageComplete(ok);
        if (ok) {
            setErrorMessage(null);
            setMessage(null);
        } else {
            setErrorMessage("The tools need to be updated via the SDK Manager");
        }
    }

    // ---- Implements SelectionListener ----

    @Override
    public void widgetSelected(SelectionEvent e) {
        if (e.getSource() == mInstallButton) {
            validatePage();
        }
    }

    @Override
    public void widgetDefaultSelected(SelectionEvent e) {
    }
}