List of usage examples for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow ModalWindow
public ModalWindow(final String id)
From source file:org.geoserver.web.data.layergroup.RootLayerEntryPanel.java
License:Open Source License
@SuppressWarnings({ "rawtypes" }) public RootLayerEntryPanel(String id, final Form form, WorkspaceInfo workspace) { super(id);//from w w w .j a va2 s . c o m setOutputMarkupId(true); final TextField<LayerInfo> rootLayerField = new TextField<LayerInfo>("rootLayer") { @Override public IConverter getConverter(Class<?> type) { return form.getConverter(type); } }; rootLayerField.setOutputMarkupId(true); rootLayerField.setRequired(true); add(rootLayerField); // global styles List<StyleInfo> globalStyles = new ArrayList<StyleInfo>(); List<StyleInfo> allStyles = GeoServerApplication.get().getCatalog().getStyles(); for (StyleInfo s : allStyles) { if (s.getWorkspace() == null) { globalStyles.add(s); } } // available styles List<StyleInfo> styles = new ArrayList<StyleInfo>(); styles.addAll(globalStyles); if (workspace != null) { styles.addAll(GeoServerApplication.get().getCatalog().getStylesByWorkspace(workspace)); } DropDownChoice<StyleInfo> styleField = new DropDownChoice<StyleInfo>("rootLayerStyle", styles) { @Override public IConverter getConverter(Class<?> type) { return form.getConverter(type); } }; styleField.setNullValid(true); add(styleField); final ModalWindow popupWindow = new ModalWindow("popup"); add(popupWindow); add(new AjaxLink("add") { @Override public void onClick(AjaxRequestTarget target) { popupWindow.setInitialHeight(375); popupWindow.setInitialWidth(525); popupWindow.setTitle(new ParamResourceModel("chooseLayer", this)); popupWindow.setContent(new LayerListPanel(popupWindow.getContentId()) { @Override protected void handleLayer(LayerInfo layer, AjaxRequestTarget target) { popupWindow.close(target); ((LayerGroupInfo) form.getModelObject()).setRootLayer(layer); target.addComponent(rootLayerField); } }); popupWindow.show(target); } }); }
From source file:org.geoserver.web.data.resource.FeatureResourceConfigurationPanel.java
License:Open Source License
public FeatureResourceConfigurationPanel(String id, final IModel model) { super(id, model); CheckBox circularArcs = new CheckBox("circularArcPresent"); add(circularArcs);//from ww w. j a va 2 s.c o m TextField<Measure> tolerance = new TextField<Measure>("linearizationTolerance", Measure.class); add(tolerance); attributePanel = new Fragment("attributePanel", "attributePanelFragment", this); attributePanel.setOutputMarkupId(true); add(attributePanel); // We need to use the resourcePool directly because we're playing with an edited // FeatureTypeInfo and the info.getFeatureType() and info.getAttributes() will hit // the resource pool without the modified properties (since it passes "this" into calls // to the ResourcePoool // just use the direct attributes, this is not editable atm attributes = new ListView("attributes", new AttributeListModel()) { @Override protected void populateItem(ListItem item) { // odd/even style item.add(new SimpleAttributeModifier("class", item.getIndex() % 2 == 0 ? "even" : "odd")); // dump the attribute information we have AttributeTypeInfo attribute = (AttributeTypeInfo) item.getModelObject(); item.add(new Label("name", attribute.getName())); item.add(new Label("minmax", attribute.getMinOccurs() + "/" + attribute.getMaxOccurs())); try { // working around a serialization issue FeatureTypeInfo typeInfo = (FeatureTypeInfo) model.getObject(); final ResourcePool resourcePool = GeoServerApplication.get().getCatalog().getResourcePool(); final FeatureType featureType = resourcePool.getFeatureType(typeInfo); org.opengis.feature.type.PropertyDescriptor pd = featureType.getDescriptor(attribute.getName()); String typeName = "?"; String nillable = "?"; try { typeName = pd.getType().getBinding().getSimpleName(); nillable = String.valueOf(pd.isNillable()); } catch (Exception e) { LOGGER.log(Level.INFO, "Could not find attribute " + attribute.getName() + " in feature type " + featureType, e); } item.add(new Label("type", typeName)); item.add(new Label("nillable", nillable)); } catch (IOException e) { item.add(new Label("type", "?")); item.add(new Label("nillable", "?")); } } }; attributePanel.add(attributes); TextArea<String> cqlFilter = new TextArea<String>("cqlFilter"); cqlFilter.add(new CqlFilterValidator(model)); add(cqlFilter); // reload links WebMarkupContainer reloadContainer = new WebMarkupContainer("reloadContainer"); attributePanel.add(reloadContainer); GeoServerAjaxFormLink reload = new GeoServerAjaxFormLink("reload") { @Override protected void onClick(AjaxRequestTarget target, Form form) { GeoServerApplication app = (GeoServerApplication) getApplication(); FeatureTypeInfo ft = (FeatureTypeInfo) getResourceInfo(); app.getCatalog().getResourcePool().clear(ft); app.getCatalog().getResourcePool().clear(ft.getStore()); target.addComponent(attributePanel); } }; reloadContainer.add(reload); GeoServerAjaxFormLink warning = new GeoServerAjaxFormLink("reloadWarning") { @Override protected void onClick(AjaxRequestTarget target, Form form) { reloadWarningDialog.show(target); } }; reloadContainer.add(warning); add(reloadWarningDialog = new ModalWindow("reloadWarningDialog")); reloadWarningDialog.setPageCreator(new ModalWindow.PageCreator() { public Page createPage() { return new ReloadWarningDialog(new StringResourceModel("featureTypeReloadWarning", FeatureResourceConfigurationPanel.this, null)); } }); reloadWarningDialog.setTitle(new StringResourceModel("warning", (Component) null, null)); reloadWarningDialog.setInitialHeight(100); reloadWarningDialog.setInitialHeight(200); // sql view handling WebMarkupContainer sqlViewContainer = new WebMarkupContainer("editSqlContainer"); attributePanel.add(sqlViewContainer); sqlViewContainer.add(new Link("editSql") { @Override public void onClick() { FeatureTypeInfo typeInfo = (FeatureTypeInfo) model.getObject(); try { setResponsePage(new SQLViewEditPage(typeInfo, ((ResourceConfigurationPage) this.getPage()))); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failure opening the sql view edit page", e); error(e.toString()); } } }); // which one do we show, reload or edit? FeatureTypeInfo typeInfo = (FeatureTypeInfo) model.getObject(); reloadContainer.setVisible( typeInfo.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, VirtualTable.class) == null); sqlViewContainer.setVisible(!reloadContainer.isVisible()); // Cascaded Stored Query WebMarkupContainer cascadedStoredQueryContainer = new WebMarkupContainer( "editCascadedStoredQueryContainer"); attributePanel.add(cascadedStoredQueryContainer); cascadedStoredQueryContainer.add(new Link("editCascadedStoredQuery") { @Override public void onClick() { FeatureTypeInfo typeInfo = (FeatureTypeInfo) model.getObject(); try { setResponsePage(new CascadedWFSStoredQueryEditPage(typeInfo, ((ResourceConfigurationPage) this.getPage()))); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failure opening the sql view edit page", e); error(e.toString()); } } }); cascadedStoredQueryContainer.setVisible(typeInfo.getMetadata() .get(FeatureTypeInfo.STORED_QUERY_CONFIGURATION, StoredQueryConfiguration.class) != null); }
From source file:org.geoserver.web.data.store.panel.FileParamPanel.java
License:Open Source License
/** * /* w w w . jav a 2 s .c om*/ * @param id * @param paramsMap * @param paramName * @param paramLabelModel * @param required * @param validators * any extra validator that should be added to the input field, or {@code null} */ public FileParamPanel(final String id, final IModel paramValue, final IModel paramLabelModel, final boolean required, IValidator... validators) { // make the value of the text field the model of this panel, for easy value retrieval super(id, paramValue); // add the dialog for the file chooser add(dialog = new ModalWindow("dialog")); // the label String requiredMark = required ? " *" : ""; Label label = new Label("paramName", paramLabelModel.getObject() + requiredMark); add(label); // the text field, with a decorator for validations textField = new TextField("paramValue", new FileModel(paramValue)); textField.setRequired(required); textField.setOutputMarkupId(true); // set the label to be the paramLabelModel otherwise a validation error would look like // "Parameter 'paramValue' is required" textField.setLabel(paramLabelModel); if (validators != null) { for (IValidator validator : validators) { textField.add(validator); } } FormComponentFeedbackBorder feedback = new FormComponentFeedbackBorder("border"); feedback.add(textField); feedback.add(chooserButton((String) paramLabelModel.getObject())); add(feedback); }
From source file:org.geoserver.web.data.store.StorePanel.java
License:Open Source License
public StorePanel(String id, StoreProvider provider, boolean selectable) { super(id, provider, selectable); // the popup window for messages popupWindow = new ModalWindow("popupWindow"); add(popupWindow);//from www . java 2s . co m }
From source file:org.geoserver.web.demo.DemoRequestsPage.java
License:Open Source License
private void setUpDemoRequestsForm(final File demoDir) { final IModel requestModel = getDefaultModel(); final Form demoRequestsForm; demoRequestsForm = new Form("demoRequestsForm"); demoRequestsForm.setOutputMarkupId(true); demoRequestsForm.setModel(requestModel); add(demoRequestsForm);/*from w ww .j a va2s . c o m*/ final List<String> demoList = getDemoList(demoDir); final DropDownChoice demoRequestsList; final IModel reqFileNameModel = new PropertyModel(requestModel, "requestFileName"); demoRequestsList = new DropDownChoice("demoRequestsList", reqFileNameModel, demoList, new IChoiceRenderer() { public String getIdValue(Object obj, int index) { return String.valueOf(obj); } public Object getDisplayValue(Object obj) { return obj; } }); demoRequestsForm.add(demoRequestsList); /* * Wanted to use a simpler OnChangeAjaxBehavior but target.addComponent(body) does not make * the EditAreaBehavior to update the body contents inside it, but instead puts the plain * TextArea contents above the empty xml editor */ demoRequestsList.add(new AjaxFormSubmitBehavior(demoRequestsForm, "onchange") { @Override protected void onSubmit(AjaxRequestTarget target) { final String reqFileName = demoRequestsList.getModelValue(); final String contents; String proxyBaseUrl; final String baseUrl; { WebRequest request = (WebRequest) DemoRequestsPage.this.getRequest(); HttpServletRequest httpServletRequest; httpServletRequest = ((WebRequest) request).getHttpServletRequest(); proxyBaseUrl = GeoServerExtensions.getProperty("PROXY_BASE_URL"); if (StringUtils.isEmpty(proxyBaseUrl)) { GeoServer gs = getGeoServer(); proxyBaseUrl = gs.getGlobal().getSettings().getProxyBaseUrl(); if (StringUtils.isEmpty(proxyBaseUrl)) { baseUrl = ResponseUtils.baseURL(httpServletRequest); } else { baseUrl = proxyBaseUrl; } } else { baseUrl = proxyBaseUrl; } } try { contents = getFileContents(reqFileName); } catch (IOException e) { LOGGER.log(Level.WARNING, "Can't load demo file " + reqFileName, e); throw new WicketRuntimeException("Can't load demo file " + reqFileName, e); } boolean demoRequestIsHttpGet = reqFileName.endsWith(".url"); final String service = reqFileName.substring(0, reqFileName.indexOf('_')).toLowerCase(); if (demoRequestIsHttpGet) { String url = ResponseUtils.appendPath(baseUrl, contents); urlTextField.setModelObject(url); body.setModelObject(""); } else { String serviceUrl = ResponseUtils.appendPath(baseUrl, service); urlTextField.setModelObject(serviceUrl); body.setModelObject(contents); } // target.addComponent(urlTextField); // target.addComponent(body); /* * Need to setResponsePage, addComponent causes the EditAreaBehavior to sometimes * not updating properly */ setResponsePage(DemoRequestsPage.this); } @Override protected void onError(AjaxRequestTarget target) { // nothing to do } }); urlTextField = new TextField("url", new PropertyModel(requestModel, "requestUrl")); urlTextField.setMarkupId("requestUrl"); urlTextField.setOutputMarkupId(true); demoRequestsForm.add(urlTextField); body = new CodeMirrorEditor("body", new PropertyModel(requestModel, "requestBody")); // force the id otherwise this blasted thing won't be usable from other forms // body.setMarkupId("requestBody"); // body.setOutputMarkupId(true); body.setTextAreaMarkupId("requestBody"); //body.add(new EditAreaBehavior()); demoRequestsForm.add(body); username = new TextField("username", new PropertyModel(requestModel, "userName")); demoRequestsForm.add(username); password = new PasswordTextField("password", new PropertyModel(requestModel, "password")); password.setRequired(false); demoRequestsForm.add(password); final ModalWindow responseWindow; responseWindow = new ModalWindow("responseWindow"); add(responseWindow); responseWindow.setPageMapName("demoResponse"); responseWindow.setCookieName("demoResponse"); responseWindow.setPageCreator(new ModalWindow.PageCreator() { public Page createPage() { return new DemoRequestResponse(requestModel); } }); demoRequestsForm.add(new AjaxSubmitLink("submit", demoRequestsForm) { @Override public void onSubmit(AjaxRequestTarget target, Form testWfsPostForm) { responseWindow.show(target); } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { // we need to force EditArea to update the textarea contents (which it hides) // before submitting the form, otherwise the contents won't be the ones the user // edited return new AjaxCallDecorator() { @Override public CharSequence decorateScript(CharSequence script) { return "document.getElementById('requestBody').value = document.gsEditors.requestBody.getValue();" + script; } }; } }); }
From source file:org.geoserver.web.demo.ReprojectPage.java
License:Open Source License
public ReprojectPage(PageParameters params) { if (params != null) { // get the params, if any sourceCRS = params.getString("fromSRS"); targetCRS = params.getString("toSRS"); }//from w ww. j ava 2 s . c o m // the popup for transformation details popupWindow = new ModalWindow("popup"); add(popupWindow); // the main form Form form = new Form("form"); add(form); // the source CRS CRSPanel sourcePanel = new CRSPanel("sourceCRS", new SRSToCRSModel(new PropertyModel(this, "sourceCRS"))) { protected void onSRSUpdated(String srs, AjaxRequestTarget target) { sourceCRS = srs; updateTransformation(target); }; }; sourcePanel.setRequired(true); form.add(sourcePanel); // the target CRS CRSPanel targetPanel = new CRSPanel("targetCRS", new SRSToCRSModel(new PropertyModel(this, "targetCRS"))) { protected void onSRSUpdated(String srs, AjaxRequestTarget target) { targetCRS = srs; updateTransformation(target); }; }; targetPanel.setRequired(true); form.add(targetPanel); // The link showing wktLink = new GeoServerAjaxFormLink("wkt", form) { @Override public void onClick(AjaxRequestTarget target, Form form) { popupWindow.setInitialHeight(525); popupWindow.setInitialWidth(525); popupWindow.setContent(new WKTPanel(popupWindow.getContentId())); popupWindow.setTitle(sourceCRS + " -> " + targetCRS); popupWindow.show(target); } }; wktLink.setEnabled(false); form.add(wktLink); sourceGeom = new GeometryTextArea("sourceGeom"); form.add(sourceGeom); sourceGeom.setOutputMarkupId(true); targetGeom = new GeometryTextArea("targetGeom"); targetGeom.setOutputMarkupId(true); form.add(targetGeom); AjaxSubmitLink forward = new AjaxSubmitLink("forward", form) { @Override protected void onSubmit(AjaxRequestTarget at, Form<?> form) { Geometry source = sourceGeom.getModelObject(); if (source == null) { error(getLocalizer().getString("ReprojectPage.sourcePointNotSpecifiedError", ReprojectPage.this, "Source Geometry is not specified")); } else { MathTransform mt = getTransform(); if (mt != null) { try { Geometry target = JTS.transform(source, mt); targetGeom.setModelObject(target); at.addComponent(targetGeom); } catch (Exception e) { error(e.getMessage()); } } } at.addComponent(feedbackPanel); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.addComponent(feedbackPanel); } }; form.add(forward); AjaxSubmitLink backward = new AjaxSubmitLink("backward", form) { @Override protected void onSubmit(AjaxRequestTarget at, Form<?> form) { Geometry target = targetGeom.getModelObject(); if (target == null) { error(getLocalizer().getString("ReprojectPage.targetPointNotSpecifiedError", ReprojectPage.this, "Target Geometry is not specified")); } else { MathTransform mt = getTransform(); if (mt != null) { try { Geometry source = JTS.transform(target, mt.inverse()); sourceGeom.setModelObject(source); at.addComponent(sourceGeom); } catch (Exception e) { error(e.getMessage()); } } } at.addComponent(feedbackPanel); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.addComponent(feedbackPanel); } }; form.add(backward); }
From source file:org.geoserver.web.importer.ImportSummaryPage.java
License:Open Source License
public ImportSummaryPage(final ImportSummary summary) { // the synthetic results IModel summaryMessage;//ww w. j a v a 2 s . co m Exception error = summary.getError(); if (error != null) { String errorSummary = error.getClass().getSimpleName() + ", " + error.getMessage(); summaryMessage = new ParamResourceModel("summaryError", this, errorSummary); } else if (summary.getProcessedLayers() == 0) { summaryMessage = new ParamResourceModel("summaryCancelled", this); // no undo link in this case add(new Label("undo", "")); } else { if (summary.getFailures() > 0) { if (summary.isCompleted()) { summaryMessage = new ParamResourceModel("summaryFailures", this, summary.getProcessedLayers(), summary.getProject(), summary.getFailures()); } else { summaryMessage = new ParamResourceModel("summaryPartialFailures", this, summary.getProcessedLayers(), summary.getProject(), summary.getFailures()); } } else { if (summary.isCompleted()) { summaryMessage = new ParamResourceModel("summarySuccess", this, summary.getProcessedLayers(), summary.getProject()); } else { summaryMessage = new ParamResourceModel("summaryPartialSuccess", this, summary.getProcessedLayers(), summary.getProject(), summary.getFailures()); } } // show undo link add(undoLink(summary)); } add(new Label("summary", summaryMessage)); // the popup window popupWindow = new ModalWindow("popup"); add(popupWindow); // the declare SRS link declareSRSLink = popupLink("declareSRS", new ParamResourceModel("declareSRS", this), srsListSelectionPanel()); declareSRSLink.getLink().setEnabled(false); declareSRSLink.setOutputMarkupId(true); add(declareSRSLink); // the list of imported layers ImportSummaryProvider provider = new ImportSummaryProvider(summary.getLayers()); summaryTable = new GeoServerTablePanel<LayerSummary>("importSummary", provider, true) { @Override protected Component getComponentForProperty(String id, IModel itemModel, Property<LayerSummary> property) { final LayerSummary layerSummary = (LayerSummary) itemModel.getObject(); final CatalogIconFactory icons = CatalogIconFactory.get(); LayerInfo layer = layerSummary.getLayer(); if (property == LAYER) { Fragment f = new Fragment(id, "edit", ImportSummaryPage.this); // keep the last modified name if possible IModel label; if (layerSummary.getLayer() != null) label = new Model(layerSummary.getLayer().getName()); else label = new Model(layerSummary.getLayerName()); // build the edit link Link editLink = editLink(layerSummary, label); editLink.setEnabled(layer != null); // also set a tooltip explaining what this action does editLink.add(new AttributeModifier("title", true, new ParamResourceModel("edit", this, label.getObject()))); f.add(editLink); return f; } else if (property == TYPE) { if (layer != null) { // show icon type or an error icon if anything went wrong ResourceReference icon; IModel title = new Model(getTypeTooltip(layer)); if (layerSummary.getStatus().successful()) { icon = icons.getSpecificLayerIcon(layer); title = new Model(getTypeTooltip(layer)); } else { icon = icons.getDisabledIcon(); title = ISSUES.getModel(itemModel); } Fragment f = new Fragment(id, "iconFragment", ImportSummaryPage.this); Image image = new Image("icon", icon); image.add(new AttributeModifier("title", true, title)); image.add(new AttributeModifier("alt", true, title)); f.add(image); return f; } else { // no icon, no description return new Label(id, ""); } } else if (property == ISSUES) { if (layerSummary.getStatus() != ImportStatus.NO_SRS_MATCH) { return new Label(id, property.getModel(itemModel)); } else { Fragment f = new Fragment(id, "noSRSMatch", ImportSummaryPage.this); f.add(new Label("issue", property.getModel(itemModel))); f.add(getLayerWKTLink(itemModel)); return f; } } else if (property == SRS) { if (layerSummary.getStatus().successful()) { return new Label(id, property.getModel(itemModel)); } else if (layerSummary.getStatus() == ImportStatus.MISSING_NATIVE_CRS || layerSummary.getStatus() == ImportStatus.NO_SRS_MATCH) { return popupLink(id, new ParamResourceModel("declareSRS", this), srsListLayerPanel(itemModel)); } else { Fragment f = new Fragment(id, "edit", ImportSummaryPage.this); // build the edit link Link editLink = editLink(layerSummary, new ParamResourceModel("directFix", this)); editLink.setEnabled(layer != null); f.add(editLink); } } else if (property == COMMANDS) { boolean geometryless = false; ResourceInfo resource = layerSummary.getLayer().getResource(); if (resource instanceof FeatureTypeInfo) { try { FeatureType featureType = ((FeatureTypeInfo) resource).getFeatureType(); geometryless = featureType.getGeometryDescriptor() == null; } catch (Exception e) { geometryless = true; } } if (layerSummary.getStatus().successful() && !geometryless) { Fragment f = new Fragment(id, "preview", ImportSummaryPage.this); PreviewLayer preview = new PreviewLayer(layer); f.add(new ExternalLink("ol", preview.getWmsLink() + "&format=application/openlayers")); f.add(new ExternalLink("ge", "../wms/kml?layers=" + layer.getName())); f.add(new ExternalLink("styler", "/styler/index.html?layer=" + urlEncode( layer.getResource().getStore().getWorkspace().getName() + ":" + layer.getName()))); return f; } else { return new Label(id, ""); } } return null; } @Override protected void onSelectionUpdate(AjaxRequestTarget target) { declareSRSLink.getLink().setEnabled(getSelection().size() > 0); target.addComponent(declareSRSLink); } }; summaryTable.setOutputMarkupId(true); summaryTable.setFilterable(false); add(summaryTable); }
From source file:org.geoserver.web.wicket.CRSPanel.java
License:Open Source License
void initComponents() { popupWindow = new ModalWindow("popup"); add(popupWindow);/*from ww w .j a v a 2 s. c o m*/ srsTextField = new TextField("srs", new Model()); add(srsTextField); srsTextField.setOutputMarkupId(true); srsTextField.add(new AjaxFormComponentUpdatingBehavior("onblur") { @Override protected void onUpdate(AjaxRequestTarget target) { convertInput(); CoordinateReferenceSystem crs = (CoordinateReferenceSystem) getConvertedInput(); if (crs != null) { setModelObject(crs); wktLabel.setDefaultModelObject(crs.getName().toString()); wktLink.setEnabled(true); } else { wktLabel.setDefaultModelObject(null); wktLink.setEnabled(false); } target.addComponent(wktLink); onSRSUpdated(toSRS(crs), target); } }); findLink = new AjaxLink("find") { @Override public void onClick(AjaxRequestTarget target) { popupWindow.setContent(srsListPanel()); popupWindow.setTitle(new ParamResourceModel("selectSRS", CRSPanel.this)); popupWindow.show(target); } }; add(findLink); wktLink = new GeoServerAjaxFormLink("wkt") { @Override public void onClick(AjaxRequestTarget target, Form form) { popupWindow.setInitialHeight(375); popupWindow.setInitialWidth(525); popupWindow.setContent(new WKTPanel(popupWindow.getContentId(), getCRS())); CoordinateReferenceSystem crs = (CoordinateReferenceSystem) CRSPanel.this.getModelObject(); if (crs != null) popupWindow.setTitle(crs.getName().toString()); popupWindow.show(target); } }; wktLink.setEnabled(getModelObject() != null); add(wktLink); wktLabel = new Label("wktLabel", new Model()); wktLink.add(wktLabel); wktLabel.setOutputMarkupId(true); }
From source file:org.geoserver.web.wicket.GeoServerDialog.java
License:Open Source License
public GeoServerDialog(String id) { super(id); add(window = new ModalWindow("dialog")); }
From source file:org.geoserver.wms.eo.web.EoLayerGroupAbstractPage.java
License:Open Source License
/** * Subclasses must call this method to initialize the UI for this page * @param layerGroup//from w w w . j a v a 2s .c om */ protected void initUI(LayerGroupInfo layerGroup) { this.returnPageClass = EoLayerGroupPage.class; lgModel = new LayerGroupDetachableModel(layerGroup); layerGroupId = layerGroup.getId(); add(popupWindow = new ModalWindow("popup")); add(dialog = new GeoServerDialog("dialog")); Form form = new Form("form", new CompoundPropertyModel(lgModel)) { @Override public IConverter getConverter(Class<?> type) { if (LayerInfo.class.isAssignableFrom(type)) { return new LayerInfoConverter(); } else if (StyleInfo.class.isAssignableFrom(type)) { return new StyleInfoConverter(); } else { return super.getConverter(type); } } }; add(form); name = new TextField<String>("name"); name.setRequired(true); groupName = layerGroup.getName(); form.add(name); form.add(new TextField("title")); form.add(new TextArea("abstract")); final DropDownChoice<WorkspaceInfo> wsChoice = new DropDownChoice("workspace", new WorkspacesModel(), new WorkspaceChoiceRenderer()); wsChoice.setNullValid(true); if (!isAuthenticatedAsAdmin()) { wsChoice.setNullValid(false); wsChoice.setRequired(true); } form.add(wsChoice); //bounding box form.add(envelopePanel = new EnvelopePanel("bounds")/*.setReadOnly(true)*/); envelopePanel.setRequired(true); envelopePanel.setCRSFieldVisible(true); envelopePanel.setCrsRequired(true); envelopePanel.setOutputMarkupId(true); form.add(new GeoServerAjaxFormLink("generateBounds") { @Override public void onClick(AjaxRequestTarget target, Form form) { // build a layer group with the current contents of the group LayerGroupInfo lg = getCatalog().getFactory().createLayerGroup(); for (EoLayerGroupEntry entry : lgEntryPanel.getEntries()) { lg.getLayers().add(entry.getLayer()); lg.getStyles().add(entry.getStyle()); } try { // grab the eventually manually inserted CoordinateReferenceSystem crs = envelopePanel.getCoordinateReferenceSystem(); if (crs != null) { //ensure the bounds calculated in terms of the user specified crs new CatalogBuilder(getCatalog()).calculateLayerGroupBounds(lg, crs); } else { //calculate from scratch new CatalogBuilder(getCatalog()).calculateLayerGroupBounds(lg); } envelopePanel.setModelObject(lg.getBounds()); target.addComponent(envelopePanel); } catch (Exception e) { throw new WicketRuntimeException(e); } } }); form.add(lgEntryPanel = new EoLayerGroupEntryPanel("layers", layerGroup, popupWindow)); lgEntryPanel.setOutputMarkupId(true); EoLayerTypeRenderer eoLayerTypeRenderer = new EoLayerTypeRenderer(); final DropDownChoice<EoLayerType> layerTypes = new DropDownChoice<EoLayerType>("layerType", EoLayerType.getRegularTypes(), eoLayerTypeRenderer); layerTypes.setModel(new Model<EoLayerType>(null)); layerTypes.setOutputMarkupId(true); form.add(layerTypes); final GeoServerAjaxFormLink createStoreLink = new GeoServerAjaxFormLink("createStore") { @Override public void onClick(AjaxRequestTarget target, Form form) { final String layerGroupName = getNonNullGroupName(target); if (layerGroupName != null) { CoverageStoreNewPage coverageStoreCreator = new CoverageStoreNewPage( new ImageMosaicFormat().getName()) { protected void onSuccessfulSave(org.geoserver.catalog.CoverageStoreInfo info, org.geoserver.catalog.Catalog catalog, org.geoserver.catalog.CoverageStoreInfo savedStore) { EoCoverageSelectorPage page = new EoCoverageSelectorPage(EoLayerGroupAbstractPage.this, layerGroupName, savedStore.getId()); setResponsePage(page); }; }; setResponsePage(coverageStoreCreator); } else { dialog.showInfo(target, null, new ParamResourceModel("layerInfoTitle", EoLayerGroupAbstractPage.this), new ParamResourceModel("provideGroupName", EoLayerGroupAbstractPage.this)); } } }; createStoreLink.setOutputMarkupId(true); form.add(createStoreLink); final GeoServerAjaxFormLink addFromStoreLink = new GeoServerAjaxFormLink("addFromStore") { @Override public void onClick(AjaxRequestTarget target, Form form) { final String layerGroupName = getNonNullGroupName(target); if (layerGroupName != null) { EoCoverageSelectorPage page = new EoCoverageSelectorPage(EoLayerGroupAbstractPage.this, layerGroupName); setResponsePage(page); } else { dialog.showInfo(target, null, new ParamResourceModel("layerInfoTitle", EoLayerGroupAbstractPage.this), new ParamResourceModel("provideGroupName", EoLayerGroupAbstractPage.this)); } } }; addFromStoreLink.setOutputMarkupId(true); form.add(addFromStoreLink); final GeoServerAjaxFormLink addLayerLink = new GeoServerAjaxFormLink("addLayer") { @Override public void onClick(AjaxRequestTarget target, Form form) { popupWindow.setInitialHeight(375); popupWindow.setInitialWidth(525); popupWindow.setTitle(new ParamResourceModel("chooseLayer", this)); layerTypes.processInput(); final EoLayerType layerType = layerTypes.getModelObject(); popupWindow.setContent( new EoLayerListPanel(popupWindow.getContentId(), layerType, lgEntryPanel.entryProvider) { @Override protected void handleLayer(LayerInfo layer, AjaxRequestTarget target) { popupWindow.close(target); layer.getMetadata().put(EoLayerType.KEY, layerType); lgEntryPanel.entryProvider.getItems() .add(new EoLayerGroupEntry(layer, layer.getDefaultStyle(), groupName)); target.addComponent(lgEntryPanel); layerTypes.setDefaultModelObject(layerTypes.getDefaultModelObject()); target.addComponent(layerTypes); } }); popupWindow.show(target); } }; addLayerLink.setEnabled(false); form.add(addLayerLink); final DropDownChoice<EoLayerGroupEntry> outlinesEntryChooser = new DropDownChoice<EoLayerGroupEntry>( "sourceLayer", new OutlineSourceModel(lgEntryPanel.items), new LayerGroupEntryRenderer()); outlinesEntryChooser.setModel(new Model<EoLayerGroupEntry>(null)); outlinesEntryChooser.setOutputMarkupId(true); outlinesEntryChooser.setEnabled(!outlinesPresent(lgEntryPanel.items)); form.add(outlinesEntryChooser); outlinesEntryChooser.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { wsChoice.processInput(); WorkspaceInfo ws = (WorkspaceInfo) wsChoice.getDefaultModelObject(); outlinesEntryChooser.processInput(); EoLayerGroupEntry entry = outlinesEntryChooser.getModelObject(); try { EoCatalogBuilder builder = new EoCatalogBuilder(getCatalog()); CoverageInfo coverage = (CoverageInfo) ((LayerInfo) entry.getLayer()).getResource(); CoverageStoreInfo store = coverage.getStore(); String url = store.getURL(); StructuredGridCoverage2DReader reader = (StructuredGridCoverage2DReader) coverage .getGridCoverageReader(null, null); LayerInfo layer = builder.createEoOutlineLayer(url, ws, groupName, coverage.getNativeCoverageName(), reader); lgEntryPanel.items.add(new EoLayerGroupEntry(layer, layer.getDefaultStyle(), groupName)); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to create outlines layer", e); String layerName = entry.getLayer().prefixedName(); error(new ParamResourceModel("outlinesCreationError", EoLayerGroupAbstractPage.this, layerName, e.getMessage()).getString()); } finally { outlinesEntryChooser.setDefaultModelObject(null); } target.addComponent(lgEntryPanel); target.addComponent(getFeedbackPanel()); target.addComponent(outlinesEntryChooser); } }); layerTypes.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { layerTypes.processInput(); boolean input = layerTypes.getModelObject() != null; addLayerLink.setEnabled(input); target.addComponent(addLayerLink); } }); name.add(new AjaxFormComponentUpdatingBehavior("onblur") { @Override protected void onUpdate(AjaxRequestTarget target) { groupName = name.getInput(); boolean nameAvailable = groupName != null && !"".equals(groupName.trim()); if (!nameAvailable) { info(new ParamResourceModel("provideGroupName", EoLayerGroupAbstractPage.this).getString()); } else { // inform the user about possible layer renames if (isLayerRenameRequired(groupName)) { info(new ParamResourceModel("layerRenameWarning", EoLayerGroupAbstractPage.this, groupName) .getString()); } } target.addComponent(createStoreLink); target.addComponent(addFromStoreLink); target.addComponent(getFeedbackPanel()); } }); if (name.getDefaultModelObject() == null || "".equals(name.getDefaultModelObject())) { info(new ParamResourceModel("provideGroupName", this).getString()); } form.add(saveLink()); form.add(cancelLink()); }