Search in sources :

Example 6 with WizardContext

use of com.intellij.ide.util.projectWizard.WizardContext in project intellij-community by JetBrains.

the class CloudModuleBuilderSourceContribution method detectModuleStructure.

private void detectModuleStructure(Module module, final String contentPath) {
    final Project project = module.getProject();
    final CreateFromSourcesMode mode = new CreateFromSourcesMode() {

        @Override
        public boolean isAvailable(WizardContext context) {
            return true;
        }

        @Override
        public void addSteps(WizardContext context, ModulesProvider modulesProvider, StepSequence sequence, String specific) {
            super.addSteps(context, modulesProvider, sequence, specific);
            myProjectBuilder.setFileToImport(contentPath);
        }
    };
    final WizardContext context = new WizardContext(project);
    final StepSequence stepSequence = mode.getSteps(context, DefaultModulesProvider.createForProject(context.getProject()));
    if (stepSequence == null) {
        return;
    }
    Disposer.register(project, new Disposable() {

        @Override
        public void dispose() {
            for (ModuleWizardStep step : stepSequence.getAllSteps()) {
                step.disposeUIResources();
            }
        }
    });
    ProgressManager.getInstance().run(new Task.Backgroundable(project, CloudBundle.getText("detect.module.structure", getCloudType().getPresentableName()), false) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            for (ModuleWizardStep step = ContainerUtil.getFirstItem(stepSequence.getSelectedSteps()); step != null; step = stepSequence.getNextStep(step)) {
                if (step instanceof AbstractStepWithProgress<?>) {
                    ((AbstractStepWithProgress) step).performStep();
                } else {
                    step.updateDataModel();
                }
            }
            CloudAccountSelectionEditor.unsetAccountOnContext(context, getCloudType());
        }

        @Override
        public boolean shouldStartInBackground() {
            return false;
        }

        @Override
        public void onSuccess() {
            ProjectBuilder moduleBuilder = mode.getModuleBuilder();
            if (moduleBuilder == null) {
                return;
            }
            moduleBuilder.commit(project);
            getNotifier().showMessage(CloudBundle.getText("cloud.support.added", getCloudType().getPresentableName()), MessageType.INFO);
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) ModulesProvider(com.intellij.openapi.roots.ui.configuration.ModulesProvider) DefaultModulesProvider(com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider) Task(com.intellij.openapi.progress.Task) StepSequence(com.intellij.ide.util.newProjectWizard.StepSequence) CreateFromSourcesMode(com.intellij.ide.util.newProjectWizard.modes.CreateFromSourcesMode) Project(com.intellij.openapi.project.Project) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) ProjectBuilder(com.intellij.ide.util.projectWizard.ProjectBuilder) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) WizardContext(com.intellij.ide.util.projectWizard.WizardContext)

Example 7 with WizardContext

use of com.intellij.ide.util.projectWizard.WizardContext in project flutter-intellij by flutter.

the class FlutterProjectCreator method createModule.

public void createModule() {
    Project project = myModel.project().getValue();
    VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null) {
        // Project was deleted.
        return;
    }
    String baseDirPath = baseDir.getPath();
    String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, myModel.projectName().get(), "");
    String contentRoot = baseDirPath + "/" + moduleName;
    File location = new File(contentRoot);
    if (!location.exists() && !location.mkdirs()) {
        String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir", location.getAbsolutePath());
        Messages.showErrorDialog(project, message, ActionsBundle.message("action.NewDirectoryProject.title"));
        return;
    }
    // ModuleBuilder mixes UI and model code too much to easily reuse. We have to override a bunch of stuff to ensure
    // that methods which expect a live UI do not get called.
    FlutterModuleBuilder builder = new FlutterModuleBuilder() {

        @NotNull
        @Override
        public FlutterCreateAdditionalSettings getAdditionalSettings() {
            return makeAdditionalSettings();
        }

        @Override
        protected FlutterSdk getFlutterSdk() {
            return FlutterSdk.forPath(myModel.flutterSdk().get());
        }

        @Override
        public boolean validate(Project current, Project dest) {
            return true;
        }

        @Override
        public ModuleWizardStep getCustomOptionsStep(final WizardContext context, final Disposable parentDisposable) {
            return null;
        }

        @Override
        public void setFlutterSdkPath(String s) {
        }

        @Override
        public ModuleWizardStep modifySettingsStep(@NotNull SettingsStep settingsStep) {
            return null;
        }
    };
    builder.setName(myModel.projectName().get());
    builder.setModuleFilePath(toSystemIndependentName(contentRoot) + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION);
    builder.commitModule(project, null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) WizardContext(com.intellij.ide.util.projectWizard.WizardContext) SettingsStep(com.intellij.ide.util.projectWizard.SettingsStep) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) FlutterModuleBuilder(io.flutter.module.FlutterModuleBuilder)

Example 8 with WizardContext

