ItEr19S08CUCreacionProxectoPlanificacionItEr18S08: Changing ICommandOnTask interface.
This commit is contained in:
parent
8cb187c9d9
commit
1a3b0a755e
7 changed files with 104 additions and 11 deletions
|
|
@ -2,8 +2,10 @@ package org.zkoss.ganttz;
|
|||
|
||||
import org.zkoss.ganttz.adapters.IDomainAndBeansMapper;
|
||||
import org.zkoss.ganttz.data.Task;
|
||||
import org.zkoss.ganttz.extensions.ContextWithPlannerTask;
|
||||
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
||||
import org.zkoss.ganttz.extensions.IContext;
|
||||
import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
|
||||
import org.zkoss.ganttz.util.MenuBuilder.ItemAction;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
|
||||
|
|
@ -30,11 +32,22 @@ public class CommandOnTaskContextualized<T> {
|
|||
}
|
||||
|
||||
public void doAction(Task task) {
|
||||
doAction(mapper.findAssociatedDomainObject(task));
|
||||
doAction(domainObjectFor(task));
|
||||
}
|
||||
|
||||
private T domainObjectFor(Task task) {
|
||||
return mapper.findAssociatedDomainObject(task);
|
||||
}
|
||||
|
||||
private void doAction(IContext<T> context, T domainObject) {
|
||||
IContextWithPlannerTask<T> contextWithTask = ContextWithPlannerTask
|
||||
.create(context, mapper
|
||||
.findAssociatedBean(domainObject));
|
||||
commandOnTask.doAction(contextWithTask, domainObject);
|
||||
}
|
||||
|
||||
public void doAction(T task) {
|
||||
commandOnTask.doAction(context, task);
|
||||
doAction(context, task);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import org.zkoss.ganttz.extensions.ICommand;
|
||||
import org.zkoss.ganttz.extensions.IContext;
|
||||
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
||||
import org.zkoss.ganttz.extensions.IContext;
|
||||
import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
|
||||
|
||||
/**
|
||||
* A object that defines several extension points for gantt planner
|
||||
|
|
@ -28,6 +29,20 @@ public class PlannerConfiguration<T> {
|
|||
|
||||
}
|
||||
|
||||
private static class NullCommandOnTask<T> implements ICommandOnTask<T> {
|
||||
|
||||
@Override
|
||||
public void doAction(IContextWithPlannerTask<T> context, T task) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private IAdapterToTaskFundamentalProperties<T> adapter;
|
||||
|
||||
private IStructureNavigator<T> navigator;
|
||||
|
|
@ -40,7 +55,6 @@ public class PlannerConfiguration<T> {
|
|||
|
||||
private ICommand<T> goingDownInLastArrowCommand = new NullCommand<T>();
|
||||
|
||||
|
||||
public PlannerConfiguration(IAdapterToTaskFundamentalProperties<T> adapter,
|
||||
IStructureNavigator<T> navigator, List<? extends T> data) {
|
||||
this.adapter = adapter;
|
||||
|
|
@ -60,7 +74,7 @@ public class PlannerConfiguration<T> {
|
|||
return data;
|
||||
}
|
||||
|
||||
public void addCommandOnTask(ICommandOnTask<T> commandOnTask){
|
||||
public void addCommandOnTask(ICommandOnTask<T> commandOnTask) {
|
||||
this.commandsOnTasks.add(commandOnTask);
|
||||
}
|
||||
|
||||
|
|
@ -68,9 +82,10 @@ public class PlannerConfiguration<T> {
|
|||
this.globalCommands.add(command);
|
||||
}
|
||||
|
||||
public List<ICommandOnTask<T>> getCommandsOnTasks(){
|
||||
public List<ICommandOnTask<T>> getCommandsOnTasks() {
|
||||
return Collections.unmodifiableList(commandsOnTasks);
|
||||
}
|
||||
|
||||
public List<ICommand<T>> getGlobalCommands() {
|
||||
return Collections.unmodifiableList(globalCommands);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
package org.zkoss.ganttz.extensions;
|
||||
|
||||
import org.zkoss.ganttz.adapters.PlannerConfiguration;
|
||||
import org.zkoss.ganttz.data.Task;
|
||||
|
||||
/**
|
||||
* An implementation of {@link IContextWithPlannerTask} that wraps another
|
||||
* context and specifies the task to be returned by
|
||||
* {@link IContextWithPlannerTask#getTask()}
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public class ContextWithPlannerTask<T> implements IContextWithPlannerTask<T> {
|
||||
|
||||
private final IContext<T> context;
|
||||
private final Task task;
|
||||
|
||||
public static <T> IContextWithPlannerTask<T> create(IContext<T> context,
|
||||
Task task) {
|
||||
return new ContextWithPlannerTask<T>(context, task);
|
||||
}
|
||||
|
||||
public ContextWithPlannerTask(IContext<T> context, Task task) {
|
||||
this.context = context;
|
||||
this.task = task;
|
||||
|
||||
}
|
||||
|
||||
public void add(T domainObject) {
|
||||
context.add(domainObject);
|
||||
}
|
||||
|
||||
public void reload(PlannerConfiguration<?> configuration) {
|
||||
context.reload(configuration);
|
||||
}
|
||||
|
||||
public void remove(T domainObject) {
|
||||
context.remove(domainObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task getTask() {
|
||||
return task;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,6 @@ public interface ICommandOnTask<T> {
|
|||
|
||||
public String getName();
|
||||
|
||||
public void doAction(IContext<T> context, T task);
|
||||
public void doAction(IContextWithPlannerTask<T> context, T task);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package org.zkoss.ganttz.extensions;
|
||||
|
||||
import org.zkoss.ganttz.data.Task;
|
||||
|
||||
/**
|
||||
* A context that adds a method to retrieve the task associated to the action
|
||||
* performed.
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public interface IContextWithPlannerTask<T> extends IContext<T> {
|
||||
|
||||
/**
|
||||
* @return the task associated to the action
|
||||
*/
|
||||
public Task getTask();
|
||||
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ import org.zkoss.ganttz.data.TaskLeaf;
|
|||
import org.zkoss.ganttz.extensions.ICommand;
|
||||
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
||||
import org.zkoss.ganttz.extensions.IContext;
|
||||
import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
|
||||
|
||||
/**
|
||||
* Some test data for planner <br />
|
||||
|
|
@ -65,10 +66,9 @@ public class DataForPlanner {
|
|||
});
|
||||
configuration
|
||||
.addCommandOnTask(new ICommandOnTask<ITaskFundamentalProperties>() {
|
||||
|
||||
@Override
|
||||
public void doAction(
|
||||
IContext<ITaskFundamentalProperties> context,
|
||||
IContextWithPlannerTask<ITaskFundamentalProperties> context,
|
||||
ITaskFundamentalProperties task) {
|
||||
context.remove(task);
|
||||
}
|
||||
|
|
@ -77,6 +77,7 @@ public class DataForPlanner {
|
|||
public String getName() {
|
||||
return "Remove";
|
||||
}
|
||||
|
||||
});
|
||||
return configuration;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import org.navalplanner.business.planner.entities.TaskElement;
|
|||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.zkoss.ganttz.extensions.IContext;
|
||||
import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
|
||||
|
||||
/**
|
||||
* A command that opens a window to make the resource allocation of a task.
|
||||
|
|
@ -22,7 +22,8 @@ public class ResourceAllocationCommand implements IResourceAllocationCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doAction(IContext<TaskElement> context, TaskElement task) {
|
||||
public void doAction(IContextWithPlannerTask<TaskElement> context,
|
||||
TaskElement task) {
|
||||
if (task instanceof Task) {
|
||||
this.resourceAllocationController.showWindow((Task) task);
|
||||
}
|
||||
|
|
@ -39,4 +40,5 @@ public class ResourceAllocationCommand implements IResourceAllocationCommand {
|
|||
this.resourceAllocationController = resourceAllocationController;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue