List of usage examples for org.apache.wicket.ajax AjaxEventBehavior AjaxEventBehavior
public AjaxEventBehavior(String event)
From source file:org.hippoecm.frontend.plugins.standards.list.ListColumn.java
License:Apache License
protected void addLinkBehavior(final Item<ICellPopulator<T>> item, final IModel<T> model) { if (isLink()) { item.add(new AjaxEventBehavior("onclick") { @Override//from w ww.j a va2s . c om protected void onEvent(AjaxRequestTarget target) { ListDataTable dataTable = item.findParent(ListDataTable.class); dataTable.getSelectionListener().selectionChanged(model); } }); } }
From source file:org.hippoecm.frontend.plugins.standards.panelperspective.breadcrumb.AjaxBreadCrumbLink.java
License:Apache License
public AjaxBreadCrumbLink(String id, IBreadCrumbModel breadCrumbModel) { super(id, breadCrumbModel); add(new AjaxEventBehavior("onclick") { private static final long serialVersionUID = 1L; @Override//from w w w .java 2 s . co m protected void onEvent(AjaxRequestTarget target) { onClick(target); } @Override protected void onComponentTag(ComponentTag tag) { // add the onclick handler only if link is enabled if (isLinkEnabled()) { super.onComponentTag(tag); } } }); }
From source file:org.hippoecm.frontend.plugins.standards.tabs.TabbedPanel.java
License:Apache License
protected Behavior newBehavior(final int tabIndex) { return new AjaxEventBehavior("onclick") { private static final long serialVersionUID = 1L; @Override/*from ww w . java 2 s.c o m*/ protected void onEvent(AjaxRequestTarget target) { plugin.onSelect(tabs.get(tabIndex), target); } }; }
From source file:org.hippoecm.frontend.widgets.RadioGroupWidget.java
License:Apache License
/** * Instantiates a new radio group widget. * //from ww w . j a v a 2 s . com * @param id * The widget id * @param choices * List containing {@link Radio} model objects * @param model the model * Model that represents selected {@link Radio} item * */ public RadioGroupWidget(String id, List<? extends T> choices, IModel<T> model) { super(id); final RadioGroup<T> group = new RadioGroup<T>("widget", model); group.setRenderBodyOnly(false); group.add(new ListView<T>("choices", choices) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<T> item) { final Radio<T> radio = new Radio<T>("radio", item.getModel()); radio.add(new AjaxEventBehavior("onchange") { private static final long serialVersionUID = 1L; @Override protected void onEvent(AjaxRequestTarget target) { group.processInput(); onChange(target, group.getModelObject()); } /* @Override protected CharSequence getEventHandler() { return generateCallbackScript(new AppendingStringBuffer("wicketAjaxPost('").append( getCallbackUrl()).append( "', wicketSerialize(document.getElementById('" + radio.getMarkupId() + "'))")); }*/ }); item.add(radio); String label = item.getDefaultModelObjectAsString(); radio.setLabel(new Model<String>(getLocalizer().getString(label, this, label))); item.add(new SimpleFormComponentLabel("label", radio)); RadioGroupWidget.this.populateItem(item); } }); add(group); }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.simplified.QuestionCategoryOpenAnswerDefinitionPanel.java
License:Open Source License
protected void addLinkComponent(IModel labelModel, IModel descriptionModel) { Label value = new Label("value", new PropertyModel(this, "openValue")); value.setOutputMarkupId(true).add(new QuestionCategorySelectionBehavior()); value.add(new AjaxEventBehavior("onclick") { /**//w w w . j a v a 2s . c o m * */ private static final long serialVersionUID = 1L; @Override protected void onEvent(AjaxRequestTarget target) { OpenAnswer openAnswer = getOpenAnswer(); pad.setData(openAnswer != null ? openAnswer.getData() : null); padWindow.show(target); } }); add(value); // Create pad modal window add(padWindow = createPadModalWindow("padModal")); padWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { /** * */ private static final long serialVersionUID = 1L; public void onClose(AjaxRequestTarget target) { if (getOpenAnswer() == null) { activeQuestionnaireAdministrationService.deleteAnswer(getQuestion(), getQuestionCategory()); } target.addComponent(QuestionCategoryOpenAnswerDefinitionPanel.this); QuestionCategoryOpenAnswerDefinitionPanel.this.fireSelectionEvent(target, isSelected()); } }); }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.simplified.SimplifiedOpenAnswerDefinitionPanel.java
License:Open Source License
/** * @param id// w w w. j av a 2s. co m * @param questionModel * @param questionCategoryModel * @param openAnswerDefinitionModel */ @SuppressWarnings("serial") public SimplifiedOpenAnswerDefinitionPanel(String id, IModel questionModel, IModel questionCategoryModel, IModel openAnswerDefinitionModel) { super(id, questionModel, questionCategoryModel, openAnswerDefinitionModel); setOutputMarkupId(true); updateState(); // make a clickable label with the current value. Label value = new Label("value", new PropertyModel(this, "openValue")); value.setOutputMarkupId(true).add(new QuestionCategorySelectionBehavior()); value.add(new AjaxEventBehavior("onclick") { @Override protected void onEvent(AjaxRequestTarget target) { padWindow.show(target); } }); add(value); add(new Label("label", getCategoryLabelResourceModel())); QuestionnaireStringResourceModel unitLabelModel = new QuestionnaireStringResourceModel( getOpenAnswerDefinitionModel(), "unitLabel"); add(new Label("unit", unitLabelModel).setVisible(StringUtils.hasLength(unitLabelModel.getString()))); AjaxImageLink link = new AjaxImageLink("link", new QuestionnaireStringResourceModel( activeQuestionnaireAdministrationService.getQuestionnaire(), "clickHere")) { @Override public void onClick(AjaxRequestTarget target) { padWindow.show(target); } }; link.getLink().add(new QuestionCategorySelectionBehavior()); link.getLink().add(new NoDragBehavior()); add(link); // Create modal window add(padWindow = new ModalWindow("padModal")); padWindow.setCssClassName("onyx"); padWindow.setInitialWidth(288); padWindow.setInitialHeight(365); padWindow.setResizable(false); final AbstractOpenAnswerDefinitionPanel pad = createPad(padWindow); padWindow.setContent(pad); // same as cancel padWindow.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { public boolean onCloseButtonClicked(AjaxRequestTarget target) { return true; } }); padWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { public void onClose(AjaxRequestTarget target) { // fire event to other selectors in case of exclusive choice IQuestionCategorySelectionListener listener = SimplifiedOpenAnswerDefinitionPanel.this .findParent(IQuestionCategorySelectionListener.class); if (listener != null) { listener.onQuestionCategorySelection(target, getQuestionModel(), getQuestionCategoryModel(), !isQuestionCategorySelected()); } target.addComponent(SimplifiedOpenAnswerDefinitionPanel.this); } }); }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.DefaultOpenAnswerDefinitionPanel.java
License:Open Source License
private void setup() { setOutputMarkupId(true);//from w ww. j ava 2 s . c o m if (!activeQuestionnaireAdministrationService.isQuestionnaireDevelopmentMode()) { OpenAnswer previousAnswer = activeQuestionnaireAdministrationService.findOpenAnswer(getQuestion(), getQuestionCategory().getCategory(), getOpenAnswerDefinition()); if (previousAnswer != null) { setData(previousAnswer.getData()); } } QuestionnaireStringResourceModel openLabel = new QuestionnaireStringResourceModel( getOpenAnswerDefinitionModel(), "label"); QuestionnaireStringResourceModel unitLabel = new QuestionnaireStringResourceModel( getOpenAnswerDefinitionModel(), "unitLabel"); add(new Label("label", openLabel)); if (getOpenAnswerDefinition().getDefaultValues().size() == 1) { setData(getOpenAnswerDefinition().getDefaultValues().get(0)); } openField = createDataField(unitLabel); openField.getField().setOutputMarkupId(true); add(openField); // validators if (!activeQuestionnaireAdministrationService.isQuestionnaireDevelopmentMode()) { for (IValidator<?> validator : OpenAnswerDefinitionValidatorFactory.getValidators( getOpenAnswerDefinitionModel(), activeQuestionnaireAdministrationService.getQuestionnaireParticipant().getParticipant())) { openField.add(validator); } } // at least this validator for textual input if (getOpenAnswerDefinition().getDataType().equals(DataType.TEXT) && getOpenAnswerDefinition().getDefaultValues().isEmpty()) { // see OpenAnswer.textValue column length openField.add( new DataValidator(new StringValidator.MaximumLengthValidator(MAXIMUM_LENGTH), DataType.TEXT)); } // behaviors openField.add(new InvalidFormFieldBehavior()); if (!activeQuestionnaireAdministrationService.isQuestionnaireDevelopmentMode()) { openField.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { // persist data activeQuestionnaireAdministrationService.answer(getQuestion(), getQuestionCategory(), getOpenAnswerDefinition(), getData()); // clean a previous error message updateFeedback(target); fireQuestionCategorySelection(target, getQuestionModel(), getQuestionCategoryModel(), true); } @Override protected void onError(AjaxRequestTarget target, RuntimeException e) { super.onError(target, e); // display error messages updateFeedback(target); } }); if (getOpenAnswerDefinition().getDefaultValues().size() == 0) { openField.add(new AjaxEventBehavior("onclick") { private static final long serialVersionUID = 1L; @Override protected void onEvent(AjaxRequestTarget target) { // persist data // do not fire event if category was already selected if (activeQuestionnaireAdministrationService.findAnswer(getQuestion(), getQuestionCategory().getCategory()) == null) { openField.focusField(target); // persist data for category activeQuestionnaireAdministrationService.answer(getQuestion(), getQuestionCategory()); fireQuestionCategorySelection(target, getQuestionModel(), getQuestionCategoryModel(), true); } } }); } } // set the label of the field openField.setLabel(QuestionnaireStringResourceModelHelper.getStringResourceModel(getQuestion(), getQuestionCategory(), getOpenAnswerDefinition())); }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.QuestionCategoryCheckBoxPanel.java
License:Open Source License
/** * Constructor./*from ww w.j a v a2s. c om*/ * * @param id * @param questionModel * @param questionCategoryModel * @param selectionsModel check group selections model * @param radioLabelVisible */ @SuppressWarnings("serial") public QuestionCategoryCheckBoxPanel(String id, IModel<Question> questionModel, IModel<QuestionCategory> questionCategoryModel, IModel<Collection<IModel<QuestionCategory>>> selectionsModel, boolean radioLabelVisible) { super(id, questionModel, questionCategoryModel); setOutputMarkupId(true); // previous answer or default selection QuestionCategory questionCategory = (QuestionCategory) getDefaultModelObject(); QuestionCategoryCheckBoxModel selectionModel = new QuestionCategoryCheckBoxModel(selectionsModel, questionCategoryModel); if (!activeQuestionnaireAdministrationService.isQuestionnaireDevelopmentMode()) { CategoryAnswer previousAnswer = activeQuestionnaireAdministrationService .findAnswer(questionModel.getObject(), questionCategory); if (previousAnswer != null) selectionModel.select(); } checkbox = new CheckBox("checkbox", selectionModel); checkbox.setLabel(new QuestionnaireStringResourceModel(questionCategoryModel, "label")); // persist selection on change event // and make sure there is no active open field previously selected if (!activeQuestionnaireAdministrationService.isQuestionnaireDevelopmentMode()) { checkbox.add(new AjaxEventBehavior("onchange") { @Override protected void onEvent(AjaxRequestTarget target) { // toggle selection // note: call for setModelObject to ensure modelChanged trigger is properly called checkbox.setModelObject(!getSelectionModel().isSelected()); if (getSelectionModel().isSelected()) { activeQuestionnaireAdministrationService.answer(getQuestion(), getQuestionCategory(), getQuestionCategory().getCategory().getOpenAnswerDefinition(), null); } else { activeQuestionnaireAdministrationService.deleteAnswer(getQuestion(), getQuestionCategory()); } if (getOpenField() != null) { if (!getSelectionModel().isSelected()) { resetOpenAnswerDefinitionPanels(target, getOpenField(), getQuestionCategoryModel()); updateFeedbackPanel(target); } } fireQuestionCategorySelection(target, getQuestionModel(), getQuestionCategoryModel(), getSelectionModel().isSelected()); } }); } FormComponentLabel checkboxLabel = new FormComponentLabel("categoryLabel", checkbox); add(checkboxLabel); checkboxLabel.add(checkbox); checkboxLabel.add(new Label("label", checkbox.getLabel()).setRenderBodyOnly(true) .setVisible(radioLabelVisible).setEscapeModelStrings(false)); if (questionCategory.getCategory().getOpenAnswerDefinition() != null) { // there is an open field openField = newOpenAnswerDefinitionPanel("open"); add(openField); checkbox.add(new AttributeAppender("class", new Model<String>("checkbox-open"), " ")); checkboxLabel.add(new AttributeModifier("class", new Model<String>("label-open"))); } else { // no open answer add(new EmptyPanel("open").setVisible(false)); } }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.QuestionCategoryRadioPanel.java
License:Open Source License
/** * Constructor.// w w w .j a va 2 s. c om * * @param id * @param questionModel * @param questionCategoryModel * @param radioLabelVisible */ @SuppressWarnings("serial") public QuestionCategoryRadioPanel(String id, IModel<Question> questionModel, IModel<QuestionCategory> questionCategoryModel, RadioGroup<QuestionCategory> radioGroup, boolean radioLabelVisible) { super(id, questionModel, questionCategoryModel); this.radioGroup = radioGroup; // previous answer or default selection QuestionCategory questionCategory = (QuestionCategory) questionCategoryModel.getObject(); Question question = (Question) questionModel.getObject(); Radio<QuestionCategory> radio = new Radio<QuestionCategory>("radio", questionCategoryModel); radio.setLabel(new QuestionnaireStringResourceModel(questionCategoryModel, "label")); // persist selection on change event // and make sure there is no active open field previously selected if (!activeQuestionnaireAdministrationService.isQuestionnaireDevelopmentMode()) { radio.add(new AjaxEventBehavior("onchange") { @Override protected void onEvent(AjaxRequestTarget target) { // make the radio group active for the selection QuestionCategoryRadioPanel.this.radioGroup.setModel(getQuestionCategoryModel()); // exclusive choice, only one answer per question activeQuestionnaireAdministrationService.deleteAnswers(getQuestion()); activeQuestionnaireAdministrationService.answer(getQuestion(), getQuestionCategory()); // make sure a previously selected open field is not asked for resetOpenAnswerDefinitionPanels(target, QuestionCategoryRadioPanel.this.radioGroup, getQuestionCategoryModel()); updateFeedbackPanel(target); fireQuestionCategorySelection(target, getQuestionModel(), getQuestionCategoryModel(), true); } }); } FormComponentLabel radioLabel = new FormComponentLabel("categoryLabel", radio); add(radioLabel); radioLabel.add(radio); radioLabel.add(new Label("label", radio.getLabel()).setRenderBodyOnly(true).setVisible(radioLabelVisible) .setEscapeModelStrings(false)); if (questionCategory.getCategory().getOpenAnswerDefinition() != null) { // there is an open field openField = newOpenAnswerDefinitionPanel("open"); add(openField); // make radio associated to open answer optionally visible using css styling radio.add(new AttributeAppender("class", new Model<String>("radio-open"), " ")); radioLabel.add(new AttributeModifier("class", new Model<String>("label-open"))); } else { // no open answer add(new EmptyPanel("open").setVisible(false)); } // previous answer or default selection if (!activeQuestionnaireAdministrationService.isQuestionnaireDevelopmentMode()) { CategoryAnswer previousAnswer = activeQuestionnaireAdministrationService.findAnswer(question, questionCategory); if (previousAnswer != null) { radioGroup.setModel(questionCategoryModel); } } }
From source file:org.obiba.onyx.quartz.editor.behavior.VariableNameBehavior.java
License:Open Source License
public VariableNameBehavior(final TextField<String> name, final TextField<String> variable, final Question parentQuestion, final Question question, final Category category) { variableNameDefined = StringUtils.isNotBlank(variable.getModelObject()); if (!variableNameDefined) { variable.setOutputMarkupId(true); variable.setModelObject(//from w w w . j a v a2 s. c o m generateVariableName(parentQuestion, question, category, name.getModelObject())); variable.add(new AttributeModifier("class", true, new Model<String>("autoDefined"))); final AjaxEventBehavior updateVariableNameBehavior = new OnChangeAjaxBehavior() { @Override protected void onUpdate(AjaxRequestTarget target) { if (!variableNameDefined) { variable.setModelObject( generateVariableName(parentQuestion, question, category, name.getModelObject())); target.addComponent(variable); } } }; name.add(updateVariableNameBehavior); variable.add(new AjaxEventBehavior("onclick") { @Override protected void onEvent(AjaxRequestTarget target) { variable.setModelObject(""); variable.add(new AttributeModifier("class", true, new Model<String>("userDefined"))); variableNameDefined = true; target.addComponent(variable); } @Override public boolean isEnabled(Component component) { return !variableNameDefined; } }); } }