public IPath getProjectLocation() { String projectName = getProjectName(); if (projectName.isEmpty()) { return null; } if (!Path.EMPTY.isValidPath(getLocationString())) { return null; } return Path.fromOSString(getLocationString()); }
public void update(Observable o, Object arg) { final IWorkspace workspace = DLTKUIPlugin.getWorkspace(); final String name = fNameGroup.getName(); // check whether the project name field is empty if (name.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.ScriptProjectWizardFirstPage_Message_enterProjectName); setPageComplete(false); return; } // check whether the project name is valid final IStatus nameStatus = workspace.validateName(name, IResource.PROJECT); if (!nameStatus.isOK()) { setErrorMessage(nameStatus.getMessage()); setPageComplete(false); return; } // check whether project already exists final IProject handle = getProjectHandle(); if (!isInLocalServer()) { if (handle.exists()) { setErrorMessage( NewWizardMessages.ScriptProjectWizardFirstPage_Message_projectAlreadyExists); setPageComplete(false); return; } } IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); String newProjectNameLowerCase = name.toLowerCase(); for (IProject currentProject : projects) { String existingProjectName = currentProject.getName(); if (existingProjectName.toLowerCase().equals(newProjectNameLowerCase)) { setErrorMessage( NewWizardMessages.ScriptProjectWizardFirstPage_Message_projectAlreadyExists); setPageComplete(false); return; } } final String location = fPHPLocationGroup.getLocation().toOSString(); // check whether location is empty if (location.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.ScriptProjectWizardFirstPage_Message_enterLocation); setPageComplete(false); return; } // check whether the location is a syntactically correct path if (!Path.EMPTY.isValidPath(location)) { setErrorMessage(NewWizardMessages.ScriptProjectWizardFirstPage_Message_invalidDirectory); setPageComplete(false); return; } // check whether the location has the workspace as prefix IPath projectPath = Path.fromOSString(location); if (!fPHPLocationGroup.isInWorkspace() && Platform.getLocation().isPrefixOf(projectPath)) { setErrorMessage( NewWizardMessages.ScriptProjectWizardFirstPage_Message_cannotCreateInWorkspace); setPageComplete(false); return; } // If we do not place the contents in the workspace validate the // location. if (!fPHPLocationGroup.isInWorkspace()) { IEnvironment environment = getEnvironment(); if (EnvironmentManager.isLocal(environment)) { final IStatus locationStatus = workspace.validateProjectLocation(handle, projectPath); File file = projectPath.toFile(); if (!locationStatus.isOK()) { setErrorMessage(locationStatus.getMessage()); setPageComplete(false); return; } if (!canCreate(projectPath.toFile())) { setErrorMessage( NewWizardMessages.ScriptProjectWizardFirstPage_Message_invalidDirectory); setPageComplete(false); return; } } } if (fragment != null) { fragment.getWizardModel().putObject("ProjectName", fNameGroup.getName()); if (!fragment.isComplete()) { setErrorMessage((String) fragment.getWizardModel().getObject(ERROR_MESSAGE)); setPageComplete(false); return; } } setPageComplete(true); setErrorMessage(null); setMessage(null); }
public void update(Observable o, Object arg) { final IWorkspace workspace = JavaPlugin.getWorkspace(); final String name = fNameGroup.getName(); // check whether the project name field is empty if (name.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterProjectName); setPageComplete(false); return; } // check whether the project name is valid final IStatus nameStatus = workspace.validateName(name, IResource.PROJECT); if (!nameStatus.isOK()) { setErrorMessage(nameStatus.getMessage()); setPageComplete(false); return; } // check whether project already exists final IProject handle = workspace.getRoot().getProject(name); if (handle.exists()) { setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_projectAlreadyExists); setPageComplete(false); return; } // check whether package name is valid final String packageName = fNameGroup.getPackageName(); if (packageName.length() == 0) { setErrorMessage(null); setMessage("Enter a top level package name."); setPageComplete(false); return; } if (JavaConventions.validatePackageName( packageName, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3) .getSeverity() == IStatus.ERROR) { setErrorMessage(null); setMessage("The entered top level package name is not valid."); setPageComplete(false); return; } IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(name); if (projectLocation.toFile().exists()) { try { // correct casing String canonicalPath = projectLocation.toFile().getCanonicalPath(); projectLocation = new Path(canonicalPath); } catch (IOException e) { JavaPlugin.log(e); } String existingName = projectLocation.lastSegment(); if (!existingName.equals(fNameGroup.getName())) { setErrorMessage( Messages.format( NewWizardMessages .NewJavaProjectWizardPageOne_Message_invalidProjectNameForWorkspaceRoot, BasicElementLabels.getResourceName(existingName))); setPageComplete(false); return; } setErrorMessage("A project at specified location already exists."); setPageComplete(false); return; } final String location = fLocationGroup.getLocation().toOSString(); // check whether location is empty if (location.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterLocation); setPageComplete(false); return; } // check whether the location is a syntactically correct path if (!Path.EMPTY.isValidPath(location)) { setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_invalidDirectory); setPageComplete(false); return; } IPath projectPath = Path.fromOSString(location); if (fLocationGroup.isWorkspaceRadioSelected()) projectPath = projectPath.append(fNameGroup.getName()); if (projectPath.toFile().exists()) { // create from existing source if (Platform.getLocation().isPrefixOf(projectPath)) { // create // from // existing // source // in // workspace if (!Platform.getLocation().equals(projectPath.removeLastSegments(1))) { setErrorMessage( NewRooWizardMessages.NewRooProjectWizardPageOne_Message_notOnWorkspaceRoot); setPageComplete(false); return; } if (!projectPath.toFile().exists()) { setErrorMessage( NewRooWizardMessages.NewRooProjectWizardPageOne_notExisingProjectOnWorkspaceRoot); setPageComplete(false); return; } } } else if (!fLocationGroup.isWorkspaceRadioSelected()) { // create at // non // existing // external // location if (!canCreate(projectPath.toFile())) { setErrorMessage( NewWizardMessages.NewJavaProjectWizardPageOne_Message_cannotCreateAtExternalLocation); setPageComplete(false); return; } // If we do not place the contents in the workspace validate the // location. final IStatus locationStatus = workspace.validateProjectLocation(handle, projectPath); if (!locationStatus.isOK()) { setErrorMessage(locationStatus.getMessage()); setPageComplete(false); return; } } if (firstValidation) { firstValidation = false; if (RooCoreActivator.getDefault().getInstallManager().getDefaultRooInstall() == null) { setErrorMessage("No Roo installation configured in workspace preferences."); setPageComplete(false); return; } } else { IRooInstall install = null; if (useDefaultRooInstall()) { install = RooCoreActivator.getDefault().getInstallManager().getDefaultRooInstall(); } else { String installName = getRooInstallName(); if (installName != null) { install = RooCoreActivator.getDefault().getInstallManager().getRooInstall(installName); } } if (install == null) { setErrorMessage("No Roo installation configured in workspace preferences."); setPageComplete(false); return; } else { installError = install.validate(); if (installError != null && !installError.isOK()) { setErrorMessage(installError.getMessage()); setPageComplete(false); return; } } } setPageComplete(true); setErrorMessage(null); setMessage(null); }
public void update(Observable o, Object arg) { final IWorkspace workspace = JavaPlugin.getWorkspace(); final String name = fNameGroup.getName(); // check whether the project name field is empty if (name.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterProjectName); setPageComplete(false); return; } // check whether the project name is valid IStatus nameStatus = workspace.validateName(name, IResource.PROJECT); if (nameStatus.isOK()) { // there are further restrictions on Grails project names nameStatus = validateProjectName(name); } if (!nameStatus.isOK()) { setErrorMessage(nameStatus.getMessage()); setPageComplete(false); return; } // check whether project already exists final IProject handle = workspace.getRoot().getProject(name); if (handle.exists()) { setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_projectAlreadyExists); setPageComplete(false); return; } IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(name); if (projectLocation.toFile().exists()) { try { // correct casing String canonicalPath = projectLocation.toFile().getCanonicalPath(); projectLocation = new Path(canonicalPath); } catch (IOException e) { JavaPlugin.log(e); } String existingName = projectLocation.lastSegment(); if (!existingName.equals(fNameGroup.getName())) { setErrorMessage( Messages.format( NewWizardMessages .NewJavaProjectWizardPageOne_Message_invalidProjectNameForWorkspaceRoot, BasicElementLabels.getResourceName(existingName))); setPageComplete(false); return; } } final String location = fLocationGroup.getLocation().toOSString(); // check whether location is empty if (location.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterLocation); setPageComplete(false); return; } // check whether the location is a syntactically correct path if (!Path.EMPTY.isValidPath(location)) { setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_invalidDirectory); setPageComplete(false); return; } IPath projectPath = Path.fromOSString(location); if (fLocationGroup.isWorkspaceRadioSelected()) projectPath = projectPath.append(fNameGroup.getName()); boolean importing = false; if (projectPath.toFile().exists()) { // create from existing source if (Platform.getLocation() .isPrefixOf(projectPath)) { // create from existing source in workspace if (!projectPath.toFile().exists()) { setErrorMessage( org.grails.ide.eclipse.ui.internal.wizard.NewGrailsWizardMessages .NewGrailsProjectWizardPageOne_notExisingProjectOnWorkspaceRoot); setPageComplete(false); return; } } importing = true; } else if (!fLocationGroup .isWorkspaceRadioSelected()) { // create at non existing external location if (!canCreate(projectPath.toFile())) { setErrorMessage( NewWizardMessages.NewJavaProjectWizardPageOne_Message_cannotCreateAtExternalLocation); setPageComplete(false); return; } // If we do not place the contents in the workspace validate the // location. final IStatus locationStatus = workspace.validateProjectLocation(handle, projectPath); if (!locationStatus.isOK()) { setErrorMessage(locationStatus.getMessage()); setPageComplete(false); return; } } // Let other checks perform before this one. // If a location was specified, the project name must match the last segment of the location if (!projectPath.isEmpty()) { String expectedProjectName = projectPath.lastSegment(); if ((name == null) || !name.equals(expectedProjectName)) { setErrorMessage( NewGrailsWizardMessages .NewGrailsProjectWizardPageOne_invalidProjectNameForExternalLocation); setPageComplete(false); return; } } if (GrailsCoreActivator.getDefault().getInstallManager().getDefaultGrailsInstall() == null) { setErrorMessage( org.grails.ide.eclipse.ui.internal.wizard.NewGrailsWizardMessages .NewGrailsProjectWizardPageOne_noGrailsInstallationInWorkspacePreferences); setPageComplete(false); return; } setPageComplete(true); setErrorMessage(null); if (importing) { // Project exists, but is not in workspace therefore import it. setMessage( Messages.format( org.grails.ide.eclipse.ui.internal.wizard.NewGrailsWizardMessages .NewGrailsProjectWizardPageOne_importingExistingProject, BasicElementLabels.getResourceName(projectPath.lastSegment()))); } else { setMessage(null); } }