Search in sources :

Example 1 with StudioWizardDialogBuilder

use of com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder in project android by JetBrains.

the class AndroidNewModuleAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    if (project != null) {
        // TODO: before submitting this code, change this to only use the new wizard
        if (Boolean.getBoolean("use.npw.modelwizard") && (e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
            ArrayList<ModuleGalleryEntry> moduleDescriptions = new ArrayList<>();
            for (ModuleDescriptionProvider provider : ModuleDescriptionProvider.EP_NAME.getExtensions()) {
                moduleDescriptions.addAll(provider.getDescriptions());
            }
            ChooseModuleTypeStep chooseModuleTypeStep = new ChooseModuleTypeStep(new NewModuleModel(project), moduleDescriptions);
            ModelWizard wizard = new ModelWizard.Builder().addStep(chooseModuleTypeStep).build();
            new StudioWizardDialogBuilder(wizard, message("android.wizard.module.new.module.title")).build().show();
        } else {
            NewModuleWizardDynamic dialog = new NewModuleWizardDynamic(project, null);
            dialog.init();
            dialog.show();
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) ChooseModuleTypeStep(com.android.tools.idea.npw.module.ChooseModuleTypeStep) ModuleDescriptionProvider(com.android.tools.idea.npw.module.ModuleDescriptionProvider) NewModuleModel(com.android.tools.idea.npw.module.NewModuleModel) ModuleGalleryEntry(com.android.tools.idea.npw.module.ModuleGalleryEntry) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) ArrayList(java.util.ArrayList) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard)

Example 2 with StudioWizardDialogBuilder

use of com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder in project android by JetBrains.

the class DeviceUiAction method showHardwareProfileWizard.

static void showHardwareProfileWizard(ConfigureDeviceModel model) {
    ModelWizard wizard = new ModelWizard.Builder().addStep(new ConfigureDeviceOptionsStep(model)).build();
    new StudioWizardDialogBuilder(wizard, "Hardware Profile Configuration").setProject(model.getProject()).build().show();
}
Also used : StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard)

Example 3 with StudioWizardDialogBuilder

use of com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder in project android by JetBrains.

the class TemplateManager method fillCategory.

private void fillCategory(NonEmptyActionGroup categoryGroup, final String category, ActionManager am) {
    Map<String, File> categoryRow = myCategoryTable.row(category);
    if (CATEGORY_ACTIVITY.equals(category)) {
        AnAction galleryAction = new AnAction() {

            @Override
            public void update(AnActionEvent e) {
                updateAction(e, "Gallery...", true);
            }

            @Override
            public void actionPerformed(AnActionEvent e) {
                // TODO: before submitting this code, change this to only use the new wizard
                if (Boolean.getBoolean("use.npw.modelwizard") && (e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
                    DataContext dataContext = e.getDataContext();
                    Module module = LangDataKeys.MODULE.getData(dataContext);
                    assert module != null;
                    VirtualFile targetFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
                    assert targetFile != null;
                    VirtualFile targetDirectory = targetFile;
                    if (!targetDirectory.isDirectory()) {
                        targetDirectory = targetFile.getParent();
                        assert targetDirectory != null;
                    }
                    AndroidFacet facet = AndroidFacet.getInstance(module);
                    assert facet != null && facet.getAndroidModel() != null;
                    List<TemplateHandle> templateList = getTemplateList(FormFactor.MOBILE);
                    List<AndroidSourceSet> sourceSets = AndroidSourceSet.getSourceSets(facet, targetDirectory);
                    assert (sourceSets.size() > 0);
                    String initialPackageSuggestion = AndroidPackageUtils.getPackageForPath(facet, sourceSets, targetDirectory);
                    Project project = facet.getModule().getProject();
                    // TODO: Missing logic to select the default template
                    RenderTemplateModel renderModel = new RenderTemplateModel(project, templateList.get(0), initialPackageSuggestion, sourceSets.get(0), AndroidBundle.message("android.wizard.activity.add"));
                    NewModuleModel moduleModel = new NewModuleModel(project);
                    ChooseActivityTypeStep chooseActivityTypeStep = new ChooseActivityTypeStep(moduleModel, renderModel, facet, templateList, targetDirectory);
                    ModelWizard wizard = new ModelWizard.Builder().addStep(chooseActivityTypeStep).build();
                    new StudioWizardDialogBuilder(wizard, "New Android Activity").build().show();
                } else {
                    DataContext dataContext = e.getDataContext();
                    final Module module = LangDataKeys.MODULE.getData(dataContext);
                    VirtualFile targetFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
                    NewAndroidActivityWizard wizard = new NewAndroidActivityWizard(module, targetFile, null);
                    wizard.init();
                    wizard.show();
                }
            }
        };
        categoryGroup.add(galleryAction);
        categoryGroup.addSeparator();
        setPresentation(category, galleryAction);
    }
    for (String templateName : categoryRow.keySet()) {
        if (EXCLUDED_TEMPLATES.contains(templateName)) {
            continue;
        }
        TemplateMetadata metadata = getTemplateMetadata(myCategoryTable.get(category, templateName));
        NewAndroidComponentAction templateAction = new NewAndroidComponentAction(category, templateName, metadata);
        String actionId = ACTION_ID_PREFIX + category + templateName;
        am.unregisterAction(actionId);
        am.registerAction(actionId, templateAction);
        categoryGroup.add(templateAction);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewAndroidActivityWizard(com.android.tools.idea.npw.NewAndroidActivityWizard) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) RenderTemplateModel(com.android.tools.idea.npw.template.RenderTemplateModel) NewAndroidComponentAction(com.android.tools.idea.actions.NewAndroidComponentAction) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) NewModuleModel(com.android.tools.idea.npw.module.NewModuleModel) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) TemplateHandle(com.android.tools.idea.npw.template.TemplateHandle) ChooseActivityTypeStep(com.android.tools.idea.npw.template.ChooseActivityTypeStep) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) AndroidSourceSet(com.android.tools.idea.npw.project.AndroidSourceSet) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard)

