Skip to content

Commit

Permalink
Review response uses MultiButtonPanel instead of three DoubleButtonPa…
Browse files Browse the repository at this point in the history
…nels.
  • Loading branch information
mederly committed Jun 9, 2015
1 parent 41d3e5d commit c0a6f63
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 254 deletions.
@@ -0,0 +1,21 @@
<!--
~ Copyright (c) 2010-2015 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.
-->
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<span wicket:id="buttons" />
</wicket:panel>
</html>
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2010-2015 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.data;

import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.data.column.DoubleButtonColumn;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;

/**
* @author shood
* @author mederly
*/
public class MultiButtonPanel<T> extends SimplePanel<T> {

private static final String ID_BUTTONS = "buttons";

int numberOfButtons;

public MultiButtonPanel(String id, int numberOfButtons, IModel<T> model) {
super(id, model);
this.numberOfButtons = numberOfButtons;
createLayout();
}

private void createLayout() {
RepeatingView buttons = new RepeatingView(ID_BUTTONS);
add(buttons);
for (int id = 0; id < numberOfButtons; id++) {
final int finalId = id;
AjaxButton button = new AjaxButton(String.valueOf(finalId), createStringResource(getCaption(finalId))) {
@Override
public void onClick(AjaxRequestTarget target) {
clickPerformed(finalId, target, MultiButtonPanel.this.getModel());
}
@Override
public boolean isEnabled(){
return MultiButtonPanel.this.isButtonEnabled(finalId, MultiButtonPanel.this.getModel());
}
};
button.add(new AttributeAppender("class", getButtonCssClass(finalId)));
buttons.add(button);
buttons.add(new Label("label"+finalId, " "));
}
}

public String getCaption(int id) {
return String.valueOf(id);
}

public boolean isButtonEnabled(int id, IModel<T> model) {
return true;
}

private String getButtonCssClass(int id) {
StringBuilder sb = new StringBuilder();
sb.append(DoubleButtonColumn.BUTTON_BASE_CLASS).append(" ");
sb.append(getButtonColorCssClass(id)).append(" ").append(getButtonSizeCssClass(id));
return sb.toString();
}

public String getButtonSizeCssClass(int id) {
return DoubleButtonColumn.BUTTON_SIZE_CLASS.DEFAULT.toString();
}

public String getButtonColorCssClass(int id) {
return DoubleButtonColumn.BUTTON_COLOR_CLASS.DEFAULT.toString();
}

public void clickPerformed(int id, AjaxRequestTarget target, IModel<T> model) {
}

public AjaxButton getButton(int id){
return (AjaxButton) get(ID_BUTTONS).get(String.valueOf(id));
}

}
@@ -0,0 +1,16 @@
#
# Copyright (c) 2010-2015 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.
#

@@ -0,0 +1,108 @@
/*
* Copyright (c) 2010-2015 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.data.column;

import com.evolveum.midpoint.web.component.data.MultiButtonPanel;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;

import java.io.Serializable;
import java.util.List;

/**
* @author shood
* @author mederly
*/
public class MultiButtonColumn<T extends Serializable> extends AbstractColumn<T, String> {

private MultiButtonPanel panel;

private List<String> captions;
private IModel<T> rowModel;
private int numberOfButtons;

public MultiButtonColumn(IModel<String> displayModel, int numberOfButtons) {
super(displayModel);
this.numberOfButtons = numberOfButtons;
}

@Override
public void populateItem(final Item<ICellPopulator<T>> cellItem, String componentId,
final IModel<T> rowModel) {
this.rowModel = rowModel;

panel = new MultiButtonPanel<T>(componentId, numberOfButtons, rowModel) {

@Override
public String getCaption(int id) {
return MultiButtonColumn.this.getCaption(id);
}

@Override
public boolean isButtonEnabled(int id, IModel<T> model) {
return MultiButtonColumn.this.isButtonEnabled(id, model);
}

@Override
public String getButtonSizeCssClass(int id) {
return MultiButtonColumn.this.getButtonSizeCssClass(id);
}

@Override
public String getButtonColorCssClass(int id) {
return MultiButtonColumn.this.getButtonColorCssClass(id);
}

@Override
public void clickPerformed(int id, AjaxRequestTarget target, IModel<T> model) {
MultiButtonColumn.this.clickPerformed(id, target, model);
}


};
cellItem.add(panel);
}

public boolean isButtonEnabled(int id, IModel<T> model) {
return true;
}

public String getCaption(int id) {
return String.valueOf(id);
}

public void clickPerformed(int id, AjaxRequestTarget target, IModel<T> model) {
}

public String getButtonColorCssClass(int id) {
return DoubleButtonColumn.BUTTON_COLOR_CLASS.DEFAULT.toString();
}

public String getButtonSizeCssClass(int id) {
return DoubleButtonColumn.BUTTON_SIZE_CLASS.SMALL.toString();
}

public MultiButtonPanel getButtonPanel(){
return panel;
}

public IModel<T> getRowModel(){
return rowModel;
}
}
Expand Up @@ -31,6 +31,7 @@
import com.evolveum.midpoint.web.component.data.TablePanel;
import com.evolveum.midpoint.web.component.data.column.DoubleButtonColumn;
import com.evolveum.midpoint.web.component.data.column.DoubleButtonColumn.BUTTON_COLOR_CLASS;
import com.evolveum.midpoint.web.component.data.column.MultiButtonColumn;
import com.evolveum.midpoint.web.component.util.LoadableModel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.PageTemplate;
Expand Down Expand Up @@ -74,6 +75,11 @@
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCasesStatisticsType.F_MARKED_AS_REVOKE_AND_REMEDIED;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCasesStatisticsType.F_WITHOUT_RESPONSE;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType.ACCEPT;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType.DELEGATE;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType.NOT_DECIDED;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType.NO_RESPONSE;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType.REDUCE;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType.REVOKE;

