Search in sources :

Example 21 with ModelWizardDialog

use of com.android.tools.idea.wizard.model.ModelWizardDialog in project android by JetBrains.

the class EmulatorTargetChooser method chooseAvd.

@Nullable
private String chooseAvd() {
    IAndroidTarget buildTarget = myFacet.getConfiguration().getAndroidTarget();
    assert buildTarget != null;
    AvdInfo[] avds = myFacet.getValidCompatibleAvds();
    if (avds.length > 0) {
        return avds[0].getName();
    }
    final Project project = myFacet.getModule().getProject();
    AvdManager manager;
    try {
        manager = myFacet.getAvdManager(new AvdManagerLog() {

            @Override
            public void error(Throwable t, String errorFormat, Object... args) {
                super.error(t, errorFormat, args);
                if (errorFormat != null) {
                    final String msg = String.format(errorFormat, args);
                    LOG.error(msg);
                }
            }
        });
    } catch (final AndroidLocation.AndroidLocationException e) {
        LOG.info(e);
        UIUtil.invokeLaterIfNeeded(new Runnable() {

            @Override
            public void run() {
                Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle());
            }
        });
        return null;
    }
    final AvdManager finalManager = manager;
    assert finalManager != null;
    return UIUtil.invokeAndWaitIfNeeded(new Computable<String>() {

        @Override
        public String compute() {
            int result = Messages.showDialog(project, "To run using the emulator, you must have an AVD defined.", "Define AVD", new String[] { "Cancel", "Create AVD" }, 1, null);
            AvdInfo createdAvd = null;
            if (result == 1) {
                AvdOptionsModel avdOptionsModel = new AvdOptionsModel(null);
                ModelWizardDialog dialog = AvdWizardUtils.createAvdWizard(null, project, avdOptionsModel);
                if (dialog.showAndGet()) {
                    createdAvd = avdOptionsModel.getCreatedAvd();
                }
            }
            return createdAvd == null ? null : createdAvd.getName();
        }
    });
}
Also used : AvdManagerLog(org.jetbrains.android.sdk.AvdManagerLog) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) IAndroidTarget(com.android.sdklib.IAndroidTarget) AvdOptionsModel(com.android.tools.idea.avdmanager.AvdOptionsModel) Project(com.intellij.openapi.project.Project) AvdManager(com.android.sdklib.internal.avd.AvdManager) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) AndroidLocation(com.android.prefs.AndroidLocation) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with ModelWizardDialog

use of com.android.tools.idea.wizard.model.ModelWizardDialog in project android by JetBrains.

the class SdkUpdaterConfigurable method apply.

