Search in sources :

Example 1 with ThrottledProgressWrapper

use of com.android.tools.idea.sdk.progress.ThrottledProgressWrapper in project android by JetBrains.

the class InstallSelectedPackagesStep method startSdkInstall.

private void startSdkInstall() {
    CustomLogger customLogger = new CustomLogger();
    synchronized (LOGGER_LOCK) {
        myLogger = new ThrottledProgressWrapper(customLogger);
    }
    Function<List<RepoPackage>, Void> completeCallback = failures -> {
        UIUtil.invokeLaterIfNeeded(() -> {
            myProgressBar.setValue(100);
            myProgressOverallLabel.setText("");
            if (!failures.isEmpty()) {
                myInstallFailed.set(true);
                myProgressBar.setEnabled(false);
            } else {
                myProgressDetailLabel.setText("Done");
                checkForUpgrades(myInstallRequests);
            }
            myInstallationFinished.set(true);
        });
        return null;
    };
    InstallerFactory factory = StudioSdkInstallerUtil.createInstallerFactory(mySdkHandler);
    InstallTask task = new InstallTask(factory, mySdkHandler, StudioSettingsController.getInstance(), myLogger);
    task.setInstallRequests(myInstallRequests);
    task.setUninstallRequests(myUninstallRequests);
    task.setCompleteCallback(completeCallback);
    task.setPrepareCompleteCallback(() -> myBackgroundAction.setEnabled(false));
    ProgressIndicator indicator;
    boolean hasOpenProjects = ProjectManager.getInstance().getOpenProjects().length > 0;
    if (hasOpenProjects) {
        indicator = new BackgroundableProcessIndicator(task);
    } else {
        // If we don't have any open projects runProcessWithProgressAsynchronously will show a modal popup no matter what.
        // Instead use an empty progress indicator to suppress that.
        indicator = new EmptyProgressIndicator();
    }
    customLogger.setIndicator(indicator);
    myLogger.logInfo("To install:");
    for (UpdatablePackage p : myInstallRequests) {
        myLogger.logInfo(String.format("- %1$s (%2$s)", p.getRemote().getDisplayName(), p.getRemote().getPath()));
    }
    myLogger.logInfo("");
    ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, indicator);
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) StudioSdkInstallerUtil(com.android.tools.idea.sdk.install.StudioSdkInstallerUtil) FalseValidator(com.android.tools.idea.ui.validation.validators.FalseValidator) StudioWizardStepPanel(com.android.tools.idea.ui.wizard.StudioWizardStepPanel) com.android.repository.api(com.android.repository.api) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard) WizardConstants(com.android.tools.idea.wizard.WizardConstants) JBLabel(com.intellij.ui.components.JBLabel) Function(java.util.function.Function) ObservableBool(com.android.tools.idea.ui.properties.core.ObservableBool) Validator(com.android.tools.idea.ui.validation.Validator) ProjectManager(com.intellij.openapi.project.ProjectManager) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) BoolValueProperty(com.android.tools.idea.ui.properties.core.BoolValueProperty) Logger(com.intellij.openapi.diagnostic.Logger) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) ProgressManager(com.intellij.openapi.progress.ProgressManager) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) TrueValidator(com.android.tools.idea.ui.validation.validators.TrueValidator) Collection(java.util.Collection) ModelWizardStep(com.android.tools.idea.wizard.model.ModelWizardStep) ActionEvent(java.awt.event.ActionEvent) ValidatorPanel(com.android.tools.idea.ui.validation.ValidatorPanel) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) TypeDetails(com.android.repository.impl.meta.TypeDetails) ThrottledProgressWrapper(com.android.tools.idea.sdk.progress.ThrottledProgressWrapper) BoolProperty(com.android.tools.idea.ui.properties.core.BoolProperty) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ThrottledProgressWrapper(com.android.tools.idea.sdk.progress.ThrottledProgressWrapper) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) List(java.util.List)

Aggregations

com.android.repository.api (com.android.repository.api)1 TypeDetails (com.android.repository.impl.meta.TypeDetails)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)1 StudioSettingsController (com.android.tools.idea.sdk.StudioSettingsController)1 StudioSdkInstallerUtil (com.android.tools.idea.sdk.install.StudioSdkInstallerUtil)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1 ThrottledProgressWrapper (com.android.tools.idea.sdk.progress.ThrottledProgressWrapper)1 BoolProperty (com.android.tools.idea.ui.properties.core.BoolProperty)1 BoolValueProperty (com.android.tools.idea.ui.properties.core.BoolValueProperty)1 ObservableBool (com.android.tools.idea.ui.properties.core.ObservableBool)1 Validator (com.android.tools.idea.ui.validation.Validator)1 ValidatorPanel (com.android.tools.idea.ui.validation.ValidatorPanel)1 FalseValidator (com.android.tools.idea.ui.validation.validators.FalseValidator)1 TrueValidator (com.android.tools.idea.ui.validation.validators.TrueValidator)1 StudioWizardStepPanel (com.android.tools.idea.ui.wizard.StudioWizardStepPanel)1 WizardConstants (com.android.tools.idea.wizard.WizardConstants)1 ModelWizard (com.android.tools.idea.wizard.model.ModelWizard)1 ModelWizardStep (com.android.tools.idea.wizard.model.ModelWizardStep)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1