ItEr18S08CUCreacionProxectoPlanificacionItEr17S10: Adding contextualized commands support.
This commit is contained in:
parent
a863ae31df
commit
454578cd12
6 changed files with 121 additions and 24 deletions
|
|
@ -0,0 +1,53 @@
|
||||||
|
package org.zkoss.ganttz;
|
||||||
|
|
||||||
|
import org.zkoss.ganttz.adapters.IDomainAndBeansMapper;
|
||||||
|
import org.zkoss.ganttz.data.Task;
|
||||||
|
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
||||||
|
import org.zkoss.ganttz.extensions.IContext;
|
||||||
|
import org.zkoss.ganttz.util.MenuBuilder.ItemAction;
|
||||||
|
import org.zkoss.zk.ui.event.Event;
|
||||||
|
|
||||||
|
public class CommandOnTaskContextualized<T> {
|
||||||
|
|
||||||
|
public static <T> CommandOnTaskContextualized<T> create(
|
||||||
|
ICommandOnTask<T> commandOnTask, IDomainAndBeansMapper<T> mapper,
|
||||||
|
IContext<T> context) {
|
||||||
|
return new CommandOnTaskContextualized<T>(commandOnTask, mapper,
|
||||||
|
context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ICommandOnTask<T> commandOnTask;
|
||||||
|
|
||||||
|
private final IContext<T> context;
|
||||||
|
|
||||||
|
private final IDomainAndBeansMapper<T> mapper;
|
||||||
|
|
||||||
|
private CommandOnTaskContextualized(ICommandOnTask<T> commandOnTask,
|
||||||
|
IDomainAndBeansMapper<T> mapper, IContext<T> context) {
|
||||||
|
this.commandOnTask = commandOnTask;
|
||||||
|
this.mapper = mapper;
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doAction(Task task) {
|
||||||
|
doAction(mapper.findAssociatedDomainObject(task));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doAction(T task) {
|
||||||
|
commandOnTask.doAction(context, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return commandOnTask.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemAction<TaskComponent> toItemAction() {
|
||||||
|
return new ItemAction<TaskComponent>() {
|
||||||
|
@Override
|
||||||
|
public void onEvent(TaskComponent choosen, Event event) {
|
||||||
|
doAction(choosen.getTask());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package org.zkoss.ganttz;
|
package org.zkoss.ganttz;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.zkoss.ganttz.data.GanttDiagramGraph;
|
import org.zkoss.ganttz.data.GanttDiagramGraph;
|
||||||
import org.zkoss.zk.au.AuRequest;
|
import org.zkoss.zk.au.AuRequest;
|
||||||
import org.zkoss.zk.au.Command;
|
import org.zkoss.zk.au.Command;
|
||||||
|
|
@ -18,12 +20,12 @@ public class GanttPanel extends XulElement implements AfterCompose {
|
||||||
private final GanttDiagramGraph diagramGraph;
|
private final GanttDiagramGraph diagramGraph;
|
||||||
|
|
||||||
public GanttPanel(GanttDiagramGraph ganttDiagramGraph,
|
public GanttPanel(GanttDiagramGraph ganttDiagramGraph,
|
||||||
TaskEditFormComposer taskEditFormComposer) {
|
List<? extends CommandOnTaskContextualized<?>> commandsOnTasksContextualized, TaskEditFormComposer taskEditFormComposer) {
|
||||||
this.diagramGraph = ganttDiagramGraph;
|
this.diagramGraph = ganttDiagramGraph;
|
||||||
timeTracker = new TimeTracker(this);
|
timeTracker = new TimeTracker(this);
|
||||||
appendChild(timeTracker);
|
appendChild(timeTracker);
|
||||||
tasksLists = TaskList.createFor(taskEditFormComposer,
|
tasksLists = TaskList.createFor(taskEditFormComposer,
|
||||||
ganttDiagramGraph.getTopLevelTasks());
|
ganttDiagramGraph.getTopLevelTasks(), commandsOnTasksContextualized);
|
||||||
dependencyList = new DependencyList();
|
dependencyList = new DependencyList();
|
||||||
appendChild(tasksLists);
|
appendChild(tasksLists);
|
||||||
appendChild(dependencyList);
|
appendChild(dependencyList);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import org.zkoss.ganttz.data.Dependency;
|
||||||
import org.zkoss.ganttz.data.GanttDiagramGraph;
|
import org.zkoss.ganttz.data.GanttDiagramGraph;
|
||||||
import org.zkoss.ganttz.data.Task;
|
import org.zkoss.ganttz.data.Task;
|
||||||
import org.zkoss.ganttz.extensions.ICommand;
|
import org.zkoss.ganttz.extensions.ICommand;
|
||||||
|
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
||||||
import org.zkoss.ganttz.extensions.IContext;
|
import org.zkoss.ganttz.extensions.IContext;
|
||||||
import org.zkoss.zk.ui.Component;
|
import org.zkoss.zk.ui.Component;
|
||||||
import org.zkoss.zk.ui.Executions;
|
import org.zkoss.zk.ui.Executions;
|
||||||
|
|
@ -35,18 +36,19 @@ public class Planner extends XulElement {
|
||||||
|
|
||||||
private DependencyAdderAdapter<?> dependencyAdder;
|
private DependencyAdderAdapter<?> dependencyAdder;
|
||||||
|
|
||||||
private List<? extends CommandContextualized<?>> contextualizedCommands;
|
private List<? extends CommandContextualized<?>> contextualizedGlobalCommands;
|
||||||
|
|
||||||
private CommandContextualized<?> goingDownInLastArrowCommand;
|
private CommandContextualized<?> goingDownInLastArrowCommand;
|
||||||
|
|
||||||
|
private List<? extends CommandOnTaskContextualized<?>> commandsOnTasksContextualized;
|
||||||
|
|
||||||
public Planner() {
|
public Planner() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskList getTaskList() {
|
TaskList getTaskList() {
|
||||||
if (ganttPanel == null)
|
if (ganttPanel == null)
|
||||||
return null;
|
return null;
|
||||||
List<Object> children = ganttPanel
|
List<Object> children = ganttPanel.getChildren();
|
||||||
.getChildren();
|
|
||||||
return Planner.findComponentsOfType(TaskList.class, children).get(0);
|
return Planner.findComponentsOfType(TaskList.class, children).get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,7 +102,8 @@ public class Planner extends XulElement {
|
||||||
public void dependenceAdded(DependencyComponent dependencyComponent) {
|
public void dependenceAdded(DependencyComponent dependencyComponent) {
|
||||||
getDependencyList().addDependencyComponent(dependencyComponent);
|
getDependencyList().addDependencyComponent(dependencyComponent);
|
||||||
diagramGraph.add(dependencyComponent.getDependency());
|
diagramGraph.add(dependencyComponent.getDependency());
|
||||||
dependencyAdder.addDependency(dependencyComponent.getDependency());
|
dependencyAdder.addDependency(dependencyComponent
|
||||||
|
.getDependency());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
taskList.addDependencyListener(dependencyAddedListener);
|
taskList.addDependencyListener(dependencyAddedListener);
|
||||||
|
|
@ -120,9 +123,11 @@ public class Planner extends XulElement {
|
||||||
dependencyRemovedListener = new DependencyRemovedListener() {
|
dependencyRemovedListener = new DependencyRemovedListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dependenceRemoved(DependencyComponent dependencyComponent) {
|
public void dependenceRemoved(
|
||||||
|
DependencyComponent dependencyComponent) {
|
||||||
diagramGraph.remove(dependencyComponent);
|
diagramGraph.remove(dependencyComponent);
|
||||||
dependencyAdder.removeDependency(dependencyComponent.getDependency());
|
dependencyAdder.removeDependency(dependencyComponent
|
||||||
|
.getDependency());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
getDependencyList().addDependencyRemovedListener(
|
getDependencyList().addDependencyRemovedListener(
|
||||||
|
|
@ -153,7 +158,7 @@ public class Planner extends XulElement {
|
||||||
adapter.addDependency(toDomainDependency(bean));
|
adapter.addDependency(toDomainDependency(bean));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDependency(Dependency bean){
|
public void removeDependency(Dependency bean) {
|
||||||
adapter.removeDependency(toDomainDependency(bean));
|
adapter.removeDependency(toDomainDependency(bean));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,9 +186,10 @@ public class Planner extends XulElement {
|
||||||
diagramGraph);
|
diagramGraph);
|
||||||
dependencyAdder = new DependencyAdderAdapter<T>(configuration
|
dependencyAdder = new DependencyAdderAdapter<T>(configuration
|
||||||
.getAdapter(), context.getMapper());
|
.getAdapter(), context.getMapper());
|
||||||
this.contextualizedCommands = contextualize(context,
|
this.contextualizedGlobalCommands = contextualize(context,
|
||||||
configuration
|
configuration.getGlobalCommands());
|
||||||
.getGlobalCommands());
|
this.commandsOnTasksContextualized = contextualize(context,
|
||||||
|
configuration.getCommandsOnTasks());
|
||||||
goingDownInLastArrowCommand = contextualize(context, configuration
|
goingDownInLastArrowCommand = contextualize(context, configuration
|
||||||
.getGoingDownInLastArrowCommand());
|
.getGoingDownInLastArrowCommand());
|
||||||
clear();
|
clear();
|
||||||
|
|
@ -198,14 +204,24 @@ public class Planner extends XulElement {
|
||||||
getChildren().clear();
|
getChildren().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> CommandContextualized<T> contextualize(
|
private <T> List<CommandOnTaskContextualized<T>> contextualize(
|
||||||
IContext<T> context, ICommand<T> command) {
|
FunctionalityExposedForExtensions<T> context,
|
||||||
|
List<ICommandOnTask<T>> commands) {
|
||||||
|
List<CommandOnTaskContextualized<T>> result = new ArrayList<CommandOnTaskContextualized<T>>();
|
||||||
|
for (ICommandOnTask<T> c : commands) {
|
||||||
|
result.add(CommandOnTaskContextualized.create(c, context
|
||||||
|
.getMapper(), context));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> CommandContextualized<T> contextualize(IContext<T> context,
|
||||||
|
ICommand<T> command) {
|
||||||
return CommandContextualized.create(command, context);
|
return CommandContextualized.create(command, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> List<CommandContextualized<T>> contextualize(
|
private <T> List<CommandContextualized<T>> contextualize(
|
||||||
IContext<T> context,
|
IContext<T> context, Collection<? extends ICommand<T>> commands) {
|
||||||
Collection<? extends ICommand<T>> commands) {
|
|
||||||
ArrayList<CommandContextualized<T>> result = new ArrayList<CommandContextualized<T>>();
|
ArrayList<CommandContextualized<T>> result = new ArrayList<CommandContextualized<T>>();
|
||||||
for (ICommand<T> command : commands) {
|
for (ICommand<T> command : commands) {
|
||||||
result.add(contextualize(context, command));
|
result.add(contextualize(context, command));
|
||||||
|
|
@ -218,13 +234,13 @@ public class Planner extends XulElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recreate() {
|
private void recreate() {
|
||||||
this.leftPane = new LeftPane(contextualizedCommands, this.diagramGraph
|
this.leftPane = new LeftPane(contextualizedGlobalCommands, this.diagramGraph
|
||||||
.getTopLevelTasks());
|
.getTopLevelTasks());
|
||||||
this.leftPane.setParent(this);
|
this.leftPane.setParent(this);
|
||||||
this.leftPane.afterCompose();
|
this.leftPane.afterCompose();
|
||||||
this.leftPane
|
this.leftPane
|
||||||
.setGoingDownInLastArrowCommand(goingDownInLastArrowCommand);
|
.setGoingDownInLastArrowCommand(goingDownInLastArrowCommand);
|
||||||
this.ganttPanel = new GanttPanel(this.diagramGraph,
|
this.ganttPanel = new GanttPanel(this.diagramGraph, commandsOnTasksContextualized,
|
||||||
taskEditFormComposer);
|
taskEditFormComposer);
|
||||||
ganttPanel.setParent(this);
|
ganttPanel.setParent(this);
|
||||||
ganttPanel.afterCompose();
|
ganttPanel.afterCompose();
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,17 @@ public class TaskList extends XulElement implements AfterCompose {
|
||||||
|
|
||||||
private final TaskEditFormComposer taskEditFormComposer;
|
private final TaskEditFormComposer taskEditFormComposer;
|
||||||
|
|
||||||
public TaskList(TaskEditFormComposer formComposer, List<Task> tasks) {
|
private final List<? extends CommandOnTaskContextualized<?>> commandsOnTasksContextualized;
|
||||||
|
|
||||||
|
public TaskList(TaskEditFormComposer formComposer, List<Task> tasks, List<? extends CommandOnTaskContextualized<?>> commandsOnTasksContextualized) {
|
||||||
this.taskEditFormComposer = formComposer;
|
this.taskEditFormComposer = formComposer;
|
||||||
this.originalTasks = tasks;
|
this.originalTasks = tasks;
|
||||||
|
this.commandsOnTasksContextualized = commandsOnTasksContextualized;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TaskList createFor(TaskEditFormComposer formComposer,
|
public static TaskList createFor(TaskEditFormComposer formComposer,
|
||||||
List<Task> tasks) {
|
List<Task> tasks, List<? extends CommandOnTaskContextualized<?>> commandsOnTasksContextualized) {
|
||||||
TaskList result = new TaskList(formComposer, tasks);
|
TaskList result = new TaskList(formComposer, tasks, commandsOnTasksContextualized);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,7 +219,8 @@ public class TaskList extends XulElement implements AfterCompose {
|
||||||
|
|
||||||
private Menupopup getContextMenuForTasks() {
|
private Menupopup getContextMenuForTasks() {
|
||||||
if (contextMenu == null) {
|
if (contextMenu == null) {
|
||||||
contextMenu = MenuBuilder.on(getPage(), getTaskComponents()).item(
|
MenuBuilder<TaskComponent> menuBuilder = MenuBuilder.on(getPage(), getTaskComponents());
|
||||||
|
menuBuilder.item(
|
||||||
"Add Dependency", new ItemAction<TaskComponent>() {
|
"Add Dependency", new ItemAction<TaskComponent>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -228,7 +232,11 @@ public class TaskList extends XulElement implements AfterCompose {
|
||||||
public void onEvent(TaskComponent choosen, Event event) {
|
public void onEvent(TaskComponent choosen, Event event) {
|
||||||
choosen.remove();
|
choosen.remove();
|
||||||
}
|
}
|
||||||
}).createWithoutSettingContext();
|
});
|
||||||
|
for (CommandOnTaskContextualized<?> command : commandsOnTasksContextualized) {
|
||||||
|
menuBuilder.item(command.getName(), command.toItemAction());
|
||||||
|
}
|
||||||
|
contextMenu = menuBuilder.createWithoutSettingContext();
|
||||||
}
|
}
|
||||||
return contextMenu;
|
return contextMenu;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.zkoss.ganttz.extensions.ICommand;
|
import org.zkoss.ganttz.extensions.ICommand;
|
||||||
import org.zkoss.ganttz.extensions.IContext;
|
import org.zkoss.ganttz.extensions.IContext;
|
||||||
|
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A object that defines several extension points for gantt planner
|
* A object that defines several extension points for gantt planner
|
||||||
|
|
@ -35,6 +36,8 @@ public class PlannerConfiguration<T> {
|
||||||
|
|
||||||
private List<ICommand<T>> globalCommands = new ArrayList<ICommand<T>>();
|
private List<ICommand<T>> globalCommands = new ArrayList<ICommand<T>>();
|
||||||
|
|
||||||
|
private List<ICommandOnTask<T>> commandsOnTasks = new ArrayList<ICommandOnTask<T>>();
|
||||||
|
|
||||||
private ICommand<T> goingDownInLastArrowCommand = new NullCommand<T>();
|
private ICommand<T> goingDownInLastArrowCommand = new NullCommand<T>();
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -57,11 +60,17 @@ public class PlannerConfiguration<T> {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addCommandOnTask(ICommandOnTask<T> commandOnTask){
|
||||||
|
this.commandsOnTasks.add(commandOnTask);
|
||||||
|
}
|
||||||
|
|
||||||
public void addGlobalCommand(ICommand<T> command) {
|
public void addGlobalCommand(ICommand<T> command) {
|
||||||
this.globalCommands.add(command);
|
this.globalCommands.add(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ICommandOnTask<T>> getCommandsOnTasks(){
|
||||||
|
return Collections.unmodifiableList(commandsOnTasks);
|
||||||
|
}
|
||||||
public List<ICommand<T>> getGlobalCommands() {
|
public List<ICommand<T>> getGlobalCommands() {
|
||||||
return Collections.unmodifiableList(globalCommands);
|
return Collections.unmodifiableList(globalCommands);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package org.zkoss.ganttz.extensions;
|
||||||
|
|
||||||
|
public interface ICommandOnTask<T> {
|
||||||
|
|
||||||
|
public String getName();
|
||||||
|
|
||||||
|
public void doAction(IContext<T> context, T task);
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue