[Bug #808] Fix bug when a resource field in Resource search is selected for the first time, set 'Current selection' as name of that resource

FEA: ItEr68S04BugFixing
This commit is contained in:
Diego Pino Garcia 2011-01-13 17:23:14 +01:00
parent 24555f43cb
commit 5b41b5a37d
4 changed files with 97 additions and 85 deletions

View file

@ -153,7 +153,7 @@ public class NewAllocationSelector extends AllocationSelector {
public NewAllocationSelectorController getController() {
return (NewAllocationSelectorController) this
.getVariable("controller", true);
.getVariable("selectorController", true);
}
public void allowSelectMultipleResources(boolean multiple) {

View file

@ -152,6 +152,7 @@ public class ResourceAllocationController extends GenericForwardComposer {
allResourcesPerDay.setWidth("80px");
newAllocationSelector.setLimitingResourceFilter(false);
newAllocationSelectorCombo.setLimitingResourceFilter(false);
newAllocationSelector.allowSelectMultipleResources(true);
initAllocationLabels();
makeReadyInputsForCalculationTypes();
}

View file

@ -61,8 +61,9 @@ import org.zkoss.zul.TreeitemRenderer;
import org.zkoss.zul.Treerow;
/**
* Controller for searching for {@link Resource}
* @author Diego Pino Garcia <dpino@igalia.com>
*
* Controller for searching for {@link Resource}
*/
public class NewAllocationSelectorController extends
AllocationSelectorController {
@ -88,16 +89,13 @@ public class NewAllocationSelectorController extends
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
comp.setVariable("controller", this, true);
initController();
comp.setVariable("selectorController", this, true);
initializeComponents();
}
/**
* Initializes ZUL components
*/
private void initController() {
doInitialSelection();
// Add event listener onSelect to criterionsTree widget
private void initializeComponents() {
// Initialize criteria tree
if (criterionsTree != null) {
criterionsTree.addEventListener("onSelect", new EventListener() {
@ -106,15 +104,13 @@ public class NewAllocationSelectorController extends
@Override
public void onEvent(Event event) throws Exception {
searchResources("", getSelectedCriterions());
showSelectedAllocations();
}
});
}
// Initialize components
criterionsTree.setTreeitemRenderer(criterionRenderer);
listBoxResources.setItemRenderer(getListitemRenderer());
refreshListBoxResources();
// Initialize found resources box
listBoxResources.addEventListener(Events.ON_SELECT,
new EventListener() {
@ -123,8 +119,12 @@ public class NewAllocationSelectorController extends
if (isGenericType()) {
returnToSpecificDueToResourceSelection();
}
showSelectedAllocations();
}
});
listBoxResources.setItemRenderer(getListitemRenderer());
// Initialize radio group of selector types
allocationTypeSelector.addEventListener(Events.ON_CHECK,
new EventListener() {
@ -136,6 +136,24 @@ public class NewAllocationSelectorController extends
showSelectedAllocations();
}
});
doInitialSelection();
}
private void showSelectedAllocations() {
allocationSelectedItems.setValue(buildSelectedAllocationsString());
}
private String buildSelectedAllocationsString() {
if (currentAllocationType == AllocationType.SPECIFIC) {
List<String> result = new ArrayList<String>();
for (Resource each : getSelectedResourcesOnListbox()) {
result.add(each.getShortDescription());
}
return StringUtils.join(result, ",");
} else {
List<Criterion> criteria = getSelectedCriterions();
return currentAllocationType.asCaption(criteria);
}
}
private List<? extends Resource> getAllResources() {
@ -158,6 +176,14 @@ public class NewAllocationSelectorController extends
refreshListBoxResources();
}
private void refreshListBoxResources() {
refreshListBoxResources(getAllResources());
}
private void refreshListBoxResources(List<? extends Resource> resources) {
listBoxResources.setModel(new SimpleListModel(resources));
}
private void returnToSpecificDueToResourceSelection() {
currentAllocationType = AllocationType.SPECIFIC;
List<Criterion> criteria = getSelectedCriterions();
@ -261,10 +287,6 @@ public class NewAllocationSelectorController extends
return result;
}
private void refreshListBoxResources(List<? extends Resource> resources) {
listBoxResources.setModel(new SimpleListModel(resources));
}
public ResourceListRenderer getListitemRenderer() {
return resourceListRenderer;
}
@ -281,10 +303,6 @@ public class NewAllocationSelectorController extends
doInitialSelection();
}
private void refreshListBoxResources() {
refreshListBoxResources(getAllResources());
}
public List<Resource> getSelectedWorkers() {
if (isGenericType()) {
return allResourcesShown();
@ -475,22 +493,8 @@ public class NewAllocationSelectorController extends
listBoxResources.setMultiple(multiple);
}
public void showSelectedAllocations() {
allocationSelectedItems.setValue(buildSelectedAllocationsString());
}
private String buildSelectedAllocationsString() {
if (currentAllocationType == AllocationType.SPECIFIC) {
List<String> result = new ArrayList<String>();
for (Resource each : getSelectedResourcesOnListbox()) {
result.add(each.getShortDescription());
}
return StringUtils.join(result, ",");
} else {
List<Criterion> criterions = getSelectedCriterions();
return currentAllocationType.asCaption(criterions);
}
public boolean isAllowSelectMultipleResources() {
return listBoxResources.isMultiple();
}
}

View file

@ -24,45 +24,46 @@
]]>
</zscript>
<vbox apply="${selectorController}">
<vbox apply="${selectorController}">
<groupbox style="margin-top: 5px" closable="false">
<caption label="${i18n:_('Select criteria set or specific resources for allocation')}" />
<caption label="${i18n:_('Select criteria set or specific resources for allocation')}" />
<hbox>
<vbox sclass="allocation-criterion-selector">
<!-- Criteria -->
<hbox>
<tree id="criterionsTree" width="420px"
height="340px" vflex="true" multiple="true"
model="@{selectorController.criterions}"
zclass="z-dottree" style="margin-top:5px;margin-bottom:5px;">
<attribute name="onSelect"><![CDATA[ selectorController.showSelectedAllocations() ]]></attribute>
<treecols>
<treecol label="${i18n:_('Criteria')}" tooltiptext="${i18n:_('Criteria (Hold CTRL for multiple selection)')}" />
</treecols>
</tree>
</vbox>
<!-- Criteria -->
<vbox sclass="allocation-criterion-selector">
<vbox>
<tree id="criterionsTree" width="420px"
height="340px" vflex="true" multiple="true"
model="@{selectorController.criterions}"
zclass="z-dottree" style="margin-top:5px;margin-bottom:5px;">
<treecols>
<treecol label="${i18n:_('Criteria')}" tooltiptext="${i18n:_('Criteria (Hold CTRL for multiple selection)')}" />
</treecols>
</tree>
<!--Matchings -->
<listbox id="listBoxResources" width="420px"
vflex="true" multiple="true" height="340px"
itemRenderer="@{selectorController.listitemRenderer}" style="margin:5px;"
onFocus="selectorController.showSelectedAllocations()" >
<attribute name="onSelect"><![CDATA[
selectorController.showSelectedAllocations();
]]></attribute>
<listhead>
<listheader label="${i18n:_('Found resources')}" tooltiptext="${i18n:_('Resources matching selected criteria')}" sort="auto" />
</listhead>
</listbox>
</vbox>
</hbox>
</vbox>
<!--Matchings -->
<vbox>
<listbox id="listBoxResources" width="420px" height="340px"
vflex="true" multiple="@{selectorController.allowSelectMultipleResources}" style="margin:5px;"
itemRenderer="@{selectorController.listitemRenderer}" >
<listhead>
<listheader label="${i18n:_('Found resources')}"
tooltiptext="${i18n:_('Resources matching selected criteria')}" sort="auto" />
</listhead>
</listbox>
</vbox>
</hbox>
<!-- Assignment Type -->
<hbox>
<grid fixedLayout="true">
<columns>
<column width="200px" />
@ -70,24 +71,30 @@
</columns>
<rows>
<row>
<hbox><label value="${i18n:_('Assignment Type')}" /><image sclass="context-help-popup" height="15px" src="/common/img/axuda.gif" tooltip="allocation-type-popup" /></hbox>
<radiogroup id="allocationTypeSelector" orient="vertical" onSelect="selectorController.showSelectedAllocations()">
<radio forEach="${selectorController.allocationTypes}"
label="${each.name}" value="${each}" />
</radiogroup>
</row>
<row>
<label value="${i18n:_('Current selection')}" />
<label id="allocationSelectedItems" value="${i18n:_('[generic all workers]')}" />
</row>
</rows></grid>
<hbox>
<label value="${i18n:_('Assignment Type')}" />
<image src="/common/img/axuda.gif" tooltip="allocation-type-popup"
sclass="context-help-popup" height="15px" />
</hbox>
<radiogroup id="allocationTypeSelector" orient="vertical">
<radio forEach="${selectorController.allocationTypes}"
label="${each.name}" value="${each}" />
</radiogroup>
</row>
<row>
<label value="${i18n:_('Current selection')}" />
<label id="allocationSelectedItems" value="${i18n:_('[generic all workers]')}" />
</row>
</rows>
</grid>
</hbox>
</groupbox>
</groupbox>
<popup id="allocation-type-popup" width="700px" >
<iframe id="iframe" src="/help/${i18n:_('en')}/08-asignacion.html" width="100%" />
</popup>
<popup id="allocation-type-popup" width="700px" >
<iframe id="iframe" src="/help/${i18n:_('en')}/08-asignacion.html" width="100%" />
</popup>
</vbox>
</vbox>
</zk>