Example usage for org.apache.wicket.markup.html.form SubmitLink SubmitLink

List of usage examples for org.apache.wicket.markup.html.form SubmitLink SubmitLink

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form SubmitLink SubmitLink.

Prototype

public SubmitLink(String id) 

Source Link

Document

With this constructor the SubmitLink must be inside a Form.

Usage

From source file:org.geoserver.web.data.store.aggregate.AbstractConfigPage.java

License:Open Source License

private SubmitLink saveLink() {
    return new SubmitLink("save") {
        @Override// w  w  w. ja v a  2 s .c  o m
        public void onSubmit() {
            AggregateTypeConfiguration config = form.getModelObject();
            List<SourceType> stypes = config.getSourceTypes();
            if (stypes == null || stypes.size() == 0) {
                error(new ParamResourceModel("atLeastOneSource", AbstractConfigPage.this).getString());
            } else if (AbstractConfigPage.this.onSubmit()) {
                originalConfig.copyFrom(config);
                setResponsePage(master.getPage());
            }
        }
    };
}

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

License:Open Source License

/**
 * Creates the page components to present the list of available vector and raster data source
 * types/*from ww w .j av a 2s  .  c  o  m*/
 * 
 * @param workspaceId
 *            the id of the workspace to attach the new resource store to.
 */
@SuppressWarnings("serial")
public NewDataPage() {

    final boolean thereAreWorkspaces = !getCatalog().getWorkspaces().isEmpty();

    if (!thereAreWorkspaces) {
        super.error((String) new ResourceModel("NewDataPage.noWorkspacesErrorMessage").getObject());
    }

    final Form storeForm = new Form("storeForm");
    add(storeForm);

    final ArrayList<String> sortedDsNames = new ArrayList<String>(getAvailableDataStores().keySet());
    Collections.sort(sortedDsNames);

    final CatalogIconFactory icons = CatalogIconFactory.get();
    final ListView dataStoreLinks = new ListView("vectorResources", sortedDsNames) {
        @Override
        protected void populateItem(ListItem item) {
            final String dataStoreFactoryName = item.getDefaultModelObjectAsString();
            final DataAccessFactory factory = getAvailableDataStores().get(dataStoreFactoryName);
            final String description = factory.getDescription();
            SubmitLink link;
            link = new SubmitLink("resourcelink") {
                @Override
                public void onSubmit() {
                    setResponsePage(new DataAccessNewPage(dataStoreFactoryName));
                }
            };
            link.setEnabled(thereAreWorkspaces);
            link.add(new Label("resourcelabel", dataStoreFactoryName));
            item.add(link);
            item.add(new Label("resourceDescription", description));
            Image icon = new Image("storeIcon", icons.getStoreIcon(factory.getClass()));
            // TODO: icons could provide a description too to be used in alt=...
            icon.add(new AttributeModifier("alt", true, new Model("")));
            item.add(icon);
        }
    };

    final List<String> sortedCoverageNames = new ArrayList<String>();
    sortedCoverageNames.addAll(getAvailableCoverageStores().keySet());
    Collections.sort(sortedCoverageNames);

    final ListView coverageLinks = new ListView("rasterResources", sortedCoverageNames) {
        @Override
        protected void populateItem(ListItem item) {
            final String coverageFactoryName = item.getDefaultModelObjectAsString();
            final Map<String, Format> coverages = getAvailableCoverageStores();
            Format format = coverages.get(coverageFactoryName);
            final String description = format.getDescription();
            SubmitLink link;
            link = new SubmitLink("resourcelink") {
                @Override
                public void onSubmit() {
                    setResponsePage(new CoverageStoreNewPage(coverageFactoryName));
                }
            };
            link.setEnabled(thereAreWorkspaces);
            link.add(new Label("resourcelabel", coverageFactoryName));
            item.add(link);
            item.add(new Label("resourceDescription", description));
            Image icon = new Image("storeIcon", icons.getStoreIcon(format.getClass()));
            // TODO: icons could provide a description too to be used in alt=...
            icon.add(new AttributeModifier("alt", true, new Model("")));
            item.add(icon);
        }
    };

    final List<OtherStoreDescription> otherStores = getOtherStores();

    final ListView otherStoresLinks = new ListView("otherStores", otherStores) {
        @Override
        protected void populateItem(ListItem item) {
            final OtherStoreDescription store = (OtherStoreDescription) item.getModelObject();
            SubmitLink link;
            link = new SubmitLink("resourcelink") {
                @Override
                public void onSubmit() {
                    setResponsePage(store.configurationPage);
                }
            };
            link.setEnabled(thereAreWorkspaces);
            link.add(
                    new Label("resourcelabel", new ParamResourceModel("other." + store.key, NewDataPage.this)));
            item.add(link);
            item.add(new Label("resourceDescription",
                    new ParamResourceModel("other." + store.key + ".description", NewDataPage.this)));
            Image icon = new Image("storeIcon", store.icon);
            // TODO: icons could provide a description too to be used in alt=...
            icon.add(new AttributeModifier("alt", true, new Model("")));
            item.add(icon);
        }
    };

    storeForm.add(dataStoreLinks);
    storeForm.add(coverageLinks);
    storeForm.add(otherStoresLinks);
}

