private void createNotificationCells(DynamicGridRow row, RuleValueConditionEntry entry, int count) throws ParseException { DynamicGridColumn valueColl = getColByIndexForActionGrid(count); if (valueColl == null) { valueColl = createColumnForActionGrid("", count); } setRowIdentifier(row, count, RuleConditionType.VALUE); DynamicGridCell preComparatorCell = row.getCells().newCell(valueColl, DynamicCellType.ENUMERATION); for (int i = 0; i < entry.getField().getParentEntity().getFields().size(); i++) { preComparatorCell.getItems().newItem(entry.getField().getParentEntity().getFields().get(i).getName()); preComparatorCell.getItems().get(i).setIdentifier(entry.getField().getParentEntity().getFields().get(i)); } preComparatorCell.setAutoPostBack(true); preComparatorCell.setValue(entry.getField().getName()); preComparatorCell.setIdentifier(entry.getField()); }
private ArrayList<String> checkRow(DynamicGridRow row, ArrayList<String> errors) { if (row.getIdentifier() != null && row.getIdentifier() instanceof RuleConditionRowVo) { RuleConditionRowVo vo = (RuleConditionRowVo) row.getIdentifier(); int collNumbers = vo.getNumberOfColumns(); if (vo.getType().equals(RuleConditionType.FIRST_LOGICAL) || vo.getType().equals(RuleConditionType.LOGICAL)) { if (row.getRows() == null || (row.getRows() != null && row.getRows().size() == 0)) { errors.add("Rule contains Logical Condition(s) without Value Condition(s)!"); } } for (int i = 1; i <= collNumbers; i++) { if (getColByIndex(i) != null) { DynamicGridCell cell = row.getCells().get(getColByIndex(i)); if (cell != null && cell.getValue() == null) { errors.add("Rule not valid! Your rule contain empty cell(s). Please check again."); return errors; } } } if (row.getRows() != null) { for (int j = 0; j < row.getRows().size(); j++) { checkRow(row.getRows().get(j), errors); } } } return errors; }
private void populateRulesNotificationEntry(RuleValueConditionEntry entry, DynamicGridRow parentRow) { DynamicGridRow row = parentRow.getRows().newRow(); DynamicGridColumn valueColl = getColByIndexForActionGrid(1); if (valueColl == null) { valueColl = createColumnForActionGrid("", 1); } setRowIdentifier(row, 1, RuleConditionType.VALUE); DynamicGridCell valueCell = row.getCells().newCell(valueColl, DynamicCellType.ENUMERATION); List<RulesEngineEntity> entities = new Entities().getAllPublicEntities(); for (int i = 0; i < entities.size(); i++) { valueCell.getItems().newItem().setValue(entities.get(i).getName()); valueCell.getItems().get(i).setIdentifier(entities.get(i)); } valueCell.setValue(form.lyrRules().tabConditions().cmbRootEntity().getValue().getName()); valueCell.setReadOnly(true); valueCell.setAutoPostBack(true); valueCell.setWidth(0); int count = row.getIdentifier() != null ? (row.getIdentifier() instanceof RuleConditionRowVo ? (((RuleConditionRowVo) row.getIdentifier()).getNumberOfColumns()) : 0) : 0; count++; try { addRuleNotificationCell(row, entry.getChild() != null ? entry.getChild() : entry, count); } catch (ParseException e) { e.printStackTrace(); } }
private void updateContextMenu() { DynamicGridRow selectedRow = form.lyrRules().tabConditions().dyngrdConditions().getSelectedRow(); DynamicGridRow selectedActionRow = form.lyrRules().tabActions().dyngrdActions().getSelectedRow(); boolean suportUserNotification = form.lyrRules().tabConditions().cmbRootEntity().getValue() != null ? (form.lyrRules().tabConditions().cmbRootEntity().getValue().supportsNotifications()) : false; form.getLocalContext().setUsersEntityAdded(false); if (selectedActionRow != null) { for (int i = 0; i < selectedActionRow.getRows().size(); i++) { if (selectedActionRow.getRows().get(i).getIdentifier() != null && selectedActionRow.getRows().get(i).getIdentifier().equals(NOTIFICATION_USER_ENTITY_INSTANCE)) { form.getLocalContext().setUsersEntityAdded(true); break; } } } boolean canMoveUp = selectedActionRow != null ? (selectedActionRow.canMoveUp() ? selectedActionRow.canMoveUp() : false) : false; boolean canMoveDown = selectedActionRow != null ? (selectedActionRow.canMoveDown() ? selectedActionRow.canMoveDown() : false) : false; boolean isEditMode = form.getMode().equals(FormMode.EDIT) ? true : false; boolean isRowSelectedOnGridCondition = selectedRow != null ? true : false; boolean isRowSelectedOnGridAction = form.lyrRules().tabActions().dyngrdActions().getSelectedRow() != null ? true : false; boolean isNotificationUser = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_USER) ? true : false) : false); boolean isNotificationUserInstance = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() instanceof AppUserShortVo ? true : false) : false); boolean isNotificationUserEntityInstance = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_USER_ENTITY_INSTANCE) ? true : false) : false); boolean isNotificationMessage = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_MESSAGE) ? true : false) : false); boolean isNotificationMessageInstance = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_MESSAGE_INSTANCE) ? true : false) : false); boolean isNotificationLineSeparatorInstance = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_LINE_SEPARATOR_INSTANCE) ? true : false) : false); boolean isNotificationEntityFieldInstance = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() instanceof RuleConditionRowVo ? true : false) : false); boolean isNotificationOption = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_OPTION) ? true : false) : false); boolean isLogicCondition = selectedRow != null ? (selectedRow.getIdentifier() != null ? (((RuleConditionRowVo) selectedRow.getIdentifier()).getType().equals(RuleConditionType.LOGICAL) ? true : false) : false) : false; boolean isValueCondition = selectedRow != null ? (selectedRow.getIdentifier() != null ? (((RuleConditionRowVo) selectedRow.getIdentifier()).getType().equals(RuleConditionType.VALUE) ? true : false) : false) : false; boolean isFirstRow = selectedRow != null ? (selectedRow.getIdentifier() != null ? (((RuleConditionRowVo) selectedRow.getIdentifier()).getType().equals(RuleConditionType.FIRST_LOGICAL) ? true : false) : false) : false; boolean isGridConditionEmpty = form.lyrRules().tabConditions().dyngrdConditions().getRows().size() > 0 ? true : false; boolean isGridActionEmpty = form.lyrRules().tabActions().dyngrdActions().getRows().size() > 0 ? true : false; form.getContextMenus().Admin.getRulesEditorAddLogicalConditionItem().setVisible(isEditMode && isRowSelectedOnGridCondition && !isValueCondition); form.getContextMenus().Admin.getRulesEditorAddValueConditionItem().setVisible(isEditMode && isRowSelectedOnGridCondition && !isValueCondition && (isLogicCondition || isFirstRow) && form.lyrRules().tabConditions().dyngrdConditions().getSelectedRow() != null); form.getContextMenus().Admin.getRulesEditorRemoveAllItem().setVisible(isEditMode && isGridConditionEmpty); form.getContextMenus().Admin.getRulesEditorRemoveItem().setVisible(isEditMode && isRowSelectedOnGridCondition && !isFirstRow); form.getContextMenus().Rules.getRulesEditorActionsAddActionItem().setVisible(isEditMode); form.getContextMenus().Rules.getRulesEditorActionsRemoveActionItem().setVisible(isEditMode && isRowSelectedOnGridAction && !isNotificationOption); form.getContextMenus().Rules.getRulesEditorActionsRemoveAllItem().setVisible(isEditMode && isGridActionEmpty); if (isNotificationUser || isNotificationUserInstance || isNotificationUserEntityInstance || isNotificationMessage || isNotificationMessageInstance || isNotificationLineSeparatorInstance || isNotificationEntityFieldInstance) { form.getContextMenus().Rules.hideAllRulesEditorActionsMenuItems(); } form.getContextMenus().Rules.getRulesEditorActionsAddUserItem().setVisible(isEditMode && isNotificationUser); form.getContextMenus().Rules.getRulesEditorActionsAddEntityUsersItem().setVisible(isEditMode && isNotificationUser && suportUserNotification && suportUserNotification && !form.getLocalContext().getUsersEntityAdded()); form.getContextMenus().Rules.getRulesEditorActionsRemoveEntityUsersItem().setVisible(isEditMode && isNotificationUserEntityInstance); form.getContextMenus().Rules.getRulesEditorActionsRemoveUserItem().setVisible(isEditMode && isNotificationUserInstance); form.getContextMenus().Rules.getRulesEditorActionsAddMessageItem().setVisible(isEditMode && isNotificationMessage); form.getContextMenus().Rules.getRulesEditorActionsRemoveMessageItem().setVisible(isEditMode && isNotificationMessageInstance); form.getContextMenus().Rules.getRulesEditorActionsAddLineSeparatorItem().setVisible(isEditMode && isNotificationMessage); form.getContextMenus().Rules.getRulesEditorActionsRemoveLineSeparatorItem().setVisible(isEditMode && isNotificationLineSeparatorInstance); form.getContextMenus().Rules.getRulesEditorActionsAddEntityFieldItem().setVisible(isEditMode && isNotificationMessage); form.getContextMenus().Rules.getRulesEditorActionsRemoveEntityFieldItem().setVisible(isEditMode && isNotificationEntityFieldInstance); form.getContextMenus().Rules.getRulesEditorActionsMoveUPItem().setVisible(isEditMode && canMoveUp && (isNotificationMessageInstance || isNotificationLineSeparatorInstance || isNotificationEntityFieldInstance)); form.getContextMenus().Rules.getRulesEditorActionsMoveDownItem().setVisible(isEditMode && canMoveDown && (isNotificationMessageInstance || isNotificationLineSeparatorInstance || isNotificationEntityFieldInstance)); }
private void createCellsByType(RulesEngineField identifier, DynamicGridCell cell) { int nextCollAvaible = clearRightCells((Integer) cell.getColumn().getIdentifier(), cell.getRow()); RulesEngineFieldType type = identifier.getType(); DynamicGridRow row = cell.getRow(); RuleConditionRowVo vo = (RuleConditionRowVo) row.getIdentifier(); int count = vo.getNumberOfColumns(); DynamicGridColumn coll = null; if (nextCollAvaible != 0) { coll = getColByIndex(nextCollAvaible); if (coll == null) { coll = createColumn("", nextCollAvaible); } } else { count++; coll = getColByIndex(count); if (coll == null) { coll = createColumn("", count); } } setRowIdentifier(row, count, RuleConditionType.VALUE); count++; DynamicGridCell conditionValueCell = cell.getRow().getCells().newCell(coll, DynamicCellType.ENUMERATION); for (int j = 0; j < type.getComparators().length; j++) { if (checkRowForAnyCollection(cell)) { if (type.getComparators()[j].equals(RuleValueComparator.NOTEQUALS)) continue; } DynamicGridCellItem item = conditionValueCell.getItems().newItem(type.getComparators()[j]); item.setIdentifier(type.getComparators()[j]); conditionValueCell.setValue(type.getComparators()[j]); conditionValueCell.setIdentifier(type.getComparators()[j]); } setRowIdentifier(row, count, RuleConditionType.VALUE); conditionValueCell.setAutoPostBack(true); count++; DynamicGridColumn colll = getColByIndex(count); DynamicGridCell cellValue = null; if (colll == null) { colll = createColumn("", count); } setRowIdentifier(row, count, RuleConditionType.VALUE); createCellByType(identifier, cell, type, colll, cellValue); }
private DynamicGridRow addValueCondition(DynamicGridRow parentRow, boolean isNewValueCondition) { DynamicGridRow row = parentRow.getRows().newRow(); row.setSelectable(true); RuleConditionRowVo vo = (RuleConditionRowVo) row.getIdentifier(); int count = 1; if (vo != null) count = vo.getNumberOfColumns(); setRowIdentifier(row, count, RuleConditionType.VALUE); DynamicGridCell ifCell = row.getCells().newCell(getColByIndex(count), DynamicCellType.HTMLVIEW); ifCell.setValue(" <b>IF</b> "); ifCell.setWidth(30); count++; DynamicGridColumn valueColl = getColByIndex(count); if (valueColl == null) { valueColl = createColumn("", count); } setRowIdentifier(row, count, RuleConditionType.VALUE); DynamicGridCell valueCell = row.getCells().newCell(valueColl, DynamicCellType.ENUMERATION); List<RulesEngineEntity> entities = new Entities().getAllPublicEntities(); for (int i = 0; i < entities.size(); i++) { valueCell.getItems().newItem().setValue(entities.get(i).getName()); valueCell.getItems().get(i).setIdentifier(entities.get(i)); } valueCell.setValue(form.lyrRules().tabConditions().cmbRootEntity().getValue().getName()); valueCell.setReadOnly(true); if (isNewValueCondition) onDyngrdConditionsCellValueChanged(valueCell); valueCell.setAutoPostBack(true); valueCell.setWidth(0); return row; }
private DynamicGridRow addRuleLogicalCondition(RuleLogicalCondition condition) { DynamicGridRow row = form.lyrRules().tabConditions().dyngrdConditions().getRows().get(0).getRows().newRow(); row.setSelectable(true); int count = 1; DynamicGridColumn ifColl = getColByIndex(count); if (ifColl == null) { ifColl = createColumn("", count); } setRowIdentifier(row, count, RuleConditionType.LOGICAL); DynamicGridCell ifCell = row.getCells().newCell(ifColl, DynamicCellType.HTMLVIEW); ifCell.setValue(" <b>IF</b> "); ifCell.setWidth(30); count++; DynamicGridColumn valueColl = getColByIndex(count); if (valueColl == null) { valueColl = createColumn("", count); } setRowIdentifier(row, count, RuleConditionType.LOGICAL); DynamicGridCell valueCell = row.getCells().newCell(valueColl, DynamicCellType.ENUMERATION); List<RuleLogicalCondition> listCondition = RuleLogicalCondition.getAll(); for (int m = 0; m < listCondition.size(); m++) { valueCell.getItems().newItem(listCondition.get(m)); valueCell.getItems().get(m).setIdentifier(listCondition.get(m)); } row.setExpanded(true); valueCell.setAutoPostBack(true); valueCell.setWidth(120); valueCell.setValue(condition); valueCell.setIdentifier(condition); return row; }
private DynamicGridRow addRootLogicalCondition(IRuleCondition ruleCondition) { form.lyrRules().tabConditions().dyngrdConditions().getRows().clear(); form.lyrRules().tabConditions().dyngrdConditions().clear(); DynamicGridColumn rootConditionNameColumn = null; DynamicGridColumn rootConditionValueColumn = null; DynamicGridRow row = null; DynamicGridCell rootConditionCell = null; rootConditionNameColumn = createColumn("", 0); rootConditionValueColumn = createColumn("", 1); row = form.lyrRules().tabConditions().dyngrdConditions().getRows().newRow(); setRowIdentifier(row, 2, RuleConditionType.FIRST_LOGICAL); form.getLocalContext().setIsFirstConditionDefined(true); rootConditionCell = row.getCells().newCell(rootConditionNameColumn != null ? rootConditionNameColumn : getColByIndex(0), DynamicCellType.HTMLVIEW); rootConditionCell.setWidth(60); rootConditionCell.setValue(" <b>IF</b> "); DynamicGridCell rootConditionValueCell = row.getCells().newCell(rootConditionValueColumn != null ? rootConditionValueColumn : getColByIndex(1), DynamicCellType.ENUMERATION); List<RuleLogicalCondition> listCondition = RuleLogicalCondition.getAll(); for (int i = 0; i < listCondition.size(); i++) { rootConditionValueCell.getItems().newItem(listCondition.get(i)); rootConditionValueCell.getItems().get(i).setIdentifier(listCondition.get(i)); } row.setExpanded(true); rootConditionValueCell.setAutoPostBack(true); rootConditionValueCell.setWidth(120); rootConditionValueCell.setValue(ruleCondition); // rootConditionValueCell.setIdentifier(ruleCondition); form.lyrRules().tabConditions().dyngrdConditions().setValue(row); return row; }