diff --git a/src/main/java/org/gcube/portlets/user/td/client/rule/RuleApplyPanel.java b/src/main/java/org/gcube/portlets/user/td/client/rule/RuleApplyPanel.java index 4adf27c..9a0e92f 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/rule/RuleApplyPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/client/rule/RuleApplyPanel.java @@ -240,19 +240,6 @@ public class RuleApplyPanel extends FramedPanel { } }); - /* - ColumnConfig readableExpressionCol = new ColumnConfig( - propsRules.readableExpression(), 160, "Expression"); - - readableExpressionCol.setCell(new AbstractCell() { - - @Override - public void render(Context context, String value, SafeHtmlBuilder sb) { - RuleApplyTemplates ruleApplyTemplates = GWT - .create(RuleApplyTemplates.class); - sb.append(ruleApplyTemplates.format(value)); - } - });*/ List> l = new ArrayList>(); l.add(nameCol); @@ -509,17 +496,37 @@ public class RuleApplyPanel extends FramedPanel { ColumnData column = comboColumns.getCurrentValue(); if (column != null) { ArrayList selectedRules = getSelectedItems(); - ArrayList rulesToBeApplied = new ArrayList(); + ArrayList rulesThatWillBeDetach = new ArrayList(); + ArrayList rulesThatWillBeApplied = new ArrayList(); + HashMap> columnRuleMapping = appliedRuleResponseData + .getColumnRuleMapping(); + if(columnRuleMapping!=null){ + ArrayList rulesApplied = columnRuleMapping + .get(column.getColumnId()); + for(RuleDescriptionData ruleApplied:rulesApplied){ + boolean ruleStillApplied = false; + for (RuleDescriptionData ruleSelected : selectedRules) { + if (ruleSelected.getId() == ruleApplied + .getId()) { + ruleStillApplied = true; + break; + } + } + + if(!ruleStillApplied){ + rulesThatWillBeDetach.add(ruleApplied); + } + } + } + for (RuleDescriptionData ruleSelected : selectedRules) { boolean ruleApplied = false; - HashMap> columnRuleMapping = appliedRuleResponseData - .getColumnRuleMapping(); - + if (columnRuleMapping != null) { - ArrayList applied = columnRuleMapping + ArrayList rulesApplied = columnRuleMapping .get(column.getColumnId()); - if (applied != null) { - for (RuleDescriptionData ruleAlreadyApplied : applied) { + if (rulesApplied != null) { + for (RuleDescriptionData ruleAlreadyApplied : rulesApplied) { if (ruleSelected.getId() == ruleAlreadyApplied .getId()) { ruleApplied = true; @@ -534,12 +541,12 @@ public class RuleApplyPanel extends FramedPanel { } if (ruleApplied == false) { - rulesToBeApplied.add(ruleSelected); + rulesThatWillBeApplied.add(ruleSelected); } } ApplyColumnRulesSession applyColumnRulesSession = new ApplyColumnRulesSession( - trId, column, rulesToBeApplied); + trId, column, rulesThatWillBeApplied, rulesThatWillBeDetach); parent.applyRules(applyColumnRulesSession); } else { Log.error("No column selected");