如下图所示,为我们经常操作的添加数据存储的界面。
可以看到这个代码在如下的位置。在这样的代码中实现跳转。header.add(new BookmarkablePageLink("addNew", NewDataPage.class));
- public class StorePage extends GeoServerSecuredPage {
- StoreProvider provider = new StoreProvider();
-
- StorePanel table;
-
- SelectionRemovalLink removal;
-
- GeoServerDialog dialog;
-
- public StorePage() {
- // the table, and wire up selection change
- table =
- new StorePanel("table", provider, true) {
- @Override
- protected void onSelectionUpdate(AjaxRequestTarget target) {
- removal.setEnabled(table.getSelection().size() > 0);
- target.add(removal);
- }
- };
- table.setOutputMarkupId(true);
- add(table);
-
- // the confirm dialog
- add(dialog = new GeoServerDialog("dialog"));
- setHeaderPanel(headerPanel());
- }
-
- protected Component headerPanel() {
- Fragment header = new Fragment(HEADER_PANEL, "header", this);
-
- // the add button
- header.add(new BookmarkablePageLink("addNew", NewDataPage.class));
-
- // the removal button
- header.add(removal = new SelectionRemovalLink("removeSelected", table, dialog));
- removal.setOutputMarkupId(true);
- removal.setEnabled(false);
-
- return header;
- }
-
- @Override
- protected ComponentAuthorizer getPageAuthorizer() {
- return ComponentAuthorizer.WORKSPACE_ADMIN;
- }
- }
进入到NewDataPage页面,进行初始化数据类型,分别为矢量、栅格、以及其他的数据。
- 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
sortedDsNames = - new ArrayList
(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", new Model("")));
- item.add(icon);
- }
- };
-
- final List
sortedCoverageNames = new ArrayList(); - 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
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", new Model("")));
- item.add(icon);
- }
- };
-
- final List
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", new Model("")));
- item.add(icon);
- }
- };
-
- storeForm.add(dataStoreLinks);
- storeForm.add(coverageLinks);
- storeForm.add(otherStoresLinks);
- }
这就是我们的NewDataPage页面。
3.DataAccessNewPage
当点击进入到shp的发布界面如下所示。
对应的代码如下所示。
- /** */
- protected void initUI(final DataStoreInfo storeInfo) throws IllegalArgumentException {
-
- if (storeInfo.getWorkspace() == null) {
- throw new IllegalArgumentException("Workspace not provided");
- }
-
- final Catalog catalog = getCatalog();
- final ResourcePool resourcePool = catalog.getResourcePool();
- DataAccessFactory dsFactory;
- try {
- dsFactory = resourcePool.getDataStoreFactory(storeInfo);
- } catch (IOException e) {
- String msg =
- (String)
- new ResourceModel("AbstractDataAccessPage.cantGetDataStoreFactory")
- .getObject();
- msg += ": " + e.getMessage();
- throw new IllegalArgumentException(msg);
- }
- if (dsFactory == null) {
- String msg =
- (String)
- new ResourceModel("AbstractDataAccessPage.cantGetDataStoreFactory")
- .getObject();
- throw new IllegalArgumentException(msg);
- }
-
- final IModel model = new CompoundPropertyModel(storeInfo);
-
- final Form paramsForm = new Form("dataStoreForm", model);
- add(paramsForm);
-
- paramsForm.add(new Label("storeType", dsFactory.getDisplayName()));
- paramsForm.add(new Label("storeTypeDescription", dsFactory.getDescription()));
-
- {
- final IModel wsModel = new PropertyModel(model, "workspace");
- final IModel wsLabelModel = new ResourceModel("workspace", "Workspace");
- workspacePanel = new WorkspacePanel("workspacePanel", wsModel, wsLabelModel, true);
- }
- paramsForm.add(workspacePanel);
-
- final TextParamPanel dataStoreNamePanel;
-
- dataStoreNamePanel =
- new TextParamPanel(
- "dataStoreNamePanel",
- new PropertyModel(model, "name"),
- new ResourceModel("AbstractDataAccessPage.dataSrcName", "Data Source Name"),
- true);
- paramsForm.add(dataStoreNamePanel);
-
- paramsForm.add(
- new TextParamPanel(
- "dataStoreDescriptionPanel",
- new PropertyModel(model, "description"),
- new ResourceModel("AbstractDataAccessPage.description", "Description"),
- false,
- (IValidator[]) null));
-
- paramsForm.add(
- new CheckBoxParamPanel(
- "dataStoreEnabledPanel",
- new PropertyModel(model, "enabled"),
- new ResourceModel("enabled", "Enabled")));
-
- {
- /*
- * Here's where the extension point is applied in order to give extensions a chance to
- * provide custom behavior/components for the coverage form other than the default
- * single "url" input field
- */
- GeoServerApplication app = getGeoServerApplication();
- storeEditPanel =
- StoreExtensionPoints.getStoreEditPanel(
- "parametersPanel", paramsForm, storeInfo, app);
- }
- paramsForm.add(storeEditPanel);
-
- paramsForm.add(new FeedbackPanel("feedback"));
-
- // validate the selected workspace does not already contain a store with the same name
- final String dataStoreInfoId = storeInfo.getId();
- StoreNameValidator storeNameValidator =
- new StoreNameValidator(
- workspacePanel.getFormComponent(),
- dataStoreNamePanel.getFormComponent(),
- dataStoreInfoId);
- paramsForm.add(storeNameValidator);
-
- paramsForm.add(new BookmarkablePageLink("cancel", StorePage.class));
-
- paramsForm.add(
- new AjaxSubmitLink("save", paramsForm) {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void onError(AjaxRequestTarget target, Form form) {
- super.onError(target, form);
- target.add(paramsForm);
- }
-
- @Override
- protected void onSubmit(AjaxRequestTarget target, Form form) {
- try {
- DataStoreInfo dataStore = (DataStoreInfo) form.getModelObject();
- onSaveDataStore(dataStore, target, true);
- } catch (IllegalArgumentException e) {
- paramsForm.error(e.getMessage());
- target.add(paramsForm);
- }
- }
- });
-
- paramsForm.add(applyLink(paramsForm));
-
- // save the namespace panel as an instance variable. Needed as per GEOS-3149
- makeNamespaceSyncUpWithWorkspace(paramsForm);
- }
这里看到数据的初始化流程。