Skip to content

Commit

Permalink
displayName for prismReferenceDefinition - updating schema + parsing,…
Browse files Browse the repository at this point in the history
… small clean up in text formatting...
  • Loading branch information
katkav committed Sep 7, 2015
1 parent 241b1df commit c6b41b0
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 241 deletions.
Expand Up @@ -19,9 +19,7 @@
<wicket:panel>
<div wicket:id="showPopup" />

<label class="control-label" wicket:id="label" />

<div wicket:id="textWrapper">
<div wicket:id="textWrapper">
<div class="input-group input-group-sm">
<span class="input-group-btn">
<button wicket:id="edit" class="btn btn-primary" type="button">
Expand Down
Expand Up @@ -28,8 +28,12 @@
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.configuration.component.ChooseTypeDialog;
import com.evolveum.midpoint.web.page.admin.roles.component.UserOrgReferenceChoosePanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

public class ValueChoosePanel <T, C extends ObjectType> extends SimplePanel<T> {

Expand All @@ -49,37 +53,17 @@ public class ValueChoosePanel <T, C extends ObjectType> extends SimplePanel<T> {

private static final String CLASS_MULTI_VALUE = "multivalue-form";

public ValueChoosePanel(String id, IModel<T> value, IModel<String> label, String labelSize,
String textSize, boolean required, Class<C> type) {
public ValueChoosePanel(String id, IModel<T> value, boolean required, Class<C> type) {
super(id, value);
setOutputMarkupId(true);

initLayout(value, label, labelSize, textSize, required, type);
initLayout(value, required, type);
}

private void initLayout(final IModel<T> value, final IModel<String> label, final String labelSize,
final String textSize, final boolean required, Class<C> type) {

Label l = new Label(ID_LABEL, label);

if (StringUtils.isNotEmpty(labelSize)) {
l.add(AttributeAppender.prepend("class", labelSize));
}
add(l);
private void initLayout(final IModel<T> value, final boolean required, Class<C> type) {


WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
textWrapper.add(AttributeAppender.prepend("class", new AbstractReadOnlyModel<String>() {

@Override
public String getObject() {
StringBuilder sb = new StringBuilder();
if (StringUtils.isNotEmpty(textSize)) {
sb.append(textSize).append(' ');
}

return sb.toString();
}
}));

TextField text = new TextField<>(ID_TEXT, createTextModel(value));
text.add(new AjaxFormComponentUpdatingBehavior("onblur") {
Expand All @@ -89,8 +73,6 @@ protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
});
text.setRequired(required);
text.setEnabled(false);
text.add(AttributeAppender.replace("placeholder", label));
text.setLabel(label);
textWrapper.add(text);

FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ComponentFeedbackMessageFilter(text));
Expand All @@ -117,11 +99,23 @@ protected T createNewEmptyItem() throws InstantiationException, IllegalAccessExc
protected void replaceIfEmpty(Object object) {
boolean added = false;
ObjectReferenceType ort = ObjectTypeUtil.createObjectRef((ObjectType) object);
ort.setTargetName(((ObjectType) object).getName());
getModel().setObject((T)ort.asReferenceValue());

}

protected void initDialog(final Class<C> type) {

if (FocusType.class.equals(type)){
initUserOrgDialog();
} else {
initGenericDialog(type);


}
}

private void initGenericDialog(Class<C> type){
ModalWindow dialog = new ChooseTypeDialog(MODAL_ID_CHOOSE_PANEL, type) {

@Override
Expand All @@ -141,7 +135,31 @@ public boolean isSearchEnabled() {
};
add(dialog);
}

private void initUserOrgDialog(){
ModalWindow dialog = new ChooseTypeDialog(MODAL_ID_CHOOSE_PANEL, UserType.class){

@Override
protected void chooseOperationPerformed(AjaxRequestTarget target, ObjectType object){
choosePerformed(target, (C)object);
}

@Override
protected WebMarkupContainer createExtraContentContainer(String extraContentId) {
return new UserOrgReferenceChoosePanel(extraContentId, Boolean.FALSE){

@Override
protected void onReferenceTypeChangePerformed(AjaxRequestTarget target, Boolean newValue) {
updateTableByTypePerformed(target, Boolean.FALSE.equals(newValue) ? UserType.class : OrgType.class);
}
};
}
};
add(dialog);
}



protected ObjectQuery createChooseQuery() {
return null;
}
Expand All @@ -155,19 +173,13 @@ protected String getOffsetClass() {
}

protected IModel<String> createTextModel(final IModel<T> model) {
return new IModel<String>() {
@Override
public String getObject() {
T obj = model.getObject();
return obj != null ? obj.toString() : null;
}
return new AbstractReadOnlyModel<String>() {

@Override
public void setObject(String object) {
}
public String getObject() {
PrismReferenceValue ort = (PrismReferenceValue) model.getObject();

@Override
public void detach() {
return ort == null ? null : (ort.getTargetName() != null ? ort.getTargetName().getOrig() : ort.getOid());
}
};
}
Expand Down Expand Up @@ -200,11 +212,7 @@ protected void choosePerformed(AjaxRequestTarget target, C object) {
target.add(this);
}

// protected void replaceIfEmpty(Object object){
// List<T> objects = getModelObject();
// objects.add((T)object);
// }


protected boolean isObjectUnique(C object) {

// for(T o: ){
Expand All @@ -219,24 +227,6 @@ protected boolean isObjectUnique(C object) {
return true;
}

// protected void removeValuePerformed(AjaxRequestTarget target, ListItem<T> item) {
// List<T> objects = getModelObject();
// Iterator<T> iterator = objects.iterator();
// while (iterator.hasNext()) {
// T object = iterator.next();
//
// if (object.equals(item.getModelObject())) {
// iterator.remove();
// break;
// }
// }
//
// if (objects.size() == 0) {
// objects.add(createNewEmptyItem());
// }
//
// target.add(this);
// }

/**
* A custom code in form of hook that can be run on event of choosing new
Expand Down
Expand Up @@ -55,6 +55,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationPhaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType;
Expand Down Expand Up @@ -267,21 +268,8 @@ private List<ItemWrapper> createProperties(PageBase pageBase) {
String value = formatAssignmentBrief(assignmentType);

temp.setValue(new PrismPropertyValue<Object>(value));
properties.add(new PropertyWrapper(this, temp, this.isReadonly(), ValueStatus.NOT_CHANGED)); // todo
// this.isReadOnly()
// -
// is
// that
// OK?
// (originally
// it
// was
// the
// default
// behavior
// for
// all
// cases)
// TODO: do this.isReadOnly() - is that OK? (originally it was the default behavior for all cases)
properties.add(new PropertyWrapper(this, temp, this.isReadonly(), ValueStatus.NOT_CHANGED));
}

} else if (isShadowAssociation()) {
Expand Down Expand Up @@ -346,6 +334,11 @@ private List<ItemWrapper> createProperties(PageBase pageBase) {
}
} else if (itemDef instanceof PrismReferenceDefinition){
PrismReferenceDefinition def = (PrismReferenceDefinition) itemDef;

if (FocusType.F_LINK_REF.equals(def.getName())){
continue;
}

PrismReference reference = container.findReference(def.getName());
boolean propertyIsReadOnly;
// decision is based on parent object status, not this
Expand Down Expand Up @@ -378,15 +371,9 @@ private List<ItemWrapper> createProperties(PageBase pageBase) {
}

private boolean isPassword(PrismPropertyDefinition def) {
// in the future, this option could apply as well
return CredentialsType.F_PASSWORD.equals(container.getElementName())
|| CredentialsType.F_PASSWORD.equals(def.getName()); // in the
// future,
// this
// option
// could
// apply
// as
// well
|| CredentialsType.F_PASSWORD.equals(def.getName());
}

private boolean isShadowAssociation() {
Expand Down Expand Up @@ -434,7 +421,7 @@ private boolean hasCapability(PrismPropertyDefinition def) {
return true;
}

// temporary - brutal hack - the following three methods are copied from
// FIXME temporary - brutal hack - the following three methods are copied from
// AddRoleAssignmentAspect - Pavol M.

private String formatAssignmentBrief(AssignmentType assignment) {
Expand Down Expand Up @@ -495,29 +482,6 @@ private static String formatTime(XMLGregorianCalendar time) {
return formatter.format(time.toGregorianCalendar().getTime());
}

// boolean isPropertyVisible(PropertyWrapper property) {
// PrismPropertyDefinition def = property.getItemDefinition();
// if (skipProperty(def) || def.isIgnored() || def.isOperational()) {
// return false;
// }
//
// // we decide not according to status of this container, but according to
// the status of the whole object
// if (object.getStatus() == ContainerStatus.ADDING) {
// return def.canAdd();
// }
//
// // otherwise, object.getStatus() is MODIFYING
//
// if (def.canModify()) {
// return showEmpty(property);
// } else {
// if (def.canRead()) {
// return showEmpty(property);
// }
// return false;
// }
// }

boolean isItemVisible(ItemWrapper item) {
ItemDefinition def = item.getItemDefinition();
Expand Down Expand Up @@ -547,49 +511,8 @@ boolean isItemVisible(ItemWrapper item) {
}
}

// boolean isReferenceVisible(ReferenceWrapper reference){
// PrismReferenceDefinition def = reference.getItemDefinition();
// if (def.isIgnored() || def.isOperational()) {
// return false;
// }
//
// // we decide not according to status of this container, but according to
// the status of the whole object
// if (object.getStatus() == ContainerStatus.ADDING) {
// return def.canAdd();
// }
//
// // otherwise, object.getStatus() is MODIFYING
//
// if (def.canModify()) {
// return showEmpty(reference);
// } else {
// if (def.canRead()) {
// return showEmpty(reference);
// }
// return false;
// }
// }

// private boolean showEmpty(PropertyWrapper property) {
// ObjectWrapper object = getObject();
//
// List<ValueWrapper> values = property.getValues();
// boolean isEmpty = values.isEmpty();
// if (values.size() == 1) {
// ValueWrapper value = values.get(0);
// if (ValueStatus.ADDED.equals(value.getStatus())) {
// isEmpty = true;
// }
// }
//
// return object.isShowEmpty() || !isEmpty;
// }
//
private boolean showEmpty(ItemWrapper item) {
ObjectWrapper object = getObject();
// item.getValues()
// if (item instanceof PropertyWrapper) {
List<ValueWrapper> values = item.getValues();
boolean isEmpty = values.isEmpty();
if (values.size() == 1) {
Expand All @@ -599,9 +522,6 @@ private boolean showEmpty(ItemWrapper item) {
}
}
return object.isShowEmpty() || !isEmpty;
// }

// return object.isShowEmpty();
}

@Override
Expand Down Expand Up @@ -686,6 +606,12 @@ private boolean skipProperty(PrismPropertyDefinition def) {
names.add(ActivationType.F_VALIDITY_STATUS);
// user
names.add(UserType.F_RESULT);
// org and roles
names.add(OrgType.F_APPROVAL_PROCESS);
names.add(OrgType.F_APPROVER_EXPRESSION);
names.add(OrgType.F_AUTOMATICALLY_APPROVED);
names.add(OrgType.F_CONDITION);


for (QName name : names) {
if (name.equals(def.getName())) {
Expand All @@ -699,17 +625,8 @@ private boolean skipProperty(PrismPropertyDefinition def) {
public boolean isReadonly() {
PrismContainerDefinition def = getItemDefinition();
if (def != null) {
return (def.canRead() && !def.canAdd() && !def.canModify()); // todo
// take
// into
// account
// the
// containing
// object
// status
// (adding
// vs.
// modifying)
// todo take into account the containing object status (adding vs. modifying)
return (def.canRead() && !def.canAdd() && !def.canModify());
}
return readonly;
}
Expand Down

0 comments on commit c6b41b0

Please sign in to comment.