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);
}
*/
}
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);
}
}
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;
}
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);
}
}
}
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);
}
}
}
Aggregations