List of usage examples for org.apache.wicket.ajax.form OnChangeAjaxBehavior OnChangeAjaxBehavior
public OnChangeAjaxBehavior()
From source file:com.evolveum.midpoint.web.page.admin.users.component.OrgMemberPanel.java
License:Apache License
@Override protected void initSearch(Form form) { /// TODO: move to utils class?? List<ObjectTypes> objectTypes = Arrays.asList(ObjectTypes.values()); Collections.sort(objectTypes, new Comparator<ObjectTypes>() { @Override/* w w w .j a va2 s.c o m*/ public int compare(ObjectTypes o1, ObjectTypes o2) { Validate.notNull(o1); Validate.notNull(o2); String type1 = o1.getValue(); String type2 = o2.getValue(); return String.CASE_INSENSITIVE_ORDER.compare(type1, type2); } }); //////////// DropDownChoice<ObjectTypes> objectType = new DropDownChoice<ObjectTypes>(ID_SEARCH_BY_TYPE, Model.of(OBJECT_TYPES_DEFAULT), objectTypes, new EnumChoiceRenderer<ObjectTypes>()); objectType.add(new OnChangeAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { refreshTable(target); } }); objectType.setOutputMarkupId(true); form.add(objectType); DropDownChoice<String> seachScrope = new DropDownChoice<String>(ID_SEARCH_SCOPE, Model.of(SEARCH_SCOPE_ONE), SEARCH_SCOPE_VALUES, new StringResourceChoiceRenderer("TreeTablePanel.search.scope")); seachScrope.add(new OnChangeAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { refreshTable(target); } }); seachScrope.setOutputMarkupId(true); form.add(seachScrope); }
From source file:com.francetelecom.clara.cloud.presentation.designer.services.cfjavaprocessing.LogicalCfJavaProcessingServicePanel.java
License:Apache License
private void initComponents() { getServiceForm().add(new CacheActivatedImage("cfjavaprocessing-icon", new ResourceModel("cfjavaprocessing.icon").getObject())); // Online help link String completeHelpUrl = ""; try {/*from w ww .j a va2s. com*/ completeHelpUrl = new StringResourceModel("portal.designer.logical.service.online_manual.baseUrl", null) .getString() + new StringResourceModel( "portal.designer.logical.service.online_manual." + getLogicalModelType(), null) .getString(); } catch (Exception e) { //do nothing } ExternalLink onlineHelpLink = new ExternalLink("onlineHelpLink", completeHelpUrl); getServiceForm().add(onlineHelpLink); if (completeHelpUrl.isEmpty()) { onlineHelpLink.setVisible(false); } // FUNCTIONNAL PARAMETERS RequiredTextField<String> label = new RequiredTextField<String>("label"); label.setLabel(new StringResourceModel("portal.designer.service.cfjava.label", null)); label.add(new PropertyValidator<>()); getServiceForm().add(label); RequiredTextField<String> groupId = new RequiredTextField<String>("softwareReference.groupId"); groupId.setLabel(new StringResourceModel("portal.designer.service.cfjava.softwareReference.groupId", null)); groupId.add(new PropertyValidator<>()); getServiceForm().add(groupId); RequiredTextField<String> artifactId = new RequiredTextField<String>("softwareReference.artifactId"); artifactId.setLabel( new StringResourceModel("portal.designer.service.cfjava.softwareReference.artifactId", null)); artifactId.add(new PropertyValidator<>()); getServiceForm().add(artifactId); RequiredTextField<String> version = new RequiredTextField<String>("softwareReference.version"); version.setLabel(new StringResourceModel("portal.designer.service.cfjava.softwareReference.version", null)); version.add(new PropertyValidator<>()); getServiceForm().add(version); RequiredTextField<String> extension = new RequiredTextField<String>("softwareReference.extension"); if (getServiceForm().getModelObject().getSoftwareReference() == null) { getServiceForm().getModelObject().setSoftwareReference(new MavenReference("", "", "", "war")); } extension.setLabel( new StringResourceModel("portal.designer.service.cfjava.softwareReference.extension", null)); extension.add(new PropertyValidator<>()); getServiceForm().add(extension); /*List<String> extensionList = new ArrayList<String>(); extensionList.add("jar"); extensionList.add("war"); extensionList.add("ear"); DropDownChoice<String> extension = new DropDownChoice<String>("softwareReference.extension", extensionList); extension.setLabel(new StringResourceModel("portal.designer.service.cfjava.softwareReference.extension",null)); extension.add(new PropertyValidator<>()); getServiceForm().add(extension);*/ TextField<String> classifier = new TextField<String>("softwareReference.classifier", String.class); classifier.setLabel( new StringResourceModel("portal.designer.service.cfjava.softwareReference.classifier", null)); classifier.add(new PropertyValidator<>()); getServiceForm().add(classifier); CheckBox optionalSoftwareReference = new CheckBox("optionalSoftwareReference"); optionalSoftwareReference.setLabel( new StringResourceModel("portal.designer.service.cfjava.optionalSoftwareReference", null)); getServiceForm().add(optionalSoftwareReference); TextField<Integer> minMemoryMbHint = new TextField<Integer>("minMemoryMbHint"); minMemoryMbHint.setLabel(new StringResourceModel("portal.designer.service.cfjava.minMemoryMbHint", null)); minMemoryMbHint.add(new AttributeModifier("class", "small")); minMemoryMbHint.add(new PropertyValidator<>()); getServiceForm().add(minMemoryMbHint); final TextField<String> iconUrl = new TextField<String>("iconUrl"); iconUrl.setLabel(new StringResourceModel("portal.designer.service.cfjava.iconUrl", null)); //iconUrl.add(new AttributeModifier("title", new StringResourceModel("portal.designer.service.cfjava.iconUrl.help",null))); //Add Wicket validation for URL iconUrl.add(new UrlValidator()); iconUrl.add(new PropertyValidator<>()); iconUrl.add(new OnChangeAjaxBehavior() { /** * */ private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { // Important, DO NOT DELETE // By Calling OnChangeAjaxBehavior, we update iconUrl field model to can push button preview with updated model } @Override protected void onError(AjaxRequestTarget target, RuntimeException e) { iconUrl.updateModel(); // The feedback is handle when click on preview button so we need to updateModel when there is an error } }); getServiceForm().add(iconUrl); getServiceForm().add(new CacheActivatedImage("imageHelp.iconUrl", getString("image.help"))); WebMarkupContainer imageContainer = new WebMarkupContainer("imageContainer"); final WebMarkupContainer icon = new WebMarkupContainer("icon"); icon.setOutputMarkupId(true); icon.setOutputMarkupPlaceholderTag(true); if (iconUrl.getModelObject() == null || iconUrl.getModelObject().equals("")) { setDefaultIconAndUpdateFeedBack(icon, null, ""); } else { setCustomIconAndUpdateFeedBack(icon, iconUrl, null); } imageContainer.add(icon); final Label feedback = new Label("feedbackError", new Model<String>("")); feedback.setOutputMarkupId(true); imageContainer.add(feedback); AjaxLink preview = new AjaxLink("preview", new Model()) { @Override public void onClick(AjaxRequestTarget target) { try { //If null or empty when click on preview button, clean feedBack and display default image if (iconUrl.getModelObject() == null || iconUrl.getModelObject().equals("")) { setDefaultIconAndCleanFeedBack(icon, feedback); } // Else try to display custom image else { //Construct URL to test integrity of what user typing URL url = new URL(iconUrl.getModelObject().toString()); if (iconUrl.getModelObject() != null) { setCustomIconAndUpdateFeedBack(icon, iconUrl, feedback); } } } catch (MalformedURLException e) { setDefaultIconAndUpdateFeedBack(icon, feedback, e.getMessage()); e.printStackTrace(); } target.add(icon); target.add(feedback); } }; imageContainer.add(preview); getServiceForm().add(imageContainer); }
From source file:com.francetelecom.clara.cloud.presentation.designer.services.jeeprocessing.LogicalJeeProcessingServicePanel.java
License:Apache License
private void initComponents() { getServiceForm().add(new CacheActivatedImage("logicalJeeProcessingPanelIcon", new ResourceModel("jeeProcessing-icon").getObject())); // Online help link String completeHelpUrl = ""; try {// w w w. ja va2s . c om completeHelpUrl = new StringResourceModel("portal.designer.logical.service.online_manual.baseUrl", null) .getString() + new StringResourceModel( "portal.designer.logical.service.online_manual." + getLogicalModelType(), null) .getString(); } catch (Exception e) { //do nothing } ExternalLink onlineHelpLink = new ExternalLink("onlineHelpLink", completeHelpUrl); getServiceForm().add(onlineHelpLink); if (completeHelpUrl.isEmpty()) { onlineHelpLink.setVisible(false); } // FUNCTIONNAL PARAMETERS RequiredTextField<String> label = new RequiredTextField<String>("label"); label.setLabel(new StringResourceModel("portal.designer.service.jee.label", null)); label.add(new PropertyValidator<>()); getServiceForm().add(label); RequiredTextField<String> groupId = new RequiredTextField<String>("softwareReference.groupId"); groupId.setLabel(new StringResourceModel("portal.designer.service.jee.softwareReference.groupId", null)); groupId.add(new PropertyValidator<>()); getServiceForm().add(groupId); RequiredTextField<String> artifactId = new RequiredTextField<String>("softwareReference.artifactId"); artifactId.setLabel( new StringResourceModel("portal.designer.service.jee.softwareReference.artifactId", null)); artifactId.add(new PropertyValidator<>()); getServiceForm().add(artifactId); RequiredTextField version = new RequiredTextField("softwareReference.version"); version.setLabel(new StringResourceModel("portal.designer.service.jee.softwareReference.version", null)); version.add(new PropertyValidator<>()); getServiceForm().add(version); TextField classifier = new TextField("softwareReference.classifier", String.class); classifier.setLabel( new StringResourceModel("portal.designer.service.jee.softwareReference.classifier", null)); classifier.add(new PropertyValidator<>()); getServiceForm().add(classifier); CheckBox optionalSoftwareReference = new CheckBox("optionalSoftwareReference"); optionalSoftwareReference .setLabel(new StringResourceModel("portal.designer.service.jee.optionalSoftwareReference", null)); getServiceForm().add(optionalSoftwareReference); TextField minMemoryMbHint = new TextField("minMemoryMbHint"); minMemoryMbHint.setLabel(new StringResourceModel("portal.designer.service.jee.minMemoryMbHint", null)); minMemoryMbHint.add(new AttributeModifier("class", "small")); minMemoryMbHint.add(new PropertyValidator<>()); getServiceForm().add(minMemoryMbHint); final TextField<String> iconUrl = new TextField<String>("iconUrl"); iconUrl.setLabel(new StringResourceModel("portal.designer.service.jee.iconUrl", null)); //iconUrl.add(new AttributeModifier("title", new StringResourceModel("portal.designer.service.jee.iconUrl.help",null))); //Add Wicket validation for URL iconUrl.add(new UrlValidator()); iconUrl.add(new PropertyValidator<>()); iconUrl.add(new OnChangeAjaxBehavior() { @Override protected void onUpdate(AjaxRequestTarget target) { // Important, DO NOT DELETE // By Calling OnChangeAjaxBehavior, we update iconUrl field model to can push button preview with updated model } @Override protected void onError(AjaxRequestTarget target, RuntimeException e) { iconUrl.updateModel(); // The feedback is handle when click on preview button so we need to updateModel when there is an error } }); getServiceForm().add(iconUrl); getServiceForm() .add(new CacheActivatedImage("imageHelp.iconUrl", new ResourceModel("image.help").getObject())); WebMarkupContainer imageContainer = new WebMarkupContainer("imageContainer"); final WebMarkupContainer icon = new WebMarkupContainer("icon"); icon.setOutputMarkupId(true); icon.setOutputMarkupPlaceholderTag(true); if (iconUrl.getModelObject() == null || iconUrl.getModelObject().equals("")) { setDefaultIconAndUpdateFeedBack(icon, null, ""); } else { setCustomIconAndUpdateFeedBack(icon, iconUrl, null); } imageContainer.add(icon); final Label feedback = new Label("feedbackError", new Model<String>("")); feedback.setOutputMarkupId(true); imageContainer.add(feedback); AjaxLink preview = new AjaxLink("preview", new Model()) { @Override public void onClick(AjaxRequestTarget target) { try { //If null or empty when click on preview button, clean feedBack and display default image if (iconUrl.getModelObject() == null || iconUrl.getModelObject().equals("")) { setDefaultIconAndCleanFeedBack(icon, feedback); } // Else try to display custom image else { //Construct URL to test integrity of what user typing URL url = new URL(iconUrl.getModelObject().toString()); if (iconUrl.getModelObject() != null) { setCustomIconAndUpdateFeedBack(icon, iconUrl, feedback); } } } catch (MalformedURLException e) { setDefaultIconAndUpdateFeedBack(icon, feedback, e.getMessage()); logger.info("Exception while getting new icon", e); } target.add(icon); target.add(feedback); } }; imageContainer.add(preview); getServiceForm().add(imageContainer); }
From source file:com.francetelecom.clara.cloud.presentation.designer.services.nodeprocessing.LogicalNodeProcessingServicePanel.java
License:Apache License
private void initComponents() { getServiceForm().add(new CacheActivatedImage("nodeprocessingIcon", new ResourceModel("nodeprocessing-icon").getObject())); // Online help link String completeHelpUrl = ""; try {/* www . j a v a 2s . c o m*/ completeHelpUrl = new StringResourceModel("portal.designer.logical.service.online_manual.baseUrl", null) .getString() + new StringResourceModel( "portal.designer.logical.service.online_manual." + getLogicalModelType(), null) .getString(); } catch (Exception e) { //do nothing } ExternalLink onlineHelpLink = new ExternalLink("onlineHelpLink", completeHelpUrl); getServiceForm().add(onlineHelpLink); if (completeHelpUrl.isEmpty()) { onlineHelpLink.setVisible(false); } // FUNCTIONNAL PARAMETERS /*RequiredTextField<String> label = new RequiredTextField<String>("label"); label.setLabel(new StringResourceModel("portal.designer.service.cfjava.label",null)); label.add(new PropertyValidator<>()); getServiceForm().add(label); RequiredTextField<String> groupId = new RequiredTextField<String>("softwareReference.groupId"); groupId.setLabel(new StringResourceModel("portal.designer.service.cfjava.softwareReference.groupId",null)); groupId.add(new PropertyValidator<>()); getServiceForm().add(groupId); RequiredTextField<String> artifactId = new RequiredTextField<String>("softwareReference.artifactId"); artifactId.setLabel(new StringResourceModel("portal.designer.service.cfjava.softwareReference.artifactId",null)); artifactId.add(new PropertyValidator<>()); getServiceForm().add(artifactId); RequiredTextField<?> version = new RequiredTextField("softwareReference.version"); version.setLabel(new StringResourceModel("portal.designer.service.cfjava.softwareReference.version",null)); version.add(new PropertyValidator<>()); getServiceForm().add(version); TextField classifier = new TextField("softwareReference.classifier", String.class); classifier.setLabel(new StringResourceModel("portal.designer.service.cfjava.softwareReference.classifier",null)); classifier.add(new PropertyValidator<>()); getServiceForm().add(classifier); CheckBox optionalSoftwareReference=new CheckBox("optionalSoftwareReference"); optionalSoftwareReference.setLabel(new StringResourceModel("portal.designer.service.cfjava.optionalSoftwareReference",null)); getServiceForm().add(optionalSoftwareReference); TextField minMemoryMbHint = new TextField("minMemoryMbHint"); minMemoryMbHint.setLabel(new StringResourceModel("portal.designer.service.cfjava.minMemoryMbHint",null)); minMemoryMbHint.add(new AttributeModifier("class","small")); minMemoryMbHint.add(new PropertyValidator<>()); getServiceForm().add(minMemoryMbHint); */ //****** Change Icon ******// final TextField<String> iconUrl = new TextField<String>("iconUrl"); iconUrl.setLabel(new StringResourceModel("portal.designer.service.cfjava.iconUrl", null)); //iconUrl.add(new AttributeModifier("title", new StringResourceModel("portal.designer.service.cfjava.iconUrl.help",null))); //Add Wicket validation for URL iconUrl.add(new UrlValidator()); iconUrl.add(new PropertyValidator<>()); iconUrl.add(new OnChangeAjaxBehavior() { @Override protected void onUpdate(AjaxRequestTarget target) { // Important, DO NOT DELETE // By Calling OnChangeAjaxBehavior, we update iconUrl field model to can push button preview with updated model } @Override protected void onError(AjaxRequestTarget target, RuntimeException e) { iconUrl.updateModel(); // The feedback is handle when click on preview button so we need to updateModel when there is an error } }); getServiceForm().add(iconUrl); getServiceForm().add(new CacheActivatedImage("imageHelp.iconUrl", getString("image.help"))); WebMarkupContainer imageContainer = new WebMarkupContainer("imageContainer"); final WebMarkupContainer icon = new WebMarkupContainer("icon"); icon.setOutputMarkupId(true); icon.setOutputMarkupPlaceholderTag(true); if (iconUrl.getModelObject() == null || iconUrl.getModelObject().equals("")) { setDefaultIconAndUpdateFeedBack(icon, null, ""); } else { setCustomIconAndUpdateFeedBack(icon, iconUrl, null); } imageContainer.add(icon); final Label feedback = new Label("feedbackError", new Model<String>("")); feedback.setOutputMarkupId(true); imageContainer.add(feedback); AjaxLink preview = new AjaxLink("preview", new Model()) { @Override public void onClick(AjaxRequestTarget target) { try { //If null or empty when click on preview button, clean feedBack and display default image if (iconUrl.getModelObject() == null || iconUrl.getModelObject().equals("")) { setDefaultIconAndCleanFeedBack(icon, feedback); } // Else try to display custom image else { //Construct URL to test integrity of what user typing URL url = new URL(iconUrl.getModelObject().toString()); if (iconUrl.getModelObject() != null) { setCustomIconAndUpdateFeedBack(icon, iconUrl, feedback); } } } catch (MalformedURLException e) { setDefaultIconAndUpdateFeedBack(icon, feedback, e.getMessage()); e.printStackTrace(); } target.add(icon); target.add(feedback); } }; imageContainer.add(preview); getServiceForm().add(imageContainer); }
From source file:com.francetelecom.clara.cloud.presentation.environments.EnvironmentCreatePanel.java
License:Apache License
private void createEnvironmentForm() { MyFormEnvironmentDto envDto = new MyFormEnvironmentDto(); List<ApplicationRelease> releaseList = null; if (release != null) { envDto.setRelease(release);/* w w w. j a va 2s . c o m*/ releaseList = new ArrayList<ApplicationRelease>(); releaseList.add(release); } else { releaseList = manageApplicationRelease.findMyApplicationReleases(); } envForm = new Form<>("envForm", new CompoundPropertyModel<>(envDto)); // ChoiceRenderer<ApplicationRelease> choiceRenderer = new ChoiceRenderer<ApplicationRelease>("releaseVersion", "name"); CompoundChoiceRenderer<ApplicationRelease> compoundChoiceRenderer = new CompoundChoiceRenderer<ApplicationRelease>( new String[] { "application.label", "releaseVersion" }, "uid", " - "); final DropDownChoice<ApplicationRelease> envDtoDropDownChoice = new DropDownChoice<ApplicationRelease>( "release", releaseList, compoundChoiceRenderer); envDtoDropDownChoice.add(new OnChangeAjaxBehavior() { private static final long serialVersionUID = -8967171434567279367L; @Override protected void onUpdate(AjaxRequestTarget target) { try { ((DesignerHelperPage) getPage()) .getLogicalDeploymentPersisted(envDtoDropDownChoice.getModelObject().getUID()); } catch (ObjectNotFoundException e) { return; } envArchitecturePanel.updateTable(); configOverrides.clear(); target.add(container); } }); if (release != null) { envDtoDropDownChoice.setEnabled(false); } // release required envDtoDropDownChoice.add(new PropertyValidator<>()); envForm.add(envDtoDropDownChoice); envForm.add(new CacheActivatedImage("imageHelp.releaseField", getString("image.help"))); final RequiredTextField<String> label = new RequiredTextField<>("label"); label.setLabel(new StringResourceModel("portal.environment.name.label", null)); label.add(new PropertyValidator<>()); label.add(new AbstractValidator<String>() { private static final long serialVersionUID = 5714188138333004292L; @Override protected void onValidate(IValidatable<String> iValidatable) { boolean isUnique = false; try { String releaseUID; if (release != null) { releaseUID = release.getUID(); } else { releaseUID = envDtoDropDownChoice.getRawInput(); } isUnique = manageEnvironment.isEnvironmentLabelUniqueForRelease(paasUser.getSsoId().getValue(), iValidatable.getValue(), releaseUID); } catch (BusinessException e) { error(iValidatable); logger.error(e.getMessage(), e); } if (!isUnique) { error(iValidatable); } } @Override protected String resourceKey() { return "portal.environment.label.non.unique"; } @Override protected Map<String, Object> variablesMap(IValidatable<String> stringIValidatable) { Map<String, Object> map = super.variablesMap(stringIValidatable); map.put("label", stringIValidatable.getValue()); return map; } }); DropDownChoice<EnvironmentDto.EnvironmentTypeEnum> envType = new DropDownChoice<EnvironmentDto.EnvironmentTypeEnum>( "type", Arrays.asList(EnvironmentDto.EnvironmentTypeEnum.values())); envType.setLabel(new StringResourceModel("portal.environment.type.label", null)); envType.add(new PropertyValidator<>()); container = new WebMarkupContainer("propertiesContainer"); container.setOutputMarkupPlaceholderTag(true); container.setVisible(false); envArchitecturePanel = new DesignerArchitectureMatrixPanel("env-design", (DesignerHelperPage) getPage(), true, true); container.add(envArchitecturePanel); overridePropsCheckbox = new AjaxCheckBox("overridePropertiesCheckbox", new Model<Boolean>()) { private static final long serialVersionUID = 7096578812745292001L; @Override protected void onUpdate(AjaxRequestTarget target) { container.setVisible(getModelObject()); target.add(container); } }; overridePropsCheckbox .setLabel(WicketUtils.getStringResourceModel(this, "portal.environment.properties.override.label")); add(overridePropsCheckbox); createFormButtons(envForm); add(envForm); envForm.add(label); envForm.add(envType); envForm.add(container); envForm.add(overridePropsCheckbox); }
From source file:com.francetelecom.clara.cloud.presentation.releases.ReleaseForkSelectPanel.java
License:Apache License
private void initComponents() { initContainers();//from www . java 2 s. com //Select appliction choice ChoiceRenderer<Application> applicationChoice = new ChoiceRenderer<>("label", "uid"); applicationSelect = new DropDownChoice<Application>("appSelect", new Model<Application>(), getApplicationList(), applicationChoice); applicationSelect.add(new OnChangeAjaxBehavior() { @Override protected void onUpdate(AjaxRequestTarget target) { Application selectedApp = applicationSelect.getModelObject(); boolean isSelected = selectedApp != null; updateContainerVisibility(isSelected, false, target); if (isSelected) { updateReleaseSelect(selectedApp.getUID(), target); updateAppDescription(selectedApp.getUID(), target); } } }); applicationSelect.setNullValid(true); appContainer.add(applicationSelect); //Select Release version choice ChoiceRenderer<ApplicationRelease> applicationReleaseVersionChoice = new ChoiceRenderer<>("releaseVersion", "uid"); releaseSelect = new DropDownChoice<ApplicationRelease>("releaseSelect", new Model<ApplicationRelease>(), (List) null, applicationReleaseVersionChoice); releaseSelect.add(new OnChangeAjaxBehavior() { @Override protected void onUpdate(AjaxRequestTarget target) { ApplicationRelease selectedRelease = releaseSelect.getModelObject(); boolean isSelected = selectedRelease != null; updateMatrixContainerVisibility(isSelected, target); if (isSelected) { try { parentPage.getLogicalDeploymentPersisted(selectedRelease.getUID()); envArchitecturePanel.updateTable(); } catch (ObjectNotFoundException e) { logger.info("Logical deployment not found for release: " + selectedRelease.getUID(), e); } } } }); releaseSelect.setNullValid(true); releaseContainer.add(releaseSelect); //Description appDescriptionLabel = new Label("appDescription", "placeholder"); appDescriptionContainer.add(appDescriptionLabel); //Matrix envArchitecturePanel = new DesignerArchitectureMatrixPanel("archi", parentPage, true, false); architectureContainer.add(envArchitecturePanel); }
From source file:com.inductiveautomation.xopc.drivers.modbus2.configuration.web.ModbusConfigurationUI.java
License:Open Source License
private void addComponents() { T settingsRecord = (T) getDefaultModelObject(); String mapString = (String) TypeUtilities.toString(settingsRecord.getAddressMap()); addressMap = MutableModbusAddressMap.fromParseableString(mapString); if (addressMap == null) { addressMap = new MutableModbusAddressMap(); }/* w ww . j a v a2s . c o m*/ radix = addressMap.getDesignatorRadix(); final Form<Object> form = new Form<Object>("form") { @Override protected void onSubmit() { handleOnSubmit(); } }; form.add(new FeedbackPanel("feedback")); final WebMarkupContainer tableContainer = new WebMarkupContainer("table-container"); tableContainer.setOutputMarkupId(true); final WebMarkupContainer radixContainer = new WebMarkupContainer("radix-container") { @Override public boolean isVisible() { return entries.size() > 0; } }; radixContainer.setOutputMarkupId(true); radixContainer.add(new Label("radix-label", new LenientResourceModel("radixlabel", "Radix")) { @Override public boolean isVisible() { return entries.size() > 0; } }); final RequiredTextField<Integer> radixField = new RequiredTextField<Integer>("radix", new PropertyModel<Integer>(this, "radix")) { @Override public boolean isVisible() { return entries.size() > 0; } }; radixField.add(new OnChangeAjaxBehavior() { @Override protected void onUpdate(AjaxRequestTarget target) { try { Integer radix = Integer.parseInt(radixField.getValue()); setRadix(radix); } catch (Exception e) { } } }); radixContainer.add(radixField); tableContainer.add(radixContainer); radixContainer.add(new Link<Object>("set-radix") { @Override public void onClick() { if (addressMap != null) { } } @Override public boolean isVisible() { return false; } }); // Create the configuration entries for the listview for (DesignatorRange dr : addressMap.keySet()) { MutableDesignatorRange mdr = new MutableDesignatorRange(dr); MutableModbusRange mbr = new MutableModbusRange(addressMap.get(dr)); entries.add(new ModbusConfigurationEntry(mdr, mbr)); } // Create the listview listview = new ListEditor<ModbusConfigurationEntry>("config-listview", getListviewModel()) { @Override protected void onPopulateItem(ListItem<ModbusConfigurationEntry> item) { final ModbusConfigurationEntry configEntry = item.getModelObject(); item.add(newPrefixTextField(configEntry)); item.add(newStartTextField(configEntry)); item.add(newEndTextField(configEntry)); item.add(newStepCheckboxField(configEntry)); item.add(newModbusUnitIDTextField(configEntry)); item.add(newModbusAddressTypeDropdown(configEntry)); item.add(newModbusAddressTextField(configEntry)); item.add(new DeleteLink("delete-link")); } }; WebMarkupContainer noMappingsContainer = new WebMarkupContainer("no-mappings-container") { @Override public boolean isVisible() { return entries.size() == 0; } ; }; noMappingsContainer .add(new Label("no-mappings-label", new LenientResourceModel("nomappings", "No mappings."))); tableContainer.add(noMappingsContainer); tableContainer.add(listview); form.add(tableContainer); form.add(new SubmitLink("add-row-link") { { setDefaultFormProcessing(false); } @Override public void onSubmit() { listview.addItem(new ModbusConfigurationEntry()); } }); form.add(new Button("save")); add(form); // CSV export try { Link<IResource> exportLink = new ResourceLink<IResource>("export-link", new ExportCsvResource()); add(exportLink); } catch (Exception e) { Link<Object> exportLink = new Link<Object>("export-link") { @Override public void onClick() { } @Override public boolean isVisible() { return false; } }; add(exportLink); } // CSV import final FileUploadField uploadField = new FileUploadField("upload-field"); Form<?> uploadForm = new Form<Object>("upload-form") { @Override protected void onSubmit() { try { addressMap = ModbusCsvParser.fromCsv(uploadField.getFileUpload().getInputStream()); radix = addressMap.getDesignatorRadix(); listview.clear(); for (DesignatorRange dr : addressMap.keySet()) { MutableDesignatorRange mdr = new MutableDesignatorRange(dr); MutableModbusRange mbr = new MutableModbusRange(addressMap.get(dr)); listview.addItem(new ModbusConfigurationEntry(mdr, mbr)); } } catch (Exception e) { error("Error importing configuration from CSV file."); } } }; uploadForm.add(uploadField); SubmitLink importLink = new SubmitLink("import-link"); uploadForm.add(importLink); add(uploadForm); }
From source file:com.inductiveautomation.xopc.drivers.modbus2.configuration.web.ModbusConfigurationUI.java
License:Open Source License
private TextField<String> newPrefixTextField(final ModbusConfigurationEntry configEntry) { final RequiredTextField<String> textField = new RequiredTextField<String>("prefix", new PropertyModel<String>(configEntry, "designatorRange.designator")); textField.add(new PatternValidator("[A-Za-z0-9_]+") { @Override/*from w w w . ja v a 2 s . co m*/ protected ValidationError decorate(ValidationError error, IValidatable<String> validatable) { error.addKey("prefix.PatternValidator"); return error; } }); textField.add(new StringValidator(1, 12) { @Override protected ValidationError decorate(ValidationError error, IValidatable<String> validatable) { error.addKey("prefix.LengthValidator"); return error; } }); textField.add(new PrefixValidator()); textField.add(new OnChangeAjaxBehavior() { @Override protected void onUpdate(AjaxRequestTarget target) { configEntry.getDesignatorRange().setDesignator(textField.getModelObject()); } }); return textField; }
From source file:com.inductiveautomation.xopc.drivers.modbus2.configuration.web.ModbusConfigurationUI.java
License:Open Source License
private TextField<String> newStartTextField(final ModbusConfigurationEntry configEntry) { final RequiredTextField<String> textField = new RequiredTextField<String>("start", new PropertyModel<String>(configEntry, "designatorRange.start")); textField.add(new RadixValidator()); textField.add(new OnChangeAjaxBehavior() { @Override/*w w w. j a va2 s . c o m*/ protected void onUpdate(AjaxRequestTarget target) { configEntry.getDesignatorRange().setStart(textField.getModelObject()); } }); return textField; }
From source file:com.inductiveautomation.xopc.drivers.modbus2.configuration.web.ModbusConfigurationUI.java
License:Open Source License
private TextField<String> newEndTextField(final ModbusConfigurationEntry configEntry) { final RequiredTextField<String> textField = new RequiredTextField<String>("end", new PropertyModel<String>(configEntry, "designatorRange.end")); textField.add(new RadixValidator()); textField.add(new OnChangeAjaxBehavior() { @Override/*from w w w . ja v a 2s.co m*/ protected void onUpdate(AjaxRequestTarget target) { configEntry.getDesignatorRange().setEnd(textField.getModelObject()); } }); return textField; }