Example usage for org.apache.wicket.markup.html.panel Panel setVisibilityAllowed

List of usage examples for org.apache.wicket.markup.html.panel Panel setVisibilityAllowed

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.panel Panel setVisibilityAllowed.

Prototype

public final Component setVisibilityAllowed(boolean allowed) 

Source Link

Document

Sets whether or not this component is allowed to be visible.

Usage

From source file:org.geoserver.web.data.store.DefaultDataStoreEditPanel.java

License:Open Source License

/**
 * Creates a form input component for the given datastore param based on its type and metadata
 * properties./*from   w w  w .ja  va  2 s  .  c  o m*/
 * 
 * @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;
}