Java Code Examples for org.apache.wicket.Component#get()

The following examples show how to use org.apache.wicket.Component#get() . 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: BeanListPropertyEditor.java    From onedev with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private List<PropertyEditor<Serializable>> getPropertyEditorsAtRow(int index) {
	int currentIndex = 0;
	Iterator<Component> it = rows.iterator();
	Component row = it.next();
	while (currentIndex++ < index) {
		row = it.next();
	}
	
	List<PropertyEditor<Serializable>> propertyEditors = new ArrayList<>();
	RepeatingView columns = (RepeatingView) row.get("properties");
	for (Component column: columns) {
		propertyEditors.add((PropertyEditor<Serializable>) column.get("propertyEditor"));
	}
	
	return propertyEditors;
}
 
Example 2
Source File: BeanListPropertyEditor.java    From onedev with MIT License 6 votes vote down vote up
@Override
protected List<Serializable> convertInputToValue() throws ConversionException {
	List<Serializable> newList = newList();
	
	for (Component row: rows) {
		Serializable element = newElement();
		newList.add(element);
		
		RepeatingView columns = (RepeatingView) row.get("properties");
		for (Component column: columns) {
			@SuppressWarnings("unchecked")
			PropertyEditor<Serializable> propertyEditor = (PropertyEditor<Serializable>) column.get("propertyEditor");
			propertyEditor.getDescriptor().setPropertyValue(element, propertyEditor.getConvertedInput());
		}
	}
	return newList;
}
 
Example 3
Source File: ParamListEditPanel.java    From onedev with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected List<Serializable> convertInputToValue() throws ConversionException {
	List<Serializable> value = new ArrayList<>();
	for (Component paramContainer: (WebMarkupContainer)get("params")) {
		Label label = (Label) paramContainer.get("name");
		ParamSupply param = new ParamSupply();
		param.setName((String) label.getDefaultModelObject());
		ParamSpec paramSpec = Preconditions.checkNotNull(getParamSpecs().get(param.getName()));
		param.setSecret(paramSpec instanceof SecretParam);
		Class<?> valuesProviderClass = (Class<?>) paramContainer.getDefaultModelObject();
		Component valuesEditor = paramContainer.get("values");
		if (valuesProviderClass == ScriptingValues.class) {
			ScriptingValues scriptingValues = new ScriptingValues();
			scriptingValues.setScriptName((String) ((PropertyEditor<Serializable>) valuesEditor).getConvertedInput()); 
			param.setValuesProvider(scriptingValues);
		} else if (valuesProviderClass == SpecifiedValues.class) {
			SpecifiedValues specifiedValues = new SpecifiedValues();
			for (Component valueContainer: (WebMarkupContainer)valuesEditor.get("values")) {
				Object propertyValue = ((PropertyEditor<Serializable>) valueContainer.get("value")).getConvertedInput();
				specifiedValues.getValues().add(paramSpec.convertToStrings(propertyValue));
			}
			param.setValuesProvider(specifiedValues);
		} else {
			param.setValuesProvider(new Ignore());
		}
		value.add(param);
	}
	return value;
}
 
Example 4
Source File: FieldListEditPanel.java    From onedev with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected List<Serializable> convertInputToValue() throws ConversionException {
	List<Serializable> value = new ArrayList<>();
	for (Component container: (WebMarkupContainer)get("fields")) {
		Label label = (Label) container.get("name");
		FieldSupply field = new FieldSupply();
		field.setName((String) label.getDefaultModelObject());
		FieldSpec fieldSpec = Preconditions.checkNotNull(getFieldSpecs().get(field.getName()));
		field.setSecret(fieldSpec instanceof SecretField);
		if (container.get("value") instanceof PropertyEditor) {
			PropertyEditor<Serializable> propertyEditor = (PropertyEditor<Serializable>) container.get("value");
			Class<?> valueProviderClass = (Class<?>) container.getDefaultModelObject();
			if (valueProviderClass == SpecifiedValue.class) {
				SpecifiedValue specifiedValue = new SpecifiedValue();
				Object propertyValue = propertyEditor.getConvertedInput();
				specifiedValue.setValue(fieldSpec.convertToStrings(propertyValue));
				field.setValueProvider(specifiedValue);
			} else {
				ScriptingValue scriptingValue = new ScriptingValue();
				scriptingValue.setScriptName((String) propertyEditor.getConvertedInput()); 
				field.setValueProvider(scriptingValue);
			} 
		} else {
			field.setValueProvider(new Ignore());
		}
		value.add(field);
	}
	return value;
}
 
Example 5
Source File: WicketPropertyResolver.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public Component resolve(MarkupContainer container,
		MarkupStream markupStream, ComponentTag tag) {
	if (tag instanceof WicketTag)
	{
		final WicketTag wTag = (WicketTag)tag;

		// If <wicket:property ...>
		if (PROPERTY.equalsIgnoreCase(wTag.getName()))
		{
			wTag.setAutoComponentTag(false);
			String oClassName = tag.getAttribute("class");
			
			String refComponent = tag.getAttribute("ref");
			IModel<?> model = container.getPage().getDefaultModel();
			if(!Strings.isEmpty(refComponent)) {
				Component component = container;
				if(refComponent.startsWith("/")) { //If starts from / - it means that path is absolute for a page
					component = container.getPage().get(refComponent.substring(1));
				} else if(refComponent.startsWith("#")) {  //Supports format like #element:suba:subb
					int subs = refComponent.indexOf(":");
					final String nameToFind = subs>0?refComponent.substring(1, subs):refComponent.substring(1);
					component = container.getPage().visitChildren((comp, visit) -> {if(comp.getId().equals(nameToFind)) visit.stop(comp);});
					if(subs>0) component = component.get(refComponent.substring(subs+1));
				} else {
					component = container.get(refComponent);
				}
				model = component.getDefaultModel();
			}
			
			String objectExpression = tag.getAttribute("object");
			if(!Strings.isEmpty(objectExpression)) model = new PropertyModel<ODocument>(model, objectExpression);
			
			DisplayMode mode = DisplayMode.parse(tag.getAttribute("mode"), DisplayMode.VIEW);
			String visualization = tag.getAttribute("visualization");
			
			String property = tag.getAttribute("property");
			if(Strings.isEmpty(property)) property = wTag.getId();
			
			
			if(Strings.isEmpty(oClassName)) {
				Object object = model.getObject();
				if(object instanceof OIdentifiable) {
					ODocument doc = ((OIdentifiable)object).getRecord();
					oClassName = doc.getSchemaClass().getName();
				}
			}
			IModel<OProperty> propertyModel = new OPropertyModel(oClassName, property);
			if(propertyModel.getObject()==null) throw new WicketRuntimeException("No such property '"+property+"' defined on class '"+oClassName+"'");
			else return new ODocumentMetaPanel<Object>(wTag.getId(), mode.asModel(), 
									(IModel<ODocument>)model, 
									propertyModel).setVisualization(visualization);
		}
	}

	// We were not able to handle the tag
	return null;
}