List of usage examples for org.apache.wicket.ajax.form AjaxFormSubmitBehavior AjaxFormSubmitBehavior
public AjaxFormSubmitBehavior(String event)
From source file:au.org.theark.core.web.component.wizard.AjaxWizardButtonBar.java
License:Open Source License
private void addAjax(final WizardButton button) { button.add(new AjaxFormSubmitBehavior("onclick") { private static final long serialVersionUID = 1L; @Override/*from w w w . jav a 2 s . co m*/ protected CharSequence getEventHandler() { AppendingStringBuffer handler = new AppendingStringBuffer(); handler.append(super.getEventHandler()); handler.append("; return false;"); return handler; } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return AjaxWizardButtonBar.this.getAjaxCallDecorator(); } @Override protected void onSubmit(AjaxRequestTarget target) { target.add(wizard); } @Override protected void onError(AjaxRequestTarget target) { target.add(wizard); } }); add(button); }
From source file:au.org.theark.core.web.component.wizard.AjaxWizardButtonBar.java
License:Open Source License
private void addAjaxCancel(final WizardButton button) { button.add(new AjaxFormSubmitBehavior("onclick") { private static final long serialVersionUID = 1L; @Override//from w w w .ja v a 2s . co m protected CharSequence getEventHandler() { AppendingStringBuffer handler = new AppendingStringBuffer(); handler.append(super.getEventHandler()); handler.append("; return false;"); return handler; } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return AjaxWizardButtonBar.this.getAjaxCallDecorator(); } @Override protected void onSubmit(AjaxRequestTarget target) { wizard.getWizardModel().cancel(); wizard = new ArkCommonWizard(wizard.getId(), wizard.getWizardSteps(), wizard.getResultListContainer(), wizard.getWizardPanelContainer(), wizard.getWizardPanelFormContainer(), wizard.getSearchPanelContainer(), wizard.getTarget()); wizard.getSearchPanelContainer().setVisible(true); wizard.getResultListContainer().setVisible(true); wizard.getWizardPanelContainer().setVisible(true); cancelWizard(target); target.add(wizard.getSearchPanelContainer()); target.add(wizard.getResultListContainer()); target.add(wizard.getWizardPanelContainer()); target.add(wizard); } @Override protected void onError(AjaxRequestTarget target) { target.add(wizard); } }); add(button); }
From source file:au.org.theark.core.web.component.wizard.AjaxWizardButtonBar.java
License:Open Source License
private void addAjaxFinish(final WizardButton button) { button.add(new AjaxFormSubmitBehavior("onclick") { private static final long serialVersionUID = 1L; @Override//w w w .java2 s.c o m protected CharSequence getEventHandler() { AppendingStringBuffer handler = new AppendingStringBuffer(); handler.append(super.getEventHandler()); handler.append("; return false;"); return handler; } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return AjaxWizardButtonBar.this.getAjaxCallDecorator(); } @Override protected void onSubmit(AjaxRequestTarget target) { wizard.getSearchPanelContainer().setVisible(true); wizard.getResultListContainer().setVisible(true); wizard.getWizardPanelContainer().setVisible(true); wizard.getWizardModel().finish(); target.add(wizard.getSearchPanelContainer()); target.add(wizard.getResultListContainer()); target.add(wizard.getWizardPanelContainer()); target.add(wizard); } @Override protected void onError(AjaxRequestTarget target) { target.add(wizard); } }); add(button); }
From source file:biz.turnonline.ecosystem.origin.frontend.myaccount.page.MyAccountBasics.java
License:Apache License
public MyAccountBasics() { add(new FirebaseAppInit(firebaseConfig)); final MyAccountModel accountModel = new MyAccountModel(); final IModel<Map<String, Country>> countriesModel = new CountriesModel(); setModel(accountModel);// w ww . jav a 2 s. c o m // form Form<Account> form = new Form<Account>("form", accountModel) { private static final long serialVersionUID = -938924956863034465L; @Override protected void onSubmit() { Account account = getModelObject(); send(getPage(), Broadcast.BREADTH, new AccountUpdateEvent(account)); } }; add(form); PropertyModel<Boolean> companyModel = new PropertyModel<>(accountModel, "company"); form.add(new CompanyPersonSwitcher("isCompanyRadioGroup", companyModel)); // account email fieldset form.add(new Label("email", new PropertyModel<>(accountModel, "email"))); // company basic info final CompanyBasicInfo<Account> basicInfo = new CompanyBasicInfo<Account>("companyData", accountModel) { private static final long serialVersionUID = -2992960490517951459L; @Override protected DropDownChoice<LegalForm> provideLegalForm(String componentId) { LegalFormListModel choices = new LegalFormListModel(); return new IndicatingAjaxDropDown<>(componentId, new LegalFormCodeModel(accountModel, "legalForm", choices), choices, new LegalFormRenderer()); } @Override protected void onConfigure() { super.onConfigure(); Account account = getModelObject(); this.setVisible(account.getCompany()); } }; form.add(basicInfo); // company basic info panel behaviors basicInfo.addLegalForm(new OnChangeAjaxBehavior() { private static final long serialVersionUID = 6948210639258798921L; @Override protected void onUpdate(AjaxRequestTarget target) { } }); basicInfo.addVatId(new Behavior() { private static final long serialVersionUID = 100053137512632023L; @Override public void onConfigure(Component component) { super.onConfigure(component); Account account = basicInfo.getModelObject(); boolean visible; if (account == null || account.getBusiness() == null) { visible = true; } else { Boolean vatPayer = account.getBusiness().getVatPayer(); visible = vatPayer == null ? Boolean.FALSE : vatPayer; } component.setVisible(visible); } }); final TextField taxId = basicInfo.getTaxId(); final TextField vatId = basicInfo.getVatId(); final CheckBox vatPayer = basicInfo.getVatPayer(); basicInfo.addVatPayer(new AjaxFormSubmitBehavior(OnChangeAjaxBehavior.EVENT_NAME) { private static final long serialVersionUID = -1238082494184937003L; @Override protected void onSubmit(AjaxRequestTarget target) { Account account = (Account) basicInfo.getDefaultModelObject(); String rawTaxIdValue = taxId.getRawInput(); AccountBusiness business = account.getBusiness(); if (rawTaxIdValue != null && Strings.isEmpty(business == null ? null : business.getVatId())) { // VAT country prefix proposal String country = business == null ? "" : business.getDomicile(); country = country.toUpperCase(); //noinspection unchecked vatId.getModel().setObject(country + rawTaxIdValue); } // must be set manually as getDefaultProcessing() returns false vatPayer.setModelObject(!(business == null ? Boolean.FALSE : business.getVatPayer())); if (target != null) { target.add(vatId.getParent()); } } @Override public boolean getDefaultProcessing() { return false; } }); // personal data panel PersonalDataPanel<Account> personalData = new PersonalDataPanel<Account>("personalData", accountModel) { private static final long serialVersionUID = -2808922906891760016L; @Override protected void onConfigure() { super.onConfigure(); Account account = getModelObject(); this.setVisible(!account.getCompany()); } }; form.add(personalData); // personal address panel PersonalAddressPanel<Account> address = new PersonalAddressPanel<Account>("personalAddress", accountModel) { private static final long serialVersionUID = 3481146248010938807L; @Override protected DropDownChoice<Country> provideCountry(String componentId) { return new IndicatingAjaxDropDown<>(componentId, new PersonalAddressCountryModel(accountModel, countriesModel), new CountryRenderer(), countriesModel); } @Override protected void onConfigure() { super.onConfigure(); Account account = getModelObject(); this.setVisible(!account.getCompany()); } }; form.add(address); address.addCountry(new OnChangeAjaxBehavior() { private static final long serialVersionUID = -1016447969591778948L; @Override protected void onUpdate(AjaxRequestTarget target) { } }); // company address panel CompanyAddressPanel<Account> companyAddress; companyAddress = new CompanyAddressPanel<Account>("companyAddress", accountModel, false, false) { private static final long serialVersionUID = -6760545061622186549L; @Override protected DropDownChoice<Country> provideCountry(String componentId) { return new IndicatingAjaxDropDown<>(componentId, new CompanyDomicileModel(accountModel, countriesModel), new CountryRenderer(), countriesModel); } @Override protected void onConfigure() { super.onConfigure(); Account account = getModelObject(); this.setVisible(account.getCompany()); } }; form.add(companyAddress); companyAddress.addCountry(new OnChangeAjaxBehavior() { private static final long serialVersionUID = -5476413125490349124L; @Override protected void onUpdate(AjaxRequestTarget target) { } }); IModel<AccountPostalAddress> postalAddressModel = new PropertyModel<>(accountModel, "postalAddress"); IModel<Boolean> hasAddress = new PropertyModel<>(accountModel, "hasPostalAddress"); PostalAddressPanel<AccountPostalAddress> postalAddress; postalAddress = new PostalAddressPanel<AccountPostalAddress>("postal-address", postalAddressModel, hasAddress) { private static final long serialVersionUID = -930960688138308527L; @Override protected DropDownChoice<Country> provideCountry(String componentId) { return new IndicatingAjaxDropDown<>(componentId, new PostalAddressCountryModel(accountModel, countriesModel), new CountryRenderer(), countriesModel); } }; form.add(postalAddress); postalAddress.addStreet(new OnChangeAjaxBehavior() { private static final long serialVersionUID = 4050800366443676166L; @Override protected void onUpdate(AjaxRequestTarget target) { } }); PropertyModel<Object> billingContactModel = PropertyModel.of(accountModel, "billingContact"); form.add(new SimplifiedContactFieldSet<>("contact", billingContactModel)); // save button form.add(new IndicatingAjaxButton("save", new I18NResourceModel("button.save"), form)); }
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
private void addComponents() { // Select the first message for initial display if (getConfig().messages.isEmpty()) { // No messages configured. Create a new message with id=1. getConfig().addMessageConfig(new MessageConfig(1)); }/*from w w w. j av a2 s . c o m*/ currentMessage = getConfig().getMessageList().get(0); currentMessage.calcOffsets(getConfig().getMessageIdType().getByteSize()); currentMessageId = currentMessage.getMessageId(); // ******************************************************************************************* // *** Form for XML import final FileUploadField uploadField = new FileUploadField("upload-field", new ListModel<FileUpload>()); Form<?> uploadForm = new Form<Object>("upload-form") { @Override protected void onSubmit() { try { FileUpload upload = uploadField.getFileUpload(); if (upload != null) { handleOnUpload(upload.getInputStream()); } else { warn(new StringResourceModel("warn.noFileToUpload", this, null).getString()); } } catch (Exception e) { this.error(new StringResourceModel("import.error", this, null).getString() + " Exception: " + e.toString()); } } }; uploadForm.add(uploadField); SubmitLink importLink = new SubmitLink("import-link"); uploadForm.add(importLink); add(uploadForm); // ******************************************************************************************* // *** The message configuration currentMessageModel = new PropertyModel<MessageConfig>(this, "currentMessage"); editForm = new Form<MessageConfig>("edit-form", new CompoundPropertyModel<MessageConfig>(currentMessageModel)) { @Override protected void onError() { // Validation error - reset the message dropdown to the original value // Clear input causes the component to reload the model currentMessageIdDropdown.clearInput(); super.onError(); } }; editForm.add(new MessageFormValidator()); WebMarkupContainer tableContainer = new WebMarkupContainer("table-container"); messageIdTypeDropDown = getMessageIdTypeDropdown(); tableContainer.add(messageIdTypeDropDown); currentMessageIdDropdown = getCurrentMessageIdDropdown(); tableContainer.add(currentMessageIdDropdown); Button buttonNew = new Button("new"); buttonNew.add(new AjaxFormSubmitBehavior("onclick") { @Override protected void onSubmit(AjaxRequestTarget target) { handleNew(target); } @Override protected void onError(AjaxRequestTarget target) { handleError(target); } }); tableContainer.add(buttonNew); Button buttonCopy = new Button("copy"); buttonCopy.add(new AjaxFormSubmitBehavior("onclick") { @Override protected void onSubmit(AjaxRequestTarget target) { handleCopy(target); } @Override protected void onError(AjaxRequestTarget target) { handleError(target); } }); tableContainer.add(buttonCopy); Button deleteButton = new Button("delete"); deleteButton.add(new AjaxEventBehavior("onclick") { @Override protected void onEvent(AjaxRequestTarget target) { handleDelete(target); } }); tableContainer.add(deleteButton); messageTypeDropdown = getMessageTypeDropdown(); tableContainer.add(messageTypeDropdown); tableContainer.add(getQueueModeDropdown()); tableContainer.add(new CheckBox("usePersistance").setOutputMarkupId(true)); WebMarkupContainer listEditorContainer = new WebMarkupContainer("list-editor"); messageIdTextField = getMessageIdTextField(); listEditorContainer.add(messageIdTextField); messageAliasTextField = getMessageAliasTextField(); listEditorContainer.add(messageAliasTextField); // Create the list editor editor = new ListEditor<TagConfig>("tags", new PropertyModel<List<TagConfig>>(currentMessageModel, "tags")) { @Override protected void onPopulateItem(EditorListItem<TagConfig> item) { item.setModel(new CompoundPropertyModel<TagConfig>(item.getModelObject())); BinaryDataType dataType = item.getModelObject().getDataType(); boolean enable = dataType.isSpecial() ? false : true; // Offset is displayed only for information item.add(new Label("offset").setOutputMarkupId(true)); if (enable) { item.add(getIdTextField()); } else { // The static TextField has no validation. Validation would fail for special tags. item.add(getSpecialIdTextField().setEnabled(false)); } item.add(getAliasTextField().setVisible(enable)); item.add(getSizeTextField().setEnabled(dataType.isArrayAllowed())); item.add(getTagLengthTypeDropDown().setEnabled(dataType.supportsVariableLength())); item.add(getDataTypeDropdown()); // Create the edit links to be used in the list editor item.add(getInsertLink()); item.add(getDeleteLink()); item.add(getMoveUpLink().setVisible(item.getIndex() > 0)); item.add(getMoveDownLink().setVisible(item.getIndex() < getList().size() - 1)); } }; listEditorContainer.add(editor); Label noItemsLabel = new Label("no-items-label", new StringResourceModel("noitems", this, null)) { @Override public boolean isVisible() { return editor.getList().size() == 0; } }; listEditorContainer.add(noItemsLabel); listEditorContainer.add(new EditorSubmitLink("add-row-link") { @Override public void onSubmit() { editor.addItem(new TagConfig()); // Adjust the visibility of the edit links updateListEditor(editor); } }); listEditorContainer.setOutputMarkupId(true); tableContainer.add(listEditorContainer); editForm.add(tableContainer); // XML export SubmitLink exportLink = new SubmitLink("export-link", editForm) { @Override public void onSubmit() { ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(getResourceStream(), getFileName()); handler.setContentDisposition(ContentDisposition.ATTACHMENT); handler.setCacheDuration(Duration.NONE); getRequestCycle().scheduleRequestHandlerAfterCurrent(handler); } private String getFileName() { return String.format("MsgConfig_%s.xml", currentMessageModel.getObject().getMessageId()); } private IResourceStream getResourceStream() { String config = currentMessageModel.getObject().toXMLString(); return new StringResourceStream(config, "text/xml"); } }; editForm.add(exportLink); uploadForm.add(editForm); }
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
private DropDownChoice<Integer> getCurrentMessageIdDropdown() { IChoiceRenderer<Integer> messageConfigRender = new IChoiceRenderer<Integer>() { @Override/* w w w . ja va 2s. c o m*/ public Object getDisplayValue(Integer object) { return String.format("%d - %s", object, getConfig().getMessageConfig(object).getMessageAlias()); } @Override public String getIdValue(Integer object, int index) { return object.toString(); } }; IModel<List<Integer>> messageListModel = new LoadableDetachableModel<List<Integer>>() { @Override protected List<Integer> load() { List<MessageConfig> messages = getConfig().getMessageList(); List<Integer> list = new ArrayList<Integer>(messages.size()); for (MessageConfig messageConfig : messages) { list.add(messageConfig.getMessageId()); } return list; } }; DropDownChoice<Integer> dropDown = new DropDownChoice<Integer>("currentMessage", new PropertyModel<Integer>(this, "currentMessageId"), messageListModel, messageConfigRender); dropDown.add(new AjaxFormSubmitBehavior("onchange") { @Override protected void onSubmit(final AjaxRequestTarget target) { // Reset feedback messages target.addChildren(getPage(), FeedbackPanel.class); // Change the current message currentMessage = getConfig().getMessageConfig(currentMessageId); currentMessage.calcOffsets(getConfig().getMessageIdType().getByteSize()); // Refresh the form updateForm(target); } @Override protected void onError(final AjaxRequestTarget target) { // Add the drop down to revert the changed selection target.add(getComponent()); handleError(target); }; }); dropDown.add(new AjaxIndicatorAppender()); dropDown.setOutputMarkupId(true); return dropDown; }
From source file:com.evolveum.midpoint.web.page.admin.configuration.component.NotificationConfigPanel.java
License:Apache License
@Override protected void initLayout() { TextField<String> defaultFromField = WebComponentUtil.createAjaxTextField(ID_DEFAULT_FROM, new PropertyModel<String>(getModel(), "defaultFrom")); CheckBox debugCheck = WebComponentUtil.createAjaxCheckBox(ID_DEBUG, new PropertyModel<Boolean>(getModel(), "debug")); DropDownChoice mailServerConfigChooser = new DropDownChoice<>(ID_MAIL_SERVER, new PropertyModel<MailServerConfigurationTypeDto>(getModel(), NotificationConfigurationDto.F_SELECTED_SERVER), new AbstractReadOnlyModel<List<MailServerConfigurationTypeDto>>() { @Override// www .jav a 2 s. c o m public List<MailServerConfigurationTypeDto> getObject() { return getModel().getObject().getServers(); } }, new ChoiceableChoiceRenderer<MailServerConfigurationTypeDto>()); mailServerConfigChooser.setNullValid(true); mailServerConfigChooser.add(new AjaxFormSubmitBehavior("click") { @Override protected void onEvent(AjaxRequestTarget target) { getForm().onFormSubmitted(); } }); mailServerConfigChooser.add(new OnChangeAjaxBehavior() { @Override protected void onUpdate(AjaxRequestTarget target) { preparePasswordFieldPlaceholder(); target.add(NotificationConfigPanel.this); } }); add(mailServerConfigChooser); Label serverConfigTooltip = new Label(ID_MAIL_SERVER_TOOLTIP); serverConfigTooltip.add(new InfoTooltipBehavior()); add(serverConfigTooltip); WebMarkupContainer serverConfigContainer = new WebMarkupContainer(ID_MAIL_SERVER_CONFIG_CONTAINER); serverConfigContainer.setOutputMarkupId(true); serverConfigContainer.setOutputMarkupPlaceholderTag(true); serverConfigContainer.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { if (getModelObject() != null) { return getModelObject().getSelectedServer() != null; } return false; } }); add(serverConfigContainer); TextField<String> hostField = WebComponentUtil.createAjaxTextField(ID_HOST, new PropertyModel<String>(getModel(), "selectedServer.host")); TextField<Integer> portField = WebComponentUtil.createAjaxTextField(ID_PORT, new PropertyModel<Integer>(getModel(), "selectedServer.port")); TextField<String> userNameField = WebComponentUtil.createAjaxTextField(ID_USERNAME, new PropertyModel<String>(getModel(), "selectedServer.username")); PasswordTextField passwordField = new PasswordTextField(ID_PASSWORD, new PropertyModel<String>(getModel(), "selectedServer.password")); passwordField.setRequired(false); passwordField.add(new EmptyOnChangeAjaxFormUpdatingBehavior()); TextField<String> redirectToFileField = WebComponentUtil.createAjaxTextField(ID_REDIRECT_TO_FILE, new PropertyModel<String>(getModel(), "redirectToFile")); DropDownFormGroup transportSecurity = new DropDownFormGroup<>(ID_TRANSPORT_SECURITY, new PropertyModel<MailTransportSecurityType>(getModel(), "selectedServer.mailTransportSecurityType"), WebComponentUtil.createReadonlyModelFromEnum(MailTransportSecurityType.class), new EnumChoiceRenderer<MailTransportSecurityType>(this), createStringResource("SystemConfigPanel.mail.transportSecurity"), ID_LABEL_SIZE, ID_INPUT_SIZE, false); // transportSecurity.add(new EmptyOnChangeAjaxFormUpdatingBehavior()); serverConfigContainer.add(hostField); serverConfigContainer.add(portField); serverConfigContainer.add(userNameField); serverConfigContainer.add(passwordField); serverConfigContainer.add(transportSecurity); add(defaultFromField); add(debugCheck); add(redirectToFileField); AjaxSubmitLink buttonAddNewMailServerConfig = new AjaxSubmitLink(ID_BUTTON_ADD_NEW_MAIL_SERVER_CONFIG) { @Override protected void onSubmit(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) { MailServerConfigurationTypeDto newConfig = new MailServerConfigurationTypeDto(); newConfig.setHost(getString("SystemConfigPanel.mail.config.placeholder")); if (getModelObject() != null) { getModelObject().getServers().add(newConfig); getModelObject().setSelectedServer(newConfig); } preparePasswordFieldPlaceholder(); target.add(NotificationConfigPanel.this, getPageBase().getFeedbackPanel()); } @Override protected void onError(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) { target.add(getPageBase().getFeedbackPanel()); } }; add(buttonAddNewMailServerConfig); AjaxSubmitLink removeMailServerConfig = new AjaxSubmitLink(ID_BUTTON_REMOVE_MAIL_SERVER_CONFIG) { @Override protected void onSubmit(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) { if (getModelObject() != null) { NotificationConfigurationDto notificationConfig = getModelObject(); MailServerConfigurationTypeDto selected = notificationConfig.getSelectedServer(); if (notificationConfig.getServers().contains(selected)) { notificationConfig.getServers().remove(selected); notificationConfig.setSelectedServer(null); } else { warn(getString("SystemConfigPanel.mail.server.remove.warn")); } target.add(NotificationConfigPanel.this, getPageBase().getFeedbackPanel()); } } @Override protected void onError(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) { target.add(getPageBase().getFeedbackPanel()); } }; removeMailServerConfig.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() { @Override public String getObject() { if (getModelObject() != null && getModelObject().getSelectedServer() != null) { return null; } else { return " disabled"; } } })); add(removeMailServerConfig); }
From source file:com.userweave.pages.configuration.report.GroupFilterPanel.java
License:Open Source License
/** * Default constructor.//from w w w .j a v a 2 s.c o m * * @param id * Component markup id. * @param group * Preselected group. May be null. */ public GroupFilterPanel(String id, Group group) { super(id); this.selectedGroup = group; Form<Void> form = new Form<Void>("form"); add(form); // form.add( // new AjaxButton("add", form) // { // private static final long serialVersionUID = 1L; // // @Override // protected void onSubmit(AjaxRequestTarget target, Form<?> form) // { // onAdd(target); // } // // @Override // protected void onError(AjaxRequestTarget target, Form<?> form) // { // } // // @Override // public boolean isVisible() // { // return addButtonIsVisible(GroupFilterPanel.this); // } // // } // ); form.add(new AjaxButton("remove", form) { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { GroupFilterPanel.this.onRemove(target); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { } // @Override // public boolean isVisible() // { // return addButtonIsVisible(GroupFilterPanel.this); // } }); form.add(choices = new DropDownChoice<Group>("groups", new PropertyModel<Group>(this, "selectedGroup"), newGroupsModel(), new ChoiceRenderer<Group>("name"))); choices.setOutputMarkupId(true); choices.setRequired(true); choices.add(new AjaxFormSubmitBehavior("onchange") { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target) { } @Override protected void onSubmit(AjaxRequestTarget target) { if (getSelectedGroup() != null && addButtonIsVisible(GroupFilterPanel.this)) { onAdd(target); } onSelect(target); } }); }
From source file:com.visural.stereotyped.ui.prototype.PrototypeEditor.java
License:Mozilla Public License
public PrototypeEditor(PageParameters params) { super(params); add(CSSPackageResource.getHeaderContribution(new WindowsTheme())); add(new HeaderContributor(new IHeaderContributor() { public void renderHead(IHeaderResponse response) { response.renderJavascript(getHeaderJS(), "header_js"); }// w w w . j a v a 2s . c o m })); stereotypeUUIDList = new ArrayList<UUID>(stereotypeService.listAll()); Collections.sort(stereotypeUUIDList, new Comparator<UUID>() { public int compare(UUID o1, UUID o2) { return stereotypeService.read(o1).getName().compareTo(stereotypeService.read(o2).getName()); } }); for (UUID uuid : stereotypeUUIDList) { stereotypeUUUIDDesc.put(uuid, stereotypeService.read(uuid).getName()); } editor.setOutputMarkupId(true); add(editor); final WebMarkupContainer wrap = new WebMarkupContainer("wrap"); editor.add(wrap.setOutputMarkupId(true)); expert = userService.getUser(userService.getCurrentUser()).getExpertMode(); stereotypeUUIDStr = params.getString(StdParam.LOAD_ID); id = UUID.fromString(stereotypeUUIDStr); if (stereotypeUUIDStr == null) { throw new IllegalArgumentException("Must provide a prototype name to load."); } userService.registerListInteraction(userService.getCurrentUser(), UserListType.RECENTLY_VIEWED, id); previewId = previewProvider.get().getNewPreviewerSession(stereotypeService.readUncached(id), new BasicHTMLResourceRenderer(stereotypeService.listAllLibraries())); components = new ArrayList<Class<? extends Component>>(); List<ComponentLibrary> libs = stereotypeService.listAllLibraries(); Stereotype s = previewProvider.get().getStereotype(previewId); for (ComponentLibrary lib : libs) { for (Class<? extends Component> com : lib.getComponents()) { if (s.allowComponent(lib.getJarName(), com)) { components.add(com); } } } EditorForm form; wrap.add(form = new EditorForm("mainForm")); prev = new PreviewerPanel("preview", previewId); wrap.add(prev); Form previewStatesForm = new Form("previewStates"); wrap.add(previewStatesForm); previewStatesForm.add(new DropDownChoice("currentPreviewState", new IModel<String>() { public String getObject() { return getDynStereotype().getCurrentPreviewStateName(); } public void setObject(String object) { if (!Function.nvl(object, "").equals(Function.nvl(getObject(), ""))) { if (object == null) { getDynStereotype().getDefaultState().select(); } else { getDynStereotype().getPreviewStateByName(object).select(); } } } public void detach() { } }, new AbstractReadOnlyModel() { @Override public Object getObject() { ArrayList al = new ArrayList(); List<PreviewState> states = getDynStereotype().getPreviewStates(); for (PreviewState ps : states) { al.add(ps.getName()); } return al; } }).setNullValid(true).add(new AjaxFormSubmitBehavior("onchange") { @Override protected void onSubmit(AjaxRequestTarget target) { target.addComponent(editor); } @Override protected void onError(AjaxRequestTarget target) { target.addComponent(editor); } })); final Dialog addPreviewStateDialog = new Dialog("addPreviewStateDialog"); addPreviewStateDialog.setOutputMarkupId(true); editor.add(addPreviewStateDialog); final AddPreviewStateForm addPreviewStateForm = new AddPreviewStateForm("addPreviewState", addPreviewStateDialog); addPreviewStateDialog.add(addPreviewStateForm); addPreviewStateDialog.add(new Label("title", new AbstractReadOnlyModel() { @Override public Object getObject() { return addPreviewStateForm.toCopy == null ? "Add Preview State" : "Copy Preview State '" + addPreviewStateForm.toCopy.getName() + "'"; } })); wrap.add(new AjaxLink("addPreviewState") { @Override public void onClick(AjaxRequestTarget target) { addPreviewStateForm.open(target); } }); wrap.add(new AjaxLink("copyPreviewState") { @Override public boolean isVisible() { return getDynStereotype().getCurrentPreviewState() != null; } @Override public void onClick(AjaxRequestTarget target) { addPreviewStateForm.open(target, getDynStereotype().getCurrentPreviewState()); } }); wrap.add(new ConfirmerAjaxLink("delPreviewState") { @Override public boolean isVisible() { return getDynStereotype().getCurrentPreviewState() != null; } @Override public void onClick(AjaxRequestTarget target) { getDynStereotype().deletePreviewState(getDynStereotype().getCurrentPreviewState()); target.addComponent(editor); } }); wrap.add(new AjaxLink("refreshAll") { @Override public void onClick(AjaxRequestTarget target) { target.addComponent(wrap); } }); wrap.add(new IndicateModalAjaxSubmitLink("save", form) { @Override public IPrivilege getRenderPrivilege() { return Privilege.currentUserHasWriteAccess(id); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.addComponent(editor); Stereotype s = previewProvider.get().getStereotype(previewId); stereotypeService.write(s); getSession().info("Saved '" + s.getName() + "' successfully."); } }); wrap.add(new IndicateModalSubmitLink("saveAndClose", form) { @Override public IPrivilege getRenderPrivilege() { return Privilege.currentUserHasWriteAccess(id); } @Override public void onSubmit() { Stereotype s = previewProvider.get().getStereotype(previewId); stereotypeService.write(s); getSession().info("Saved '" + s.getName() + "' successfully."); setResponsePage(LandingPage.class); } }); wrap.add(new ConfirmerAjaxLink("close") { @Override public void onClick(AjaxRequestTarget target) { setResponsePage(LandingPage.class); } }); wrap.add(new IndicateModalAjaxLink("fix") { @Override public void onClick(AjaxRequestTarget target) { target.addComponent(editor); Stereotype s = getDynStereotype(); List<Slot> slots = new ArrayList<Slot>(); recurse(s, slots); int fixed = 0; for (int n = 0; n < slots.size() - 1; n++) { Slot cur = slots.get(n); if (listHasUUID(slots.subList(n + 1, slots.size()), cur.getUuid())) { cur.mutateUUID(true); fixed++; } } getSession().info("Fixed " + fixed + " broken slots."); } private boolean listHasUUID(List<Slot> l, UUID uuid) { for (Slot s : l) { if (s.getUuid().equals(uuid)) { return true; } } return false; } private void recurse(Component c, List<Slot> result) { if (c == null || c.getSlots() == null || c.getSlots().isEmpty()) { return; } for (Slot s : c.getSlots()) { recurse(s, result); } } private void recurse(Slot s, List<Slot> result) { if (s == null) { return; } result.add(s); if (s.getContent() != null && !s.getContent().isEmpty()) { for (Component c : s.getContent()) { recurse(c, result); } } } }); wrap.add(new WebMarkupContainer("previewWindow") .add(new SimpleAttributeModifier("href", prev.getPreviewURL()))); }
From source file:dk.netdesign.common.osgi.config.wicket.ConfigurationPage.java
License:Apache License
public final void setUpPage() { String name = controllerModel.getObject().getName(); String id = controllerModel.getObject().getID(); Label configName = new Label("configName", Model.of(name)); add(configName);/*from w w w . j a v a2 s . c om*/ Label configID = new Label("configID", Model.of(id)); add(configID); final ListView<AttributeValue> attributePanels = new ListView<AttributeValue>("attribute-panels", attributeModel) { @Override protected void populateItem(ListItem<AttributeValue> item) { AttributeValue attributeAndValue = item.getModelObject(); item.add(new ConfigurationItemPanel(attributeAndValue.getAttribute(), attributeAndValue.getValue(), attributeAndValue.errorMessageModel, "attribute-panel")); } }; Form configForm = new Form("configForm"); configForm.add(new AjaxFormSubmitBehavior("submit") { @Override protected void onSubmit(AjaxRequestTarget target) { super.onSubmit(target); LOGGER.info("Attempting to persist new configuration"); for (AttributeValue value : attributeModel.getObject()) { value.setErrorMessage(null); } Map<String, ParsingException> exceptions = new HashMap<>(); for (AttributeValue value : attributeModel.getObject()) { try { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Parsing " + value.getValue().getObject()); } Object castObject = value.getValue().getCastObject(); LOGGER.debug("Parsed object: " + castObject); controllerModel.getObject().setItem(value.getAttribute(), castObject); } catch (ParsingException ex) { ParsingException previousException = exceptions.put(ex.getKey(), ex); if (previousException != null) { LOGGER.info("Exception overwritten for key " + ex.getKey() + ": " + previousException.getMessage()); } } } if (!exceptions.isEmpty()) { resetCommit(controllerModel.getObject()); for (AttributeValue value : attributeModel.getObject()) { ParsingException ex = exceptions.get(value.attribute.getID()); if (ex != null) { if (ex.getCause() != null && ex.getCause() instanceof TypeFilterException) { value.setErrorMessage(ex.getCause().getMessage()); } else { value.setErrorMessage(ex.getMessage()); } } } } else { try { controllerModel.getObject().commitProperties(); } catch (MultiParsingException ex) { for (ParsingException pex : ex.getExceptions()) { for (AttributeValue value : attributeModel.getObject()) { if (value.attribute.getID().equals(pex.getKey())) { if (pex.getCause() != null && pex.getCause() instanceof TypeFilterException) { value.setErrorMessage(pex.getCause().getMessage()); } else { value.setErrorMessage(pex.getMessage()); } break; } } } } catch (InvocationException ex) { LOGGER.warn("Attempted to commit configuration, but controller was not in set-state", ex); } } LOGGER.debug("Committing configuration: " + controllerModel.getObject()); target.add(ConfigurationPage.this); } }); configForm.add(attributePanels); add(configForm); }