ItEr19S08CUCreacionProxectoPlanificacionItEr18S08: Adding split command.
This commit is contained in:
parent
e9d0a7589c
commit
ce0a7a5c72
8 changed files with 69 additions and 4 deletions
|
|
@ -123,7 +123,6 @@ public class TaskElementTest {
|
|||
assertThat(first.getWorkHours(), equalTo(20));
|
||||
assertThat(second.getWorkHours(), equalTo(30));
|
||||
assertThat(third.getWorkHours(), equalTo(50));
|
||||
//TODO specify which will be the value for the end date
|
||||
}
|
||||
|
||||
private void checkPopertiesAreKept(Task taskBeingSplitted,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package org.zkoss.ganttz.extensions;
|
||||
|
||||
import org.zkoss.ganttz.adapters.PlannerConfiguration;
|
||||
import org.zkoss.ganttz.data.Position;
|
||||
import org.zkoss.ganttz.data.Task;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package org.navalplanner.web.planner;
|
||||
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
||||
|
||||
public interface ISplitTaskCommand extends ICommandOnTask<TaskElement> {
|
||||
|
||||
public void setState(PlanningState planningState);
|
||||
|
||||
}
|
||||
|
|
@ -57,11 +57,16 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
ISaveCommand saveCommand = getSaveCommand();
|
||||
saveCommand.setState(planningState);
|
||||
configuration.addGlobalCommand(saveCommand);
|
||||
|
||||
IResourceAllocationCommand resourceAllocationCommand = getResourceAllocationCommand();
|
||||
resourceAllocationCommand
|
||||
.setResourceAllocationController(resourceAllocationController);
|
||||
configuration.addCommandOnTask(resourceAllocationCommand);
|
||||
|
||||
ISplitTaskCommand splitCommand = getSplitCommand();
|
||||
splitCommand.setState(planningState);
|
||||
configuration.addCommandOnTask(splitCommand);
|
||||
|
||||
onTransaction.use(configuration);
|
||||
}
|
||||
|
||||
|
|
@ -133,8 +138,11 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
protected abstract ISaveCommand getSaveCommand();
|
||||
|
||||
|
||||
protected abstract IResourceAllocationCommand getResourceAllocationCommand();
|
||||
|
||||
protected abstract ISplitTaskCommand getSplitCommand();
|
||||
|
||||
private Order reload(Order order) {
|
||||
try {
|
||||
return orderService.find(order.getId());
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ public class PlanningState {
|
|||
}
|
||||
|
||||
public void removed(TaskElement taskElement) {
|
||||
taskElement.detach();
|
||||
toSave.remove(taskElement);
|
||||
toRemove.add(taskElement);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package org.navalplanner.web.planner;
|
||||
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.business.planner.entities.TaskGroup;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
|
||||
|
||||
@Component
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class SplitTaskCommand implements ISplitTaskCommand {
|
||||
|
||||
private PlanningState planningState;
|
||||
|
||||
@Override
|
||||
public void setState(PlanningState planningState) {
|
||||
this.planningState = planningState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction(IContextWithPlannerTask<TaskElement> context,
|
||||
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);
|
||||
}
|
||||
|
||||
private int[] createTwoEqualShares(TaskElement taskElement) {
|
||||
Integer workHours = taskElement.getWorkHours();
|
||||
int half = workHours / 2;
|
||||
return new int[] { half, half + workHours % 2 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Split task";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ public class TaskElementAdapter implements ITaskElementAdapter {
|
|||
taskElement.setStartDate(order.getInitDate());
|
||||
}
|
||||
if (taskElement.getEndDate() == null) {
|
||||
Integer workHours = taskElement.getOrderElement().getWorkHours();
|
||||
Integer workHours = taskElement.getWorkHours();
|
||||
long endDateTime = taskElement.getStartDate().getTime()
|
||||
+ (workHours * 3600l * 1000);
|
||||
taskElement.setEndDate(new Date(endDateTime));
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
<lookup-method name="getTaskElementAdapter" bean="taskElementAdapter"/>
|
||||
<lookup-method name="getSaveCommand" bean="saveCommand"/>
|
||||
<lookup-method name="getResourceAllocationCommand" bean="resourceAllocationCommand"/>
|
||||
<lookup-method name="getSplitCommand" bean="splitTaskCommand"/>
|
||||
</bean>
|
||||
|
||||
<context:component-scan base-package="org.navalplanner.web"/>
|
||||
</beans>
|
||||
</beans>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue