protected boolean checkLibraryName(String libraryName) { if (MPSModuleRepository.getInstance().getModuleByUID(libraryName) != null) { myThis.getDialog().setErrorText("Duplicate library name: " + libraryName); return false; } return true; }
/*package*/ void onCancel() { myThis.getDialog().dispose(); }
/*package*/ void onOk() { if (myThis.getSourcesPath().length() == 0) { myThis.getDialog().setErrorText("Enter the sources path"); return; } File sourcesDir = new File(myThis.getSourcesPath()); if (!(sourcesDir.exists())) { myThis.getDialog().setErrorText("Specified sources dir doesn't exist"); return; } String moduleName = myThis.myModuleNameField.getText(); // RE-3532 if (!SolutionUtils.isValidModuleName(moduleName)) { myThis.getDialog().setErrorText("Invalid module name"); return; } if (moduleName.isEmpty()) { myThis.getDialog().setErrorText("Enter the module name"); return; } final String libraryName = moduleName; if (!checkLibraryName(libraryName)) { return; } String projectPath = FileUtil.getCanonicalPath(myThis.getProject().getProjectFile().getParentFile()); String solutionDirPath = projectPath + File.separator + "modules" + File.separator + libraryName; String message = NewModuleCheckUtil.checkModuleDirectory( new File(solutionDirPath), MPSExtentions.DOT_SOLUTION, "Module"); if (message != null) { myThis.getDialog().setErrorText(message); return; } final String descriptorPath = solutionDirPath + File.separator + libraryName + MPSExtentions.DOT_SOLUTION; myThis.getDialog().dispose(); SolutionUtils.refreshModuleFiles(descriptorPath); final List<SModelDescriptor> modelDescriptors = new ArrayList<SModelDescriptor>(); execute(descriptorPath, modelDescriptors); // RE-3181 ModelAccess.instance() .runWriteActionInCommand( new Runnable() { @Override public void run() { try { SWCStubsRegistry.setAvoidIndexing(true); SModelOperations.validateLanguagesAndImportsNew(modelDescriptors, myResult); } finally { SWCStubsRegistry.setAvoidIndexing(false); StubSolutionUtils.invalidateStubSolutionCaches(myResult); } } }, getProject().getProject()); }