ItEr17S10CUCreacionProxectoPlanificacionItEr16S12: Adding support for defining and adding commands to the planner.
This commit is contained in:
parent
0c459b2502
commit
fc12eccb9e
10 changed files with 201 additions and 26 deletions
|
|
@ -0,0 +1,43 @@
|
|||
package org.zkoss.ganttz;
|
||||
|
||||
import org.zkoss.ganttz.extensions.ICommand;
|
||||
import org.zkoss.ganttz.extensions.IContext;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
import org.zkoss.zul.Button;
|
||||
|
||||
class CommandContextualized {
|
||||
|
||||
public static CommandContextualized create(ICommand command,
|
||||
IContext context) {
|
||||
return new CommandContextualized(command, context);
|
||||
}
|
||||
|
||||
private final ICommand command;
|
||||
|
||||
private final IContext context;
|
||||
|
||||
private CommandContextualized(ICommand command, IContext context) {
|
||||
this.command = command;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void doAction() {
|
||||
command.doAction(context);
|
||||
}
|
||||
|
||||
Button toButton() {
|
||||
Button result = new Button();
|
||||
result.setLabel(command.getName());
|
||||
result.addEventListener(Events.ON_CLICK, new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
doAction();
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.zkoss.ganttz;
|
||||
|
||||
import org.zkoss.ganttz.extensions.IContext;
|
||||
|
||||
public class FunctionalityExposedForExtensions implements IContext {
|
||||
|
||||
private final Planner planner;
|
||||
|
||||
public FunctionalityExposedForExtensions(Planner planner) {
|
||||
this.planner = planner;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package org.zkoss.ganttz;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.ganttz.util.TaskBean;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.HtmlMacroComponent;
|
||||
import org.zkoss.zul.Button;
|
||||
|
||||
/**
|
||||
* LeftPane of the planner. Responsible of showing global commands and the
|
||||
* leftTasksTree <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public class LeftPane extends HtmlMacroComponent {
|
||||
|
||||
private final List<TaskBean> topLevelTasks;
|
||||
|
||||
private List<CommandContextualized> commands;
|
||||
|
||||
private LeftTasksTree leftTasksTree;
|
||||
|
||||
public LeftPane(List<CommandContextualized> commands,
|
||||
List<TaskBean> topLevelTasks) {
|
||||
this.commands = commands;
|
||||
this.topLevelTasks = topLevelTasks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompose() {
|
||||
super.afterCompose();
|
||||
leftTasksTree = new LeftTasksTree(topLevelTasks);
|
||||
addCommands();
|
||||
getContainer().appendChild(leftTasksTree);
|
||||
leftTasksTree.afterCompose();
|
||||
}
|
||||
|
||||
private void addCommands() {
|
||||
Component commandsContainer = getCommandsContainer();
|
||||
for (CommandContextualized command : commands) {
|
||||
Button button = command.toButton();
|
||||
commandsContainer.appendChild(button);
|
||||
}
|
||||
}
|
||||
|
||||
private Component getContainer() {
|
||||
Component commandsContainer = getCommandsContainer();
|
||||
Component container = commandsContainer.getParent();
|
||||
return container;
|
||||
}
|
||||
|
||||
private Component getCommandsContainer() {
|
||||
Component commandsContainer = getFellow("leftpane_commands");
|
||||
return commandsContainer;
|
||||
}
|
||||
|
||||
public void taskRemoved(TaskBean taskBean) {
|
||||
leftTasksTree.taskRemoved(taskBean);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package org.zkoss.ganttz;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -12,6 +13,8 @@ import org.zkoss.ganttz.adapters.IAdapterToTaskFundamentalProperties;
|
|||
import org.zkoss.ganttz.adapters.IDomainAndBeansMapper;
|
||||
import org.zkoss.ganttz.adapters.IStructureNavigator;
|
||||
import org.zkoss.ganttz.adapters.PlannerConfiguration;
|
||||
import org.zkoss.ganttz.extensions.ICommand;
|
||||
import org.zkoss.ganttz.extensions.IContext;
|
||||
import org.zkoss.ganttz.util.DependencyBean;
|
||||
import org.zkoss.ganttz.util.GanttDiagramGraph;
|
||||
import org.zkoss.ganttz.util.ITaskFundamentalProperties;
|
||||
|
|
@ -30,7 +33,7 @@ public class Planner extends XulElement {
|
|||
private GanttDiagramGraph diagramGraph = new GanttDiagramGraph();
|
||||
private DependencyRemovedListener dependencyRemovedListener;
|
||||
private TaskRemovedListener taskRemovedListener;
|
||||
private LeftTasksTree leftTasksTree;
|
||||
private LeftPane leftPane;
|
||||
|
||||
private GanttPanel ganttPanel;
|
||||
|
||||
|
|
@ -40,6 +43,8 @@ public class Planner extends XulElement {
|
|||
|
||||
private DependencyAdderAdapter<?> dependencyAdder;
|
||||
|
||||
private List<CommandContextualized> contextualizedCommands;
|
||||
|
||||
public Planner() {
|
||||
}
|
||||
|
||||
|
|
@ -93,8 +98,8 @@ public class Planner extends XulElement {
|
|||
|
||||
private void removePreviousDetails() {
|
||||
List<Object> children = getChildren();
|
||||
for (LeftTasksTree l : Planner.findComponentsOfType(LeftTasksTree.class,
|
||||
children)) {
|
||||
for (LeftTasksTree l : Planner.findComponentsOfType(
|
||||
LeftTasksTree.class, children)) {
|
||||
removeChild(l);
|
||||
}
|
||||
}
|
||||
|
|
@ -127,7 +132,7 @@ public class Planner extends XulElement {
|
|||
@Override
|
||||
public void taskRemoved(Task taskRemoved) {
|
||||
diagramGraph.remove(taskRemoved.getTaskBean());
|
||||
leftTasksTree.taskRemoved(taskRemoved.getTaskBean());
|
||||
leftPane.taskRemoved(taskRemoved.getTaskBean());
|
||||
TaskList taskList = getTaskList();
|
||||
setHeight(getHeight());// forcing smart update
|
||||
taskList.adjustZoomColumnsHeight();
|
||||
|
|
@ -239,9 +244,21 @@ public class Planner extends XulElement {
|
|||
this.diagramGraph.applyAllRestrictions();
|
||||
dependencyAdder = new DependencyAdderAdapter<T>(configuration
|
||||
.getAdapter(), mapper);
|
||||
contextualizedCommands = contextualize(
|
||||
new FunctionalityExposedForExtensions(this), configuration
|
||||
.getCommands());
|
||||
recreate();
|
||||
}
|
||||
|
||||
private List<CommandContextualized> contextualize(IContext context,
|
||||
Collection<? extends ICommand> commands) {
|
||||
ArrayList<CommandContextualized> result = new ArrayList<CommandContextualized>();
|
||||
for (ICommand command : commands) {
|
||||
result.add(CommandContextualized.create(command, context));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private <T> TaskBean extractTaskBean(
|
||||
List<DomainDependency<T>> dependencies, OneToOneMapper<T> mapper,
|
||||
T data, IStructureNavigator<T> navigator,
|
||||
|
|
@ -257,7 +274,7 @@ public class Planner extends XulElement {
|
|||
container.add(extractTaskBean(dependencies, mapper, child,
|
||||
navigator, adapter));
|
||||
}
|
||||
return container;
|
||||
result = container;
|
||||
}
|
||||
mapper.register(result, data);
|
||||
return result;
|
||||
|
|
@ -269,12 +286,11 @@ public class Planner extends XulElement {
|
|||
|
||||
private void recreate() {
|
||||
removePreviousDetails();
|
||||
this.leftTasksTree = new LeftTasksTree(this.diagramGraph
|
||||
this.leftPane = new LeftPane(contextualizedCommands, this.diagramGraph
|
||||
.getTopLevelTasks());
|
||||
insertBefore(this.leftTasksTree,
|
||||
(Component) (getChildren().isEmpty() ? null : getChildren()
|
||||
.get(0)));
|
||||
this.leftTasksTree.afterCompose();
|
||||
insertBefore(this.leftPane, (Component) (getChildren().isEmpty() ? null
|
||||
: getChildren().get(0)));
|
||||
this.leftPane.afterCompose();
|
||||
removePreviousGanntPanel();
|
||||
this.ganttPanel = new GanttPanel(this.diagramGraph,
|
||||
taskEditFormComposer);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
package org.zkoss.ganttz.adapters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.ganttz.extensions.ICommand;
|
||||
|
||||
/**
|
||||
* A object that defines several extension points for gantt planner
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
|
|
@ -14,6 +18,8 @@ public class PlannerConfiguration<T> {
|
|||
|
||||
private List<? extends T> data;
|
||||
|
||||
private List<ICommand> commands = new ArrayList<ICommand>();
|
||||
|
||||
public PlannerConfiguration(IAdapterToTaskFundamentalProperties<T> adapter,
|
||||
IStructureNavigator<T> navigator, List<? extends T> data) {
|
||||
this.adapter = adapter;
|
||||
|
|
@ -33,4 +39,12 @@ public class PlannerConfiguration<T> {
|
|||
return data;
|
||||
}
|
||||
|
||||
public void addCommand(ICommand command) {
|
||||
this.commands.add(command);
|
||||
}
|
||||
|
||||
public List<ICommand> getCommands() {
|
||||
return Collections.unmodifiableList(commands);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package org.zkoss.ganttz.extensions;
|
||||
|
||||
/**
|
||||
* An action that can be applied to the planner and it's wanted to be available
|
||||
* to the user <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public interface ICommand {
|
||||
|
||||
public String getName();
|
||||
|
||||
public void doAction(IContext context);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.zkoss.ganttz.extensions;
|
||||
|
||||
/**
|
||||
* A facade for operations allowed to extensions <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public interface IContext {
|
||||
|
||||
// TODO expose functionality as needed
|
||||
|
||||
}
|
||||
|
|
@ -19,6 +19,12 @@
|
|||
<mold-uri>~./ganttz/planner.dsp</mold-uri>
|
||||
</mold>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<component-name>leftPane</component-name>
|
||||
<component-class>org.zkoss.ganttz.LeftPane</component-class>
|
||||
<macro-uri>~./ganttz/zul/leftPane.zul</macro-uri>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<component-name>leftTasksTree</component-name>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<zk xmlns:n="http://www.zkoss.org/2005/zk/native">
|
||||
<n:div id="listdetails_container">
|
||||
<hbox id="leftpane_commands">
|
||||
</hbox>
|
||||
</n:div>
|
||||
</zk>
|
||||
|
|
@ -1,16 +1,7 @@
|
|||
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
|
||||
<zk xmlns:n="http://www.zkoss.org/2005/zk/native">
|
||||
<button label="${c:l('listdetails.add_task')}"
|
||||
onClick="self.getParent().addTask();" />
|
||||
<button label="Engadir Contedor"
|
||||
onClick="self.getParent().addTaskContainer();" />
|
||||
<n:div id="listdetails_container">
|
||||
<tree id="tasksTree">
|
||||
<treecols sizable="false">
|
||||
<treecol label="Name"/>
|
||||
<treecol label="Start"/>
|
||||
<treecol label="End"/>
|
||||
</treecols>
|
||||
</tree>
|
||||
</n:div>
|
||||
</zk>
|
||||
<tree id="tasksTree">
|
||||
<treecols sizable="false">
|
||||
<treecol label="Name"/>
|
||||
<treecol label="Start"/>
|
||||
<treecol label="End"/>
|
||||
</treecols>
|
||||
</tree>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue