Author: scabanovich
Date: 2008-02-13 09:05:07 -0500 (Wed, 13 Feb 2008)
New Revision: 6299
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponent.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamScope.java
Log:
JBIDE-1778 Incremental modification of seam package structure is implemented
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponent.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponent.java 2008-02-13
14:00:19 UTC (rev 6298)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponent.java 2008-02-13
14:05:07 UTC (rev 6299)
@@ -22,12 +22,15 @@
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamComponentDeclaration;
import org.jboss.tools.seam.core.ISeamComponentMethod;
+import org.jboss.tools.seam.core.ISeamElement;
import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
+import org.jboss.tools.seam.core.ISeamPackage;
import org.jboss.tools.seam.core.ISeamPropertiesDeclaration;
import org.jboss.tools.seam.core.ISeamProperty;
import org.jboss.tools.seam.core.ISeamXmlComponentDeclaration;
import org.jboss.tools.seam.core.ScopeType;
import org.jboss.tools.seam.core.SeamComponentMethodType;
+import org.jboss.tools.seam.core.event.Change;
/**
* @author Viacheslav Kabanovich
@@ -41,6 +44,9 @@
Set<ISeamXmlComponentDeclaration> xmlDeclarations = new
HashSet<ISeamXmlComponentDeclaration>();
Set<ISeamPropertiesDeclaration> propertyDeclarations = new
HashSet<ISeamPropertiesDeclaration>();
+ SeamPackage projectPackage = null;
+ SeamPackage scopePackage = null;
+
public SeamComponent () {
}
@@ -264,5 +270,89 @@
public SeamComponent clone() throws CloneNotSupportedException {
return this;
}
+
+ public void setProjectPackage(SeamPackage p) {
+ projectPackage = p;
+ }
+
+ public void setScopePackage(SeamPackage p) {
+ scopePackage = p;
+ }
+
+ public List<Change> removeFromModel(List<Change> changes) {
+ SeamScope pc = (SeamScope)getParent();
+ if(pc != null) {
+ pc.removeComponent(this);
+ changes = Change.addChange(changes, new Change(pc, null, this, null));
+ }
+ if(scopePackage != null) {
+ removeFrom(scopePackage);
+ changes = Change.addChange(changes, new Change(scopePackage, null, this, null));
+ scopePackage = null;
+ }
+ if(projectPackage != null) {
+ removeFrom(projectPackage);
+ changes = Change.addChange(changes, new Change(projectPackage, null, this, null));
+ projectPackage = null;
+ }
+
+ return changes;
+ }
+
+ public List<Change> revalidate(List<Change> changes) {
+ SeamScope pc = (SeamScope)getParent();
+ SeamScope pn = (SeamScope)getSeamProject().getScope(getScope());
+ if(pc != pn) {
+ if(pc != null) {
+ pc.removeComponent(this);
+ changes = Change.addChange(changes, new Change(pc, null, this, null));
+ }
+ setParent(pn);
+ pn.addComponent(this);
+ changes = Change.addChange(changes, new Change(pn, null, null, this));
+ if(scopePackage != null) {
+ removeFrom(scopePackage);
+ changes = Change.addChange(changes, new Change(scopePackage, null, this, null));
+ scopePackage = null;
+ }
+ }
+ if(scopePackage != null &&
!scopePackage.getQualifiedName().equals(SeamPackageUtil.getPackageName(this))) {
+ removeFrom(scopePackage);
+ changes = Change.addChange(changes, new Change(scopePackage, null, this, null));
+ scopePackage = null;
+ }
+ if(scopePackage == null) {
+ pn.validatePackage(this);
+ }
+ if(projectPackage != null &&
!projectPackage.getQualifiedName().equals(SeamPackageUtil.getPackageName(this))) {
+ removeFrom(projectPackage);
+ changes = Change.addChange(changes, new Change(projectPackage, null, this, null));
+ projectPackage = null;
+ }
+ if(projectPackage == null) {
+ ((SeamProject)getSeamProject()).validatePackage(this);
+ }
+ return changes;
+ }
+
+ private void removeFrom(ISeamPackage p) {
+ p.getComponents().remove(this);
+ while(p != null && p.getComponents().size() + p.getPackages().size() == 0) {
+ ISeamElement o = p.getParent();
+ if(o instanceof ISeamPackage) {
+ ISeamPackage q = (ISeamPackage)o;
+ q.getPackages().remove(p);
+ p = q;
+ } else if(o instanceof SeamScope) {
+ SeamScope s = (SeamScope)o;
+ s.removePackage(p);
+ p = null;
+ } else if(o instanceof SeamProject) {
+ SeamProject project = (SeamProject)o;
+ project.removePackage(p);
+ p = null;
+ }
+ }
+ }
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2008-02-13
14:00:19 UTC (rev 6298)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2008-02-13
14:05:07 UTC (rev 6299)
@@ -202,7 +202,7 @@
* @param scopeType
* @return
*/
- public ISeamScope getScope(ScopeType scopeType) {
+ public SeamScope getScope(ScopeType scopeType) {
return scopesMap.get(scopeType);
}
@@ -210,9 +210,17 @@
*
*/
public Collection<ISeamPackage> getPackages() {
- return packages.values();
+ synchronized(packages) {
+ return packages.values();
+ }
}
+ public void removePackage(ISeamPackage p) {
+ synchronized(packages) {
+ packages.remove(p.getName());
+ }
+ }
+
/**
*
*/
@@ -568,8 +576,6 @@
}
if(!sourcePaths.contains(source)) sourcePaths.add(source);
- revalidateLock++;
-
if(ds.getImports().size() > 0) {
setImports(source.toString(), ds.getImports());
} else {
@@ -578,6 +584,7 @@
Map<Object,ISeamComponentDeclaration> currentComponents =
findComponentDeclarations(source);
+ Set<ISeamComponent> affectedComponents = new HashSet<ISeamComponent>();
List<Change> addedComponents = null;
for (int i = 0; i < components.length; i++) {
SeamComponentDeclaration loaded = (SeamComponentDeclaration)components[i];
@@ -592,6 +599,10 @@
SeamComponent c = getComponent(name);
+ if(c != null) {
+ affectedComponents.add(c);
+ }
+
String oldClassName = c == null ? null : c.getClassName();
if(current != null) {
@@ -610,6 +621,9 @@
loaded = current;
current = null;
c = getComponent(name);
+ if(c != null) {
+ affectedComponents.add(c);
+ }
} else {
if(loaded instanceof ISeamXmlComponentDeclaration) {
ISeamXmlComponentDeclaration xml = (ISeamXmlComponentDeclaration)loaded;
@@ -622,6 +636,7 @@
if(c == null && name != null) {
ScopeType scopeType = loaded.getScope();
c = newComponent(name, scopeType);
+ affectedComponents.add(c);
allComponents.put(name, c);
addVariable(c);
c.addDeclaration(loaded);
@@ -647,14 +662,19 @@
} else if(loaded instanceof ISeamXmlComponentDeclaration) {
ISeamXmlComponentDeclaration xml = (ISeamXmlComponentDeclaration)loaded;
onXMLLoadedDeclaration(c, oldClassName, xml);
- }
+ }
}
+
+ for (ISeamComponent c: affectedComponents) {
+ SeamComponent sc = (SeamComponent)c;
+ addedComponents = sc.revalidate(addedComponents);
+ }
+
fireChanges(addedComponents);
componentDeclarationsRemoved(currentComponents);
- revalidateLock--;
- revalidate();
+// revalidate();
Map<Object, ISeamFactory> currentFactories = findFactoryDeclarations(source);
List<Change> addedFactories = null;
@@ -751,6 +771,7 @@
c.addDeclaration(j);
changes = Change.addChange(changes, new Change(c, null, null, j));
}
+ if(changes != null) c.revalidate(changes);
fireChanges(changes);
}
@@ -762,7 +783,6 @@
if(!sourcePaths.contains(source)) return;
sourcePaths.remove(source);
removeImports(source.toString());
- revalidateLock++;
Iterator<SeamComponent> iterator = allComponents.values().iterator();
while(iterator.hasNext()) {
List<Change> changes = null;
@@ -794,8 +814,7 @@
it.remove();
}
}
- revalidateLock--;
- revalidate();
+// revalidate();
Iterator<ISeamFactory> factories = allFactories.iterator();
while(factories.hasNext()) {
@@ -879,10 +898,7 @@
private List<Change> removeEmptyComponent(SeamComponent c) {
List<Change> changes = null;
ISeamElement p = c.getParent();
- if(p instanceof SeamScope) {
- ((SeamScope)p).removeComponent(c);
- changes = Change.addChange(null, new Change(p, null, c, null));
- }
+ changes = c.removeFromModel(changes);
removeVariable(c);
changes = Change.addChange(changes, new Change(this, null, c, null));
return changes;
@@ -1314,47 +1330,42 @@
/**
*
*/
- int revalidateLock = 0;
-
- /**
- *
- */
void revalidate() {
- if(revalidateLock > 0) return;
- revalidateScopes();
- revalidatePackages();
+// if(revalidateLock > 0) return;
+// revalidateScopes();
+// revalidatePackages();
}
/**
*
*/
- void revalidateScopes() {
- List<Change> changes = null;
- for(SeamComponent c : allComponents.values()) {
- SeamScope pc = (SeamScope)c.getParent();
- SeamScope pn = (SeamScope)getScope(c.getScope());
- if(pc == pn) continue;
- c.setParent(pn);
- if(pc != null) {
- pc.removeComponent(c);
- changes = Change.addChange(changes, new Change(pc, null, c, null));
- }
- pn.addComponent(c);
- changes = Change.addChange(changes, new Change(pn, null, null, c));
- }
- for (int i = 0; i < scopes.length; i++) {
- scopes[i].revalidatePackages();
- }
- fireChanges(changes);
- }
+// void revalidateScopes() {
+// List<Change> changes = null;
+// for(SeamComponent c : allComponents.values()) {
+// SeamScope pc = (SeamScope)c.getParent();
+// SeamScope pn = getScope(c.getScope());
+// if(pc == pn) continue;
+// c.setParent(pn);
+// if(pc != null) {
+// pc.removeComponent(c);
+// changes = Change.addChange(changes, new Change(pc, null, c, null));
+// }
+// pn.addComponent(c);
+// changes = Change.addChange(changes, new Change(pn, null, null, c));
+// }
+// for (int i = 0; i < scopes.length; i++) {
+// scopes[i].revalidatePackages();
+// }
+// fireChanges(changes);
+// }
/**
*
*/
- void revalidatePackages() {
- List<Change> changes = SeamPackageUtil.revalidatePackages(this, allComponents,
getComponents(), packages);
- fireChanges(changes);
- }
+// void revalidatePackages() {
+// List<Change> changes = SeamPackageUtil.revalidatePackages(this, allComponents,
getComponents(), packages);
+// fireChanges(changes);
+// }
/**
*
@@ -1457,4 +1468,9 @@
}
}
+ public void validatePackage(SeamComponent c) {
+ SeamPackage p = (SeamPackage)SeamPackageUtil.findOrCreatePackage(this, packages,
SeamPackageUtil.getPackageName(c));
+ c.setProjectPackage(p);
+ p.getComponents().add(c);
+ }
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamScope.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamScope.java 2008-02-13
14:00:19 UTC (rev 6298)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamScope.java 2008-02-13
14:05:07 UTC (rev 6299)
@@ -42,7 +42,9 @@
}
public Collection<ISeamPackage> getPackages() {
- return packages.values();
+ synchronized(packages) {
+ return packages.values();
+ }
}
public Collection<ISeamPackage> getAllPackages() {
@@ -75,4 +77,15 @@
((SeamProject)getSeamProject()).fireChanges(changes);
}
+ public void validatePackage(SeamComponent c) {
+ SeamPackage p = (SeamPackage)SeamPackageUtil.findOrCreatePackage(this, packages,
SeamPackageUtil.getPackageName(c));
+ c.setScopePackage(p);
+ p.getComponents().add(c);
+ }
+
+ public void removePackage(ISeamPackage p) {
+ synchronized(packages) {
+ packages.remove(p.getName());
+ }
+ }
}