/**
* @author mederly
Expand Down Expand Up @@ -278,100 +284,35 @@ private List<IColumn<CertCaseDto, String>> initColumns() {
column = new PropertyColumn(createStringResource("PageCertCampaign.table.reviewedInStage"), CertCaseDto.F_CURRENT_RESPONSE_STAGE_NUMBER);
columns.add(column);

column = new DoubleButtonColumn<CertCaseDto>(new Model(), null) {

@Override
public String getFirstCap() {
return PageCertCampaign.this.createStringResource(
"PageCertCampaign.menu.accept").getString();
}

@Override
public String getSecondCap() {
return PageCertCampaign.this.createStringResource(
"PageCertCampaign.menu.revoke").getString();
}

@Override
public String getFirstColorCssClass() {
return getDecisionButtonColor(getRowModel(), ACCEPT);
}

@Override
public String getSecondColorCssClass() {
return getDecisionButtonColor(getRowModel(), AccessCertificationResponseType.REVOKE);
}
};
columns.add(column);
column = new DoubleButtonColumn<CertCaseDto>(new Model(), null) {

@Override
public String getFirstCap() {
return PageCertCampaign.this.createStringResource(
"PageCertCampaign.menu.reduce").getString();
}

@Override
public String getSecondCap() {
return PageCertCampaign.this.createStringResource(
"PageCertCampaign.menu.notDecided").getString();
}

@Override
public String getFirstColorCssClass() {
return getDecisionButtonColor(getRowModel(), AccessCertificationResponseType.REDUCE);
}
column = new MultiButtonColumn<CertCaseDto>(new Model(), 6) {

@Override
public String getSecondColorCssClass() {
return getDecisionButtonColor(getRowModel(), AccessCertificationResponseType.NOT_DECIDED);
}

@Override
public boolean isFirstButtonEnabled(IModel<CertCaseDto> model) {
return false;
}

@Override
public boolean isSecondButtonEnabled(IModel<CertCaseDto> model) {
return false;
}
};
columns.add(column);
column = new DoubleButtonColumn<CertCaseDto>(new Model(), null) {

@Override
public String getFirstCap() {
return PageCertCampaign.this.createStringResource(
"PageCertCampaign.menu.delegate").getString();
}
private final String[] captionKeys = {
"PageCertCampaign.menu.accept",
"PageCertCampaign.menu.revoke",
"PageCertCampaign.menu.reduce",
"PageCertCampaign.menu.notDecided",
"PageCertCampaign.menu.delegate",
"PageCertCampaign.menu.noResponse"
};

@Override
public String getSecondCap() {
return PageCertCampaign.this.createStringResource(
"PageCertCampaign.menu.noResponse").getString();
}
private final AccessCertificationResponseType[] responses = {
ACCEPT, REVOKE, REDUCE, NOT_DECIDED, DELEGATE, NO_RESPONSE
};

@Override
public String getFirstColorCssClass() {
return getDecisionButtonColor(getRowModel(), AccessCertificationResponseType.DELEGATE);
public String getCaption(int id) {
return PageCertCampaign.this.createStringResource(captionKeys[id]).getString();
}

@Override
public String getSecondColorCssClass() {
return getDecisionButtonColor(getRowModel(), AccessCertificationResponseType.NO_RESPONSE);
}

@Override
public boolean isFirstButtonEnabled(IModel<CertCaseDto> model) {
public boolean isButtonEnabled(int id, IModel<CertCaseDto> model) {
return false;
}

@Override
public boolean isSecondButtonEnabled(IModel<CertCaseDto> model) {
return false;
public String getButtonColorCssClass(int id) {
return getDecisionButtonColor(getRowModel(), responses[id]);
}

};
columns.add(column);

Expand Down
Expand Up @@ -25,7 +25,7 @@
<div class="checkbox">
<label>
<input type="checkbox" wicket:id="showNotDecidedOnly"/>
<wicket:message key="PageCertDecisions.checkbox.showNotDecidedOnly"/>
<wicket:message key="PageCertDecisions.checkbox.showNoResponseOnly"/>
</label>
</div>
</form>
Expand Down

0 comments on commit c0a6f63

Please sign in to comment.