Author: scabanovich
Date: 2007-08-14 12:06:15 -0400 (Tue, 14 Aug 2007)
New Revision: 3127
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/icons/impl/XModelObjectIcon.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/impl/SharableElementImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/Watcher.java
Log:
EXIN-160
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java 2007-08-14
15:34:05 UTC (rev 3126)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java 2007-08-14
16:06:15 UTC (rev 3127)
@@ -254,7 +254,7 @@
public void setAdoptManager(String adoptclass) {
try {
if(adoptclass != null && adoptclass.length() > 0) {
- adopt =
(XAdoptManager)ModelFeatureFactory.getInstance().createFeatureInstance(adoptclass);
+ adopt = new XAdoptWrapper(adoptclass, this);
}
} catch (Exception e) {
ModelPlugin.getPluginLog().logError("XModelEntityImpl:setAdoptManager:" +
e.getMessage());
@@ -428,3 +428,36 @@
}
}
+class XAdoptWrapper implements XAdoptManager {
+ String adoptclass;
+ XModelEntityImpl entity;
+
+ public XAdoptWrapper(String adoptclass, XModelEntityImpl entity) {
+ this.adoptclass = adoptclass;
+ this.entity = entity;
+ }
+
+ public void adopt(XModelObject target, XModelObject object, Properties p) {
+ validate();
+ if(entity.adopt != null) {
+ entity.adopt.adopt(target, object, p);
+ }
+ }
+
+ public boolean isAdoptable(XModelObject target, XModelObject object) {
+ validate();
+ return entity.adopt != null && entity.adopt.isAdoptable(target, object);
+ }
+
+ void validate() {
+ try {
+ if(adoptclass != null && adoptclass.length() > 0) {
+ entity.adopt =
(XAdoptManager)ModelFeatureFactory.getInstance().createFeatureInstance(adoptclass);
+ }
+ } catch (Exception e) {
+ ModelPlugin.getPluginLog().logError("XModelEntityImpl:setAdoptManager:" +
e.getMessage());
+ entity.adopt = null;
+ }
+ }
+
+}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/icons/impl/XModelObjectIcon.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/icons/impl/XModelObjectIcon.java 2007-08-14
15:34:05 UTC (rev 3126)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/icons/impl/XModelObjectIcon.java 2007-08-14
16:06:15 UTC (rev 3127)
@@ -18,7 +18,7 @@
public class XModelObjectIcon {
private static Hashtable<String,Image> cacheEclipse = new
Hashtable<String,Image>();
- private static Hashtable<String,ImageComponent> components = null;
+ static Hashtable<String,ImageComponent> components = null;
private static synchronized void load(XModelObject object) {
if(components != null || object == null) return;
@@ -29,12 +29,7 @@
String[] keys = mapping.getKeys();
for (int i = 0; i < keys.length; i++) {
String v = mapping.getValue(keys[i]);
- try {
- ImageComponent c =
(ImageComponent)ModelFeatureFactory.getInstance().createFeatureInstance(v);
- components.put(keys[i], c);
- } catch (Exception e) {
- ///XStudioPlugin.getDefault().getLog().log(new Status(Status.ERROR,
XStudioPlugin.PLUGIN_ID, Status.OK, "Cannot load icon " + keys[i] + "
" + v,e));
- }
+ components.put(keys[i], new ImageComponentWrapper(keys[i], v));
}
}
@@ -105,3 +100,41 @@
}
}
+
+class ImageComponentWrapper implements ImageComponent {
+ String key;
+ String classname;
+ ImageComponent imageComponent;
+
+ ImageComponentWrapper(String key, String classname) {
+ this.key = key;
+ this.classname = classname;
+ }
+
+ public int getHash(XModelObject obj) {
+ validate();
+ if(imageComponent == null) return 0;
+ return imageComponent.getHash(obj);
+ }
+
+ public Image getImage(XModelObject obj) {
+ validate();
+ if(imageComponent == null) return null;
+ return imageComponent.getImage(obj);
+ }
+
+ void validate() {
+ try {
+ ImageComponent c =
(ImageComponent)ModelFeatureFactory.getInstance().createFeatureInstance(classname);
+ if(c == null) {
+ XModelObjectIcon.components.remove(key);
+ } else {
+ XModelObjectIcon.components.put(key, c);
+ }
+ } catch (Exception e) {
+ ///XStudioPlugin.getDefault().getLog().log(new Status(Status.ERROR,
XStudioPlugin.PLUGIN_ID, Status.OK, "Cannot load icon " + keys[i] + "
" + v,e));
+ XModelObjectIcon.components.remove(key);
+ }
+ }
+
+}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/impl/SharableElementImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/impl/SharableElementImpl.java 2007-08-14
15:34:05 UTC (rev 3126)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/impl/SharableElementImpl.java 2007-08-14
16:06:15 UTC (rev 3127)
@@ -137,7 +137,7 @@
SharableElementImpl s = (SharableElementImpl)children.get(name);
if(s == null) return;
for (int i = 0; i < LIST.length; i++) {
- XScope sc = getXScope(LIST[i]);
+ XScope sc = s.getXScope(LIST[i]);
if(sc.exists() &&
!XStudioLoaderPeer.instance().isScopeEditable(LIST[i]))
return;
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/Watcher.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/Watcher.java 2007-08-14
15:34:05 UTC (rev 3126)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/Watcher.java 2007-08-14
16:06:15 UTC (rev 3127)
@@ -11,17 +11,19 @@
package org.jboss.tools.common.model.project;
import java.util.*;
+
import org.jboss.tools.common.model.markers.ResourceMarkers;
import org.jboss.tools.common.model.*;
import org.jboss.tools.common.model.event.*;
import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
import org.jboss.tools.common.model.plugin.ModelPlugin;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.model.util.ModelFeatureFactory;
public class Watcher implements XModelTreeListener {
- static String[] CONTRIBUTORS = new String[]{
- "org.jboss.tools.struts.webprj.model.helpers.sync.SyncProjectContext",
- "org.jboss.tools.jsf.web.JSFWatcherContributor",
+ static String[][] CONTRIBUTORS = new String[][]{
+ {"org.jboss.tools.struts.webprj.model.helpers.sync.SyncProjectContext",
"org.jboss.tools.struts.strutsnature"},
+ {"org.jboss.tools.jsf.web.JSFWatcherContributor",
"org.jboss.tools.jsf.jsfnature"}
};
public static Watcher getInstance(XModel model) {
@@ -36,22 +38,9 @@
}
protected XModel model;
- protected IWatcherContributor[] contributors = new IWatcherContributor[0];
+ protected Map<String,IWatcherContributor> contributors = new HashMap<String,
IWatcherContributor>();
private boolean lock = false;
-/*
- Job job;
-
- class WatcherJob extends Job {
- public WatcherJob() {
- super("Watcher" + XModelConstants.getWorkspace(model));
- }
- protected IStatus run(IProgressMonitor monitor) {
- Watcher.this.updateAll();
- return Status.OK_STATUS;
- }
-
- };
-*/
+
class WatcherRunnable implements XJob.XRunnable {
String id = "Watcher - " + XModelConstants.getWorkspace(model);
@@ -64,61 +53,65 @@
}
}
+
private Watcher() {
- loadContributors();
}
- void loadContributors() {
- ArrayList<IWatcherContributor> list = new
ArrayList<IWatcherContributor>();
+ void updateContributors() {
+ if(model == null) return;
for (int i = 0; i < CONTRIBUTORS.length; i++) {
- try {
- Object watcher =
ModelFeatureFactory.getInstance().createFeatureInstance(CONTRIBUTORS[i]);
- if(watcher instanceof IWatcherContributor)
- list.add((IWatcherContributor)watcher);
- else
- if(ModelPlugin.isDebugEnabled()) {
- ModelPlugin.getPluginLog().logInfo("Class is not implemented
IWatcherContributor interface!");
- }
- } catch (Exception e) {
- ModelPlugin.getPluginLog().logError(e);
+ String nature = CONTRIBUTORS[i][1];
+ if(EclipseResourceUtil.hasNature(model, nature)) {
+ if(contributors.containsKey(nature)) {
+ continue;
+ } else {
+ try {
+ Object watcher =
ModelFeatureFactory.getInstance().createFeatureInstance(CONTRIBUTORS[i][0]);
+ if(watcher instanceof IWatcherContributor) {
+ IWatcherContributor c = (IWatcherContributor)watcher;
+ c.init(model);
+ contributors.put(nature, c);
+ } else
+ if(ModelPlugin.isDebugEnabled()) {
+ ModelPlugin.getPluginLog().logInfo("Class is not implemented
IWatcherContributor interface!");
+ }
+ } catch (Exception e) {
+ ModelPlugin.getPluginLog().logError(e);
+ }
+ }
+ } else {
+ contributors.remove(nature);
}
}
- contributors = list.toArray(new IWatcherContributor[0]);
}
public void setModel(XModel model) {
this.model = model;
- for (int i = 0; i < contributors.length; i++) {
- contributors[i].init(model);
- }
-// job = new WatcherJob();
}
public void forceUpdate() {
if(model.getProperties().getProperty(IModelNature.ECLIPSE_PROJECT) == null) return;
XJob.addRunnable(new WatcherRunnable());
-// if(job.getState() == Job.NONE) {
-// job.schedule(600);
-// };
}
private void updateAll() {
if(lock) return;
lock();
+ updateContributors();
try {
String err = null;
- for (int i = 0; i < contributors.length; i++) {
- if(!contributors[i].isActive()) continue;
- contributors[i].update();
+ for (IWatcherContributor c : contributors.values()) {
+ if(!c.isActive()) continue;
+ c.update();
if(err == null) {
- err = contributors[i].getError();
+ err = c.getError();
}
}
setError(err);
setCorrect(err == null);
- for (int i = 0; i < contributors.length; i++) {
- if(!contributors[i].isActive()) continue;
- contributors[i].updateProject();
+ for (IWatcherContributor c : contributors.values()) {
+ if(!c.isActive()) continue;
+ c.updateProject();
}
} finally {
unlock();