use of com.evolveum.midpoint.web.component.util.SelectableBean in project midpoint by Evolveum.
the class ChildCasesPanel method initLayout.
protected void initLayout() {
setOutputMarkupId(true);
MainObjectListPanel<CaseType> table = new MainObjectListPanel<CaseType>(ID_CHILD_CASES_PANEL, CaseType.class, Collections.emptyList()) {
@Override
protected List<IColumn<SelectableBean<CaseType>, String>> createDefaultColumns() {
List<IColumn<SelectableBean<CaseType>, String>> columns = new ArrayList<IColumn<SelectableBean<CaseType>, String>>();
IColumn column = new PropertyColumn(createStringResource("pageCases.table.description"), "value.description");
columns.add(column);
columns.add(ColumnUtils.createCaseActorsColumn(ChildCasesPanel.this.getPageBase()));
column = new PropertyColumn<SelectableBeanImpl<CaseType>, String>(createStringResource("pageCases.table.state"), CaseType.F_STATE.getLocalPart(), "value.state") {
@Override
public String getCssClass() {
return "col-sm-2 col-md-1";
}
};
columns.add(column);
column = new AbstractExportableColumn<SelectableBean<CaseType>, String>(createStringResource("pageCases.table.workitems")) {
@Override
public void populateItem(Item<ICellPopulator<SelectableBean<CaseType>>> cellItem, String componentId, IModel<SelectableBean<CaseType>> model) {
cellItem.add(new Label(componentId, model.getObject().getValue() != null && model.getObject().getValue().getWorkItem() != null ? model.getObject().getValue().getWorkItem().size() : null));
}
@Override
public IModel<String> getDataModel(IModel<SelectableBean<CaseType>> rowModel) {
return Model.of(rowModel.getObject().getValue() != null && rowModel.getObject().getValue().getWorkItem() != null ? Integer.toString(rowModel.getObject().getValue().getWorkItem().size()) : "");
}
@Override
public String getCssClass() {
return "col-md-2 col-lg-1";
}
};
columns.add(column);
return (List) columns;
}
@Override
protected boolean isCreateNewObjectEnabled() {
return false;
}
@Override
protected ISelectableDataProvider<CaseType, SelectableBean<CaseType>> createProvider() {
return createSelectableBeanObjectDataProvider(() -> getChildCasesQuery(), null);
}
@Override
protected UserProfileStorage.TableId getTableId() {
return UserProfileStorage.TableId.PAGE_CASE_CHILD_CASES_TAB;
}
@Override
protected List<InlineMenuItem> createInlineMenu() {
return new ArrayList<>();
}
@Override
protected IColumn<SelectableBean<CaseType>, String> createCheckboxColumn() {
return null;
}
};
table.setOutputMarkupId(true);
add(table);
}
use of com.evolveum.midpoint.web.component.util.SelectableBean in project midpoint by Evolveum.
the class InternalsLoggedInUsersPanel method initLayout.
private void initLayout() {
MainObjectListPanel<F> table = new MainObjectListPanel(ID_TABLE, FocusType.class, null) {
@Override
protected void objectDetailsPerformed(AjaxRequestTarget target, ObjectType object) {
if (WebComponentUtil.hasDetailsPage(object.getClass())) {
PageParameters parameters = new PageParameters();
parameters.add(OnePageParameterEncoder.PARAMETER, object.getOid());
getPageBase().navigateToNext(WebComponentUtil.getObjectDetailsPage(object.getClass()), parameters);
}
}
@Override
protected List<IColumn<SelectableBean<F>, String>> createDefaultColumns() {
return InternalsLoggedInUsersPanel.this.initColumns();
}
@Override
protected List<InlineMenuItem> createInlineMenu() {
return initInlineMenu();
}
@Override
protected UserProfileStorage.TableId getTableId() {
return null;
}
@Override
protected ISelectableDataProvider<UserSessionManagementType, SelectableBean<F>> createProvider() {
LoadableModel<List<UserSessionManagementType>> principals = new LoadableModel<List<UserSessionManagementType>>(true) {
@Override
protected List<UserSessionManagementType> load() {
return loadLoggedInPrincipals();
}
};
return new SelectableListDataProvider<SelectableBean<F>, UserSessionManagementType>(InternalsLoggedInUsersPanel.this, principals) {
@Override
protected SelectableBean<F> createObjectWrapper(UserSessionManagementType principal) {
SelectableBeanImpl<F> user = new SelectableBeanImpl<>((F) principal.getFocus());
user.setActiveSessions(principal.getActiveSessions());
user.setNodes(principal.getNode());
return user;
}
};
}
@Override
protected boolean isCreateNewObjectEnabled() {
return false;
}
@Override
protected List<Component> createToolbarButtonsList(String buttonId) {
return new ArrayList<>();
}
@Override
protected boolean enableSavePageSize() {
return false;
}
};
add(table);
}
use of com.evolveum.midpoint.web.component.util.SelectableBean in project midpoint by Evolveum.
the class WebComponentUtil method createMenuItemsFromActions.
@NotNull
public static List<InlineMenuItem> createMenuItemsFromActions(@NotNull List<GuiActionType> actions, String operation, PageBase pageBase, @NotNull Supplier<Collection<? extends ObjectType>> selectedObjectsSupplier) {
List<InlineMenuItem> menuItems = new ArrayList<>();
actions.forEach(action -> {
if (action.getTaskTemplateRef() == null) {
return;
}
String templateOid = action.getTaskTemplateRef().getOid();
if (StringUtils.isEmpty(templateOid)) {
return;
}
String label = action.getDisplay() != null && PolyStringUtils.isNotEmpty(action.getDisplay().getLabel()) ? action.getDisplay().getLabel().getOrig() : action.getName();
menuItems.add(new InlineMenuItem(Model.of(label)) {
private static final long serialVersionUID = 1L;
@Override
public InlineMenuItemAction initAction() {
return new ColumnMenuAction<SelectableBean<ObjectType>>() {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
OperationResult result = new OperationResult(operation);
try {
Collection<String> oids;
if (getRowModel() != null) {
oids = Collections.singletonList(getRowModel().getObject().getValue().getOid());
} else {
oids = CollectionUtils.emptyIfNull(selectedObjectsSupplier.get()).stream().filter(o -> o.getOid() != null).map(o -> o.getOid()).collect(Collectors.toSet());
}
if (!oids.isEmpty()) {
@NotNull Item<PrismValue, ItemDefinition> extensionQuery = prepareExtensionValues(oids);
MidPointPrincipal principal = pageBase.getPrincipal();
if (principal == null) {
throw new SecurityViolationException("No current user");
}
TaskType newTask = pageBase.getModelService().getObject(TaskType.class, templateOid, createCollection(createExecutionPhase()), pageBase.createSimpleTask(operation), result).asObjectable();
newTask.setName(PolyStringType.fromOrig(newTask.getName().getOrig() + " " + (int) (Math.random() * 10000)));
newTask.setOid(null);
newTask.setTaskIdentifier(null);
newTask.setOwnerRef(createObjectRef(principal.getFocus()));
newTask.setExecutionState(RUNNABLE);
newTask.setSchedulingState(READY);
newTask.asPrismObject().getOrCreateExtension().add(extensionQuery);
ObjectSetBasedWorkDefinitionType workDef = ObjectSetUtil.getObjectSetDefinitionFromTask(newTask);
QueryType query = (QueryType) extensionQuery.getRealValue();
ObjectSetType objectSet = workDef.getObjects();
if (objectSet == null) {
objectSet = new ObjectSetType();
objectSet.setType(ObjectType.COMPLEX_TYPE);
}
objectSet.setQuery(query);
workDef.setObjects(objectSet);
ObjectDelta<TaskType> delta = DeltaFactory.Object.createAddDelta(newTask.asPrismObject());
Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges = saveTask(delta, result, pageBase);
String newTaskOid = ObjectDeltaOperation.findAddDeltaOid(executedChanges, newTask.asPrismObject());
newTask.setOid(newTaskOid);
newTask.setTaskIdentifier(newTaskOid);
result.setInProgress();
result.setBackgroundTaskOid(newTask.getOid());
} else {
result.recordWarning(pageBase.createStringResource("WebComponentUtil.message.createMenuItemsFromActions.warning").getString());
}
} catch (Exception ex) {
result.recordFatalError(result.getOperation(), ex);
target.add(pageBase.getFeedbackPanel());
} finally {
pageBase.showResult(result);
target.add(pageBase.getFeedbackPanel());
}
}
};
}
/**
* Extension values are task-dependent. Therefore, in the future we will probably make
* this behaviour configurable. For the time being we assume that the task template will be
* of "iterative task handler" type and so it will expect mext:objectQuery extension property.
*
* FIXME
*/
@NotNull
private Item<PrismValue, ItemDefinition> prepareExtensionValues(Collection<String> oids) throws SchemaException {
PrismContext prismContext = pageBase.getPrismContext();
ObjectQuery objectQuery = prismContext.queryFor(ObjectType.class).id(oids.toArray(new String[0])).build();
QueryType queryBean = pageBase.getQueryConverter().createQueryType(objectQuery);
PrismContainerDefinition<?> extDef = PrismContext.get().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(TaskType.class).findContainerDefinition(TaskType.F_EXTENSION);
ItemDefinition<Item<PrismValue, ItemDefinition>> def = extDef != null ? extDef.findItemDefinition(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY) : null;
if (def == null) {
throw new SchemaException("No definition of " + SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY + " in the extension");
}
Item<PrismValue, ItemDefinition> extensionItem = def.instantiate();
extensionItem.add(prismContext.itemFactory().createValue(queryBean));
return extensionItem;
}
});
});
return menuItems;
}
use of com.evolveum.midpoint.web.component.util.SelectableBean in project midpoint by Evolveum.
the class PageTasks method addCustomColumns.
private void addCustomColumns(List<IColumn<SelectableBean<TaskType>, String>> columns) {
columns.add(2, new ObjectReferenceColumn<>(createStringResource("pageTasks.task.objectRef"), SelectableBeanImpl.F_VALUE + "." + TaskType.F_OBJECT_REF.getLocalPart()) {
private static final long serialVersionUID = 1L;
@Override
public IModel<ObjectReferenceType> extractDataModel(IModel<SelectableBean<TaskType>> rowModel) {
SelectableBean<TaskType> bean = rowModel.getObject();
return Model.of(bean.getValue().getObjectRef());
}
});
columns.add(4, new AbstractExportableColumn<>(createStringResource("pageTasks.task.currentRunTime"), TaskType.F_COMPLETION_TIMESTAMP.getLocalPart()) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<ICellPopulator<SelectableBean<TaskType>>> item, final String componentId, final IModel<SelectableBean<TaskType>> rowModel) {
DateLabelComponent dateLabel = new DateLabelComponent(componentId, new IModel<>() {
private static final long serialVersionUID = 1L;
@Override
public Date getObject() {
Date date = getCurrentRuntime(rowModel);
SelectableBean<TaskType> task = rowModel.getObject();
if (task.getValue().getExecutionState() == TaskExecutionStateType.CLOSED && date != null) {
((DateLabelComponent) item.get(componentId)).setBefore(createStringResource("pageTasks.task.closedAt").getString() + " ");
} else if (date != null) {
((DateLabelComponent) item.get(componentId)).setBefore(WebComponentUtil.formatDurationWordsForLocal(date.getTime(), true, true, PageTasks.this));
}
return date;
}
}, WebComponentUtil.getShortDateTimeFormat(PageTasks.this));
item.add(dateLabel);
}
@Override
public IModel<String> getDataModel(IModel<SelectableBean<TaskType>> rowModel) {
SelectableBean<TaskType> task = rowModel.getObject();
Date date = getCurrentRuntime(rowModel);
String displayValue = "";
if (date != null) {
if (task.getValue().getExecutionState() == TaskExecutionStateType.CLOSED) {
displayValue = createStringResource("pageTasks.task.closedAt").getString() + WebComponentUtil.getShortDateTimeFormattedValue(date, PageTasks.this);
} else {
displayValue = WebComponentUtil.formatDurationWordsForLocal(date.getTime(), true, true, PageTasks.this);
}
}
return Model.of(displayValue);
}
});
columns.add(5, new AbstractExportableColumn<>(createStringResource("pageTasks.task.scheduledToRunAgain")) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<SelectableBean<TaskType>>> item, String componentId, final IModel<SelectableBean<TaskType>> rowModel) {
item.add(new Label(componentId, () -> createScheduledToRunAgain(rowModel)));
}
@Override
public IModel<String> getDataModel(IModel<SelectableBean<TaskType>> rowModel) {
return Model.of(createScheduledToRunAgain(rowModel));
}
});
}
use of com.evolveum.midpoint.web.component.util.SelectableBean in project midpoint by Evolveum.
the class ResourceTasksPanel method initLayout.
protected void initLayout() {
final MainObjectListPanel<TaskType> tasksPanel = new MainObjectListPanel<>(ID_TASKS_TABLE, TaskType.class, null) {
private static final long serialVersionUID = 1L;
@Override
protected UserProfileStorage.TableId getTableId() {
return UserProfileStorage.TableId.PAGE_RESOURCE_TASKS_PANEL;
}
@Override
protected ISelectableDataProvider<TaskType, SelectableBean<TaskType>> createProvider() {
return createSelectableBeanObjectDataProvider(() -> createResourceTasksQuery(), null);
}
@Override
protected List<InlineMenuItem> createInlineMenu() {
return null;
}
@Override
protected void newObjectPerformed(AjaxRequestTarget target, AssignmentObjectRelation relation, CompiledObjectCollectionView collectionView) {
if (collectionView == null) {
collectionView = getObjectCollectionView();
}
List<ObjectReferenceType> archetypeRef = ObjectCollectionViewUtil.getArchetypeReferencesList(collectionView);
try {
PrismContext prismContext = getPrismContext();
PrismObjectDefinition<TaskType> def = prismContext.getSchemaRegistry().findObjectDefinitionByType(TaskType.COMPLEX_TYPE);
PrismObject<TaskType> obj = def.instantiate();
TaskType newTask = obj.asObjectable();
ObjectReferenceType resourceRef = new ObjectReferenceType();
resourceRef.setOid(ResourceTasksPanel.this.getModelObject().getOid());
resourceRef.setType(ResourceType.COMPLEX_TYPE);
newTask.setObjectRef(resourceRef);
WebComponentUtil.initNewObjectWithReference(getPageBase(), newTask, archetypeRef);
} catch (SchemaException ex) {
getPageBase().getFeedbackMessages().error(ResourceTasksPanel.this, ex.getUserFriendlyMessage());
target.add(getPageBase().getFeedbackPanel());
}
}
@Override
protected List<IColumn<SelectableBean<TaskType>, String>> createDefaultColumns() {
return ColumnUtils.getDefaultTaskColumns();
}
@Override
protected List<CompiledObjectCollectionView> getNewObjectInfluencesList() {
List<CompiledObjectCollectionView> newObjectInfluencesList = super.getNewObjectInfluencesList();
List<CompiledObjectCollectionView> filteredInfluencesList = new ArrayList<>();
if (newObjectInfluencesList != null) {
newObjectInfluencesList.forEach(influence -> {
if (influence.getCollection() != null && influence.getCollection().getCollectionRef() != null && ArrayUtils.contains(resourceTaskArchetypeOids, influence.getCollection().getCollectionRef().getOid())) {
filteredInfluencesList.add(influence);
}
});
}
return filteredInfluencesList;
}
};
tasksPanel.setAdditionalBoxCssClasses(GuiStyleConstants.CLASS_OBJECT_TASK_BOX_CSS_CLASSES);
add(tasksPanel);
AjaxButton runNow = new AjaxButton(ID_RUN_NOW, getPageBase().createStringResource("pageTaskEdit.button.runNow")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
List<String> oids = createOidList(getTaskListPanel().getSelectedRealObjects());
if (!oids.isEmpty()) {
OperationResult result = TaskOperationUtils.runNowPerformed(oids, getPageBase());
getPageBase().showResult(result);
} else {
noTasksSelected();
}
target.add(getPageBase().getFeedbackPanel());
}
};
add(runNow);
AjaxButton resume = new AjaxButton(ID_RESUME, getPageBase().createStringResource("pageTaskEdit.button.resume")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
List<TaskType> tasks = getTaskListPanel().getSelectedRealObjects();
if (!tasks.isEmpty()) {
OperationResult result = TaskOperationUtils.resumeTasks(tasks, getPageBase());
getPageBase().showResult(result);
} else {
noTasksSelected();
}
target.add(getPageBase().getFeedbackPanel());
}
};
add(resume);
AjaxButton suspend = new AjaxButton(ID_SUSPEND, getPageBase().createStringResource("pageTaskEdit.button.suspend")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
List<TaskType> tasks = getTaskListPanel().getSelectedRealObjects();
if (!tasks.isEmpty()) {
OperationResult result = TaskOperationUtils.suspendTasks(tasks, getPageBase());
getPageBase().showResult(result);
} else {
noTasksSelected();
}
target.add(getPageBase().getFeedbackPanel());
}
};
add(suspend);
}
Aggregations