ItEr23S10CUAsignacionGrupoRecursosAPlanificacionItEr22S10: [Refactoring] Adds SpecificResourceAllocation form

Select Resource and add to SpecificResourceAllocation list
Delete SpecificResourceAllocation from list
This commit is contained in:
Diego Pino Garcia 2009-08-31 12:48:08 +02:00 committed by Óscar González Fernández
parent 2b96be887c
commit b6bfb56f47
4 changed files with 171 additions and 98 deletions

View file

@ -120,4 +120,11 @@ public interface IResourceAllocationModel {
*/
void updateGanttTaskDuration();
/**
* Adds {@link SpecificResourceAllocation} to {@link Task}
*
* @param worker
*/
void addSpecificResourceAllocation(Worker worker);
}

View file

@ -1,6 +1,9 @@
package org.navalplanner.web.planner;
import static org.navalplanner.web.I18nHelper._;
import java.math.BigDecimal;
import java.util.List;
import java.util.Set;
import org.navalplanner.business.planner.entities.ResourceAllocation;
@ -9,6 +12,7 @@ import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.Worker;
import org.navalplanner.web.common.Util;
import org.navalplanner.web.common.components.WorkerSearch;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.zkoss.zk.ui.Component;
@ -16,20 +20,17 @@ import org.zkoss.zk.ui.SuspendNotAllowedException;
import org.zkoss.zk.ui.WrongValueException;
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.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Decimalbox;
import org.zkoss.zul.Label;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.api.Window;
import static org.navalplanner.web.I18nHelper._;
/**
* Controller for {@link ResourceAllocation} view.
*
@ -41,7 +42,7 @@ public class ResourceAllocationController extends GenericForwardComposer {
private IResourceAllocationModel resourceAllocationModel;
private ResourceAllocationListitemRender resourceAllocationRenderer = new ResourceAllocationListitemRender();
private ResourceAllocationRenderer resourceAllocationRenderer = new ResourceAllocationRenderer();
private Listbox resourcesList;
@ -64,7 +65,7 @@ public class ResourceAllocationController extends GenericForwardComposer {
return resourceAllocationModel.getResourceAllocations();
}
public ResourceAllocationListitemRender getResourceAllocationRenderer() {
public ResourceAllocationRenderer getResourceAllocationRenderer() {
return resourceAllocationRenderer;
}
@ -126,92 +127,136 @@ public class ResourceAllocationController extends GenericForwardComposer {
window.setVisible(false);
}
public void showSearchResources(Event e) {
WorkerSearch workerSearch = new WorkerSearch();
workerSearch.setParent(self.getParent());
workerSearch.afterCompose();
Window window = workerSearch.getWindow();
try {
window.doModal();
} catch (SuspendNotAllowedException e1) {
e1.printStackTrace();
return;
} catch (InterruptedException e1) {
e1.printStackTrace();
return;
}
// Get selected workers and add specificResourceAllocations
List<Worker> workers = workerSearch.getWorkers();
for (Worker worker : workers) {
resourceAllocationModel.addSpecificResourceAllocation(worker);
}
Util.reloadBindings(resourcesList);
}
/**
* Renders every {@link ResourceAllocation} showing a form to modify its
* information.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
* Renders a {@link SpecificResourceAllocation} item
*
* @author Diego Pino Garcia <dpino@igalia.com>
*
*/
public class ResourceAllocationListitemRender implements ListitemRenderer {
private class ResourceAllocationRenderer implements ListitemRenderer {
@Override
public void render(Listitem item, Object data) throws Exception {
final ResourceAllocation resourceAllocation = (ResourceAllocation) data;
final SpecificResourceAllocation resourceAllocation = (SpecificResourceAllocation) data;
item.setValue(resourceAllocation);
resourceAllocationModel.setResourceAllocation(resourceAllocation);
final Worker worker = resourceAllocationModel.getWorker();
Listcell cellResource = new Listcell();
final Textbox resourceTextbox = new Textbox();
Util.bind(
resourceTextbox, new Util.Getter<String>() {
@Override
public String get() {
if (worker == null) {
return "";
}
return worker.getNif();
}
}, new Util.Setter<String>() {
@Override
public void set(String value) {
Worker worker = resourceAllocationModel
.findWorkerByNif(value);
if (worker == null) {
throw new WrongValueException(resourceTextbox,
_("Worker not found"));
} else {
resourceAllocationModel
.setWorker(
(SpecificResourceAllocation) resourceAllocation,
worker);
}
}
});
resourceTextbox.addEventListener(Events.ON_CHANGE,
// Label fields are fixed, can only be viewed
appendLabel(item, resourceAllocation.getWorker().getName());
appendLabel(item, resourceAllocation.getWorker().getNif());
// Pecentage field is editable
bindPercentage(appendDecimalbox(item), resourceAllocation);
// On click delete button
appendButton(item, _("Delete")).addEventListener("onClick",
new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
resourceAllocationModel
.removeResourceAllocation(resourceAllocation);
Util.reloadBindings(resourcesList);
}
});
cellResource.appendChild(resourceTextbox);
cellResource.setParent(item);
}
Listcell cellPercentage = new Listcell();
cellPercentage.appendChild(Util.bind(
new Decimalbox(),
new Util.Getter<BigDecimal>() {
/**
* Appends {@link Label} to {@link Listitem}
*
* @param listitem
* @param name value for {@link Label}
*/
private void appendLabel(Listitem listitem, String name) {
Label label = new Label(name);
@Override
public BigDecimal get() {
return resourceAllocation.getPercentage().scaleByPowerOfTen(2);
}
}, new Util.Setter<BigDecimal>() {
Listcell listCell = new Listcell();
listCell.appendChild(label);
listitem.appendChild(listCell);
}
@Override
public void set(BigDecimal value) {
resourceAllocation.setPercentage(value.setScale(2).divide(new BigDecimal(100),BigDecimal.ROUND_DOWN));
}
}));
cellPercentage.setParent(item);
/**
* Appends {@link Button} to {@link Listitem}
*
* @param listitem
* @param label value for {@link Button}
* @return
*/
private Button appendButton(Listitem listitem, String label) {
Button button = new Button(label);
Listcell cellMessage = new Listcell();
String message = "";
Listcell listCell = new Listcell();
listCell.appendChild(button);
listitem.appendChild(listCell);
if (worker != null) {
if (!resourceAllocationModel.workerSatisfiesCriterions()) {
message = _("The worker does not satisfy the criterions");
return button;
}
/**
* Append a Textbox @{link Percentage} to listItem
*
* @param listItem
*/
private Decimalbox appendDecimalbox(Listitem item) {
Decimalbox decimalbox = new Decimalbox();
// Insert textbox in listcell and append to listItem
Listcell listCell = new Listcell();
listCell.appendChild(decimalbox);
item.appendChild(listCell);
return decimalbox;
}
/**
* Binds Textbox @{link Percentage} to a {@link ResourceAllocation}
* {@link Percentage}
*
* @param txtPercentage
* @param resourceAllocation
*/
private void bindPercentage(final Decimalbox decimalbox,
final ResourceAllocation resourceAllocation) {
Util.bind(decimalbox, new Util.Getter<BigDecimal>() {
@Override
public BigDecimal get() {
return resourceAllocation.getPercentage().scaleByPowerOfTen(2);
}
}
cellMessage.appendChild(new Label(message));
cellMessage.setParent(item);
}, new Util.Setter<BigDecimal>() {
@Override
public void set(BigDecimal value) {
resourceAllocation
.setPercentage(value.setScale(2).divide(
new BigDecimal(100), BigDecimal.ROUND_DOWN));
}
});
}
}
}

