use of org.apache.wicket.model.util.ListModel in project webanno by webanno.
the class AutomationPage method commonInit.
private void commonInit() {
setVersioned(false);
setModel(Model.of(new AnnotatorStateImpl(Mode.AUTOMATION)));
WebMarkupContainer rightSidebar = new WebMarkupContainer("rightSidebar");
// Override sidebar width from preferencesa
rightSidebar.add(new AttributeModifier("style", LambdaModel.of(() -> String.format("flex-basis: %d%%;", getModelObject().getPreferences().getSidebarSize()))));
rightSidebar.setOutputMarkupId(true);
add(rightSidebar);
centerArea = new WebMarkupContainer("centerArea");
centerArea.add(visibleWhen(() -> getModelObject().getDocument() != null));
centerArea.setOutputMarkupPlaceholderTag(true);
centerArea.add(new DocumentNamePanel("documentNamePanel", getModel()));
actionBar = new ActionBar("actionBar");
centerArea.add(actionBar);
rightSidebar.add(detailEditor = createDetailEditor());
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("automateView", new ListModel<>(segments)) {
private static final long serialVersionUID = 2583509126979792202L;
@Override
public void onChange(AjaxRequestTarget aTarget) {
try {
// update begin/end of the curation segment based on bratAnnotatorModel changes
// (like sentence change in auto-scroll mode,....
aTarget.addChildren(getPage(), IFeedback.class);
AnnotatorState state = AutomationPage.this.getModelObject();
curationContainer.setState(state);
CAS editorCas = getEditorCas();
setCurationSegmentBeginEnd(editorCas);
suggestionView.requestUpdate(aTarget, curationContainer, annotationSelectionByUsernameAndAddress, curationSegment);
annotationEditor.requestRender(aTarget);
update(aTarget);
} catch (Exception e) {
handleException(aTarget, e);
}
}
};
centerArea.add(suggestionView);
curationContainer = new CurationContainer();
curationContainer.setState(getModelObject());
}
use of org.apache.wicket.model.util.ListModel in project webanno by webanno.
the class ApplicationPageBase method commonInit.
private void commonInit() {
for (GlobalInterceptor interceptor : interceptorsRegistry.getInterceptors()) {
interceptor.intercept(this);
}
footerItems = new ListModel<>(new ArrayList<>());
footerItemRegistry.getFooterItems().stream().map(c -> c.create("item")).forEach(c -> footerItems.getObject().add(c));
footer = new WebMarkupContainer("footer");
footer.setOutputMarkupId(true);
add(footer);
footer.add(new ListView<Component>("footerItems", footerItems) {
private static final long serialVersionUID = 5912513189482015963L;
{
setReuseItems(true);
}
@Override
protected void populateItem(ListItem<Component> aItem) {
aItem.setOutputMarkupPlaceholderTag(true);
aItem.add(aItem.getModelObject());
}
});
Properties settings = SettingsUtil.getSettings();
// Override locale to be used by application
String locale = settings.getProperty(SettingsUtil.CFG_LOCALE, "en");
switch(locale) {
case "auto":
// Do nothing - locale is picked up from browser
break;
default:
// Override the locale in the session
getSession().setLocale(Locale.forLanguageTag(locale));
break;
}
// Add menubar
try {
Class<? extends Component> menubarClass = getApplication().getMetaData(MENUBAR_CLASS);
if (menubarClass == null) {
menubarClass = MenuBar.class;
}
add(ConstructorUtils.invokeConstructor(menubarClass, "menubar"));
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e1) {
throw new RuntimeException(e1);
}
feedbackPanel = new BootstrapFeedbackPanel("feedbackPanel");
feedbackPanel.setOutputMarkupId(true);
feedbackPanel.setFilter((IFeedbackMessageFilter) aMessage -> {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String username = auth != null ? auth.getName() : "SYSTEM";
if (aMessage.isFatal()) {
LOG.error("{}: {}", username, aMessage.getMessage());
} else if (aMessage.isError()) {
LOG.error("{}: {}", username, aMessage.getMessage());
} else if (aMessage.isWarning()) {
LOG.warn("{}: {}", username, aMessage.getMessage());
} else if (aMessage.isInfo()) {
LOG.info("{}: {}", username, aMessage.getMessage());
} else if (aMessage.isDebug()) {
LOG.debug("{}: {}", username, aMessage.getMessage());
}
return true;
});
add(feedbackPanel);
}
use of org.apache.wicket.model.util.ListModel in project webanno by webanno.
the class CurationPage method commonInit.
private void commonInit() {
setModel(Model.of(new AnnotatorStateImpl(Mode.CURATION)));
centerArea = new WebMarkupContainer("centerArea");
centerArea.add(visibleWhen(() -> getModelObject().getDocument() != null));
centerArea.setOutputMarkupPlaceholderTag(true);
centerArea.add(new DocumentNamePanel("documentNamePanel", getModel()));
add(centerArea);
actionBar = new ActionBar("actionBar");
centerArea.add(actionBar);
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))));
// Ensure that a user is set
getModelObject().setUser(new User(CURATION_USER, Role.ROLE_USER));
curationContainer = new CurationContainer();
curationContainer.setState(getModelObject());
WebMarkupContainer sidebarCell = new WebMarkupContainer("rightSidebar");
sidebarCell.setOutputMarkupPlaceholderTag(true);
// Override sidebar width from preferences
sidebarCell.add(new AttributeModifier("style", () -> String.format("flex-basis: %d%%;", getModelObject() != null ? getModelObject().getPreferences().getSidebarSize() : 10)));
add(sidebarCell);
curationView = new SourceListView();
List<UserAnnotationSegment> segments = new LinkedList<>();
UserAnnotationSegment userAnnotationSegments = new UserAnnotationSegment();
if (getModelObject() != null) {
userAnnotationSegments.setSelectionByUsernameAndAddress(annotationSelectionByUsernameAndAddress);
userAnnotationSegments.setAnnotatorState(getModelObject());
segments.add(userAnnotationSegments);
}
// update source list model only first time.
sourceListModel = sourceListModel == null ? curationContainer.getCurationViews() : sourceListModel;
suggestionViewPanel = new SuggestionViewPanel("suggestionViewPanel", new ListModel<>(segments)) {
private static final long serialVersionUID = 2583509126979792202L;
@Override
public void onChange(AjaxRequestTarget aTarget) {
try {
// update begin/end of the curationsegment based on annotator state
// changes
// (like sentence change in auto-scroll mode,....
aTarget.addChildren(getPage(), IFeedback.class);
CurationPage.this.updatePanel(aTarget, curationContainer);
} catch (UIMAException e) {
error(ExceptionUtils.getRootCause(e));
} catch (ClassNotFoundException | AnnotationException | IOException e) {
error("Error: " + e.getMessage());
}
}
};
suggestionViewPanel.setOutputMarkupPlaceholderTag(true);
suggestionViewPanel.add(visibleWhen(() -> getModelObject() != null && getModelObject().getDocument() != null));
centerArea.add(suggestionViewPanel);
editor = new AnnotationDetailEditorPanel("annotationDetailEditorPanel", this, getModel()) {
private static final long serialVersionUID = 2857345299480098279L;
@Override
protected void onChange(AjaxRequestTarget aTarget) {
aTarget.addChildren(getPage(), IFeedback.class);
try {
updatePanel(aTarget, curationContainer);
} 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());
}
}
@Override
protected void onAutoForward(AjaxRequestTarget aTarget) {
annotationEditor.requestRender(aTarget);
}
@Override
protected void onConfigure() {
super.onConfigure();
setEnabled(getModelObject() != null && getModelObject().getDocument() != null && !documentService.getSourceDocument(getModelObject().getDocument().getProject(), getModelObject().getDocument().getName()).getState().equals(SourceDocumentState.CURATION_FINISHED));
}
@Override
public CAS getEditorCas() throws IOException {
return CurationPage.this.getEditorCas();
}
};
sidebarCell.add(editor);
annotationEditor = new BratAnnotationEditor("mergeView", getModel(), editor, this::getEditorCas);
annotationEditor.setHighlightEnabled(false);
annotationEditor.add(visibleWhen(() -> getModelObject() != null && getModelObject().getDocument() != null));
annotationEditor.setOutputMarkupPlaceholderTag(true);
// reset sentenceAddress and lastSentenceAddress to the orginal once
centerArea.add(annotationEditor);
// add container for sentences panel
sentenceListContainer = new WebMarkupContainer("sentenceListContainer");
sentenceListContainer.setOutputMarkupPlaceholderTag(true);
sentenceListContainer.add(visibleWhen(() -> getModelObject() != null && getModelObject().getDocument() != null));
add(sentenceListContainer);
// add container for list of sentences panel
sentenceLinksListView = new WebMarkupContainer("sentenceLinkListView");
sentenceLinksListView.setOutputMarkupPlaceholderTag(true);
sentenceLinksListView.add(new ListView<SourceListView>("sentenceLinkList", LoadableDetachableModel.of(() -> curationContainer.getCurationViews())) {
private static final long serialVersionUID = 8539162089561432091L;
@Override
protected void populateItem(ListItem<SourceListView> item) {
item.add(new SentenceLink("sentenceNumber", item.getModel()));
}
});
sentenceListContainer.add(sentenceLinksListView);
}
use of org.apache.wicket.model.util.ListModel in project midpoint by Evolveum.
the class ResourceTasksPanel method createTaskModel.
private ListModel<TaskType> createTaskModel(PrismObject<ResourceType> object) {
OperationResult result = new OperationResult(OPERATION_LOAD_TASKS);
List<PrismObject<TaskType>> tasks = WebModelServiceUtils.searchObjects(TaskType.class, QueryBuilder.queryFor(TaskType.class, pageBase.getPrismContext()).item(TaskType.F_OBJECT_REF).ref(object.getOid()).build(), result, pageBase);
List<TaskType> tasksType = new ArrayList<TaskType>();
for (PrismObject<TaskType> task : tasks) {
tasksType.add(task.asObjectable());
}
return new ListModel<>(tasksType);
}
use of org.apache.wicket.model.util.ListModel in project midpoint by Evolveum.
the class AuditLogViewerPanel method initParametersPanel.
private void initParametersPanel(Form mainForm) {
WebMarkupContainer parametersPanel = new WebMarkupContainer(ID_PARAMETERS_PANEL);
parametersPanel.setOutputMarkupId(true);
mainForm.add(parametersPanel);
PropertyModel<XMLGregorianCalendar> fromModel = new PropertyModel<XMLGregorianCalendar>(auditSearchDto, AuditSearchDto.F_FROM);
DatePanel from = new DatePanel(ID_FROM, fromModel);
DateValidator dateFromValidator = WebComponentUtil.getRangeValidator(mainForm, new ItemPath(AuditSearchDto.F_FROM));
dateFromValidator.setMessageKey("AuditLogViewerPanel.dateValidatorMessage");
dateFromValidator.setDateFrom((DateTimeField) from.getBaseFormComponent());
for (FormComponent<?> formComponent : from.getFormComponents()) {
formComponent.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
}
from.setOutputMarkupId(true);
parametersPanel.add(from);
PropertyModel<XMLGregorianCalendar> toModel = new PropertyModel<XMLGregorianCalendar>(auditSearchDto, AuditSearchDto.F_TO);
DatePanel to = new DatePanel(ID_TO, toModel);
DateValidator dateToValidator = WebComponentUtil.getRangeValidator(mainForm, new ItemPath(AuditSearchDto.F_FROM));
dateToValidator.setMessageKey("AuditLogViewerPanel.dateValidatorMessage");
dateToValidator.setDateTo((DateTimeField) to.getBaseFormComponent());
for (FormComponent<?> formComponent : to.getFormComponents()) {
formComponent.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
}
to.setOutputMarkupId(true);
parametersPanel.add(to);
PropertyModel<ItemPathDto> changedItemModel = new PropertyModel<ItemPathDto>(auditSearchDto, AuditSearchDto.F_CHANGED_ITEM);
ItemPathPanel changedItemPanel = new ItemPathPanel(ID_CHANGED_ITEM, changedItemModel, pageBase);
// changedItemPanel.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
// changedItemPanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
changedItemPanel.setOutputMarkupId(true);
parametersPanel.add(changedItemPanel);
PropertyModel<String> hostIdentifierModel = new PropertyModel<>(auditSearchDto, AuditSearchDto.F_HOST_IDENTIFIER);
TextPanel<String> hostIdentifier = new TextPanel<>(ID_HOST_IDENTIFIER, hostIdentifierModel);
hostIdentifier.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
hostIdentifier.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
hostIdentifier.setOutputMarkupId(true);
parametersPanel.add(hostIdentifier);
ListModel<AuditEventTypeType> eventTypeListModel = new ListModel<AuditEventTypeType>(Arrays.asList(AuditEventTypeType.values()));
PropertyModel<AuditEventTypeType> eventTypeModel = new PropertyModel<AuditEventTypeType>(auditSearchDto, AuditSearchDto.F_EVENT_TYPE);
DropDownChoicePanel<AuditEventTypeType> eventType = new DropDownChoicePanel<AuditEventTypeType>(ID_EVENT_TYPE, eventTypeModel, eventTypeListModel, new EnumChoiceRenderer<AuditEventTypeType>(), true);
eventType.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
eventType.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
eventType.setOutputMarkupId(true);
parametersPanel.add(eventType);
WebMarkupContainer eventStage = new WebMarkupContainer(ID_EVENT_STAGE);
eventStage.add(visibilityByKey(visibilityMap, EVENT_STAGE_LABEL_VISIBILITY));
eventStage.setOutputMarkupId(true);
parametersPanel.add(eventStage);
ListModel<AuditEventStageType> eventStageListModel = new ListModel<AuditEventStageType>(Arrays.asList(AuditEventStageType.values()));
PropertyModel<AuditEventStageType> eventStageModel = new PropertyModel<AuditEventStageType>(auditSearchDto, AuditSearchDto.F_EVENT_STAGE);
DropDownChoicePanel<AuditEventStageType> eventStageField = new DropDownChoicePanel<AuditEventStageType>(ID_EVENT_STAGE_FIELD, eventStageModel, eventStageListModel, new EnumChoiceRenderer<AuditEventStageType>(), true);
eventStageField.add(visibilityByKey(visibilityMap, EVENT_STAGE_FIELD_VISIBILITY));
eventStageField.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
eventStageField.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
eventStageField.setOutputMarkupId(true);
eventStage.add(eventStageField);
ListModel<OperationResultStatusType> outcomeListModel = new ListModel<OperationResultStatusType>(Arrays.asList(OperationResultStatusType.values()));
PropertyModel<OperationResultStatusType> outcomeModel = new PropertyModel<OperationResultStatusType>(auditSearchDto, AuditSearchDto.F_OUTCOME);
DropDownChoicePanel<OperationResultStatusType> outcome = new DropDownChoicePanel<OperationResultStatusType>(ID_OUTCOME, outcomeModel, outcomeListModel, new EnumChoiceRenderer<OperationResultStatusType>(), true);
outcome.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
outcome.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
outcome.setOutputMarkupId(true);
parametersPanel.add(outcome);
List<String> channelList = WebComponentUtil.getChannelList();
List<QName> channelQnameList = new ArrayList<QName>();
for (int i = 0; i < channelList.size(); i++) {
String channel = channelList.get(i);
if (channel != null) {
QName channelQName = QNameUtil.uriToQName(channel);
channelQnameList.add(channelQName);
}
}
ListModel<QName> channelListModel = new ListModel<QName>(channelQnameList);
PropertyModel<QName> channelModel = new PropertyModel<QName>(auditSearchDto, AuditSearchDto.F_CHANNEL);
DropDownChoicePanel<QName> channel = new DropDownChoicePanel<QName>(ID_CHANNEL, channelModel, channelListModel, new QNameChoiceRenderer(), true);
channel.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
channel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
channel.setOutputMarkupId(true);
parametersPanel.add(channel);
List<Class<? extends ObjectType>> allowedClasses = new ArrayList<>();
allowedClasses.add(UserType.class);
MultiValueChoosePanel<ObjectType> chooseInitiatorPanel = new SingleValueChoosePanel<ObjectReferenceType, ObjectType>(ID_INITIATOR_NAME, allowedClasses, objectReferenceTransformer, new PropertyModel<ObjectReferenceType>(auditSearchDto, AuditSearchDto.F_INITIATOR_NAME));
parametersPanel.add(chooseInitiatorPanel);
WebMarkupContainer targetOwnerName = new WebMarkupContainer(ID_TARGET_OWNER_NAME);
targetOwnerName.add(visibilityByKey(visibilityMap, TARGET_OWNER_LABEL_VISIBILITY));
parametersPanel.add(targetOwnerName);
MultiValueChoosePanel<ObjectType> chooseTargerOwnerPanel = new SingleValueChoosePanel<ObjectReferenceType, ObjectType>(ID_TARGET_OWNER_NAME_FIELD, allowedClasses, objectReferenceTransformer, new PropertyModel<ObjectReferenceType>(auditSearchDto, AuditSearchDto.F_TARGET_OWNER_NAME));
chooseTargerOwnerPanel.add(visibilityByKey(visibilityMap, TARGET_OWNER_FIELD_VISIBILITY));
targetOwnerName.add(chooseTargerOwnerPanel);
WebMarkupContainer targetName = new WebMarkupContainer(ID_TARGET_NAME);
targetName.add(visibilityByKey(visibilityMap, TARGET_NAME_LABEL_VISIBILITY));
parametersPanel.add(targetName);
List<Class<? extends ObjectType>> allowedClassesAll = new ArrayList<>();
allowedClassesAll.addAll(ObjectTypes.getAllObjectTypes());
MultiValueChoosePanel<ObjectType> chooseTargetPanel = new MultiValueChoosePanel<ObjectType>(ID_TARGET_NAME_FIELD, new PropertyModel<List<ObjectType>>(auditSearchDto, AuditSearchDto.F_TARGET_NAMES_OBJECTS), allowedClassesAll);
chooseTargetPanel.setOutputMarkupId(true);
chooseTargetPanel.add(visibilityByKey(visibilityMap, TARGET_NAME_FIELD_VISIBILITY));
targetName.add(chooseTargetPanel);
AjaxSubmitButton ajaxButton = new AjaxSubmitButton(ID_SEARCH_BUTTON, createStringResource("BasicSearchPanel.search")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
auditLogStorage.setSearchDto(searchDto);
auditLogStorage.setPageNumber(0);
Form mainForm = (Form) getParent().getParent();
addOrReplaceTable(mainForm);
getFeedbackPanel().getFeedbackMessages().clear();
target.add(getFeedbackPanel());
target.add(mainForm);
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
target.add(getFeedbackPanel());
}
};
WebMarkupContainer valueRefTargetNameContainer = new WebMarkupContainer(ID_VALUE_REF_TARGET_NAMES);
valueRefTargetNameContainer.add(visibilityByKey(visibilityMap, TARGET_NAME_LABEL_VISIBILITY));
parametersPanel.add(valueRefTargetNameContainer);
MultiValueChoosePanel<ObjectType> chooseValueRefTargetNamePanel = new MultiValueChoosePanel<ObjectType>(ID_VALUE_REF_TARGET_NAMES_FIELD, new PropertyModel<List<ObjectType>>(auditSearchDto, AuditSearchDto.F_VALUE_REF_TARGET_NAME), allowedClassesAll);
chooseValueRefTargetNamePanel.setOutputMarkupId(true);
chooseValueRefTargetNamePanel.add(visibilityByKey(visibilityMap, VALUE_REF_TARGET_NAME_FIELD_VISIBILITY));
valueRefTargetNameContainer.add(chooseValueRefTargetNamePanel);
ajaxButton.setOutputMarkupId(true);
parametersPanel.add(ajaxButton);
}
Aggregations