package jetbrains.mps.ide.ui.dialogs.properties.creators; /*Generated by MPS */ import jetbrains.mps.util.Computable; import java.util.List; import java.awt.Component; import jetbrains.mps.project.structure.model.ModelRootDescriptor; import jetbrains.mps.ide.ui.filechoosers.treefilechooser.TreeFileChooser; import jetbrains.mps.vfs.IFile; import java.util.ArrayList; import jetbrains.mps.internal.collections.runtime.ListSequence; import com.intellij.openapi.ui.Messages; import jetbrains.mps.internal.collections.runtime.ISelector; import jetbrains.mps.vfs.FileSystem; import org.jetbrains.mps.openapi.persistence.PersistenceFacade; import org.jetbrains.mps.openapi.persistence.ModelRoot; import jetbrains.mps.extapi.persistence.FolderModelRootBase; import org.jetbrains.mps.openapi.persistence.Memento; import jetbrains.mps.persistence.MementoImpl; public class StubRootChooser implements Computable<List<String>> { private Component myComponent; private List<ModelRootDescriptor> myRoots; private boolean myJavaOnly; public StubRootChooser(Component component, List<ModelRootDescriptor> roots, boolean javaOnly) { myComponent = component; myRoots = roots; myJavaOnly = javaOnly; } @Override public List<String> compute() { TreeFileChooser chooser = new TreeFileChooser(); chooser.setMode(TreeFileChooser.MODE_FILES_AND_DIRECTORIES); List<IFile> files = chooser.showMultiSelectionDialog(null); List<String> result = new ArrayList<String>(); for (IFile file : files) { ListSequence.fromList(result).addElement(file.getPath()); } if (ListSequence.fromList(result).isEmpty()) { return result; } if (myJavaOnly) { int res = Messages.showYesNoDialog(myComponent, "MPS can try creating models for the specified locations, so that class files can be referenced from MPS models directly. Would you like to import models for the specified locations?", "Model Roots", Messages.getQuestionIcon()); if (res == Messages.YES) { ListSequence.fromList(myRoots).addSequence(ListSequence.fromList(result).select(new ISelector<String, ModelRootDescriptor>() { public ModelRootDescriptor select(String it) { return ModelRootDescriptor.getJavaStubsModelRoot(FileSystem.getInstance().getFile(it)); } })); } } else { final List<String> modelRootTypes = ListSequence.fromListWithValues(new ArrayList<String>(), PersistenceFacade.getInstance().getTypeIds()); if (ListSequence.fromList(modelRootTypes).isEmpty()) { return result; } List<String> modelRootNames = ListSequence.fromList(modelRootTypes).select(new ISelector<String, String>() { public String select(String it) { // TODO return it; } }).toListSequence(); final int res = Messages.showChooseDialog(myComponent, "MPS can try creating models for the specified locations,\n" + "so that class files can be referenced from MPS models directly.\n" + "Would you like to import models for the specified locations?", "Model Roots", ListSequence.fromList(modelRootNames).toGenericArray(String.class), ListSequence.fromList(modelRootNames).first(), Messages.getQuestionIcon()); if (res >= 0) { ListSequence.fromList(myRoots).addSequence(ListSequence.fromList(result).select(new ISelector<String, ModelRootDescriptor>() { public ModelRootDescriptor select(String it) { String type = ListSequence.fromList(modelRootTypes).getElement(res); ModelRoot root = PersistenceFacade.getInstance().getModelRootFactory(type).create(); if (root instanceof FolderModelRootBase) { ((FolderModelRootBase) root).setPath(it); } Memento m = new MementoImpl(); root.save(m); return new ModelRootDescriptor(type, m); } })); } } return result; } }