use of org.apache.wicket.model.util.ListModel 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.model.util.ListModel in project midpoint by Evolveum.
the class ChooseFocusTypeAndRelationDialogPanel method initLayout.
private void initLayout() {
MessagePanel warningMessage = new MessagePanel(ID_WARNING_FEEDBACK, MessagePanel.MessagePanelType.WARN, getWarningMessageModel());
warningMessage.setOutputMarkupId(true);
warningMessage.add(new VisibleBehaviour(() -> getWarningMessageModel() != null));
add(warningMessage);
DropDownFormGroup<QName> type = new DropDownFormGroup<>(ID_OBJECT_TYPE, Model.of(getDefaultObjectType()), Model.ofList(getSupportedObjectTypes()), new QNameObjectTypeChoiceRenderer(), createStringResource("chooseFocusTypeAndRelationDialogPanel.type"), "chooseFocusTypeAndRelationDialogPanel.tooltip.type", "col-md-4", "col-md-8", true);
type.getInput().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
type.setOutputMarkupId(true);
type.add(new VisibleBehaviour(this::isFocusTypeSelectorVisible));
add(type);
IModel<Map<String, String>> options = new Model(null);
options.setObject(new HashMap<>());
ListMultipleChoicePanel<QName> relation = new ListMultipleChoicePanel<>(ID_RELATION, Model.ofList(getDefaultRelations()), new ListModel<>(getSupportedRelations()), WebComponentUtil.getRelationChoicesRenderer(getPageBase()), options);
relation.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
relation.setOutputMarkupId(true);
add(relation);
WebMarkupContainer relationRequired = new WebMarkupContainer(ID_RELATION_REQUIRED);
relationRequired.add(new VisibleBehaviour((this::isRelationRequired)));
add(relationRequired);
Label label = new Label(ID_INFO_MESSAGE, getModel());
label.add(new VisibleBehaviour(() -> getModel() != null && getModelObject() != null));
add(label);
AjaxButton confirmButton = new AjaxButton(ID_BUTTON_OK, createStringResource("Button.ok")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
DropDownFormGroup<QName> type = getTypePanel(getParent());
QName typeChosen = type.getModelObject();
ListMultipleChoicePanel<QName> relation = getRelationPanel(getParent());
Collection<QName> relationChosen = relation.getModelObject();
if (relationChosen.contains(PrismConstants.Q_ANY)) {
relationChosen = getSupportedRelations();
}
ChooseFocusTypeAndRelationDialogPanel.this.okPerformed(typeChosen, relationChosen, target);
getPageBase().hideMainPopup(target);
}
};
add(confirmButton);
AjaxButton cancelButton = new AjaxButton(ID_CANCEL_OK, createStringResource("Button.cancel")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
getPageBase().hideMainPopup(target);
}
};
add(cancelButton);
AjaxButton configuredButton = new AjaxButton(ID_CONFIGURE_TASK, new StringResourceModel("ConfigureTaskConfirmationPanel.configure", this, null)) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
DropDownFormGroup<QName> type = getTypePanel(getParent());
QName typeChosen = type.getModelObject();
ListMultipleChoicePanel<QName> relation = getRelationPanel(getParent());
Collection<QName> relationChosen = relation.getModelObject();
PrismObject<TaskType> task = getTask(typeChosen, relationChosen, target);
if (task == null) {
return;
}
((PageBase) getPage()).hideMainPopup(target);
WebComponentUtil.dispatchToObjectDetailsPage(task, true, ChooseFocusTypeAndRelationDialogPanel.this);
}
};
configuredButton.add(new VisibleBehaviour(this::isTaskConfigureButtonVisible));
add(configuredButton);
}
use of org.apache.wicket.model.util.ListModel in project midpoint by Evolveum.
the class ResourceDetailsTabPanel method initLayout.
protected void initLayout() {
PrismObject<ResourceType> resourceObject = getModelObject();
ResourceType resource = resourceObject.asObjectable();
add(createLastAvailabilityStatusInfo(resource));
add(createSourceTargetInfo(resource));
add(createSchemaStatusInfo(resource));
CapabilitiesPanel capabilities = new CapabilitiesPanel(PANEL_CAPABILITIES, capabilitiesModel);
add(capabilities);
List<ResourceConfigurationDto> resourceConfigList = createResourceConfigList(resource);
ListDataProvider<ResourceConfigurationDto> resourceConfigProvider = new ListDataProvider<>(ResourceDetailsTabPanel.this, new ListModel<>(resourceConfigList));
List<IColumn<SelectableBeanImpl<ResourceType>, String>> tableColumns = new ArrayList<>();
tableColumns.add(ColumnUtils.createPropertyColumn(new ColumnTypeDto<>("ShadowType.kind", "objectTypeDefinition.kind", ShadowType.F_KIND.getLocalPart())));
tableColumns.add(new PropertyColumn<>(createStringResource("ShadowType.objectClass"), "objectTypeDefinition.objectClass") {
@Override
public IModel<?> getDataModel(IModel<SelectableBeanImpl<ResourceType>> rowModel) {
IModel<QName> model = (IModel<QName>) super.getDataModel(rowModel);
if (model.getObject() != null) {
return () -> model.getObject().getLocalPart();
}
return model;
}
});
List<ColumnTypeDto<String>> columns = Arrays.asList(new ColumnTypeDto<>("ShadowType.intent", "objectTypeDefinition.intent", ShadowType.F_INTENT.getLocalPart()), new ColumnTypeDto<>("ResourceType.isSync", "sync", null));
tableColumns.addAll(ColumnUtils.createColumns(columns));
PropertyColumn tasksColumn = new PropertyColumn(PageBase.createStringResourceStatic(this, "ResourceType.tasks"), "definedTasks") {
@Override
public void populateItem(Item item, String componentId, final IModel rowModel) {
ResourceConfigurationDto conf = (ResourceConfigurationDto) rowModel.getObject();
RepeatingView repeater = new RepeatingView(componentId);
for (final TaskType task : conf.getDefinedTasks()) {
repeater.add(new AjaxLinkPanel(repeater.newChildId(), new Model<>(task.getName().getOrig())) {
@Override
public void onClick(AjaxRequestTarget target) {
ResourceDetailsTabPanel.this.taskDetailsPerformed(target, task.getOid());
}
});
}
item.add(repeater);
}
};
tableColumns.add(tasksColumn);
BoxedTablePanel<ResourceConfigurationDto> resourceConfig = new BoxedTablePanel("resourceConfig", resourceConfigProvider, tableColumns);
resourceConfig.setAdditionalBoxCssClasses("box-success");
add(resourceConfig);
}
use of org.apache.wicket.model.util.ListModel 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.model.util.ListModel in project webanno by webanno.
the class CorrectionPage method commonInit.
private void commonInit() {
setVersioned(false);
setModel(Model.of(new AnnotatorStateImpl(Mode.CORRECTION)));
WebMarkupContainer rightSidebar = new WebMarkupContainer("rightSidebar");
// Override sidebar width from preferences
rightSidebar.add(new AttributeModifier("style", LambdaModel.of(() -> String.format("flex-basis: %d%%;", getModelObject().getPreferences().getSidebarSize()))));
rightSidebar.setOutputMarkupId(true);
add(rightSidebar);
rightSidebar.add(detailEditor = createDetailEditor());
centerArea = new WebMarkupContainer("centerArea");
centerArea.add(visibleWhen(() -> getModelObject().getDocument() != null));
centerArea.setOutputMarkupPlaceholderTag(true);
centerArea.add(createDocumentInfoLabel());
actionBar = new ActionBar("actionBar");
centerArea.add(actionBar);
annotationEditor = new BratAnnotationEditor("mergeView", getModel(), detailEditor, this::getEditorCas);
centerArea.add(annotationEditor);
add(centerArea);
getModelObject().setPagingStrategy(new SentenceOrientedPagingStrategy());
centerArea.add(getModelObject().getPagingStrategy().createPositionLabel(MID_NUMBER_OF_PAGES, getModel()).add(visibleWhen(() -> getModelObject().getDocument() != null)).add(LambdaBehavior.onEvent(RenderAnnotationsEvent.class, (c, e) -> e.getRequestHandler().add(c))));
List<UserAnnotationSegment> segments = new LinkedList<>();
UserAnnotationSegment userAnnotationSegment = new UserAnnotationSegment();
if (getModelObject().getDocument() != null) {
userAnnotationSegment.setSelectionByUsernameAndAddress(annotationSelectionByUsernameAndAddress);
userAnnotationSegment.setAnnotatorState(getModelObject());
segments.add(userAnnotationSegment);
}
suggestionView = new SuggestionViewPanel("correctionView", new ListModel<>(segments)) {
private static final long serialVersionUID = 2583509126979792202L;
@Override
public void onChange(AjaxRequestTarget aTarget) {
AnnotatorState state = CorrectionPage.this.getModelObject();
aTarget.addChildren(getPage(), IFeedback.class);
try {
// update begin/end of the curation segment based on bratAnnotatorModel changes
// (like sentence change in auto-scroll mode,....
curationContainer.setState(state);
CAS editorCas = getEditorCas();
setCurationSegmentBeginEnd(editorCas);
suggestionView.requestUpdate(aTarget, curationContainer, annotationSelectionByUsernameAndAddress, curationSegment);
annotationEditor.requestRender(aTarget);
update(aTarget);
} catch (UIMAException e) {
LOG.error("Error: " + e.getMessage(), e);
error("Error: " + ExceptionUtils.getRootCauseMessage(e));
} catch (Exception e) {
LOG.error("Error: " + e.getMessage(), e);
error("Error: " + e.getMessage());
}
}
};
centerArea.add(suggestionView);
curationContainer = new CurationContainer();
curationContainer.setState(getModelObject());
}
Aggregations