Search in sources :

Example 16 with ModelWizardDialog

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

the class NewAndroidComponentAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
        return;
    }
    Module module = LangDataKeys.MODULE.getData(dataContext);
    if (module == null) {
        return;
    }
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null || facet.getAndroidModel() == null) {
        return;
    }
    VirtualFile targetFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
    File file = TemplateManager.getInstance().getTemplateFile(myTemplateCategory, myTemplateName);
    assert targetFile != null;
    VirtualFile targetDirectory = targetFile;
    if (!targetDirectory.isDirectory()) {
        targetDirectory = targetFile.getParent();
        assert targetDirectory != null;
    }
    assert file != null;
    // e.g. "Empty Activity", "Tabbed Activity"
    String activityDescription = e.getPresentation().getText();
    List<AndroidSourceSet> sourceSets = AndroidSourceSet.getSourceSets(facet, targetDirectory);
    assert sourceSets.size() > 0;
    String initialPackageSuggestion = AndroidPackageUtils.getPackageForPath(facet, sourceSets, targetDirectory);
    Project project = module.getProject();
    RenderTemplateModel templateModel = new RenderTemplateModel(project, new TemplateHandle(file), initialPackageSuggestion, sourceSets.get(0), "New " + activityDescription);
    boolean isActivity = isActivityTemplate();
    String dialogTitle = AndroidBundle.message(isActivity ? "android.wizard.new.activity.title" : "android.wizard.new.component.title");
    String stepTitle = AndroidBundle.message(isActivity ? "android.wizard.config.activity.title" : "android.wizard.config.component.title");
    ModelWizard.Builder wizardBuilder = new ModelWizard.Builder();
    wizardBuilder.addStep(new ConfigureTemplateParametersStep(templateModel, stepTitle, sourceSets, facet));
    ModelWizardDialog dialog = new StudioWizardDialogBuilder(wizardBuilder.build(), dialogTitle).setProject(project).build();
    dialog.show();
/*
    // TODO: Implement the getCreatedElements call for the wizard
    final PsiElement[] createdElements = dialog.getCreatedElements();

    for (PsiElement createdElement : createdElements) {
      view.selectElement(createdElement);
    }
    */
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) RenderTemplateModel(com.android.tools.idea.npw.template.RenderTemplateModel) IdeView(com.intellij.ide.IdeView) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) TemplateHandle(com.android.tools.idea.npw.template.TemplateHandle) ConfigureTemplateParametersStep(com.android.tools.idea.npw.template.ConfigureTemplateParametersStep) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) AndroidSourceSet(com.android.tools.idea.npw.project.AndroidSourceSet) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard)

Example 17 with ModelWizardDialog

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

the class InstallPlatformHyperlink method execute.

@Override
protected void execute(@NotNull Project project) {
    List<String> requested = Lists.newArrayList();
    for (AndroidVersion version : myAndroidVersions) {
        requested.add(DetailsTypes.getPlatformPath(version));
    }
    ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(project, requested);
    if (dialog != null && dialog.showAndGet()) {
        GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
    }
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Example 18 with ModelWizardDialog

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

the class AttachAndroidSdkSourcesNotificationProvider method createNotificationPanel.

@Override
@Nullable
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
    if (file.getFileType() != JavaClassFileType.INSTANCE) {
        return null;
    }
    // Locate the java source of the class file, if not found, then it might come from a SDK.
    if (JavaEditorFileSwapper.findSourceFile(myProject, file) == null) {
        JdkOrderEntry jdkOrderEntry = findAndroidSdkEntryForFile(file);
        if (jdkOrderEntry == null) {
            return null;
        }
        Sdk sdk = jdkOrderEntry.getJdk();
        String sdkHome = sdk.getHomePath();
        if (sdkHome == null) {
            return null;
        }
        if (sdk.getRootProvider().getFiles(OrderRootType.SOURCES).length > 0) {
            return null;
        }
        AndroidPlatform platform = AndroidPlatform.getInstance(sdk);
        if (platform == null) {
            return null;
        }
        EditorNotificationPanel panel = new EditorNotificationPanel();
        panel.setText("Sources for '" + jdkOrderEntry.getJdkName() + "' not found.");
        panel.createActionLabel("Download", () -> {
            List<String> requested = Lists.newArrayList();
            requested.add(DetailsTypes.getSourcesPath(platform.getApiVersion()));
            ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(myProject, requested);
            if (dialog != null && dialog.showAndGet()) {
                updateSdkSourceRoot(sdk);
            }
        });
        panel.createActionLabel("Refresh (if already downloaded)", () -> updateSdkSourceRoot(sdk));
        return panel;
    }
    return null;
}
Also used : EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Sdk(com.intellij.openapi.projectRoots.Sdk) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with ModelWizardDialog

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

the class InstallArtifactHyperlink method execute.

@Override
protected void execute(@NotNull Project project) {
    List<String> requested = new ArrayList<>();
    requested.add(myPath);
    ModelWizardDialog dialog = createDialogForPaths(project, requested);
    if (dialog != null) {
        dialog.setTitle("Install Missing Components");
        if (dialog.showAndGet()) {
            GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Example 20 with ModelWizardDialog

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

the class InstallBuildToolsHyperlink method execute.

@Override
protected void execute(@NotNull Project project) {
    List<String> requested = Lists.newArrayList();
    Revision minBuildToolsRev = Revision.parseRevision(myVersion);
    requested.add(DetailsTypes.getBuildToolsPath(minBuildToolsRev));
    ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(project, requested);
    if (dialog != null && dialog.showAndGet()) {
        if (myBuildFile != null) {
            setBuildToolsVersion(project, myBuildFile, myVersion, true);
        } else {
            GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
        }
    }
}
Also used : Revision(com.android.repository.Revision) 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