Author: scabanovich
Date: 2012-02-15 16:25:24 -0500 (Wed, 15 Feb 2012)
New Revision: 38780
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/operation/WebNatureOperation.java
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/operation/WebProjectAdoptOperation.java
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/project/ImportWebProjectWizardPage.java
Log:
JBIDE-10892
https://issues.jboss.org/browse/JBIDE-10892
Improved comparing paths.
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/operation/WebNatureOperation.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/operation/WebNatureOperation.java 2012-02-15
21:15:36 UTC (rev 38779)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/operation/WebNatureOperation.java 2012-02-15
21:25:24 UTC (rev 38780)
@@ -11,6 +11,7 @@
package org.jboss.tools.jst.web.ui.operation;
import java.io.File;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;
@@ -412,14 +413,14 @@
wcco.setDataModel(dataModel);
dataModel.setProperty(IProjectCreationPropertiesNew.PROJECT_NAME, projectName);
dataModel.setProperty(IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME,
projectName);
- if(!isDefaultLocation(projectLocation)) {
+ if(!isDefaultLocation(projectLocation, true)) {
dataModel.setProperty(IProjectCreationPropertiesNew.USE_DEFAULT_LOCATION,
Boolean.FALSE);
dataModel.setProperty(IProjectCreationPropertiesNew.USER_DEFINED_LOCATION,
projectLocation);
}
if(!getProject().exists()) {
IProjectDescription pd =
ModelPlugin.getWorkspace().newProjectDescription(getProject().getName());
- if(!isDefaultLocation(projectLocation)) {
+ if(!isDefaultLocation(projectLocation, true)) {
pd.setLocation(new Path(projectLocation));
}
getProject().create(pd, null);
@@ -516,16 +517,29 @@
return true;
}
- private boolean isDefaultLocation(String projectLocation) {
+ protected boolean isDefaultLocation(String projectLocation, boolean exact) {
String root =
ModelPlugin.getWorkspace().getRoot().getLocation().toString().replace('\\',
'/');
- return (projectLocation.replace('\\','/') + "/").equals(root
+ "/" + getProject().getName() + "/"); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
-// return (projectLocation.replace('\\','/') +
"/").startsWith(root + "/" + getProject().getName() + "/");
+ try {
+ File f1 = new File(projectLocation);
+ if(f1.exists()) {
+ String pLocation = f1.getCanonicalPath().replace('\\','/') +
'/';
+ String rLocation =
ModelPlugin.getWorkspace().getRoot().getLocation().toFile().getCanonicalPath().replace('\\','/')
+ '/' + getProject().getName() + '/';
+ return exact ? pLocation.equals(rLocation) : pLocation.startsWith(rLocation);
+
+ }
+ } catch (IOException e) {
+ WebUiPlugin.getDefault().logError(e);
+ }
+ return exact ? (projectLocation.replace('\\','/') +
'/').equals(root + '/' + getProject().getName() + '/')
+ : (projectLocation.replace('\\','/') + '/').startsWith(root
+ '/' + getProject().getName() + '/');
}
private String createLinks(String projectLocation) throws CoreException {
+ if(isDefaultLocation(projectLocation, false)) {
+ return projectLocation;
+ }
IProject project = getProject();
String root =
ModelPlugin.getWorkspace().getRoot().getLocation().toString().replace('\\',
'/');
- if((projectLocation.replace('\\','/') + "/").startsWith(root
+ "/" + project.getName() + "/")) return projectLocation;
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String webroot = getProperty(WEB_CONTENT_LOCATION_ID);
String[] javaRoot = (String[])getPropertyObject(JAVA_SOURCES_LOCATION_ID);
@@ -566,6 +580,11 @@
return wsProjectLocation;
}
+
+// private boolean isProjectLocationInsideWorkspaceProject(String projectLocation) {
+// File project
+// return false;
+// }
private org.eclipse.wst.common.project.facet.core.runtime.IRuntime
findFacetRuntime(IRuntime runtime) {
String runtimeName = getProperty(WebNatureOperation.RUNTIME_NAME);
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/operation/WebProjectAdoptOperation.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/operation/WebProjectAdoptOperation.java 2012-02-15
21:15:36 UTC (rev 38779)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/operation/WebProjectAdoptOperation.java 2012-02-15
21:25:24 UTC (rev 38780)
@@ -163,9 +163,11 @@
if(getProject().exists()) return true;
String location = getProperty(PROJECT_LOCATION_ID).replace('\\', '/');
+ if(isDefaultLocation(location, false)) {
+ return true;
+ }
String root =
ModelPlugin.getWorkspace().getRoot().getLocation().toString().replace('\\',
'/');
String wsProjectLocation = (root + "/" +
getProject().getName()).replace('\\', '/');; //$NON-NLS-1$
- if(location.equals(wsProjectLocation) || location.startsWith(wsProjectLocation +
"/")) return true; //$NON-NLS-1$
File wsf = new File(wsProjectLocation);
if(!wsf.isDirectory()) return true;
File[] cs = wsf.listFiles();
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/project/ImportWebProjectWizardPage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/project/ImportWebProjectWizardPage.java 2012-02-15
21:15:36 UTC (rev 38779)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/project/ImportWebProjectWizardPage.java 2012-02-15
21:25:24 UTC (rev 38780)
@@ -13,6 +13,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
+import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@@ -103,7 +104,7 @@
webXmlLocationAdapter.setValue("" + context.getInitialLocation());
//$NON-NLS-1$
} else {
linkAdapter =
support.getPropertyEditorAdapterByName(ImportWebDirProjectContext.ATTR_LINK);
- linkAdapter.setValue("true"); //$NON-NLS-1$
+ linkAdapter.setValue("false"); //$NON-NLS-1$
}
}
@@ -185,9 +186,12 @@
setPageComplete(validatePage());
getContainer().updateButtons();
if(linkAdapter != null) {
- support.getFieldEditorByName(ImportWebDirProjectContext.ATTR_LINK).setEnabled(mayNeedLink(),
(Composite)getControl());
+ boolean requiresLink = !isProjectFolderPresentInWorkspace() &&
isLocationInsideWorkspace();
+ support.getFieldEditorByName(ImportWebDirProjectContext.ATTR_LINK).setEnabled(mayNeedLink()
&& !requiresLink, (Composite)getControl());
if(!mayNeedLink() && linkAdapter != null) {
linkAdapter.setValue("false"); //$NON-NLS-1$
+ } else if(requiresLink) {
+ linkAdapter.setValue("true"); //$NON-NLS-1$
}
}
}
@@ -199,12 +203,15 @@
updateContext(false, true);
setPageComplete(validatePage());
getContainer().updateButtons();
+ boolean requiresLink = !isProjectFolderPresentInWorkspace() &&
isLocationInsideWorkspace();
if(linkAdapter != null) {
- support.getFieldEditorByName(ImportWebDirProjectContext.ATTR_LINK).setEnabled(mayNeedLink(),
(Composite)getControl());
+ support.getFieldEditorByName(ImportWebDirProjectContext.ATTR_LINK).setEnabled(mayNeedLink()
&& !requiresLink, (Composite)getControl());
+ if(!mayNeedLink()) {
+ linkAdapter.setValue("false"); //$NON-NLS-1$
+ } else if(requiresLink) {
+ linkAdapter.setValue("true"); //$NON-NLS-1$
+ }
}
- if(!mayNeedLink() && linkAdapter != null) {
- linkAdapter.setValue("false"); //$NON-NLS-1$
- }
}
}
);
@@ -235,11 +242,29 @@
private boolean mayNeedLink() {
String location = getWebXmlLocationValue();
if(location == null || location.trim().length() == 0) return false;
+ return !isProjectFolderPresentInWorkspace() || !isLocationInsideWorkspace();
+ }
+
+ private boolean isProjectFolderPresentInWorkspace() {
+ File workspaceFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
+ return new File(workspaceFile, getProjectNameValue()).exists();
+ }
+
+ private boolean isLocationInsideWorkspace() {
+ String location = getWebXmlLocationValue();
+ if(location == null || location.trim().length() == 0) return false;
String workspace =
ResourcesPlugin.getWorkspace().getRoot().getLocation().toString().replace('\\',
'/') + '/';
location = location.replace('\\', '/');
- if(!location.startsWith(workspace)) return true;
-
- return false;
+ File webxmlFile = new File(location);
+ File workspaceFile = new File(workspace);
+ if(webxmlFile.exists() && workspaceFile.exists()) {
+ try {
+ return webxmlFile.getCanonicalPath().startsWith(workspaceFile.getCanonicalPath());
+ } catch (IOException e) {
+ WebUiPlugin.getDefault().logError(e);
+ }
+ }
+ return location.startsWith(workspace);
}
private void updateProjectNameValue(boolean onProjectNameEdit, boolean
onProjectLocationEdit) {
@@ -439,7 +464,7 @@
setErrorMessage(WizardKeys.getString(ImportWebDirProjectContext.PAGE_NAME+"_existsInWorkspace"));
//$NON-NLS-1$
return false;
}
-
+
return true;
}