[108837] Structure edit sychronization
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/StructureEdit.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/StructureEdit.java
index fcd72f2..491351c 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/StructureEdit.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/StructureEdit.java
@@ -86,6 +86,7 @@
private final ModuleStructuralModel structuralModel;
private final Map dependentCores = new HashMap();
+ private IProject aProject;
private boolean isStructuralModelSelfManaged;
private boolean isReadOnly;
@@ -314,6 +315,7 @@
structuralModel = aNature.getModuleStructuralModelForRead(this);
else
structuralModel = aNature.getModuleStructuralModelForWrite(this);
+ aProject = aNature.getProject();
isReadOnly = toAccessAsReadOnly;
isStructuralModelSelfManaged = true;
}
@@ -331,6 +333,7 @@
*/
public StructureEdit(ModuleStructuralModel aStructuralModel) {
structuralModel = aStructuralModel;
+ aProject = aStructuralModel.getProject();
}
/**
@@ -347,7 +350,10 @@
public void save(IProgressMonitor aMonitor) {
if (isReadOnly)
throwAttemptedReadOnlyModification();
- structuralModel.save(aMonitor, this);
+ synchronized (structuralModel) {
+ if (!structuralModel.isDisposed())
+ structuralModel.save(aMonitor, this);
+ }
}
/**
@@ -364,7 +370,10 @@
public void saveIfNecessary(IProgressMonitor aMonitor) {
if (isReadOnly)
throwAttemptedReadOnlyModification();
- structuralModel.saveIfNecessary(aMonitor, this);
+ synchronized (structuralModel) {
+ if (!structuralModel.isDisposed())
+ structuralModel.saveIfNecessary(aMonitor, this);
+ }
}
/**
@@ -377,8 +386,15 @@
* @see org.eclipse.wst.common.componentcore.IEditModelHandler#dispose()
*/
public void dispose() {
- if (isStructuralModelSelfManaged)
- structuralModel.releaseAccess(this);
+
+ if (isStructuralModelSelfManaged) {
+ synchronized (structuralModel) {
+ if (!structuralModel.isDisposed()) {
+ structuralModel.releaseAccess(this);
+ }
+ }
+
+ }
if (dependentCores.size() > 0) {
synchronized (dependentCores) {
for (Iterator cores = dependentCores.values().iterator(); cores.hasNext();)
@@ -393,11 +409,16 @@
* </p>
*/
public void prepareProjectComponentsIfNecessary() {
- try {
- structuralModel.prepareProjectModulesIfNecessary();
- } catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+
+ synchronized (structuralModel) {
+ if (!structuralModel.isDisposed()) {
+ try {
+ structuralModel.prepareProjectModulesIfNecessary();
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
}
}
@@ -411,7 +432,12 @@
* @return The root object of the underlying model
*/
public ProjectComponents getComponentModelRoot() {
- return (ProjectComponents) structuralModel.getPrimaryRootObject();
+ ProjectComponents comps = null;
+ synchronized (structuralModel) {
+ if (!structuralModel.isDisposed())
+ comps = (ProjectComponents) structuralModel.getPrimaryRootObject();
+ }
+ return comps;
}
/**
@@ -743,7 +769,7 @@
ModuleURIUtil.ensureValidFullyQualifiedModuleURI(aModuleURI);
String projectName = aModuleURI.segment(ModuleURIUtil.ModuleURI.PROJECT_NAME_INDX);
/* Accessing a local module */
- if (structuralModel.getProject().getName().equals(projectName)) {
+ if (getProject().getName().equals(projectName)) {
return getComponent();
}
return getDependentModuleCore(aModuleURI).getComponent();
@@ -821,7 +847,7 @@
return true;
try {
- String localProjectName = structuralModel.getProject().getName();
+ String localProjectName = getProject().getName();
if(ModuleURIUtil.ensureValidFullyQualifiedModuleURI(dependentHandle, false)) {
String dependentProjectName = aDependentModule.getHandle().segment(ModuleURIUtil.ModuleURI.PROJECT_NAME_INDX);
return localProjectName.equals(dependentProjectName);
@@ -885,4 +911,9 @@
public static URI createComponentURI(IProject aContainingProject, String aComponentName) {
return URI.createURI(PlatformURLModuleConnection.MODULE_PROTOCOL + IPath.SEPARATOR + PlatformURLModuleConnection.RESOURCE_MODULE + aContainingProject.getName() + IPath.SEPARATOR + aComponentName);
}
+
+
+ protected IProject getProject() {
+ return aProject;
+ }
}