ItEr22S12CUVistaRecursosTempoPorProxectoItEr21S07: Removing access to context from DependencyComponent

This commit is contained in:
Óscar González Fernández 2009-08-18 12:26:56 +02:00
parent 62a6632f7d
commit 3577620603
3 changed files with 20 additions and 12 deletions

View file

@ -5,6 +5,7 @@ import java.beans.PropertyChangeListener;
import org.zkoss.ganttz.data.Dependency;
import org.zkoss.ganttz.data.DependencyType;
import org.zkoss.ganttz.data.GanttDiagramGraph;
import org.zkoss.ganttz.data.Task;
import org.zkoss.zk.au.out.AuInvoke;
import org.zkoss.zk.ui.ext.AfterCompose;
@ -21,15 +22,17 @@ public class DependencyComponent extends XulElement implements AfterCompose {
private TaskComponent destination;
private FunctionalityExposedForExtensions<?> context;
private DependencyType type;
public DependencyComponent(FunctionalityExposedForExtensions<?> context,
TaskComponent source, TaskComponent destination) {
this.context = context;
public DependencyComponent(TaskComponent source, TaskComponent destination,
DependencyType type) {
this.type = type;
if (source == null)
throw new IllegalArgumentException("source cannot be null");
if (destination == null)
throw new IllegalArgumentException("destination cannot be null");
if (type == null)
throw new IllegalArgumentException("type must be not null");
this.source = source;
this.destination = destination;
}
@ -96,13 +99,13 @@ public class DependencyComponent extends XulElement implements AfterCompose {
return destination;
}
public Dependency getDependency() {
return context.getDiagramGraph().getDependencyFrom(source.getTask(),
public Dependency getDependency(GanttDiagramGraph diagramGraph) {
return diagramGraph.getDependencyFrom(source.getTask(),
destination.getTask());
}
public DependencyType getDependencyType() {
return getDependency().getType();
return type;
}
public boolean hasSameSourceAndDestination(Dependency dependency) {

View file

@ -35,7 +35,7 @@ public class DependencyList extends XulElement implements AfterCompose {
@Override
public void onEvent(final DependencyComponent choosen, Event event) {
context.changeType(choosen.getDependency(), type);
context.changeType(dependencyFor(choosen), type);
}
}
@ -160,8 +160,8 @@ public class DependencyList extends XulElement implements AfterCompose {
public void onEvent(
final DependencyComponent choosen,
Event event) {
context.removeDependency(choosen
.getDependency());
context
.removeDependency(dependencyFor(choosen));
}
});
contextMenuBuilder.item("Set End-Start", new ChangeTypeAction(
@ -229,4 +229,9 @@ public class DependencyList extends XulElement implements AfterCompose {
}
}
}
private Dependency dependencyFor(
final DependencyComponent dependencyComponent) {
return dependencyComponent.getDependency(context.getDiagramGraph());
}
}

View file

@ -75,9 +75,9 @@ public class TaskList extends XulElement implements AfterCompose {
}
List<DependencyComponent> result = new ArrayList<DependencyComponent>();
for (Dependency dependency : dependencies) {
result.add(new DependencyComponent(context, taskComponentByTask
result.add(new DependencyComponent(taskComponentByTask
.get(dependency.getSource()), taskComponentByTask
.get(dependency.getDestination())));
.get(dependency.getDestination()), dependency.getType()));
}
return result;
}