ItEr25S09CUAsignacionCalendarioLaboralRecursoItEr24S10: Adding new command to assign a calendar to a task.

This commit is contained in:
Manuel Rego Casasnovas 2009-09-04 12:29:47 +02:00 committed by Óscar González Fernández
parent bb02bcfb02
commit 6c55338623
10 changed files with 275 additions and 2 deletions

View file

@ -0,0 +1,47 @@
package org.navalplanner.web.planner;
import static org.navalplanner.web.I18nHelper._;
import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.planner.entities.TaskElement;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
/**
* A command that opens a window to make the calendar allocation of a task.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class CalendarAllocationCommand implements ICalendarAllocationCommand {
private CalendarAllocationController calendarAllocationController;
public CalendarAllocationCommand() {
}
@Override
public void doAction(IContextWithPlannerTask<TaskElement> context,
TaskElement task) {
if (task instanceof Task) {
this.calendarAllocationController.showWindow((Task) task, context
.getTask());
}
}
@Override
public String getName() {
return _("Calendar allocation");
}
@Override
public void setCalendarAllocationController(
CalendarAllocationController calendarAllocationController) {
this.calendarAllocationController = calendarAllocationController;
}
}

View file

@ -0,0 +1,87 @@
package org.navalplanner.web.planner;
import java.util.List;
import org.navalplanner.business.calendars.entities.BaseCalendar;
import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.web.common.Util;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.SuspendNotAllowedException;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Comboitem;
import org.zkoss.zul.Window;
/**
* Controller for allocate one calendar to a task view.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
@org.springframework.stereotype.Component("calendarAllocationController")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class CalendarAllocationController extends GenericForwardComposer {
private ICalendarAllocationModel calendarAllocationModel;
private Window window;
private Combobox calendarCombo;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
window = (Window) comp;
}
public void showWindow(Task task, org.zkoss.ganttz.data.Task task2) {
calendarAllocationModel.setTask(task);
calendarCombo = (Combobox) window.getFellow("calendarCombo");
fillCalendarComboAndMarkSelected();
try {
Util.reloadBindings(window);
window.doModal();
} catch (SuspendNotAllowedException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
private void fillCalendarComboAndMarkSelected() {
calendarCombo.getChildren().clear();
BaseCalendar assignedCalendar = calendarAllocationModel
.getAssignedCalendar();
List<BaseCalendar> calendars = calendarAllocationModel
.getBaseCalendars();
for (BaseCalendar calendar : calendars) {
Comboitem item = new org.zkoss.zul.Comboitem(calendar.getName());
item.setValue(calendar);
calendarCombo.appendChild(item);
if ((assignedCalendar != null)
&& calendar.getId().equals(assignedCalendar.getId())) {
calendarCombo.setSelectedItem(item);
}
}
}
public void assign(Comboitem comboitem) {
BaseCalendar calendar = (BaseCalendar) comboitem.getValue();
calendarAllocationModel.confirmAssignCalendar(calendar);
window.setVisible(false);
}
public void cancel() {
calendarAllocationModel.cancel();
window.setVisible(false);
}
public BaseCalendar getAssignedCalendar() {
return calendarAllocationModel.getAssignedCalendar();
}
}

View file

@ -0,0 +1,54 @@
package org.navalplanner.web.planner;
import java.util.List;
import org.navalplanner.business.calendars.daos.IBaseCalendarDAO;
import org.navalplanner.business.calendars.entities.BaseCalendar;
import org.navalplanner.business.planner.entities.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Model for UI operations related to calendar allocation popup.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
@Service
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class CalendarAllocationModel implements ICalendarAllocationModel {
@Autowired
private IBaseCalendarDAO baseCalendarDAO;
private Task task;
@Override
@Transactional(readOnly = true)
public List<BaseCalendar> getBaseCalendars() {
return baseCalendarDAO.getBaseCalendars();
}
@Override
public void setTask(Task task) {
this.task = task;
}
@Override
public void confirmAssignCalendar(BaseCalendar calendar) {
task.setCalendar(calendar);
}
@Override
public BaseCalendar getAssignedCalendar() {
return task.getCalendar();
}
@Override
public void cancel() {
task = null;
}
}

View file

@ -0,0 +1,16 @@
package org.navalplanner.web.planner;
import org.navalplanner.business.planner.entities.TaskElement;
import org.zkoss.ganttz.extensions.ICommandOnTask;
/**
* Contract for {@link CalendarAllocationCommand}.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public interface ICalendarAllocationCommand extends ICommandOnTask<TaskElement> {
void setCalendarAllocationController(
CalendarAllocationController calendarAllocationController);
}

View file

@ -0,0 +1,25 @@
package org.navalplanner.web.planner;
import java.util.List;
import org.navalplanner.business.calendars.entities.BaseCalendar;
import org.navalplanner.business.planner.entities.Task;
/**
* Contract for {@link CalendarAllocationModel}.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public interface ICalendarAllocationModel {
List<BaseCalendar> getBaseCalendars();
void setTask(Task task);
void confirmAssignCalendar(BaseCalendar calendar);
void cancel();
BaseCalendar getAssignedCalendar();
}

View file

@ -17,6 +17,7 @@ public interface IOrderPlanningModel {
ResourceAllocationController resourceAllocationController,
EditTaskController editTaskController,
SplittingController splittingController,
CalendarAllocationController calendarAllocationController,
IConfigurationOnTransaction onTransaction);
}

View file

@ -46,6 +46,9 @@ public class OrderPlanningController implements
private Planner planner;
@Autowired
private CalendarAllocationController calendarAllocationController;
public OrderPlanningController() {
}
@ -53,6 +56,7 @@ public class OrderPlanningController implements
public void showSchedule(Order order) {
model.createConfiguration(order, resourceAllocationController,
editTaskController, splittingController,
calendarAllocationController,
new IConfigurationOnTransaction() {
@Override
@ -73,4 +77,8 @@ public class OrderPlanningController implements
return splittingController;
}
public CalendarAllocationController getCalendarAllocationController() {
return calendarAllocationController;
}
}

View file

@ -1,5 +1,7 @@
package org.navalplanner.web.planner;
import static org.navalplanner.web.I18nHelper._;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@ -18,8 +20,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.zkoss.ganttz.adapters.IStructureNavigator;
import org.zkoss.ganttz.adapters.PlannerConfiguration;
import static org.navalplanner.web.I18nHelper._;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
@ -51,6 +51,7 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
ResourceAllocationController resourceAllocationController,
EditTaskController editTaskController,
SplittingController splittingController,
CalendarAllocationController calendarAllocationController,
IConfigurationOnTransaction onTransaction) {
Order orderReloaded = reload(order);
if (!orderReloaded.isSomeTaskElementScheduled())
@ -79,6 +80,11 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
editTaskCommand.setEditTaskController(editTaskController);
configuration.setEditTaskCommand(editTaskCommand);
ICalendarAllocationCommand calendarAllocationCommand = getCalendarAllocationCommand();
calendarAllocationCommand
.setCalendarAllocationController(calendarAllocationController);
configuration.addCommandOnTask(calendarAllocationCommand);
onTransaction.use(configuration);
}
@ -159,6 +165,8 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
protected abstract IEditTaskCommand getEditTaskCommand();
protected abstract ICalendarAllocationCommand getCalendarAllocationCommand();
private Order reload(Order order) {
try {
return orderDAO.find(order.getId());

View file

@ -22,6 +22,7 @@
<lookup-method name="getSplitCommand" bean="splitTaskCommand"/>
<lookup-method name="getMergeTaskCommand" bean="mergeTaskCommand"/>
<lookup-method name="getEditTaskCommand" bean="editTaskCommand"/>
<lookup-method name="getCalendarAllocationCommand" bean="calendarAllocationCommand"/>
</bean>
<context:component-scan base-package="org.navalplanner.web"/>

View file

@ -17,6 +17,7 @@
planningController = orderPlanningController;
allocationController = planningController.resourceAllocationController;
splittingTaskController = planningController.splittingController;
calendarController = planningController.calendarAllocationController;
]]>
</zscript>
@ -138,6 +139,31 @@
</vbox>
</window>
<window id="calendarAllocationWindow" self="@{define(content)}"
apply="${calendarController}"
title="${i18n:_('Calendar allocation')}" width="600px"
closable="true" visible="false">
<vbox>
<label value="${i18n:_('Select the calendar')}" />
<combobox id="calendarCombo">
<comboitem self="@{each='baseCalnedar'}" value="@{baseCalnedar}"
label="@{baseCalnedar.name}" />
</combobox>
<hbox>
<button label="${i18n:_('Assign')}"
onClick="calendarController.assign(calendarCombo.selectedItem);" />
<button label="${i18n:_('Cancel')}"
onClick="calendarController.cancel();" />
</hbox>
</vbox>
</window>
<zscript><![CDATA[
planningController.registerPlanner(planner);
]]>