use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class OrgTreePanel method initLayout.
private void initLayout(ModelServiceLocator serviceLocator) {
WebMarkupContainer treeHeader = new WebMarkupContainer(ID_TREE_HEADER);
treeHeader.setOutputMarkupId(true);
add(treeHeader);
String title = StringUtils.isEmpty(treeTitleKey) ? "TreeTablePanel.hierarchy" : treeTitleKey;
Label treeTitle = new Label(ID_TREE_TITLE, createStringResource(title));
treeHeader.add(treeTitle);
List<InlineMenuItem> actions = createTreeMenu();
DropdownButtonDto model = new DropdownButtonDto(null, "fa fa-cog", null, actions);
DropdownButtonPanel treeMenu = new DropdownButtonPanel(ID_TREE_MENU, model) {
private static final long serialVersionUID = 1L;
@Override
protected String getSpecialButtonClass() {
return "btn-default";
}
@Override
protected boolean visibleCaret() {
return false;
}
};
treeMenu.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return !actions.isEmpty();
}
});
treeMenu.setOutputMarkupId(true);
treeMenu.setOutputMarkupPlaceholderTag(true);
treeHeader.add(treeMenu);
ISortableTreeProvider provider = new OrgTreeProvider(this, getModel(), preselecteOrgsList) {
@Override
protected ObjectFilter getCustomFilter() {
return OrgTreePanel.this.getCustomFilter();
}
};
WebMarkupContainer treeContainer = new WebMarkupContainer(ID_TREE_CONTAINER) {
private static final long serialVersionUID = 1L;
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
// method computes height based on document.innerHeight() -
// screen height;
Component form = OrgTreePanel.this.getParent().get("memberPanel");
if (form != null) {
// TODO fix
// response.render(OnDomReadyHeaderItem.forScript(
// "updateHeight('" + getMarkupId() + "', ['#" + form.getMarkupId() + "'], ['#"
// + OrgTreePanel.this.get(ID_TREE_HEADER).getMarkupId() + "'])"));
}
}
};
add(treeContainer);
TreeStateModel treeStateMode = new TreeStateModel(this, provider, getOrgTreeStateStorage()) {
private static final long serialVersionUID = 1L;
@Override
public Set<TreeSelectableBean<OrgType>> getExpandedItems() {
return OrgTreePanel.this.getExpandedItems(getOrgTreeStateStorage());
}
@Override
public Set<TreeSelectableBean<OrgType>> getCollapsedItems() {
return OrgTreePanel.this.getCollapsedItems(getOrgTreeStateStorage());
}
@Override
public void setCollapsedItems(TreeStateSet items) {
OrgTreePanel.this.setCollapsedItems(null, getOrgTreeStateStorage());
}
};
contentPannels = new ArrayList<OrgTreeFolderContent>();
MidpointNestedTree tree = new MidpointNestedTree(ID_TREE, provider, treeStateMode) {
@Override
protected Component newContentComponent(String id, IModel<TreeSelectableBean<OrgType>> model) {
OrgTreeFolderContent contentPannel = new OrgTreeFolderContent(id, model, selectable, selected, this, getOrgTreeStateStorage()) {
@Override
protected void selectTreeItemPerformed(TreeSelectableBean<OrgType> selected, AjaxRequestTarget target) {
OrgTreePanel.this.selectTreeItemPerformed(selected, target);
}
@Override
protected IModel<Boolean> getCheckboxModel(IModel<TreeSelectableBean<OrgType>> org) {
return OrgTreePanel.this.getCheckBoxValueModel(org);
}
@Override
protected void onUpdateCheckbox(AjaxRequestTarget target) {
selected = getModel();
onOrgTreeCheckBoxSelectionPerformed(target, selected);
}
@Override
protected IModel<List<InlineMenuItem>> createInlineMenuItemsModel() {
return new ReadOnlyModel<>(() -> createTreeChildrenMenuInternal(model.getObject(), serviceLocator.getCompiledGuiProfile()));
}
};
contentPannels.add(contentPannel);
return contentPannel;
}
@Override
public void collapse(TreeSelectableBean<OrgType> collapsedItem) {
super.collapse(collapsedItem);
Set<TreeSelectableBean<OrgType>> items = OrgTreePanel.this.getExpandedItems(getOrgTreeStateStorage());
if (items != null && items.contains(collapsedItem)) {
items.remove(collapsedItem);
}
OrgTreePanel.this.setExpandedItems((TreeStateSet) items, getOrgTreeStateStorage());
OrgTreePanel.this.addCollapsedItem(collapsedItem, getOrgTreeStateStorage());
}
@Override
public void expand(TreeSelectableBean<OrgType> expandedItem) {
super.expand(expandedItem);
Set<TreeSelectableBean<OrgType>> items = OrgTreePanel.this.getCollapsedItems(getOrgTreeStateStorage());
if (items != null && items.contains(expandedItem)) {
items.remove(expandedItem);
}
OrgTreePanel.this.setCollapsedItems((TreeStateSet) items, getOrgTreeStateStorage());
OrgTreePanel.this.addExpandedItem(expandedItem, getOrgTreeStateStorage());
}
};
tree.setItemReuseStrategy(new ReuseIfModelsEqualStrategy());
tree.setOutputMarkupId(true);
tree.add(new WindowsTheme());
treeContainer.add(tree);
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class MainMenuPanel method createSubmenu.
private void createSubmenu(final ListItem<MenuItem> listItem) {
IModel<MenuItem> menuItem = listItem.getModel();
listItem.add(AttributeModifier.replace("class", new ReadOnlyModel<>(() -> {
if (menuItem.getObject().isMenuActive(getPageBase())) {
return "active";
}
return null;
})));
Link<String> subLink = new Link<String>(ID_SUB_LINK) {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
menuItemPerformed(menuItem.getObject());
}
};
listItem.add(subLink);
WebMarkupContainer subLinkIcon = new WebMarkupContainer(ID_SUB_LINK_ICON);
subLinkIcon.add(AttributeAppender.append("class", new PropertyModel<>(menuItem, MainMenuItem.F_ICON_CLASS)));
subLink.add(subLinkIcon);
Label subLabel = new Label(ID_SUB_LABEL, new StringResourceModel("${nameModel}", menuItem).setDefaultValue(new PropertyModel<>(menuItem, "nameModel")));
subLink.add(subLabel);
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class CorrelationContextPanel method initLayout.
@Override
protected void initLayout() {
IModel<CorrelationContextDto> correlationCtxModel = createCorrelationContextModel();
ListView<String> headers = new ListView<>(ID_HEADERS, new PropertyModel<>(correlationCtxModel, F_OPTION_HEADERS)) {
@Override
protected void populateItem(ListItem<String> item) {
item.add(new Label(ID_HEADER, item.getModel()));
}
};
add(headers);
ListView<CorrelationOptionDto> actions = new ListView<>(ID_ACTIONS, new PropertyModel<>(correlationCtxModel, CorrelationContextDto.F_CORRELATION_OPTIONS)) {
@Override
protected void populateItem(ListItem<CorrelationOptionDto> item) {
AjaxButton actionButton = new AjaxButton(ID_ACTION) {
@Override
public void onClick(AjaxRequestTarget target) {
CaseType correlationCase = getObjectDetailsModels().getObjectType();
WorkItemId workItemId = WorkItemId.of(correlationCase.getWorkItem().get(0));
AbstractWorkItemOutputType output = new AbstractWorkItemOutputType().outcome(item.getModelObject().getIdentifier());
Task task = getPageBase().createSimpleTask("DecideCorrelation");
OperationResult result = task.getResult();
try {
getPageBase().getCaseService().completeWorkItem(workItemId, output, task, result);
result.computeStatusIfUnknown();
} catch (Throwable e) {
result.recordFatalError("Cannot finish correlation process, " + e.getMessage(), e);
}
getPageBase().showResult(result);
target.add(getPageBase().getFeedbackPanel());
}
};
actionButton.add(new Label(ID_ACTION_LABEL, item.getModelObject().isNewOwner() ? TEXT_CREATE_NEW : TEXT_CORRELATE));
item.add(actionButton);
}
};
add(actions);
ListView<CorrelationOptionDto> referenceIds = new ListView<>(ID_NAMES, new PropertyModel<>(correlationCtxModel, CorrelationContextDto.F_CORRELATION_OPTIONS)) {
@Override
protected void populateItem(ListItem<CorrelationOptionDto> item) {
// A full-object reference to the candidate owner
ReadOnlyModel<ObjectReferenceType> referenceModel = new ReadOnlyModel<>(() -> {
CorrelationOptionDto optionDto = item.getModelObject();
if (!optionDto.isNewOwner()) {
return ObjectTypeUtil.createObjectRefWithFullObject(optionDto.getObject());
} else {
// GUI cannot currently open object that does not exist in the repository.
return null;
}
});
item.add(new LinkedReferencePanel<>(ID_NAME, referenceModel));
}
};
add(referenceIds);
ListView<CorrelationPropertyDefinition> rows = new ListView<>(ID_ROWS, new PropertyModel<>(correlationCtxModel, CorrelationContextDto.F_CORRELATION_PROPERTIES)) {
@Override
protected void populateItem(ListItem<CorrelationPropertyDefinition> item) {
// First column contains the property name
item.add(new Label(ID_ATTR_NAME, new PropertyModel<>(item.getModel(), CorrelationPropertyDefinition.F_DISPLAY_NAME)));
// Here are columns for values for individual options
item.add(createColumnsForPropertyRow(correlationCtxModel, item));
}
};
add(rows);
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class DisplayNamePanel method createHeaderModel.
protected IModel<String> createHeaderModel() {
// TODO: align with DisplayNameModel
return new ReadOnlyModel<>(() -> {
if (getModelObject() == null) {
return "";
}
if (ObjectType.class.isAssignableFrom(getModelObject().getClass())) {
return WebComponentUtil.getEffectiveName((ObjectType) getModelObject(), AbstractRoleType.F_DISPLAY_NAME);
}
if (isObjectPolicyConfigurationType()) {
QName typeValue = WebComponentUtil.getValue(getModel().getObject().asPrismContainerValue(), ObjectPolicyConfigurationType.F_TYPE, QName.class);
ObjectReferenceType objectTemplate = ((ObjectPolicyConfigurationType) getModel().getObject()).getObjectTemplateRef();
if (objectTemplate == null || objectTemplate.getTargetName() == null) {
return "";
}
String objectTemplateNameValue = objectTemplate.getTargetName().toString();
StringBuilder sb = new StringBuilder();
if (typeValue != null) {
sb.append(typeValue.getLocalPart()).append(" - ");
}
sb.append(objectTemplateNameValue);
return sb.toString();
}
PrismProperty<?> name = getModelObject().asPrismContainerValue().findProperty(ObjectType.F_NAME);
if (name == null || name.isEmpty()) {
return "";
}
if (QNameUtil.match(DOMUtil.XSD_STRING, name.getDefinition().getTypeName())) {
return (String) name.getRealValue();
} else if (QNameUtil.match(PolyStringType.COMPLEX_TYPE, name.getDefinition().getTypeName())) {
return WebComponentUtil.getTranslatedPolyString((PolyString) name.getRealValue());
}
return name.getRealValue().toString();
});
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class ImagePanel method initLayout.
private void initLayout() {
Label image = new Label(ID_IMAGE);
image.add(AttributeModifier.replace("class", new PropertyModel<>(getModel(), "icon.cssClass")));
image.add(AttributeModifier.replace("title", new PropertyModel<>(getModel(), "tooltip.orig")));
image.add(AttributeAppender.append("style", new ReadOnlyModel<>(() -> StringUtils.isNotBlank(getColor()) ? "color: " + getColor() + ";" : "")));
image.setOutputMarkupId(true);
image.add(new VisibleBehaviour(() -> getModelObject() != null && getModelObject().getIcon() != null && StringUtils.isNotEmpty(getModelObject().getIcon().getCssClass())));
add(image);
ExternalImage customLogoImgSrc = new ExternalImage(ID_IMAGE_SRC, WebComponentUtil.getIconUrlModel(getModelObject() != null ? getModelObject().getIcon() : null));
customLogoImgSrc.setOutputMarkupId(true);
customLogoImgSrc.add(new VisibleBehaviour(() -> getModelObject() != null && getModelObject().getIcon() != null && StringUtils.isNotEmpty(getModelObject().getIcon().getImageUrl())));
add(customLogoImgSrc);
}
Aggregations