2009-10-01 18:46:46 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of ###PROJECT_NAME###
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
|
|
|
|
* Desenvolvemento Tecnolóxico de Galicia
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-04-14 17:51:03 +02:00
|
|
|
package org.zkoss.ganttz;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2009-07-28 20:17:49 +02:00
|
|
|
import java.util.Arrays;
|
2009-07-20 15:37:40 +02:00
|
|
|
import java.util.Collection;
|
2009-04-14 17:51:03 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2009-07-16 10:40:57 +02:00
|
|
|
import org.zkoss.ganttz.adapters.PlannerConfiguration;
|
2009-07-20 18:00:11 +02:00
|
|
|
import org.zkoss.ganttz.data.Dependency;
|
2009-07-20 15:37:47 +02:00
|
|
|
import org.zkoss.ganttz.data.GanttDiagramGraph;
|
2009-07-28 20:17:49 +02:00
|
|
|
import org.zkoss.ganttz.data.Position;
|
2009-07-20 18:00:11 +02:00
|
|
|
import org.zkoss.ganttz.data.Task;
|
2009-07-20 15:37:40 +02:00
|
|
|
import org.zkoss.ganttz.extensions.ICommand;
|
2009-07-22 18:43:31 +02:00
|
|
|
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
2009-07-20 15:37:40 +02:00
|
|
|
import org.zkoss.ganttz.extensions.IContext;
|
2009-09-30 23:30:52 +02:00
|
|
|
import org.zkoss.ganttz.util.ComponentsFinder;
|
2009-08-31 16:58:07 +02:00
|
|
|
import org.zkoss.ganttz.util.OnZKDesktopRegistry;
|
2009-09-01 11:30:02 +02:00
|
|
|
import org.zkoss.ganttz.util.script.IScriptsRegister;
|
2009-04-30 13:42:39 +02:00
|
|
|
import org.zkoss.zk.ui.Executions;
|
2009-10-02 18:28:55 +02:00
|
|
|
import org.zkoss.zk.ui.HtmlMacroComponent;
|
|
|
|
|
import org.zkoss.zul.Label;
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2009-10-02 18:28:55 +02:00
|
|
|
public class Planner extends HtmlMacroComponent {
|
2009-04-14 17:51:03 +02:00
|
|
|
|
2009-07-16 10:41:03 +02:00
|
|
|
private GanttDiagramGraph diagramGraph = new GanttDiagramGraph();
|
2009-08-18 12:26:56 +02:00
|
|
|
|
2009-07-20 15:37:40 +02:00
|
|
|
private LeftPane leftPane;
|
2009-07-16 10:40:58 +02:00
|
|
|
|
2009-06-15 21:48:54 +02:00
|
|
|
private GanttPanel ganttPanel;
|
|
|
|
|
|
2009-07-22 18:43:31 +02:00
|
|
|
private List<? extends CommandContextualized<?>> contextualizedGlobalCommands;
|
2009-07-20 15:37:40 +02:00
|
|
|
|
2009-07-20 15:37:42 +02:00
|
|
|
private CommandContextualized<?> goingDownInLastArrowCommand;
|
|
|
|
|
|
2009-07-22 18:43:31 +02:00
|
|
|
private List<? extends CommandOnTaskContextualized<?>> commandsOnTasksContextualized;
|
|
|
|
|
|
2009-07-28 12:28:47 +02:00
|
|
|
private CommandOnTaskContextualized<?> editTaskCommand;
|
|
|
|
|
|
2009-08-18 12:26:56 +02:00
|
|
|
private FunctionalityExposedForExtensions<?> context;
|
|
|
|
|
|
2009-04-14 17:51:03 +02:00
|
|
|
public Planner() {
|
2009-09-01 11:30:02 +02:00
|
|
|
registerNeededScripts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void registerNeededScripts() {
|
|
|
|
|
IScriptsRegister register = getScriptsRegister();
|
|
|
|
|
register.register(ScriptsRequiredByPlanner.class);
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
2009-04-29 17:40:02 +02:00
|
|
|
TaskList getTaskList() {
|
2009-07-20 15:37:41 +02:00
|
|
|
if (ganttPanel == null)
|
|
|
|
|
return null;
|
2009-07-22 18:43:31 +02:00
|
|
|
List<Object> children = ganttPanel.getChildren();
|
2009-09-30 23:30:52 +02:00
|
|
|
return ComponentsFinder.findComponentsOfType(TaskList.class, children).get(0);
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
2009-04-30 13:42:39 +02:00
|
|
|
public String getContextPath() {
|
|
|
|
|
return Executions.getCurrent().getContextPath();
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-29 18:35:19 +02:00
|
|
|
public DependencyList getDependencyList() {
|
2009-07-26 16:17:52 +02:00
|
|
|
if (ganttPanel == null)
|
|
|
|
|
return null;
|
2009-06-15 21:48:54 +02:00
|
|
|
List<Object> children = ganttPanel.getChildren();
|
2009-09-30 23:30:52 +02:00
|
|
|
List<DependencyList> found = ComponentsFinder.findComponentsOfType(DependencyList.class,
|
2009-04-29 18:35:19 +02:00
|
|
|
children);
|
|
|
|
|
if (found.isEmpty())
|
|
|
|
|
return null;
|
|
|
|
|
return found.get(0);
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-28 20:17:49 +02:00
|
|
|
public void addTasks(Position position, Collection<? extends Task> newTasks) {
|
2009-07-20 15:37:41 +02:00
|
|
|
TaskList taskList = getTaskList();
|
|
|
|
|
if (taskList != null && leftPane != null) {
|
2009-07-28 20:17:49 +02:00
|
|
|
taskList.addTasks(position, newTasks);
|
|
|
|
|
leftPane.addTasks(position, newTasks);
|
2009-07-16 10:40:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-28 20:17:49 +02:00
|
|
|
public void addTask(Position position, Task task) {
|
|
|
|
|
addTasks(position, Arrays.asList(task));
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-26 16:17:52 +02:00
|
|
|
void addDependencies(Collection<? extends Dependency> dependencies) {
|
|
|
|
|
DependencyList dependencyList = getDependencyList();
|
|
|
|
|
if (dependencyList == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (DependencyComponent d : getTaskList().asDependencyComponents(
|
|
|
|
|
dependencies)) {
|
|
|
|
|
dependencyList.addDependencyComponent(d);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-16 10:40:57 +02:00
|
|
|
public <T> void setConfiguration(PlannerConfiguration<T> configuration) {
|
2009-07-16 10:40:58 +02:00
|
|
|
if (configuration == null)
|
|
|
|
|
return;
|
2009-07-16 10:41:03 +02:00
|
|
|
this.diagramGraph = new GanttDiagramGraph();
|
2009-07-20 15:37:41 +02:00
|
|
|
FunctionalityExposedForExtensions<T> context = new FunctionalityExposedForExtensions<T>(
|
|
|
|
|
this, configuration.getAdapter(), configuration.getNavigator(),
|
|
|
|
|
diagramGraph);
|
2009-07-22 18:43:31 +02:00
|
|
|
this.contextualizedGlobalCommands = contextualize(context,
|
|
|
|
|
configuration.getGlobalCommands());
|
|
|
|
|
this.commandsOnTasksContextualized = contextualize(context,
|
|
|
|
|
configuration.getCommandsOnTasks());
|
2009-07-20 15:37:42 +02:00
|
|
|
goingDownInLastArrowCommand = contextualize(context, configuration
|
|
|
|
|
.getGoingDownInLastArrowCommand());
|
2009-07-28 12:28:47 +02:00
|
|
|
editTaskCommand = contextualize(context, configuration
|
|
|
|
|
.getEditTaskCommand());
|
2009-08-18 12:26:56 +02:00
|
|
|
this.context = context;
|
2009-07-22 13:27:22 +02:00
|
|
|
clear();
|
|
|
|
|
context.add(configuration.getData());
|
2009-09-30 19:07:03 +02:00
|
|
|
setupComponents();
|
2009-07-22 13:27:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void clear() {
|
2009-10-02 18:28:55 +02:00
|
|
|
// this.leftPane = null;
|
|
|
|
|
// this.ganttPanel = null;
|
|
|
|
|
// getChildren().clear();
|
2009-07-16 10:40:57 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-22 18:43:31 +02:00
|
|
|
private <T> List<CommandOnTaskContextualized<T>> contextualize(
|
|
|
|
|
FunctionalityExposedForExtensions<T> context,
|
|
|
|
|
List<ICommandOnTask<T>> commands) {
|
|
|
|
|
List<CommandOnTaskContextualized<T>> result = new ArrayList<CommandOnTaskContextualized<T>>();
|
|
|
|
|
for (ICommandOnTask<T> c : commands) {
|
2009-07-28 12:28:47 +02:00
|
|
|
result.add(contextualize(context, c));
|
2009-07-22 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-28 12:28:47 +02:00
|
|
|
private <T> CommandOnTaskContextualized<T> contextualize(
|
|
|
|
|
FunctionalityExposedForExtensions<T> context,
|
|
|
|
|
ICommandOnTask<T> commandOnTask) {
|
|
|
|
|
return CommandOnTaskContextualized.create(commandOnTask, context
|
|
|
|
|
.getMapper(), context);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-22 18:43:31 +02:00
|
|
|
private <T> CommandContextualized<T> contextualize(IContext<T> context,
|
|
|
|
|
ICommand<T> command) {
|
2009-07-28 12:28:47 +02:00
|
|
|
if (command == null)
|
|
|
|
|
return null;
|
2009-07-20 15:37:42 +02:00
|
|
|
return CommandContextualized.create(command, context);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-20 15:37:41 +02:00
|
|
|
private <T> List<CommandContextualized<T>> contextualize(
|
2009-07-22 18:43:31 +02:00
|
|
|
IContext<T> context, Collection<? extends ICommand<T>> commands) {
|
2009-07-20 15:37:41 +02:00
|
|
|
ArrayList<CommandContextualized<T>> result = new ArrayList<CommandContextualized<T>>();
|
|
|
|
|
for (ICommand<T> command : commands) {
|
2009-07-20 15:37:42 +02:00
|
|
|
result.add(contextualize(context, command));
|
2009-07-20 15:37:40 +02:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-16 10:41:03 +02:00
|
|
|
public GanttDiagramGraph getGanttDiagramGraph() {
|
|
|
|
|
return diagramGraph;
|
2009-04-27 15:57:33 +02:00
|
|
|
}
|
|
|
|
|
|
2009-09-30 19:07:03 +02:00
|
|
|
private void setupComponents() {
|
2009-07-22 18:43:32 +02:00
|
|
|
this.leftPane = new LeftPane(contextualizedGlobalCommands,
|
|
|
|
|
this.diagramGraph.getTopLevelTasks());
|
2009-08-18 12:26:56 +02:00
|
|
|
this.ganttPanel = new GanttPanel(this.context,
|
2009-07-28 12:28:47 +02:00
|
|
|
commandsOnTasksContextualized, editTaskCommand);
|
2009-10-02 18:28:55 +02:00
|
|
|
// leftPane.setParent(this);
|
|
|
|
|
// ganttPanel.setParent(this);
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
2009-07-22 18:43:32 +02:00
|
|
|
|
|
|
|
|
void removeTask(Task task) {
|
|
|
|
|
TaskList taskList = getTaskList();
|
|
|
|
|
taskList.remove(task);
|
2009-09-30 23:26:32 +02:00
|
|
|
getDependencyList().taskRemoved(task);
|
2009-07-22 18:43:32 +02:00
|
|
|
leftPane.taskRemoved(task);
|
|
|
|
|
setHeight(getHeight());// forcing smart update
|
|
|
|
|
taskList.adjustZoomColumnsHeight();
|
|
|
|
|
getDependencyList().redrawDependencies();
|
|
|
|
|
}
|
2009-09-01 11:30:02 +02:00
|
|
|
|
|
|
|
|
private IScriptsRegister getScriptsRegister() {
|
|
|
|
|
return OnZKDesktopRegistry.getLocatorFor(IScriptsRegister.class)
|
|
|
|
|
.retrieve();
|
|
|
|
|
}
|
2009-10-02 18:28:55 +02:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterCompose() {
|
|
|
|
|
super.afterCompose();
|
|
|
|
|
getFellow("insertionPointLeftPanel")
|
|
|
|
|
.appendChild(new Label("Left Pane"));
|
|
|
|
|
// leftPane);
|
|
|
|
|
|
|
|
|
|
// leftPane.afterCompose();
|
|
|
|
|
// ganttPanel.afterCompose();
|
|
|
|
|
|
|
|
|
|
// this.leftPane
|
|
|
|
|
// .setGoingDownInLastArrowCommand(goingDownInLastArrowCommand);
|
|
|
|
|
|
|
|
|
|
// leftPane.afterCompose();
|
|
|
|
|
|
|
|
|
|
getFellow("insertionPointRightPanel").appendChild(
|
|
|
|
|
new Label("Timetracker"));
|
|
|
|
|
// timeTrackerComponent);
|
|
|
|
|
// getFellow("insertionPointRightPanel").appendChild(resourceLoadList);
|
|
|
|
|
// TimeTrackerComponent timetrackerheader = (TimeTrackerComponent)
|
|
|
|
|
// timeTrackerComponent .clone();
|
|
|
|
|
// getFellow("insertionPointTimetracker").
|
|
|
|
|
// appendChild(timetrackerheader);
|
|
|
|
|
// timetrackerheader.afterCompose();
|
|
|
|
|
// timeTrackerComponent.afterCompose();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|