use of org.apache.wicket.markup.html.form.FormComponent in project oc-explorer by devgateway.
the class FileInputBootstrapFormComponentWrapper method addBootstrapFileInputComponent.
private void addBootstrapFileInputComponent() {
// this is where the newly uploaded files are saved
final IModel<List<FileUpload>> internalUploadModel = new ListModel<>();
/*
* some customization of the BootstrapFileInput Component
*/
FileInputConfig fileInputConfig = new FileInputConfig();
fileInputConfig.put(new Key<String>("browseLabel"), new StringResourceModel("browseLabel", FileInputBootstrapFormComponentWrapper.this, null).getString());
fileInputConfig.put(new Key<String>("uploadClass"), "btn btn-blue");
fileInputConfig.put(new Key<String>("browseClass"), "btn btn-blue");
bootstrapFileInput = new BootstrapFileInput("bootstrapFileInput", internalUploadModel, fileInputConfig) {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
@Override
protected void onSubmit(final AjaxRequestTarget target) {
super.onSubmit(target);
List<FileUpload> fileUploads = internalUploadModel.getObject();
if (fileUploads != null) {
// check if we uploaded too many files
if (maxFiles > 0 && filesModel.size() + fileUploads.size() > maxFiles) {
if (maxFiles == 1) {
FileInputBootstrapFormComponentWrapper.this.fatal(new StringResourceModel("OneUpload", FileInputBootstrapFormComponentWrapper.this, null).getString());
} else {
FileInputBootstrapFormComponentWrapper.this.fatal(new StringResourceModel("tooManyFiles", FileInputBootstrapFormComponentWrapper.this, Model.of(maxFiles)).getString());
}
FileInputBootstrapFormComponentWrapper.this.invalid();
} else {
// and update the model
for (FileUpload upload : fileUploads) {
FileMetadata fileMetadata = new FileMetadata();
fileMetadata.setName(upload.getClientFileName());
fileMetadata.setContentType(upload.getContentType());
fileMetadata.setSize(upload.getSize());
FileContent fileContent = new FileContent();
fileContent.setBytes(upload.getBytes());
fileMetadata.setContent(fileContent);
filesModel.add(fileMetadata);
// don't display the success notification
// FileInputBootstrapFormComponentWrapper.this.success(new
// StringResourceModel("successUpload",
// FileInputBootstrapFormComponentWrapper.this,
// null, new
// Model(upload.getClientFileName())).getString());
}
}
}
FileInputBootstrapFormComponentWrapper.this.getModel().setObject((T) filesModel);
target.add(fileUploadFeedback);
target.add(pendingFiles);
}
};
add(bootstrapFileInput);
/**
* due to an upgrade of FormGroup in wicket7/wicket-bootrap-0.10, the
* visitor that finds inner FormComponentS, will now find two instead of
* one: the FileInputBootstrapFormComponentWrapper and also the
* BootstrapFileInputField. This is the RIGHT result, previously in
* wicket 6.x it only got the first level of children, hence only one
* FormComponent (the FileInputBootstrapFormComponentWrapper). It would
* then read the label from FileInputBootstrapFormComponentWrapper and
* use it for displaying the label of the FormGroup. In
* wicket7/wicket-bootstrap-0.10 this will result in reading the label
* of BootstrapFileInputField which is null. So you will notice no
* labels for FormGroupS. We fix this by forcing the label of the
* underlying fileInput element to the same model as the label used by
* FileInputBootstrapFormComponentWrapper
*/
FormComponent<?> fileInput = (FormComponent<?>) bootstrapFileInput.get("fileInputForm").get("fileInput");
fileInput.setLabel(this.getLabel());
// only to admins
if (visibleOnlyToAdmin) {
MetaDataRoleAuthorizationStrategy.authorize(bootstrapFileInput, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
}
// want to read only
if (disableDeleteButton) {
MetaDataRoleAuthorizationStrategy.authorize(bootstrapFileInput, Component.RENDER, MetaDataRoleAuthorizationStrategy.NO_ROLE);
}
}
use of org.apache.wicket.markup.html.form.FormComponent in project midpoint by Evolveum.
the class SearchPropertyPanel method initSearchItemField.
protected void initSearchItemField(WebMarkupContainer searchItemContainer) {
Component searchItemField;
PropertySearchItem<T> item = getModelObject();
IModel<List<DisplayableValue<?>>> choices = null;
switch(item.getSearchItemType()) {
case REFERENCE:
searchItemField = new ReferenceValueSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value"), (PrismReferenceDefinition) item.getDefinition().getDef()) {
@Override
public Boolean isItemPanelEnabled() {
return item.isEnabled();
}
@Override
protected boolean isAllowedNotFoundObjectRef() {
return item.getSearch().getTypeClass().equals(AuditEventRecordType.class);
}
@Override
protected List<QName> getAllowedRelations() {
if (item.getSearch().getTypeClass().equals(AuditEventRecordType.class)) {
return Collections.emptyList();
}
return super.getAllowedRelations();
}
};
break;
case BOOLEAN:
choices = (IModel) createBooleanChoices();
case ENUM:
if (choices == null) {
choices = new ListModel(item.getAllowedValues(getPageBase()));
}
searchItemField = WebComponentUtil.createDropDownChoices(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), "value"), (IModel) choices, true, getPageBase());
break;
case DATE:
searchItemField = new DateIntervalSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), "fromDate"), new PropertyModel(getModel(), "toDate"));
break;
case ITEM_PATH:
searchItemField = new ItemPathSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), "value.value"));
break;
case TEXT:
PrismObject<LookupTableType> lookupTable = WebComponentUtil.findLookupTable(item.getDefinition().getDef(), getPageBase());
if (lookupTable != null) {
searchItemField = createAutoCompetePanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value"), lookupTable.asObjectable());
} else {
searchItemField = new TextPanel<String>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value"));
}
break;
default:
searchItemField = new TextPanel<String>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value"));
}
if (searchItemField instanceof InputPanel && !(searchItemField instanceof AutoCompleteTextPanel)) {
FormComponent<?> baseFormComponent = ((InputPanel) searchItemField).getBaseFormComponent();
baseFormComponent.add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
baseFormComponent.add(AttributeAppender.append("style", "width: 140px; max-width: 400px !important;"));
baseFormComponent.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
baseFormComponent.add(new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
return item.isEnabled();
}
@Override
public boolean isVisible() {
return item.isVisible();
}
});
}
searchItemField.setOutputMarkupId(true);
searchItemContainer.add(searchItemField);
}
use of org.apache.wicket.markup.html.form.FormComponent in project midpoint by Evolveum.
the class AbstractInputGuiComponentFactory method configure.
@Override
public void configure(PrismPropertyPanelContext<T> panelCtx, Component component) {
if (!(component instanceof InputPanel)) {
return;
}
InputPanel panel = (InputPanel) component;
final List<FormComponent> formComponents = panel.getFormComponents();
for (FormComponent<T> formComponent : formComponents) {
PrismPropertyWrapper<T> propertyWrapper = panelCtx.unwrapWrapperModel();
IModel<String> label = LambdaModel.of(propertyWrapper::getDisplayName);
formComponent.setLabel(label);
formComponent.setRequired(panelCtx.isMandatory());
if (formComponent instanceof TextField) {
formComponent.add(new AttributeModifier("size", "42"));
}
formComponent.add(panelCtx.getAjaxEventBehavior());
formComponent.add(panelCtx.getVisibleEnableBehavior());
}
panel.getValidatableComponent().add(panelCtx.getExpressionValidator());
panelCtx.getFeedback().setFilter(new ComponentFeedbackMessageFilter(panel.getValidatableComponent()));
}
use of org.apache.wicket.markup.html.form.FormComponent in project midpoint by Evolveum.
the class ACAttributeValuePanel method initLayout.
private void initLayout(Form form, boolean ignoreMandatoryAttributes) {
ACValueConstructionDto dto = getModel().getObject();
PrismPropertyDefinition definition = dto.getAttribute().getDefinition();
InputPanel input = createTypedInputComponent(ID_INPUT, definition);
for (FormComponent comp : input.getFormComponents()) {
comp.setLabel(new PropertyModel<>(dto.getAttribute(), ACAttributeDto.F_NAME));
if (!ignoreMandatoryAttributes) {
comp.setRequired(definition.getMinOccurs() > 0);
}
comp.add(new AjaxFormComponentUpdatingBehavior("blur") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
}
});
}
add(input);
AjaxLink<Void> addLink = new AjaxLink<Void>(ID_ADD) {
@Override
public void onClick(AjaxRequestTarget target) {
addPerformed(target);
}
};
add(addLink);
addLink.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return isAddVisible();
}
});
AjaxLink<Void> removeLink = new AjaxLink<Void>(ID_REMOVE) {
@Override
public void onClick(AjaxRequestTarget target) {
removePerformed(target);
}
};
add(removeLink);
removeLink.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return isRemoveVisible();
}
});
}
Aggregations