Index: src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java =================================================================== --- src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java (revision 0) +++ src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java (revision 0) @@ -0,0 +1,24 @@ +package org.jboss.tools.common.model.filesystems.impl; + +import java.util.HashMap; +import java.util.Map; + +public class JarAccessFactory { + + static Map jars = new HashMap(); + + public static JarAccess getJarAccess(String location, JarSystemImpl context) { + JarAccess jar = jars.get(location); + if(jar == null) { + jar = new JarAccess(); + jar.setMain(context); + jar.setLocation(location); + jars.put(location, jar); + } + if(context != jar.getMain()) { + jar.addSlave(context); + } + return jar; + } + +} Index: src/org/jboss/tools/common/model/filesystems/impl/JarSystemImpl.java =================================================================== --- src/org/jboss/tools/common/model/filesystems/impl/JarSystemImpl.java (revision 22369) +++ src/org/jboss/tools/common/model/filesystems/impl/JarSystemImpl.java (working copy) @@ -10,6 +10,8 @@ ******************************************************************************/ package org.jboss.tools.common.model.filesystems.impl; +import java.util.Set; + import org.jboss.tools.common.model.*; import org.jboss.tools.common.model.util.*; @@ -15,7 +17,7 @@ public class JarSystemImpl extends JarFolderImpl implements org.jboss.tools.common.model.filesystems.FileSystem { private static final long serialVersionUID = 7958999759019059243L; - protected JarAccess jar = new JarAccess(); + protected JarAccess jar = null; public JarSystemImpl() {} @@ -28,6 +30,9 @@ } protected JarAccess getJarAccess() { + if(jar == null) { + jar = JarAccessFactory.getJarAccess(getLocation(), this); + } return jar; } @@ -38,9 +43,16 @@ protected String getAbsolutePath() { return ""; //$NON-NLS-1$ } + + boolean loaded2 = false; protected void loadChildren() { - if(jar.isLoaded()) return; +// if(jar.isLoaded()) return; + + if(this != getJarAccess().getMain()) return; + if(loaded2) return; + loaded2 = true; + synchronized (this) { jar.setLocation(getLocation()); super.loadChildren(); @@ -47,6 +59,16 @@ } } + public XModelObject[] getChildren() { + JarSystemImpl main = getJarAccess().getMain(); + return (main == this) ? super.getChildren() : main.getChildren(); + } + + public XModelObject getChildByPathPart(String pathpart) { + JarSystemImpl main = getJarAccess().getMain(); + return (main == this) ? super.getChildByPathPart(pathpart) : main.getChildByPathPart(pathpart); + } + public String getPathPart() { return name(); } @@ -56,7 +78,12 @@ } public String getTempLocation() { - if(!jar.isLoaded()) loadChildren(); + JarSystemImpl main = getJarAccess().getMain(); + if(main != this && main != null) { + main.getChildren(); + } else if(!jar.isLoaded()) { + loadChildren(); + } String s = jar.getTempLocation(); return (s == null) ? get(XModelObjectConstants.ATTR_NAME_LOCATION) : s; } @@ -62,10 +89,12 @@ } public LFileObject getFileObject(String relpath) { - return jar.getFileObject(name(), relpath); + return getJarAccess().getFileObject(name(), relpath); } public boolean update() { + if(getJarAccess().getMain() != this) return true; + if(jar.isModified()) { if(jar.isLoaded()) { XModelObject[] cs = getChildren(); @@ -72,9 +101,10 @@ for (int i = 0; i < cs.length; i++) removeChild_0(cs[i]); jar.invalidate(); } - loaded = false; - fire = true; - fireStructureChanged(3, null); + jarUpdated(); + + JarSystemImpl[] ss = getJarAccess().getSlaves(); + for (JarSystemImpl s: ss) s.jarUpdated(); } return true; } @@ -79,6 +109,13 @@ return true; } + public void jarUpdated() { + loaded = false; + loaded2 = false; + fire = true; + fireStructureChanged(3, null); + } + public String getPresentationString() { String location = getLocation(); if(location != null) { Index: src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java =================================================================== --- src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java (revision 22369) +++ src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java (working copy) @@ -18,6 +18,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.zip.ZipEntry; @@ -23,8 +24,10 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import org.eclipse.core.resources.IProject; import org.jboss.tools.common.model.XModelObjectConstants; import org.jboss.tools.common.model.plugin.ModelPlugin; +import org.jboss.tools.common.model.util.EclipseResourceUtil; import org.jboss.tools.common.util.FileUtil; public class JarAccess { @@ -274,6 +277,52 @@ return templocation; } + JarSystemImpl main = null; + Set slaves = new HashSet(); + + public JarSystemImpl getMain() { + IProject p = EclipseResourceUtil.getProject(main); + if(p == null || !p.isAccessible() || main.getParent() == null) { + main = null; + synchronized(slaves) { + Iterator it = slaves.iterator(); + while(it.hasNext()) { + JarSystemImpl s = it.next(); + p = EclipseResourceUtil.getProject(s); + if(p == null || !p.isAccessible() || s.getParent() == null) { + it.remove(); + } else if(main == null) { + main = s; + it.remove(); + } + } + } + if(main != null) main.jarUpdated(); + JarSystemImpl[] ss = getSlaves(); + for (JarSystemImpl s: ss) s.jarUpdated(); + } + return main; + } + + public void setMain(JarSystemImpl main) { + this.main = main; + } + + public JarSystemImpl[] getSlaves() { + synchronized(slaves) { + return slaves.toArray(new JarSystemImpl[slaves.size()]); + } + } + + public void addSlave(JarSystemImpl s) { + synchronized(slaves) { + slaves.add(s); + } + } + + public boolean isSlave(JarSystemImpl s) { + return slaves.contains(s); + } } class LFileObjectJarImpl implements LFileObject {