2009-10-01 18:46:46 +02:00
|
|
|
/*
|
2010-02-04 06:57:00 +01:00
|
|
|
* This file is part of NavalPlan
|
2009-10-01 18:46:46 +02:00
|
|
|
*
|
2010-07-19 09:36:44 +02:00
|
|
|
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
|
2010-07-19 09:47:20 +02:00
|
|
|
* Desenvolvemento Tecnolóxico de Galicia
|
2010-12-10 19:50:21 +01:00
|
|
|
* Copyright (C) 2011 Igalia S.L.
|
|
|
|
|
*
|
2009-10-01 18:46:46 +02:00
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-04-14 17:51:03 +02:00
|
|
|
package org.zkoss.ganttz;
|
|
|
|
|
|
|
|
|
|
import java.beans.PropertyChangeEvent;
|
|
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
|
|
2009-11-09 00:14:49 +01:00
|
|
|
import org.apache.commons.lang.Validate;
|
2009-07-20 18:00:11 +02:00
|
|
|
import org.zkoss.ganttz.data.Dependency;
|
2009-07-20 15:37:47 +02:00
|
|
|
import org.zkoss.ganttz.data.DependencyType;
|
2010-10-07 00:14:26 +02:00
|
|
|
import org.zkoss.ganttz.data.GanttDate;
|
2009-07-22 18:43:32 +02:00
|
|
|
import org.zkoss.ganttz.data.Task;
|
2009-11-09 00:40:46 +01:00
|
|
|
import org.zkoss.ganttz.data.constraint.Constraint;
|
|
|
|
|
import org.zkoss.ganttz.data.constraint.Constraint.IConstraintViolationListener;
|
2009-04-14 17:51:03 +02:00
|
|
|
import org.zkoss.zk.au.out.AuInvoke;
|
|
|
|
|
import org.zkoss.zk.ui.ext.AfterCompose;
|
|
|
|
|
import org.zkoss.zul.impl.XulElement;
|
|
|
|
|
|
|
|
|
|
/**
|
2009-08-13 17:23:12 +02:00
|
|
|
*
|
2009-08-12 12:29:37 +02:00
|
|
|
* @author Francisco Javier Moran Rúa <jmoran@igalia.com>
|
|
|
|
|
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
|
2009-04-14 17:51:03 +02:00
|
|
|
*/
|
2009-07-20 18:00:11 +02:00
|
|
|
public class DependencyComponent extends XulElement implements AfterCompose {
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2009-07-20 18:00:11 +02:00
|
|
|
private TaskComponent source;
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2009-07-20 18:00:11 +02:00
|
|
|
private TaskComponent destination;
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2009-08-18 12:26:56 +02:00
|
|
|
private DependencyType type;
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2009-11-09 00:14:49 +01:00
|
|
|
private Dependency dependency;
|
|
|
|
|
|
2010-10-07 00:14:26 +02:00
|
|
|
private IConstraintViolationListener<GanttDate> violationListener;
|
2009-11-09 00:40:46 +01:00
|
|
|
|
2009-08-18 12:26:56 +02:00
|
|
|
public DependencyComponent(TaskComponent source, TaskComponent destination,
|
2009-11-09 00:14:49 +01:00
|
|
|
Dependency dependency) {
|
|
|
|
|
Validate.notNull(dependency);
|
|
|
|
|
Validate.notNull(source);
|
|
|
|
|
Validate.notNull(destination);
|
|
|
|
|
Validate.isTrue(source.getTask() == dependency.getSource());
|
|
|
|
|
Validate.isTrue(destination.getTask() == dependency.getDestination());
|
|
|
|
|
this.type = dependency.getType();
|
2009-04-14 17:51:03 +02:00
|
|
|
this.source = source;
|
|
|
|
|
this.destination = destination;
|
2009-11-09 00:14:49 +01:00
|
|
|
this.dependency = dependency;
|
2010-10-07 00:14:26 +02:00
|
|
|
violationListener = new IConstraintViolationListener<GanttDate>() {
|
2009-11-09 00:40:46 +01:00
|
|
|
|
|
|
|
|
@Override
|
2010-10-07 00:14:26 +02:00
|
|
|
public void constraintViolated(Constraint<GanttDate> constraint,
|
|
|
|
|
GanttDate value) {
|
2010-12-10 19:50:21 +01:00
|
|
|
response("constraintViolated", new AuInvoke(
|
|
|
|
|
DependencyComponent.this, "setCSSClass",
|
|
|
|
|
"violated-dependency"));
|
2009-11-09 00:40:46 +01:00
|
|
|
}
|
2010-12-15 12:56:51 +01:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void constraintSatisfied(Constraint<GanttDate> constraint,
|
|
|
|
|
GanttDate value) {
|
2010-12-10 19:50:21 +01:00
|
|
|
response("constraintViolated", new AuInvoke(
|
|
|
|
|
DependencyComponent.this, "setCSSClass", "dependency"));
|
2010-12-15 12:56:51 +01:00
|
|
|
}
|
2009-11-09 00:40:46 +01:00
|
|
|
};
|
|
|
|
|
this.dependency.addConstraintViolationListener(violationListener);
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterCompose() {
|
|
|
|
|
PropertyChangeListener listener = new PropertyChangeListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
|
|
redrawDependency();
|
|
|
|
|
}
|
|
|
|
|
};
|
2009-07-20 18:00:11 +02:00
|
|
|
this.source.getTask().addFundamentalPropertiesChangeListener(listener);
|
|
|
|
|
this.destination.getTask().addFundamentalPropertiesChangeListener(listener);
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the idTaskOrig
|
|
|
|
|
*/
|
|
|
|
|
public String getIdTaskOrig() {
|
|
|
|
|
return source.getUuid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setIdTaskOrig(String idTaskOrig) {
|
2009-07-20 18:00:11 +02:00
|
|
|
this.source = findTaskComponent(idTaskOrig);
|
2009-04-14 17:51:03 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-20 18:00:11 +02:00
|
|
|
private TaskComponent findTaskComponent(String idTaskOrig) {
|
|
|
|
|
return (TaskComponent) getFellow(idTaskOrig);
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the idTaskEnd
|
|
|
|
|
*/
|
|
|
|
|
public String getIdTaskEnd() {
|
|
|
|
|
return destination.getUuid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setIdTaskEnd(String idTaskEnd) {
|
2009-07-20 18:00:11 +02:00
|
|
|
this.destination = findTaskComponent(idTaskEnd);
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void zoomChanged() {
|
|
|
|
|
redrawDependency();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void redrawDependency() {
|
|
|
|
|
response("zoomChanged", new AuInvoke(this, "draw"));
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-22 18:43:32 +02:00
|
|
|
public boolean contains(Task task) {
|
|
|
|
|
Task sourceTask = getSource().getTask();
|
|
|
|
|
Task destinationTask = getDestination().getTask();
|
|
|
|
|
return task.equals(sourceTask) || task.equals(destinationTask);
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
2009-04-27 15:57:33 +02:00
|
|
|
|
2009-07-20 18:00:11 +02:00
|
|
|
public TaskComponent getSource() {
|
2009-04-27 15:57:33 +02:00
|
|
|
return source;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-20 18:00:11 +02:00
|
|
|
public TaskComponent getDestination() {
|
2009-04-27 15:57:33 +02:00
|
|
|
return destination;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-09 00:14:49 +01:00
|
|
|
public Dependency getDependency() {
|
|
|
|
|
return dependency;
|
2009-04-27 15:57:33 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-12 12:29:39 +02:00
|
|
|
public DependencyType getDependencyType() {
|
2009-08-18 12:26:56 +02:00
|
|
|
return type;
|
2009-08-12 12:29:37 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-18 12:26:56 +02:00
|
|
|
public boolean hasSameSourceAndDestination(Dependency dependency) {
|
|
|
|
|
Task sourceTask = source.getTask();
|
|
|
|
|
Task destinationTask = destination.getTask();
|
|
|
|
|
return sourceTask.equals(dependency.getSource())
|
|
|
|
|
&& destinationTask.equals(dependency.getDestination());
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|