Java Code Examples for org.apache.wicket.markup.html.WebMarkupContainer#getDefaultModelObject()

The following examples show how to use org.apache.wicket.markup.html.WebMarkupContainer#getDefaultModelObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParamListEditPanel.java    From onedev with MIT License 4 votes vote down vote up
private Component newParamsView(Class<?> paramBeanClass) {
	RepeatingView paramsView = new RepeatingView("params");
	paramsView.setDefaultModel(Model.of(paramBeanClass.getName()));
	BeanDescriptor beanDescriptor = new BeanDescriptor(paramBeanClass);
	for (List<PropertyDescriptor> groupProperties: beanDescriptor.getProperties().values()) {
		for (PropertyDescriptor property: groupProperties) {
			WebMarkupContainer container = new WebMarkupContainer(paramsView.newChildId());
			container.add(new Label("name", property.getDisplayName()));

			ParamSupply param = params.get(property.getDisplayName());
			if (param != null) {
				container.add(newValuesEditor("values", property, param.getValuesProvider()));
				container.setDefaultModel(Model.of(param.getValuesProvider().getClass()));
			} else {
				container.add(newValuesEditor("values", property, newSpecifiedValuesProvider(property)));
				container.setDefaultModel(Model.of(SpecifiedValues.class));
			}

			String required;
			if (property.isPropertyRequired() 
					&& property.getPropertyClass() != boolean.class
					&& property.getPropertyClass() != Boolean.class) {
				required = "*";
			} else {
				required = "&nbsp;";
			}
			
			container.add(new Label("required", required).setEscapeModelStrings(false));
			
			boolean isSecret = property.getPropertyGetter().getAnnotation(Password.class) != null;

			List<String> choices = new ArrayList<>();
			if (isSecret) {
				choices.add(SpecifiedValues.SECRET_DISPLAY_NAME);
				choices.add(ScriptingValues.SECRET_DISPLAY_NAME);
				choices.add(Ignore.DISPLAY_NAME);
			} else {
				choices.add(SpecifiedValues.DISPLAY_NAME);
				choices.add(ScriptingValues.DISPLAY_NAME);
				choices.add(Ignore.DISPLAY_NAME);
			}
			DropDownChoice<String> valuesProviderChoice = new DropDownChoice<String>("valuesProvider", new IModel<String>() {
				
				@Override
				public void detach() {
				}

				@Override
				public String getObject() {
					Class<?> valuesProviderClass = (Class<?>) container.getDefaultModelObject();
					if (valuesProviderClass == SpecifiedValues.class)
						return isSecret?SpecifiedValues.SECRET_DISPLAY_NAME:SpecifiedValues.DISPLAY_NAME;
					else if (valuesProviderClass == ScriptingValues.class)
						return isSecret?ScriptingValues.SECRET_DISPLAY_NAME:ScriptingValues.DISPLAY_NAME;
					else
						return Ignore.DISPLAY_NAME;
				}

				@Override
				public void setObject(String object) {
					ValuesProvider valuesProvider;
					if (object.equals(SpecifiedValues.DISPLAY_NAME) || object.equals(SpecifiedValues.SECRET_DISPLAY_NAME))  
						valuesProvider = newSpecifiedValuesProvider(property);
					else if (object.equals(ScriptingValues.DISPLAY_NAME) || object.equals(ScriptingValues.SECRET_DISPLAY_NAME))
						valuesProvider = new ScriptingValues();
					else
						valuesProvider = new Ignore();
					container.replace(newValuesEditor("values", property, valuesProvider));
					container.setDefaultModelObject(valuesProvider.getClass());
				}
									
			}, choices);
			
			valuesProviderChoice.setNullValid(false);
			
			valuesProviderChoice.add(new AjaxFormComponentUpdatingBehavior("change"){

				@Override
				protected void onUpdate(AjaxRequestTarget target) {
					onPropertyUpdating(target);
					target.add(container);
				}
				
			});
			container.add(valuesProviderChoice);
			container.add(new Label("description", property.getDescription()).setEscapeModelStrings(false));
			container.add(new FencedFeedbackPanel("feedback", container));
			container.setOutputMarkupId(true);
			paramsView.add(container);
		}
	}
	
	return paramsView;
}
 
