public DefaultCoverageStoreEditPanel(final String componentId, final Form storeEditForm) { super(componentId, storeEditForm); final IModel formModel = storeEditForm.getModel(); // url TextParamPanel url = new TextParamPanel( "urlPanel", new PropertyModel(formModel, "URL"), new ResourceModel("url", "URL"), true); url.getFormComponent().add(new FileExistsValidator()); add(url); }
/** * Creates a form input component for the given datastore param based on its type and metadata * properties. * * @param paramMetadata * @return */ private Panel getInputComponent( final String componentId, final IModel paramsModel, final ParamInfo paramMetadata) { final String paramName = paramMetadata.getName(); final String paramLabel = paramMetadata.getName(); final boolean required = paramMetadata.isRequired(); final boolean deprecated = paramMetadata.isDeprecated(); final Class<?> binding = paramMetadata.getBinding(); final List<Serializable> options = paramMetadata.getOptions(); Panel parameterPanel; if ("dbtype".equals(paramName) || "filetype".equals(paramName)) { // skip the two well known discriminators IModel model = new MapModel(paramsModel, paramName); TextParamPanel tp = new TextParamPanel( componentId, model, new ResourceModel(paramLabel, paramLabel), required); tp.setVisible(false); parameterPanel = tp; } else if ("namespace".equals(paramName)) { IModel namespaceModel = new NamespaceParamModel(paramsModel, paramName); IModel paramLabelModel = new ResourceModel(paramLabel, paramLabel); parameterPanel = new NamespacePanel(componentId, namespaceModel, paramLabelModel, true); } else if (options != null && options.size() > 0) { IModel<Serializable> valueModel = new MapModel(paramsModel, paramName); IModel<String> labelModel = new ResourceModel(paramLabel, paramLabel); parameterPanel = new DropDownChoiceParamPanel(componentId, valueModel, labelModel, options, required); } else if (Boolean.class == binding) { // TODO Add prefix for better i18n? parameterPanel = new CheckBoxParamPanel( componentId, new MapModel(paramsModel, paramName), new ResourceModel(paramLabel, paramLabel)); } else if (String.class == binding && paramMetadata.isPassword()) { parameterPanel = new PasswordParamPanel( componentId, new MapModel(paramsModel, paramName), new ResourceModel(paramLabel, paramLabel), required); } else { IModel model; if ("url".equalsIgnoreCase(paramName)) { model = new URLModel(paramsModel, paramName); } else { model = new MapModel(paramsModel, paramName); } Panel tp; if (paramMetadata.isLargeText()) { tp = new TextAreaParamPanel( componentId, model, new ResourceModel(paramLabel, paramLabel), required); } else { tp = new TextParamPanel( componentId, model, new ResourceModel(paramLabel, paramLabel), required); } // if it can be a reference to the local filesystem make sure it's valid FormComponent<String> fc = ((ParamPanel) tp).getFormComponent(); if (paramName.equalsIgnoreCase("url")) { fc.add(new FileExistsValidator()); } // make sure the proper value is returned, but don't set it for strings otherwise // we incur in a wicket bug (the empty string is not converter back to a null) // GR: it doesn't work for File neither. // AA: better not mess with files, the converters turn data dir relative to // absolute and bye bye data dir portability if (binding != null && !String.class.equals(binding) && !File.class.equals(binding) && !URL.class.equals(binding) && !binding.isArray()) { fc.setType(binding); } parameterPanel = tp; } Object parameterValue = parameterPanel.getDefaultModelObject(); boolean visible = !(deprecated && isEmpty(parameterValue)); parameterPanel.setVisible(visible); parameterPanel.setVisibilityAllowed(visible); return parameterPanel; }
/** * Creates a form input component for the given datastore param based on its type and metadata * properties. * * @param paramMetadata * @return */ private Panel getInputComponent( final String componentId, final IModel paramsModel, final ParamInfo paramMetadata) { final String paramName = paramMetadata.getName(); final String paramLabel = paramMetadata.getName(); final boolean required = paramMetadata.isRequired(); final Class<?> binding = paramMetadata.getBinding(); Panel parameterPanel; if ("dbtype".equals(paramName) || "filetype".equals(paramName)) { // skip the two well known discriminators IModel model = new MapModel(paramsModel, paramName); TextParamPanel tp = new TextParamPanel( componentId, model, new ResourceModel(paramLabel, paramLabel), required); tp.setVisible(false); parameterPanel = tp; } else if ("namespace".equals(paramName)) { IModel namespaceModel = new NamespaceParamModel(paramsModel, paramName); IModel paramLabelModel = new ResourceModel(paramLabel, paramLabel); parameterPanel = new NamespacePanel(componentId, namespaceModel, paramLabelModel, true); } else if (Boolean.class == binding) { // TODO Add prefix for better i18n? parameterPanel = new CheckBoxParamPanel( componentId, new MapModel(paramsModel, paramName), new ResourceModel(paramLabel, paramLabel)); } else if (String.class == binding && paramMetadata.isPassword()) { parameterPanel = new PasswordParamPanel( componentId, new MapModel(paramsModel, paramName), new ResourceModel(paramLabel, paramLabel), required); } else { IModel model; if ("url".equalsIgnoreCase(paramName)) { model = new URLModel(paramsModel, paramName); } else { model = new MapModel(paramsModel, paramName); } TextParamPanel tp = new TextParamPanel( componentId, model, new ResourceModel(paramLabel, paramLabel), required); // if it can be a reference to the local filesystem make sure it's valid if (paramName.equalsIgnoreCase("url")) { tp.getFormComponent().add(new FileExistsValidator()); } // make sure the proper value is returned, but don't set it for strings otherwise // we incur in a wicket bug (the empty string is not converter back to a null) // GR: it doesn't work for File neither. // AA: better not mess with files, the converters turn data dir relative to // absolute and bye bye data dir portability if (binding != null && !String.class.equals(binding) && !File.class.equals(binding) && !URL.class.equals(binding)) { tp.getFormComponent().setType(binding); } parameterPanel = tp; } return parameterPanel; }