Search in sources :

Example 1 with CreateFromSourcesMode

use of com.intellij.ide.util.newProjectWizard.modes.CreateFromSourcesMode 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)

Aggregations

StepSequence (com.intellij.ide.util.newProjectWizard.StepSequence)1 CreateFromSourcesMode (com.intellij.ide.util.newProjectWizard.modes.CreateFromSourcesMode)1 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)1 ProjectBuilder (com.intellij.ide.util.projectWizard.ProjectBuilder)1 WizardContext (com.intellij.ide.util.projectWizard.WizardContext)1 Disposable (com.intellij.openapi.Disposable)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 DefaultModulesProvider (com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider)1 ModulesProvider (com.intellij.openapi.roots.ui.configuration.ModulesProvider)1