@Override
public void apply() throws ConfigurationException {
    myPanel.saveSources();
    HtmlBuilder message = new HtmlBuilder();
    message.openHtmlBody();
    final List<LocalPackage> toDelete = Lists.newArrayList();
    final Map<RemotePackage, UpdatablePackage> requestedPackages = Maps.newHashMap();
    for (PackageNodeModel model : myPanel.getStates()) {
        if (model.getState() == PackageNodeModel.SelectedState.NOT_INSTALLED) {
            if (model.getPkg().hasLocal()) {
                toDelete.add(model.getPkg().getLocal());
            }
        } else if (model.getState() == PackageNodeModel.SelectedState.INSTALLED && (model.getPkg().isUpdate() || !model.getPkg().hasLocal())) {
            UpdatablePackage pkg = model.getPkg();
            requestedPackages.put(pkg.getRemote(), pkg);
        }
    }
    boolean found = false;
    if (!toDelete.isEmpty()) {
        found = true;
        message.add("The following components will be deleted: \n");
        message.beginList();
        for (LocalPackage item : toDelete) {
            message.listItem().add(item.getDisplayName()).add(", Revision: ").add(item.getVersion().toString());
        }
        message.endList();
    }
    if (!requestedPackages.isEmpty()) {
        found = true;
        message.add("The following components will be installed: \n");
        message.beginList();
        Multimap<RemotePackage, RemotePackage> dependencies = HashMultimap.create();
        ProgressIndicator progress = new StudioLoggerProgressIndicator(getClass());
        RepositoryPackages packages = getRepoManager().getPackages();
        for (RemotePackage item : requestedPackages.keySet()) {
            List<RemotePackage> packageDependencies = InstallerUtil.computeRequiredPackages(ImmutableList.of(item), packages, progress);
            if (packageDependencies == null) {
                Messages.showErrorDialog((Project) null, "Unable to resolve dependencies for " + item.getDisplayName(), "Dependency Error");
                throw new ConfigurationException("Unable to resolve dependencies.");
            }
            for (RemotePackage dependency : packageDependencies) {
                dependencies.put(dependency, item);
            }
            message.listItem().add(String.format("%1$s %2$s %3$s", item.getDisplayName(), item.getTypeDetails() instanceof DetailsTypes.ApiDetailsType ? "revision" : "version", item.getVersion()));
        }
        for (RemotePackage dependency : dependencies.keySet()) {
            if (requestedPackages.containsKey(dependency)) {
                continue;
            }
            Set<RemotePackage> requests = Sets.newHashSet(dependencies.get(dependency));
            requests.remove(dependency);
            if (!requests.isEmpty()) {
                message.listItem().add(dependency.getDisplayName()).add(" (Required by ");
                Iterator<RemotePackage> requestIterator = requests.iterator();
                message.add(requestIterator.next().getDisplayName());
                while (requestIterator.hasNext()) {
                    message.add(", ").add(requestIterator.next().getDisplayName());
                }
                message.add(")");
            }
        }
        message.endList();
    }
    message.closeHtmlBody();
    if (found) {
        if (confirmChange(message)) {
            if (!requestedPackages.isEmpty() || !toDelete.isEmpty()) {
                ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPackages(myPanel.getComponent(), requestedPackages.values(), toDelete, true);
                if (dialog != null) {
                    dialog.show();
                    for (RemotePackage remotePackage : requestedPackages.keySet()) {
                        PackageOperation installer = getRepoManager().getInProgressInstallOperation(remotePackage);
                        if (installer != null) {
                            PackageOperation.StatusChangeListener listener = (installer1, progress) -> myPanel.getComponent().repaint();
                            myListeners.add(listener);
                            installer.registerStateChangeListener(listener);
                        }
                    }
                }
            }
            myPanel.refresh();
        } else {
            throw new ConfigurationException("Installation was canceled.");
        }
    } else {
        // We didn't have any changes, so just reload (maybe the channel changed).
        myChannelChangedCallback.run();
    }
}
Also used : Settings(com.intellij.openapi.options.ex.Settings) AllIcons(com.intellij.icons.AllIcons) DataContext(com.intellij.openapi.actionSystem.DataContext) com.android.repository.api(com.android.repository.api) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) Nls(org.jetbrains.annotations.Nls) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Map(java.util.Map) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Objects(com.google.common.base.Objects) com.google.common.collect(com.google.common.collect) DataManager(com.intellij.ide.DataManager) AncestorEvent(javax.swing.event.AncestorEvent) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) Iterator(java.util.Iterator) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioHelpManagerImpl(com.android.tools.idea.help.StudioHelpManagerImpl) HtmlBuilder(com.android.utils.HtmlBuilder) Set(java.util.Set) Configurable(com.intellij.openapi.options.Configurable) InstallerUtil(com.android.repository.util.InstallerUtil) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) AncestorListenerAdapter(com.intellij.ui.AncestorListenerAdapter) SdkQuickfixUtils(com.android.tools.idea.sdk.wizard.SdkQuickfixUtils) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) HtmlBuilder(com.android.utils.HtmlBuilder) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) ConfigurationException(com.intellij.openapi.options.ConfigurationException) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Example 23 with ModelWizardDialog

use of com.android.tools.idea.wizard.model.ModelWizardDialog in project android by JetBrains.

the class NewProjectWizardDemo method runWizard.

private void runWizard(ModelWizard wizard, String title) {
    ModelWizardDialog dialog = new ModelWizardDialog(wizard, title, myRootPanel, new DemoWizardLayout(), null, ModelWizardDialog.CancellationPolicy.ALWAYS_CAN_CANCEL);
    dialog.setSize(-1, 300);
    dialog.show();
}
Also used : ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Aggregations

ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)23 Project (com.intellij.openapi.project.Project)7 AndroidVersion (com.android.sdklib.AndroidVersion)4 File (java.io.File)4 NotNull (org.jetbrains.annotations.NotNull)4 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)3 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)3 StudioDownloader (com.android.tools.idea.sdk.StudioDownloader)3 StudioSettingsController (com.android.tools.idea.sdk.StudioSettingsController)3 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)3 ImmutableList (com.google.common.collect.ImmutableList)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Nullable (org.jetbrains.annotations.Nullable)3 AndroidLocation (com.android.prefs.AndroidLocation)2 RemotePackage (com.android.repository.api.RemotePackage)2 RepoManager (com.android.repository.api.RepoManager)2 DEFAULT_EXPIRATION_PERIOD_MS (com.android.repository.api.RepoManager.DEFAULT_EXPIRATION_PERIOD_MS)2 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)2 AndroidSdks (com.android.tools.idea.sdk.AndroidSdks)2 StudioProgressRunner (com.android.tools.idea.sdk.progress.StudioProgressRunner)2