Example 4 with StudioWizardDialogBuilder

use of com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder in project android by JetBrains.

the class SdkQuickfixUtils method createDialog.

@VisibleForTesting
@Nullable
static ModelWizardDialog createDialog(@Nullable Project project, @Nullable Component parent, @Nullable Collection<String> requestedPaths, @Nullable Collection<UpdatablePackage> requestedPackages, @Nullable Collection<LocalPackage> requestedUninstalls, @Nullable AndroidSdkHandler sdkHandler, boolean backgroundable) {
    if (sdkHandler == null) {
        return null;
    }
    RepoManager mgr = sdkHandler.getSdkManager(REPO_LOGGER);
    if (mgr.getLocalPath() == null) {
        String title = "SDK Problem";
        String msg = "<html>" + "Your Android SDK is missing or out of date." + "<br>" + "You can configure your SDK via <b>Configure | Project Defaults | Project Structure | SDKs</b></html>";
        Messages.showErrorDialog(msg, title);
        return null;
    }
    List<String> unknownPaths = new ArrayList<>();
    List<UpdatablePackage> resolvedPackages;
    mgr.loadSynchronously(0, new StudioLoggerProgressIndicator(SdkQuickfixUtils.class), new StudioDownloader(), StudioSettingsController.getInstance());
    RepositoryPackages packages = mgr.getPackages();
    if (requestedPackages == null) {
        requestedPackages = new ArrayList<>();
    }
    requestedPackages.addAll(lookupPaths(requestedPaths, packages, unknownPaths));
    try {
        resolvedPackages = resolve(requestedPackages, packages);
    } catch (PackageResolutionException e) {
        Messages.showErrorDialog(e.getMessage(), "Error Resolving Packages");
        return null;
    }
    Set<LocalPackage> resolvedUninstalls = new HashSet<>();
    if (requestedUninstalls != null) {
        resolvedUninstalls.addAll(requestedUninstalls);
        // We don't want to uninstall something required by a package we're installing
        resolvedPackages.forEach(updatable -> resolvedUninstalls.remove(updatable.getLocal()));
    }
    List<UpdatablePackage> unavailableDownloads = Lists.newArrayList();
    verifyAvailability(resolvedPackages, unavailableDownloads);
    // If there were requests we didn't understand or can't download, show an error.
    if (!unknownPaths.isEmpty() || !unavailableDownloads.isEmpty()) {
        String title = "Packages Unavailable";
        HtmlBuilder builder = new HtmlBuilder();
        builder.openHtmlBody().add(String.format("%1$s packages are not available for download!", resolvedPackages.isEmpty() ? "All" : "Some")).newline().newline().add("The following packages are not available:").beginList();
        for (UpdatablePackage p : unavailableDownloads) {
            builder.listItem().add(p.getRepresentative().getDisplayName());
        }
        for (String p : unknownPaths) {
            builder.listItem().add("Package id " + p);
        }
        builder.endList().closeHtmlBody();
        Messages.showErrorDialog(builder.getHtml(), title);
    }
    // If everything was removed, don't continue.
    if (resolvedPackages.isEmpty() && resolvedUninstalls.isEmpty()) {
        return null;
    }
    List<RemotePackage> installRequests = resolvedPackages.stream().map(UpdatablePackage::getRemote).collect(Collectors.toList());
    ModelWizard.Builder wizardBuilder = new ModelWizard.Builder();
    wizardBuilder.addStep(new LicenseAgreementStep(new LicenseAgreementModel(mgr.getLocalPath()), installRequests));
    InstallSelectedPackagesStep installStep = new InstallSelectedPackagesStep(resolvedPackages, resolvedUninstalls, sdkHandler, backgroundable);
    wizardBuilder.addStep(installStep);
    ModelWizard wizard = wizardBuilder.build();
    String title = "SDK Quickfix Installation";
    return new StudioWizardDialogBuilder(wizard, title, parent).setProject(project).setModalityType(DialogWrapper.IdeModalityType.IDE).setCancellationPolicy(ModelWizardDialog.CancellationPolicy.CAN_CANCEL_UNTIL_CAN_FINISH).build();
}
Also used : HtmlBuilder(com.android.utils.HtmlBuilder) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard) HtmlBuilder(com.android.utils.HtmlBuilder) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) VisibleForTesting(com.android.annotations.VisibleForTesting) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with StudioWizardDialogBuilder

