ItEr13S14ArquitecturaClientesItEr11S12: It loads data from a graph instead of markup.
This commit is contained in:
parent
1bab9464c6
commit
3e8165ab96
14 changed files with 326 additions and 248 deletions
|
|
@ -22,9 +22,7 @@ import org.zkoss.zul.Menupopup;
|
|||
import org.zkoss.zul.impl.XulElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francisco Javier Moran Rúa
|
||||
*
|
||||
*/
|
||||
public class DependencyList extends XulElement implements AfterCompose {
|
||||
|
||||
|
|
@ -48,7 +46,6 @@ public class DependencyList extends XulElement implements AfterCompose {
|
|||
void addDependency(Dependency dependency) {
|
||||
appendChild(dependency);
|
||||
addContextMenu(dependency);
|
||||
publishDependency(dependency);
|
||||
}
|
||||
|
||||
private void addContextMenu(Dependency dependency) {
|
||||
|
|
@ -59,6 +56,12 @@ public class DependencyList extends XulElement implements AfterCompose {
|
|||
return (GanttPanel) getParent();
|
||||
}
|
||||
|
||||
public void setDependencies(List<Dependency> dependencies) {
|
||||
for (Dependency dependency : dependencies) {
|
||||
addDependency(dependency);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompose() {
|
||||
if (listener == null) {
|
||||
|
|
@ -90,24 +93,9 @@ public class DependencyList extends XulElement implements AfterCompose {
|
|||
taskRemovedListener);
|
||||
}
|
||||
addContextMenu();
|
||||
publishDependencies();
|
||||
|
||||
}
|
||||
|
||||
private void publishDependencies() {
|
||||
for (Dependency dependency : getDependencies()) {
|
||||
publishDependency(dependency);
|
||||
}
|
||||
}
|
||||
|
||||
private void publishDependency(Dependency dependency) {
|
||||
getPlanner().publishDependency(dependency);
|
||||
}
|
||||
|
||||
private Planner getPlanner() {
|
||||
return getGanttPanel().getPlanner();
|
||||
}
|
||||
|
||||
private void addContextMenu() {
|
||||
for (Dependency dependency : getDependencies()) {
|
||||
addContextMenu(dependency);
|
||||
|
|
|
|||
|
|
@ -1,25 +1,48 @@
|
|||
package org.zkoss.ganttz;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.ganttz.util.DependencyRegistry;
|
||||
import org.zkoss.zk.ui.ext.AfterCompose;
|
||||
import org.zkoss.zul.impl.XulElement;
|
||||
|
||||
public class GanttPanel extends XulElement {
|
||||
public class GanttPanel extends XulElement implements AfterCompose {
|
||||
|
||||
private TaskList tasksLists;
|
||||
|
||||
private TimeTracker timeTracker;
|
||||
|
||||
private DependencyList dependencyList;
|
||||
|
||||
private final DependencyRegistry dependencyRegistry;
|
||||
|
||||
public GanttPanel(DependencyRegistry dependencyRegistry) {
|
||||
this.dependencyRegistry = dependencyRegistry;
|
||||
timeTracker = new TimeTracker();
|
||||
appendChild(timeTracker);
|
||||
tasksLists = TaskList.createFor(dependencyRegistry.getTasks());
|
||||
dependencyList = new DependencyList();
|
||||
appendChild(tasksLists);
|
||||
appendChild(dependencyList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompose() {
|
||||
tasksLists.afterCompose();
|
||||
dependencyList.setDependencies(tasksLists
|
||||
.asDependencies(dependencyRegistry.getDependencies()));
|
||||
timeTracker.afterCompose();
|
||||
dependencyList.afterCompose();
|
||||
}
|
||||
|
||||
public TimeTracker getTimeTracker() {
|
||||
List<Object> children = getChildren();
|
||||
return Planner.findComponentsOfType(TimeTracker.class, children).get(0);
|
||||
return timeTracker;
|
||||
}
|
||||
|
||||
public TaskList getTaskList() {
|
||||
List<Object> children = getChildren();
|
||||
return Planner.findComponentsOfType(TaskList.class, children).get(0);
|
||||
return tasksLists;
|
||||
}
|
||||
|
||||
public DependencyList getDependencyList() {
|
||||
List<Object> children = getChildren();
|
||||
return Planner.findComponentsOfType(DependencyList.class, children)
|
||||
.get(0);
|
||||
return dependencyList;
|
||||
}
|
||||
|
||||
public Planner getPlanner() {
|
||||
|
|
|
|||
|
|
@ -1,22 +1,25 @@
|
|||
package org.zkoss.ganttz;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.zkoss.util.resource.Labels;
|
||||
import org.zkoss.ganttz.util.TaskBean;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.HtmlMacroComponent;
|
||||
|
||||
public class ListDetails extends HtmlMacroComponent {
|
||||
|
||||
private static Log LOG = LogFactory.getLog(ListDetails.class);
|
||||
|
||||
private TaskRemovedListener taskRemovedListener;
|
||||
|
||||
public ListDetails() {
|
||||
LOG.info("constructing list details");
|
||||
private final List<TaskBean> taskBeans;
|
||||
|
||||
public ListDetails(List<TaskBean> taskBeans) {
|
||||
this.taskBeans = taskBeans;
|
||||
}
|
||||
|
||||
Planner getPlanner() {
|
||||
|
|
@ -28,10 +31,10 @@ public class ListDetails extends HtmlMacroComponent {
|
|||
return Planner.findComponentsOfType(TaskDetail.class, children);
|
||||
}
|
||||
|
||||
public void taskRemoved(Task taskRemoved) {
|
||||
public void taskRemoved(TaskBean taskRemoved) {
|
||||
List<TaskDetail> taskDetails = getTaskDetails();
|
||||
for (TaskDetail taskDetail : taskDetails) {
|
||||
if (taskDetail.getTaskId().equals(taskRemoved.getId())) {
|
||||
if (taskDetail.getTaskBean().equals(taskRemoved)) {
|
||||
removeDetail(taskDetail);
|
||||
return;
|
||||
}
|
||||
|
|
@ -44,20 +47,34 @@ public class ListDetails extends HtmlMacroComponent {
|
|||
}
|
||||
|
||||
public void addTask() {
|
||||
TaskDetail taskDetail = new TaskDetail();
|
||||
String newId = UUID.randomUUID().toString();
|
||||
taskDetail.setTaskId(newId);
|
||||
taskDetail.setDynamicProperty("start", TaskDetail.format(new Date()));
|
||||
taskDetail.setDynamicProperty("length", "30 days");
|
||||
taskDetail.setDynamicProperty("taskName", Labels
|
||||
.getLabel("task.new_task_name"));
|
||||
Component insertionPoint = getInsertionPoint();
|
||||
taskDetail.setParent(insertionPoint);
|
||||
TaskBean newTask = new TaskBean();
|
||||
newTask.setName("Nova Tarefa");
|
||||
newTask.setBeginDate(new Date());
|
||||
newTask.setEndDate(threeMonthsLater(newTask.getBeginDate()));
|
||||
System.out.println(newTask.getEndDate());
|
||||
addTask(newTask);
|
||||
getPlanner().addTask(newTask);
|
||||
}
|
||||
|
||||
private static Date threeMonthsLater(Date now) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(now);
|
||||
calendar.add(Calendar.MONTH, 3);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompose() {
|
||||
super.afterCompose();
|
||||
for (TaskBean taskBean : taskBeans) {
|
||||
addTask(taskBean);
|
||||
}
|
||||
}
|
||||
|
||||
private void addTask(TaskBean taskBean) {
|
||||
TaskDetail taskDetail = TaskDetail.create(taskBean);
|
||||
getInsertionPoint().appendChild(taskDetail);
|
||||
taskDetail.afterCompose();
|
||||
Task task = new Task();
|
||||
getPlanner().addTask(task);
|
||||
task.setColor("#007bbe");
|
||||
task.setId(newId);
|
||||
}
|
||||
|
||||
private Component getInsertionPoint() {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
package org.zkoss.ganttz;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.zkoss.ganttz.util.DependencyRegistry;
|
||||
import org.zkoss.ganttz.util.TaskBean;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.ext.AfterCompose;
|
||||
import org.zkoss.zul.impl.XulElement;
|
||||
|
|
@ -15,14 +14,16 @@ public class Planner extends XulElement implements AfterCompose {
|
|||
|
||||
private DependencyAddedListener dependencyAddedListener;
|
||||
|
||||
private Map<String, TaskBean> tasksById = new HashMap<String, TaskBean>();
|
||||
|
||||
private DependencyRegistry dependencyRegistry = new DependencyRegistry();
|
||||
|
||||
private DependencyRemovedListener dependencyRemovedListener;
|
||||
|
||||
private TaskRemovedListener taskRemovedListener;
|
||||
|
||||
private ListDetails listDetails;
|
||||
|
||||
private GanttPanel ganttPanel;
|
||||
|
||||
public Planner() {
|
||||
}
|
||||
|
||||
|
|
@ -42,22 +43,6 @@ public class Planner extends XulElement implements AfterCompose {
|
|||
return result.get(0);
|
||||
}
|
||||
|
||||
void publish(String taskId, TaskBean task) {
|
||||
if (taskId == null)
|
||||
throw new IllegalArgumentException("taskId cannot be null");
|
||||
if (task == null)
|
||||
throw new IllegalArgumentException("task cannot be null");
|
||||
if (tasksById.containsKey(taskId))
|
||||
throw new IllegalArgumentException("task with id " + taskId
|
||||
+ " is already in " + tasksById);
|
||||
tasksById.put(taskId, task);
|
||||
dependencyRegistry.add(task);
|
||||
}
|
||||
|
||||
TaskBean retrieve(String taskId) {
|
||||
return tasksById.get(taskId);
|
||||
}
|
||||
|
||||
public static <T> List<T> findComponentsOfType(Class<T> type,
|
||||
List<? extends Object> children) {
|
||||
ArrayList<T> result = new ArrayList<T>();
|
||||
|
|
@ -73,12 +58,16 @@ public class Planner extends XulElement implements AfterCompose {
|
|||
return Executions.getCurrent().getContextPath();
|
||||
}
|
||||
|
||||
private GanttPanel getGanntPanel() {
|
||||
return findOneComponentOfType(GanttPanel.class);
|
||||
private void removePreviousGanntPanel() {
|
||||
List<Object> children = getChildren();
|
||||
for (GanttPanel ganttPanel : findComponentsOfType(GanttPanel.class,
|
||||
children)) {
|
||||
removeChild(ganttPanel);
|
||||
}
|
||||
}
|
||||
|
||||
public DependencyList getDependencyList() {
|
||||
List<Object> children = getGanntPanel().getChildren();
|
||||
List<Object> children = ganttPanel.getChildren();
|
||||
List<DependencyList> found = findComponentsOfType(DependencyList.class,
|
||||
children);
|
||||
if (found.isEmpty())
|
||||
|
|
@ -86,18 +75,29 @@ public class Planner extends XulElement implements AfterCompose {
|
|||
return found.get(0);
|
||||
}
|
||||
|
||||
private ListDetails getDetails() {
|
||||
private void removePreviousDetails() {
|
||||
List<Object> children = getChildren();
|
||||
return Planner.findComponentsOfType(ListDetails.class, children).get(0);
|
||||
for (ListDetails l : Planner.findComponentsOfType(ListDetails.class,
|
||||
children)) {
|
||||
removeChild(l);
|
||||
}
|
||||
}
|
||||
|
||||
public TaskEditFormComposer getModalFormComposer() {
|
||||
return getTaskList().getModalFormComposer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompose() {
|
||||
if (dependencyRegistry == null)
|
||||
throw new IllegalStateException("dependencyRegistry must be set");
|
||||
ganttPanel.afterCompose();
|
||||
TaskList taskList = getTaskList();
|
||||
dependencyAddedListener = new DependencyAddedListener() {
|
||||
@Override
|
||||
public void dependenceAdded(Dependency dependency) {
|
||||
getDependencyList().addDependency(dependency);
|
||||
publishDependency(dependency);
|
||||
}
|
||||
};
|
||||
taskList.addDependencyListener(dependencyAddedListener);
|
||||
|
|
@ -105,8 +105,8 @@ public class Planner extends XulElement implements AfterCompose {
|
|||
@Override
|
||||
public void taskRemoved(Task taskRemoved) {
|
||||
dependencyRegistry.remove(taskRemoved.getTaskBean());
|
||||
getDetails().taskRemoved(taskRemoved);
|
||||
getGanntPanel().invalidate();
|
||||
listDetails.taskRemoved(taskRemoved.getTaskBean());
|
||||
ganttPanel.invalidate();
|
||||
}
|
||||
};
|
||||
taskList.addTaskRemovedListener(taskRemovedListener);
|
||||
|
|
@ -121,12 +121,31 @@ public class Planner extends XulElement implements AfterCompose {
|
|||
dependencyRemovedListener);
|
||||
}
|
||||
|
||||
public void addTask(Task task) {
|
||||
getTaskList().addTask(task);
|
||||
public void addTask(TaskBean newTask) {
|
||||
getTaskList().addTask(newTask);
|
||||
getDependencyList().invalidate();
|
||||
dependencyRegistry.add(newTask);
|
||||
}
|
||||
|
||||
public void publishDependency(Dependency dependency) {
|
||||
dependencyRegistry.add(dependency);
|
||||
private void publishDependency(Dependency dependency) {
|
||||
dependencyRegistry.add(dependency.getDependencyBean());
|
||||
}
|
||||
|
||||
public DependencyRegistry getDependencyRegistry() {
|
||||
return dependencyRegistry;
|
||||
}
|
||||
|
||||
public void setDependencyRegistry(DependencyRegistry dependencyRegistry) {
|
||||
this.dependencyRegistry = dependencyRegistry;
|
||||
removePreviousDetails();
|
||||
this.listDetails = new ListDetails(dependencyRegistry.getTasks());
|
||||
insertBefore(this.listDetails,
|
||||
(Component) (getChildren().isEmpty() ? null : getChildren()
|
||||
.get(0)));
|
||||
this.listDetails.afterCompose();
|
||||
removePreviousGanntPanel();
|
||||
this.ganttPanel = new GanttPanel(this.dependencyRegistry);
|
||||
appendChild(ganttPanel);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import java.util.ArrayList;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
|
@ -27,13 +28,13 @@ import org.zkoss.zk.ui.Component;
|
|||
import org.zkoss.zk.ui.UiException;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
import org.zkoss.zk.ui.ext.AfterCompose;
|
||||
import org.zkoss.zul.Div;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author javi
|
||||
*/
|
||||
public class Task extends Div {
|
||||
public class Task extends Div implements AfterCompose {
|
||||
|
||||
private static Pattern pixelsSpecificationPattern = Pattern
|
||||
.compile("\\s*(\\d+)px\\s*;?\\s*");
|
||||
|
|
@ -122,16 +123,34 @@ public class Task extends Div {
|
|||
}
|
||||
};
|
||||
|
||||
public Task() {
|
||||
public static Task asTask(TaskBean taskBean) {
|
||||
return new Task(taskBean);
|
||||
}
|
||||
|
||||
public Task(TaskBean taskBean) {
|
||||
setHeight("20px"); /* Initial constant for standard task height */
|
||||
setContext("idContextMenuTaskAssigment");
|
||||
this.taskBean = taskBean;
|
||||
setColor("#007bbe");
|
||||
setId(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
public void afterCompose() {
|
||||
updateProperties();
|
||||
this.taskBean.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
updateProperties();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String _color;
|
||||
|
||||
private List<WeakReference<DependencyAddedListener>> dependencyListeners = new LinkedList<WeakReference<DependencyAddedListener>>();
|
||||
|
||||
private TaskBean taskBean;
|
||||
private final TaskBean taskBean;
|
||||
|
||||
public TaskBean getTaskBean() {
|
||||
return taskBean;
|
||||
|
|
@ -141,22 +160,6 @@ public class Task extends Div {
|
|||
return taskBean.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
super.setId(id);
|
||||
if (taskBean != null)
|
||||
throw new IllegalStateException("taskBean already set");
|
||||
taskBean = getPlanner().retrieve(id);
|
||||
updateProperties();
|
||||
taskBean.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
updateProperties();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getLength() {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -202,12 +205,10 @@ public class Task extends Div {
|
|||
|
||||
// Command action to do
|
||||
void doUpdatePosition(String leftX, String topY) {
|
||||
System.out.println("leftX:" + getLeft() + "newLeft:" + leftX);
|
||||
this.taskBean.setBeginDate(getMapper().toDate(stripPx(leftX)));
|
||||
}
|
||||
|
||||
void doUpdateSize(String size) {
|
||||
System.out.println("size:" + getWidth() + "newWidth:" + size);
|
||||
int pixels = stripPx(size);
|
||||
this.taskBean.setLengthMilliseconds(getMapper().toMilliseconds(pixels));
|
||||
}
|
||||
|
|
@ -303,5 +304,4 @@ public class Task extends Div {
|
|||
getTaskList().removeTask(this);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package org.zkoss.ganttz;
|
|||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
|
@ -15,7 +14,6 @@ import java.util.regex.Pattern;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.zkoss.ganttz.util.TaskBean;
|
||||
import org.zkoss.zk.ui.AbstractComponent;
|
||||
import org.zkoss.zk.ui.HtmlMacroComponent;
|
||||
import org.zkoss.zk.ui.ext.AfterCompose;
|
||||
import org.zkoss.zul.Datebox;
|
||||
|
|
@ -23,18 +21,6 @@ import org.zkoss.zul.Textbox;
|
|||
|
||||
public class TaskDetail extends HtmlMacroComponent implements AfterCompose {
|
||||
|
||||
private static long parseLength(String length) {
|
||||
return LengthType.getTimeInMilliseconds(length);
|
||||
}
|
||||
|
||||
private static Date parseStartDate(String start) {
|
||||
try {
|
||||
return dateFormat.parse(start);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
static String format(Date date) {
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
|
@ -77,7 +63,7 @@ public class TaskDetail extends HtmlMacroComponent implements AfterCompose {
|
|||
|
||||
private String taskId;
|
||||
|
||||
private TaskBean taskBean;
|
||||
private final TaskBean taskBean;
|
||||
|
||||
public TaskBean getTaskBean() {
|
||||
return taskBean;
|
||||
|
|
@ -116,37 +102,21 @@ public class TaskDetail extends HtmlMacroComponent implements AfterCompose {
|
|||
|
||||
private Datebox endDateBox;
|
||||
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
public static TaskDetail create(TaskBean bean) {
|
||||
return new TaskDetail(bean);
|
||||
}
|
||||
|
||||
public void setTaskId(String taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public TaskDetail() {
|
||||
LOG.info("Detail component constructor");
|
||||
private TaskDetail(TaskBean task) {
|
||||
this.taskBean = task;
|
||||
}
|
||||
|
||||
public TaskBean getData() {
|
||||
return taskBean;
|
||||
}
|
||||
|
||||
private Planner getPlanner() {
|
||||
AbstractComponent parent = (AbstractComponent) getParent();
|
||||
while (!(parent instanceof ListDetails)) {
|
||||
parent = (AbstractComponent) parent.getParent();
|
||||
}
|
||||
return ((ListDetails) parent).getPlanner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompose() {
|
||||
super.afterCompose();
|
||||
taskBean = new TaskBean((String) getDynamicProperty("taskName"),
|
||||
parseStartDate((String) getDynamicProperty("start")),
|
||||
parseLength((String) getDynamicProperty("length")));
|
||||
getPlanner().publish(taskId, taskBean);
|
||||
updateComponents();
|
||||
taskBean.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
|
||||
|
|
@ -172,4 +142,5 @@ public class TaskDetail extends HtmlMacroComponent implements AfterCompose {
|
|||
getStartDateBox().setValue(taskBean.getBeginDate());
|
||||
getEndDateBox().setValue(taskBean.getEndDate());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,15 @@ package org.zkoss.ganttz;
|
|||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.zkoss.ganttz.util.DependencyBean;
|
||||
import org.zkoss.ganttz.util.MenuBuilder;
|
||||
import org.zkoss.ganttz.util.TaskBean;
|
||||
import org.zkoss.ganttz.util.WeakReferencedListeners;
|
||||
import org.zkoss.ganttz.util.MenuBuilder.ItemAction;
|
||||
import org.zkoss.ganttz.util.WeakReferencedListeners.ListenerNotification;
|
||||
|
|
@ -26,9 +30,8 @@ import org.zkoss.zul.Menupopup;
|
|||
import org.zkoss.zul.impl.XulElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francisco Javier Moran Rúa
|
||||
*
|
||||
* Component to show the list of task in the planner
|
||||
* @author Javier Moran Rua <jmoran@igalia.com>
|
||||
*/
|
||||
public class TaskList extends XulElement implements AfterCompose {
|
||||
|
||||
|
|
@ -45,10 +48,40 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
|
||||
private TaskEditFormComposer taskEditFormComposer = new TaskEditFormComposer();
|
||||
|
||||
private List<TaskBean> originalTasks;
|
||||
|
||||
public TaskList(List<TaskBean> tasks) {
|
||||
this.originalTasks = tasks;
|
||||
}
|
||||
|
||||
public static TaskList createFor(List<TaskBean> tasks) {
|
||||
TaskList result = new TaskList(tasks);
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Dependency> asDependencies(List<DependencyBean> dependencies) {
|
||||
List<? extends Object> children = getChildren();
|
||||
List<Task> tasks = Planner.findComponentsOfType(Task.class, children);
|
||||
Map<TaskBean, Task> taskByTaskBean = new HashMap<TaskBean, Task>();
|
||||
for (Task task : tasks) {
|
||||
taskByTaskBean.put(task.getTaskBean(), task);
|
||||
}
|
||||
List<Dependency> result = new ArrayList<Dependency>();
|
||||
for (DependencyBean dependencyBean : dependencies) {
|
||||
result.add(new Dependency(taskByTaskBean.get(dependencyBean
|
||||
.getSource()), taskByTaskBean.get(dependencyBean
|
||||
.getDestination())));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addTask(TaskBean newTask) {
|
||||
addTask(Task.asTask(newTask));
|
||||
}
|
||||
|
||||
public synchronized void addTask(Task task) {
|
||||
task.setParent(this);
|
||||
invalidate();
|
||||
getDependencyList().invalidate();
|
||||
addContextMenu(task);
|
||||
addListenerForTaskEditForm(task);
|
||||
ListIterator<WeakReference<DependencyAddedListener>> iterator = listeners
|
||||
|
|
@ -61,16 +94,7 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DependencyList getDependencyList() {
|
||||
return getGanttPanel().getDependencyList();
|
||||
}
|
||||
|
||||
private void addListenersForTaskEditForm() {
|
||||
for (Task task : getTasks()) {
|
||||
addListenerForTaskEditForm(task);
|
||||
}
|
||||
task.afterCompose();
|
||||
}
|
||||
|
||||
private void addListenerForTaskEditForm(final Task task) {
|
||||
|
|
@ -88,17 +112,15 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
getContextMenuForTasks().open(task);
|
||||
try {
|
||||
getContextMenuForTasks().open(task);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addContextMenu() {
|
||||
for (Task task : getTasks()) {
|
||||
addContextMenu(task);
|
||||
}
|
||||
}
|
||||
|
||||
public void addRemoveListener(TaskRemovedListener listener) {
|
||||
taskRemovedListeners.addListener(listener);
|
||||
}
|
||||
|
|
@ -124,11 +146,13 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
public String getSameHeightElementId() {
|
||||
TimeTracker timeTracker = getTimeTracker();
|
||||
AbstractComponent fakeRow = timeTracker.getFakeRow();
|
||||
if (fakeRow == null)
|
||||
return "";
|
||||
return fakeRow.getUuid();
|
||||
}
|
||||
|
||||
private TimeTracker getTimeTracker() {
|
||||
return (getGanttPanel()).getTimeTracker();
|
||||
return getGanttPanel().getTimeTracker();
|
||||
}
|
||||
|
||||
DatesMapper getMapper() {
|
||||
|
|
@ -162,6 +186,9 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
|
||||
@Override
|
||||
public void afterCompose() {
|
||||
for (TaskBean taskBean : originalTasks) {
|
||||
addTask(Task.asTask(taskBean));
|
||||
}
|
||||
if (zoomLevelChangedListener == null) {
|
||||
zoomLevelChangedListener = new ZoomLevelChangedListener() {
|
||||
@Override
|
||||
|
|
@ -175,8 +202,6 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
};
|
||||
getTimeTracker().addZoomListener(zoomLevelChangedListener);
|
||||
}
|
||||
addListenersForTaskEditForm();
|
||||
addContextMenu();
|
||||
}
|
||||
|
||||
private Menupopup getContextMenuForTasks() {
|
||||
|
|
@ -209,4 +234,5 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
public TaskEditFormComposer getModalFormComposer() {
|
||||
return taskEditFormComposer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,16 +21,13 @@ import org.zkoss.zk.ui.HtmlMacroComponent;
|
|||
import org.zkoss.zul.Label;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Francisco Javier Moran Rúa
|
||||
*
|
||||
* @author Javier Moran Rua <jmoran@igalia.com>
|
||||
*/
|
||||
|
||||
public class TimeTracker extends HtmlMacroComponent {
|
||||
|
||||
private static Interval getTestInterval() {
|
||||
return new Interval(TimeTrackerState.year(2009), TimeTrackerState
|
||||
return new Interval(TimeTrackerState.year(2008), TimeTrackerState
|
||||
.year(2019));
|
||||
}
|
||||
|
||||
|
|
@ -44,6 +41,12 @@ public class TimeTracker extends HtmlMacroComponent {
|
|||
|
||||
private Collection<DetailItem> detailsSecondLevelCached = null;
|
||||
|
||||
private ZoomLevel detailLevel;
|
||||
|
||||
public TimeTracker() {
|
||||
this.detailLevel = ZoomLevel.DETAIL_ONE;
|
||||
}
|
||||
|
||||
public void addZoomListener(ZoomLevelChangedListener listener) {
|
||||
zoomListeners
|
||||
.add(new WeakReference<ZoomLevelChangedListener>(listener));
|
||||
|
|
@ -102,7 +105,7 @@ public class TimeTracker extends HtmlMacroComponent {
|
|||
}
|
||||
|
||||
private void changeDetailLevel(ZoomLevel d) {
|
||||
setDynamicProperty("detailLevel", d);
|
||||
this.detailLevel = d;
|
||||
datesMapper = null;
|
||||
detailsFirstLevelCached = null;
|
||||
detailsSecondLevelCached = null;
|
||||
|
|
@ -117,7 +120,7 @@ public class TimeTracker extends HtmlMacroComponent {
|
|||
}
|
||||
|
||||
private ZoomLevel getDetailLevel() {
|
||||
return (ZoomLevel) getDynamicProperty("detailLevel");
|
||||
return detailLevel;
|
||||
}
|
||||
|
||||
public AbstractComponent getFakeRow() {
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ import org.zkoss.ganttz.Dependency;
|
|||
* the {@link DependencyBean dependency} as arcs. It enforces the rules embodied
|
||||
* in the dependencies and in the duration of the tasks using listeners. <br/>
|
||||
* Created at Apr 24, 2009
|
||||
*
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*
|
||||
*/
|
||||
public class DependencyRegistry {
|
||||
|
||||
|
|
@ -98,10 +96,10 @@ public class DependencyRegistry {
|
|||
rulesEnforcersByTask.get(destination).update();
|
||||
}
|
||||
|
||||
public void add(Dependency dependency) {
|
||||
TaskBean destination = dependency.getDestination().getTaskBean();
|
||||
graph.addEdge(dependency.getSource().getTaskBean(), destination,
|
||||
dependency.getDependencyBean());
|
||||
public void add(DependencyBean dependency) {
|
||||
TaskBean source = dependency.getSource();
|
||||
TaskBean destination = dependency.getDestination();
|
||||
graph.addEdge(source, destination, dependency);
|
||||
getEnforcer(destination).update();
|
||||
}
|
||||
|
||||
|
|
@ -109,4 +107,13 @@ public class DependencyRegistry {
|
|||
return rulesEnforcersByTask.get(destination);
|
||||
}
|
||||
|
||||
public List<TaskBean> getTasks() {
|
||||
return new ArrayList<TaskBean>(graph.vertexSet());
|
||||
}
|
||||
|
||||
public List<DependencyBean> getDependencies() {
|
||||
Set<DependencyBean> edgeSet = graph.edgeSet();
|
||||
return new ArrayList<DependencyBean>(edgeSet);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,7 @@ import java.util.List;
|
|||
import org.zkoss.ganttz.util.Interval;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francisco Javier Moran Rúa
|
||||
*
|
||||
*/
|
||||
public abstract class TimeTrackerState {
|
||||
|
||||
|
|
@ -26,9 +24,7 @@ public abstract class TimeTrackerState {
|
|||
|
||||
/**
|
||||
* This class is conceived as an immutable class.
|
||||
*
|
||||
* @author Francisco Javier Moran Rúa
|
||||
*
|
||||
*/
|
||||
public final static class DetailItem {
|
||||
|
||||
|
|
@ -123,8 +119,6 @@ public abstract class TimeTrackerState {
|
|||
|
||||
protected static long calculateYearsBetween(Date initialDate, Date endDate) {
|
||||
|
||||
System.out.println("Initial date:" + initialDate);
|
||||
System.out.println("End date:" + endDate);
|
||||
long milsecondsDiff = endDate.getTime() - initialDate.getTime();
|
||||
|
||||
// To chech later: If you put MILLSECONDS_IN_YEAR the
|
||||
|
|
|
|||
|
|
@ -3,27 +3,5 @@
|
|||
<vbox class="listdetails" id="insertionPoint">
|
||||
<button label="${c:l('listdetails.add_task')}"
|
||||
onClick="insertionPoint.getParent().addTask();" />
|
||||
<taskdetail taskId="task1" start="01/06/2009" length="365 days"
|
||||
taskName="Tarefa1"
|
||||
color="blue"/>
|
||||
<taskdetail taskId="task2" start="01/01/2011" length="365 days"
|
||||
taskName="Tarefa2"
|
||||
color="red"/>
|
||||
<taskdetail taskId="task3" start="01/01/2013" length="365 days"
|
||||
taskName="Tarefa3"
|
||||
color="yellow"/>
|
||||
|
||||
<taskdetail taskId="task4" start="01/01/2013" length="365 days"
|
||||
taskName="Tarefa4"
|
||||
color="yellow"/>
|
||||
|
||||
<!--taskdetail taskId="task5" start="01/01/2010" length="100 days"
|
||||
taskName="Tarefa5"
|
||||
color="orange"/>
|
||||
|
||||
<taskdetail taskId="task6" start="01/01/2010" length="100 days"
|
||||
taskName="Tarefa6"
|
||||
color="white"/-->
|
||||
|
||||
</vbox>
|
||||
</zk>
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
|
||||
<zk>
|
||||
|
||||
<zscript><![CDATA[
|
||||
top = self;
|
||||
]]>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
package org.navalplanner.web.planner;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.zkoss.ganttz.util.DependencyBean;
|
||||
import org.zkoss.ganttz.util.DependencyRegistry;
|
||||
import org.zkoss.ganttz.util.DependencyType;
|
||||
import org.zkoss.ganttz.util.TaskBean;
|
||||
|
||||
/**
|
||||
* Some test data for planner <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public class DataForPlanner {
|
||||
|
||||
public DataForPlanner() {
|
||||
}
|
||||
|
||||
public DependencyRegistry getEmpty() {
|
||||
return new DependencyRegistry();
|
||||
}
|
||||
|
||||
public DependencyRegistry getLightLoad() {
|
||||
return getModelWith(50);
|
||||
}
|
||||
|
||||
public DependencyRegistry getMediumLoad() {
|
||||
return getModelWith(300);
|
||||
}
|
||||
|
||||
public DependencyRegistry getHighLoad() {
|
||||
return getModelWith(500);
|
||||
}
|
||||
|
||||
private DependencyRegistry getModelWith(int tasksToCreate) {
|
||||
DependencyRegistry dependencyRegistry = new DependencyRegistry();
|
||||
Date now = new Date();
|
||||
Date end = threeMonthsLater(now);
|
||||
TaskBean first = null;
|
||||
TaskBean second = null;
|
||||
for (int i = 0; i < tasksToCreate; i++) {
|
||||
TaskBean taskBean = new TaskBean();
|
||||
if (i == 0)
|
||||
first = taskBean;
|
||||
if (i == 1)
|
||||
second = taskBean;
|
||||
taskBean.setName("tarefa " + (i + 1));
|
||||
taskBean.setBeginDate(now);
|
||||
taskBean.setEndDate(end);
|
||||
dependencyRegistry.add(taskBean);
|
||||
}
|
||||
dependencyRegistry.add(new DependencyBean(first, second,
|
||||
DependencyType.END_START));
|
||||
return dependencyRegistry;
|
||||
}
|
||||
|
||||
private static Date threeMonthsLater(Date now) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(now);
|
||||
calendar.add(Calendar.MONTH, 3);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,53 +6,41 @@
|
|||
<?link rel="stylesheet" type="text/css" href="/common/css/navalpro.css"?>
|
||||
<zk>
|
||||
|
||||
<planner self="@{define(content)}">
|
||||
<div id="idContextMenuTaskAssigment" use="org.zk.myhello.pages.MyHelloPageListener">
|
||||
<zscript><![CDATA[
|
||||
plannerData = new org.navalplanner.web.planner.DataForPlanner();
|
||||
]]>
|
||||
</zscript>
|
||||
<!-- choose lightLoad, mediumLoad or highLoad.
|
||||
-->
|
||||
<planner id="planner" self="@{define(content)}" dependencyRegistry="${plannerData.lightLoad}">
|
||||
<div id="idContextMenuTaskAssigment"
|
||||
use="org.zk.myhello.pages.MyHelloPageListener">
|
||||
</div>
|
||||
</planner>
|
||||
|
||||
<listdetails>
|
||||
</listdetails>
|
||||
<ganttpanel>
|
||||
<timetracker detailLevel="${idContextMenuTaskAssigment.currentDetailLevel}" />
|
||||
<tasklist id="taskList">
|
||||
<task id="task1" color="#007bbe"/>
|
||||
<window border="normal" width="300px"
|
||||
apply="${planner.modalFormComposer}">
|
||||
<grid>
|
||||
<rows>
|
||||
<row>
|
||||
${c:l('task.name')}
|
||||
<textbox id="name" />
|
||||
</row>
|
||||
<row>
|
||||
${c:l('task.start')}
|
||||
<datebox id="startDateBox" compact="true" />
|
||||
</row>
|
||||
<row>
|
||||
${c:l('task.end')}
|
||||
<datebox id="endDateBox" compact="true" />
|
||||
</row>
|
||||
<row>
|
||||
${c:l('task.notes')}
|
||||
<textbox id="notes" />
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
<button id="ok" label=" ${c:l('task.ok')}" />
|
||||
</window>
|
||||
|
||||
<task id="task2" color="#007bbe"/>
|
||||
|
||||
<task id="task3" color="#007bbe"/>
|
||||
|
||||
<task id="task4" color="#007bbe"/>
|
||||
|
||||
<!--task id="task5" color="orange"/>
|
||||
|
||||
<task id="task6" color="white"/-->
|
||||
|
||||
</tasklist>
|
||||
|
||||
|
||||
<window border="normal" width="300px" apply="${taskList.modalFormComposer}">
|
||||
<grid>
|
||||
<rows>
|
||||
<row>${c:l('task.name')} <textbox id="name"/></row>
|
||||
<row>${c:l('task.start')} <datebox id="startDateBox" compact="true"/>
|
||||
</row>
|
||||
<row>
|
||||
${c:l('task.end')} <datebox id="endDateBox" compact="true" />
|
||||
</row>
|
||||
<row>
|
||||
${c:l('task.notes')} <textbox id="notes" />
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
<button id="ok" label=" ${c:l('task.ok')}" />
|
||||
</window>
|
||||
|
||||
<dependencylist>
|
||||
<dependency idTaskOrig="task1" idTaskEnd="task2"/>
|
||||
<dependency idTaskOrig="task2" idTaskEnd="task3"/>
|
||||
<dependency idTaskOrig="task1" idTaskEnd="task4"/>
|
||||
</dependencylist>
|
||||
</ganttpanel>
|
||||
</planner>
|
||||
|
||||
</zk>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue