ItEr18S09CUCreacionProxectoPlanificacionItEr17S10: Showing popup for splitting hours.
This commit is contained in:
parent
2601e38372
commit
6aa76be16f
8 changed files with 218 additions and 8 deletions
|
|
@ -16,6 +16,7 @@ public interface IOrderPlanningModel {
|
|||
void createConfiguration(Order order,
|
||||
ResourceAllocationController resourceAllocationController,
|
||||
EditTaskController editTaskController,
|
||||
SplittingController splittingController,
|
||||
ConfigurationOnTransaction onTransaction);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,6 @@ public interface ISplitTaskCommand extends ICommandOnTask<TaskElement> {
|
|||
|
||||
public void setState(PlanningState planningState);
|
||||
|
||||
public void setSplitWindowController(SplittingController splittingController);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,14 @@ public class OrderPlanningController implements
|
|||
@Autowired
|
||||
private ResourceAllocationController resourceAllocationController;
|
||||
|
||||
@Autowired
|
||||
private SplittingController splittingController;
|
||||
|
||||
public ResourceAllocationController getResourceAllocationController() {
|
||||
return resourceAllocationController;
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private EditTaskController editTaskController;
|
||||
|
||||
|
|
@ -48,7 +52,7 @@ public class OrderPlanningController implements
|
|||
@Override
|
||||
public void showSchedule(Order order) {
|
||||
model.createConfiguration(order, resourceAllocationController,
|
||||
editTaskController,
|
||||
editTaskController, splittingController,
|
||||
new ConfigurationOnTransaction() {
|
||||
|
||||
@Override
|
||||
|
|
@ -65,4 +69,8 @@ public class OrderPlanningController implements
|
|||
handler.registerListener(this, planner.getPage());
|
||||
}
|
||||
|
||||
public SplittingController getSplittingController() {
|
||||
return splittingController;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
public void createConfiguration(Order order,
|
||||
ResourceAllocationController resourceAllocationController,
|
||||
EditTaskController editTaskController,
|
||||
SplittingController splittingController,
|
||||
ConfigurationOnTransaction onTransaction) {
|
||||
Order orderReloaded = reload(order);
|
||||
if (!orderReloaded.isSomeTaskElementScheduled())
|
||||
|
|
@ -66,6 +67,7 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
ISplitTaskCommand splitCommand = getSplitCommand();
|
||||
splitCommand.setState(planningState);
|
||||
splitCommand.setSplitWindowController(splittingController);
|
||||
configuration.addCommandOnTask(splitCommand);
|
||||
|
||||
IMergeTaskCommand mergeCommand = getMergeTaskCommand();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
package org.navalplanner.web.planner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
public class ShareBean {
|
||||
|
||||
public static int[] toHours(ShareBean... shares) {
|
||||
Validate.noNullElements(shares);
|
||||
int[] result = new int[shares.length];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = shares[i].getHours();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int sum(Collection<? extends ShareBean> shareBeans) {
|
||||
Validate.noNullElements(shareBeans);
|
||||
int result = 0;
|
||||
for (ShareBean shareBean : shareBeans) {
|
||||
result += shareBean.getHours();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<ShareBean> toShareBeans(String name, int[] hours) {
|
||||
ArrayList<ShareBean> result = new ArrayList<ShareBean>();
|
||||
for (int i = 0; i < hours.length; i++) {
|
||||
ShareBean s = new ShareBean();
|
||||
s.setName(name + "." + (i + 1));
|
||||
s.setHours(hours[i]);
|
||||
result.add(s);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer hours;
|
||||
|
||||
public ShareBean() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
if (StringUtils.isEmpty(name))
|
||||
return;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getHours() {
|
||||
return hours;
|
||||
}
|
||||
|
||||
public void setHours(Integer share) {
|
||||
if (share == null || share <= 0)
|
||||
return;
|
||||
this.hours = share;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
package org.navalplanner.web.planner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.business.planner.entities.TaskGroup;
|
||||
import org.navalplanner.web.planner.SplittingController.ActionOnOk;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -13,6 +16,7 @@ import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
|
|||
public class SplitTaskCommand implements ISplitTaskCommand {
|
||||
|
||||
private PlanningState planningState;
|
||||
private SplittingController splittingController;
|
||||
|
||||
@Override
|
||||
public void setState(PlanningState planningState) {
|
||||
|
|
@ -20,17 +24,31 @@ public class SplitTaskCommand implements ISplitTaskCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doAction(IContextWithPlannerTask<TaskElement> context,
|
||||
TaskElement taskElement) {
|
||||
public void doAction(final IContextWithPlannerTask<TaskElement> context,
|
||||
final TaskElement taskElement) {
|
||||
if (!taskElement.isLeaf()) {
|
||||
// TODO show some message if this action is not aplyable
|
||||
return;
|
||||
}
|
||||
Task task = (Task) taskElement;
|
||||
TaskGroup newGroup = task.split(createTwoEqualShares(taskElement));
|
||||
context.replace(task, newGroup);
|
||||
planningState.removed(taskElement);
|
||||
planningState.added(newGroup);
|
||||
final Task task = (Task) taskElement;
|
||||
int[] shares = createTwoEqualShares(taskElement);
|
||||
splittingController.show(
|
||||
ShareBean.toShareBeans(task.getName(), shares), task
|
||||
.getWorkHours(), new ActionOnOk() {
|
||||
|
||||
@Override
|
||||
public void doOkAction(ShareBean[] shares) {
|
||||
TaskGroup newGroup = task.split(ShareBean
|
||||
.toHours(shares));
|
||||
List<TaskElement> children = newGroup.getChildren();
|
||||
for (int i = 0; i < shares.length; i++) {
|
||||
children.get(i).setName(shares[i].getName());
|
||||
}
|
||||
context.replace(task, newGroup);
|
||||
planningState.removed(taskElement);
|
||||
planningState.added(newGroup);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private int[] createTwoEqualShares(TaskElement taskElement) {
|
||||
|
|
@ -44,4 +62,9 @@ public class SplitTaskCommand implements ISplitTaskCommand {
|
|||
return "Split task";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSplitWindowController(SplittingController splittingController) {
|
||||
this.splittingController = splittingController;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,81 @@
|
|||
package org.navalplanner.web.planner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.util.Clients;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Label;
|
||||
import org.zkoss.zul.SimpleListModel;
|
||||
import org.zkoss.zul.Window;
|
||||
import org.zkoss.zul.api.Grid;
|
||||
|
||||
@Component
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class SplittingController extends GenericForwardComposer {
|
||||
|
||||
private ActionOnOk curentAction;
|
||||
private Window window;
|
||||
|
||||
private Grid sharesListing;
|
||||
|
||||
private Label totalHoursLabel;
|
||||
private List<ShareBean> sharesList;
|
||||
private Integer totalHours;
|
||||
|
||||
public interface ActionOnOk {
|
||||
public void doOkAction(ShareBean[] shares);
|
||||
}
|
||||
|
||||
public void show(List<ShareBean> initialSharesList, Integer totalHours,
|
||||
ActionOnOk ok) {
|
||||
this.sharesList = initialSharesList;
|
||||
this.totalHours = totalHours;
|
||||
this.curentAction = ok;
|
||||
this.totalHoursLabel.setValue(totalHours + "");
|
||||
this.sharesListing.setModel(new SimpleListModel(initialSharesList));
|
||||
showWindow();
|
||||
}
|
||||
|
||||
public void onClick$splitOk() {
|
||||
checkSumIsEqualToTotal();
|
||||
Clients.closeErrorBox(totalHoursLabel);
|
||||
hideWindow();
|
||||
curentAction.doOkAction(this.sharesList.toArray(new ShareBean[0]));
|
||||
}
|
||||
|
||||
private void checkSumIsEqualToTotal() {
|
||||
int sum = ShareBean.sum(sharesList);
|
||||
if (sum != totalHours) {
|
||||
throw new WrongValueException(totalHoursLabel,
|
||||
"the sum is not equal: " + sum);
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick$splitCancel() {
|
||||
hideWindow();
|
||||
}
|
||||
|
||||
private void showWindow() {
|
||||
try {
|
||||
window.setMode("modal");
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void hideWindow() {
|
||||
window.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(org.zkoss.zk.ui.Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
window = (Window) comp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
<zscript><![CDATA[
|
||||
planningController = orderPlanningController;
|
||||
allocationController = planningController.resourceAllocationController;
|
||||
splittingTaskController = planningController.splittingController;
|
||||
]]>
|
||||
</zscript>
|
||||
|
||||
|
|
@ -84,6 +85,30 @@
|
|||
</vbox>
|
||||
</window>
|
||||
|
||||
<window id="splittingWindow" visible="false" apply="${splittingTaskController}" minwidth="${400}" >
|
||||
<vbox>
|
||||
<hbox>
|
||||
<label value="Total hours:" /> <label id="totalHoursLabel"/>
|
||||
</hbox>
|
||||
<grid id="sharesListing" fixedLayout="true">
|
||||
<columns sizable="true">
|
||||
<column label="Name" />
|
||||
<column label="Hours" />
|
||||
</columns>
|
||||
<rows>
|
||||
<row self="@{each='share'}">
|
||||
<textbox value="@{share.name}" constraint="no empty"/>
|
||||
<intbox value="@{share.hours}" constraint="no negative,no zero"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
<hbox>
|
||||
<button label="Ok" id="splitOk" />
|
||||
<button label="Cancel" id="splitCancel" />
|
||||
</hbox>
|
||||
</vbox>
|
||||
</window>
|
||||
|
||||
<zscript><![CDATA[
|
||||
planningController.registerPlanner(planner);
|
||||
]]>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue