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-11-02 19:58:43 +01:00
|
|
|
import org.zkoss.ganttz.adapters.IDisabilityConfiguration;
|
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-10-06 16:03:03 +02:00
|
|
|
import org.zkoss.ganttz.timetracker.TimeTracker;
|
2009-10-14 09:10:05 +02:00
|
|
|
import org.zkoss.ganttz.timetracker.TimeTrackerComponent;
|
|
|
|
|
import org.zkoss.ganttz.timetracker.TimeTrackerComponentWithoutColumns;
|
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-10-05 18:23:09 +02:00
|
|
|
import org.zkoss.zk.ui.Component;
|
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;
|
2009-10-05 18:23:09 +02:00
|
|
|
import org.zkoss.zul.Separator;
|
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-11-07 14:05:13 +01:00
|
|
|
private GanttDiagramGraph diagramGraph;
|
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-11-04 00:36:09 +01:00
|
|
|
private transient IDisabilityConfiguration disabilityConfiguration;
|
2009-10-14 07:50:17 +02:00
|
|
|
|
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-11-03 20:38:03 +01:00
|
|
|
if (ganttPanel == null) {
|
2009-07-20 15:37:41 +02:00
|
|
|
return null;
|
2009-11-03 20:38:03 +01:00
|
|
|
}
|
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-11-03 20:38:03 +01:00
|
|
|
if (ganttPanel == null) {
|
2009-07-26 16:17:52 +02:00
|
|
|
return null;
|
2009-11-03 20:38:03 +01:00
|
|
|
}
|
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);
|
2009-11-03 20:38:03 +01:00
|
|
|
if (found.isEmpty()) {
|
2009-04-29 18:35:19 +02:00
|
|
|
return null;
|
2009-11-03 20:38:03 +01:00
|
|
|
}
|
2009-04-29 18:35:19 +02:00
|
|
|
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-10-05 18:09:13 +02:00
|
|
|
public void zoomIncrease() {
|
|
|
|
|
if (ganttPanel == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ganttPanel.zoomIncrease();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void zoomDecrease() {
|
|
|
|
|
if (ganttPanel == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ganttPanel.zoomDecrease();
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-16 10:40:57 +02:00
|
|
|
public <T> void setConfiguration(PlannerConfiguration<T> configuration) {
|
2009-11-03 20:38:03 +01:00
|
|
|
if (configuration == null) {
|
2009-07-16 10:40:58 +02:00
|
|
|
return;
|
2009-11-03 20:38:03 +01:00
|
|
|
}
|
2009-11-07 16:08:47 +01:00
|
|
|
this.diagramGraph = new GanttDiagramGraph(configuration
|
2009-11-08 23:41:44 +01:00
|
|
|
.getStartConstraints(), configuration.getEndConstraints(),
|
|
|
|
|
configuration.isDependenciesConstraintsHavePriority());
|
2009-11-04 00:28:29 +01:00
|
|
|
FunctionalityExposedForExtensions<T> newContext = new FunctionalityExposedForExtensions<T>(
|
2009-07-20 15:37:41 +02:00
|
|
|
this, configuration.getAdapter(), configuration.getNavigator(),
|
|
|
|
|
diagramGraph);
|
2009-11-04 00:28:29 +01:00
|
|
|
this.contextualizedGlobalCommands = contextualize(newContext,
|
2009-07-22 18:43:31 +02:00
|
|
|
configuration.getGlobalCommands());
|
2009-11-04 00:28:29 +01:00
|
|
|
this.commandsOnTasksContextualized = contextualize(newContext,
|
2009-07-22 18:43:31 +02:00
|
|
|
configuration.getCommandsOnTasks());
|
2009-11-04 00:28:29 +01:00
|
|
|
goingDownInLastArrowCommand = contextualize(newContext, configuration
|
2009-07-20 15:37:42 +02:00
|
|
|
.getGoingDownInLastArrowCommand());
|
2009-11-04 00:28:29 +01:00
|
|
|
editTaskCommand = contextualize(newContext, configuration
|
2009-07-28 12:28:47 +02:00
|
|
|
.getEditTaskCommand());
|
2009-11-04 00:28:29 +01:00
|
|
|
this.context = newContext;
|
2009-11-02 19:58:43 +01:00
|
|
|
this.disabilityConfiguration = configuration;
|
2009-11-04 00:28:29 +01:00
|
|
|
newContext.add(configuration.getData());
|
2009-09-30 19:07:03 +02:00
|
|
|
setupComponents();
|
2009-10-02 18:28:56 +02:00
|
|
|
|
2009-10-14 00:20:56 +02:00
|
|
|
setAt("insertionPointLeftPanel", leftPane);
|
2009-10-02 18:28:56 +02:00
|
|
|
leftPane.afterCompose();
|
2009-10-14 00:20:56 +02:00
|
|
|
setAt("insertionPointRightPanel", ganttPanel);
|
2009-10-02 18:28:56 +02:00
|
|
|
ganttPanel.afterCompose();
|
2009-10-06 16:02:58 +02:00
|
|
|
|
2009-10-14 09:10:05 +02:00
|
|
|
TimeTrackerComponent timetrackerheader = new TimeTrackerComponentWithoutColumns(
|
2009-10-15 17:36:23 +02:00
|
|
|
ganttPanel.getTimeTracker(), "timetrackerheader");
|
2009-10-14 09:10:05 +02:00
|
|
|
|
|
|
|
|
setAt("insertionPointTimetracker", timetrackerheader);
|
|
|
|
|
timetrackerheader.afterCompose();
|
|
|
|
|
|
2009-10-06 16:02:58 +02:00
|
|
|
Component chartComponent = configuration.getChartComponent();
|
|
|
|
|
if (chartComponent != null) {
|
2009-10-14 13:14:14 +02:00
|
|
|
setAt("insertionPointChart", chartComponent);
|
2009-10-06 16:02:58 +02:00
|
|
|
}
|
2009-10-14 07:50:17 +02:00
|
|
|
|
2009-12-03 13:06:46 +01:00
|
|
|
this.context.showCriticalPath();
|
2009-07-22 13:27:22 +02:00
|
|
|
}
|
|
|
|
|
|
2009-10-14 00:20:56 +02:00
|
|
|
private void setAt(String insertionPointId, Component component) {
|
|
|
|
|
Component insertionPoint = getFellow(insertionPointId);
|
|
|
|
|
insertionPoint.getChildren().clear();
|
|
|
|
|
insertionPoint.appendChild(component);
|
|
|
|
|
}
|
|
|
|
|
|
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-11-03 20:38:03 +01:00
|
|
|
if (command == null) {
|
2009-07-28 12:28:47 +02:00
|
|
|
return null;
|
2009-11-03 20:38:03 +01:00
|
|
|
}
|
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-09-30 19:07:03 +02:00
|
|
|
private void setupComponents() {
|
2009-10-05 18:23:09 +02:00
|
|
|
insertGlobalCommands();
|
|
|
|
|
this.leftPane = new LeftPane(this.diagramGraph.getTopLevelTasks());
|
2009-08-18 12:26:56 +02:00
|
|
|
this.ganttPanel = new GanttPanel(this.context,
|
2009-10-14 07:50:17 +02:00
|
|
|
commandsOnTasksContextualized, editTaskCommand,
|
2009-11-02 19:58:43 +01:00
|
|
|
disabilityConfiguration);
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
2009-07-22 18:43:32 +02:00
|
|
|
|
2009-10-14 00:20:56 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2009-10-05 18:23:09 +02:00
|
|
|
private void insertGlobalCommands() {
|
|
|
|
|
Component toolbar = getToolbar();
|
|
|
|
|
Component firstSeparator = getFirstSeparatorFromToolbar();
|
2009-10-14 00:20:56 +02:00
|
|
|
toolbar.getChildren().removeAll(getBefore(toolbar, firstSeparator));
|
2009-10-05 18:23:09 +02:00
|
|
|
for (CommandContextualized<?> c : contextualizedGlobalCommands) {
|
|
|
|
|
toolbar.insertBefore(c.toButton(), firstSeparator);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-14 00:20:56 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
private List<Component> getBefore(Component parent, Component child) {
|
|
|
|
|
List<Component> children = parent.getChildren();
|
|
|
|
|
List<Component> result = new ArrayList<Component>();
|
|
|
|
|
for (Component object : children) {
|
|
|
|
|
if (object == child) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
result.add(object);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-05 18:23:09 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
private Component getFirstSeparatorFromToolbar() {
|
|
|
|
|
Component toolbar = getToolbar();
|
|
|
|
|
List<Component> children = toolbar.getChildren();
|
|
|
|
|
List<Separator> separators = ComponentsFinder
|
|
|
|
|
.findComponentsOfType(
|
|
|
|
|
Separator.class, children);
|
|
|
|
|
return separators.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Component getToolbar() {
|
|
|
|
|
Component toolbar = getFellow("toolbar");
|
|
|
|
|
return toolbar;
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-06 16:03:03 +02:00
|
|
|
public TimeTracker getTimeTracker() {
|
|
|
|
|
return ganttPanel.getTimeTracker();
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-06 16:02:57 +02:00
|
|
|
}
|