Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Evolveum/midpoint
- Loading branch information
Showing
6 changed files
with
221 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...min-gui/src/main/java/com/evolveum/midpoint/web/component/input/TwoStateBooleanPanel.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
126 changes: 126 additions & 0 deletions
126
...min-gui/src/main/java/com/evolveum/midpoint/web/component/input/TwoStateBooleanPanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |