/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 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 .
*/
package org.zkoss.ganttz;
import static org.zkoss.ganttz.i18n.I18nHelper._;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.zkoss.ganttz.adapters.IDisabilityConfiguration;
import org.zkoss.ganttz.adapters.IDomainAndBeansMapper;
import org.zkoss.ganttz.adapters.PlannerConfiguration;
import org.zkoss.ganttz.data.Dependency;
import org.zkoss.ganttz.data.GanttDiagramGraph;
import org.zkoss.ganttz.data.Position;
import org.zkoss.ganttz.data.Task;
import org.zkoss.ganttz.data.GanttDiagramGraph.GanttZKDiagramGraph;
import org.zkoss.ganttz.data.GanttDiagramGraph.IGraphChangeListener;
import org.zkoss.ganttz.extensions.ICommand;
import org.zkoss.ganttz.extensions.ICommandOnTask;
import org.zkoss.ganttz.extensions.IContext;
import org.zkoss.ganttz.timetracker.TimeTracker;
import org.zkoss.ganttz.timetracker.TimeTrackerComponent;
import org.zkoss.ganttz.timetracker.TimeTrackerComponentWithoutColumns;
import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
import org.zkoss.ganttz.util.ComponentsFinder;
import org.zkoss.ganttz.util.LongOperationFeedback;
import org.zkoss.ganttz.util.OnZKDesktopRegistry;
import org.zkoss.ganttz.util.WeakReferencedListeners;
import org.zkoss.ganttz.util.LongOperationFeedback.ILongOperation;
import org.zkoss.ganttz.util.WeakReferencedListeners.IListenerNotification;
import org.zkoss.ganttz.util.script.IScriptsRegister;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.HtmlMacroComponent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zkex.zul.api.South;
import org.zkoss.zul.Button;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Separator;
import org.zkoss.zul.SimpleListModel;
public class Planner extends HtmlMacroComponent {
public static void registerNeededScripts() {
IScriptsRegister register = getScriptsRegister();
register.register(ScriptsRequiredByPlanner.class);
}
private static IScriptsRegister getScriptsRegister() {
return OnZKDesktopRegistry.getLocatorFor(IScriptsRegister.class)
.retrieve();
}
public static boolean guessContainersExpandedByDefaultGivenPrintParameters(
Map printParameters) {
return guessContainersExpandedByDefault(convertToURLParameters(printParameters));
}
private static Map convertToURLParameters(
Map printParameters) {
Map result = new HashMap();
for (Entry each : printParameters.entrySet()) {
result.put(each.getKey(), new String[] { each.getValue() });
}
return result;
}
public static boolean guessContainersExpandedByDefault(
Map queryURLParameters) {
String[] values = queryURLParameters.get("expanded");
if (values == null) {
return false;
}
return toLowercaseSet(values).contains("all");
}
private static Set toLowercaseSet(String[] values) {
Set result = new HashSet();
for (String each : values) {
result.add(each.toLowerCase());
}
return result;
}
private GanttZKDiagramGraph diagramGraph;
private LeftPane leftPane;
private GanttPanel ganttPanel;
private boolean fixedZoomByUser = false;
private List extends CommandContextualized>> contextualizedGlobalCommands;
private CommandContextualized> goingDownInLastArrowCommand;
private List extends CommandOnTaskContextualized>> commandsOnTasksContextualized;
private CommandOnTaskContextualized> doubleClickCommand;
private FunctionalityExposedForExtensions> context;
private transient IDisabilityConfiguration disabilityConfiguration;
private boolean isShowingCriticalPath = false;
private boolean isShowingLabels = false;
private boolean isShowingResources = false;
private boolean isFlattenTree = false;
private ZoomLevel initialZoomLevel = null;
private Listbox listZoomLevels = null;
private WeakReferencedListeners chartVisibilityListeners = WeakReferencedListeners
.create();
public Planner() {
registerNeededScripts();
}
TaskList getTaskList() {
if (ganttPanel == null) {
return null;
}
List