From 53f119e95faa282c40a6924aa8bc077f3130de91 Mon Sep 17 00:00:00 2001 From: Diego Pino Garcia Date: Wed, 13 Apr 2011 13:33:34 +0200 Subject: [PATCH] [Bug #974] Refactor the code that handles selection of function allocation options FEA: ItEr74S04BugFixing --- .../AdvancedAllocationController.java | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AdvancedAllocationController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AdvancedAllocationController.java index 6ba6ec961..b09c5abb0 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AdvancedAllocationController.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AdvancedAllocationController.java @@ -1246,39 +1246,42 @@ class Row { @Override public void onEvent(Event event) throws Exception { - ResourceAllocation resourceAllocation = getAllocation(); - AssignmentFunction assignmentFunction = resourceAllocation - .getAssignmentFunction(); - IAssignmentFunctionConfiguration choosen = (IAssignmentFunctionConfiguration) assignmentFunctionsCombo - .getSelectedItem().getValue(); - boolean hasChanged = !choosen - .isTargetedTo(assignmentFunction); - boolean noPreviousAllocation = assignmentFunction == null; - if (hasChanged) { - boolean changeConfirmed = false; - if (noPreviousAllocation || (changeConfirmed = isChangeConfirmed()) ) { - choosen.applyDefaultFunction(resourceAllocation); - assignmentFunctionsCombo.setVariable("previousValue", assignmentFunctionsCombo.getValue(), true); - return; - } - - if (!changeConfirmed) { - String previousValue = (String) assignmentFunctionsCombo.getVariable("previousValue", true); - assignmentFunctionsCombo.setValue(previousValue); + final String currentValue = assignmentFunctionsCombo.getValue(); + if (currentValue.equals(getPreviousValue())) { + return; + } + if (showConfirmChangeFunctionDialog() == Messagebox.YES) { + IAssignmentFunctionConfiguration function = getSelectedFunction(); + if (function != null) { + function.applyDefaultFunction(getAllocation()); } + } else { + setPreviousValue(currentValue); } } - private boolean isChangeConfirmed() + private IAssignmentFunctionConfiguration getSelectedFunction() { + Comboitem selectedItem = assignmentFunctionsCombo.getSelectedItem(); + return (selectedItem != null) ? (IAssignmentFunctionConfiguration) selectedItem.getValue() : null; + } + + private String getPreviousValue() { + return (String) assignmentFunctionsCombo.getVariable("previousValue", true); + } + + private void setPreviousValue(String value) { + assignmentFunctionsCombo.setVariable("previousValue", value, true); + } + + private int showConfirmChangeFunctionDialog() throws InterruptedException { - int status = Messagebox - .show( - _("You are going to change the assignment function. Are you sure?"), + return Messagebox + .show(_("You are going to change the assignment function. Are you sure?"), _("Confirm change"), Messagebox.YES | Messagebox.NO, Messagebox.QUESTION); - return Messagebox.YES == status; } + }); }