2009-04-14 17:51:03 +02:00
|
|
|
package org.zkoss.ganttz;
|
|
|
|
|
|
|
|
|
|
import java.beans.PropertyChangeEvent;
|
|
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
|
|
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;
|
2009-07-22 18:43:32 +02:00
|
|
|
import org.zkoss.ganttz.data.Task;
|
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-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-07-20 18:00:11 +02:00
|
|
|
public DependencyComponent() {
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2009-07-05 17:15:30 +02:00
|
|
|
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-20 18:00:11 +02:00
|
|
|
public DependencyComponent(TaskComponent source, TaskComponent destination) {
|
2009-04-14 17:51:03 +02:00
|
|
|
this();
|
|
|
|
|
if (source == null)
|
|
|
|
|
throw new IllegalArgumentException("source cannot be null");
|
|
|
|
|
if (destination == null)
|
|
|
|
|
throw new IllegalArgumentException("destination cannot be null");
|
|
|
|
|
this.source = source;
|
|
|
|
|
this.destination = destination;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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-07-20 18:00:11 +02:00
|
|
|
public Dependency getDependency() {
|
|
|
|
|
return new Dependency(source.getTask(), destination
|
|
|
|
|
.getTask(), DependencyType.END_START);
|
2009-04-27 15:57:33 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-12 12:29:37 +02:00
|
|
|
public String getDependencyType() {
|
|
|
|
|
return this.getDependency().getType().name().toString();
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|