List of usage examples for org.apache.wicket.model AbstractReadOnlyModel AbstractReadOnlyModel
AbstractReadOnlyModel
From source file:com.evolveum.midpoint.web.page.admin.server.PageTaskEdit.java
License:Apache License
private void initMainInfo(Form mainForm) { RequiredTextField<String> name = new RequiredTextField<String>(ID_NAME, new PropertyModel<String>(model, TaskDto.F_NAME)); name.add(new VisibleEnableBehaviour() { @Override//from ww w . j av a 2 s.c om public boolean isVisible() { return edit; } }); name.add(new AttributeModifier("style", "width: 100%")); name.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); mainForm.add(name); Label nameLabel = new Label(ID_NAME_LABEL, new PropertyModel(model, TaskDto.F_NAME)); nameLabel.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return !edit; } }); mainForm.add(nameLabel); TextArea<String> description = new TextArea<String>(ID_DESCRIPTION, new PropertyModel<String>(model, TaskDto.F_DESCRIPTION)); description.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return edit; } }); // description.add(new AttributeModifier("style", "width: 100%")); // description.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); mainForm.add(description); Label descriptionLabel = new Label(ID_DESCRIPTION_LABEL, new PropertyModel(model, TaskDto.F_DESCRIPTION)); descriptionLabel.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return !edit; } }); mainForm.add(descriptionLabel); Label oid = new Label("oid", new PropertyModel(model, "oid")); mainForm.add(oid); mainForm.add(new Label(ID_IDENTIFIER, new PropertyModel(model, TaskDto.F_IDENTIFIER))); Label category = new Label("category", new PropertyModel(model, "category")); mainForm.add(category); LinkPanel parent = new LinkPanel(ID_PARENT, new PropertyModel(model, TaskDto.F_PARENT_TASK_NAME)) { @Override public void onClick(AjaxRequestTarget target) { String oid = model.getObject().getParentTaskOid(); if (oid != null) { PageParameters parameters = new PageParameters(); parameters.add(OnePageParameterEncoder.PARAMETER, oid); setResponsePage(new PageTaskEdit(parameters, PageTaskEdit.this)); } } }; mainForm.add(parent); ListView<String> handlerUriList = new ListView<String>(ID_HANDLER_URI_LIST, new PropertyModel(model, TaskDto.F_HANDLER_URI_LIST)) { @Override protected void populateItem(ListItem<String> item) { item.add(new Label(ID_HANDLER_URI, item.getModelObject())); } }; mainForm.add(handlerUriList); // Label uri = new Label(ID_HANDLER_URI, new PropertyModel(model, "uri")); // mainForm.add(uri); Label execution = new Label("execution", new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDtoExecutionStatus executionStatus = model.getObject().getExecution(); if (executionStatus != TaskDtoExecutionStatus.CLOSED) { return getString(TaskDtoExecutionStatus.class.getSimpleName() + "." + executionStatus.name()); } else { return getString(TaskDtoExecutionStatus.class.getSimpleName() + "." + executionStatus.name() + ".withTimestamp", new AbstractReadOnlyModel<String>() { @Override public String getObject() { if (model.getObject().getCompletionTimestamp() != null) { return new Date(model.getObject().getCompletionTimestamp()) .toLocaleString(); // todo correct formatting } else { return "?"; } } }); } } }); mainForm.add(execution); Label node = new Label("node", new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDto dto = model.getObject(); if (!TaskDtoExecutionStatus.RUNNING.equals(dto.getExecution())) { return null; } return PageTaskEdit.this.getString("pageTaskEdit.message.node", dto.getExecutingAt()); } }); mainForm.add(node); }
From source file:com.evolveum.midpoint.web.page.admin.server.PageTaskEdit.java
License:Apache License
private void initSchedule(Form mainForm) { //todo probably can be removed, visibility can be updated in children (already components) [lazyman] final WebMarkupContainer container = new WebMarkupContainer("container"); container.setOutputMarkupId(true);/*from ww w . ja va 2 s. c o m*/ mainForm.add(container); final IModel<Boolean> recurringCheck = new PropertyModel<Boolean>(model, "recurring"); final IModel<Boolean> boundCheck = new PropertyModel<Boolean>(model, "bound"); WebMarkupContainer suspendReqRecurring = new WebMarkupContainer("suspendReqRecurring"); suspendReqRecurring.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return edit && isRunnableOrRunning(); } }); mainForm.add(suspendReqRecurring); final WebMarkupContainer boundContainer = new WebMarkupContainer("boundContainer"); boundContainer.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return recurringCheck.getObject(); } }); boundContainer.setOutputMarkupId(true); container.add(boundContainer); WebMarkupContainer suspendReqBound = new WebMarkupContainer("suspendReqBound"); suspendReqBound.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return edit && isRunnableOrRunning(); } }); boundContainer.add(suspendReqBound); final WebMarkupContainer intervalContainer = new WebMarkupContainer("intervalContainer"); intervalContainer.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return recurringCheck.getObject(); } }); intervalContainer.setOutputMarkupId(true); container.add(intervalContainer); final WebMarkupContainer cronContainer = new WebMarkupContainer("cronContainer"); cronContainer.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return recurringCheck.getObject() && !boundCheck.getObject(); } }); cronContainer.setOutputMarkupId(true); container.add(cronContainer); AjaxCheckBox recurring = new AjaxCheckBox("recurring", recurringCheck) { @Override protected void onUpdate(AjaxRequestTarget target) { target.add(container); target.add(PageTaskEdit.this.get("mainForm:recurring")); } }; recurring.setOutputMarkupId(true); recurring.add(new VisibleEnableBehaviour() { @Override public boolean isEnabled() { return edit && !isRunnableOrRunning(); } }); mainForm.add(recurring); final AjaxCheckBox bound = new AjaxCheckBox("bound", boundCheck) { @Override protected void onUpdate(AjaxRequestTarget target) { target.add(container); target.add(PageTaskEdit.this.get("mainForm:recurring")); } }; bound.add(new VisibleEnableBehaviour() { @Override public boolean isEnabled() { return edit && !isRunnableOrRunning(); } }); boundContainer.add(bound); Label boundHelp = new Label("boundHelp"); boundHelp.add(new InfoTooltipBehavior()); boundContainer.add(boundHelp); TextField<Integer> interval = new TextField<Integer>("interval", new PropertyModel<Integer>(model, "interval")); interval.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); interval.add(new VisibleEnableBehaviour() { @Override public boolean isEnabled() { return edit && (!isRunnableOrRunning() || !boundCheck.getObject()); } }); intervalContainer.add(interval); TextField<String> cron = new TextField<String>("cron", new PropertyModel<String>(model, "cronSpecification")); cron.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); cron.add(new VisibleEnableBehaviour() { @Override public boolean isEnabled() { return edit && (!isRunnableOrRunning() || !boundCheck.getObject()); } }); cronContainer.add(cron); Label cronHelp = new Label("cronHelp"); cronHelp.add(new InfoTooltipBehavior()); cronContainer.add(cronHelp); DateInput notStartBefore = new DateInput("notStartBeforeField", new PropertyModel<Date>(model, "notStartBefore")); notStartBefore.setOutputMarkupId(true); notStartBefore.add(new VisibleEnableBehaviour() { @Override public boolean isEnabled() { return edit && !isRunning(); } }); mainForm.add(notStartBefore); DateInput notStartAfter = new DateInput("notStartAfterField", new PropertyModel<Date>(model, "notStartAfter")); notStartAfter.setOutputMarkupId(true); notStartAfter.add(new VisibleEnableBehaviour() { @Override public boolean isEnabled() { return edit; } }); mainForm.add(notStartAfter); DropDownChoice misfire = new DropDownChoice("misfireAction", new PropertyModel<MisfireActionType>(model, "misfireAction"), WebMiscUtil.createReadonlyModelFromEnum(MisfireActionType.class), new EnumChoiceRenderer<MisfireActionType>(PageTaskEdit.this)); misfire.add(new VisibleEnableBehaviour() { @Override public boolean isEnabled() { return edit; } }); mainForm.add(misfire); Label lastStart = new Label("lastStarted", new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDto dto = model.getObject(); if (dto.getLastRunStartTimestampLong() == null) { return "-"; } Date date = new Date(dto.getLastRunStartTimestampLong()); return WebMiscUtil.formatDate(date); } }); mainForm.add(lastStart); Label lastFinished = new Label("lastFinished", new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDto dto = model.getObject(); if (dto.getLastRunFinishTimestampLong() == null) { return "-"; } Date date = new Date(dto.getLastRunFinishTimestampLong()); return WebMiscUtil.formatDate(date); } }); mainForm.add(lastFinished); Label nextRun = new Label("nextRun", new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDto dto = model.getObject(); if (dto.getRecurring() && dto.getBound() && isRunning()) { return getString("pageTasks.runsContinually"); } if (dto.getNextRunStartTimeLong() == null) { return "-"; } Date date = new Date(dto.getNextRunStartTimeLong()); return WebMiscUtil.formatDate(date); } }); mainForm.add(nextRun); mainForm.add(new StartEndDateValidator(notStartBefore, notStartAfter)); mainForm.add(new ScheduleValidator(getTaskManager(), recurring, bound, interval, cron)); }
From source file:com.evolveum.midpoint.web.page.admin.server.PageTasks.java
License:Apache License
private void initSearchForm(Form searchForm) { DropDownChoice listSelect = new DropDownChoice(ID_STATE, new PropertyModel(searchModel, TasksSearchDto.F_STATUS), new AbstractReadOnlyModel<List<TaskDtoExecutionStatusFilter>>() { @Override// w w w. j a v a 2s.com public List<TaskDtoExecutionStatusFilter> getObject() { return createTypeList(); } }, new EnumChoiceRenderer(PageTasks.this)); listSelect.add(createFilterAjaxBehaviour()); listSelect.setOutputMarkupId(true); listSelect.setNullValid(false); if (listSelect.getModel().getObject() == null) { listSelect.getModel().setObject(TaskDtoExecutionStatusFilter.ALL); } searchForm.add(listSelect); DropDownChoice categorySelect = new DropDownChoice(ID_CATEGORY, new PropertyModel(searchModel, TasksSearchDto.F_CATEGORY), new AbstractReadOnlyModel<List<String>>() { @Override public List<String> getObject() { return createCategoryList(); } }, new IChoiceRenderer<String>() { @Override public Object getDisplayValue(String object) { if (ALL_CATEGORIES.equals(object)) { object = "AllCategories"; } return PageTasks.this.getString("pageTasks.category." + object); } @Override public String getIdValue(String object, int index) { return Integer.toString(index); } }); categorySelect.setOutputMarkupId(true); categorySelect.setNullValid(false); categorySelect.add(createFilterAjaxBehaviour()); if (categorySelect.getModel().getObject() == null) { categorySelect.getModel().setObject(ALL_CATEGORIES); } searchForm.add(categorySelect); CheckBox showSubtasks = new CheckBox(ID_SHOW_SUBTASKS, new PropertyModel(searchModel, TasksSearchDto.F_SHOW_SUBTASKS)); showSubtasks.add(createFilterAjaxBehaviour()); searchForm.add(showSubtasks); AjaxSubmitButton clearButton = new AjaxSubmitButton(ID_SEARCH_CLEAR) { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { clearSearchPerformed(target); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(getFeedbackPanel()); } }; searchForm.add(clearButton); }
From source file:com.evolveum.midpoint.web.page.admin.server.PageTasks.java
License:Apache License
private List<IColumn<NodeDto, String>> initNodeColumns() { List<IColumn<NodeDto, String>> columns = new ArrayList<IColumn<NodeDto, String>>(); IColumn column = new CheckBoxHeaderColumn<NodeDto>(); columns.add(column);//w w w . j a va2s.co m column = new LinkColumn<NodeDto>(createStringResource("pageTasks.node.name"), "name", "name") { @Override public void onClick(AjaxRequestTarget target, IModel<NodeDto> rowModel) { NodeDto node = rowModel.getObject(); nodeDetailsPerformed(target, node.getOid()); } }; columns.add(column); columns.add(new EnumPropertyColumn<NodeDto>(createStringResource("pageTasks.node.executionStatus"), "executionStatus") { @Override protected String translate(Enum en) { return createStringResource(en).getString(); } }); // CheckBoxColumn check = new CheckBoxColumn(createStringResource("pageTasks.node.running"), "running"); // check.setEnabled(false); // columns.add(check); // currently, name == identifier, so this is redundant // columns.add(new PropertyColumn(createStringResource("pageTasks.node.nodeIdentifier"), "nodeIdentifier")); columns.add(new PropertyColumn(createStringResource("pageTasks.node.managementPort"), "managementPort")); columns.add(new AbstractColumn<NodeDto, String>(createStringResource("pageTasks.node.lastCheckInTime")) { @Override public void populateItem(Item<ICellPopulator<NodeDto>> item, String componentId, final IModel<NodeDto> rowModel) { item.add(new Label(componentId, new AbstractReadOnlyModel<Object>() { @Override public Object getObject() { return createLastCheckInTime(rowModel); } })); } }); CheckBoxColumn check = new CheckBoxColumn(createStringResource("pageTasks.node.clustered"), "clustered"); check.setEnabled(false); columns.add(check); columns.add(new PropertyColumn(createStringResource("pageTasks.node.statusMessage"), "statusMessage")); columns.add(new InlineMenuHeaderColumn(createNodesInlineMenu())); return columns; }
From source file:com.evolveum.midpoint.web.page.admin.server.PageTasks.java
License:Apache License
private List<IColumn<TaskDto, String>> initTaskColumns() { List<IColumn<TaskDto, String>> columns = new ArrayList<IColumn<TaskDto, String>>(); IColumn column = new CheckBoxHeaderColumn<TaskType>(); columns.add(column);//from w ww .j a v a 2 s. c o m column = createTaskNameColumn(this, "pageTasks.task.name"); columns.add(column); columns.add(createTaskCategoryColumn(this, "pageTasks.task.category")); columns.add(new AbstractColumn<TaskDto, String>(createStringResource("pageTasks.task.objectRef")) { @Override public void populateItem(Item<ICellPopulator<TaskDto>> item, String componentId, final IModel<TaskDto> rowModel) { item.add(new Label(componentId, new AbstractReadOnlyModel<Object>() { @Override public Object getObject() { return createObjectRef(rowModel); } })); } }); columns.add(createTaskExecutionStatusColumn(this, "pageTasks.task.execution")); columns.add(new PropertyColumn<TaskDto, String>(createStringResource("pageTasks.task.executingAt"), "executingAt")); columns.add(new AbstractColumn<TaskDto, String>(createStringResource("pageTasks.task.progress")) { @Override public void populateItem(Item<ICellPopulator<TaskDto>> cellItem, String componentId, final IModel<TaskDto> rowModel) { cellItem.add(new Label(componentId, new AbstractReadOnlyModel<Object>() { @Override public Object getObject() { return createProgress(rowModel); } })); } }); columns.add(new AbstractColumn<TaskDto, String>(createStringResource("pageTasks.task.currentRunTime")) { @Override public void populateItem(Item<ICellPopulator<TaskDto>> item, String componentId, final IModel<TaskDto> rowModel) { item.add(new Label(componentId, new AbstractReadOnlyModel<Object>() { @Override public Object getObject() { return createCurrentRuntime(rowModel); } })); } }); columns.add( new AbstractColumn<TaskDto, String>(createStringResource("pageTasks.task.scheduledToRunAgain")) { @Override public void populateItem(Item<ICellPopulator<TaskDto>> item, String componentId, final IModel<TaskDto> rowModel) { item.add(new Label(componentId, new AbstractReadOnlyModel<Object>() { @Override public Object getObject() { return createScheduledToRunAgain(rowModel); } })); } }); columns.add(new IconColumn<TaskDto>(createStringResource("pageTasks.task.status")) { @Override protected IModel<String> createTitleModel(final IModel<TaskDto> rowModel) { return new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDto dto = rowModel.getObject(); if (dto != null && dto.getStatus() != null) { return createStringResourceStatic(PageTasks.this, dto.getStatus()).getString(); } else { return createStringResourceStatic(PageTasks.this, OperationResultStatus.UNKNOWN) .getString(); } } }; } @Override protected IModel<String> createIconModel(final IModel<TaskDto> rowModel) { return new AbstractReadOnlyModel<String>() { @Override public String getObject() { if (rowModel != null && rowModel.getObject() != null && rowModel.getObject().getStatus() != null) { return OperationResultStatusIcon.parseOperationalResultStatus( rowModel.getObject().getStatus().createStatusType()).getIcon(); } else return OperationResultStatusIcon.UNKNOWN.getIcon(); } }; } }); columns.add(new InlineMenuHeaderColumn(createTasksInlineMenu())); return columns; }
From source file:com.evolveum.midpoint.web.page.admin.server.PageTasks.java
License:Apache License
public static AbstractColumn<TaskDto, String> createTaskCategoryColumn(final Component component, String label) {/* w w w.j av a2s . co m*/ return new AbstractColumn<TaskDto, String>(createStringResourceStatic(component, label)) { @Override public void populateItem(Item<ICellPopulator<TaskDto>> item, String componentId, final IModel<TaskDto> rowModel) { item.add(new Label(componentId, new AbstractReadOnlyModel<Object>() { @Override public Object getObject() { return createStringResourceStatic(component, "pageTasks.category." + rowModel.getObject().getCategory()).getString(); } })); } }; }
From source file:com.evolveum.midpoint.web.page.admin.server.TaskBasicTabPanel.java
License:Apache License
private void initLayoutBasic() { // Name//from w w w . j a v a 2 s . c om WebMarkupContainer nameContainer = new WebMarkupContainer(ID_NAME_CONTAINER); RequiredTextField<String> name = new RequiredTextField<>(ID_NAME, new PropertyModel<String>(taskDtoModel, TaskDto.F_NAME)); name.add(parentPage.createEnabledIfEdit(new ItemPath(TaskType.F_NAME))); name.add(new AttributeModifier("style", "width: 100%")); name.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); nameContainer.add(name); nameContainer.add(parentPage.createVisibleIfAccessible(new ItemPath(TaskType.F_NAME))); add(nameContainer); // Description WebMarkupContainer descriptionContainer = new WebMarkupContainer(ID_DESCRIPTION_CONTAINER); TextArea<String> description = new TextArea<>(ID_DESCRIPTION, new PropertyModel<String>(taskDtoModel, TaskDto.F_DESCRIPTION)); description.add(parentPage.createEnabledIfEdit(new ItemPath(TaskType.F_DESCRIPTION))); // description.add(new AttributeModifier("style", "width: 100%")); // description.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); descriptionContainer.add(description); descriptionContainer.add(parentPage.createVisibleIfAccessible(new ItemPath(TaskType.F_DESCRIPTION))); add(descriptionContainer); // OID Label oid = new Label(ID_OID, new PropertyModel(getObjectWrapperModel(), ID_OID)); add(oid); // Identifier WebMarkupContainer identifierContainer = new WebMarkupContainer(ID_IDENTIFIER_CONTAINER); identifierContainer.add(new Label(ID_IDENTIFIER, new PropertyModel(taskDtoModel, TaskDto.F_IDENTIFIER))); identifierContainer.add(parentPage.createVisibleIfAccessible(new ItemPath(TaskType.F_TASK_IDENTIFIER))); add(identifierContainer); // Category WebMarkupContainer categoryContainer = new WebMarkupContainer(ID_CATEGORY_CONTAINER); categoryContainer.add(new Label(ID_CATEGORY, WebComponentUtil.createCategoryNameModel(this, new PropertyModel(taskDtoModel, TaskDto.F_CATEGORY)))); categoryContainer.add(parentPage.createVisibleIfAccessible(new ItemPath(TaskType.F_CATEGORY))); add(categoryContainer); // Parent WebMarkupContainer parentContainer = new WebMarkupContainer(ID_PARENT_CONTAINER); final LinkPanel parent = new LinkPanel(ID_PARENT, new PropertyModel<String>(taskDtoModel, TaskDto.F_PARENT_TASK_NAME)) { @Override public void onClick(AjaxRequestTarget target) { String oid = taskDtoModel.getObject().getParentTaskOid(); if (oid != null) { PageParameters parameters = new PageParameters(); parameters.add(OnePageParameterEncoder.PARAMETER, oid); setResponsePage(PageTaskEdit.class, parameters); } } }; parentContainer.add(parent); parentContainer.add(parentPage.createVisibleIfAccessible(new ItemPath(TaskType.F_PARENT))); add(parentContainer); // Owner WebMarkupContainer ownerContainer = new WebMarkupContainer(ID_OWNER_CONTAINER); final LinkPanel owner = new LinkPanel(ID_OWNER, new PropertyModel<String>(taskDtoModel, TaskDto.F_OWNER_NAME)) { @Override public void onClick(AjaxRequestTarget target) { String oid = taskDtoModel.getObject().getOwnerOid(); if (oid != null) { PageParameters parameters = new PageParameters(); parameters.add(OnePageParameterEncoder.PARAMETER, oid); setResponsePage(PageUser.class, parameters); } } }; ownerContainer.add(owner); ownerContainer.add(parentPage.createVisibleIfAccessible(new ItemPath(TaskType.F_OWNER_REF))); add(ownerContainer); // Handler URI ListView<String> handlerUriContainer = new ListView<String>(ID_HANDLER_URI_CONTAINER, new PropertyModel(taskDtoModel, TaskDto.F_HANDLER_URI_LIST)) { @Override protected void populateItem(ListItem<String> item) { item.add(new Label(ID_HANDLER_URI, item.getModelObject())); } }; handlerUriContainer.add(parentPage.createVisibleIfAccessible(new ItemPath(TaskType.F_HANDLER_URI), new ItemPath(TaskType.F_OTHER_HANDLERS_URI_STACK))); add(handlerUriContainer); // Execution WebMarkupContainer executionContainer = new WebMarkupContainer(ID_EXECUTION_CONTAINER); Label execution = new Label(ID_EXECUTION, new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDtoExecutionStatus executionStatus = taskDtoModel.getObject().getExecution(); if (executionStatus != TaskDtoExecutionStatus.CLOSED) { return getString(TaskDtoExecutionStatus.class.getSimpleName() + "." + executionStatus.name()); } else { return getString(TaskDtoExecutionStatus.class.getSimpleName() + "." + executionStatus.name() + ".withTimestamp", new AbstractReadOnlyModel<String>() { @Override public String getObject() { if (taskDtoModel.getObject().getCompletionTimestamp() != null) { return new Date(taskDtoModel.getObject().getCompletionTimestamp()) .toLocaleString(); // todo correct formatting } else { return "?"; } } }); } } }); executionContainer.add(execution); Label node = new Label(ID_NODE, new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDto dto = taskDtoModel.getObject(); if (!TaskDtoExecutionStatus.RUNNING.equals(dto.getExecution())) { return null; } return parentPage.getString("pageTaskEdit.message.node", dto.getExecutingAt()); } }); executionContainer.add(node); executionContainer.add(parentPage.createVisibleIfAccessible(new ItemPath(TaskType.F_EXECUTION_STATUS), new ItemPath(TaskType.F_NODE_AS_OBSERVED))); add(executionContainer); }
From source file:com.evolveum.midpoint.web.page.admin.server.TaskSchedulingTabPanel.java
License:Apache License
private void initLayoutForInfoPanel() { // last start WebMarkupContainer lastStartedContainer = new WebMarkupContainer(ID_LAST_STARTED_CONTAINER); Label lastStart = new Label(ID_LAST_STARTED, new AbstractReadOnlyModel<String>() { @Override// w w w .j a v a2 s . c o m public String getObject() { TaskDto dto = taskDtoModel.getObject(); if (dto.getLastRunStartTimestampLong() == null) { return "-"; } else { return WebComponentUtil.formatDate(new Date(dto.getLastRunStartTimestampLong())); } } }); lastStartedContainer.add(lastStart); Label lastStartAgo = new Label(ID_LAST_STARTED_AGO, new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDto dto = taskDtoModel.getObject(); if (dto.getLastRunStartTimestampLong() == null) { return ""; } else { final long ago = System.currentTimeMillis() - dto.getLastRunStartTimestampLong(); return createStringResource("TaskStatePanel.message.ago", DurationFormatUtils.formatDurationWords(ago, true, true)).getString(); } } }); lastStartedContainer.add(lastStartAgo); lastStartedContainer.add(parentPage.createVisibleIfAccessible(TaskType.F_LAST_RUN_START_TIMESTAMP)); add(lastStartedContainer); // last finish WebMarkupContainer lastFinishedContainer = new WebMarkupContainer(ID_LAST_FINISHED_CONTAINER); Label lastFinished = new Label(ID_LAST_FINISHED, new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDto dto = taskDtoModel.getObject(); if (dto.getLastRunFinishTimestampLong() == null) { return "-"; } else { return WebComponentUtil.formatDate(new Date(dto.getLastRunFinishTimestampLong())); } } }); lastFinishedContainer.add(lastFinished); Label lastFinishedAgo = new Label(ID_LAST_FINISHED_AGO, new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDto dto = taskDtoModel.getObject(); if (dto.getLastRunFinishTimestampLong() == null) { return ""; } else { Long duration; if (dto.getLastRunStartTimestampLong() == null || dto.getLastRunFinishTimestampLong() < dto.getLastRunStartTimestampLong()) { duration = null; } else { duration = dto.getLastRunFinishTimestampLong() - dto.getLastRunStartTimestampLong(); } long ago = System.currentTimeMillis() - dto.getLastRunFinishTimestampLong(); if (duration != null) { return getString("TaskStatePanel.message.durationAndAgo", DurationFormatUtils.formatDurationWords(ago, true, true), duration); } else { return getString("TaskStatePanel.message.ago", DurationFormatUtils.formatDurationWords(ago, true, true)); } } } }); lastFinishedContainer.add(lastFinishedAgo); lastFinishedContainer.add(parentPage.createVisibleIfAccessible(TaskType.F_LAST_RUN_FINISH_TIMESTAMP)); add(lastFinishedContainer); WebMarkupContainer nextRunContainer = new WebMarkupContainer(ID_NEXT_RUN_CONTAINER); Label nextRun = new Label(ID_NEXT_RUN, new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDto dto = taskDtoModel.getObject(); if (dto.isRecurring() && dto.isBound() && dto.isRunning()) { return getString("pageTasks.runsContinually"); } else if (dto.getNextRunStartTimeLong() == null) { return "-"; } else { return WebComponentUtil.formatDate(new Date(dto.getNextRunStartTimeLong())); } } }); nextRunContainer.add(nextRun); Label nextRunIn = new Label(ID_NEXT_RUN_IN, new AbstractReadOnlyModel<String>() { @Override public String getObject() { TaskDto dto = taskDtoModel.getObject(); if (dto.getNextRunStartTimeLong() == null || (dto.isRecurring() && dto.isBound() && dto.isRunning())) { return ""; } else { long currentTime = System.currentTimeMillis(); final long in = dto.getNextRunStartTimeLong() - currentTime; if (in >= 0) { return getString("TaskStatePanel.message.in", DurationFormatUtils.formatDurationWords(in, true, true)); } else { return ""; } } } }); nextRunContainer.add(nextRunIn); nextRunContainer.add(parentPage.createVisibleIfAccessible(TaskType.F_NEXT_RUN_START_TIMESTAMP)); add(nextRunContainer); }
From source file:com.evolveum.midpoint.web.page.admin.server.TaskSubtasksAndThreadsTabPanel.java
License:Apache License
private void initLayout(final IModel<TaskDto> taskDtoModel) { WebMarkupContainer threadsConfigurationPanel = new WebMarkupContainer(ID_THREADS_CONFIGURATION_PANEL); add(threadsConfigurationPanel);/*from ww w . j a v a 2 s .c o m*/ threadsConfigurationPanel.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return taskDtoModel.getObject().configuresWorkerThreads(); } }); final TextField<Integer> workerThreads = new TextField<>(ID_WORKER_THREADS, new PropertyModel<Integer>(taskDtoModel, TaskDto.F_WORKER_THREADS)); workerThreads.setOutputMarkupId(true); workerThreads.add(new VisibleEnableBehaviour() { @Override public boolean isEnabled() { return parentPage.isEdit(); } }); threadsConfigurationPanel.add(workerThreads); VisibleEnableBehaviour hiddenWhenEditingOrNoSubtasks = new VisibleEnableBehaviour() { @Override public boolean isVisible() { return !parentPage.isEdit() && !taskDtoModel.getObject().getSubtasks().isEmpty(); } }; Label subtasksLabel = new Label(ID_SUBTASKS_LABEL, new ResourceModel("pageTaskEdit.subtasksLabel")); subtasksLabel.add(hiddenWhenEditingOrNoSubtasks); add(subtasksLabel); SubtasksPanel subtasksPanel = new SubtasksPanel(ID_SUBTASKS_PANEL, new PropertyModel<List<TaskDto>>(taskDtoModel, TaskDto.F_SUBTASKS), parentPage.getWorkflowManager().isEnabled()); subtasksPanel.add(hiddenWhenEditingOrNoSubtasks); add(subtasksPanel); VisibleEnableBehaviour hiddenWhenNoSubtasks = new VisibleEnableBehaviour() { @Override public boolean isVisible() { TaskDto taskDto = taskDtoModel.getObject(); return taskDto != null && !taskDto.getTransientSubtasks().isEmpty(); } }; Label workerThreadsTableLabel = new Label(ID_WORKER_THREADS_TABLE_LABEL, new ResourceModel("TaskStatePanel.workerThreads")); workerThreadsTableLabel.add(hiddenWhenNoSubtasks); add(workerThreadsTableLabel); List<IColumn<WorkerThreadDto, String>> columns = new ArrayList<>(); columns.add(new PropertyColumn(createStringResourceStatic(this, "TaskStatePanel.subtaskName"), WorkerThreadDto.F_NAME)); columns.add(new EnumPropertyColumn<WorkerThreadDto>( createStringResourceStatic(this, "TaskStatePanel.subtaskState"), WorkerThreadDto.F_EXECUTION_STATUS)); columns.add(new PropertyColumn(createStringResourceStatic(this, "TaskStatePanel.subtaskObjectsProcessed"), WorkerThreadDto.F_PROGRESS)); ISortableDataProvider<WorkerThreadDto, String> threadsProvider = new ListDataProvider<>(this, new AbstractReadOnlyModel<List<WorkerThreadDto>>() { @Override public List<WorkerThreadDto> getObject() { List<WorkerThreadDto> rv = new ArrayList<>(); TaskDto taskDto = taskDtoModel.getObject(); if (taskDto != null) { for (TaskDto subtaskDto : taskDto.getTransientSubtasks()) { rv.add(new WorkerThreadDto(subtaskDto)); } } return rv; } }); TablePanel<WorkerThreadDto> workerThreadsTablePanel = new TablePanel<>(ID_WORKER_THREADS_TABLE, threadsProvider, columns); workerThreadsTablePanel.add(hiddenWhenNoSubtasks); add(workerThreadsTablePanel); }
From source file:com.evolveum.midpoint.web.page.admin.server.TaskSummaryPanel.java
License:Apache License
@Override protected IModel<String> getTitleModel() { return new AbstractReadOnlyModel<String>() { @Override//from www. j a v a 2 s . c om public String getObject() { TaskDto taskDto = parentPage.getTaskDto(); if (taskDto.isWorkflow()) { return getString("TaskSummaryPanel.requestedBy", parentPage.getTaskDto().getRequestedBy()); } else { TaskType taskType = getModelObject(); String rv; if (taskType.getExpectedTotal() != null) { rv = createStringResource("TaskSummaryPanel.progressWithTotalKnown", taskType.getProgress(), taskType.getExpectedTotal()).getString(); } else { rv = createStringResource("TaskSummaryPanel.progressWithTotalUnknown", taskType.getProgress()).getString(); } if (taskDto.isSuspended()) { rv += " " + getString("TaskSummaryPanel.progressIfSuspended"); } else if (taskDto.isClosed()) { rv += " " + getString("TaskSummaryPanel.progressIfClosed"); } else if (taskDto.isWaiting()) { rv += " " + getString("TaskSummaryPanel.progressIfWaiting"); } else if (taskDto.getStalledSince() != null) { rv += " " + getString("TaskSummaryPanel.progressIfStalled", WebComponentUtil.formatDate(new Date(parentPage.getTaskDto().getStalledSince()))); } return rv; } } }; }