From source file:org.geoserver.web.data.workspace.WorkspaceEditPage.java

License:Open Source License

private void init(WorkspaceInfo ws) {
    defaultWs = ws.getId().equals(getCatalog().getDefaultWorkspace().getId());

    wsModel = new WorkspaceDetachableModel(ws);

    NamespaceInfo ns = getCatalog().getNamespaceByPrefix(ws.getName());
    nsModel = new NamespaceDetachableModel(ns);

    Form form = new Form("form", new CompoundPropertyModel(nsModel)) {
        protected void onSubmit() {
            try {
                saveWorkspace();/* w w  w.  j a v a2s .  c  o m*/
            } catch (RuntimeException e) {
                LOGGER.log(Level.WARNING, "Failed to save workspace", e);
                error(e.getMessage() == null
                        ? "Failed to save workspace, no error message available, see logs for details"
                        : e.getMessage());
            }
        }
    };
    add(form);

    //check for full admin, we don't allow workspace admins to change all settings
    boolean isFullAdmin = isAuthenticatedAsAdmin();

    TextField name = new TextField("name", new PropertyModel(wsModel, "name"));
    name.setRequired(true);
    name.setEnabled(isFullAdmin);

    name.add(new XMLNameValidator());
    form.add(name);
    TextField uri = new TextField("uri", new PropertyModel(nsModel, "uRI"), String.class);
    uri.setRequired(true);
    uri.add(new URIValidator());
    form.add(uri);
    CheckBox defaultChk = new CheckBox("default", new PropertyModel(this, "defaultWs"));
    form.add(defaultChk);
    defaultChk.setEnabled(isFullAdmin);

    //stores
    //        StorePanel storePanel = new StorePanel("storeTable", new StoreProvider(ws), false);
    //        form.add(storePanel);

    add(dialog = new GeoServerDialog("dialog"));

    //local settings
    form.add(settingsPanel = new SettingsPanel("settings", wsModel));
    form.add(new HelpLink("settingsHelp").setDialog(dialog));

    //local services
    form.add(servicesPanel = new ServicesPanel("services", wsModel));
    form.add(new HelpLink("servicesHelp").setDialog(dialog));

    SubmitLink submit = new SubmitLink("save");
    form.add(submit);
    form.setDefaultButton(submit);
    form.add(new BookmarkablePageLink("cancel", WorkspacePage.class));
}

From source file:org.geoserver.web.importer.AbstractDBMSPage.java

License:Open Source License

/**
 * Setups the datastore and moves to the next page
 * //from w  w  w . j  a va  2  s .  com
 * @return
 */
