ItEr22S12CUVistaRecursosTempoPorProxectoItEr21S07: Instead of using DependencyAddedListener the context is called telling that the dependency has been added.
This commit is contained in:
parent
f68dc9f411
commit
596bac9dbc
6 changed files with 58 additions and 125 deletions
|
|
@ -53,8 +53,7 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
|
|||
* @param parent
|
||||
*/
|
||||
void register(Integer insertionPositionForTop, Task task,
|
||||
T domainObject,
|
||||
TaskContainer parent) {
|
||||
T domainObject, TaskContainer parent) {
|
||||
fromDomainToTask.put(domainObject, task);
|
||||
fromTaskToDomain.put(task, domainObject);
|
||||
if (parent != null) {
|
||||
|
|
@ -231,4 +230,39 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
|
|||
add(position, newDomainObject);
|
||||
}
|
||||
|
||||
public GanttDiagramGraph getDiagramGraph() {
|
||||
return diagramGraph;
|
||||
}
|
||||
|
||||
private DomainDependency<T> toDomainDependency(Dependency bean) {
|
||||
T source = mapper.findAssociatedDomainObject(bean.getSource());
|
||||
T destination = mapper
|
||||
.findAssociatedDomainObject(bean.getDestination());
|
||||
DomainDependency<T> dep = DomainDependency.createDependency(source,
|
||||
destination, bean.getType());
|
||||
return dep;
|
||||
}
|
||||
|
||||
public void addDependency(DependencyComponent dependencyComponent) {
|
||||
Dependency dependency = dependencyComponent.getDependency();
|
||||
if (!canAddDependency(dependency))
|
||||
return;
|
||||
getDependencyList().addDependencyComponent(dependencyComponent);
|
||||
diagramGraph.add(dependency);
|
||||
adapter.addDependency(toDomainDependency(dependency));
|
||||
}
|
||||
|
||||
private boolean canAddDependency(Dependency dependency) {
|
||||
return adapter.canAddDependency(toDomainDependency(dependency));
|
||||
}
|
||||
|
||||
private DependencyList getDependencyList() {
|
||||
return planner.getDependencyList();
|
||||
}
|
||||
|
||||
public void removeDependency(Dependency dependency) {
|
||||
adapter.removeDependency(toDomainDependency(dependency));
|
||||
diagramGraph.remove(dependency);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,14 +19,15 @@ public class GanttPanel extends XulElement implements AfterCompose {
|
|||
|
||||
private final GanttDiagramGraph diagramGraph;
|
||||
|
||||
public GanttPanel(GanttDiagramGraph ganttDiagramGraph,
|
||||
public GanttPanel(
|
||||
FunctionalityExposedForExtensions<?> context,
|
||||
List<? extends CommandOnTaskContextualized<?>> commandsOnTasksContextualized,
|
||||
CommandOnTaskContextualized<?> editTaskCommand) {
|
||||
this.diagramGraph = ganttDiagramGraph;
|
||||
this.diagramGraph = context.getDiagramGraph();
|
||||
timeTracker = new TimeTracker(this);
|
||||
appendChild(timeTracker);
|
||||
tasksLists = TaskList.createFor(editTaskCommand,
|
||||
ganttDiagramGraph.getTopLevelTasks(), commandsOnTasksContextualized);
|
||||
tasksLists = TaskList.createFor(context, editTaskCommand,
|
||||
commandsOnTasksContextualized);
|
||||
dependencyList = new DependencyList();
|
||||
appendChild(tasksLists);
|
||||
appendChild(dependencyList);
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.zkoss.ganttz;
|
||||
|
||||
public interface IDependencyAddedListener {
|
||||
|
||||
public void dependenceAdded(DependencyComponent dependencyComponent);
|
||||
}
|
||||
|
|
@ -5,11 +5,6 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.zkoss.ganttz.adapters.DomainDependency;
|
||||
import org.zkoss.ganttz.adapters.IAdapterToTaskFundamentalProperties;
|
||||
import org.zkoss.ganttz.adapters.IDomainAndBeansMapper;
|
||||
import org.zkoss.ganttz.adapters.PlannerConfiguration;
|
||||
import org.zkoss.ganttz.data.Dependency;
|
||||
import org.zkoss.ganttz.data.GanttDiagramGraph;
|
||||
|
|
@ -23,17 +18,12 @@ import org.zkoss.zul.impl.XulElement;
|
|||
|
||||
public class Planner extends XulElement {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(Planner.class);
|
||||
|
||||
private IDependencyAddedListener dependencyAddedListener;
|
||||
private GanttDiagramGraph diagramGraph = new GanttDiagramGraph();
|
||||
private IDependencyRemovedListener dependencyRemovedListener;
|
||||
private LeftPane leftPane;
|
||||
|
||||
private GanttPanel ganttPanel;
|
||||
|
||||
private DependencyAdderAdapter<?> dependencyAdder;
|
||||
|
||||
private List<? extends CommandContextualized<?>> contextualizedGlobalCommands;
|
||||
|
||||
private CommandContextualized<?> goingDownInLastArrowCommand;
|
||||
|
|
@ -42,6 +32,8 @@ public class Planner extends XulElement {
|
|||
|
||||
private CommandOnTaskContextualized<?> editTaskCommand;
|
||||
|
||||
private FunctionalityExposedForExtensions<?> context;
|
||||
|
||||
public Planner() {
|
||||
}
|
||||
|
||||
|
|
@ -78,29 +70,14 @@ public class Planner extends XulElement {
|
|||
return found.get(0);
|
||||
}
|
||||
|
||||
public boolean canAddDependency(Dependency dependency) {
|
||||
return dependencyAdder.canAddDependency(dependency);
|
||||
}
|
||||
|
||||
public void registerListeners() {
|
||||
TaskList taskList = getTaskList();
|
||||
dependencyAddedListener = new IDependencyAddedListener() {
|
||||
|
||||
@Override
|
||||
public void dependenceAdded(DependencyComponent dependencyComponent) {
|
||||
getDependencyList().addDependencyComponent(dependencyComponent);
|
||||
diagramGraph.add(dependencyComponent.getDependency());
|
||||
dependencyAdder.addDependency(dependencyComponent
|
||||
.getDependency());
|
||||
}
|
||||
};
|
||||
taskList.addDependencyListener(dependencyAddedListener);
|
||||
dependencyRemovedListener = new IDependencyRemovedListener() {
|
||||
|
||||
@Override
|
||||
public void dependenceRemoved(
|
||||
DependencyComponent dependencyComponent) {
|
||||
dependencyRemoved(dependencyComponent);
|
||||
context.removeDependency(dependencyComponent.getDependency());
|
||||
}
|
||||
};
|
||||
getDependencyList().addDependencyRemovedListener(
|
||||
|
|
@ -130,41 +107,6 @@ public class Planner extends XulElement {
|
|||
}
|
||||
}
|
||||
|
||||
private static class DependencyAdderAdapter<T> {
|
||||
|
||||
private final IAdapterToTaskFundamentalProperties<T> adapter;
|
||||
private final IDomainAndBeansMapper<T> mapper;
|
||||
|
||||
public DependencyAdderAdapter(
|
||||
IAdapterToTaskFundamentalProperties<T> adapter,
|
||||
IDomainAndBeansMapper<T> mapper) {
|
||||
this.adapter = adapter;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public void addDependency(Dependency bean) {
|
||||
adapter.addDependency(toDomainDependency(bean));
|
||||
}
|
||||
|
||||
public void removeDependency(Dependency bean) {
|
||||
adapter.removeDependency(toDomainDependency(bean));
|
||||
}
|
||||
|
||||
private DomainDependency<T> toDomainDependency(Dependency bean) {
|
||||
T source = mapper.findAssociatedDomainObject(bean.getSource());
|
||||
T destination = mapper.findAssociatedDomainObject(bean
|
||||
.getDestination());
|
||||
DomainDependency<T> dep = DomainDependency.createDependency(source,
|
||||
destination, bean.getType());
|
||||
return dep;
|
||||
}
|
||||
|
||||
public boolean canAddDependency(Dependency bean) {
|
||||
return adapter.canAddDependency(toDomainDependency(bean));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public <T> void setConfiguration(PlannerConfiguration<T> configuration) {
|
||||
if (configuration == null)
|
||||
return;
|
||||
|
|
@ -172,8 +114,6 @@ public class Planner extends XulElement {
|
|||
FunctionalityExposedForExtensions<T> context = new FunctionalityExposedForExtensions<T>(
|
||||
this, configuration.getAdapter(), configuration.getNavigator(),
|
||||
diagramGraph);
|
||||
dependencyAdder = new DependencyAdderAdapter<T>(configuration
|
||||
.getAdapter(), context.getMapper());
|
||||
this.contextualizedGlobalCommands = contextualize(context,
|
||||
configuration.getGlobalCommands());
|
||||
this.commandsOnTasksContextualized = contextualize(context,
|
||||
|
|
@ -182,6 +122,7 @@ public class Planner extends XulElement {
|
|||
.getGoingDownInLastArrowCommand());
|
||||
editTaskCommand = contextualize(context, configuration
|
||||
.getEditTaskCommand());
|
||||
this.context = context;
|
||||
clear();
|
||||
context.add(configuration.getData());
|
||||
recreate();
|
||||
|
|
@ -238,7 +179,7 @@ public class Planner extends XulElement {
|
|||
this.leftPane.afterCompose();
|
||||
this.leftPane
|
||||
.setGoingDownInLastArrowCommand(goingDownInLastArrowCommand);
|
||||
this.ganttPanel = new GanttPanel(this.diagramGraph,
|
||||
this.ganttPanel = new GanttPanel(this.context,
|
||||
commandsOnTasksContextualized, editTaskCommand);
|
||||
ganttPanel.setParent(this);
|
||||
ganttPanel.afterCompose();
|
||||
|
|
@ -252,9 +193,4 @@ public class Planner extends XulElement {
|
|||
taskList.adjustZoomColumnsHeight();
|
||||
getDependencyList().redrawDependencies();
|
||||
}
|
||||
|
||||
void dependencyRemoved(DependencyComponent dependencyComponent) {
|
||||
diagramGraph.remove(dependencyComponent);
|
||||
dependencyAdder.removeDependency(dependencyComponent.getDependency());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
package org.zkoss.ganttz;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.zkoss.ganttz.data.Dependency;
|
||||
|
|
@ -42,20 +39,25 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
|
||||
private final List<? extends CommandOnTaskContextualized<?>> commandsOnTasksContextualized;
|
||||
|
||||
private final FunctionalityExposedForExtensions<?> context;
|
||||
|
||||
public TaskList(
|
||||
FunctionalityExposedForExtensions<?> context,
|
||||
CommandOnTaskContextualized<?> editTaskCommand,
|
||||
List<Task> tasks,
|
||||
List<? extends CommandOnTaskContextualized<?>> commandsOnTasksContextualized) {
|
||||
this.context = context;
|
||||
this.editTaskCommand = editTaskCommand;
|
||||
this.originalTasks = tasks;
|
||||
this.commandsOnTasksContextualized = commandsOnTasksContextualized;
|
||||
}
|
||||
|
||||
public static TaskList createFor(
|
||||
FunctionalityExposedForExtensions<?> context,
|
||||
CommandOnTaskContextualized<?> editTaskCommand,
|
||||
List<Task> tasks,
|
||||
List<? extends CommandOnTaskContextualized<?>> commandsOnTasksContextualized) {
|
||||
TaskList result = new TaskList(editTaskCommand, tasks,
|
||||
TaskList result = new TaskList(context, editTaskCommand, context
|
||||
.getDiagramGraph().getTopLevelTasks(),
|
||||
commandsOnTasksContextualized);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -71,7 +73,7 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
}
|
||||
List<DependencyComponent> result = new ArrayList<DependencyComponent>();
|
||||
for (Dependency dependency : dependencies) {
|
||||
result.add(new DependencyComponent(taskComponentByTask
|
||||
result.add(new DependencyComponent(context, taskComponentByTask
|
||||
.get(dependency.getSource()), taskComponentByTask
|
||||
.get(dependency.getDestination())));
|
||||
}
|
||||
|
|
@ -219,11 +221,6 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
return getTaskComponents().size();
|
||||
}
|
||||
|
||||
public void addDependencyListener(IDependencyAddedListener listener) {
|
||||
dependencyListeners.add(new WeakReference<IDependencyAddedListener>(
|
||||
listener));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompose() {
|
||||
for (Task task : originalTasks) {
|
||||
|
|
@ -295,31 +292,6 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
public void addDependency(TaskComponent source, TaskComponent destination) {
|
||||
DependencyComponent dependencyComponent = new DependencyComponent(
|
||||
source, destination);
|
||||
if (getPlanner().canAddDependency(dependencyComponent.getDependency())) {
|
||||
fireDependenceAdded(dependencyComponent);
|
||||
}
|
||||
context.addDependency(dependencyComponent);
|
||||
}
|
||||
|
||||
private List<WeakReference<IDependencyAddedListener>> dependencyListeners = new LinkedList<WeakReference<IDependencyAddedListener>>();
|
||||
|
||||
private void fireDependenceAdded(DependencyComponent dependencyComponent) {
|
||||
ArrayList<IDependencyAddedListener> active = new ArrayList<IDependencyAddedListener>();
|
||||
synchronized (this) {
|
||||
ListIterator<WeakReference<IDependencyAddedListener>> iterator = dependencyListeners
|
||||
.listIterator();
|
||||
while (iterator.hasNext()) {
|
||||
WeakReference<IDependencyAddedListener> next = iterator.next();
|
||||
IDependencyAddedListener listener = next.get();
|
||||
if (listener == null) {
|
||||
iterator.remove();
|
||||
} else {
|
||||
active.add(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (IDependencyAddedListener listener : active) {
|
||||
listener.dependenceAdded(dependencyComponent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import java.util.WeakHashMap;
|
|||
|
||||
import org.jgrapht.DirectedGraph;
|
||||
import org.jgrapht.graph.SimpleDirectedGraph;
|
||||
import org.zkoss.ganttz.DependencyComponent;
|
||||
|
||||
/**
|
||||
* This class contains a graph with the {@link Task tasks} as vertexes and the
|
||||
|
|
@ -179,9 +178,9 @@ public class GanttDiagramGraph {
|
|||
}
|
||||
}
|
||||
|
||||
public void remove(DependencyComponent dependencyComponent) {
|
||||
graph.removeEdge(dependencyComponent.getDependency());
|
||||
Task destination = dependencyComponent.getDependency().getDestination();
|
||||
public void remove(Dependency dependency) {
|
||||
graph.removeEdge(dependency);
|
||||
Task destination = dependency.getDestination();
|
||||
rulesEnforcersByTask.get(destination).enforce();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue