156afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye/* 256afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * Copyright (C) 2012 The Android Open Source Project 356afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * 456afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 556afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * you may not use this file except in compliance with the License. 656afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * You may obtain a copy of the License at 756afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * 856afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * http://www.eclipse.org/org/documents/epl-v10.php 956afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * 1056afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * Unless required by applicable law or agreed to in writing, software 1156afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * distributed under the License is distributed on an "AS IS" BASIS, 1256afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1356afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * See the License for the specific language governing permissions and 1456afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye * limitations under the License. 1556afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye */ 1656afaff9c34a60c0e850324938d101a0509f8a38Tor Norbyepackage com.android.ide.eclipse.adt.internal.wizards.templates; 1756afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye 1856afaff9c34a60c0e850324938d101a0509f8a38Tor Norbyeimport org.eclipse.jface.wizard.WizardPage; 1956afaff9c34a60c0e850324938d101a0509f8a38Tor Norbyeimport org.eclipse.swt.SWT; 2056afaff9c34a60c0e850324938d101a0509f8a38Tor Norbyeimport org.eclipse.swt.events.SelectionEvent; 2156afaff9c34a60c0e850324938d101a0509f8a38Tor Norbyeimport org.eclipse.swt.events.SelectionListener; 2256afaff9c34a60c0e850324938d101a0509f8a38Tor Norbyeimport org.eclipse.swt.layout.GridData; 2356afaff9c34a60c0e850324938d101a0509f8a38Tor Norbyeimport org.eclipse.swt.layout.GridLayout; 2456afaff9c34a60c0e850324938d101a0509f8a38Tor Norbyeimport org.eclipse.swt.widgets.Button; 2556afaff9c34a60c0e850324938d101a0509f8a38Tor Norbyeimport org.eclipse.swt.widgets.Composite; 2656afaff9c34a60c0e850324938d101a0509f8a38Tor Norbyeimport org.eclipse.swt.widgets.Label; 2756afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye 2856afaff9c34a60c0e850324938d101a0509f8a38Tor Norbyeclass UpdateToolsPage extends WizardPage implements SelectionListener { 2956afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye private Button mInstallButton; 3056afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye UpdateToolsPage() { 3156afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye super("update"); 3256afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye setTitle("Update Tools"); 3356afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye validatePage(); 3456afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye } 3556afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye 3656afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye @Override 3756afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye public void createControl(Composite parent) { 3856afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye Composite container = new Composite(parent, SWT.NULL); 3956afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye setControl(container); 4056afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye container.setLayout(new GridLayout(1, false)); 4156afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye 4256afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye Label label = new Label(container, SWT.WRAP); 4356afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye GridData layoutData = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1); 4456afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye layoutData.widthHint = NewTemplatePage.WIZARD_PAGE_WIDTH - 50; 4556afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye label.setLayoutData(layoutData); 4656afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye label.setText( 4756afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye "Your tools installation appears to be out of date (or not yet installed).\n" + 4856afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye "\n" + 4956afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye "This wizard depends on templates distributed with the Android SDK Tools.\n" + 5056afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye "\n" + 5156afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye "Please update the tools first (via Window > Android SDK Manager, or by " + 5256afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye "using the \"android\" command in a terminal window). Note that on Windows " + 5356afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye "you may need to restart the IDE, since there are some known problems where " + 5456afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye "Windows locks the files held open by the running IDE, so the updater is " + 5556afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye "unable to delete them in order to upgrade them."); 5656afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye 5756afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye mInstallButton = new Button(container, SWT.NONE); 5856afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye mInstallButton.setText("Check Again"); 5956afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye mInstallButton.addSelectionListener(this); 6056afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye } 6156afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye 6256afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye @Override 6356afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye public boolean isPageComplete() { 6456afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye return isUpToDate(); 6556afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye } 6656afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye 6756afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye static boolean isUpToDate() { 686d1e4fdd6b2132b895aae80de3dba83c3960d43fTor Norbye return TemplateManager.getTemplateRootFolder() != null; 6956afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye } 7056afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye 7156afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye private void validatePage() { 7256afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye boolean ok = isUpToDate(); 7356afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye setPageComplete(ok); 7456afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye if (ok) { 7556afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye setErrorMessage(null); 7656afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye setMessage(null); 7756afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye } else { 7856afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye setErrorMessage("The tools need to be updated via the SDK Manager"); 7956afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye } 8056afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye } 8156afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye 8256afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye // ---- Implements SelectionListener ---- 8356afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye 8456afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye @Override 8556afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye public void widgetSelected(SelectionEvent e) { 8656afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye if (e.getSource() == mInstallButton) { 8756afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye validatePage(); 8856afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye } 8956afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye } 9056afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye 9156afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye @Override 9256afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye public void widgetDefaultSelected(SelectionEvent e) { 9356afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye } 9456afaff9c34a60c0e850324938d101a0509f8a38Tor Norbye} 95