Search in sources :

Example 1 with BoundFactsChangedEvent

use of org.drools.workbench.screens.guided.dtable.client.widget.table.events.gwt.BoundFactsChangedEvent in project drools-wb by kiegroup.

the class ConditionColumnSynchronizer method append.

@Override
public void append(final PatternConditionMetaData metaData) throws VetoException {
    // Check operation is supported
    if (!handlesAppend(metaData)) {
        return;
    }
    final Pattern52 pattern = metaData.getPattern();
    final ConditionCol52 column = (ConditionCol52) metaData.getColumn();
    // Add pattern if it does not already exist
    if (!model.getConditions().contains(pattern)) {
        model.getConditions().add(pattern);
        // Signal patterns changed event
        final BoundFactsChangedEvent bfce = new BoundFactsChangedEvent(rm.getLHSBoundFacts());
        eventBus.fireEvent(bfce);
    }
    pattern.getChildColumns().add(column);
    synchroniseAppendColumn(column);
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) BoundFactsChangedEvent(org.drools.workbench.screens.guided.dtable.client.widget.table.events.gwt.BoundFactsChangedEvent)

Example 2 with BoundFactsChangedEvent

use of org.drools.workbench.screens.guided.dtable.client.widget.table.events.gwt.BoundFactsChangedEvent in project drools-wb by kiegroup.

the class ConditionColumnSynchronizer method delete.

@Override
public void delete(final ColumnMetaData metaData) throws VetoException {
    // Check operation is supported
    if (!handlesDelete(metaData)) {
        return;
    }
    final ConditionCol52 column = (ConditionCol52) metaData.getColumn();
    final int columnIndex = model.getExpandedColumns().indexOf(column);
    final Pattern52 pattern = model.getPattern(column);
    // Check if pattern change can be applied to model
    if (!isPotentialConditionDeletionSafe(column)) {
        throw new VetoDeletePatternInUseException();
    }
    if (!isPotentialPatternDeletionSafe(pattern)) {
        throw new VetoDeletePatternInUseException();
    }
    // Perform deletion
    pattern.getChildColumns().remove(column);
    // Remove pattern if it contains zero conditions
    if (pattern.getChildColumns().isEmpty()) {
        model.getConditions().remove(pattern);
        // Signal patterns changed event to Decision Table Widget
        final BoundFactsChangedEvent bfce = new BoundFactsChangedEvent(rm.getLHSBoundFacts());
        eventBus.fireEvent(bfce);
    }
    synchroniseDeleteColumn(columnIndex);
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) BoundFactsChangedEvent(org.drools.workbench.screens.guided.dtable.client.widget.table.events.gwt.BoundFactsChangedEvent) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) VetoDeletePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException)

Example 3 with BoundFactsChangedEvent

use of org.drools.workbench.screens.guided.dtable.client.widget.table.events.gwt.BoundFactsChangedEvent in project drools-wb by kiegroup.

the class BRLConditionColumnSynchronizer method update.

@Override
public List<BaseColumnFieldDiff> update(final ColumnMetaData originalMetaData, final ColumnMetaData editedMetaData) throws VetoException {
    // Check operation is supported
    if (!(handlesUpdate(originalMetaData) && handlesUpdate(editedMetaData))) {
        return Collections.emptyList();
    }
    // Check whether any discarded bindings were used. If so veto the update.
    final BRLConditionColumn originalColumn = (BRLConditionColumn) originalMetaData.getColumn();
    final BRLConditionColumn editedColumn = (BRLConditionColumn) editedMetaData.getColumn();
    final Set<String> originalBindings = getPatternBindings(originalColumn);
    final Set<String> editedBindings = getPatternBindings(editedColumn);
    originalBindings.removeAll(editedBindings);
    for (String binding : originalBindings) {
        if (rm.isBoundFactUsed(binding)) {
            throw new VetoUpdatePatternInUseException();
        }
    }
    final List<BaseColumnFieldDiff> diffs = originalColumn.diff(editedColumn);
    // Copy existing data for re-use if applicable
    final Map<String, List<DTCellValue52>> originalColumnsData = new HashMap<>();
    for (BRLConditionVariableColumn variable : originalColumn.getChildColumns()) {
        int iColumnIndex = model.getExpandedColumns().indexOf(variable);
        final List<DTCellValue52> originalColumnData = new ArrayList<>();
        final String key = makeUpdateBRLConditionColumnKey(variable);
        for (List<DTCellValue52> row : model.getData()) {
            originalColumnData.add(row.get(iColumnIndex));
        }
        originalColumnsData.put(key, originalColumnData);
    }
    // Insert new columns setting data from that above, if applicable. Column visibility is handled here too.
    model.getConditions().add(model.getConditions().indexOf(originalColumn), editedColumn);
    for (BRLConditionVariableColumn childModelColumn : editedColumn.getChildColumns()) {
        final String key = makeUpdateBRLConditionColumnKey(childModelColumn);
        if (originalColumnsData.containsKey(key)) {
            final List<DTCellValue52> originalColumnData = originalColumnsData.get(key);
            synchroniseAppendColumn(childModelColumn, originalColumnData);
        } else {
            synchroniseAppendColumn(childModelColumn);
        }
    }
    // Delete columns for the original definition
    doDelete(originalColumn);
    // Signal patterns changed event to Decision Table Widget
    final BoundFactsChangedEvent pce = new BoundFactsChangedEvent(rm.getLHSBoundFacts());
    eventBus.fireEvent(pce);
    return diffs;
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VetoUpdatePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) BoundFactsChangedEvent(org.drools.workbench.screens.guided.dtable.client.widget.table.events.gwt.BoundFactsChangedEvent) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

BoundFactsChangedEvent (org.drools.workbench.screens.guided.dtable.client.widget.table.events.gwt.BoundFactsChangedEvent)3 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)2 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)1 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)1 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)1 BaseColumnFieldDiff (org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff)1 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)1 VetoDeletePatternInUseException (org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException)1 VetoUpdatePatternInUseException (org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException)1