@Override public AttrGroup getAttrGroup(final EntityWithConfigurableAttr entity, final String groupName) { if (attrSchemata == null) { loadAttrSchema(); } final AttrSchema entitySchema = attrSchemata.get(entity.getAttrSchemaName()); return entitySchema .getGroups() .stream() .filter(group -> group.getName().equals(groupName)) .findFirst() .orElse(null); }
@Override public AttrDescription getAttrDescription(final AttrGroup attrGroup, final String descriptionName) { return (attrGroup == null) ? null : attrGroup .getDescriptions() .stream() .filter(desc -> desc.getPropertyName().equals(descriptionName)) .findFirst() .orElse(null); } }
public BaseAttributePanel(final String id, final AttrGroup attrGroup) { super(id); this.attrGroup = attrGroup; add(container); container.setOutputMarkupId(true); final String i18nKey = attrGroup.getI18nKey(); final String heading = (i18nKey != null) ? getString(i18nKey) : null; container.add(new Label("heading", heading)); }
private void createDatepicker(T attrRow, GridBuilder gridBuilder) { final String startTimeLabel = getString(attrGroup.getI18nKeyStartTime()); final FieldsetPanel dateFs = gridBuilder.newFieldset(startTimeLabel); final PropertyModel<Date> dateModel = new PropertyModel<>(attrRow, "startTime"); final DatePanel dp = new DatePanel(dateFs.newChildId(), dateModel, DatePanelSettings.get().withTargetType(java.sql.Date.class)); dp.setRequired(true); dp.add(this::validateDate); dateFs.add(dp); final DateTextField dateField = dp.getDateField(); dateField.setMarkupId(attrGroup.getName() + "-startTime").setOutputMarkupId(true); }
private <PK extends Serializable, T extends TimeableAttrRow<PK>, U extends EntityWithConfigurableAttr & EntityWithTimeableAttr<PK, T>> void createTimedAttrPanel( final DivPanel divPanel, final U entity, final AbstractEditPage<?, ?, ?> parentPage, final Function<AttrGroup, T> addNewEntryFunction, final AttrGroup group) { switch (group.getType()) { case PERIOD: case INSTANT_OF_TIME: divPanel.add(new TimedAttributePanel<>(divPanel.newChildId(), group, entity, parentPage, addNewEntryFunction)); break; default: log.error("The Type " + group.getType() + " is not supported."); break; } } }
private void validateDate(IValidatable<Date> iValidatable) { final Date dateToValidate = iValidatable.getValue(); final T selectedAttrRow = selectedAttrRowModel.getObject(); DayMonthGranularity gran = attrGroup.getDayMonthGranularity(); if (gran == null) { gran = DayMonthGranularity.DAY; } Predicate<T> predicate; String errorKey; switch (gran) { case MONTH: predicate = row -> DateUtils.isSameMonth(row.getStartTime(), dateToValidate); errorKey = "attr.starttime.alreadyexists.month"; break; default: predicate = row -> DateHelper.isSameDay(row.getStartTime(), dateToValidate); errorKey = "attr.starttime.alreadyexists.day"; } final boolean thereIsAlreadyAnEntryWithTheSameDate = getTimeableAttrRowsOfThisGroup() .stream() // remove the currently selected entry from the stream, otherwise this will always be true if you don't change the date .filter(row -> !row.equals(selectedAttrRow)) .anyMatch(predicate); if (thereIsAlreadyAnEntryWithTheSameDate) { iValidatable.error(new ValidationError().addKey(errorKey)); } }
@Override public <PK extends Serializable, T extends TimeableAttrRow<PK>, U extends EntityWithConfigurableAttr & EntityWithTimeableAttr<PK, T> & EntityWithAttributes> void createAttrPanels( final TabPanel tabPanel, final U entity, final AbstractEditPage<?, ?, ?> parentPage, final Function<AttrGroup, T> addNewEntryFunction) { final AttrSchema attrSchema = getAttrSchema(entity.getAttrSchemaName()); if (attrSchema == null) { return; } for (AttrGroup group : attrSchema.getGroups()) { final GridBuilder tabContainer = tabPanel.getOrCreateTab(group.getI18nKeySubmenu()); final DivPanel divPanel = tabContainer.getPanel(); if (!divPanel.hasChilds()) { // this panel is fresh, we have to add our css class addHtmlClass(divPanel); } createAttrPanel(divPanel, entity, parentPage, addNewEntryFunction, group); } }
private <PK extends Serializable, T extends TimeableAttrRow<PK>, U extends EntityWithConfigurableAttr & EntityWithTimeableAttr<PK, T> & EntityWithAttributes> void createAttrPanel( final DivPanel divPanel, final U entity, final AbstractEditPage<?, ?, ?> parentPage, final Function<AttrGroup, T> addNewEntryFunction, final AttrGroup group) { switch (group.getType()) { case PERIOD: case INSTANT_OF_TIME: divPanel.add(new TimedAttributePanel<>(divPanel.newChildId(), group, entity, parentPage, addNewEntryFunction)); break; case NOT_TIMEABLE: divPanel.add(new AttributePanel(divPanel.newChildId(), group, entity)); break; default: log.error("The Type " + group.getType() + " is not supported."); break; } }
default void setAndOutputMarkupId(final Component component, final AttrGroup group, final AttrDescription desc) { component.setMarkupId(group.getName() + "-" + desc.getPropertyName()).setOutputMarkupId(true); } }
@Override public Map<String, SearchColumnMetadata> getAdditionallySearchFields(EntityMetadata entm, String params) { Map<String, SearchColumnMetadata> ret = new HashMap<>(); AttrSchemaService service = AttrSchemaServiceSpringBeanImpl.get(); AttrSchema schema = service.getAttrSchema(params); if (schema != null) { for (AttrGroup group : schema.getGroups()) { for (AttrDescription ad : group.getDescriptions()) { ColumnMetadata cmd = getColumnMetadataFromColumnDesc(entm, ad); SearchColumnMetadataBean scmd = new SearchColumnMetadataBean(ad.getPropertyName(), cmd); scmd.setIndexType(String.class); scmd.setIndexed(true); ret.put(ad.getPropertyName(), scmd); } } return ret; } else { log.info("Can't get AttrSchema. Continoue without."); return null; } }
private Button createDeleteButton() { final Button deleteButton = new Button("deleteButton"); deleteButton.add(new AjaxEventBehavior("click") { @Override protected void onEvent(AjaxRequestTarget target) { // open dialog only if an attr row is selected if (selectedAttrRowModel.getObject() != null) { deleteDialog.open(target); } } }); deleteButton.setMarkupId(attrGroup.getName() + "-deleteButton").setOutputMarkupId(true); return deleteButton; }
protected DivPanel createContent(final EntityWithAttributes entity, final Consumer<GridBuilder> gridBuilderConsumer) { final GridBuilder gridBuilder = new GridBuilder(null, "content"); gridBuilder.newSplitPanel(GridSize.COL100); // this can be used to create content before the rest of the content is created if (gridBuilderConsumer != null) { gridBuilderConsumer.accept(gridBuilder); } // create the content according to the descriptions of this group (from the xml file) for (final AttrDescription desc : attrGroup.getDescriptions()) { final String label = getString(desc.getI18nkey()); final FieldsetPanel fs = gridBuilder.newFieldset(label); final ComponentWrapperPanel component = attrSchemaService.createWicketComponent(fs.newChildId(), attrGroup, desc, entity); fs.add((Component) component); } return gridBuilder.getMainContainer(); } }
@Override protected void init() { super.init(); // AttrPanels gridBuilder.newSplitPanel(GridSize.COL100, true); // set hasSubSplitPanel to true to remove borders from this split panel final DivPanel divPanel = gridBuilder.getPanel(); final Function<AttrGroup, EmployeeConfigurationTimedDO> addNewEntryFunction = group -> employeeConfigurationService .addNewTimeAttributeRow(data, group.getName()); attrSchemaService.createAttrPanels(divPanel, data, parentPage, addNewEntryFunction); }
private Button createAddButton() { final Button addButton = new Button("addButton"); addButton.add(new AjaxEventBehavior("click") { @Override protected void onEvent(AjaxRequestTarget target) { if (!isDirty) { addAndSelectNewEntry(); updateChoicesOfDateDropDown(false); container.addOrReplace(createContentWithDatepicker()); target.add(container); // a new attr row must be dirty because it is new and must be saved isDirty = true; } else { // this indicates that the add button was clicked in onBeforeRender newSelectedAttrRow = null; saveChangesDialog.open(target); } } }); addButton.setMarkupId(attrGroup.getName() + "-addButton").setOutputMarkupId(true); return addButton; }
dropDown.setMarkupId(attrGroup.getName() + "-dateDropDown").setOutputMarkupId(true); return dropDown;
.addNewTimeAttributeRow(data, group.getName()); attrSchemaService.createAttrPanels(tabPanel, data, parentPage, addNewEntryFunction);
final Function<AttrGroup, VisitorbookTimedDO> addNewEntryFunction = group -> visitorbookService.addNewTimeAttributeRow(data, group.getName()); attrSchemaService.createTimedAttrPanels(gridBuilder.getPanel(), data, parentPage, addNewEntryFunction);