SubmitLink submitLink() {
    // TODO: fill this up with the required parameters
    return new SubmitLink("next") {

        @Override
        public void onSubmit() {
            try {
                // check there is not another store with the same name
                WorkspaceInfo workspace = generalParams.getWorkpace();
                NamespaceInfo namespace = getCatalog().getNamespaceByPrefix(workspace.getName());
                StoreInfo oldStore = getCatalog().getStoreByName(workspace, generalParams.name,
                        StoreInfo.class);
                if (oldStore != null) {
                    error(new ParamResourceModel("ImporterError.duplicateStore", AbstractDBMSPage.this,
                            generalParams.name, workspace.getName()).getString());
                    return;
                }

                // build up the store connection param map
                Map<String, Serializable> params = new HashMap<String, Serializable>();
                DataStoreFactorySpi factory = fillStoreParams(namespace, params);

                // ok, check we can connect
                DataAccess store = null;
                try {
                    store = DataAccessFinder.getDataStore(params);
                    // force the store to open a connection
                    store.getNames();
                    store.dispose();
                } catch (Throwable e) {
                    LOGGER.log(Level.INFO, "Could not connect to the datastore", e);
                    error(new ParamResourceModel("ImporterError.databaseConnectionError", AbstractDBMSPage.this,
                            e.getMessage()).getString());
                    return;
                } finally {
                    if (store != null)
                        store.dispose();
                }

                // build the store
                CatalogBuilder builder = new CatalogBuilder(getCatalog());
                builder.setWorkspace(workspace);
                StoreInfo si = builder.buildDataStore(generalParams.name);
                si.setDescription(generalParams.description);
                si.getConnectionParameters().putAll(params);
                si.setEnabled(true);
                si.setType(factory.getDisplayName());
                getCatalog().add(si);

                // redirect to the layer chooser
                PageParameters pp = new PageParameters();
                pp.put("store", si.getName());
                pp.put("workspace", workspace.getName());
                pp.put("storeNew", true);
                pp.put("workspaceNew", false);
                pp.put("skipGeometryless", isGeometrylessExcluded());
                setResponsePage(VectorLayerChooserPage.class, pp);
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Error while setting up mass import", e);
            }

        }
    };
}

From source file:org.geoserver.web.importer.DirectoryPage.java

License:Open Source License

SubmitLink submitLink() {
    return new SubmitLink("next") {

        @Override/*w  w w .j a va2 s  .c om*/
        public void onSubmit() {
            try {
                // check there is not another store with the same name
                WorkspaceInfo workspace = generalParams.getWorkpace();
                NamespaceInfo namespace = getCatalog().getNamespaceByPrefix(workspace.getName());
                StoreInfo oldStore = getCatalog().getStoreByName(workspace, generalParams.name,
                        StoreInfo.class);
                if (oldStore != null) {
                    error(new ParamResourceModel("ImporterError.duplicateStore", DirectoryPage.this,
                            generalParams.name, workspace.getName()).getString());
                    return;
                }

                // build/reuse the store
                String storeType = new ShapefileDataStoreFactory().getDisplayName();
                Map<String, Serializable> params = new HashMap<String, Serializable>();
                params.put(ShapefileDataStoreFactory.URLP.key, new File(directory).toURI().toURL().toString());
                params.put(ShapefileDataStoreFactory.NAMESPACEP.key, new URI(namespace.getURI()).toString());

                DataStoreInfo si;
                StoreInfo preExisting = getCatalog().getStoreByName(workspace, generalParams.name,
                        StoreInfo.class);
                boolean storeNew = false;
                if (preExisting != null) {
                    if (!(preExisting instanceof DataStoreInfo)) {
                        error(new ParamResourceModel("storeExistsNotVector", this, generalParams.name));
                        return;
                    }
                    si = (DataStoreInfo) preExisting;
                    if (!si.getType().equals(storeType) || !si.getConnectionParameters().equals(params)) {
                        error(new ParamResourceModel("storeExistsNotSame", this, generalParams.name));
                        return;
                    }
                    // make sure it's enabled, we just verified the directory exists
                    si.setEnabled(true);
                } else {
                    storeNew = true;
                    CatalogBuilder builder = new CatalogBuilder(getCatalog());
                    builder.setWorkspace(workspace);
                    si = builder.buildDataStore(generalParams.name);
                    si.setDescription(generalParams.description);
                    si.getConnectionParameters().putAll(params);
                    si.setEnabled(true);
                    si.setType(storeType);

                    getCatalog().add(si);
                }

                // redirect to the layer chooser
                PageParameters pp = new PageParameters();
                pp.put("store", si.getName());
                pp.put("workspace", workspace.getName());
                pp.put("storeNew", storeNew);
                pp.put("workspaceNew", false);
                setResponsePage(VectorLayerChooserPage.class, pp);
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Error while setting up mass import", e);
            }

        }
    };
}

From source file:org.geoserver.web.importer.ImportPage.java

License:Open Source License

