Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Feb 10, 2015
2 parents a5d1a50 + e82e5fc commit f847cf3
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 6 deletions.
Expand Up @@ -19,6 +19,7 @@
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class AssignmentEditorDto extends SelectableBean implements Comparable<As
public static final String F_RELATION = "relation";
public static final String F_TENANT_REF = "tenantRef";
public static final String F_ALT_NAME = "altName";
public static final String F_IS_ORG_UNIT_MANAGER = "isOrgUnitManager";

private String name;
private String altName;
Expand All @@ -71,6 +73,7 @@ public class AssignmentEditorDto extends SelectableBean implements Comparable<As
private boolean showEmpty = false;
private boolean minimized = true;

private Boolean isOrgUnitManager = Boolean.FALSE;
private AssignmentType newAssignment;
private List<ACAttributeDto> attributes;

Expand Down Expand Up @@ -102,6 +105,23 @@ public AssignmentEditorDto(ObjectType targetObject, AssignmentEditorDtoType type
this.altName = getAlternativeName(assignment);

this.attributes = prepareAssignmentAttributes(assignment, pageBase);
this.isOrgUnitManager = determineUserOrgRelation(assignment);
}

private Boolean determineUserOrgRelation(AssignmentType assignment){
if(!AssignmentEditorDtoType.ORG_UNIT.equals(getType())){
return Boolean.FALSE;
}

if(assignment == null || assignment.getTargetRef() == null || assignment.getTargetRef().getRelation() == null){
return Boolean.FALSE;
}

if(SchemaConstants.ORG_MANAGER.equals(assignment.getTargetRef().getRelation())){
return Boolean.TRUE;
}

return Boolean.FALSE;
}

