This is an automated email from the git hooks/post-receive script. New commit to branch feature/7929_editeur_de_zone in repository tutti. See http://git.codelutin.com/tutti.git commit 48ded36fc3c1b6808e5e1a49090924f47fd6ed9d Author: Kevin Morin <morin@codelutin.com> Date: Wed Jan 27 18:38:05 2016 +0100 noeuds + renderer + modeles d'arbre + modele de zone (refs #7929) --- .../content/protocol/zones/StratasTreeModel.java | 123 +++++++++++++++++++ .../protocol/zones/ZoneEditorTreeCellRenderer.java | 45 +++++++ .../swing/content/protocol/zones/ZoneUIModel.java | 136 +++++++++++++++++++++ .../content/protocol/zones/ZonesTreeModel.java | 98 +++++++++++++++ .../content/protocol/zones/nodes/StrataNode.java | 20 +++ .../protocol/zones/nodes/SubStrataNode.java | 20 +++ .../content/protocol/zones/nodes/ZoneNode.java | 20 +++ 7 files changed, 462 insertions(+) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/StratasTreeModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/StratasTreeModel.java new file mode 100644 index 0000000..4a17b0f --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/StratasTreeModel.java @@ -0,0 +1,123 @@ +package fr.ifremer.tutti.ui.swing.content.protocol.zones; + +import fr.ifremer.tutti.persistence.entities.protocol.Strata; +import fr.ifremer.tutti.persistence.entities.protocol.SubStrata; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.nodes.StrataNode; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.nodes.SubStrataNode; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashSet; + +/** + * @author Kevin Morin (Code Lutin) + * @since 4.5 + */ +public class StratasTreeModel extends DefaultTreeModel { + + /** Logger. */ + private static final Log log = LogFactory.getLog(StratasTreeModel.class); + + public StratasTreeModel() { + super(new DefaultMutableTreeNode()); + } + + public void removeStratas(Collection<Strata> stratasToRemove) { + + DefaultMutableTreeNode root = (DefaultMutableTreeNode) getRoot(); + + Enumeration rootChildren = root.children(); + Collection<DefaultMutableTreeNode> nodesToRemove = new HashSet<>(); + + while (rootChildren.hasMoreElements()) { + + StrataNode strataNode = (StrataNode) rootChildren.nextElement(); + + if (stratasToRemove.contains(strataNode.getStrata())) { + nodesToRemove.add(strataNode); + } + } + + nodesToRemove.forEach(strataNode ->removeNodeFromParent(strataNode)); + + } + +// public void removeSubStratas(Collection<Strata> subStratasToRemove) { +// +// DefaultMutableTreeNode root = (DefaultMutableTreeNode) getRoot(); +// +// Enumeration rootChildren = root.children(); +// Collection<DefaultMutableTreeNode> nodesToRemove = new HashSet<>(); +// +// while (rootChildren.hasMoreElements()) { +// +// StrataNode strataNode = (StrataNode) rootChildren.nextElement(); +// +// if (stratasToRemove.contains(strataNode.getStrata())) { +// nodesToRemove.add(strataNode); +// } +// } +// +// nodesToRemove.forEach(strataNode ->removeNodeFromParent(strataNode)); +// +// } + + public void addStratas(Collection<Strata> stratasToAdd) { + + DefaultMutableTreeNode root = (DefaultMutableTreeNode) getRoot(); + + stratasToAdd.forEach(strata -> { + + StrataNode strataNode = new StrataNode(strata); + insertNodeInto(strataNode, root, root.getChildCount()); + + strata.getSubstrata().forEach(substrata -> { + + if (substrata != null) { + SubStrataNode subStrataNode = new SubStrataNode(substrata); + insertNodeInto(subStrataNode, strataNode, strataNode.getChildCount()); + } + + }); + + }); + + } + + public void addSubStratas(Collection<SubStrata> subStratas, Strata strata) { + + StrataNode strataNode = findStrataNode(strata); + + subStratas.forEach(substrata -> { + + if (substrata != null) { + SubStrataNode subStrataNode = new SubStrataNode(substrata); + insertNodeInto(subStrataNode, strataNode, strataNode.getChildCount()); + } + + }); + + } + + protected StrataNode findStrataNode(Strata strata) { + + DefaultMutableTreeNode root = (DefaultMutableTreeNode) getRoot(); + + Enumeration rootChildren = root.children(); + + StrataNode strataNode = null; + + while (strataNode == null && rootChildren.hasMoreElements()) { + StrataNode nextNode = (StrataNode) rootChildren.nextElement(); + if (strata.equals(nextNode.getStrata())) { + strataNode = nextNode; + } + } + + return strataNode; + } +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorTreeCellRenderer.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorTreeCellRenderer.java new file mode 100644 index 0000000..a319e9e --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorTreeCellRenderer.java @@ -0,0 +1,45 @@ +package fr.ifremer.tutti.ui.swing.content.protocol.zones; + +import fr.ifremer.tutti.persistence.entities.protocol.Strata; +import fr.ifremer.tutti.persistence.entities.protocol.SubStrata; +import fr.ifremer.tutti.persistence.entities.protocol.Zone; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.nodes.StrataNode; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.nodes.SubStrataNode; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.nodes.ZoneNode; + +import javax.swing.JTree; +import javax.swing.tree.DefaultTreeCellRenderer; +import java.awt.Component; + +/** + * @author Kevin Morin (Code Lutin) + * @since 4.5 + */ +public class ZoneEditorTreeCellRenderer extends DefaultTreeCellRenderer { + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { + + super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); + + String text = ""; + + if (value instanceof StrataNode) { + Strata strata = ((StrataNode) value).getStrata(); + text = strata.getLocation().getLabel(); + + } else if (value instanceof SubStrataNode) { + SubStrata substrata = ((SubStrataNode) value).getSubstrata(); + text = substrata.getLocation().getLabel(); + + } else if (value instanceof ZoneNode) { + Zone zone = ((ZoneNode) value).getZone(); + text = zone.getLabel(); + } + + setText(text); + + return this; + } + +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneUIModel.java new file mode 100644 index 0000000..e01af7e --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneUIModel.java @@ -0,0 +1,136 @@ +package fr.ifremer.tutti.ui.swing.content.protocol.zones; + +import fr.ifremer.tutti.persistence.entities.protocol.Strata; +import fr.ifremer.tutti.persistence.entities.protocol.Zone; +import fr.ifremer.tutti.persistence.entities.protocol.Zones; +import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; + +import java.util.Collection; +import java.util.HashSet; + +/** + * @author Kevin Morin (Code Lutin) + * @since 4.5 + */ +public class ZoneUIModel extends AbstractTuttiBeanUIModel<Zone, ZoneUIModel> implements Zone { + + protected final Zone delegate = Zones.newZone(); + + protected static Binder<ZoneUIModel, Zone> toBeanBinder = BinderFactory.newBinder(ZoneUIModel.class, Zone.class); + + protected static Binder<Zone, ZoneUIModel> fromBeanBinder = BinderFactory.newBinder(Zone.class, ZoneUIModel.class); + + public ZoneUIModel() { + super(fromBeanBinder, toBeanBinder); + } + + @Override + public void addAllStrata(Collection<Strata> strata) { + Object oldValue = new HashSet<>(getStrata()); + delegate.addAllStrata(strata); + firePropertyChanged(PROPERTY_STRATA, oldValue, strata); + } + + @Override + public void addStrata(Strata strata) { + Object oldValue = new HashSet<>(getStrata()); + delegate.addStrata(strata); + firePropertyChanged(PROPERTY_STRATA, oldValue, strata); + } + + @Override + public boolean containsAllStrata(Collection<Strata> strata) { + return delegate.containsAllStrata(strata); + } + + @Override + public boolean containsStrata(Strata strata) { + return delegate.containsStrata(strata); + } + + @Override + public String getLabel() { + return delegate.getLabel(); + } + + @Override + public Collection<Strata> getStrata() { + return delegate.getStrata(); + } + + @Override + public Strata getStrata(int index) { + return delegate.getStrata(index); + } + + @Override + public boolean isStrataEmpty() { + return delegate.isStrataEmpty(); + } + + @Override + public boolean removeAllStrata(Collection<Strata> strata) { + Object oldValue = new HashSet<>(getStrata()); + boolean result = delegate.removeAllStrata(strata); + firePropertyChanged(PROPERTY_STRATA, oldValue, strata); + return result; + } + + @Override + public boolean removeStrata(Strata strata) { + Object oldValue = new HashSet<>(getStrata()); + boolean result = delegate.removeStrata(strata); + firePropertyChanged(PROPERTY_STRATA, oldValue, strata); + return result; + } + + @Override + public void setLabel(String label) { + Object oldValue = getLabel(); + delegate.setLabel(label); + firePropertyChanged(PROPERTY_LABEL, oldValue, label); + } + + @Override + public void setStrata(Collection<Strata> strata) { + Object oldValue = new HashSet<>(getStrata()); + delegate.setStrata(strata); + firePropertyChanged(PROPERTY_STRATA, oldValue, strata); + } + + @Override + public int sizeStrata() { + return delegate.sizeStrata(); + } + + @Override + public void setId(String id) { + Object oldValue = getId(); + delegate.setId(id); + firePropertyChanged(PROPERTY_ID, oldValue, id); + } + + @Override + public void setId(Integer id) { + Object oldValue = getId(); + delegate.setId(id); + firePropertyChanged(PROPERTY_ID, oldValue, id); + } + + @Override + public Integer getIdAsInt() { + return delegate.getIdAsInt(); + } + + @Override + public String getId() { + return delegate.getId(); + } + + @Override + protected Zone newEntity() { + return Zones.newZone(); + } +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZonesTreeModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZonesTreeModel.java new file mode 100644 index 0000000..b2d3e19 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZonesTreeModel.java @@ -0,0 +1,98 @@ +package fr.ifremer.tutti.ui.swing.content.protocol.zones; + +import com.google.common.base.Preconditions; +import fr.ifremer.tutti.persistence.entities.protocol.Strata; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.nodes.StrataNode; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.nodes.ZoneNode; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashSet; + +/** + * @author Kevin Morin (Code Lutin) + * @since 4.5 + */ +public class ZonesTreeModel extends DefaultTreeModel { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ZonesTreeModel.class); + + public ZonesTreeModel() { + super(new DefaultMutableTreeNode()); + } + + public void removeZones(Collection<ZoneUIModel> zonesToRemove) { + + DefaultMutableTreeNode root = (DefaultMutableTreeNode) getRoot(); + + Enumeration rootChildren = root.children(); + Collection<DefaultMutableTreeNode> nodesToRemove = new HashSet<>(); + + while (rootChildren.hasMoreElements()) { + + ZoneNode zoneNode = (ZoneNode) rootChildren.nextElement(); + + if (zonesToRemove.contains(zoneNode.getZone())) { + nodesToRemove.add(zoneNode); + } + } + + nodesToRemove.forEach(zoneNode ->removeNodeFromParent(zoneNode)); + } + + public void addZones(Collection<ZoneUIModel> zonesToAdd) { + + DefaultMutableTreeNode root = (DefaultMutableTreeNode) getRoot(); + + zonesToAdd.forEach(zone -> { + + ZoneNode zoneNode = new ZoneNode(zone); + insertNodeInto(zoneNode, root, root.getChildCount()); + + }); + } + + public void setStratas(ZoneUIModel zone, Collection<Strata> stratas) { + + DefaultMutableTreeNode root = (DefaultMutableTreeNode) getRoot(); + + Enumeration rootChildren = root.children(); + + ZoneNode zoneNode = null; + + while (zoneNode == null && rootChildren.hasMoreElements()) { + ZoneNode nextNode = (ZoneNode) rootChildren.nextElement(); + if (zone.equals(nextNode.getZone())) { + zoneNode = nextNode; + } + } + + Preconditions.checkNotNull(zoneNode); + + for (Strata strata : stratas) { + + StrataNode strataNode = new StrataNode(strata); + + if (log.isInfoEnabled()) { + log.info("add strata " + strata.getLocation().getLabel()); + } + + insertNodeInto(strataNode, zoneNode, zoneNode.getChildCount()); + +// newAvailableStratas.get(strata).forEach(substrata -> { +// +// if (substrata != null) { +// SubStrataNode subStrataNode = new SubStrataNode(substrata); +// insertNodeInto(subStrataNode, strataNode, strataNode.getChildCount()); +// } +// +// }); + + } + } +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/nodes/StrataNode.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/nodes/StrataNode.java new file mode 100644 index 0000000..87255bc --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/nodes/StrataNode.java @@ -0,0 +1,20 @@ +package fr.ifremer.tutti.ui.swing.content.protocol.zones.nodes; + +import fr.ifremer.tutti.persistence.entities.protocol.Strata; + +import javax.swing.tree.DefaultMutableTreeNode; + +/** + * @author Kevin Morin (Code Lutin) + * @since 4.5 + */ +public class StrataNode extends DefaultMutableTreeNode { + + public StrataNode(Strata strata) { + super(strata, true); + } + + public Strata getStrata() { + return (Strata) userObject; + } +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/nodes/SubStrataNode.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/nodes/SubStrataNode.java new file mode 100644 index 0000000..0cc705d --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/nodes/SubStrataNode.java @@ -0,0 +1,20 @@ +package fr.ifremer.tutti.ui.swing.content.protocol.zones.nodes; + +import fr.ifremer.tutti.persistence.entities.protocol.SubStrata; + +import javax.swing.tree.DefaultMutableTreeNode; + +/** + * @author Kevin Morin (Code Lutin) + * @since 4.5 + */ +public class SubStrataNode extends DefaultMutableTreeNode { + + public SubStrataNode(SubStrata substrata) { + super(substrata, false); + } + + public SubStrata getSubstrata() { + return (SubStrata) userObject; + } +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/nodes/ZoneNode.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/nodes/ZoneNode.java new file mode 100644 index 0000000..8406978 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/nodes/ZoneNode.java @@ -0,0 +1,20 @@ +package fr.ifremer.tutti.ui.swing.content.protocol.zones.nodes; + +import fr.ifremer.tutti.ui.swing.content.protocol.zones.ZoneUIModel; + +import javax.swing.tree.DefaultMutableTreeNode; + +/** + * @author Kevin Morin (Code Lutin) + * @since 4.5 + */ +public class ZoneNode extends DefaultMutableTreeNode { + + public ZoneNode(ZoneUIModel zone) { + super(zone, true); + } + + public ZoneUIModel getZone() { + return (ZoneUIModel) userObject; + } +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.