SubmitLink submitLink() {
    return new SubmitLink("import") {

        @Override// w  ww.  j a va2s . com
        public void onSubmit() {
            try {
                // build the datastore namespace URI
                String ns = buildDatastoreNamespace();

                // build the workspace
                WorkspaceInfo ws = getCatalog().getWorkspaceByName(project);
                boolean workspaceNew = false;
                if (ws == null) {
                    workspaceNew = true;
                    ws = getCatalog().getFactory().createWorkspace();
                    ws.setName(project);
                    NamespaceInfo nsi = getCatalog().getFactory().createNamespace();
                    nsi.setPrefix(project);
                    nsi.setURI(ns);
                    getCatalog().add(ws);
                    getCatalog().add(nsi);
                }

                // build/reuse the store
                String storeType = new DirectoryDataStoreFactory().getDisplayName();
                Map<String, Serializable> params = new HashMap<String, Serializable>();
                params.put(DirectoryDataStoreFactory.URLP.key, new File(directory).toURI().toURL().toString());
                params.put(DirectoryDataStoreFactory.NAMESPACE.key, new URI(ns).toString());

                DataStoreInfo si;
                StoreInfo preExisting = getCatalog().getStoreByName(ws, project, StoreInfo.class);
                boolean storeNew = false;
                if (preExisting != null) {
                    if (!(preExisting instanceof DataStoreInfo)) {
                        error(new ParamResourceModel("storeExistsNotVector", this, project));
                        return;
                    }
                    si = (DataStoreInfo) preExisting;
                    if (!si.getType().equals(storeType) || !si.getConnectionParameters().equals(params)) {
                        error(new ParamResourceModel("storeExistsNotSame", this, project));
                        return;
                    }
                    // make sure it's enabled, we just verified the directory exists
                    si.setEnabled(true);
                } else {
                    storeNew = true;
                    CatalogBuilder builder = new CatalogBuilder(getCatalog());
                    builder.setWorkspace(ws);
                    si = builder.buildDataStore(project);
                    si.getConnectionParameters().putAll(params);
                    si.setEnabled(true);
                    si.setType(storeType);

                    getCatalog().add(si);
                }

                // build and run the importer
                FeatureTypeImporter importer = new FeatureTypeImporter(si, null, getCatalog(), workspaceNew,
                        storeNew);
                ImporterThreadManager manager = (ImporterThreadManager) getGeoServerApplication()
                        .getBean("importerPool");
                String importerKey = manager.startImporter(importer);

                setResponsePage(new ImportProgressPage(importerKey));
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Error while setting up mass import", e);
            }

        }
    };
}

From source file:org.geoserver.web.importer.VectorLayerChooserPage.java

License:Open Source License

SubmitLink submitLink() {
    return new SubmitLink("import") {

        @Override/*ww w  .j a v  a2  s  .  c  o  m*/
        public void onSubmit() {
            try {
                // grab the selection
                Set<Name> names = new java.util.HashSet<Name>();
                for (Resource r : layers.getSelection()) {
                    names.add(r.getName());
                }

                // if nothing was selected we need to go back
                if (names.size() == 0) {
                    error(new ParamResourceModel("selectionEmpty", VectorLayerChooserPage.this).getString());
                    return;
                }

                DataStoreInfo store = getCatalog().getDataStoreByName(wsName, storeName);

                // build and run the importer
                FeatureTypeImporter importer = new FeatureTypeImporter(store, null, names, getCatalog(),
                        workspaceNew, storeNew);
                ImporterThreadManager manager = (ImporterThreadManager) getGeoServerApplication()
                        .getBean("importerPool");
                String importerKey = manager.startImporter(importer);

                setResponsePage(new ImportProgressPage(importerKey));
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Error while setting up mass import", e);
            }

        }
    };
}

From source file:org.geoserver.web.publish.PublishedConfigurationPage.java

License:Open Source License

/**
 * //from   ww  w. j  a v a  2 s . c om
 */
