Package org.geoserver.web.data.store

Source Code of org.geoserver.web.data.store.AbstractWMSStorePage

/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.web.data.store;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.validation.validator.RangeValidator;
import org.geoserver.catalog.WMSStoreInfo;
import org.geoserver.web.ComponentAuthorizer;
import org.geoserver.web.GeoServerSecuredPage;
import org.geoserver.web.data.store.panel.CheckBoxParamPanel;
import org.geoserver.web.data.store.panel.PasswordParamPanel;
import org.geoserver.web.data.store.panel.TextParamPanel;
import org.geoserver.web.data.store.panel.WorkspacePanel;
import org.geoserver.web.wicket.GeoServerDialog;
import org.geoserver.web.wicket.ParamResourceModel;

/**
* Supports coverage store configuration
*
* @author Andrea Aime
* @see StoreEditPanel
*/
@SuppressWarnings("serial")
abstract class AbstractWMSStorePage extends GeoServerSecuredPage {

    protected WorkspacePanel workspacePanel;

    private Form form;
   
    GeoServerDialog dialog;

    TextParamPanel capabilitiesURL;

    protected TextParamPanel usernamePanel;
   
    protected PasswordParamPanel password;
   
    void initUI(final WMSStoreInfo store) {
        IModel model = new Model(store);
       
        add(dialog = new GeoServerDialog("dialog"));

        // build the form
        form = new Form("form", model);
        add(form);

        // name
        PropertyModel nameModel = new PropertyModel(model, "name");
        final TextParamPanel namePanel = new TextParamPanel("namePanel", nameModel,
                new ResourceModel("AbstractWMSStorePage.dataSrcName", "Data Source Name"), true);

        form.add(namePanel);

        // description and enabled
        form.add(new TextParamPanel("descriptionPanel", new PropertyModel(model,
                "description"), new ResourceModel("AbstractWMSStorePage.description", "Description"), false));
        form.add(new CheckBoxParamPanel("enabledPanel", new PropertyModel(model, "enabled"),
                new ResourceModel("enabled", "Enabled")));
        // a custom converter will turn this into a namespace url
        workspacePanel = new WorkspacePanel("workspacePanel",
                new PropertyModel(model, "workspace"), new ResourceModel("workspace", "Workspace"),
                true);
        form.add(workspacePanel);
       
        capabilitiesURL = new TextParamPanel("capabilitiesURL", new PropertyModel(model, "capabilitiesURL"),
                new ParamResourceModel("capabilitiesURL", AbstractWMSStorePage.this), true);
        form.add(capabilitiesURL);

        // user name
        PropertyModel userModel = new PropertyModel(model, "username");
        usernamePanel = new TextParamPanel("userNamePanel", userModel, new ResourceModel(
                "AbstractWMSStorePage.userName"), false);

        form.add(usernamePanel);

        // password
        PropertyModel passwordModel = new PropertyModel(model, "password");
        form.add(password = new PasswordParamPanel("passwordPanel", passwordModel, new ResourceModel(
                "AbstractWMSStorePage.password"), false));
       
        // max concurrent connections
        final PropertyModel<Boolean> useHttpConnectionPoolModel = new PropertyModel<Boolean>(model,
                "useConnectionPooling");
        CheckBoxParamPanel useConnectionPooling = new CheckBoxParamPanel(
                "useConnectionPoolingPanel", useHttpConnectionPoolModel, new ResourceModel(
                        "AbstractWMSStorePage.useHttpConnectionPooling"));
        form.add(useConnectionPooling);

        PropertyModel<String> connectionsModel = new PropertyModel<String>(model, "maxConnections");
        final TextParamPanel maxConnections = new TextParamPanel("maxConnectionsPanel",
                connectionsModel, new ResourceModel("AbstractWMSStorePage.maxConnections"), true,
                new RangeValidator<Integer>(1, 128));
        maxConnections.setOutputMarkupId(true);
        maxConnections.setEnabled(useHttpConnectionPoolModel.getObject());
        form.add(maxConnections);

        useConnectionPooling.getFormComponent().add(new OnChangeAjaxBehavior() {

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                boolean enabled = useHttpConnectionPoolModel.getObject();
                maxConnections.setEnabled(enabled);
                target.addComponent(maxConnections);
            }
        });
       
        // connect timeout
        PropertyModel<Integer> connectTimeoutModel = new PropertyModel<Integer>(model, "connectTimeout");
        form.add(new TextParamPanel("connectTimeoutPanel", connectTimeoutModel, new ResourceModel(
                "AbstractWMSStorePage.connectTimeout"), true, new RangeValidator<Integer>(1, 240)));

        // read timeout
        PropertyModel<Integer> readTimeoutModel = new PropertyModel<Integer>(model, "readTimeout");
        form.add(new TextParamPanel("readTimeoutPanel", readTimeoutModel, new ResourceModel(
                "AbstractWMSStorePage.readTimeout"), true, new RangeValidator<Integer>(1, 360)));

        // cancel/submit buttons
        form.add(new BookmarkablePageLink("cancel", StorePage.class));
        form.add(saveLink());
        form.setDefaultButton(saveLink());

        // feedback panel for error messages
        form.add(new FeedbackPanel("feedback"));

        StoreNameValidator storeNameValidator = new StoreNameValidator(workspacePanel
                .getFormComponent(), namePanel.getFormComponent(), store.getId());
        form.add(storeNameValidator);
    }

    private AjaxSubmitLink saveLink() {
        return new AjaxSubmitLink("save", form) {

            @Override
            protected void onError(AjaxRequestTarget target, Form form) {
                super.onError(target, form);
                target.addComponent(form);
            }

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form form) {
                form.process();
                WMSStoreInfo info = (WMSStoreInfo) form.getModelObject();
                try {
                    onSave(info, target);
                } catch (IllegalArgumentException e) {
                    form.error(e.getMessage());
                    target.addComponent(form);
                }
            }
        };
    }

    /**
     * Template method for subclasses to take the appropriate action when the coverage store page
     * "save" button is pressed.
     *
     * @param info
     *            the StoreInfo to save
     * @throws IllegalArgumentException
     *             with an appropriate error message if the save action can't be successfully
     *             performed
     */
    protected abstract void onSave(WMSStoreInfo info, AjaxRequestTarget target)
            throws IllegalArgumentException;

    protected void clone(final WMSStoreInfo source, WMSStoreInfo target) {
        target.setDescription(source.getDescription());
        target.setEnabled(source.isEnabled());
        target.setName(source.getName());
        target.setType(source.getType());
        target.setCapabilitiesURL(source.getCapabilitiesURL());
        target.setWorkspace(source.getWorkspace());
        target.setUsername(source.getUsername());
        target.setPassword(source.getPassword());
        target.setUseConnectionPooling(source.isUseConnectionPooling());
        target.setMaxConnections(source.getMaxConnections());
        target.setConnectTimeout(source.getConnectTimeout());
        target.setReadTimeout(source.getReadTimeout());
    }

    @Override
    protected ComponentAuthorizer getPageAuthorizer() {
        return ComponentAuthorizer.WORKSPACE_ADMIN;
    }
}
TOP

Related Classes of org.geoserver.web.data.store.AbstractWMSStorePage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.