ItEr33S14CUCreacionUnidadesPlanificacion: When a dependency is violated, it's notified to the component

This commit is contained in:
Óscar González Fernández 2009-11-09 00:40:46 +01:00
parent 46a901746a
commit 94be25b58c
3 changed files with 103 additions and 5 deletions

View file

@ -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<Date> 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<Date>() {
@Override
public void constraintViolated(Constraint<Date> constraint,
Date value) {
// TODO mark graphically dependency as violated
}
};
this.dependency.addConstraintViolationListener(violationListener);
}
@Override

View file

@ -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<Constraint<Date>> 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<Date> 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<Constraint<Date>> toConstraints(Calculation calculation) {
return violationsNotificator.withListener(calculation.toConstraints(
source, type));
}
public void addConstraintViolationListener(
IConstraintViolationListener<Date> listener) {
violationsNotificator.addConstraintViolationListener(listener);
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(source).append(destination).append(

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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 <ogonzalez@igalia.com>
*
*/
public class ConstraintViolationNotificator<T> {
public static <T> ConstraintViolationNotificator<T> create() {
return new ConstraintViolationNotificator<T>();
}
private WeakReferencedListeners<IConstraintViolationListener<T>> constraintViolationListeners = WeakReferencedListeners
.create();
private IConstraintViolationListener<T> bridge = new IConstraintViolationListener<T>() {
@Override
public void constraintViolated(Constraint<T> constraint, T value) {
fireConstraintViolated(constraint, value);
}
};
public List<Constraint<T>> withListener(List<Constraint<T>> constraints) {
for (Constraint<T> each : constraints) {
each.addConstraintViolationListener(bridge);
}
return constraints;
}
private void fireConstraintViolated(final Constraint<T> constraint,
final T value) {
constraintViolationListeners
.fireEvent(new IListenerNotification<IConstraintViolationListener<T>>() {
@Override
public void doNotify(
IConstraintViolationListener<T> listener) {
listener.constraintViolated(constraint, value);
}
});
}
public void addConstraintViolationListener(
IConstraintViolationListener<T> listener) {
constraintViolationListeners.addListener(listener);
}
}