List of usage examples for org.apache.wicket.ajax.markup.html AjaxLink setVisible
public final Component setVisible(final boolean visible)
From source file:org.onehippo.forge.document.commenting.cms.impl.DefaultDocumentCommentingFieldPlugin.java
License:Apache License
public DefaultDocumentCommentingFieldPlugin(IPluginContext context, IPluginConfig config) { super(context, config); setOutputMarkupId(true);/* w ww .j ava2 s . co m*/ documentModel = (JcrNodeModel) getModel(); commentingContext = new CommentingContext(context, config, documentModel); String commentPersistenceManagerClazz = config.getString("comment.persistence.manager", null); if (StringUtils.isNotBlank(commentPersistenceManagerClazz)) { try { commentPersistenceManager = (CommentPersistenceManager) Class .forName(commentPersistenceManagerClazz).newInstance(); } catch (Exception e) { log.error("Cannot create custom comment persistence manager.", e); } } if (commentPersistenceManager == null) { commentPersistenceManager = new DefaultJcrCommentPersistenceManager(); } queryLimit = config.getAsLong("comment.query.limit", 100); editableByAuthorOnly = config.getAsBoolean("comment.editable.author.only", false); deletableByAuthorOnly = config.getAsBoolean("comment.deletable.author.only", false); add(new Label("doc-commenting-caption", getCaptionModel())); MarkupContainer commentsContainer = new WebMarkupContainer("doc-comments-container"); addDialogAction = new DialogAction( createDialogFactory(new CommentItem(), new SerializableCallable<Object>() { @Override public Object call() throws Exception { refreshCommentItems(); return refreshDocumentEditorWithSelectedCompounds(); } }), getDialogService()); AjaxLink addLink = new AjaxLink("add") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { addDialogAction.execute(); } }; final Image addImage = new Image("add-image") { private static final long serialVersionUID = 1L; }; addImage.setImageResourceReference(ADD_ICON_REF, null); addLink.add(addImage); addLink.setVisible(canCreateCommentItem(UserSession.get().getJcrSession())); commentsContainer.add(addLink); refreshCommentItems(); commentsContainer.add(createRefreshingView()); add(commentsContainer); }
From source file:org.onehippo.forge.document.commenting.cms.impl.DefaultDocumentCommentingFieldPlugin.java
License:Apache License
private RefreshingView<? extends Serializable> createRefreshingView() { return new RefreshingView<Serializable>("view") { private static final long serialVersionUID = 1L; private IDataProvider<CommentItem> dataProvider = new SimpleListDataProvider<CommentItem>( currentCommentItems);//from w ww . j av a2 s . c o m @Override protected Iterator getItemModels() { final Iterator<? extends CommentItem> baseIt = dataProvider.iterator(0, currentCommentItems.size()); return new Iterator<IModel<CommentItem>>() { public boolean hasNext() { return baseIt.hasNext(); } public IModel<CommentItem> next() { return dataProvider.model(baseIt.next()); } public void remove() { baseIt.remove(); } }; } @Override protected void populateItem(Item item) { final CommentItem comment = (CommentItem) item.getModelObject(); final Session userJcrSession = UserSession.get().getJcrSession(); final Label commentHeadLabel = new Label("docitem-head-text", new Model<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return getCommentPersistenceManager().getCommentHeadText(getCommentingContext(), comment); } }); commentHeadLabel.setEscapeModelStrings(false); item.add(commentHeadLabel); final String headTooltip = getCommentPersistenceManager() .getCommentHeadTooltip(getCommentingContext(), comment); if (StringUtils.isNotBlank(headTooltip)) { commentHeadLabel.add(new AttributeModifier("title", new Model<String>(headTooltip))); } final Label commentBodyLabel = new Label("docitem-body-text", new Model<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return getCommentPersistenceManager().getCommentBodyText(getCommentingContext(), comment); } }); commentBodyLabel.setEscapeModelStrings(false); item.add(commentBodyLabel); final String bodyTooltip = getCommentPersistenceManager() .getCommentBodyTooltip(getCommentingContext(), comment); if (StringUtils.isNotBlank(bodyTooltip)) { commentBodyLabel.add(new AttributeModifier("title", new Model<String>(bodyTooltip))); } if (item.getIndex() == currentCommentItems.size() - 1) { item.add(new AttributeAppender("class", new Model("last"), " ")); } final DialogAction editDialogAction = new DialogAction( createDialogFactory(comment, new SerializableCallable<Object>() { @Override public Object call() throws Exception { refreshCommentItems(); return refreshDocumentEditorWithSelectedCompounds(); } }), getDialogService()); AjaxLink editLink = new AjaxLink("edit") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { editDialogAction.execute(); } }; final Image editImage = new Image("edit-image") { private static final long serialVersionUID = 1L; }; editImage.setImageResourceReference(EDIT_ICON_REF, null); editLink.add(editImage); editLink.setVisible(isEditableCommentItem(userJcrSession, comment)); item.add(editLink); AjaxLink deleteLink = new AjaxLink("delete") { private static final long serialVersionUID = 1L; @Override public void onClick(final AjaxRequestTarget target) { try { final ConfirmDialog confirmDlg = new ConfirmDialog( new StringResourceModel("confirm.delete.comment.title", this, null, "Confirmation"), new StringResourceModel("confirm.delete.comment.message", this, null, "Are you sure to delete the item?")) { @Override public void invokeWorkflow() throws Exception { getCommentPersistenceManager().deleteCommentItem(getCommentingContext(), comment); currentCommentItems.remove(comment); refreshDocumentEditorWithSelectedCompounds(); } }; getDialogService().show(confirmDlg); } catch (CommentingException e) { log.error("Failed to delete comment.", e); } } }; final Image deleteImage = new Image("delete-image") { private static final long serialVersionUID = 1L; }; deleteImage.setImageResourceReference(DELETE_ICON_REF, null); deleteLink.add(deleteImage); deleteLink.setVisible(isDeletableCommentItem(userJcrSession, comment)); item.add(deleteLink); } }; }
From source file:org.onexus.website.api.pages.search.SearchPage.java
License:Apache License
public SearchPage(String componentId, IModel<SearchPageStatus> statusModel, boolean showTypes, boolean showLogo) { super(componentId, statusModel); IModel<SearchPageStatus> pageStatusModel = new PropertyModel<SearchPageStatus>(this, "status"); indicator = new WebMarkupContainer("indicator"); indicator.setOutputMarkupId(true);//from w w w . j a va 2s .com indicator.add(new Image("loading", OnDomReadyPanel.LOADING_IMAGE)); add(indicator); WebMarkupContainer container = new WebMarkupContainer("container"); container.add(new AttributeModifier("class", showLogo ? "show-logo" : "hide-logo")); Form form = new Form<SearchPageStatus>("form"); form.add(new AjaxButton("submit") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { setFiltersStatus(null); userFilter = null; SearchPage.this.onSubmit(SearchPage.this.getStatus(), SearchPage.this.getConfig().getWebsiteConfig().getORI().getParent(), userFilter); target.add(SearchPage.this.get("boxes")); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { } }); form.setMultiPart(true); // By default use the first search type List<SearchType> types = getConfig().getTypes(); if (getStatus().getType() == null && !types.isEmpty()) { getStatus().setType(types.get(0)); } search = new TextField<String>("search", new PropertyModel<String>(pageStatusModel, "search")); search.setOutputMarkupId(true); if (!Strings.isEmpty(getStatus().getType().getPlaceholder())) { search.add(new AttributeModifier("placeholder", getStatus().getType().getPlaceholder())); } search.add(new AutoCompleteBehavior<IEntity>(new EntityRenderer(), new AutoCompleteSettings()) { @Override protected Iterator<IEntity> getChoices(String input) { return getAutocompleteChoices(input); } @Override protected String findIndicatorId() { return null; } }); form.add(search); // Filters list modal final WebMarkupContainer widgetModal = new WebMarkupContainer("widgetModal"); widgetModal.setOutputMarkupId(true); widgetModal.add(new Label("header", "")); widgetModal.add(new EmptyPanel("widget")); widgetModal.add(new AjaxLink<String>("close") { @Override public void onClick(AjaxRequestTarget target) { target.appendJavaScript("$('#" + widgetModal.getMarkupId() + "').modal('hide')"); } }); form.add(widgetModal); final AjaxLink<String> list = new AjaxLink<String>("list") { @Override public void onClick(AjaxRequestTarget target) { FiltersWidgetConfig filters = getStatus().getType().getFilters(); if (filters != null) { FiltersWidgetStatus status = filters.createEmptyStatus(); status.setConfig(filters); setFiltersStatus(status); widgetModal.addOrReplace(new Label("header", filters.getTitle())); widgetModal.addOrReplace(new SearchFiltersWidget("widget", new PropertyModel<FiltersWidgetStatus>(SearchPage.this, "filtersStatus")) { @Override protected void applyFilter(FilterConfig filterConfig, AjaxRequestTarget target) { filterConfig.setDeletable(true); search.setModelValue(new String[] { filterConfig.getName() }); target.add(search); userFilter = filterConfig; SearchPage.this.addOrReplace(internalBoxesPanel(filterConfig)); target.add(SearchPage.this.get("boxes")); target.appendJavaScript("$('#" + widgetModal.getMarkupId() + "').modal('hide')"); } }); target.add(widgetModal); target.appendJavaScript("$('#" + widgetModal.getMarkupId() + "').modal('show')"); } } }; list.setOutputMarkupPlaceholderTag(true); form.add(list); FiltersWidgetConfig filters = getStatus().getType().getFilters(); if (filters == null) { list.setVisible(false); } else { list.add(new AttributeModifier("rel", "tooltip")); list.add(new AttributeModifier("title", filters.getTitle())); list.setVisible(true); } setFiltersStatus(null); // Choose type RadioChoice<SearchType> typeSelect = new RadioChoice<SearchType>("type", new PropertyModel<SearchType>(pageStatusModel, "type"), types, new SearchTypeRenderer()); typeSelect.add(new AjaxFormChoiceComponentUpdatingBehavior() { @Override protected void onUpdate(AjaxRequestTarget target) { getStatus().setSearch(""); if (!Strings.isEmpty(getStatus().getType().getPlaceholder())) { search.add(new AttributeModifier("placeholder", getStatus().getType().getPlaceholder())); } else { search.add(new AttributeModifier("placeholder", "")); } SearchPage.this.addOrReplace(internalBoxesPanel()); target.add(search); target.add(SearchPage.this.get("container").get("form").get("examplesContainer")); target.add(SearchPage.this.get("boxes")); FiltersWidgetConfig filters = getStatus().getType().getFilters(); if (filters == null) { list.setVisible(false); } else { list.setVisible(true); list.add(new AttributeModifier("title", filters.getTitle())); } setFiltersStatus(null); target.add(list); } }); form.add(typeSelect); typeSelect.setVisible(showTypes); container.add(form); add(container); // Examples WebMarkupContainer examples = new WebMarkupContainer("examplesContainer"); examples.setOutputMarkupId(true); examples.add(new ListView<SearchExample>("examples", new ExamplesModel(new PropertyModel<SearchType>(pageStatusModel, "type"))) { @Override protected void populateItem(ListItem<SearchExample> item) { AjaxLink<SearchExample> link = new AjaxLink<SearchExample>("link", item.getModel()) { @Override public void onClick(AjaxRequestTarget target) { onSearch(target, getModelObject().getQuery()); } }; link.add(new Label("label", new PropertyModel<String>(item.getModel(), "label"))); item.add(link); WebMarkupContainer sep = new WebMarkupContainer("sep"); sep.setVisible(item.getIndex() + 1 != getModelObject().size()); item.add(sep); } }); form.add(examples); add(internalBoxesPanel()); }
From source file:org.patientview.radar.web.pages.admin.AdminConsultantPage.java
License:Open Source License
public AdminConsultantPage(PageParameters parameters) { super();//ww w .ja v a2s . c o m final Consultant consultant; // if id is empty or -1 then its a new consultant else try pull back record StringValue idValue = parameters.get(PARAM_ID); if (idValue.isEmpty() || idValue.toLong() == -1) { consultant = new Consultant(); newConsultant = true; } else { consultant = utilityManager.getConsultant(idValue.toLongObject()); } CompoundPropertyModel<Consultant> consultantModel = new CompoundPropertyModel<Consultant>(consultant); final FeedbackPanel feedback = new FeedbackPanel("feedback"); feedback.setOutputMarkupId(true); feedback.setOutputMarkupPlaceholderTag(true); add(feedback); final Form<Consultant> userForm = new Form<Consultant>("consultantForm", consultantModel) { protected void onSubmit() { try { utilityManager.saveConsultant(getModelObject()); if (newConsultant) { setResponsePage(AdminConsultantsPage.class); } } catch (Exception e) { error("Could not save consultant: " + e.toString()); } } }; add(userForm); userForm.add(new RequiredTextField("forename")); userForm.add(new RequiredTextField("surname")); // get centres and sort by name List<Centre> centres = utilityManager.getCentres(); Collections.sort(centres, Centre.getComparator()); DropDownChoice<Centre> centre = new DropDownChoice<Centre>("centre", centres, new ChoiceRenderer<Centre>("name", "id")); centre.setRequired(true); userForm.add(centre); AjaxLink delete = new AjaxLink("delete") { public void onClick(AjaxRequestTarget ajaxRequestTarget) { try { utilityManager.deleteConsultant(consultant); setResponsePage(AdminConsultantsPage.class); } catch (Exception e) { error("Could not delete consultant " + e); ajaxRequestTarget.add(feedback); } } }; delete.setVisible(!newConsultant); userForm.add(delete); userForm.add(new AjaxSubmitLink("saveTop") { protected void onSubmit(AjaxRequestTarget ajaxRequestTarget, Form<?> form) { setResponsePage(AdminConsultantsPage.class); } protected void onError(AjaxRequestTarget ajaxRequestTarget, Form<?> form) { ajaxRequestTarget.add(feedback); } }); userForm.add(new AjaxLink("cancelTop") { public void onClick(AjaxRequestTarget ajaxRequestTarget) { setResponsePage(AdminConsultantsPage.class); } }); userForm.add(new AjaxSubmitLink("saveBottom") { protected void onSubmit(AjaxRequestTarget ajaxRequestTarget, Form<?> form) { setResponsePage(AdminConsultantsPage.class); } protected void onError(AjaxRequestTarget ajaxRequestTarget, Form<?> form) { ajaxRequestTarget.add(feedback); } }); userForm.add(new AjaxLink("cancelBottom") { public void onClick(AjaxRequestTarget ajaxRequestTarget) { setResponsePage(AdminConsultantsPage.class); } }); }
From source file:org.patientview.radar.web.panels.followup.RrtTherapyPanel.java
License:Open Source License
public RrtTherapyPanel(String id, final IModel<Long> radarNumberModel) { super(id);//from ww w .ja v a 2 s . c o m setOutputMarkupId(true); setOutputMarkupPlaceholderTag(true); // General details TextField radarNumber = new TextField("radarNumber", radarNumberModel); radarNumber.setEnabled(false); add(radarNumber); add(new TextField("hospitalNumber", RadarModelFactory.getHospitalNumberModel(radarNumberModel, patientManager))); add(new TextField("diagnosis", new PropertyModel( RadarModelFactory.getDiagnosisCodeModel(radarNumberModel, diagnosisManager), "abbreviation"))); add(new TextField("firstName", RadarModelFactory.getFirstNameModel(radarNumberModel, patientManager))); add(new TextField("surname", RadarModelFactory.getSurnameModel(radarNumberModel, patientManager))); add(new DateTextField("dob", RadarModelFactory.getDobModel(radarNumberModel, patientManager), RadarApplication.DATE_PATTERN)); final IModel<Date> esrfDateModel = new LoadableDetachableModel<Date>() { @Override protected Date load() { Diagnosis diagnosis = RadarModelFactory.getDiagnosisModel(radarNumberModel, diagnosisManager) .getObject(); if (diagnosis != null) { return diagnosis.getEsrfDate(); } return null; } }; add(new DateLabel("esrfDate", esrfDateModel, new PatternDateConverter(RadarApplication.DATE_PATTERN, true)) { @Override public boolean isVisible() { return esrfDateModel.getObject() != null; } }); add(new WebMarkupContainer("esrfNotEnteredContainer") { @Override public boolean isVisible() { return esrfDateModel.getObject() == null; } }); // Reusable panel for the dialysis table add(new DialysisTablePanel("dialysisContainer", radarNumberModel)); final IModel transplantListModel = new AbstractReadOnlyModel<List>() { @Override public List getObject() { if (radarNumberModel.getObject() != null) { return transplantManager.getTransplantsByRadarNumber(radarNumberModel.getObject()); } return Collections.emptyList(); } }; final IModel editTransplantModel = new Model<Transplant>(); final List<Component> addTransplantFormComponentsToUpdate = new ArrayList<Component>(); final List<Component> editTransplantFormComponentsToUpdate = new ArrayList<Component>(); final WebMarkupContainer transplantsContainer = new WebMarkupContainer("transplantsContainer"); add(transplantsContainer); transplantsContainer.setOutputMarkupPlaceholderTag(true); transplantsContainer.setOutputMarkupId(true); // Container for edit transplants final MarkupContainer editTransplantContainer = new WebMarkupContainer("editTransplantContainer") { @Override public boolean isVisible() { return editTransplantModel.getObject() != null; } }; editTransplantContainer.setOutputMarkupPlaceholderTag(true); editTransplantContainer.setOutputMarkupPlaceholderTag(true); add(editTransplantContainer); final IModel<Transplant.RejectData> addRejectModel = new CompoundPropertyModel<Transplant.RejectData>( new Model<Transplant.RejectData>()); // Container for reject transplants final MarkupContainer rejectDataContainer = new WebMarkupContainer("rejectDataContainer") { @Override public boolean isVisible() { return addRejectModel.getObject() != null; } }; rejectDataContainer.setOutputMarkupPlaceholderTag(true); rejectDataContainer.setOutputMarkupId(true); add(rejectDataContainer); // Transplants table transplantsContainer.add(new ListView<Transplant>("transplants", transplantListModel) { @Override protected void populateItem(final ListItem<Transplant> item) { item.setModel(new CompoundPropertyModel<Transplant>(item.getModelObject())); item.add(DateLabel.forDatePattern("date", RadarApplication.DATE_PATTERN)); item.add(new Label("modality.description")); item.add(new Label("recurr", new AbstractReadOnlyModel<Object>() { @Override public Object getObject() { return Boolean.TRUE.equals(item.getModelObject().getRecurr()) ? "yes" : "no"; } })); item.add(DateLabel.forDatePattern("dateRecurr", RadarApplication.DATE_PATTERN)); item.add(DateLabel.forDatePattern("dateFailureRejectData.failureDate", RadarApplication.DATE_PATTERN)); IModel rejectDataListModel = new AbstractReadOnlyModel<List>() { @Override public List getObject() { return transplantManager.getRejectDataByTransplantNumber(item.getModelObject().getId()); } }; final WebMarkupContainer rejectDataListContainer = new WebMarkupContainer( "rejectDataListContainer"); rejectDataListContainer.setOutputMarkupId(true); rejectDataContainer.setOutputMarkupPlaceholderTag(true); rejectDataListContainer .add(new ListView<Transplant.RejectData>("rejectDataList", rejectDataListModel) { @Override protected void populateItem(final ListItem<Transplant.RejectData> rejectDataListItem) { rejectDataListItem.setModel(new CompoundPropertyModel<Transplant.RejectData>( rejectDataListItem.getModelObject())); rejectDataListItem.add( DateLabel.forDatePattern("rejectedDate", RadarApplication.DATE_PATTERN)); rejectDataListItem .add(DateLabel.forDatePattern("biopsyDate", RadarApplication.DATE_PATTERN)); AjaxLink ajaxDeleteLink = new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget target) { transplantManager.deleteRejectData(rejectDataListItem.getModelObject()); target.add(rejectDataListContainer); } }; rejectDataListItem.add(ajaxDeleteLink); ajaxDeleteLink.add(RadarBehaviourFactory.getDeleteConfirmationBehaviour()); AuthenticatedWebSession session = RadarSecuredSession.get(); if (session.isSignedIn()) { if (session.getRoles().hasRole(User.ROLE_PATIENT)) { ajaxDeleteLink.setVisible(false); } } } }); item.add(rejectDataListContainer); // Delete, edit and add reject buttons AjaxLink ajaxDeleteLink = new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget target) { Transplant transplant = item.getModelObject(); transplantManager.deleteTransplant(transplant); target.add(addTransplantFormComponentsToUpdate .toArray(new Component[addTransplantFormComponentsToUpdate.size()])); target.add(transplantsContainer); } }; item.add(ajaxDeleteLink); ajaxDeleteLink.add(RadarBehaviourFactory.getDeleteConfirmationBehaviour()); AjaxLink ajaxEditLink = new AjaxLink("editLink") { @Override public void onClick(AjaxRequestTarget target) { editTransplantModel.setObject(item.getModelObject()); target.add(editTransplantContainer); } }; item.add(ajaxEditLink); AjaxLink ajaxAddRejectLink = new AjaxLink("addRejectLink") { { if (item.getModelObject().getDateFailureRejectData() != null) { if (item.getModelObject().getDateFailureRejectData().getFailureDate() != null) { setVisible(false); } } } @Override public void onClick(AjaxRequestTarget target) { Transplant.RejectData rejectData = new Transplant.RejectData(); rejectData.setTransplantId(item.getModelObject().getId()); addRejectModel.setObject(rejectData); target.add(rejectDataContainer); } }; item.add(ajaxAddRejectLink); AuthenticatedWebSession session = RadarSecuredSession.get(); if (session.isSignedIn()) { if (session.getRoles().hasRole(User.ROLE_PATIENT)) { ajaxDeleteLink.setVisible(false); ajaxEditLink.setVisible(false); ajaxAddRejectLink.setVisible(false); } } } }); final List<Component> rejectDataComponentsToUpdate = new ArrayList<Component>(); // Form for adding reject data - model probably needs changing Form<Transplant.RejectData> rejectDataForm = new Form<Transplant.RejectData>("form", addRejectModel); rejectDataForm.add(new RadarDateTextField("rejectedDate", rejectDataForm, rejectDataComponentsToUpdate)); rejectDataForm.add(new RadarDateTextField("biopsyDate", rejectDataForm, rejectDataComponentsToUpdate)); rejectDataForm.add(new AjaxSubmitLink("add") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.add(rejectDataContainer); target.add(transplantsContainer); target.add( rejectDataComponentsToUpdate.toArray(new Component[rejectDataComponentsToUpdate.size()])); try { transplantManager.saveRejectDataWithValidation((Transplant.RejectData) form.getModelObject()); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } addRejectModel.setObject(null); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add( rejectDataComponentsToUpdate.toArray(new Component[rejectDataComponentsToUpdate.size()])); } }); rejectDataForm.add(new AjaxLink("cancel") { @Override public void onClick(AjaxRequestTarget target) { addRejectModel.setObject(null); target.add(rejectDataContainer); } }); rejectDataForm.add(DateLabel.forDatePattern("transplantDate", new Model<Date>(), "dd/MM/yyyy")); rejectDataContainer.add(rejectDataForm); rejectDataForm.add(new FeedbackPanel("dateRejectFeedback", new IFeedbackMessageFilter() { public boolean accept(FeedbackMessage feedbackMessage) { List<String> acceptedErrorMessages = new ArrayList<String>(); acceptedErrorMessages.addAll(TransplantManager.REJECT_DATA_ERROR_MESSAGES); return acceptedErrorMessages.contains(feedbackMessage.getMessage()); } })); // Edit transplant form Form<Transplant> editTransplantForm = new TransplantForm("form", new CompoundPropertyModel<Transplant>(editTransplantModel), editTransplantFormComponentsToUpdate); editTransplantContainer.add(editTransplantForm); editTransplantForm.add(new AjaxSubmitLink("saveTop") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.add(editTransplantContainer); target.add(transplantsContainer); try { transplantManager.saveTransplant((Transplant) form.getModelObject()); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } editTransplantModel.setObject(null); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(editTransplantFormComponentsToUpdate .toArray(new Component[editTransplantFormComponentsToUpdate.size()])); } }); editTransplantForm.add(new AjaxLink("cancelTop") { @Override public void onClick(AjaxRequestTarget target) { editTransplantModel.setObject(null); target.add(editTransplantContainer); } }); editTransplantForm.add(new AjaxSubmitLink("saveBottom") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.add(editTransplantContainer); target.add(transplantsContainer); try { transplantManager.saveTransplant((Transplant) form.getModelObject()); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } editTransplantModel.setObject(null); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(editTransplantFormComponentsToUpdate .toArray(new Component[editTransplantFormComponentsToUpdate.size()])); } }); editTransplantForm.add(new AjaxLink("cancelBottom") { @Override public void onClick(AjaxRequestTarget target) { editTransplantModel.setObject(null); target.add(editTransplantContainer); } }); // Add transplant form Form<Transplant> addTransplantForm = new TransplantForm("addTransplantForm", new CompoundPropertyModel<Transplant>(new Transplant()), addTransplantFormComponentsToUpdate); addTransplantForm.add(new AjaxSubmitLink("add") { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { target.add(form); Transplant transplant = (Transplant) form.getModelObject(); transplant.setRadarNumber(radarNumberModel.getObject()); try { transplantManager.saveTransplant(transplant); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } form.getModel().setObject(new Transplant()); transplantsContainer.setVisible(true); target.add(transplantsContainer); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(addTransplantFormComponentsToUpdate .toArray(new Component[addTransplantFormComponentsToUpdate.size()])); } }); addTransplantForm.setOutputMarkupId(true); addTransplantForm.setOutputMarkupPlaceholderTag(true); add(addTransplantForm); }
From source file:org.patientview.radar.web.panels.navigation.BaseNavigationPanel.java
License:Open Source License
protected void addLogoutLink(boolean userLoggedIn) { AjaxLink logoutLink = new AjaxLink<HomePage>("logoutLink") { @Override/*from w ww.j ava 2 s . c om*/ public void onClick(AjaxRequestTarget ajaxRequestTarget) { RadarSecuredSession.get().invalidate(); setResponsePage(HomePage.class); } }; logoutLink.setVisible(userLoggedIn); add(logoutLink); }
From source file:org.patientview.radar.web.panels.PlasmaPheresisPanel.java
License:Open Source License
public PlasmaPheresisPanel(String id, final IModel<Long> radarNumberModel) { super(id);//from w ww. ja v a 2 s. c o m final WebMarkupContainer plasmapheresisContainer = new WebMarkupContainer("plasmapheresisContainer"); plasmapheresisContainer.setOutputMarkupId(true); plasmapheresisContainer.setOutputMarkupPlaceholderTag(true); add(plasmapheresisContainer); final List<Component> addPlasmapheresisComponentsToUpdate = new ArrayList<Component>(); final List<Component> editPlasmapheresisComponentsToUpdate = new ArrayList<Component>(); final IModel plasmapheresisListModel = new AbstractReadOnlyModel<List>() { @Override public List getObject() { if (radarNumberModel.getObject() != null) { return plasmapheresisManager.getPlasmapheresisByRadarNumber(radarNumberModel.getObject()); } return Collections.emptyList(); } }; final IModel editPlasmapheresisModel = new Model<Plasmapheresis>(); final MarkupContainer editPlasmapheresisContainer = new WebMarkupContainer("editPlasmapheresisContainer") { @Override public boolean isVisible() { return editPlasmapheresisModel.getObject() != null; } }; editPlasmapheresisContainer.setOutputMarkupPlaceholderTag(true); editPlasmapheresisContainer.setOutputMarkupId(true); ListView<Plasmapheresis> plasmapheresisListViewlistView = new ListView<Plasmapheresis>("plasmapheresis", plasmapheresisListModel) { @Override protected void populateItem(final ListItem<Plasmapheresis> item) { item.setModel(new CompoundPropertyModel<Plasmapheresis>(item.getModelObject())); item.add(DateLabel.forDatePattern("startDate", RadarApplication.DATE_PATTERN)); item.add(DateLabel.forDatePattern("endDate", RadarApplication.DATE_PATTERN)); item.add(new Label("plasmapheresisExchanges.name")); item.add(new Label("response.label")); AjaxLink ajaxDeleteLink = new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget target) { Plasmapheresis plasmapheresis = item.getModelObject(); plasmapheresisManager.deletePlasmaPheresis(plasmapheresis); target.add(addPlasmapheresisComponentsToUpdate .toArray(new Component[addPlasmapheresisComponentsToUpdate.size()])); target.add(plasmapheresisContainer); } }; item.add(ajaxDeleteLink); ajaxDeleteLink.add(RadarBehaviourFactory.getDeleteConfirmationBehaviour()); AjaxLink ajaxEditLink = new AjaxLink("editLink") { @Override public void onClick(AjaxRequestTarget target) { editPlasmapheresisModel.setObject(item.getModelObject()); target.add(editPlasmapheresisContainer); } }; item.add(ajaxEditLink); AuthenticatedWebSession session = RadarSecuredSession.get(); if (session.isSignedIn()) { if (session.getRoles().hasRole(User.ROLE_PATIENT)) { ajaxDeleteLink.setVisible(false); ajaxEditLink.setVisible(false); } } } }; plasmapheresisContainer.add(plasmapheresisListViewlistView); // Add the form PlasmapheresisForm editPlasmapheresisForm = new PlasmapheresisForm("editPlasmapheresisForm", new CompoundPropertyModel<Plasmapheresis>(editPlasmapheresisModel), editPlasmapheresisComponentsToUpdate); editPlasmapheresisForm.add(new AjaxSubmitLink("saveTop") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.add(editPlasmapheresisContainer); target.add(plasmapheresisContainer); try { plasmapheresisManager.savePlasmapheresis((Plasmapheresis) form.getModelObject()); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } form.getModel().setObject(null); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(editPlasmapheresisComponentsToUpdate .toArray(new Component[editPlasmapheresisComponentsToUpdate.size()])); } }); editPlasmapheresisForm.add(new AjaxLink("cancelTop") { @Override public void onClick(AjaxRequestTarget target) { editPlasmapheresisModel.setObject(null); target.add(editPlasmapheresisContainer); } }); editPlasmapheresisForm.add(new AjaxSubmitLink("saveBottom") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.add(editPlasmapheresisContainer); target.add(plasmapheresisContainer); try { plasmapheresisManager.savePlasmapheresis((Plasmapheresis) form.getModelObject()); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } form.getModel().setObject(null); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(editPlasmapheresisComponentsToUpdate .toArray(new Component[editPlasmapheresisComponentsToUpdate.size()])); } }); editPlasmapheresisForm.add(new AjaxLink("cancelBottom") { @Override public void onClick(AjaxRequestTarget target) { editPlasmapheresisModel.setObject(null); target.add(editPlasmapheresisContainer); } }); editPlasmapheresisContainer.add(editPlasmapheresisForm); add(editPlasmapheresisContainer); // Add the add plasmapheresis form PlasmapheresisForm addPlasmapheresisForm = new PlasmapheresisForm("addPlasmapheresisForm", new CompoundPropertyModel<Plasmapheresis>(new Plasmapheresis()), addPlasmapheresisComponentsToUpdate); addPlasmapheresisForm.add(new AjaxSubmitLink("save") { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { target.add(addPlasmapheresisComponentsToUpdate .toArray(new Component[addPlasmapheresisComponentsToUpdate.size()])); target.add(plasmapheresisContainer); Plasmapheresis plasmapheresis = (Plasmapheresis) form.getModelObject(); plasmapheresis.setRadarNumber(radarNumberModel.getObject()); try { plasmapheresisManager.savePlasmapheresis(plasmapheresis); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } form.getModel().setObject(new Plasmapheresis()); plasmapheresisContainer.setVisible(true); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(addPlasmapheresisComponentsToUpdate .toArray(new Component[addPlasmapheresisComponentsToUpdate.size()])); } }); add(addPlasmapheresisForm); }
From source file:org.patientview.radar.web.panels.RelapsePanel.java
License:Open Source License
public RelapsePanel(String id, final IModel<Long> radarNumberModel) { super(id);/*w w w.j ava 2s . c o m*/ setOutputMarkupId(true); setOutputMarkupPlaceholderTag(true); final IModel<Boolean> relapseListVisibilityModel = new Model<Boolean>(false); if (radarNumberModel.getObject() != null) { relapseListVisibilityModel .setObject(!relapseManager.getRelapsesByRadarNumber(radarNumberModel.getObject()).isEmpty()); } final WebMarkupContainer relapseListViewContainer = new WebMarkupContainer("relapseListViewContainer") { @Override public boolean isVisible() { return relapseListVisibilityModel.getObject(); } }; relapseListViewContainer.setOutputMarkupId(true); relapseListViewContainer.setOutputMarkupPlaceholderTag(true); add(relapseListViewContainer); final List<Component> addRelapseComponentsToUpdate = new ArrayList<Component>(); final List<Component> editRelapseComponentsToUpdate = new ArrayList<Component>(); final IModel relapseListModel = new AbstractReadOnlyModel<List>() { @Override public List getObject() { if (radarNumberModel.getObject() != null) { return relapseManager.getRelapsesByRadarNumber(radarNumberModel.getObject()); } return Collections.emptyList(); } }; // final IModel editRelapseModel = new Model<Relapse>(); final MarkupContainer editRelapseContainer = new WebMarkupContainer("editRelapseContainer") { @Override public boolean isVisible() { return editRelapseModel.getObject() != null; } }; editRelapseContainer.setOutputMarkupPlaceholderTag(true); editRelapseContainer.setOutputMarkupId(true); ListView<Relapse> relapseListView = new ListView<Relapse>("relapseListView", relapseListModel) { @Override protected void populateItem(final ListItem<Relapse> item) { item.setModel(new CompoundPropertyModel<Relapse>(item.getModelObject())); item.add(DateLabel.forDatePattern("dateOfRelapse", RadarApplication.DATE_PATTERN)); item.add(new Label("transplantedNative.label")); item.add(new Label("viralTrigger")); item.add(new Label("immunisationTrigger")); item.add(new Label("otherTrigger")); item.add(new Label("drug1")); item.add(new Label("drug2")); item.add(new Label("drug3")); item.add(new Label("remissionAchieved.label")); item.add(DateLabel.forDatePattern("dateOfRemission", RadarApplication.DATE_PATTERN)); AjaxLink ajaxDeleteLink = new AjaxLink("delete") { @Override public void onClick(AjaxRequestTarget target) { Relapse relapse = item.getModelObject(); relapseManager.deleteRelapse(relapse); target.add(addRelapseComponentsToUpdate .toArray(new Component[addRelapseComponentsToUpdate.size()])); target.add(relapseListViewContainer); relapseListVisibilityModel.setObject( !relapseManager.getRelapsesByRadarNumber(radarNumberModel.getObject()).isEmpty()); } }; item.add(ajaxDeleteLink); ajaxDeleteLink.add(RadarBehaviourFactory.getDeleteConfirmationBehaviour()); AjaxLink ajaxEditLink = new AjaxLink("edit") { @Override public void onClick(AjaxRequestTarget target) { editRelapseModel.setObject(item.getModelObject()); target.add(editRelapseContainer); } }; item.add(ajaxEditLink); AuthenticatedWebSession session = RadarSecuredSession.get(); if (session.isSignedIn()) { if (session.getRoles().hasRole(User.ROLE_PATIENT)) { ajaxDeleteLink.setVisible(false); ajaxEditLink.setVisible(false); } } } }; relapseListViewContainer.add(relapseListView); // General details TextField<Long> radarNumber = new TextField<Long>("radarNumber", radarNumberModel); radarNumber.setEnabled(false); add(radarNumber); add(new TextField("hospitalNumber", RadarModelFactory.getHospitalNumberModel(radarNumberModel, patientManager))); add(new TextField("diagnosis", new PropertyModel( RadarModelFactory.getDiagnosisCodeModel(radarNumberModel, diagnosisManager), "abbreviation"))); add(new TextField("firstName", RadarModelFactory.getFirstNameModel(radarNumberModel, patientManager))); add(new TextField("surname", RadarModelFactory.getSurnameModel(radarNumberModel, patientManager))); add(new DateTextField("dob", RadarModelFactory.getDobModel(radarNumberModel, patientManager), RadarApplication.DATE_PATTERN)); RelapseForm editRelapseForm = new RelapseForm("editRelapseForm", new CompoundPropertyModel<Relapse>(editRelapseModel), editRelapseComponentsToUpdate); editRelapseForm.add(new AjaxSubmitLink("saveTop") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { relapseManager.saveRelapse((Relapse) form.getModelObject()); form.getModel().setObject(null); target.add(editRelapseContainer); target.add(relapseListViewContainer); target.add(form); target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add( editRelapseComponentsToUpdate.toArray(new Component[editRelapseComponentsToUpdate.size()])); } }); editRelapseForm.add(new AjaxLink("cancelTop") { @Override public void onClick(AjaxRequestTarget target) { editRelapseModel.setObject(null); target.add(editRelapseContainer); } }); editRelapseForm.add(new AjaxSubmitLink("saveBottom") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { relapseManager.saveRelapse((Relapse) form.getModelObject()); form.getModel().setObject(null); target.add(editRelapseContainer); target.add(relapseListViewContainer); target.add(form); target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add( editRelapseComponentsToUpdate.toArray(new Component[editRelapseComponentsToUpdate.size()])); } }); editRelapseForm.add(new AjaxLink("cancelBottom") { @Override public void onClick(AjaxRequestTarget target) { editRelapseModel.setObject(null); target.add(editRelapseContainer); } }); editRelapseContainer.add(editRelapseForm); add(editRelapseContainer); WebMarkupContainer addRelapseFormContainer = new WebMarkupContainer("addRelapseFormContainer"); Form<Relapse> addRelapseform = new RelapseForm("addRelapseForm", new CompoundPropertyModel<Relapse>(new Relapse()), addRelapseComponentsToUpdate); addRelapseform.setOutputMarkupId(true); addRelapseform.setOutputMarkupPlaceholderTag(true); addRelapseform.add(new AjaxSubmitLink("submit") { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { Relapse relapse = (Relapse) form.getModelObject(); relapse.setRadarNumber(radarNumberModel.getObject()); relapseManager.saveRelapse(relapse); target.add( addRelapseComponentsToUpdate.toArray(new Component[addRelapseComponentsToUpdate.size()])); relapseListVisibilityModel.setObject(true); target.add(relapseListViewContainer); form.getModel().setObject(new Relapse()); target.add(form); } @Override protected void onError(AjaxRequestTarget ajaxRequestTarget, Form<?> form) { ajaxRequestTarget.add( addRelapseComponentsToUpdate.toArray(new Component[addRelapseComponentsToUpdate.size()])); } }); addRelapseFormContainer.add(addRelapseform); add(addRelapseFormContainer); PlasmaPheresisPanel plasmaPheresisPanel = new PlasmaPheresisPanel("plasmapheresisPanel", radarNumberModel); add(plasmaPheresisPanel); }
From source file:org.patientview.radar.web.panels.subtabs.TreatmentPanel.java
License:Open Source License
public TreatmentPanel(String id, final IModel<Long> radarNumberModel, boolean firstVisit, IModel<Therapy> followingVisitTherapyModel, List<Component> followingVisitComponentsToUpdate) { super(id);// www . j av a2s . com // Immunosuppression including Monoclonals final IModel immunosuppressionTreatmentListModel = new AbstractReadOnlyModel<List>() { @Override public List getObject() { if (radarNumberModel.getObject() != null) { return immunosuppressionManager .getImmunosuppressionTreatmentByRadarNumber(radarNumberModel.getObject()); } return Collections.emptyList(); } }; editImmunosuppressionTreatmentIModel = new Model<ImmunosuppressionTreatment>(); final List<Component> addImmunoSuppressComponentsToUpdate = new ArrayList<Component>(); final List<Component> editImmunoSuppressComponentsToUpdate = new ArrayList<Component>(); final WebMarkupContainer immunosuppressionTreatmentsContainer = new WebMarkupContainer( "immunosuppressionTreatmentsContainer"); // For showing edit from ajax call final MarkupContainer editContainer = new WebMarkupContainer("editContainer") { @Override public boolean isVisible() { return editImmunosuppressionTreatmentIModel.getObject() != null; } }; editContainer.setOutputMarkupId(true); editContainer.setOutputMarkupPlaceholderTag(true); ListView<ImmunosuppressionTreatment> immunosuppressionTreatmentListView = new ListView<ImmunosuppressionTreatment>( "immunosuppressionTreatments", immunosuppressionTreatmentListModel) { @Override protected void populateItem(final ListItem<ImmunosuppressionTreatment> item) { item.setModel(new CompoundPropertyModel<ImmunosuppressionTreatment>(item.getModelObject())); item.add(DateLabel.forDatePattern("startDate", RadarApplication.DATE_PATTERN)); item.add(DateLabel.forDatePattern("endDate", RadarApplication.DATE_PATTERN)); item.add(new Label("immunosuppression.description")); item.add(new Label("cyclophosphamideTotalDose") { @Override public boolean isVisible() { return item.getModelObject().getImmunosuppression().getId().equals(CYCLOPHOSPHAMIDE_ID); } }); AjaxLink ajaxDeleteLink = new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget ajaxRequestTarget) { immunosuppressionManager.deleteImmunosuppressionTreatment(item.getModelObject()); ajaxRequestTarget.add(addImmunoSuppressComponentsToUpdate .toArray(new Component[addImmunoSuppressComponentsToUpdate.size()])); ajaxRequestTarget.add(immunosuppressionTreatmentsContainer); } }; item.add(ajaxDeleteLink); ajaxDeleteLink.add(RadarBehaviourFactory.getDeleteConfirmationBehaviour()); AjaxLink ajaxEditLink = new AjaxLink("editLink") { @Override public void onClick(AjaxRequestTarget ajaxRequestTarget) { editImmunosuppressionTreatmentIModel.setObject(item.getModelObject()); ajaxRequestTarget.add(editContainer); } }; item.add(ajaxEditLink); AuthenticatedWebSession session = RadarSecuredSession.get(); if (session.isSignedIn()) { if (session.getRoles().hasRole(User.ROLE_PATIENT)) { ajaxDeleteLink.setVisible(false); ajaxEditLink.setVisible(false); } } immunosuppressionTreatmentsContainer.setVisible(true); } }; immunosuppressionTreatmentsContainer.add(immunosuppressionTreatmentListView); add(immunosuppressionTreatmentsContainer); immunosuppressionTreatmentsContainer.setOutputMarkupId(true); immunosuppressionTreatmentsContainer.setOutputMarkupPlaceholderTag(true); // Construct the form final ImmunosuppressionTreatmentForm addImmunosuppressionForm = new ImmunosuppressionTreatmentForm( "addImmunosuppressionForm", new CompoundPropertyModel<ImmunosuppressionTreatment>(new ImmunosuppressionTreatment()), addImmunoSuppressComponentsToUpdate); ImmunosuppressionTreatmentForm editImmunosuppressionForm = new ImmunosuppressionTreatmentForm( "editImmunosuppressionForm", new CompoundPropertyModel<ImmunosuppressionTreatment>(editImmunosuppressionTreatmentIModel), editImmunoSuppressComponentsToUpdate); editImmunosuppressionForm.add(new AjaxSubmitLink("saveTop") { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { target.add(editContainer); target.add(immunosuppressionTreatmentsContainer); try { immunosuppressionManager .saveImmunosuppressionTreatment((ImmunosuppressionTreatment) form.getModelObject()); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } editImmunosuppressionTreatmentIModel.setObject(null); addImmunosuppressionForm.clearInput(); target.add(addImmunosuppressionForm); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(editImmunoSuppressComponentsToUpdate .toArray(new Component[editImmunoSuppressComponentsToUpdate.size()])); } }); editImmunosuppressionForm.add(new AjaxLink("cancelTop") { @Override public void onClick(AjaxRequestTarget target) { editImmunosuppressionTreatmentIModel.setObject(null); target.add(editContainer); } }); editImmunosuppressionForm.add(new AjaxSubmitLink("saveBottom") { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { target.add(editContainer); target.add(immunosuppressionTreatmentsContainer); try { immunosuppressionManager .saveImmunosuppressionTreatment((ImmunosuppressionTreatment) form.getModelObject()); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } editImmunosuppressionTreatmentIModel.setObject(null); addImmunosuppressionForm.clearInput(); target.add(addImmunosuppressionForm); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(editImmunoSuppressComponentsToUpdate .toArray(new Component[editImmunoSuppressComponentsToUpdate.size()])); } }); editImmunosuppressionForm.add(new AjaxLink("cancelBottom") { @Override public void onClick(AjaxRequestTarget target) { editImmunosuppressionTreatmentIModel.setObject(null); target.add(editContainer); } }); editContainer.add(editImmunosuppressionForm); add(editContainer); addImmunosuppressionForm.add(new AjaxSubmitLink("submit") { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { target.add(immunosuppressionTreatmentsContainer); target.add(addImmunoSuppressComponentsToUpdate .toArray(new Component[addImmunoSuppressComponentsToUpdate.size()])); ImmunosuppressionTreatment immunosuppressionTreatment = (ImmunosuppressionTreatment) form .getModelObject(); immunosuppressionTreatment.setRadarNumber(radarNumberModel.getObject()); try { immunosuppressionManager.saveImmunosuppressionTreatment(immunosuppressionTreatment); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } form.getModel().setObject(new ImmunosuppressionTreatment()); immunosuppressionTreatmentsContainer.setVisible(true); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(addImmunoSuppressComponentsToUpdate .toArray(new Component[addImmunoSuppressComponentsToUpdate.size()])); } }); add(addImmunosuppressionForm); // Drugs final List<Component> therapyFormComponentsToUpdate = new ArrayList<Component>(); final CompoundPropertyModel<Therapy> firstVisitTherapyFormModel = new CompoundPropertyModel<Therapy>( new LoadableDetachableModel<Therapy>() { @Override public Therapy load() { Therapy therapyModelObject = null; if (radarNumberModel.getObject() != null) { therapyModelObject = therapyManager .getFirstTherapyByRadarNumber(radarNumberModel.getObject()); } if (therapyModelObject == null) { therapyModelObject = new Therapy(); therapyModelObject.setSequenceNumber(1); } return therapyModelObject; } }); CompoundPropertyModel<Therapy> therapyFormModel; if (firstVisit) { therapyFormModel = firstVisitTherapyFormModel; } else { therapyFormModel = new CompoundPropertyModel<Therapy>(followingVisitTherapyModel); } final Form<Therapy> therapyForm = new Form<Therapy>("therapyForm", therapyFormModel) { @Override protected void onSubmit() { Therapy therapy = getModelObject(); therapy.setRadarNumber(radarNumberModel.getObject()); therapyManager.saveTherapy(therapy); } }; final IModel<Boolean> isSrnsModel = RadarModelFactory.getIsSrnsModel(radarNumberModel, diagnosisManager); IModel firstColumnLabelModel = new LoadableDetachableModel() { @Override protected Object load() { return isSrnsModel.getObject() ? "Prior to Referral" : "Drugs in the 4 weeks after Biopsy"; } }; Label successLabelTop = RadarComponentFactory.getSuccessMessageLabel("successMessageTop", therapyForm, therapyFormComponentsToUpdate); Label errorLabelTop = RadarComponentFactory.getErrorMessageLabel("errorMessageTop", therapyForm, therapyFormComponentsToUpdate); Label successLabelBottom = RadarComponentFactory.getSuccessMessageLabel("successMessageBottom", therapyForm, therapyFormComponentsToUpdate); Label errorLabelBottom = RadarComponentFactory.getErrorMessageLabel("errorMessageBottom", therapyForm, therapyFormComponentsToUpdate); RadarRequiredDateTextField treatmentRecordDate = new RadarRequiredDateTextField("treatmentRecordDate", therapyForm, therapyFormComponentsToUpdate); therapyForm.add(treatmentRecordDate); Label firstColumnLabel = new Label("firstColumnLabel", firstColumnLabelModel); therapyForm.add(firstColumnLabel); WebMarkupContainer currentContainer = new WebMarkupContainer("currentContainer") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }; therapyForm.add(currentContainer); WebMarkupContainer nsaidContainerParent = new WebMarkupContainer("nsaidContainerParent") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }; YesNoRadioGroupPanel nsaidContainer = new YesNoRadioGroupPanel("nsaidContainer", true, (CompoundPropertyModel) therapyFormModel, "nsaid"); nsaidContainerParent.add(nsaidContainer); therapyForm.add(nsaidContainerParent); nsaidContainerParent.add(new YesNoRadioGroupPanel("nsaidPriorContainer", true, (CompoundPropertyModel) therapyFormModel, "nsaidPrior") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }); WebMarkupContainer diureticContainerParent = new WebMarkupContainer("diureticContainerParent") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }; YesNoRadioGroupPanel diureticContainer = new YesNoRadioGroupPanel("diureticContainer", true, (CompoundPropertyModel) therapyFormModel, "diuretic"); diureticContainerParent.add(diureticContainer); therapyForm.add(diureticContainerParent); diureticContainerParent.add(new YesNoRadioGroupPanel("diureticPriorContainer", true, (CompoundPropertyModel) therapyFormModel, "diureticPrior") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }); boolean antihypertensiveToggleInit = (Boolean.FALSE .equals(therapyForm.getModelObject().getAntihypertensive()) && Boolean.FALSE.equals(therapyForm.getModelObject().getAntihypertensivePrior())) || (therapyForm.getModelObject().getAntihypertensive() == null && therapyForm.getModelObject().getAntihypertensivePrior() == null) ? false : true; final IModel<Boolean> antihypertensiveToggleModel = new Model<Boolean>(antihypertensiveToggleInit); AjaxFormChoiceComponentUpdatingBehavior antihypertensiveToggleBehaviour = new AjaxFormChoiceComponentUpdatingBehavior() { @Override protected void onUpdate(AjaxRequestTarget target) { antihypertensiveToggleModel.setObject(therapyForm.getModelObject().getAntihypertensive()); target.add( therapyFormComponentsToUpdate.toArray(new Component[therapyFormComponentsToUpdate.size()])); } }; AjaxFormChoiceComponentUpdatingBehavior antihypertensiveToggleBehaviour2 = new AjaxFormChoiceComponentUpdatingBehavior() { @Override protected void onUpdate(AjaxRequestTarget target) { antihypertensiveToggleModel.setObject(therapyForm.getModelObject().getAntihypertensivePrior()); target.add( therapyFormComponentsToUpdate.toArray(new Component[therapyFormComponentsToUpdate.size()])); } }; YesNoRadioGroupPanel antihypertensiveContainer = new YesNoRadioGroupPanel("antihypertensiveContainer", true, therapyFormModel, "antihypertensive", antihypertensiveToggleBehaviour); therapyForm.add(antihypertensiveContainer); therapyForm.add(new YesNoRadioGroupPanel("antihypertensivePriorContainer", true, therapyFormModel, "antihypertensivePrior", antihypertensiveToggleBehaviour2) { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }); WebMarkupContainer aceInhibitorContainer = new WebMarkupContainer("aceInhibitorContainer") { @Override public boolean isVisible() { return antihypertensiveToggleModel.getObject(); } }; therapyFormComponentsToUpdate.add(aceInhibitorContainer); aceInhibitorContainer.setOutputMarkupId(true); aceInhibitorContainer.setOutputMarkupPlaceholderTag(true); YesNoRadioGroupPanel aceInhibitorRadioGroup = new YesNoRadioGroupPanel("aceInhibitorRadioGroup", true, therapyFormModel, "aceInhibitor"); aceInhibitorContainer.add(aceInhibitorRadioGroup); YesNoRadioGroupPanel aceInhibitorPriorRadioGroup = new YesNoRadioGroupPanel("aceInhibitorPriorRadioGroup", true, therapyFormModel, "aceInhibitorPrior") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }; aceInhibitorContainer.add(aceInhibitorPriorRadioGroup); therapyForm.add(aceInhibitorContainer); WebMarkupContainer arb1AntagonistContainer = new WebMarkupContainer("arb1AntagonistContainer") { @Override public boolean isVisible() { return antihypertensiveToggleModel.getObject(); } }; therapyFormComponentsToUpdate.add(arb1AntagonistContainer); arb1AntagonistContainer.setOutputMarkupId(true); arb1AntagonistContainer.setOutputMarkupPlaceholderTag(true); arb1AntagonistContainer.add( new YesNoRadioGroupPanel("arb1AntagonistRadioGroup", true, therapyFormModel, "arb1Antagonist")); arb1AntagonistContainer.add(new YesNoRadioGroupPanel("arb1AntagonistPriorRadioGroup", true, therapyFormModel, "arb1AntagonistPrior") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }); therapyForm.add(arb1AntagonistContainer); WebMarkupContainer calciumChannelBlockerContainer = new WebMarkupContainer( "calciumChannelBlockerContainer") { @Override public boolean isVisible() { return antihypertensiveToggleModel.getObject(); } }; therapyFormComponentsToUpdate.add(calciumChannelBlockerContainer); calciumChannelBlockerContainer.setOutputMarkupId(true); calciumChannelBlockerContainer.setOutputMarkupPlaceholderTag(true); calciumChannelBlockerContainer.add(new YesNoRadioGroupPanel("calciumChannelBlockerRadioGroup", true, therapyFormModel, "calciumChannelBlocker")); calciumChannelBlockerContainer.add(new YesNoRadioGroupPanel("calciumChannelBlockerPriorRadioGroup", true, therapyFormModel, "calciumChannelBlockerPrior") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }); therapyForm.add(calciumChannelBlockerContainer); WebMarkupContainer betaBlockerContainer = new WebMarkupContainer("betaBlockerContainer") { @Override public boolean isVisible() { return antihypertensiveToggleModel.getObject(); } }; therapyFormComponentsToUpdate.add(betaBlockerContainer); betaBlockerContainer.setOutputMarkupId(true); betaBlockerContainer.setOutputMarkupPlaceholderTag(true); betaBlockerContainer .add(new YesNoRadioGroupPanel("betaBlockerRadioGroup", true, therapyFormModel, "betaBlocker")); betaBlockerContainer.add( new YesNoRadioGroupPanel("betaBlockerPriorRadioGroup", true, therapyFormModel, "betaBlockerPrior") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }); therapyForm.add(betaBlockerContainer); WebMarkupContainer otherAntihypertensiveContainer = new WebMarkupContainer( "otherAntihypertensiveContainer") { @Override public boolean isVisible() { return antihypertensiveToggleModel.getObject(); } }; therapyFormComponentsToUpdate.add(otherAntihypertensiveContainer); otherAntihypertensiveContainer.setOutputMarkupId(true); otherAntihypertensiveContainer.setOutputMarkupPlaceholderTag(true); otherAntihypertensiveContainer.add(new YesNoRadioGroupPanel("otherAntihypertensiveRadioGroup", true, therapyFormModel, "otherAntihypertensive")); otherAntihypertensiveContainer.add(new YesNoRadioGroupPanel("otherAntihypertensivePriorRadioGroup", true, therapyFormModel, "otherAntihypertensivePrior") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }); therapyForm.add(otherAntihypertensiveContainer); therapyForm.add(new YesNoRadioGroupPanel("insulinContainer", true, therapyFormModel, "insulin")); therapyForm.add(new YesNoRadioGroupPanel("insulinPriorContainer", true, therapyFormModel, "insulinPrior") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }); WebMarkupContainer lipidLoweringAgentContainerParent = new WebMarkupContainer( "lipidLoweringAgentContainerParent") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }; lipidLoweringAgentContainerParent.add(new YesNoRadioGroupPanel("lipidLoweringAgentContainer", true, therapyFormModel, "lipidLoweringAgent")); lipidLoweringAgentContainerParent.add(new YesNoRadioGroupPanel("lipidLoweringAgentPriorContainer", true, therapyFormModel, "lipidLoweringAgentPrior") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }); therapyForm.add(lipidLoweringAgentContainerParent); therapyForm.add(new YesNoRadioGroupPanel("epoContainer", true, therapyFormModel, "epo")); therapyForm.add(new YesNoRadioGroupPanel("epoPriorContainer", true, therapyFormModel, "epoPrior") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }); therapyForm.add(new TextField("other1")); WebMarkupContainer other1PriorContainer = new WebMarkupContainer("other1PriorContainer") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }; other1PriorContainer.add(new TextField("other1Prior")); therapyForm.add(other1PriorContainer); therapyForm.add(new TextField("other2")); WebMarkupContainer other2PriorContainer = new WebMarkupContainer("other2PriorContainer") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }; other2PriorContainer.add(new TextField("other2Prior")); therapyForm.add(other2PriorContainer); therapyForm.add(new TextField("other3")); WebMarkupContainer other3PriorContainer = new WebMarkupContainer("other3PriorContainer") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }; other3PriorContainer.add(new TextField("other3Prior")); therapyForm.add(other3PriorContainer); therapyForm.add(new TextField("other4")); WebMarkupContainer other4PriorContainer = new WebMarkupContainer("other4PriorContainer") { @Override public boolean isVisible() { return isSrnsModel.getObject(); } }; other4PriorContainer.add(new TextField("other4Prior")); therapyForm.add(other4PriorContainer); AjaxSubmitLink saveTop = new AjaxSubmitLink("saveTop", therapyForm) { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.add( therapyFormComponentsToUpdate.toArray(new Component[therapyFormComponentsToUpdate.size()])); target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add( therapyFormComponentsToUpdate.toArray(new Component[therapyFormComponentsToUpdate.size()])); } }; therapyForm.add(saveTop); add(therapyForm); AjaxSubmitLink saveBottom = new AjaxSubmitLink("saveBottom", therapyForm) { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.add( therapyFormComponentsToUpdate.toArray(new Component[therapyFormComponentsToUpdate.size()])); target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add( therapyFormComponentsToUpdate.toArray(new Component[therapyFormComponentsToUpdate.size()])); } }; therapyForm.add(saveBottom); add(therapyForm); // Plasmapheresis PlasmaPheresisPanel plasmaPheresisPanel = new PlasmaPheresisPanel("plasmapheresisPanel", radarNumberModel); add(plasmaPheresisPanel); DialysisTablePanel dialysisTablePanel = new DialysisTablePanel("dialysisContainer", radarNumberModel); dialysisTablePanel.setVisible(firstVisit); add(dialysisTablePanel); if (!firstVisit) { for (Component component : followingVisitComponentsToUpdate) { therapyFormComponentsToUpdate.add(component); } } }
From source file:org.patientview.radar.web.panels.tables.DialysisTablePanel.java
License:Open Source License
public DialysisTablePanel(String id, final IModel<Long> radarNumberModel) { super(id);//from w ww . java2s .c o m final IModel dialysisListModel = new AbstractReadOnlyModel<List>() { @Override public List getObject() { if (radarNumberModel.getObject() != null) { return treatmentManager.getTreatmentsByRadarNumber(radarNumberModel.getObject()); } return Collections.emptyList(); } }; final WebMarkupContainer dialysisContainer = new WebMarkupContainer("dialysisContainer"); add(dialysisContainer); final List<Component> addDialysisFormComponentsToUpdate = new ArrayList<Component>(); final List<Component> editDialysisFormComponentsToUpdate = new ArrayList<Component>(); final IModel editDialysisModel = new Model<Treatment>(); // Edit dialysis container final MarkupContainer editDialysisContainer = new WebMarkupContainer("editDialysisContainer") { @Override public boolean isVisible() { return editDialysisModel.getObject() != null; } }; editDialysisContainer.setOutputMarkupPlaceholderTag(true); editDialysisContainer.setOutputMarkupPlaceholderTag(true); add(editDialysisContainer); // Dialysis ListView<Treatment> dialysisListView = new ListView<Treatment>("dialysis", dialysisListModel) { @Override protected void populateItem(final ListItem<Treatment> item) { item.setModel(new CompoundPropertyModel<Treatment>(item.getModelObject())); item.add(new Label("treatmentModality.description")); item.add(DateLabel.forDatePattern("startDate", RadarApplication.DATE_PATTERN)); item.add(DateLabel.forDatePattern("endDate", RadarApplication.DATE_PATTERN)); AjaxLink ajaxDeleteLink = new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget target) { Treatment treatment = item.getModelObject(); treatmentManager.deleteTreatment(treatment); target.add(addDialysisFormComponentsToUpdate .toArray(new Component[addDialysisFormComponentsToUpdate.size()])); target.add(dialysisContainer); } }; item.add(ajaxDeleteLink); ajaxDeleteLink.add(RadarBehaviourFactory.getDeleteConfirmationBehaviour()); AjaxLink ajaxEditLink = new AjaxLink("editLink") { @Override public void onClick(AjaxRequestTarget target) { editDialysisModel.setObject(item.getModelObject()); target.add(editDialysisContainer); } }; item.add(ajaxEditLink); AuthenticatedWebSession session = RadarSecuredSession.get(); if (session.isSignedIn()) { if (session.getRoles().hasRole(User.ROLE_PATIENT)) { ajaxDeleteLink.setVisible(false); ajaxEditLink.setVisible(false); } } } }; dialysisContainer.setOutputMarkupId(true); dialysisContainer.setOutputMarkupPlaceholderTag(true); dialysisContainer.add(dialysisListView); DialysisForm editDialysisForm = new DialysisForm("editDialysisForm", new CompoundPropertyModel<Treatment>(editDialysisModel), editDialysisFormComponentsToUpdate); editDialysisForm.add(new AjaxSubmitLink("saveTop") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.add(editDialysisContainer); target.add(dialysisContainer); try { treatmentManager.saveTreatment((Treatment) form.getModelObject()); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } form.getModel().setObject(null); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(editDialysisFormComponentsToUpdate .toArray(new Component[editDialysisFormComponentsToUpdate.size()])); } }); editDialysisForm.add(new AjaxLink("cancelTop") { @Override public void onClick(AjaxRequestTarget target) { editDialysisModel.setObject(null); target.add(editDialysisContainer); } }); editDialysisForm.add(new AjaxSubmitLink("saveBottom") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.add(editDialysisContainer); target.add(dialysisContainer); try { treatmentManager.saveTreatment((Treatment) form.getModelObject()); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } form.getModel().setObject(null); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(editDialysisFormComponentsToUpdate .toArray(new Component[editDialysisFormComponentsToUpdate.size()])); } }); editDialysisForm.add(new AjaxLink("cancelBottom") { @Override public void onClick(AjaxRequestTarget target) { editDialysisModel.setObject(null); target.add(editDialysisContainer); } }); editDialysisContainer.add(editDialysisForm); // Add dialysis form DialysisForm addDialysisForm = new DialysisForm("addDialysisForm", new CompoundPropertyModel<Treatment>(new Treatment()), addDialysisFormComponentsToUpdate); addDialysisForm.add(new AjaxSubmitLink("save") { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { target.add(addDialysisFormComponentsToUpdate .toArray(new Component[addDialysisFormComponentsToUpdate.size()])); target.add(dialysisContainer); Treatment treatment = (Treatment) form.getModelObject(); treatment.setRadarNumber(radarNumberModel.getObject()); try { treatmentManager.saveTreatment(treatment); } catch (InvalidModelException e) { for (String error : e.getErrors()) { error(error); } return; } form.getModel().setObject(new Treatment()); dialysisContainer.setVisible(true); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(addDialysisFormComponentsToUpdate .toArray(new Component[addDialysisFormComponentsToUpdate.size()])); } }); add(addDialysisForm); }