Example 2
Source File: FieldListEditPanel.java    From onedev with MIT License 4 votes vote down vote up
private Component newFieldsView(Class<?> fieldBeanClass) {
	RepeatingView fieldsView = new RepeatingView("fields");
	fieldsView.setDefaultModel(Model.of(fieldBeanClass.getName()));
	BeanDescriptor beanDescriptor = new BeanDescriptor(fieldBeanClass);
	for (List<PropertyDescriptor> groupProperties: beanDescriptor.getProperties().values()) {
		for (PropertyDescriptor property: groupProperties) {
			if (getFieldSpecs().containsKey(property.getDisplayName())) {
				WebMarkupContainer container = new WebMarkupContainer(fieldsView.newChildId());
				FieldSupply field = fields.get(property.getDisplayName());
				if (field != null) {
					container.add(newValueEditor("value", property, field.getValueProvider()));
					container.setDefaultModel(Model.of(field.getValueProvider().getClass()));
				} else {
					container.add(newValueEditor("value", property, newSpecifiedValueProvider(property)));
					container.setDefaultModel(Model.of(SpecifiedValue.class));
				}
				
				container.add(new Label("name", property.getDisplayName()));

				String required;
				if (property.isPropertyRequired() 
						&& property.getPropertyClass() != boolean.class
						&& property.getPropertyClass() != Boolean.class) {
					required = "*";
				} else {
					required = "&nbsp;";
				}
				
				container.add(new Label("required", required).setEscapeModelStrings(false));
				
				boolean isSecret = property.getPropertyGetter().getAnnotation(Password.class) != null;

				List<String> choices = new ArrayList<>();
				if (isSecret) {
					choices.add(SpecifiedValue.SECRET_DISPLAY_NAME);
					choices.add(ScriptingValue.SECRET_DISPLAY_NAME);
					choices.add(Ignore.DISPLAY_NAME);
				} else {
					choices.add(SpecifiedValue.DISPLAY_NAME);
					choices.add(ScriptingValue.DISPLAY_NAME);
					choices.add(Ignore.DISPLAY_NAME);
				}
				DropDownChoice<String> valueProviderChoice = new DropDownChoice<String>("valueProvider", new IModel<String>() {
					
					@Override
					public void detach() {
					}

					@Override
					public String getObject() {
						Class<?> valueProviderClass = (Class<?>) container.getDefaultModelObject();
						if (valueProviderClass == SpecifiedValue.class)
							return isSecret?SpecifiedValue.SECRET_DISPLAY_NAME:SpecifiedValue.DISPLAY_NAME;
						else if (valueProviderClass == ScriptingValue.class)
							return isSecret?ScriptingValue.SECRET_DISPLAY_NAME:ScriptingValue.DISPLAY_NAME;
						else
							return Ignore.DISPLAY_NAME;
					}

					@Override
					public void setObject(String object) {
						ValueProvider valueProvider;
						if (object.equals(SpecifiedValue.DISPLAY_NAME) || object.equals(SpecifiedValue.SECRET_DISPLAY_NAME))  
							valueProvider = newSpecifiedValueProvider(property);
						else if (object.equals(ScriptingValue.DISPLAY_NAME) || object.equals(ScriptingValue.SECRET_DISPLAY_NAME))
							valueProvider = new ScriptingValue();
						else
							valueProvider = new Ignore();
						container.replace(newValueEditor("value", property, valueProvider));
						container.setDefaultModelObject(valueProvider.getClass());
					}
					
				}, choices);
				
				valueProviderChoice.setNullValid(false);
				
				valueProviderChoice.add(new AjaxFormComponentUpdatingBehavior("change"){

					@Override
					protected void onUpdate(AjaxRequestTarget target) {
						onPropertyUpdating(target);
						target.add(container);
					}
					
				});
				container.add(valueProviderChoice);
				
				container.add(new Label("description", property.getDescription()).setEscapeModelStrings(false));
				container.add(new FencedFeedbackPanel("feedback", container));
				container.setOutputMarkupId(true);
				fieldsView.add(container);
			}
		}
	}
	
	return fieldsView;
}