use of org.apache.wicket.markup.html.list.ListItem in project hale by halestudio.
the class StatusPage method addControls.
@Override
protected void addControls(boolean loggedIn) {
super.addControls(loggedIn);
final String workspaceId = getPageParameters().get(PARAMETER_WORKSPACE).toOptionalString();
if (workspaceId == null || workspaceId.isEmpty()) {
throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Workspace ID not specified.");
}
try {
workspaces.getWorkspaceFolder(workspaceId);
} catch (FileNotFoundException e) {
throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Workspace does not exist.");
}
final IModel<TransformationWorkspace> workspace = new LoadableDetachableModel<TransformationWorkspace>() {
private static final long serialVersionUID = 2600444242247550094L;
@Override
protected TransformationWorkspace load() {
return new TransformationWorkspace(workspaceId);
}
};
// job panel
final Serializable family = AbstractTransformationJob.createFamily(workspaceId);
final JobPanel jobs = new JobPanel("jobs", family, true);
add(jobs);
// status
final Label status = new Label("status", new LoadableDetachableModel<String>() {
private static final long serialVersionUID = -4351763182104835300L;
@Override
protected String load() {
if (workspace.getObject().isTransformationFinished()) {
if (workspace.getObject().isTransformationSuccessful()) {
return "Transformation completed.";
} else {
return "Transformation failed.";
}
} else {
if (Job.getJobManager().find(family).length > 0) {
return "Transformation is running:";
} else {
return "No transformation running.";
}
}
}
});
status.setOutputMarkupId(true);
add(status);
// result
final WebMarkupContainer result = new WebMarkupContainer("result");
result.setOutputMarkupId(true);
add(result);
final WebMarkupContainer update = new WebMarkupContainer("update") {
private static final long serialVersionUID = -2591480922683644827L;
@Override
public boolean isVisible() {
return workspace.getObject().isTransformationFinished();
}
};
result.add(update);
// result : report
File reportFile = workspace.getObject().getReportFile();
DownloadLink report = new DownloadLink("log", reportFile, reportFile.getName());
update.add(report);
// result : file list
IModel<? extends List<File>> resultFilesModel = new LoadableDetachableModel<List<File>>() {
private static final long serialVersionUID = -7971872898614031331L;
@Override
protected List<File> load() {
return Arrays.asList(workspace.getObject().getTargetFolder().listFiles());
}
};
final ListView<File> fileList = new ListView<File>("file", resultFilesModel) {
private static final long serialVersionUID = -8045643864251639540L;
@Override
protected void populateItem(ListItem<File> item) {
// download link
DownloadLink download = new DownloadLink("download", item.getModelObject(), item.getModelObject().getName());
item.add(download);
// file name
download.add(new Label("name", item.getModelObject().getName()));
}
};
update.add(fileList);
// leaseEnd
String leaseEnd;
try {
leaseEnd = workspaces.getLeaseEnd(workspaceId).toString(DateTimeFormat.mediumDateTime());
} catch (IOException e) {
leaseEnd = "unknown";
}
add(new Label("leaseEnd", leaseEnd));
boolean transformationFinished = workspace.getObject().isTransformationFinished();
if (transformationFinished) {
// disable job timer
jobs.getTimer().stopOnNextUpdate();
} else {
// timer
add(new AbstractAjaxTimerBehavior(Duration.milliseconds(1500)) {
private static final long serialVersionUID = -3726349470723024150L;
@Override
protected void onTimer(AjaxRequestTarget target) {
if (workspace.getObject().isTransformationFinished()) {
// update status and result
target.add(status);
target.add(result);
// stop timers
stop(target);
jobs.getTimer().stopOnNextUpdate();
}
}
});
}
}
use of org.apache.wicket.markup.html.list.ListItem in project webanno by webanno.
the class AnnotationPreferencesDialogContent method createLayerContainer.
private ListView<AnnotationLayer> createLayerContainer() {
return new ListView<AnnotationLayer>("annotationLayers") {
private static final long serialVersionUID = -4040731191748923013L;
@Override
protected void populateItem(ListItem<AnnotationLayer> item) {
// add checkbox
// get initial state
AnnotationPreference pref = stateModel.getObject().getPreferences();
List<Long> hiddenLayerIds = pref.getHiddenAnnotationLayerIds();
boolean isPreferredToShow = !hiddenLayerIds.contains(item.getModelObject().getId());
CheckBox layer_cb = new CheckBox("annotationLayerActive", Model.of(isPreferredToShow));
layer_cb.add(new AjaxEventBehavior("change") {
private static final long serialVersionUID = 8378489004897115519L;
@Override
protected void onEvent(AjaxRequestTarget target) {
// check state & live update preferences
List<Long> hiddenLayerIds = stateModel.getObject().getPreferences().getHiddenAnnotationLayerIds();
// get and switch state of checkbox
boolean isPreferredToShow = layer_cb.getModelObject();
layer_cb.setModelObject(!isPreferredToShow);
// live update preferences
if (isPreferredToShow) {
// prefer to deactivate layer
hiddenLayerIds.add(item.getModelObject().getId());
} else {
// prefer to activate layer
hiddenLayerIds.remove(item.getModelObject().getId());
}
}
});
item.add(layer_cb);
// add coloring strategy combobox
ChoiceRenderer<ColoringStrategyType> choiceRenderer = new ChoiceRenderer<>("descriptiveName");
List<ColoringStrategyType> choices = new ArrayList<ColoringStrategyType>(EnumSet.allOf(ColoringStrategyType.class));
Model<ColoringStrategyType> initialSelected = Model.of(form.getModelObject().colorPerLayer.get(item.getModelObject().getId()));
DropDownChoice<ColoringStrategyType> layer_color = new DropDownChoice<ColoringStrategyType>("layercoloring", initialSelected, choices, choiceRenderer);
layer_color.add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1060397773470276585L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
AnnotationLayer current_layer = item.getModelObject();
ColoringStrategyType selectedColor = layer_color.getModelObject();
form.getModelObject().colorPerLayer.put(current_layer.getId(), selectedColor);
}
});
item.add(layer_color);
// add label
Label lbl = new Label("annotationLayerDesc", item.getModelObject().getUiName());
item.add(lbl);
}
};
}
use of org.apache.wicket.markup.html.list.ListItem in project syncope by apache.
the class LogsITCase method searchLog.
private Component searchLog(final String property, final String searchPath, final String key) {
Component component = TESTER.getComponentFromLastRenderedPage(searchPath);
Component result = component.getPage().visitChildren(ListItem.class, (final ListItem<LoggerTO> object, final IVisit<Component> visit) -> {
try {
if (object.getModelObject() instanceof LoggerTO && PropertyResolver.getPropertyGetter(property, object.getModelObject()).invoke(object.getModelObject()).equals(key)) {
visit.stop(object);
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
LOG.error("Error invoke method", ex);
}
});
return result;
}
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);
}
use of org.apache.wicket.markup.html.list.ListItem in project wicket by apache.
the class ComponentQueueingTest method repeater2.
/**
* repeater
*/
@Test
public void repeater2() {
TestPage p = new TestPage();
p.setPageMarkup("<p wicket:id='a'><p wicket:id='lv'><p wicket:id='b'><p wicket:id='c'></p></p></p></p>");
MarkupContainer a = new A();
LV l = new LV(3) {
@Override
protected void populateItem(ListItem<Integer> item) {
item.queue(new B(), new C());
}
};
p.queue(a, l);
tester.startPage(p);
assertThat(l.size(), is(3));
for (Component item : l) {
assertThat(p, hasPath(new Path(a, l, item, new B(), new C())));
}
}
Aggregations