r2684 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/session
Author: kmorin Date: 2013-06-04 12:13:53 +0200 (Tue, 04 Jun 2013) New Revision: 2684 Url: http://nuiton.org/projects/jaxx/repository/revisions/2684 Log: fixes #2716 [SwingSession] enable to replace a component if its path already exists Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/session/SwingSession.java Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/session/SwingSession.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/session/SwingSession.java 2013-05-30 13:38:34 UTC (rev 2683) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/session/SwingSession.java 2013-06-04 10:13:53 UTC (rev 2684) @@ -27,6 +27,8 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; @@ -234,14 +236,43 @@ } public void add(Component c) { - if (registeredComponent.contains(c)) { - log.warn(String.format( - "Component already added %s(%s)", c.getClass(), c.getName())); - } else { - registeredComponent.add(c); - walkThrowComponent("", Collections.singleton(c), - new RestoreStateAction()); + add(c, false); + } + + public void add(final Component c, boolean replace) { + if (c == null) { + return; } + final String cName = getComponentName(c); + Object existingComponent = CollectionUtils.find(registeredComponent, + new Predicate() { + @Override + public boolean evaluate(Object o) { + Component comp = (Component) o; + String compName = getComponentName(comp); + return c.getClass().equals(comp.getClass()) + && cName.equals(compName); + } + }); + + if (existingComponent != null) { + if (replace) { + if (log.isDebugEnabled()) { + log.debug("replacing the component fir path /" + cName); + } + remove((Component) existingComponent); + + } else { + log.warn(String.format( + "Component already added %s(%s)", c.getClass(), c.getName())); + return; + } + } + + registeredComponent.add(c); + walkThrowComponent("", + Collections.singleton(c), + new RestoreStateAction()); } /**
participants (1)
-
kmorin@users.nuiton.org