use of org.apache.wicket.markup.html.list.ListItem in project midpoint by Evolveum.
the class DashboardSearchPanel method initLayout.
@Override
protected void initLayout() {
final Form searchForm = new Form(ID_SEARCH_FORM);
add(searchForm);
searchForm.setOutputMarkupId(true);
final List<String> accessibleSearchTypes = new ArrayList<>();
if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_USERS_ALL_URL, AuthorizationConstants.AUTZ_UI_USERS_URL)) {
accessibleSearchTypes.add(SEARCH_TYPES.get(USER_INDEX));
}
if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_RESOURCES_ALL_URL, AuthorizationConstants.AUTZ_UI_RESOURCES_URL)) {
accessibleSearchTypes.add(SEARCH_TYPES.get(RESOURCE_INDEX));
}
if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_TASKS_ALL_URL, AuthorizationConstants.AUTZ_UI_TASKS_URL)) {
accessibleSearchTypes.add(SEARCH_TYPES.get(TASK_INDEX));
}
if (accessibleSearchTypes.size() == 0) {
searchForm.setVisible(false);
} else {
final TextField searchInput = new TextField(ID_SEARCH_INPUT, Model.of("")) {
@Override
protected void onComponentTag(final ComponentTag tag) {
super.onComponentTag(tag);
tag.put("placeholder", createStringResource("SearchPanel.searchByName").getString());
}
};
searchForm.add(searchInput);
final Label buttonLabel = new Label(ID_BUTTON_LABEL, new Model<String>() {
public String getObject() {
return accessibleSearchTypes.get(selectedSearchType);
}
});
buttonLabel.setOutputMarkupId(true);
final AjaxSubmitLink searchButton = new AjaxSubmitLink(ID_SEARCH_BUTTON) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
String searchType = buttonLabel.getDefaultModel().getObject().toString();
String searchText = searchInput.getValue();
performSearch(searchType, searchText == null ? "" : searchText);
}
};
searchButton.setOutputMarkupId(true);
searchButton.add(buttonLabel);
searchForm.add(searchButton);
searchForm.setDefaultButton(searchButton);
// final WebMarkupContainer list = new WebMarkupContainer(ID_SEARCH_TYPES);
// list.setOutputMarkupId(true);
ListView<String> li = new ListView<String>(ID_SEARCH_TYPES, new IModel<List<String>>() {
@Override
public void detach() {
}
@Override
public List<String> getObject() {
return accessibleSearchTypes;
}
@Override
public void setObject(List<String> list) {
}
}) {
@Override
protected void populateItem(final ListItem<String> item) {
final AjaxLink searchTypeLink = new AjaxLink(ID_SEARCH_TYPE_ITEM) {
@Override
public IModel<?> getBody() {
return new Model<String>(item.getModel().getObject());
}
@Override
public void onClick(AjaxRequestTarget target) {
selectedSearchType = accessibleSearchTypes.indexOf(item.getModelObject());
target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_BUTTON)));
}
@Override
protected void onComponentTag(final ComponentTag tag) {
super.onComponentTag(tag);
tag.put("value", item.getModelObject());
}
};
searchTypeLink.setOutputMarkupId(true);
item.add(searchTypeLink);
}
};
li.setOutputMarkupId(true);
searchForm.add(li);
// final RepeatingView searchTypes = new RepeatingView(ID_SEARCH_TYPE_ITEM);
// searchTypes.setOutputMarkupId(true);
// if (accessibleSearchTypes.size() > 1) {
// for (int i = 0; i < accessibleSearchTypes.size(); i++) {
// if (i == selectedSearchType){
// continue;
// }
// final String searchTypeItem = accessibleSearchTypes.get(i);
// final AjaxSubmitLink searchTypeLink = new AjaxSubmitLink(searchTypes.newChildId()) {
// @Override
// public void onSubmit(AjaxRequestTarget target, Form<?> form) {
// selectedSearchType = accessibleSearchTypes.indexOf(searchTypeItem);
// target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_BUTTON)));
// target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_TYPES)));
//// target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_TYPES, ID_SEARCH_TYPE_ITEM)));
// }
//
// @Override
// protected void onComponentTag(final ComponentTag tag) {
// super.onComponentTag(tag);
// tag.put("value", searchTypeItem);
// }
//
// };
// searchTypeLink.setOutputMarkupId(true);
// Label linkLabel = new Label(ID_LINK_LABEL, new Model<String>() {
// public String getObject() {
// return searchTypeItem;
// }
// });
// linkLabel.setOutputMarkupId(true);
// searchTypeLink.add(linkLabel);
// searchTypes.add(searchTypeLink);
// }
// }
// list.add(searchTypes);
// if (accessibleSearchTypes.size() == 1){
// list.setVisible(false);
// }
// searchForm.add(list);
}
}
use of org.apache.wicket.markup.html.list.ListItem in project ocvn by devgateway.
the class FileInputBootstrapFormComponentWrapper method addAlreadyUploadedFilesComponent.
/**
* already uploaded files section
*/
private void addAlreadyUploadedFilesComponent() {
alreadyUploadedFiles = new WebMarkupContainer("alreadyUploadedFiles") {
private static final long serialVersionUID = 1L;
@Override
protected void onInitialize() {
super.onInitialize();
setVisibilityAllowed(isVisibleAlreadyUploadedFiles());
}
};
alreadyUploadedFiles.setOutputMarkupPlaceholderTag(true);
alreadyUploadedFiles.setOutputMarkupId(true);
add(alreadyUploadedFiles);
alreadyUploadedFiles.add(new Label("uploadedFilesTitle", new StringResourceModel("uploadedFilesTitle", this, null)));
AbstractReadOnlyModel<List<FileMetadata>> alreadyUploadedFilesModel = new AbstractReadOnlyModel<List<FileMetadata>>() {
private static final long serialVersionUID = 1L;
@Override
public List<FileMetadata> getObject() {
List<FileMetadata> fileObject = new ArrayList<>();
// get only the already uploaded files
for (FileMetadata file : filesModel) {
if (!file.isNew()) {
fileObject.add(file);
}
}
return fileObject;
}
};
ListView<FileMetadata> list = new ListView<FileMetadata>("list", alreadyUploadedFilesModel) {
private static final long serialVersionUID = 1L;
private List<IndicatingAjaxLink<Void>> deleteButtons = new ArrayList<>();
@Override
protected void populateItem(final ListItem<FileMetadata> item) {
// make file name clickable
Link<FileMetadata> downloadLink = new Link<FileMetadata>("downloadLink", item.getModel()) {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
final FileMetadata modelObject = getModelObject();
AbstractResourceStreamWriter rstream = new AbstractResourceStreamWriter() {
private static final long serialVersionUID = 1L;
@Override
public void write(final OutputStream output) throws IOException {
output.write(modelObject.getContent().getBytes());
}
@Override
public String getContentType() {
return modelObject.getContentType();
}
};
ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(rstream, modelObject.getName());
handler.setContentDisposition(ContentDisposition.ATTACHMENT);
getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
}
};
downloadLink.add(new Label("downloadText", item.getModelObject().getName()));
downloadLink.add(new TooltipBehavior(new StringResourceModel("downloadUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
item.add(downloadLink);
Link<FileMetadata> download = new CustomDownloadLink("download", item.getModel());
item.add(download);
IndicatingAjaxLink<Void> delete = new IndicatingAjaxLink<Void>("delete") {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
@Override
public void onClick(final AjaxRequestTarget target) {
filesModel.remove(item.getModelObject());
FileInputBootstrapFormComponentWrapper.this.getModel().setObject((T) filesModel);
target.add(alreadyUploadedFiles);
}
};
delete.add(new IconBehavior(GlyphIconType.remove));
delete.add(new TooltipBehavior(new StringResourceModel("removeUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
delete.setVisible(true);
item.add(delete);
deleteButtons.add(delete);
// only to admins
if (visibleOnlyToAdmin) {
MetaDataRoleAuthorizationStrategy.authorize(delete, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
}
if (disableDeleteButton) {
delete.setVisibilityAllowed(false);
}
}
@Override
public void onEvent(final IEvent<?> event) {
/*
* disable 'delete' buttons based on the form state
*/
if (event.getPayload() instanceof EditingDisabledEvent) {
for (IndicatingAjaxLink<?> del : deleteButtons) {
del.setVisibilityAllowed(false);
}
}
if (event.getPayload() instanceof EditingEnabledEvent) {
for (IndicatingAjaxLink<?> del : deleteButtons) {
del.setVisibilityAllowed(true);
}
}
}
};
alreadyUploadedFiles.add(list);
}
Aggregations