View file

@ -1,5 +1,6 @@
package org.navalplanner.web.planner;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
@ -186,4 +187,13 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
ganttTask.setEndDate(task.getEndDate());
}
@Override
public void addSpecificResourceAllocation(Worker worker) {
SpecificResourceAllocation resourceAllocation = SpecificResourceAllocation
.create(task);
resourceAllocation.setWorker(worker);
resourceAllocation.setPercentage(new BigDecimal(1));
task.addResourceAllocation(resourceAllocation);
}
}

View file

@ -6,6 +6,11 @@
<?link rel="stylesheet" type="text/css" href="/planner/css/ganttzk.css"?>
<?link rel="stylesheet" type="text/css" href="/common/css/navalpro_v01.css"?>
<?link rel="stylesheet" type="text/css" href="/common/css/navalpro_zk.css"?>
<?component name="workerSearch"
class="org.navalplanner.web.common.components.WorkerSearch"
macroURI="/resources/search/worker_search.zul" ?>
<zk>
<zscript><![CDATA[
@ -55,34 +60,40 @@
<button id="ok" label="${i18n:_('Accept')}" />
</popup>
<window id="resourceAllocationWindow" visible="false" apply="${allocationController}">
<vbox>
<label value="${i18n:_('Required criterions')}" />
<listbox id="requiredCriterions"
model="@{allocationController.criterions}">
<listitem self="@{each='criterion'}">
<listcell label="@{criterion.name}"></listcell>
</listitem>
</listbox>
<label id="requiredCriterionsEmpty" value="${i18n:_('None')}" visible="false" />
<hbox>
<button id="addResourceAllocation" label="${i18n:_('Add')}"
onClick="allocationController.addResourceAllocation();" />
<button id="removeResourceAllocation" label="${i18n:_('Delete')}"
onClick="allocationController.removeResourceAllocation();" />
</hbox>
<listbox id="resourcesList"
model="@{allocationController.resourceAllocations}"
itemRenderer="@{allocationController.resourceAllocationRenderer}">
<listhead>
<listheader label="${i18n:_('Resource')}" />
<listheader label="${i18n:_('Percentage')}" />
<listheader label="${i18n:_('Message')}" />
</listhead>
</listbox>
<button id="closeResourceAllocationWindow" label="${i18n:_('Back')}"
onClick="allocationController.back();" />
</vbox>
<window id="resourceAllocationWindow" self="@{define(content)}"
apply="${allocationController}"
title="${i18n:_('Resource allocation')}" width="600px"
closable="true" visible="false">
<tabbox>
<tabs>
<tab
label="${i18n:_('Specific resource allocation')}">
</tab>
</tabs>
<tabpanels>
<tabpanel>
<listbox id="resourcesList"
model="@{allocationController.resourceAllocations}"
itemRenderer="@{allocationController.resourceAllocationRenderer}">
<listhead>
<listheader label="${i18n:_('Name')}" />
<listheader label="${i18n:_('NIF')}" />
<listheader label="${i18n:_('Percentage')}" />
<listheader label="" />
</listhead>
</listbox>
</tabpanel>
</tabpanels>
</tabbox>
<hbox>
<button label="${i18n:_('Save')}" />
<button label="${i18n:_('Cancel')}" />
<button label="${i18n:_('Search resources...')}"
onClick="allocationController.showSearchResources(event)" />
<button label="${i18n:_('Advance allocation')}" />
</hbox>
</window>
<window id="splittingWindow" visible="false" apply="${splittingTaskController}" minwidth="${400}" >