use of com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder in project android by JetBrains.

the class AndroidAssetStudioAction method actionPerformed.

@Override
public final void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
        return;
    }
    final Module module = LangDataKeys.MODULE.getData(dataContext);
    if (module == null) {
        return;
    }
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        return;
    }
    ModelWizard wizard = createWizard(facet);
    if (wizard != null) {
        StudioWizardDialogBuilder dialogBuilder = new StudioWizardDialogBuilder(wizard, "Asset Studio");
        dialogBuilder.setProject(facet.getModule().getProject()).setMinimumSize(getWizardSize()).setHelpUrl(getHelpUrl());
        dialogBuilder.build().show();
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) IdeView(com.intellij.ide.IdeView) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard)

Aggregations

StudioWizardDialogBuilder (com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder)8 ModelWizard (com.android.tools.idea.wizard.model.ModelWizard)8 Module (com.intellij.openapi.module.Module)3 Project (com.intellij.openapi.project.Project)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 NewModuleModel (com.android.tools.idea.npw.module.NewModuleModel)2 AndroidSourceSet (com.android.tools.idea.npw.project.AndroidSourceSet)2 RenderTemplateModel (com.android.tools.idea.npw.template.RenderTemplateModel)2 TemplateHandle (com.android.tools.idea.npw.template.TemplateHandle)2 IdeView (com.intellij.ide.IdeView)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)1 NewAndroidComponentAction (com.android.tools.idea.actions.NewAndroidComponentAction)1 NewAndroidActivityWizard (com.android.tools.idea.npw.NewAndroidActivityWizard)1 NewProjectWizardDynamic (com.android.tools.idea.npw.NewProjectWizardDynamic)1 ChooseModuleTypeStep (com.android.tools.idea.npw.module.ChooseModuleTypeStep)1 ModuleDescriptionProvider (com.android.tools.idea.npw.module.ModuleDescriptionProvider)1 ModuleGalleryEntry (com.android.tools.idea.npw.module.ModuleGalleryEntry)1