Author: snjeza
Date: 2012-05-01 09:44:45 -0400 (Tue, 01 May 2012)
New Revision: 40672
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesLocationPage.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java
Log:
JBIDE-11721 - Project location input is not validated in New Project Example wizard
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesLocationPage.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesLocationPage.java 2012-05-01
12:38:10 UTC (rev 40671)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesLocationPage.java 2012-05-01
13:44:45 UTC (rev 40672)
@@ -1,10 +1,12 @@
package org.jboss.tools.project.examples.wizard;
+import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
import org.eclipse.jface.dialogs.Dialog;
@@ -131,6 +133,15 @@
@Override
public void widgetSelected(SelectionEvent e) {
enableControls(outputDirectoryBrowse);
+ if (!isWorkspace.getSelection()) {
+ String location = outputDirectoryText.getText().trim();
+ if (!validateLocation(location)) {
+ return;
+ }
+ }
+ setPageComplete(true);
+ setErrorMessage(null);
+ setMessage(null);
ProjectExamplesActivator.getDefault().getPreferenceStore().setValue(ProjectExamplesActivator.PROJECT_EXAMPLES_DEFAULT,
isWorkspace.getSelection());
}
@@ -140,7 +151,16 @@
@Override
public void modifyText(ModifyEvent e) {
+ if (!isWorkspace.getSelection()) {
+ String location = outputDirectoryText.getText().trim();
+ if (!validateLocation(location)) {
+ return;
+ }
+ }
ProjectExamplesActivator.getDefault().getPreferenceStore().setValue(ProjectExamplesActivator.PROJECT_EXAMPLES_OUTPUT_DIRECTORY,
outputDirectoryText.getText());
+ setPageComplete(true);
+ setErrorMessage(null);
+ setMessage(null);
}
});
Control workingSetControl= createWorkingSetControl(composite);
@@ -148,6 +168,15 @@
setPageComplete(true);
}
+
+ private boolean canCreate(File file) {
+ while (!file.exists()) {
+ file= file.getParentFile();
+ if (file == null)
+ return false;
+ }
+ return file.canWrite();
+ }
public void init(IStructuredSelection selection, IWorkbenchPart activePart) {
setWorkingSets(getSelectedWorkingSet(selection, activePart));
@@ -299,4 +328,29 @@
return null;
}
+ private boolean validateLocation(String location) {
+ if (location.length() == 0) {
+ setErrorMessage(null);
+ setMessage("Enter a location for the project");
+ setPageComplete(false);
+ return false;
+ }
+ // check whether the location is a syntactically correct path
+ if (!Path.EMPTY.isValidPath(location)) {
+ setErrorMessage("Invalid project contents directory");
+ setPageComplete(false);
+ return false;
+ }
+ IPath projectPath = Path.fromOSString(location);
+ if (!projectPath.toFile().exists()) {
+ // check non-existing external location
+ if (!canCreate(projectPath.toFile())) {
+ setErrorMessage("Cannot create project content at the given external
location.");
+ setPageComplete(false);
+ return false;
+ }
+ }
+ return true;
+ }
+
}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java 2012-05-01
12:38:10 UTC (rev 40671)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java 2012-05-01
13:44:45 UTC (rev 40672)
@@ -10,6 +10,7 @@
************************************************************************************/
package org.jboss.tools.maven.project.examples.wizard;
+import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
@@ -26,7 +27,9 @@
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
@@ -45,7 +48,6 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
@@ -87,7 +89,8 @@
private WizardContext context;
private IRuntimeLifecycleListener listener;
- private Link warninglink;
+ private Button isWorkspace;
+ private Combo outputDirectoryCombo;
public ArchetypeExamplesWizardFirstPage() {
super(new ProjectImportConfiguration(), "", "",new
ArrayList<IWorkingSet>());
@@ -252,12 +255,24 @@
//Need to be called first, or error message would be overwritten
super.validate();
+ if (!isPageComplete()) {
+ return;
+ }
+ if (outputDirectoryCombo != null && isWorkspace != null) {
+ if (!isWorkspace.getSelection()) {
+ String location = outputDirectoryCombo.getText();
+ if (!validateLocation(location)) {
+ return;
+ }
+ }
+ }
String errorMessage = validateInputs();
setErrorMessage(errorMessage);
setMessage(null);
setPageComplete(errorMessage == null);
validateEnterpriseRepo();
+
}
private String validateInputs() {
@@ -393,14 +408,17 @@
field.setAccessible(true);
Object useDefaultWorkspaceLocation = field.get(this);
if (useDefaultWorkspaceLocation instanceof Button) {
- final Button useDefaultWorkspaceLocationButton = (Button)
useDefaultWorkspaceLocation;
- useDefaultWorkspaceLocationButton.setSelection(value);
- useDefaultWorkspaceLocationButton.notifyListeners(SWT.Selection, new Event());
- useDefaultWorkspaceLocationButton.addSelectionListener(new SelectionAdapter() {
+ isWorkspace = (Button) useDefaultWorkspaceLocation;
+ isWorkspace.setSelection(value);
+ isWorkspace.notifyListeners(SWT.Selection, new Event());
+ isWorkspace.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- ProjectExamplesActivator.getDefault().getPreferenceStore().setValue(ProjectExamplesActivator.PROJECT_EXAMPLES_DEFAULT,
useDefaultWorkspaceLocationButton.getSelection());
+ validate();
+ if (isPageComplete()) {
+ ProjectExamplesActivator.getDefault().getPreferenceStore().setValue(ProjectExamplesActivator.PROJECT_EXAMPLES_DEFAULT,
isWorkspace.getSelection());
+ }
}
});
@@ -416,14 +434,17 @@
field.setAccessible(true);
Object locationComboField = field.get(this);
if (locationComboField instanceof Combo) {
- final Combo locationCombo = (Combo) locationComboField;
- locationCombo.setText(defaultLocation);
- locationCombo.notifyListeners(SWT.Selection, new Event());
- locationCombo.addModifyListener(new ModifyListener() {
+ outputDirectoryCombo = (Combo) locationComboField;
+ outputDirectoryCombo.setText(defaultLocation);
+ outputDirectoryCombo.notifyListeners(SWT.Selection, new Event());
+ outputDirectoryCombo.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
- ProjectExamplesActivator.getDefault().getPreferenceStore().setValue(ProjectExamplesActivator.PROJECT_EXAMPLES_OUTPUT_DIRECTORY,
locationCombo.getText());
+ validate();
+ if (isPageComplete()) {
+ ProjectExamplesActivator.getDefault().getPreferenceStore().setValue(ProjectExamplesActivator.PROJECT_EXAMPLES_OUTPUT_DIRECTORY,
outputDirectoryCombo.getText());
+ }
}
});
@@ -433,6 +454,26 @@
}
}
+ private boolean validateLocation(String location) {
+ IPath projectPath = Path.fromOSString(location);
+ if (!projectPath.toFile().exists()) {
+ if (!canCreate(projectPath.toFile())) {
+ setErrorMessage("Cannot create project content at the given external
location.");
+ setPageComplete(false);
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean canCreate(File file) {
+ while (!file.exists()) {
+ file= file.getParentFile();
+ if (file == null)
+ return false;
+ }
+ return file.canWrite();
+ }
@Override
public void dispose() {
if (dialogSettings != null && serverRuntimes != null &&
serverTargetCombo != null) {
Show replies by date