private List<ACAttributeDto> prepareAssignmentAttributes(AssignmentType assignment, PageBase pageBase){
Expand Down Expand Up @@ -336,6 +356,14 @@ public PrismContainerValue getOldValue() {
}

public PrismContainerValue getNewValue() throws SchemaException {
if(AssignmentEditorDtoType.ORG_UNIT.equals(getType())){
if(isOrgUnitManager()){
newAssignment.getTargetRef().setRelation(SchemaConstants.ORG_MANAGER);
} else {
newAssignment.getTargetRef().setRelation(null);
}
}

//this removes activation element if it's empty
ActivationType activation = newAssignment.getActivation();
if (activation == null || activation.asPrismContainerValue().isEmpty()) {
Expand Down Expand Up @@ -388,6 +416,14 @@ public void setDescription(String description) {
newAssignment.setDescription(description);
}

public Boolean isOrgUnitManager() {
return isOrgUnitManager;
}

public void setOrgUnitManager(Boolean orgUnitManager) {
isOrgUnitManager = orgUnitManager;
}

@Override
public int compareTo(AssignmentEditorDto other) {
Validate.notNull(other, "Can't compare assignment editor dto with null.");
Expand Down Expand Up @@ -441,6 +477,7 @@ public boolean equals(Object o) {

AssignmentEditorDto that = (AssignmentEditorDto) o;

if (isOrgUnitManager != that.isOrgUnitManager) return false;
if (minimized != that.minimized) return false;
if (showEmpty != that.showEmpty) return false;
if (altName != null ? !altName.equals(that.altName) : that.altName != null) return false;
Expand All @@ -467,6 +504,7 @@ public int hashCode() {
result = 31 * result + (tenantRef != null ? tenantRef.hashCode() : 0);
result = 31 * result + (showEmpty ? 1 : 0);
result = 31 * result + (minimized ? 1 : 0);
result = 31 * result + (isOrgUnitManager ? 1 : 0);
result = 31 * result + (newAssignment != null ? newAssignment.hashCode() : 0);
result = 31 * result + (attributes != null ? attributes.hashCode() : 0);
return result;
Expand Down
Expand Up @@ -46,14 +46,14 @@
</div>
</div>
</div>
<div class="row">
<div class="row" wicket:id="relationContainer">
<div class="col-xs-4">
<span><wicket:message key="AssignmentEditorPanel.relation"/></span>
</div>
<div class="col-xs-8">
<div class="row">
<div class="col-xs-9">
<input type="text" class="form-control input-sm" wicket:id="relation"/>
<div wicket:id="relation" />
</div>
</div>
</div>
Expand Down
Expand Up @@ -34,6 +34,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.DateInput;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.component.input.TwoStateBooleanPanel;
import com.evolveum.midpoint.web.component.prism.InputPanel;
import com.evolveum.midpoint.web.component.util.LoadableModel;
import com.evolveum.midpoint.web.component.util.SimplePanel;
Expand All @@ -57,7 +58,6 @@
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.AbstractReadOnlyModel;
Expand Down Expand Up @@ -95,6 +95,7 @@ public class AssignmentEditorPanel extends SimplePanel<AssignmentEditorDto> {
private static final String ID_ACTIVATION_BLOCK = "activationBlock";
private static final String ID_BODY = "body";
private static final String ID_DESCRIPTION = "description";
private static final String ID_RELATION_CONTAINER = "relationContainer";
private static final String ID_RELATION = "relation";
private static final String ID_ADMINISTRATIVE_STATUS = "administrativeStatus";
private static final String ID_VALID_FROM = "validFrom";
Expand Down Expand Up @@ -319,9 +320,30 @@ private void initBodyLayout(WebMarkupContainer body) {
new PropertyModel<String>(getModel(), AssignmentEditorDto.F_DESCRIPTION));
body.add(description);

TextField relation = new TextField<>(ID_RELATION, new PropertyModel<String>(getModel(), AssignmentEditorDto.F_RELATION));
relation.setEnabled(false);
body.add(relation);
WebMarkupContainer relationContainer = new WebMarkupContainer(ID_RELATION_CONTAINER);
relationContainer.setOutputMarkupId(true);
relationContainer.setOutputMarkupPlaceholderTag(true);
relationContainer.add(new VisibleEnableBehaviour(){

@Override
public boolean isVisible() {
AssignmentEditorDto dto = getModel().getObject();
if(dto != null){
if(AssignmentEditorDtoType.ORG_UNIT.equals(dto.getType())){
return true;
}
}

return false;
}
});
body.add(relationContainer);

TwoStateBooleanPanel relation = new TwoStateBooleanPanel(ID_RELATION, new PropertyModel<Boolean>(getModel(), AssignmentEditorDto.F_IS_ORG_UNIT_MANAGER),
"AssignmentEditorPanel.member", "AssignmentEditorPanel.manager", null);
relation.setOutputMarkupId(true);
relation.setOutputMarkupPlaceholderTag(true);
relationContainer.add(relation);

WebMarkupContainer tenantRefContainer = new WebMarkupContainer(ID_CONTAINER_TENANT_REF);
ChooseTypePanel tenantRef = new ChooseTypePanel(ID_TENANT_CHOOSER,
Expand Down
Expand Up @@ -28,6 +28,8 @@ AssignmentEditorPanel.tenantRef=Tenant
AssignmentEditorPanel.name.focus=(focus mapping)
AssignmentEditorPanel.name.noTarget=(no target)
AssignmentEditorPanel.showMore=Show more
AssignmentEditorPanel.member=Member
AssignmentEditorPanel.manager=Manager
AssignmentEditorPanel.targetError=Assignment target was not found. Either target oid is malformed or target object does not exist.


@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2013 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<wicket:panel>

<div class="btn-group btn-group-sm" data-toggle="buttons-radio">
<button wicket:id="optionOne" type="button" class="btn"></button>
<button wicket:id="optionTwo" type="button" class="btn"></button>
</div>

</wicket:panel>
</html>
@@ -0,0 +1,126 @@
/*
* Copyright (c) 2010-2013 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.web.component.input;

import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;

/**
* Use this component when two-state widget is needed (e.g. boolean attributes - true/false)
* Bear in mind that:
* - first button represents FALSE
* - second button represents TRUE
*
* @author shood
* */
public class TwoStateBooleanPanel extends SimplePanel<Boolean>{

private static final String ID_BUTTON_ONE = "optionOne";
private static final String ID_BUTTON_TWO = "optionTwo";

private static final String DEFAULT_BUTTON_CLASS = "btn-default";

public TwoStateBooleanPanel(String id, IModel<Boolean> model){
this(id, model, null, null, null);
}

public TwoStateBooleanPanel(String id, IModel<Boolean> model, String optionOneLabel,
String optionTwoLabel, String buttonCssClass){
super(id, model);

setOutputMarkupId(true);
initLayout(optionOneLabel, optionTwoLabel, buttonCssClass);
}

protected void initLayout(final String optionOneLabel, final String optionTwoLabel, final String buttonCssClass){

AjaxButton buttonFalse = new AjaxButton(ID_BUTTON_ONE, new AbstractReadOnlyModel<String>() {

@Override
public String getObject() {
if(optionOneLabel == null){
return getString("ThreeStateBooleanPanel.false");
} else {
return getString(optionOneLabel);
}
}
}) {

@Override
public void onClick(AjaxRequestTarget target) {
stateChanged(Boolean.FALSE, target);
}
};
buttonFalse.setOutputMarkupId(true);
buttonFalse.add(prepareButtonCssClass(buttonCssClass));
buttonFalse.add(prepareActiveButtonAppender(Boolean.FALSE));
add(buttonFalse);

AjaxButton buttonTrue = new AjaxButton(ID_BUTTON_TWO, new AbstractReadOnlyModel<String>() {

@Override
public String getObject() {
if(optionTwoLabel == null){
return getString("ThreeStateBooleanPanel.true");
} else {
return getString(optionTwoLabel);
}
}
}) {

@Override
public void onClick(AjaxRequestTarget target) {
stateChanged(Boolean.TRUE, target);
}
};
buttonTrue.setOutputMarkupId(true);
buttonTrue.add(prepareButtonCssClass(buttonCssClass));
buttonTrue.add(prepareActiveButtonAppender(Boolean.TRUE));
add(buttonTrue);
}

private void stateChanged(Boolean newValue, AjaxRequestTarget target){
getModel().setObject(newValue);
target.add(this);
}

private AttributeAppender prepareActiveButtonAppender(final Boolean value){
return new AttributeAppender("class", new AbstractReadOnlyModel<String>() {

@Override
public String getObject() {
if(getModel() != null){
return getModel().getObject() == value ? " active" : null;
}

return null;
}
});
}

private AttributeAppender prepareButtonCssClass(String cssClass){
if(cssClass == null){
return new AttributeAppender("class", " " + DEFAULT_BUTTON_CLASS);
} else {
return new AttributeAppender("class", " " + cssClass);
}
}
}

0 comments on commit f847cf3

Please sign in to comment.