use of com.intellij.ide.util.projectWizard.WizardContext in project android by JetBrains.

the class SourceToGradleModuleStep method createDependentSteps.

@NotNull
@Override
protected Collection<? extends ModelWizardStep> createDependentSteps() {
    WizardContext context = getModel().getContext();
    ArrayList<ModelWizardStep> wrappedSteps = new ArrayList<>();
    for (ModuleImporter importer : ModuleImporter.getAllImporters(context)) {
        for (ModuleWizardStep inputStep : importer.createWizardSteps()) {
            wrappedSteps.add(new ModuleWizardStepAdapter(context, inputStep));
        }
    }
    return wrappedSteps;
}
Also used : ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) ModuleImporter(com.android.tools.idea.gradle.project.ModuleImporter) WizardContext(com.intellij.ide.util.projectWizard.WizardContext) ArrayList(java.util.ArrayList) ModelWizardStep(com.android.tools.idea.wizard.model.ModelWizardStep) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with WizardContext

use of com.intellij.ide.util.projectWizard.WizardContext in project android by JetBrains.

the class AdtImportLocationStep method validate.

@Override
public boolean validate() throws ConfigurationException {
    WizardContext context = getWizardContext();
    GradleImport importer = AdtImportProvider.getImporter(context);
    if (importer != null) {
        List<String> errors = importer.getErrors();
        if (!errors.isEmpty()) {
            throw new ConfigurationException(errors.get(0));
        }
    }
    // The following code is based on similar code in com.intellij.ide.util.newProjectWizard.ProjectNameStep
    String projectFileDirectory = getProjectFileDirectory();
    if (projectFileDirectory.length() == 0) {
        throw new ConfigurationException(String.format("Enter %1$s file location", context.getPresentationName()));
    }
    boolean shouldPromptCreation = myIsPathChangedByUser;
    if (!ProjectWizardUtil.createDirectoryIfNotExists(String.format("The %1$s file directory\n", context.getPresentationName()), projectFileDirectory, shouldPromptCreation)) {
        return false;
    }
    boolean shouldContinue = true;
    File projectFile = new File(getProjectFileDirectory());
    String title = "New Project";
    if (projectFile.isFile()) {
        shouldContinue = false;
        String message = String.format("%s exists and is a file.\nPlease specify a different project location", projectFile.getAbsolutePath());
        Messages.showErrorDialog(message, title);
    } else if (projectFile.isDirectory()) {
        File[] files = projectFile.listFiles();
        if (files != null && files.length > 0) {
            String message = String.format("%1$s folder already exists and is not empty.\nIts content may be overwritten.\nContinue?", projectFile.getAbsolutePath());
            int answer = Messages.showYesNoDialog(message, title, Messages.getQuestionIcon());
            shouldContinue = answer == 0;
        }
    }
    return shouldContinue;
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) WizardContext(com.intellij.ide.util.projectWizard.WizardContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 10 with WizardContext

use of com.intellij.ide.util.projectWizard.WizardContext in project liferay-ide by liferay.

the class LiferayProjectTypeStep method getTemplatesMap.

public static MultiMap<TemplatesGroup, ProjectTemplate> getTemplatesMap(WizardContext context) {
    MultiMap<TemplatesGroup, ProjectTemplate> groups = new MultiMap<>();
    for (ProjectTemplatesFactory factory : ProjectTemplatesFactory.EP_NAME.getExtensions()) {
        Stream<String> stream = Stream.of(factory.getGroups());
        stream.map(group -> new AbstractMap.SimpleEntry<>(group, factory.createTemplates(group, context))).filter(pair -> !CoreUtil.isNullOrEmpty(pair.getValue())).forEach(pair -> {
            String group = pair.getKey();
            Icon icon = factory.getGroupIcon(group);
            String parentGroup = factory.getParentGroup(group);
            TemplatesGroup templatesGroup = new TemplatesGroup(group, null, icon, factory.getGroupWeight(group), parentGroup, group, null);
            groups.putValues(templatesGroup, Arrays.asList(pair.getValue()));
        });
    }
    return groups;
}
Also used : AbstractMap(java.util.AbstractMap) UIUtil(com.intellij.util.ui.UIUtil) CommitStepException(com.intellij.ide.wizard.CommitStepException) Arrays(java.util.Arrays) THashMap(gnu.trove.THashMap) JBLabel(com.intellij.ui.components.JBLabel) WizardDelegate(com.intellij.ide.util.newProjectWizard.WizardDelegate) AddSupportForFrameworksPanel(com.intellij.ide.util.newProjectWizard.AddSupportForFrameworksPanel) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Map(java.util.Map) Disposer(com.intellij.openapi.util.Disposer) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MultiMap(com.intellij.util.containers.MultiMap) TemplatesGroup(com.intellij.ide.util.newProjectWizard.TemplatesGroup) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) LibrariesContainerFactory(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory) Collection(java.util.Collection) BuilderBasedTemplate(com.intellij.platform.templates.BuilderBasedTemplate) FactoryMap(com.intellij.util.containers.FactoryMap) Set(java.util.Set) Icon(javax.swing.Icon) Collectors(java.util.stream.Collectors) WizardContext(com.intellij.ide.util.projectWizard.WizardContext) Nullable(org.jetbrains.annotations.Nullable) Dimension(java.awt.Dimension) List(java.util.List) Stream(java.util.stream.Stream) CoreUtil(com.liferay.ide.idea.util.CoreUtil) Function(com.intellij.util.Function) ModulesProvider(com.intellij.openapi.roots.ui.configuration.ModulesProvider) SettingsStep(com.intellij.ide.util.projectWizard.SettingsStep) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) JPanel(javax.swing.JPanel) ListSelectionModel(javax.swing.ListSelectionModel) CardLayout(java.awt.CardLayout) ProjectCategoryUsagesCollector(com.intellij.ide.projectWizard.ProjectCategoryUsagesCollector) JTextField(javax.swing.JTextField) ModuleBuilder(com.intellij.ide.util.projectWizard.ModuleBuilder) ContainerUtil(com.intellij.util.containers.ContainerUtil) ProjectTemplate(com.intellij.platform.ProjectTemplate) FrameworkSupportModelBase(com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelBase) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FrameworkSupportNode(com.intellij.ide.util.newProjectWizard.FrameworkSupportNode) LibrariesContainer(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer) TemplateModuleBuilder(com.intellij.platform.templates.TemplateModuleBuilder) ProjectCategory(com.intellij.ide.projectWizard.ProjectCategory) FrameworkSupportUtil(com.intellij.ide.util.frameworkSupport.FrameworkSupportUtil) Project(com.intellij.openapi.project.Project) ModuleType(com.intellij.openapi.module.ModuleType) StepSequence(com.intellij.ide.util.newProjectWizard.StepSequence) FrameworkRole(com.intellij.ide.util.frameworkSupport.FrameworkRole) JComponent(javax.swing.JComponent) JBList(com.intellij.ui.components.JBList) StringUtil(com.intellij.openapi.util.text.StringUtil) ListItemDescriptorAdapter(com.intellij.openapi.ui.popup.ListItemDescriptorAdapter) Convertor(com.intellij.util.containers.Convertor) FrameworkSupportNodeBase(com.intellij.ide.util.newProjectWizard.FrameworkSupportNodeBase) CollectionListModel(com.intellij.ui.CollectionListModel) ProjectTemplatesFactory(com.intellij.platform.ProjectTemplatesFactory) Disposable(com.intellij.openapi.Disposable) SingleSelectionModel(com.intellij.ui.SingleSelectionModel) FrameworkSupportInModuleProvider(com.intellij.framework.addSupport.FrameworkSupportInModuleProvider) AbstractMap(java.util.AbstractMap) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) JLabel(javax.swing.JLabel) GroupedItemsListRenderer(com.intellij.ui.popup.list.GroupedItemsListRenderer) ConcurrentMultiMap(com.intellij.util.containers.ConcurrentMultiMap) ListSelectionListener(javax.swing.event.ListSelectionListener) Collections(java.util.Collections) ListSpeedSearch(com.intellij.ui.ListSpeedSearch) MultiMap(com.intellij.util.containers.MultiMap) ConcurrentMultiMap(com.intellij.util.containers.ConcurrentMultiMap) ProjectTemplatesFactory(com.intellij.platform.ProjectTemplatesFactory) TemplatesGroup(com.intellij.ide.util.newProjectWizard.TemplatesGroup) Icon(javax.swing.Icon) ProjectTemplate(com.intellij.platform.ProjectTemplate)

Aggregations

WizardContext (com.intellij.ide.util.projectWizard.WizardContext)11 Project (com.intellij.openapi.project.Project)4 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)3 Disposable (com.intellij.openapi.Disposable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NotNull (org.jetbrains.annotations.NotNull)3 StepSequence (com.intellij.ide.util.newProjectWizard.StepSequence)2 SettingsStep (com.intellij.ide.util.projectWizard.SettingsStep)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2 ModulesProvider (com.intellij.openapi.roots.ui.configuration.ModulesProvider)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ModuleImporter (com.android.tools.idea.gradle.project.ModuleImporter)1 ModelWizardStep (com.android.tools.idea.wizard.model.ModelWizardStep)1 FrameworkSupportInModuleProvider (com.intellij.framework.addSupport.FrameworkSupportInModuleProvider)1 ProjectCategory (com.intellij.ide.projectWizard.ProjectCategory)1 ProjectCategoryUsagesCollector (com.intellij.ide.projectWizard.ProjectCategoryUsagesCollector)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 FrameworkRole (com.intellij.ide.util.frameworkSupport.FrameworkRole)1 FrameworkSupportUtil (com.intellij.ide.util.frameworkSupport.FrameworkSupportUtil)1