map.put(ActionKey.POLICY_CHOOSEFB, new PolicyAction(ActionKey.POLICY_CHOOSEFB, rb.getString("choosefallback")) {
@Override
public void actionPerformed(ActionEvent e) {
PolicyModel policy = dbModel.getCurrentPolicy();
List<PolicyModel> currentPolicies = null;
PolicyLevel level = dbModel.getActiveLevel();
if (level == PolicyLevel.A) {
currentPolicies = dbModel.getAPolicies();
} else if (level == PolicyLevel.C) {
currentPolicies = dbModel.getCPolicies();
} else if (level == PolicyLevel.I) {
currentPolicies = dbModel.getIPolicies();
}
List<PolicyModel> list = new ArrayList<PolicyModel>(currentPolicies);
list.remove(policy); // die darf sowieso nicht drin sein
for (Iterator<PolicyModel> it = list.iterator(); it.hasNext();) {
PolicyModel next = it.next();
if (!PolicyUtilities.isValidPolicyFallback(policy, next)) {
it.remove(); // entferne alle invaliden
} else {
// prüfen, ob Policy schon Elternteil einer anderen Policy ist
for (int i=0; i<currentPolicies.size(); i++) {
PolicyModel ref = currentPolicies.get(i);
if(!ref.equals(next))
if(PolicyUtilities.isParentPolicy(ref, next))
it.remove();
}
}
}
PolicyModel p = PolicyUtilities.getDummyPolicy();
if ((list.isEmpty()) && (policy.getFallback() == null)) {
if(PolicyUtilities.isShowWarnings()) {
mb = PolicyUtilities.getMessageBundle();
PolicyUtilities.showMessageDialog(mb.getString("nofbavailable"), JOptionPane.INFORMATION_MESSAGE);
}
} else {
list.add(p);
Object[] policies = list.toArray();
FallBackChooserDialog dlg = new FallBackChooserDialog();
dlg.showDialog(policies);
Object result = dlg.getResult();
if (result != null) {
PolicyModel fb = (PolicyModel) result;
if(fb.equals(p))
dbModel.getCurrentPolicy().setFallback(null);
else
dbModel.getCurrentPolicy().setFallback((PolicyModel) dlg.getResult());
PolicyUtilities.setPolicyRanks(currentPolicies, true);