List of usage examples for org.apache.wicket Component setDefaultModel
public Component setDefaultModel(final IModel<?> model)
From source file:com.evolveum.midpoint.web.component.util.FutureUpdateBehavior.java
License:Apache License
@Override protected void onTimer(final AjaxRequestTarget target) { if (future == null || !future.isDone()) { return;/* w ww .ja va2 s.com*/ } try { T data = future.get(); Component component = getComponent(); if (component instanceof BaseSimplePanel) { BaseSimplePanel<T> panel = (BaseSimplePanel<T>) component; panel.getModel().setObject(data); } else { if (component.getDefaultModel() == null) { component.setDefaultModel(new Model()); } component.setDefaultModelObject(data); } stop(target); onPostSuccess(target); } catch (InterruptedException ex) { handleError(ex, target); } catch (ExecutionException ex) { handleError(ex, target); } }
From source file:com.mycompany.RunAwayTextPage.java
License:Apache License
private AjaxEventBehavior getEventBehavior(final Component updateComponent) { return new AjaxEventBehavior("onMouseOver") { @Override// w ww. j a v a 2s .c om protected void onEvent(AjaxRequestTarget target) { this.getComponent().setDefaultModel(new Model<String>("")); this.getComponent().remove(this); String nextId = getNextId(this.getComponent().getId()); Component nextComponent = RunAwayTextPage.this.get("updateComponent").get(nextId); nextComponent.add(getEventBehavior(updateComponent)); nextComponent.setDefaultModel(new Model<String>("?")); target.add(updateComponent); } }; }
From source file:com.mycompany.RunAwayTextPage.java
License:Apache License
private AjaxEventBehavior getRollEvent() { return new AjaxEventBehavior("onMouseOver") { @Override//from ww w . j a v a 2 s .c o m protected void onEvent(AjaxRequestTarget target) { Component comp = this.getComponent(); comp.remove(this); comp.add(new AbstractAjaxTimerBehavior(Duration.milliseconds(20)) { @Override protected void onTimer(AjaxRequestTarget target) { Component comp = this.getComponent(); comp.setDefaultModel(new Model<String>(view.get(part))); part++; if (view.size() <= part) { stop(); part = 0; comp.remove(this); comp.add(getRollEvent()); } target.add(comp); } }); target.add(comp); } }; }
From source file:org.apache.isis.viewer.wicket.ui.components.collectioncontents.multiple.CollectionContentsMultipleViewsPanel.java
License:Apache License
@Override public void onEvent(IEvent<?> event) { super.onEvent(event); final IsisSelectorEvent selectorEvent = IsisEnvelopeEvent.openLetter(event, IsisSelectorEvent.class); if (selectorEvent == null) { return;//w w w . j a v a 2 s. c om } final CollectionSelectorPanel selectorDropdownPanel = CollectionSelectorProvider.Util .getCollectionSelectorProvider(this); if (selectorDropdownPanel == null) { // not expected, because this event shouldn't be called. // but no harm in simply returning... return; } String selectedView = selectorEvent.hintFor(selectorDropdownPanel, UIHINT_VIEW); if (selectedView == null) { return; } int underlyingViewNum = selectorHelper.lookup(selectedView); final EntityCollectionModel dummyModel = getModel().asDummy(); for (int i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) { final Component component = underlyingViews[i]; if (component == null) { continue; } final boolean isSelected = i == underlyingViewNum; applyCssVisibility(component, isSelected); component.setDefaultModel(isSelected ? getModel() : dummyModel); } this.selectedComponent = underlyingViews[underlyingViewNum]; final AjaxRequestTarget target = selectorEvent.getTarget(); if (target != null) { target.add(this, selectorDropdownPanel); } }
From source file:org.apache.isis.viewer.wicket.ui.components.entity.selector.links.EntityLinksSelectorPanel.java
License:Apache License
private void addUnderlyingViews(final String underlyingIdPrefix, final EntityModel model, final ComponentFactory factory) { final List<ComponentFactory> componentFactories = findOtherComponentFactories(model, factory); final int selected = honourViewHintElseDefault(componentFactories, model); final EntityLinksSelectorPanel selectorPanel = this; // create all, hide the one not selected final Component[] underlyingViews = new Component[MAX_NUM_UNDERLYING_VIEWS]; int i = 0;/*from w w w .j a v a 2s .c o m*/ final EntityModel emptyModel = dummyOf(model); for (ComponentFactory componentFactory : componentFactories) { final String underlyingId = underlyingIdPrefix + "-" + i; Component underlyingView = componentFactory.createComponent(underlyingId, i == selected ? model : emptyModel); underlyingViews[i++] = underlyingView; selectorPanel.addOrReplace(underlyingView); } // hide any unused placeholders while (i < MAX_NUM_UNDERLYING_VIEWS) { String underlyingId = underlyingIdPrefix + "-" + i; permanentlyHide(underlyingId); i++; } // selector if (componentFactories.size() <= 1) { permanentlyHide(ID_VIEWS); } else { final Model<ComponentFactory> componentFactoryModel = new Model<>(); selectorPanel.selectedComponentFactory = componentFactories.get(selected); componentFactoryModel.setObject(selectorPanel.selectedComponentFactory); final WebMarkupContainer views = new WebMarkupContainer(ID_VIEWS); final Label viewButtonTitle = new Label(ID_VIEW_BUTTON_TITLE, "Hidden"); views.addOrReplace(viewButtonTitle); final Label viewButtonIcon = new Label(ID_VIEW_BUTTON_ICON, ""); views.addOrReplace(viewButtonIcon); final WebMarkupContainer container = new WebMarkupContainer(ID_VIEW_LIST); views.addOrReplace(container); views.setOutputMarkupId(true); this.setOutputMarkupId(true); final ListView<ComponentFactory> listView = new ListView<ComponentFactory>(ID_VIEW_ITEM, componentFactories) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<ComponentFactory> item) { final int underlyingViewNum = item.getIndex(); final ComponentFactory componentFactory = item.getModelObject(); final AbstractLink link = new AjaxLink<Void>(ID_VIEW_LINK) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { EntityLinksSelectorPanel linksSelectorPanel = EntityLinksSelectorPanel.this; linksSelectorPanel.setViewHintAndBroadcast(underlyingViewNum, target); final EntityModel dummyModel = dummyOf(model); for (int i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) { final Component component = underlyingViews[i]; if (component == null) { continue; } final boolean isSelected = i == underlyingViewNum; applyCssVisibility(component, isSelected); component.setDefaultModel(isSelected ? model : dummyModel); } selectorPanel.selectedComponentFactory = componentFactory; selectorPanel.selectedComponent = underlyingViews[underlyingViewNum]; selectorPanel.onSelect(target); target.add(selectorPanel, views); } @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); Buttons.fixDisabledState(this, tag); } }; IModel<String> title = nameFor(componentFactory); Label viewItemTitleLabel = new Label(ID_VIEW_ITEM_TITLE, title); link.add(viewItemTitleLabel); Label viewItemIcon = new Label(ID_VIEW_ITEM_ICON, ""); link.add(viewItemIcon); boolean isEnabled = componentFactory != selectorPanel.selectedComponentFactory; if (!isEnabled) { viewButtonTitle.setDefaultModel(title); IModel<String> cssClass = cssClassFor(componentFactory, viewButtonIcon); viewButtonIcon .add(AttributeModifier.replace("class", "ViewLinkItem " + cssClass.getObject())); link.setVisible(false); } else { IModel<String> cssClass = cssClassFor(componentFactory, viewItemIcon); viewItemIcon.add(new CssClassAppender(cssClass)); } item.add(link); } private IModel<String> cssClassFor(final ComponentFactory componentFactory, Label viewIcon) { IModel<String> cssClass = null; if (componentFactory instanceof CollectionContentsAsFactory) { CollectionContentsAsFactory collectionContentsAsFactory = (CollectionContentsAsFactory) componentFactory; cssClass = collectionContentsAsFactory.getCssClass(); viewIcon.setDefaultModelObject(""); viewIcon.setEscapeModelStrings(true); } if (cssClass == null) { String name = componentFactory.getName(); cssClass = Model.of(StringExtensions.asLowerDashed(name)); // Small hack: if there is no specific CSS class then we assume that background-image is used // the span.ViewItemLink should have some content to show it // FIX: find a way to do this with CSS (width and height don't seems to help) viewIcon.setDefaultModelObject("     "); viewIcon.setEscapeModelStrings(false); } return cssClass; } private IModel<String> nameFor(final ComponentFactory componentFactory) { IModel<String> name = null; if (componentFactory instanceof CollectionContentsAsFactory) { CollectionContentsAsFactory collectionContentsAsFactory = (CollectionContentsAsFactory) componentFactory; name = collectionContentsAsFactory.getTitleLabel(); } if (name == null) { name = Model.of(componentFactory.getName()); } return name; } }; container.add(listView); addOrReplace(views); } for (i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) { Component component = underlyingViews[i]; if (component != null) { if (i != selected) { component.add(new CssClassAppender(INVISIBLE_CLASS)); } else { selectedComponent = component; } } } }
From source file:org.apache.isis.viewer.wicket.ui.selector.links.LinksSelectorPanelAbstract.java
License:Apache License
private void addUnderlyingViews(final String underlyingIdPrefix, final T model, final ComponentFactory factory) { final List<ComponentFactory> componentFactories = findOtherComponentFactories(model, factory); final int selected = determineInitialFactory(componentFactories, model); final LinksSelectorPanelAbstract<T> selectorPanel = LinksSelectorPanelAbstract.this; // create all, hide the one not selected final Component[] underlyingViews = new Component[MAX_NUM_UNDERLYING_VIEWS]; int i = 0;/*from ww w. j ava 2 s . c o m*/ final T emptyModel = dummyOf(model); for (ComponentFactory componentFactory : componentFactories) { final String underlyingId = underlyingIdPrefix + "-" + i; Component underlyingView = componentFactory.createComponent(underlyingId, i == selected ? model : emptyModel); underlyingViews[i++] = underlyingView; selectorPanel.addOrReplace(underlyingView); } // hide any unused placeholders while (i < MAX_NUM_UNDERLYING_VIEWS) { String underlyingId = underlyingIdPrefix + "-" + i; permanentlyHide(underlyingId); i++; } // selector if (componentFactories.size() <= 1) { permanentlyHide(ID_VIEWS); } else { final Model<ComponentFactory> componentFactoryModel = new Model<ComponentFactory>(); selectorPanel.selectedComponentFactory = componentFactories.get(selected); componentFactoryModel.setObject(selectorPanel.selectedComponentFactory); final WebMarkupContainer views = new WebMarkupContainer(ID_VIEWS); final WebMarkupContainer container = new WebMarkupContainer(ID_VIEW_LIST); views.addOrReplace(container); views.setOutputMarkupId(true); this.setOutputMarkupId(true); final ListView<ComponentFactory> listView = new ListView<ComponentFactory>(ID_VIEW_ITEM, componentFactories) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<ComponentFactory> item) { final int underlyingViewNum = item.getIndex(); final ComponentFactory componentFactory = item.getModelObject(); final AbstractLink link = new AjaxLink<Void>(ID_VIEW_LINK) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { final T dummyModel = dummyOf(model); for (int i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) { final Component component = underlyingViews[i]; if (component == null) { continue; } final boolean isSelected = i == underlyingViewNum; applyCssVisibility(component, isSelected); component.setDefaultModel(isSelected ? model : dummyModel); } selectorPanel.selectedComponentFactory = componentFactory; selectorPanel.selectedComponent = underlyingViews[underlyingViewNum]; selectorPanel.onSelect(target); target.add(selectorPanel, views); } }; String name = nameFor(componentFactory); Label viewTitleLabel = new Label(ID_VIEW_TITLE, name); viewTitleLabel.add(new CssClassAppender(StringExtensions.asLowerDashed(name))); link.add(viewTitleLabel); item.add(link); link.setEnabled(componentFactory != selectorPanel.selectedComponentFactory); } private String nameFor(final ComponentFactory componentFactory) { return componentFactory instanceof CollectionContentsAsUnresolvedPanelFactory ? "hide" : componentFactory.getName(); } }; container.add(listView); addOrReplace(views); } for (i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) { Component component = underlyingViews[i]; if (component != null) { if (i != selected) { component.add(new AttributeAppender("class", " " + INVISIBLE_CLASS)); } else { selectedComponent = component; } } } }
From source file:org.geoserver.gwc.web.gridset.TileMatrixSetEditor.java
License:Open Source License
/** * @param id//from ww w. jav a2 s . c om * @param model * the model over the appropriate list of {@link Grid} * @see WMSInfo#getAuthorityURLs() * @see LayerInfo#getAuthorityURLs() * @see LayerGroupInfo#getAuthorityURLs() */ public TileMatrixSetEditor(final String id, final IModel<GridSetInfo> info) { super(id, new PropertyModel<List<Grid>>(info, "levels")); add(new TileMatrixSetValidator()); final IModel<List<Grid>> list = getModel(); checkNotNull(list.getObject()); this.info = info; this.readOnly = info.getObject().isInternal(); // container for ajax updates final WebMarkupContainer container = new WebMarkupContainer("container"); container.setOutputMarkupId(true); add(container); final IModel<Boolean> preserveesolutionsModel = new PropertyModel<Boolean>(info, "resolutionsPreserved"); final RadioGroup<Boolean> resolutionsOrScales = new RadioGroup<Boolean>("useResolutionsOrScalesGroup", preserveesolutionsModel); container.add(resolutionsOrScales); Radio<Boolean> preserveResolutions = new Radio<Boolean>("preserveResolutions", new Model<Boolean>(Boolean.TRUE)); Radio<Boolean> preserveScales = new Radio<Boolean>("preserveScales", new Model<Boolean>(Boolean.FALSE)); resolutionsOrScales.add(preserveResolutions); resolutionsOrScales.add(preserveScales); // update the table when this option changes so either the resolutions or scales column is // enabled resolutionsOrScales.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { resolutionsOrScales.processInput(); final boolean useResolutions = resolutionsOrScales.getModelObject().booleanValue(); Iterator<? extends ListItem<Grid>> iterator = grids.iterator(); while (iterator.hasNext()) { ListItem<Grid> next = iterator.next(); next.get("resolution").setEnabled(useResolutions); next.get("scale").setEnabled(!useResolutions); } target.addComponent(table); } }); // the link list table = new WebMarkupContainer("table"); table.setOutputMarkupId(true); table.add(thLabel("level")); table.add(thLabel("resolution")); table.add(thLabel("scale")); table.add(thLabel("name")); table.add(thLabel("tiles")); container.add(table); grids = new ListView<Grid>("gridLevels", new ArrayList<Grid>(list.getObject())) { private static final long serialVersionUID = 1L; @Override protected void onBeforeRender() { super.onBeforeRender(); } @Override protected void populateItem(final ListItem<Grid> item) { // odd/even style final int index = item.getIndex(); item.add(new SimpleAttributeModifier("class", index % 2 == 0 ? "even" : "odd")); item.add(new Label("zoomLevel", String.valueOf(index))); final TextField<Double> resolution; final TextField<Double> scale; final TextField<String> name; final Label tiles; final Component removeLink; resolution = new DecimalTextField("resolution", new PropertyModel<Double>(item.getModel(), "resolution")); resolution.setOutputMarkupId(true); item.add(resolution); scale = new DecimalTextField("scale", new PropertyModel<Double>(item.getModel(), "scaleDenom")); scale.setOutputMarkupId(true); item.add(scale); name = new TextField<String>("name", new PropertyModel<String>(item.getModel(), "name")); item.add(name); IModel<String> tilesModel = new IModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { // resolution.processInput(); Double res = resolution.getModelObject(); GridSetInfo gridSetInfo = TileMatrixSetEditor.this.info.getObject(); final ReferencedEnvelope extent = gridSetInfo.getBounds(); if (res == null || extent == null) { return "--"; } final int tileWidth = gridSetInfo.getTileWidth(); final int tileHeight = gridSetInfo.getTileHeight(); final double mapUnitWidth = tileWidth * res.doubleValue(); final double mapUnitHeight = tileHeight * res.doubleValue(); final long tilesWide = (long) Math .ceil((extent.getWidth() - mapUnitWidth * 0.01) / mapUnitWidth); final long tilesHigh = (long) Math .ceil((extent.getHeight() - mapUnitHeight * 0.01) / mapUnitHeight); NumberFormat nf = NumberFormat.getIntegerInstance();// so it shows grouping // for large numbers String tilesStr = nf.format(tilesWide) + " x " + nf.format(tilesHigh); return tilesStr; } @Override public void detach() { // } @Override public void setObject(String object) { // } }; tiles = new Label("tiles", tilesModel); tiles.setOutputMarkupId(true); item.add(tiles); // remove link if (TileMatrixSetEditor.this.readOnly) { removeLink = new Label("removeLink", ""); } else { removeLink = new ImageAjaxLink("removeLink", GWCIconFactory.DELETE_ICON) { private static final long serialVersionUID = 1L; @Override protected void onClick(AjaxRequestTarget target) { List<Grid> list = new ArrayList<Grid>(grids.getModelObject()); int index = ((Integer) getDefaultModelObject()).intValue(); list.remove(index); grids.setModelObject(list); target.addComponent(container); } }; removeLink.setDefaultModel(new Model<Integer>(Integer.valueOf(index))); removeLink.add(new AttributeModifier("title", true, new ResourceModel("TileMatrixSetEditor.removeLink"))); } item.add(removeLink); final boolean isResolutionsPreserved = preserveesolutionsModel.getObject(); resolution.setEnabled(isResolutionsPreserved); scale.setEnabled(!isResolutionsPreserved); resolution.add(new AjaxFormComponentUpdatingBehavior("onblur") { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { resolution.processInput(); Double res = resolution.getModelObject(); Double scaleDenominator = null; if (null != res) { GridSetInfo gridSetInfo = TileMatrixSetEditor.this.info.getObject(); Double metersPerUnit = gridSetInfo.getMetersPerUnit(); if (metersPerUnit != null) { scaleDenominator = res.doubleValue() * metersPerUnit.doubleValue() / GridSetFactory.DEFAULT_PIXEL_SIZE_METER; } } scale.setModelObject(scaleDenominator); target.addComponent(resolution); target.addComponent(scale); target.addComponent(tiles); } }); scale.add(new AjaxFormComponentUpdatingBehavior("onblur") { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { scale.processInput(); final Double scaleDenominator = scale.getModelObject(); Double res = null; if (null != scaleDenominator) { GridSetInfo gridSetInfo = TileMatrixSetEditor.this.info.getObject(); final double pixelSize = gridSetInfo.getPixelSize(); Double metersPerUnit = gridSetInfo.getMetersPerUnit(); if (metersPerUnit != null) { res = pixelSize * scaleDenominator / metersPerUnit; } } resolution.setModelObject(res); target.addComponent(resolution); target.addComponent(scale); target.addComponent(tiles); } }); } }; grids.setOutputMarkupId(true); // this is necessary to avoid loosing item contents on edit/validation checks grids.setReuseItems(true); table.add(grids); }
From source file:org.geoserver.gwc.web.layer.GridSubsetsEditor.java
License:Open Source License
public GridSubsetsEditor(final String id, final IModel<Set<XMLGridSubset>> model) { super(id, model); add(validator = new GridSubsetListValidator()); // container for ajax updates final WebMarkupContainer container = new WebMarkupContainer("container"); container.setOutputMarkupId(true);/*from w w w . j av a2s. c o m*/ add(container); // the link list table = new WebMarkupContainer("table"); table.setOutputMarkupId(true); container.add(table); grids = new ListView<XMLGridSubset>("gridSubsets", new ArrayList<XMLGridSubset>(model.getObject())) { private static final long serialVersionUID = 1L; @Override protected void onBeforeRender() { super.onBeforeRender(); } @Override protected void populateItem(final ListItem<XMLGridSubset> item) { // odd/even style final int index = item.getIndex(); item.add(new SimpleAttributeModifier("class", index % 2 == 0 ? "even" : "odd")); final XMLGridSubset gridSubset = item.getModelObject(); GridSetBroker gridSetBroker = GWC.get().getGridSetBroker(); String gridsetDescription = null; int gridsetLevels; boolean gridsetExists; { final GridSet gridSet = gridSetBroker.get(gridSubset.getGridSetName()); gridsetExists = gridSet != null; if (gridsetExists) { gridsetLevels = gridSet.getNumLevels(); gridsetDescription = gridSet.getDescription(); } else { gridsetLevels = gridSubset.getZoomStop() == null ? 1 : gridSubset.getZoomStop().intValue(); } } final Label gridSetLabel; final Component gridSetBounds; gridSetLabel = new Label("gridSet", new PropertyModel<String>(item.getModel(), "gridSetName")); if (!gridsetExists) { gridSetLabel.add(new AttributeModifier("style", true, new Model<String>("color:red;text-decoration:line-through;"))); getPage().warn("GridSet " + gridSubset.getGridSetName() + " does not exist"); } item.add(gridSetLabel); if (null != gridsetDescription) { gridSetLabel.add(new AttributeModifier("title", true, new Model<String>(gridsetDescription))); } final Component removeLink; final int maxZoomLevel = gridsetLevels - 1; final ArrayList<Integer> zoomLevels = new ArrayList<Integer>(maxZoomLevel + 1); for (int z = 0; z <= maxZoomLevel; z++) { zoomLevels.add(Integer.valueOf(z)); } // zoomStart has all zoom levels as choices // zoomStop choices start at zoomStart's selection // minCachedLevel start at zoomStart's selection and ends at zoomStop's selection // maxCachedLevel start at minCachedLevels' and ends at zoomStop's selection final IModel<Integer> zoomStartModel; final IModel<Integer> zoomStopModel; final IModel<Integer> minCachedLevelModel; final IModel<Integer> maxCachedLevelModel; final ZoomLevelDropDownChoice zoomStart; final ZoomLevelDropDownChoice zoomStop; final ZoomLevelDropDownChoice minCachedLevel; final ZoomLevelDropDownChoice maxCachedLevel; zoomStartModel = new PropertyModel<Integer>(item.getModel(), "zoomStart"); zoomStopModel = new PropertyModel<Integer>(item.getModel(), "zoomStop"); minCachedLevelModel = new PropertyModel<Integer>(item.getModel(), "minCachedLevel"); maxCachedLevelModel = new PropertyModel<Integer>(item.getModel(), "maxCachedLevel"); @SuppressWarnings({ "rawtypes", "unchecked" }) final IModel<List<Integer>> allLevels = new Model(zoomLevels); zoomStart = new ZoomLevelDropDownChoice("zoomStart", zoomStartModel, allLevels); zoomStart.setEnabled(gridsetExists); item.add(zoomStart); zoomStop = new ZoomLevelDropDownChoice("zoomStop", zoomStopModel, allLevels); zoomStop.setEnabled(gridsetExists); item.add(zoomStop); minCachedLevel = new ZoomLevelDropDownChoice("minCachedLevel", minCachedLevelModel, allLevels); minCachedLevel.setEnabled(gridsetExists); item.add(minCachedLevel); maxCachedLevel = new ZoomLevelDropDownChoice("maxCachedLevel", maxCachedLevelModel, allLevels); maxCachedLevel.setEnabled(gridsetExists); item.add(maxCachedLevel); for (ZoomLevelDropDownChoice dropDown : Arrays.asList(zoomStart, zoomStop, minCachedLevel, maxCachedLevel)) { dropDown.add(new OnChangeAjaxBehavior() { private static final long serialVersionUID = 1L; // cascades to zoomStop, min and max cached levels @Override protected void onUpdate(AjaxRequestTarget target) { updateValidZoomRanges(zoomStart, zoomStop, minCachedLevel, maxCachedLevel, target); } }); } updateValidZoomRanges(zoomStart, zoomStop, minCachedLevel, maxCachedLevel, null); // gridSetBounds = new EnvelopePanel("bounds"); // gridSetBounds.setCRSFieldVisible(false); // gridSetBounds.setCrsRequired(false); // gridSetBounds.setLabelsVisibility(false); // gridSetBounds.setModel(new Model<ReferencedEnvelope>(new ReferencedEnvelope())); gridSetBounds = new Label("bounds", new ResourceModel("GridSubsetsEditor.bounds.dynamic")); item.add(gridSetBounds); removeLink = new ImageAjaxLink("removeLink", GWCIconFactory.DELETE_ICON) { private static final long serialVersionUID = 1L; @Override protected void onClick(AjaxRequestTarget target) { List<XMLGridSubset> list; list = new ArrayList<XMLGridSubset>(grids.getModelObject()); final XMLGridSubset subset = (XMLGridSubset) getDefaultModelObject(); list.remove(subset); grids.setModelObject(list); List<String> choices = new ArrayList<String>(availableGridSets.getChoices()); choices.add(subset.getGridSetName()); Collections.sort(choices); availableGridSets.setChoices(choices); target.addComponent(container); target.addComponent(availableGridSets); } }; removeLink.setDefaultModel(item.getModel()); removeLink.add( new AttributeModifier("title", true, new ResourceModel("GridSubsetsEditor.removeLink"))); item.add(removeLink); } }; grids.setOutputMarkupId(true); // this is necessary to avoid loosing item contents on edit/validation checks grids.setReuseItems(true); table.add(grids); List<String> gridSetNames = new ArrayList<String>(GWC.get().getGridSetBroker().getNames()); for (XMLGridSubset gs : model.getObject()) { gridSetNames.remove(gs.getGridSetName()); } Collections.sort(gridSetNames); GeoServerAjaxFormLink addGridsubsetLink = new GeoServerAjaxFormLink("addGridSubset") { private static final long serialVersionUID = 1L; @Override protected void onClick(AjaxRequestTarget target, Form form) { availableGridSets.processInput(); final String selectedGridset = availableGridSets.getModelObject(); if (null == selectedGridset) { return; } List<String> choices = new ArrayList<String>(availableGridSets.getChoices()); choices.remove(selectedGridset); availableGridSets.setChoices(choices); availableGridSets.setEnabled(!choices.isEmpty()); XMLGridSubset newSubset = new XMLGridSubset(); newSubset.setGridSetName(selectedGridset); grids.getModelObject().add(newSubset); target.addComponent(table); target.addComponent(availableGridSets); } }; addGridsubsetLink.add(new Icon("addIcon", GWCIconFactory.ADD_ICON)); add(addGridsubsetLink); availableGridSets = new DropDownChoice<String>("availableGridsets", new Model<String>(), gridSetNames); availableGridSets.setOutputMarkupId(true); add(availableGridSets); }
From source file:org.geoserver.web.netcdf.NetCDFPanel.java
License:Open Source License
public NetCDFPanel(String id, IModel<T> netcdfModel) { super(id, netcdfModel); // New Container // container for ajax updates container = new WebMarkupContainer("container"); container.setOutputMarkupId(true);//ww w .j a v a2 s.c o m add(container); // CheckBox associated to the shuffle parameter shuffle = new CheckBox("shuffle", new PropertyModel(netcdfModel, "shuffle")); container.add(shuffle); // TextBox associated to the compression parameter compressionLevel = new TextField<Integer>("compressionLevel", new PropertyModel(netcdfModel, "compressionLevel")); List<DataPacking> dataPackings = Arrays.asList(DataPacking.values()); dataPacking = new DropDownChoice<DataPacking>("dataPacking", new PropertyModel(netcdfModel, "dataPacking"), dataPackings); dataPacking.setOutputMarkupId(true); container.add(dataPacking); compressionLevel.add(new AbstractValidator<Integer>() { @Override public boolean validateOnNullValue() { return true; } @Override protected void onValidate(IValidatable<Integer> validatable) { if (validatable != null && validatable.getValue() != null) { Integer value = validatable.getValue(); if (value < 0) { ValidationError error = new ValidationError(); error.setMessage(new ParamResourceModel("NetCDFOutSettingsPanel.lowCompression", null, "") .getObject()); validatable.error(error); } else if (value > 9) { ValidationError error = new ValidationError(); error.setMessage(new ParamResourceModel("NetCDFOutSettingsPanel.highCompression", null, "") .getObject()); validatable.error(error); } } } }); container.add(compressionLevel); IModel<List<GlobalAttribute>> attributeModel = new PropertyModel(netcdfModel, "globalAttributes"); // Global Attributes definition globalAttributes = new ListView<GlobalAttribute>("globalAttributes", attributeModel) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<GlobalAttribute> item) { // Create form final Label keyField; keyField = new Label("key", new PropertyModel<String>(item.getModel(), "key")); item.add(keyField); // Create form final Label valueField; valueField = new Label("value", new PropertyModel<String>(item.getModel(), "value")); item.add(valueField); final Component removeLink; removeLink = new ImageAjaxLink("remove", DELETE_ICON) { private static final long serialVersionUID = 1L; @Override protected void onClick(AjaxRequestTarget target) { List<GlobalAttribute> list; list = new ArrayList<GlobalAttribute>(globalAttributes.getModelObject()); final GlobalAttribute attribute = (GlobalAttribute) getDefaultModelObject(); list.remove(attribute); globalAttributes.setModelObject(list); item.remove(); target.addComponent(container); } }; removeLink.setDefaultModel(item.getModel()); item.add(removeLink); } }; globalAttributes.setOutputMarkupId(true); container.add(globalAttributes); // TextField for a new Value final TextField<String> newValue = new TextField<String>("newValue", Model.of("")); newValue.setOutputMarkupId(true); container.add(newValue); // TextField for a new Key final TextField<String> newKey = new TextField<String>("newKey", Model.of("")); newKey.setOutputMarkupId(true); container.add(newKey); GeoServerAjaxFormLink addLink = new GeoServerAjaxFormLink("add") { private static final long serialVersionUID = 1L; @Override protected void onClick(AjaxRequestTarget target, Form form) { newValue.processInput(); newKey.processInput(); String key = newKey.getModelObject(); if (key == null || key.isEmpty()) { ParamResourceModel rm = new ParamResourceModel("NetCDFOutSettingsPanel.nonEmptyKey", null, ""); error(rm.getString()); } else { String value = newValue.getModelObject(); GlobalAttribute attribute = new GlobalAttribute(key, value); if (!globalAttributes.getModelObject().contains(attribute)) { globalAttributes.getModelObject().add(attribute); } newKey.setModel(Model.of("")); // Reset the key field newValue.setModel(Model.of("")); // Reset the Value field target.addComponent(container); } } }; addLink.add(new Icon("addIcon", ADD_ICON)); container.add(addLink); NetCDFSettingsContainer object = netcdfModel.getObject(); object.toString(); }
From source file:wicket.contrib.groovy.builder.BaseComponentBuilder.java
License:Apache License
/** * Remove properties that are set so auto-mapping should work without problems *//*w ww . ja v a 2 s .c o m*/ public static void setModel(Component component, Map attrs) { if (attrs == null) return; Object modelObj = attrs.get("model"); if (modelObj == null) return; if (modelObj instanceof IModel<?>) component.setDefaultModel((IModel<?>) modelObj); else component.setDefaultModel(new Model(modelObj.toString())); attrs.remove("model"); }