From 94be25b58c2ba12dfeaf56627a4ee7d68c77cacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Mon, 9 Nov 2009 00:40:46 +0100 Subject: [PATCH] ItEr33S14CUCreacionUnidadesPlanificacion: When a dependency is violated, it's notified to the component --- .../org/zkoss/ganttz/DependencyComponent.java | 14 ++++ .../org/zkoss/ganttz/data/Dependency.java | 20 +++-- .../util/ConstraintViolationNotificator.java | 74 +++++++++++++++++++ 3 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 ganttzk/src/main/java/org/zkoss/ganttz/util/ConstraintViolationNotificator.java diff --git a/ganttzk/src/main/java/org/zkoss/ganttz/DependencyComponent.java b/ganttzk/src/main/java/org/zkoss/ganttz/DependencyComponent.java index 53db335ca..17f1ac77a 100644 --- a/ganttzk/src/main/java/org/zkoss/ganttz/DependencyComponent.java +++ b/ganttzk/src/main/java/org/zkoss/ganttz/DependencyComponent.java @@ -22,11 +22,14 @@ package org.zkoss.ganttz; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.Date; import org.apache.commons.lang.Validate; import org.zkoss.ganttz.data.Dependency; import org.zkoss.ganttz.data.DependencyType; import org.zkoss.ganttz.data.Task; +import org.zkoss.ganttz.data.constraint.Constraint; +import org.zkoss.ganttz.data.constraint.Constraint.IConstraintViolationListener; import org.zkoss.zk.au.out.AuInvoke; import org.zkoss.zk.ui.ext.AfterCompose; import org.zkoss.zul.impl.XulElement; @@ -46,6 +49,8 @@ public class DependencyComponent extends XulElement implements AfterCompose { private Dependency dependency; + private IConstraintViolationListener violationListener; + public DependencyComponent(TaskComponent source, TaskComponent destination, Dependency dependency) { Validate.notNull(dependency); @@ -57,6 +62,15 @@ public class DependencyComponent extends XulElement implements AfterCompose { this.source = source; this.destination = destination; this.dependency = dependency; + violationListener = new IConstraintViolationListener() { + + @Override + public void constraintViolated(Constraint constraint, + Date value) { + // TODO mark graphically dependency as violated + } + }; + this.dependency.addConstraintViolationListener(violationListener); } @Override diff --git a/ganttzk/src/main/java/org/zkoss/ganttz/data/Dependency.java b/ganttzk/src/main/java/org/zkoss/ganttz/data/Dependency.java index 64fae0afb..8dd3d5e2c 100644 --- a/ganttzk/src/main/java/org/zkoss/ganttz/data/Dependency.java +++ b/ganttzk/src/main/java/org/zkoss/ganttz/data/Dependency.java @@ -28,6 +28,8 @@ import java.util.List; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.zkoss.ganttz.data.constraint.Constraint; +import org.zkoss.ganttz.data.constraint.Constraint.IConstraintViolationListener; +import org.zkoss.ganttz.util.ConstraintViolationNotificator; /** * This class represents a dependency. Contains the source and the destination. @@ -75,11 +77,6 @@ public class Dependency { return result; } - private List> toConstraints( - Calculation calculation) { - return calculation.toConstraints(source, type); - } - private final Task source; private final Task destination; @@ -88,6 +85,9 @@ public class Dependency { private final boolean visible; + private ConstraintViolationNotificator violationsNotificator = ConstraintViolationNotificator + .create(); + public Dependency(Task source, Task destination, DependencyType type, boolean visible) { if (source == null) { @@ -110,6 +110,16 @@ public class Dependency { this(source, destination, type, true); } + private List> toConstraints(Calculation calculation) { + return violationsNotificator.withListener(calculation.toConstraints( + source, type)); + } + + public void addConstraintViolationListener( + IConstraintViolationListener listener) { + violationsNotificator.addConstraintViolationListener(listener); + } + @Override public int hashCode() { return new HashCodeBuilder().append(source).append(destination).append( diff --git a/ganttzk/src/main/java/org/zkoss/ganttz/util/ConstraintViolationNotificator.java b/ganttzk/src/main/java/org/zkoss/ganttz/util/ConstraintViolationNotificator.java new file mode 100644 index 000000000..6a4dd2a07 --- /dev/null +++ b/ganttzk/src/main/java/org/zkoss/ganttz/util/ConstraintViolationNotificator.java @@ -0,0 +1,74 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.zkoss.ganttz.util; + +import java.util.List; + +import org.zkoss.ganttz.data.constraint.Constraint; +import org.zkoss.ganttz.data.constraint.Constraint.IConstraintViolationListener; +import org.zkoss.ganttz.util.WeakReferencedListeners.IListenerNotification; + +/** + * @author Óscar González Fernández + * + */ +public class ConstraintViolationNotificator { + + public static ConstraintViolationNotificator create() { + return new ConstraintViolationNotificator(); + } + + private WeakReferencedListeners> constraintViolationListeners = WeakReferencedListeners + .create(); + + private IConstraintViolationListener bridge = new IConstraintViolationListener() { + + @Override + public void constraintViolated(Constraint constraint, T value) { + fireConstraintViolated(constraint, value); + } + }; + + public List> withListener(List> constraints) { + for (Constraint each : constraints) { + each.addConstraintViolationListener(bridge); + } + return constraints; + } + + private void fireConstraintViolated(final Constraint constraint, + final T value) { + constraintViolationListeners + .fireEvent(new IListenerNotification>() { + + @Override + public void doNotify( + IConstraintViolationListener listener) { + listener.constraintViolated(constraint, value); + } + }); + } + + public void addConstraintViolationListener( + IConstraintViolationListener listener) { + constraintViolationListeners.addListener(listener); + } + +}