diff options
10 files changed, 231 insertions, 120 deletions
diff --git a/android/src/com/android/tools/idea/welcome/config/FirstRunWizardMode.java b/android/src/com/android/tools/idea/welcome/config/FirstRunWizardMode.java index bf30fd5b86a..74f0a0211da 100644 --- a/android/src/com/android/tools/idea/welcome/config/FirstRunWizardMode.java +++ b/android/src/com/android/tools/idea/welcome/config/FirstRunWizardMode.java @@ -61,6 +61,9 @@ public enum FirstRunWizardMode { } public boolean shouldCreateAvd() { + if (this == MISSING_SDK) { + return false; + } return getInstallerData().shouldCreateAvd(); } diff --git a/android/src/com/android/tools/idea/welcome/wizard/ConsolidatedProgressStep.java b/android/src/com/android/tools/idea/welcome/wizard/ConsolidatedProgressStep.java new file mode 100644 index 00000000000..dc0c5801c98 --- /dev/null +++ b/android/src/com/android/tools/idea/welcome/wizard/ConsolidatedProgressStep.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.tools.idea.welcome.wizard; + +import com.android.tools.idea.welcome.install.WizardException; +import com.android.tools.idea.wizard.AndroidStudioWizardPath; +import com.android.tools.idea.wizard.DynamicWizardHost; +import com.intellij.execution.ui.ConsoleViewContentType; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.diagnostic.Logger; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * Step to show installation progress for long running operations contributed by other paths. + */ +public class ConsolidatedProgressStep extends ProgressStep { + private final AtomicBoolean myIsBusy = new AtomicBoolean(false); + private final DynamicWizardHost myHost; + private List<? extends AndroidStudioWizardPath> myPaths; + + public ConsolidatedProgressStep(@NotNull Disposable disposable, @NotNull DynamicWizardHost host) { + super(disposable); + myHost = host; + } + + public void setPaths(@NotNull List<? extends AndroidStudioWizardPath> paths) { + myPaths = paths; + } + + @Override + public boolean canGoNext() { + return super.canGoNext() && !myIsBusy.get(); + } + + @Override + protected void execute() { + myIsBusy.set(true); + myHost.runSensitiveOperation(getProgressIndicator(), true, new Runnable() { + @Override + public void run() { + try { + doLongRunningOperation(ConsolidatedProgressStep.this); + } + catch (WizardException e) { + Logger.getInstance(getClass()).error(e); + showConsole(); + print(e.getMessage() + "\n", ConsoleViewContentType.ERROR_OUTPUT); + } + finally { + myIsBusy.set(false); + } + } + }); + } + + private void doLongRunningOperation(@NotNull final ProgressStep progressStep) throws WizardException { + for (AndroidStudioWizardPath path : myPaths) { + if (progressStep.isCanceled()) { + break; + } + if (path instanceof LongRunningOperationPath) { + ((LongRunningOperationPath)path).runLongOperation(); + } + } + } + + @Override + public boolean canGoPrevious() { + return false; + } + + @Override + public boolean isStepVisible() { + return myPaths != null && !myPaths.isEmpty(); + } +} diff --git a/android/src/com/android/tools/idea/welcome/wizard/FirstRunWizard.java b/android/src/com/android/tools/idea/welcome/wizard/FirstRunWizard.java index a98da338447..26e45cb48b8 100644 --- a/android/src/com/android/tools/idea/welcome/wizard/FirstRunWizard.java +++ b/android/src/com/android/tools/idea/welcome/wizard/FirstRunWizard.java @@ -22,21 +22,14 @@ import com.android.tools.idea.sdk.wizard.LicenseAgreementStep; import com.android.tools.idea.welcome.config.AndroidFirstRunPersistentData; import com.android.tools.idea.welcome.config.FirstRunWizardMode; import com.android.tools.idea.welcome.install.FirstRunWizardDefaults; -import com.android.tools.idea.welcome.install.WizardException; -import com.android.tools.idea.wizard.AndroidStudioWizardPath; -import com.android.tools.idea.wizard.DynamicWizard; -import com.android.tools.idea.wizard.DynamicWizardHost; -import com.android.tools.idea.wizard.SingleStepPath; +import com.android.tools.idea.wizard.*; import com.android.utils.NullLogger; import com.google.common.collect.Multimap; -import com.intellij.execution.ui.ConsoleViewContentType; -import com.intellij.openapi.diagnostic.Logger; -import org.jetbrains.android.sdk.AndroidSdkUtils; +import com.intellij.openapi.util.SystemInfo; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; /** @@ -44,6 +37,9 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class FirstRunWizard extends DynamicWizard { public static final String WIZARD_TITLE = "Android Studio Setup Wizard"; + public static final ScopedStateStore.Key<Boolean> KEY_CUSTOM_INSTALL = + ScopedStateStore.createKey("custom.install", ScopedStateStore.Scope.WIZARD, Boolean.class); + @NotNull private final FirstRunWizardMode myMode; @Nullable private final Multimap<PkgType, RemotePkgInfo> myRemotePackages; /** @@ -66,7 +62,7 @@ public class FirstRunWizard extends DynamicWizard { @Override public void init() { File initialSdkLocation = FirstRunWizardDefaults.getInitialSdkLocation(myMode); - SetupProgressStep progressStep = new SetupProgressStep(); + ConsolidatedProgressStep progressStep = new FirstRunProgressStep(); myComponentsPath = new InstallComponentsPath(progressStep, myMode, initialSdkLocation, myRemotePackages); if (myMode == FirstRunWizardMode.NEW_INSTALL) { boolean sdkExists = initialSdkLocation.isDirectory() && @@ -74,7 +70,15 @@ public class FirstRunWizard extends DynamicWizard { addPath(new SingleStepPath(new FirstRunWelcomeStep(sdkExists))); } addPath(myJdkPath); + if (myMode == FirstRunWizardMode.NEW_INSTALL) { + addPath(new SingleStepPath(new InstallationTypeWizardStep(KEY_CUSTOM_INSTALL))); + } + addPath(new SingleStepPath(new SelectThemeStep(KEY_CUSTOM_INSTALL))); + addPath(myComponentsPath); + if (SystemInfo.isLinux && myMode != FirstRunWizardMode.INSTALL_HANDOFF) { + addPath(new SingleStepPath(new LinuxHaxmInfoStep())); + } if (myMode != FirstRunWizardMode.INSTALL_HANDOFF) { addPath(new SingleStepPath(new LicenseAgreementStep(getDisposable()))); } @@ -116,17 +120,6 @@ public class FirstRunWizard extends DynamicWizard { return "Finishing setup..."; } - private void doLongRunningOperation(@NotNull final ProgressStep progressStep) throws WizardException { - for (AndroidStudioWizardPath path : myPaths) { - if (progressStep.isCanceled()) { - break; - } - if (path instanceof LongRunningOperationPath) { - ((LongRunningOperationPath)path).runLongOperation(); - } - } - } - @Override public void performFinishingActions() { // Nothing @@ -137,42 +130,10 @@ public class FirstRunWizard extends DynamicWizard { return "Android Studio Setup Wizard"; } - public class SetupProgressStep extends ProgressStep { - private final AtomicBoolean myIsBusy = new AtomicBoolean(false); - - public SetupProgressStep() { - super(FirstRunWizard.this.getDisposable()); - } - - @Override - public boolean canGoNext() { - return super.canGoNext() && !myIsBusy.get(); - } - - @Override - protected void execute() { - myIsBusy.set(true); - myHost.runSensitiveOperation(getProgressIndicator(), true, new Runnable() { - @Override - public void run() { - try { - doLongRunningOperation(SetupProgressStep.this); - } - catch (WizardException e) { - Logger.getInstance(getClass()).error(e); - showConsole(); - print(e.getMessage() + "\n", ConsoleViewContentType.ERROR_OUTPUT); - } - finally { - myIsBusy.set(false); - } - } - }); - } - - @Override - public boolean canGoPrevious() { - return false; + public class FirstRunProgressStep extends ConsolidatedProgressStep { + public FirstRunProgressStep() { + super(getDisposable(), myHost); + setPaths(myPaths); } /** diff --git a/android/src/com/android/tools/idea/welcome/wizard/InstallComponentsPath.java b/android/src/com/android/tools/idea/welcome/wizard/InstallComponentsPath.java index f3bc761eeb9..bde20f423de 100644 --- a/android/src/com/android/tools/idea/welcome/wizard/InstallComponentsPath.java +++ b/android/src/com/android/tools/idea/welcome/wizard/InstallComponentsPath.java @@ -59,8 +59,6 @@ import java.util.*; * perform component setup. */ public class InstallComponentsPath extends DynamicWizardPath implements LongRunningOperationPath { - public static final ScopedStateStore.Key<Boolean> KEY_CUSTOM_INSTALL = - ScopedStateStore.createKey("custom.install", ScopedStateStore.Scope.PATH, Boolean.class); public static final AndroidVersion LATEST_ANDROID_VERSION = new AndroidVersion(22, null); private static final ScopedStateStore.Key<String> KEY_SDK_INSTALL_LOCATION = ScopedStateStore.createKey("download.sdk.location", ScopedStateStore.Scope.PATH, String.class); @@ -91,7 +89,7 @@ public class InstallComponentsPath extends DynamicWizardPath implements LongRunn components.add(platforms); } if (Haxm.canRun() && reason == FirstRunWizardMode.NEW_INSTALL) { - components.add(new Haxm(stateStore, KEY_CUSTOM_INSTALL)); + components.add(new Haxm(stateStore, FirstRunWizard.KEY_CUSTOM_INSTALL)); } if (createAvd) { components.add(new AndroidVirtualDevice(stateStore, myRemotePackages)); @@ -222,16 +220,12 @@ public class InstallComponentsPath extends DynamicWizardPath implements LongRunn @Override protected void init() { boolean createAvd = myMode.shouldCreateAvd(); - if (myMode == FirstRunWizardMode.NEW_INSTALL) { - addStep(new InstallationTypeWizardStep(KEY_CUSTOM_INSTALL)); - } - addStep(new SelectThemeStep(KEY_CUSTOM_INSTALL)); String pathString = mySdkLocation.getAbsolutePath(); myState.put(KEY_SDK_INSTALL_LOCATION, pathString); myComponentTree = createComponentTree(myMode, myState, createAvd); myComponentTree.init(myProgressStep); - mySdkComponentsStep = new SdkComponentsStep(myComponentTree, KEY_CUSTOM_INSTALL, KEY_SDK_INSTALL_LOCATION, myMode); + mySdkComponentsStep = new SdkComponentsStep(myComponentTree, FirstRunWizard.KEY_CUSTOM_INSTALL, KEY_SDK_INSTALL_LOCATION, myMode); addStep(mySdkComponentsStep); SdkManager manager = SdkManager.createManager(pathString, new NullLogger()); @@ -240,11 +234,8 @@ public class InstallComponentsPath extends DynamicWizardPath implements LongRunn for (DynamicWizardStep step : myComponentTree.createSteps()) { addStep(step); } - if (SystemInfo.isLinux && myMode != FirstRunWizardMode.INSTALL_HANDOFF) { - addStep(new LinuxHaxmInfoStep()); - } if (myMode != FirstRunWizardMode.INSTALL_HANDOFF) { - addStep(new InstallSummaryStep(KEY_CUSTOM_INSTALL, KEY_SDK_INSTALL_LOCATION, new Supplier<Collection<RemotePkgInfo>>() { + addStep(new InstallSummaryStep(FirstRunWizard.KEY_CUSTOM_INSTALL, KEY_SDK_INSTALL_LOCATION, new Supplier<Collection<RemotePkgInfo>>() { @Override public Collection<RemotePkgInfo> get() { return myComponentInstaller.getPackagesToInstallInfos(myState.get(KEY_SDK_INSTALL_LOCATION), myComponentTree.getChildrenToInstall()); @@ -265,7 +256,7 @@ public class InstallComponentsPath extends DynamicWizardPath implements LongRunn } myComponentTree.updateState(manager); } - if (modified.contains(KEY_CUSTOM_INSTALL) || modified.contains(KEY_SDK_INSTALL_LOCATION) || + if (modified.contains(FirstRunWizard.KEY_CUSTOM_INSTALL) || modified.contains(KEY_SDK_INSTALL_LOCATION) || myComponentTree.componentStateChanged(modified)) { myState.put(WizardConstants.INSTALL_REQUESTS_KEY, getPackageDescriptions()); } diff --git a/sdk-updates/src/META-INF/plugin.xml b/sdk-updates/src/META-INF/plugin.xml index 19d1529080e..0270be05ff6 100644 --- a/sdk-updates/src/META-INF/plugin.xml +++ b/sdk-updates/src/META-INF/plugin.xml @@ -46,6 +46,8 @@ <actions> <action id="Android.RunAndroidSdkManager" class="com.android.tools.idea.updater.configure.RunSdkConfigAction" icon="AndroidIcons.SdkManager" overrides="true"/> + <action id="WelcomeScreen.RunAndroidSdkManager" class="com.android.tools.idea.updater.configure.RunSdkConfigAction" + icon="AndroidIcons.SdkManagerLarge" overrides="true"/> </actions> </idea-plugin> diff --git a/sdk-updates/src/com/android/tools/idea/updater/configure/CheckboxClickListener.java b/sdk-updates/src/com/android/tools/idea/updater/configure/CheckboxClickListener.java index b4a44f3484f..265e7d525c9 100644 --- a/sdk-updates/src/com/android/tools/idea/updater/configure/CheckboxClickListener.java +++ b/sdk-updates/src/com/android/tools/idea/updater/configure/CheckboxClickListener.java @@ -20,6 +20,7 @@ import com.intellij.ui.dualView.TreeTableView; import com.intellij.ui.treeStructure.treetable.TreeTableTree; import org.jetbrains.annotations.NotNull; +import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; @@ -38,6 +39,10 @@ class CheckboxClickListener extends ClickListener { @Override public boolean onClick(@NotNull MouseEvent e, int clickCount) { + Object source = e.getSource(); + if (source instanceof JComponent && !((JComponent)source).isEnabled()) { + return false; + } TreeTableTree tree = myTreeTable.getTree(); int row = tree.getRowForLocation(e.getX(), e.getY()); if (row < 0) { diff --git a/sdk-updates/src/com/android/tools/idea/updater/configure/PlatformComponentsPanel.java b/sdk-updates/src/com/android/tools/idea/updater/configure/PlatformComponentsPanel.java index c394ef7acc0..2b5a18666f3 100644 --- a/sdk-updates/src/com/android/tools/idea/updater/configure/PlatformComponentsPanel.java +++ b/sdk-updates/src/com/android/tools/idea/updater/configure/PlatformComponentsPanel.java @@ -186,4 +186,10 @@ public class PlatformComponentsPanel { public void setIncludePreview(boolean includePreview) { myIncludePreview = includePreview; } + + public void setEnabled(boolean enabled) { + myPlatformDetailTable.setEnabled(enabled); + myPlatformSummaryTable.setEnabled(enabled); + myPlatformDetailsCheckbox.setEnabled(enabled); + } }
\ No newline at end of file diff --git a/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigPanel.form b/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigPanel.form index 1677973ad77..a62867ed49d 100644 --- a/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigPanel.form +++ b/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigPanel.form @@ -16,26 +16,28 @@ <text value="Manager for the Android SDK and Tools used by Android Studio"/> </properties> </component> - <grid id="7bcd0" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="7bcd0" binding="mySdkLocationPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> - <grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + <grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false"/> </constraints> <properties/> <border type="none"/> <children> <component id="38898" class="javax.swing.JTextField" binding="mySdkLocation"> <constraints> - <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"> + <minimum-size width="400" height="-1"/> + </grid> </constraints> <properties/> </component> - <component id="c575b" class="com.intellij.ui.components.JBLabel"> + <component id="c575b" class="com.intellij.ui.components.JBLabel" binding="mySdkLocationLabel"> <constraints> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/> </constraints> <properties> - <enabled value="false"/> + <enabled value="true"/> <text value="Android SDK Location:"/> </properties> </component> @@ -45,14 +47,18 @@ </constraints> <properties/> </component> - <hspacer id="3b2ca"> + <component id="898d3" class="com.intellij.ui.components.JBLabel" binding="mySdkErrorLabel"> <constraints> - <grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> + <grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> </constraints> - </hspacer> + <properties> + <text value="SDK Location must be set"/> + <visible value="false"/> + </properties> + </component> </children> </grid> - <tabbedpane id="46ef2" class="com.intellij.ui.components.JBTabbedPane" default-binding="true"> + <tabbedpane id="46ef2" class="com.intellij.ui.components.JBTabbedPane" binding="myTabPane"> <constraints> <grid row="2" column="0" row-span="1" col-span="2" vsize-policy="7" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"> <preferred-size width="200" height="200"/> diff --git a/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigPanel.java b/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigPanel.java index 703fec714d3..6dcc72bbad3 100644 --- a/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigPanel.java +++ b/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigPanel.java @@ -23,20 +23,30 @@ import com.android.tools.idea.sdk.remote.RemoteSdk; import com.android.tools.idea.sdk.remote.UpdatablePkgInfo; import com.android.tools.idea.sdk.remote.internal.sources.SdkSources; import com.android.tools.idea.stats.UsageTracker; +import com.android.tools.idea.welcome.config.FirstRunWizardMode; +import com.android.tools.idea.welcome.install.FirstRunWizardDefaults; +import com.android.tools.idea.welcome.wizard.InstallComponentsPath; +import com.android.tools.idea.welcome.wizard.ConsolidatedProgressStep; +import com.android.tools.idea.wizard.DialogWrapperHost; +import com.android.tools.idea.wizard.DynamicWizard; +import com.android.tools.idea.wizard.DynamicWizardHost; +import com.android.tools.idea.wizard.SingleStepPath; import com.android.utils.ILogger; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import com.google.common.collect.TreeMultimap; +import com.intellij.icons.AllIcons; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.options.ShowSettingsUtil; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.ui.InputValidator; -import com.intellij.openapi.ui.Messages; import com.intellij.openapi.updateSettings.impl.UpdateSettingsConfigurable; -import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.HyperlinkAdapter; import com.intellij.ui.HyperlinkLabel; +import com.intellij.ui.JBColor; +import com.intellij.ui.components.JBLabel; +import com.intellij.ui.components.JBTabbedPane; import com.intellij.ui.dualView.TreeTableView; import com.intellij.ui.table.SelectionProvider; import com.intellij.util.ui.tree.TreeUtil; @@ -71,6 +81,10 @@ public class SdkUpdaterConfigPanel { private HyperlinkLabel myLaunchStandaloneLink; private HyperlinkLabel myChannelLink; private HyperlinkLabel myEditSdkLink; + private JBTabbedPane myTabPane; + private JPanel mySdkLocationPanel; + private JBLabel mySdkLocationLabel; + private JBLabel mySdkErrorLabel; private SdkSources mySdkSources; private Runnable mySourcesChangeListener = new DispatchRunnable() { @Override @@ -123,22 +137,61 @@ public class SdkUpdaterConfigPanel { myEditSdkLink.addHyperlinkListener(new HyperlinkAdapter() { @Override protected void hyperlinkActivated(HyperlinkEvent e) { - String newLocation = Messages - .showInputDialog(getComponent(), "New SDK Location:", "Set SDK Location", null, mySdkLocation.getText(), new InputValidator() { - @Override - public boolean checkInput(String inputString) { - return IdeSdks.isValidAndroidSdkPath(new File(inputString)); + final DynamicWizardHost host = new DialogWrapperHost(null); + DynamicWizard wizard = new DynamicWizard(null, null, "SDK Setup", host) { + @Override + public void init() { + ConsolidatedProgressStep progressStep = new ConsolidatedProgressStep(myHost.getDisposable(), host); + String sdkPath = mySdkLocation.getText(); + File location; + if (StringUtil.isEmpty(sdkPath)) { + location = FirstRunWizardDefaults.getInitialSdkLocation(FirstRunWizardMode.MISSING_SDK); } + else { + location = new File(sdkPath); + } + InstallComponentsPath path = + new InstallComponentsPath(progressStep, FirstRunWizardMode.MISSING_SDK, location, + mySdkState.getPackages().getRemotePkgInfos()); + progressStep.setPaths(Lists.newArrayList(path)); + addPath(path); + addPath(new SingleStepPath(progressStep)); + super.init(); + } - @Override - public boolean canClose(String inputString) { - return checkInput(inputString); + @Override + public void performFinishingActions() { + final File newPath = IdeSdks.getAndroidSdkPath(); + if (newPath != null) { + mySdkState = SdkState.getInstance(AndroidSdkData.getSdkData(newPath)); + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + mySdkLocation.setText(newPath.getAbsolutePath()); + refresh(); + } + }); } - }); - setSdkPath(newLocation); + } + + @NotNull + @Override + protected String getProgressTitle() { + return "Setting up SDK..."; + } + + @Override + protected String getWizardActionDescription() { + return "Setting up SDK..."; + } + }; + wizard.init(); + wizard.show(); } }); mySdkLocation.setEditable(false); + mySdkErrorLabel.setIcon(AllIcons.General.BalloonError); + mySdkErrorLabel.setForeground(JBColor.RED); } public void setIncludePreview(boolean includePreview) { @@ -227,6 +280,8 @@ public class SdkUpdaterConfigPanel { } public void refresh() { + validate(); + myPlatformComponentsPanel.startLoading(); myToolComponentsPanel.startLoading(); myUpdateSitesPanel.startLoading(); @@ -243,6 +298,19 @@ public class SdkUpdaterConfigPanel { mySdkState.loadAsync(SdkState.DEFAULT_EXPIRATION_PERIOD_MS, false, myUpdater, remoteComplete, null, true); } + private void validate() { + AndroidSdkData data = mySdkState.getSdkData(); + File sdkLocation = null; + if (data != null) { + sdkLocation = data.getLocation(); + } + boolean valid = sdkLocation != null; + myTabPane.setEnabled(valid); + myPlatformComponentsPanel.setEnabled(valid); + mySdkLocationLabel.setForeground(valid ? JBColor.foreground() : JBColor.RED); + mySdkErrorLabel.setVisible(!valid); + } + private void loadPackages(SdkPackages packages) { Multimap<AndroidVersion, UpdatablePkgInfo> platformPackages = TreeMultimap.create(); Set<UpdatablePkgInfo> buildToolsPackages = Sets.newTreeSet(); @@ -291,7 +359,10 @@ public class SdkUpdaterConfigPanel { public void reset() { refresh(); - mySdkLocation.setText(IdeSdks.getAndroidSdkPath().getPath()); + File path = IdeSdks.getAndroidSdkPath(); + if (path != null) { + mySdkLocation.setText(path.getPath()); + } myPlatformComponentsPanel.reset(); myToolComponentsPanel.reset(); myUpdateSitesPanel.reset(); @@ -305,27 +376,6 @@ public class SdkUpdaterConfigPanel { myUpdateSitesPanel.save(); } - private void setSdkPath(String newLocation) { - final File currentPath = IdeSdks.getAndroidSdkPath(); - assert currentPath != null; // shouldn't be able to get to this point without sdk set. - final File newPath = new File(newLocation); - assert IdeSdks.isValidAndroidSdkPath(newPath); - - if (FileUtil.filesEqual(currentPath, newPath)) { - return; - } - - List<Sdk> sdks = IdeSdks.setAndroidSdkPath(newPath, null); - if (sdks.isEmpty()) { - Messages.showErrorDialog(getComponent(), "Failed to set SDK path"); - } - else { - mySdkState = SdkState.getInstance(AndroidSdkData.getSdkData(newPath)); - mySdkLocation.setText(newPath.getAbsolutePath()); - refresh(); - } - } - private static class CycleAction extends AbstractAction { boolean myBackward; diff --git a/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigurable.java b/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigurable.java index 3ab21b26e15..4ec026e8fa8 100644 --- a/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigurable.java +++ b/sdk-updates/src/com/android/tools/idea/updater/configure/SdkUpdaterConfigurable.java @@ -78,11 +78,6 @@ public class SdkUpdaterConfigurable implements SearchableConfigurable { @Override public JComponent createComponent() { AndroidSdkData data = AndroidSdkUtils.tryToChooseAndroidSdk(); - if (data == null) { - JPanel errorPanel = new JPanel(); - errorPanel.add(new JBLabel("Failed to find android sdk")); - return errorPanel; - } final Runnable channelChangedCallback = new Runnable() { @Override public void run() { |