List of usage examples for org.apache.wicket.model AbstractReadOnlyModel AbstractReadOnlyModel
AbstractReadOnlyModel
From source file:dk.teachus.frontend.components.calendar.PeriodsCalendarPanel.java
License:Apache License
@Override protected final List<String> getTimeSlotContent(final DateMidnight date, final TimeSlot<PeriodBookingTimeSlotPayload> timeSlot, final ListItem<TimeSlot<PeriodBookingTimeSlotPayload>> timeSlotItem) { // Click action timeSlotItem.add(new AjaxEventBehavior("onclick") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override//from ww w .j a va2 s . c om protected void onEvent(AjaxRequestTarget target) { onTimeSlotClicked(timeSlot, timeSlot.getStartTime().toDateTime(date), target); target.add(timeSlotItem); } @Override public boolean isEnabled(Component component) { return isTimeSlotBookable(timeSlot); } }); timeSlotItem.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public String getObject() { return getTimeSlotClass(timeSlot); } })); List<String> contentLines = new ArrayList<String>(); Period period = timeSlot.getPayload().getPeriod(); // Time line DateTime startTime = timeSlot.getStartTime().toDateTime(date); DateTime endTime = timeSlot.getEndTime().toDateTime(date); org.joda.time.Period minutesDuration = new org.joda.time.Period(startTime, endTime, PeriodType.minutes()); String timePriceLine = TIME_FORMAT.print(startTime) + "-" + TIME_FORMAT.print(endTime) + " - " //$NON-NLS-1$//$NON-NLS-2$ + Math.round(minutesDuration.getMinutes()) + "m"; //$NON-NLS-1$ if (period.getPrice() > 0) { timePriceLine += " - " + Formatters.getFormatCurrency().format(period.getPrice()); //$NON-NLS-1$ } contentLines.add(timePriceLine); // Period if (Strings.isEmpty(period.getLocation()) == false) { contentLines.add(period.getLocation()); } appendToTimeSlotContent(contentLines, timeSlot); return contentLines; }
From source file:dk.teachus.frontend.components.form.AbstractInputElement.java
License:Apache License
@Override protected void onBeforeRender() { super.onBeforeRender(); if (attached == false) { Component label = newLabelComponent("label"); add(label);/* w ww . ja v a 2 s . c o m*/ IModel<String> requiredModel = new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return required ? "*" : " "; } }; add(new Label("required", requiredModel).setEscapeModelStrings(false)); feedbackPanel = new FeedbackPanel("feedback"); feedbackPanel.setOutputMarkupId(true); add(feedbackPanel); Component input = newInputComponent("input", feedbackPanel); add(input); feedbackPanel.setFilter(getFeedbackMessageFilter()); for (IValidator<T> validator : validators) { addValidator(validator); } onEndAttach(); attached = true; } }
From source file:dk.teachus.frontend.components.form.SelectPupilsPanel.java
License:Apache License
public SelectPupilsPanel(String id, IModel<? extends Collection<Pupil>> model) { super(id, model); selectGroup = new CheckGroup<Pupil>("selectGroup", getModel()); selectGroup.setRenderBodyOnly(false); add(selectGroup);/* ww w . j av a2 s . c o m*/ // Header selectGroup.add(new CheckGroupSelector("selectAll")); selectGroup.add(new Label("name", TeachUsSession.get().getString("General.pupil"))); // Check list model IModel<List<Pupil>> pupilsModel = new LoadableDetachableModel<List<Pupil>>() { private static final long serialVersionUID = 1L; @Override protected List<Pupil> load() { List<Pupil> pupils = loadPupils(); return pupils; } }; selectGroup.add(new ListView<Pupil>("pupils", pupilsModel) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<Pupil> item) { item.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return (item.getIndex() + 1) % 2 == 0 ? "even" : "odd"; } })); Check<Pupil> check = new Check<Pupil>("select", item.getModel()); item.add(check); FormComponentLabel label = new FormComponentLabel("label", check); item.add(label); label.add(new Label("name", new PropertyModel<String>(item.getModel(), "name")) .setRenderBodyOnly(true)); } }); }
From source file:dk.teachus.frontend.components.form.TextAreaElement.java
License:Apache License
public TextAreaElement(String label, IModel<String> inputModel, final boolean required) { add(new Label("label", label).setRenderBodyOnly(true)); IModel<String> requiredModel = new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override//from ww w. j a v a 2 s . co m public String getObject() { return required ? "*" : " "; } }; add(new Label("required", requiredModel).setEscapeModelStrings(false)); feedbackPanel = new FeedbackPanel("feedback"); feedbackPanel.setOutputMarkupId(true); add(feedbackPanel); inputField = new TextArea<String>("inputField", inputModel); inputField.setRequired(required); inputField.setLabel(new Model<String>(label)); add(inputField); feedbackPanel.setFilter(new ComponentFeedbackMessageFilter(inputField)); }
From source file:dk.teachus.frontend.components.list.ListPanel.java
License:Apache License
private AjaxNavigationToolbar createNavigationToolbar(DataTable<T> dataTable) { return new AjaxNavigationToolbar(dataTable) { private static final long serialVersionUID = 1L; @Override//from w ww .j av a 2 s .c om protected WebComponent newNavigatorLabel(String navigatorId, final DataTable<?> table) { Label label = new Label(navigatorId, new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { int of = table.getRowCount(); int from = table.getCurrentPage() * table.getItemsPerPage(); int to = Math.min(of, from + table.getItemsPerPage()); from++; if (of == 0) { from = 0; to = 0; } String label = TeachUsSession.get().getString("ListPanel.navigatorLabel"); label = label.replace("${from}", "" + from); label = label.replace("${to}", "" + to); label = label.replace("${of}", "" + of); return label; } }); label.setRenderBodyOnly(true); return label; } @Override protected PagingNavigator newPagingNavigator(String navigatorId, DataTable<?> table) { return new AjaxPagingNavigator(navigatorId, table) { private static final long serialVersionUID = 1L; @Override protected void onAjaxEvent(final AjaxRequestTarget target) { target.add(getTable()); } @Override protected Link<?> newPagingNavigationLink(String id, IPageable pageable, final int pageNumber) { final Link<?> pagingNavigationLink = super.newPagingNavigationLink(id, pageable, pageNumber); pagingNavigationLink.setBody(Model.of("")); pagingNavigationLink .add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { String cls = "btn btn-mini"; if (pageNumber == 0) { cls += " icon-fast-backward"; } else { cls += " icon-fast-forward"; } if (false == pagingNavigationLink.isEnabled()) { cls += " disabled"; } return cls; } })); return pagingNavigationLink; } @Override protected Link<?> newPagingNavigationIncrementLink(String id, IPageable pageable, final int increment) { final Link<?> pagingNavigationIncrementLink = super.newPagingNavigationIncrementLink(id, pageable, increment); pagingNavigationIncrementLink.setBody(Model.of("")); pagingNavigationIncrementLink .add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { String cls = "btn btn-mini"; if (increment < 0) { cls += " icon-backward"; } else { cls += " icon-forward"; } if (false == pagingNavigationIncrementLink.isEnabled()) { cls += " disabled"; } return cls; } })); return pagingNavigationIncrementLink; } @Override protected PagingNavigation newNavigation(String id, IPageable pageable, IPagingLabelProvider labelProvider) { return new AjaxPagingNavigation(id, pageable, labelProvider) { private static final long serialVersionUID = 1L; @Override protected Link<?> newPagingNavigationLink(String id, IPageable pageable, int pageIndex) { final Link<?> pagingNavigationLink = super.newPagingNavigationLink(id, pageable, pageIndex); pagingNavigationLink .add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { StringBuilder cls = new StringBuilder(); cls.append("btn btn-mini"); if (false == pagingNavigationLink.isEnabled()) { cls.append(" btn-primary disabled"); } return cls.toString(); } })); return pagingNavigationLink; } }; } }; } }; }
From source file:dk.teachus.frontend.components.menu.MenuItemsPanel.java
License:Apache License
public MenuItemsPanel(String id, IModel<List<MenuItem>> itemsModel, final IModel<PageCategory> activeMenuItemModel) { super(id, itemsModel); add(new ListView<MenuItem>("menuItems", itemsModel) { private static final long serialVersionUID = 1L; @Override//w w w . j a v a 2s .co m protected void populateItem(final ListItem<MenuItem> listItem) { listItem.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { PageCategory activeMenuType = activeMenuItemModel.getObject(); PageCategory menuItemType = listItem.getModelObject().getMenuItemType(); return activeMenuType == menuItemType ? "active" : null; } })); final WebMarkupContainer link; final MenuItem menuItem = listItem.getModelObject(); if (menuItem instanceof MenuItemPageLink) { final MenuItemPageLink menuItemLink = (MenuItemPageLink) menuItem; link = new BookmarkablePageLink<Void>("menuLink", menuItemLink.getPageClass(), menuItemLink.getPageParameters()); listItem.add(link); link.add(new Label("menuLabel", menuItemLink.getLabel()).setRenderBodyOnly(true)); link.add(new WebMarkupContainer("downIcon").setVisible(false)); listItem.add(new WebComponent("subMenu").setVisible(false)); } else if (menuItem instanceof MenuItemContainer) { MenuItemContainer menuItemContainer = (MenuItemContainer) menuItem; listItem.add(AttributeModifier.append("class", "dropdown")); link = new WebMarkupContainer("menuLink"); link.setOutputMarkupId(true); link.add(AttributeModifier.replace("href", "#")); link.add(AttributeModifier.replace("class", "dropdown-toggle")); link.add(AttributeModifier.replace("data-toggle", "dropdown")); link.add(AttributeModifier.replace("role", "button")); listItem.add(link); link.add(new Label("menuLabel", menuItemContainer.getLabel()).setRenderBodyOnly(true)); link.add(new WebMarkupContainer("downIcon").setRenderBodyOnly(true)); MenuItemsPanel subMenu = new MenuItemsPanel("subMenu", new PropertyModel<List<MenuItem>>(menuItemContainer, "subMenuItems"), new AbstractReadOnlyModel<PageCategory>() { private static final long serialVersionUID = 1L; @Override public PageCategory getObject() { return null; } }); subMenu.add(AttributeModifier.replace("class", "dropdown-menu")); subMenu.add(AttributeModifier.replace("role", "menu")); subMenu.add(AttributeModifier.replace("aria-labelledby", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return link.getMarkupId(); } })); listItem.add(subMenu); } else { throw new IllegalStateException("Unknown menuItem type: " + menuItem); } // Icon WebComponent icon = new WebComponent("icon") { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return menuItem.getIconName() != null; } }; icon.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return "icon-" + menuItem.getIconName(); } })); link.add(icon); } }); }
From source file:dk.teachus.frontend.components.Toolbar.java
License:Apache License
public Toolbar(String id, List<ToolbarItemInterface> items) { super(id);// w ww . j a v a 2 s . com RepeatingView itemsContainer = new RepeatingView("items"); //$NON-NLS-1$ add(itemsContainer); for (final ToolbarItemInterface item : items) { WebMarkupContainer itemContainer = new WebMarkupContainer(itemsContainer.newChildId()); itemsContainer.add(itemContainer); Link<Void> link = null; if (item instanceof ToolbarItem) { final ToolbarItem toolbarItem = (ToolbarItem) item; link = new Link<Void>("link") { private static final long serialVersionUID = 1L; @Override public void onClick() { toolbarItem.onEvent(); } }; } else if (item instanceof BookmarkableToolbarItem) { BookmarkableToolbarItem bookmarkableToolbarItem = (BookmarkableToolbarItem) item; link = new BookmarkablePageLink<Void>("link", bookmarkableToolbarItem.getPageClass(), bookmarkableToolbarItem.getPageParameters()); } else { throw new IllegalArgumentException("Toolbar item not supported: " + item.getClass().getName()); } link.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { if (item.isCurrent(Toolbar.this.getPage())) { return "btn-primary disabled"; } return null; } })); itemContainer.add(link); link.add(new Label("label", item.getLabel()).setRenderBodyOnly(true)); //$NON-NLS-1$ } }
From source file:dk.teachus.frontend.pages.BasePage.java
License:Apache License
public BasePage() { Theme theme = getTheme();//ww w . java2 s. com if (theme == null) { theme = Theme.BLUE; } StringBuilder sb = new StringBuilder(TeachUsSession.get().getString("General.teachUsTitle")); //$NON-NLS-1$ sb.append(" "); //$NON-NLS-1$ sb.append(TeachUsApplication.get().getVersion()); add(new Label("title", sb.toString())); //$NON-NLS-1$ IModel<List<MenuItem>> itemsModel = new PropertyModel<List<MenuItem>>(this, "menuItems"); IModel<List<MenuItem>> rightItemsModel = new PropertyModel<List<MenuItem>>(this, "rightMenuItems"); IModel<PageCategory> activeMenuItemModel = new PropertyModel<PageCategory>(this, "pageCategory"); add(new MenuPanel("menu", itemsModel, rightItemsModel, activeMenuItemModel)); add(new Label("copyright", "2006-" + new DateMidnight().getYear() + " TeachUs Booking Systems")); ajaxLoader = new WebMarkupContainer("ajaxLoader"); ajaxLoader.setOutputMarkupId(true); add(ajaxLoader); /* * Google Analytics */ WebMarkupContainer googleAnalytics = new WebMarkupContainer("googleAnalytics") { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return TeachUsApplication.get().getConfiguration() .hasConfiguration(ApplicationConfiguration.GOOGLE_ANALYTICS_WEB_PROPERTY_ID); } @Override public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { String content = markupStream.get().toCharSequence().toString(); content = content.replace("UA-XXXXX-X", TeachUsApplication.get().getConfiguration() .getConfiguration(ApplicationConfiguration.GOOGLE_ANALYTICS_WEB_PROPERTY_ID)); replaceComponentTagBody(markupStream, openTag, content); } }; add(googleAnalytics); /* * New Relic */ add(new Label("newRelicTimingHeader", NewRelic.getBrowserTimingHeader()).setEscapeModelStrings(false) .setRenderBodyOnly(true)); add(new Label("newRelicTimingFooter", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return NewRelic.getBrowserTimingFooter(); } }).setEscapeModelStrings(false).setRenderBodyOnly(true)); }
From source file:eu.kunas.homeclowd.frontend.pages.auth.SignInPage.java
License:Apache License
@Override protected void onInitialize() { super.onInitialize(); handleProperties();/*from w w w.j a va 2 s. co m*/ final List<MediaSource> mm = new ArrayList<>(); String contextPath = WebApplication.get().getServletContext().getContextPath(); mm.add(new MediaSource(contextPath + "/audio?audio=1", "audio/wav")); IModel<List<MediaSource>> mediaSourceList = new AbstractReadOnlyModel<List<MediaSource>>() { private static final long serialVersionUID = 1L; public List<MediaSource> getObject() { return mm; } }; add(new Html5Audio("audioPlayer", mediaSourceList) { private static final long serialVersionUID = 1L; @Override protected boolean isControls() { return true; } @Override protected boolean isAutoPlay() { return true; } @Override protected boolean isAutoBuffer() { return true; } }); Form form = new StatelessForm("loginForm") { @Override protected void onSubmit() { boolean authResult = AuthenticatedWebSession.get().signIn(user.getUsername(), user.getPassword()); if (authResult) { feedbackPanel.setVisible(false); continueToOriginalDestination(); } else { feedbackPanel.setVisible(true); getPage().error("Login Failed"); } } @Override protected void onError() { feedbackPanel.setVisible(true); super.onError(); } }; form.setDefaultModel(new CompoundPropertyModel(user)); form.add(new Label("buildNo", new Model<>(p.getProperty("version") + " " + p.getProperty("build.date")))); form.add(new TextField("username").add(new PropertyValidator())); form.add(new PasswordTextField("password").add(new PropertyValidator())); add(form); feedbackPanel = new FeedbackPanel("feedbackMessage", new ExactErrorLevelFilter(FeedbackMessage.ERROR)); feedbackPanel.setVisible(false); form.add(feedbackPanel); }
From source file:eu.uqasar.web.dashboard.widget.reportingwidget.ReportingSettingsPanel.java
License:Apache License
public ReportingSettingsPanel(String id, IModel<ReportingWidget> model) { super(id, model); setOutputMarkupPlaceholderTag(true); final ReportingWidget qualityWidget = model.getObject(); Form<Widget> form = new Form<>("form"); cube = getModelObject().getSettings().get("cube"); if (cube == null) { cube = "jira"; }/* ww w.j av a 2s .c o m*/ selectedAdditionalRule = getModelObject().getSettings().get("selectedAdditionalRule"); selectedRule = getModelObject().getSettings().get("selectedRule"); chartType = getModelObject().getSettings().get("chartType"); if (chartType == null) { chartType = ReportingWidget.COLUMN_TYPE; } try { InitialContext ic = new InitialContext(); dataService = (SonarDataService) ic.lookup("java:module/SonarDataService"); projects = dataService.getSonarProjects(); } catch (NamingException e) { e.printStackTrace(); } // Add Rules and Additional Rules as DropDownList rulesMap = qualityWidget.getRulesMap(projects); // //Add selection of cubes for report generation. List<String> cubes = Arrays.asList("jira", "sonarcube"); final DropDownChoice<String> selectedCubes = new DropDownChoice<>("cube", new PropertyModel<String>(this, "cube"), cubes); selectedCubes.setRequired(true); form.add(selectedCubes); // Field for the chart type chartType = getModelObject().getSettings().get("chartType"); DropDownChoice<String> choice = new DropDownChoice<>("chartType", new PropertyModel<String>(this, "chartType"), ReportingWidget.TYPES); form.add(choice); // Create a void form for ListView and WebMarkupContainer Form<Void> formVoid = new Form<>("formVoid"); ruleWebMrkUpContainer = new WebMarkupContainer("ruleContainer", new Model<Rule>()); ruleWebMrkUpContainer.setOutputMarkupId(true); formVoid.add(ruleWebMrkUpContainer); ruleWebMrkUpContainer.add(rulesView = new ListView<Rule>("rulesListView", Model.ofList(proposedRules)) { private static final long serialVersionUID = 1L; @Override protected void onConfigure() { super.onConfigure(); // update model rulesView.setModelObject(proposedRules); } @Override protected void populateItem(ListItem<Rule> item) { final Rule proposedRule = item.getModelObject(); // //get dropdown list method will give two different lists.. IModel<List<? extends String>> ruleChoices = new AbstractReadOnlyModel<List<? extends String>>() { /** * */ private static final long serialVersionUID = 1L; @Override public List<String> getObject() { return new ArrayList<>(rulesMap.keySet()); } }; IModel<List<? extends String>> additionalRuleChoices = new AbstractReadOnlyModel<List<? extends String>>() { /** * */ private static final long serialVersionUID = 1L; @Override public List<String> getObject() { List<String> models = rulesMap.get(proposedRule.getSelectedRule()); // very important // System.out.println("selectedRule : " + proposedUser.getSelectedRule()); if (models == null) { models = Collections.emptyList(); } return models; } }; item.add(rules = new DropDownChoice<>("rules", new PropertyModel<String>(proposedRule, "selectedRule"), ruleChoices)); rules.setOutputMarkupId(true); rules.setNullValid(true); rules.setRequired(true); rules.setMarkupId("rules" + item.getIndex()); // very important item.add(additionalRules = new DropDownChoice<>("additionalRules", new PropertyModel<String>(proposedRule, "selectedAdditionalRule"), additionalRuleChoices)); additionalRules.setOutputMarkupId(true); additionalRules.setMarkupId("additionalRules" + item.getIndex()); // very important additionalRules.setNullValid(true); additionalRules.setRequired(true); rules.add(new AjaxFormComponentUpdatingBehavior("onchange") { // very important /** * */ private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { target.add(additionalRules); target.add(rules); } }); additionalRules.add(new AjaxFormComponentUpdatingBehavior("onchange") { // very important private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { target.add(additionalRules); target.add(rules); } }); } }); AjaxSubmitLink addRuleButton = new AjaxSubmitLink("add.rule", formVoid) { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> formVoid) { // target.add(feedbackPanel); target.add(formVoid); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> formVoid) { addNewRuleToList(target, formVoid); } }; addRuleButton.add(new Label("button.add.save", new StringResourceModel("button.add.save", this, Model.of(proposedRules)))); formVoid.add(addRuleButton); rulesView.setOutputMarkupId(true); form.add(formVoid); form.add(new AjaxSubmitLink("submit") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { Dashboard dashboard = findParent(DashboardPanel.class).getDashboard(); if (dashboard != null && dashboardContext != null) { // Here, create a url query based on selected Rule and Additional Rule from dynamic dropdown lists.. urlToLoad = createRule(); System.out.println(urlToLoad); getModelObject().getSettings().put("urlToLoad", urlToLoad); getModelObject().getSettings().put("cube", cube); getModelObject().getSettings().put("selectedAdditionalRule", selectedAdditionalRule); getModelObject().getSettings().put("selectedRule", selectedRule); getModelObject().getSettings().put("chartType", chartType); System.out.print("dashboard : " + dashboard); dashboardContext.getDashboardPersiter().save(dashboard); hideSettingPanel(target); WidgetPanel widgetPanel = findParent(WidgetPanel.class); ReportingWidget tasksWidget = (ReportingWidget) widgetPanel.getModelObject(); tasksWidget.setTitle("Reporting Widget For " + cube + " cube"); ReportingWidgetView widgetView = (ReportingWidgetView) widgetPanel.getWidgetView(); target.add(widgetView); PageParameters params = new PageParameters(); DbDashboard dbdb = (DbDashboard) dashboard; params.add("id", dbdb.getId()); setResponsePage(DashboardViewPage.class, params); } } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { } }); form.add(new AjaxLink<Void>("cancel") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { hideSettingPanel(target); } }); add(form); }