@SuppressWarnings("rawtypes")
private void initComponents() {
    this.tabPanelCustomModels = new LinkedHashMap<Class<? extends PublishedEditTabPanel<T>>, IModel<?>>();

    add(new Label("publishedinfoname", getPublishedInfo().prefixedName()));
    Form<T> theForm = new Form<T>("publishedinfo", myModel);
    add(theForm);

    List<ITab> tabs = new ArrayList<ITab>();

    // add the "well known" tabs
    tabs.add(new AbstractTab(new org.apache.wicket.model.ResourceModel("ResourceConfigurationPage.Data")) {
        private static final long serialVersionUID = 1L;

        public Panel getPanel(String panelID) {
            return createMainTab(panelID).setInputEnabled(inputEnabled);
        }
    });

    tabs.add(
            new AbstractTab(new org.apache.wicket.model.ResourceModel("ResourceConfigurationPage.Publishing")) {
                private static final long serialVersionUID = 1L;

                public Panel getPanel(String panelID) {
                    return new PublishingEditTabPanel(panelID).setInputEnabled(inputEnabled);
                }
            });

    // add the tabs contributed via extension point
    List<PublishedEditTabPanelInfo> tabPanels = getGeoServerApplication()
            .getBeansOfType(PublishedEditTabPanelInfo.class);

    // sort the tabs based on order
    Collections.sort(tabPanels, new Comparator<PublishedEditTabPanelInfo>() {
        public int compare(PublishedEditTabPanelInfo o1, PublishedEditTabPanelInfo o2) {
            Integer order1 = o1.getOrder() >= 0 ? o1.getOrder() : Integer.MAX_VALUE;
            Integer order2 = o2.getOrder() >= 0 ? o2.getOrder() : Integer.MAX_VALUE;

            return order1.compareTo(order2);
        }
    });

    for (PublishedEditTabPanelInfo ttabPanelInfo : tabPanels) {
        if (ttabPanelInfo.supports(getPublishedInfo())) {

            @SuppressWarnings("unchecked")
            PublishedEditTabPanelInfo<T> tabPanelInfo = (PublishedEditTabPanelInfo<T>) ttabPanelInfo;

            String titleKey = tabPanelInfo.getTitleKey();
            IModel<String> titleModel = null;
            if (titleKey != null) {
                titleModel = new org.apache.wicket.model.ResourceModel(titleKey);
            } else {
                titleModel = new Model<String>(tabPanelInfo.getComponentClass().getSimpleName());
            }

            final Class<PublishedEditTabPanel<T>> panelClass = tabPanelInfo.getComponentClass();
            IModel<?> panelCustomModel = tabPanelInfo.createOwnModel(myModel, isNew);
            tabPanelCustomModels.put(panelClass, panelCustomModel);

            tabs.add(new AbstractTab(titleModel) {
                private static final long serialVersionUID = -6637277497986497791L;
                private final Class<PublishedEditTabPanel<T>> panelType = panelClass;

                @Override
                public Panel getPanel(String panelId) {
                    PublishedEditTabPanel<?> tabPanel;
                    final IModel<?> panelCustomModel = tabPanelCustomModels.get(panelType);
                    try {
                        // if this tab needs a custom model instead of just our layer model, then
                        // let it create it once
                        if (panelCustomModel == null) {
                            tabPanel = panelClass.getConstructor(String.class, IModel.class)
                                    .newInstance(panelId, myModel);
                        } else {
                            tabPanel = panelClass.getConstructor(String.class, IModel.class, IModel.class)
                                    .newInstance(panelId, myModel, panelCustomModel);
                        }
                    } catch (Exception e) {
                        throw new WicketRuntimeException(e);
                        // LOGGER.log(Level.WARNING, "Error creating resource panel", e);
                    }
                    return tabPanel;
                }
            });
        }
    }

    // we need to override with submit links so that the various form
    // element
    // will validate and write down into their
    tabbedPanel = new TabbedPanel("tabs", tabs) {
        private static final long serialVersionUID = 1L;

        @Override
        protected WebMarkupContainer newLink(String linkId, final int index) {
            return new SubmitLink(linkId) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onSubmit() {
                    setSelectedTab(index);
                }
            };
        }
    };
    theForm.add(tabbedPanel);
    theForm.add(saveLink());
    theForm.add(cancelLink());
}

From source file:org.geoserver.web.publish.PublishedConfigurationPage.java

License:Open Source License

private SubmitLink saveLink() {
    return new SubmitLink("save") {
        private static final long serialVersionUID = 1839992481355433705L;

        @Override/*from ww  w .  j av a 2s .co  m*/
        public void onSubmit() {
            doSave();
        }
    };
}

From source file:org.geoserver.web.security.data.AbstractDataAccessRulePage.java

License:Open Source License

SubmitLink saveLink() {
    return new SubmitLink("save") {
        @Override//from  ww  w .ja v  a  2s.com
        public void onSubmit() {
            onFormSubmit();
        }
    };
}