Skip to content

Commit

Permalink
ReportPopup - resourceName, change from autocomplete to select component
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-lizner committed Aug 24, 2015
1 parent 90d4c82 commit bbcd465
Showing 1 changed file with 66 additions and 64 deletions.
Expand Up @@ -20,8 +20,8 @@
import com.evolveum.midpoint.web.component.DateInput;
import com.evolveum.midpoint.web.component.data.TablePanel;
import com.evolveum.midpoint.web.component.data.column.EditablePropertyColumn;
import com.evolveum.midpoint.web.component.input.AutoCompleteTextPanel;
import com.evolveum.midpoint.web.component.input.DatePanel;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.component.input.TextPanel;
import com.evolveum.midpoint.web.component.prism.InputPanel;
import com.evolveum.midpoint.web.component.util.ListDataProvider;
Expand Down Expand Up @@ -55,97 +55,98 @@
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

public class RunReportPopupPanel extends SimplePanel<ReportDto> {

@SpringBean(name = "modelController")
private ModelService modelService;
@SpringBean(name = "taskManager")
private TaskManager taskManager;
private static final Trace LOGGER = TraceManager.getTrace(RunReportPopupPanel.class);

private static final String DOT_CLASS = RunReportPopupPanel.class.getName() + ".";
private static final String OPERATION_LOAD_RESOURCES = DOT_CLASS + "createResourceList";

private static final String ID_MAIN_FORM = "mainForm";

private static final String ID_NAME_LABEL = "label";
private static final String ID_RUN = "runReport";

private static final String ID_LABEL_SIZE = "col-md-4";
private static final String ID_INPUT_SIZE = "col-md-8";

private static final String ID_PARAMETERS_TABLE = "paramTable";

private IModel<ReportDto> reportModel;
private ReportType reportType;

public void setReportType(ReportType reportType) {
this.reportType = reportType;

if (getParametersTable() != null) {
replace(createTablePanel());
}
}

public RunReportPopupPanel(String id) {
super(id);
}

@Override
protected void initLayout() {

TablePanel table = createTablePanel();
add(table);

AjaxButton addButton = new AjaxButton(ID_RUN,
createStringResource("runReportPopupContent.button.run")) {

@Override
public void onClick(AjaxRequestTarget target) {
runConfirmPerformed(target, reportModel, getParameters());
}
};
add(addButton);

}

private TablePanel createTablePanel() {
reportModel = new LoadableModel<ReportDto>(false) {

@Override
protected ReportDto load() {
return new ReportDto(reportType, true);
}
};

ISortableDataProvider<JasperReportParameterDto, String> provider = new ListDataProvider<>(this,
new PropertyModel<List<JasperReportParameterDto>>(reportModel, "jasperReportDto.parameters"));
TablePanel table = new TablePanel<>(ID_PARAMETERS_TABLE, provider, initParameterColumns());
table.setOutputMarkupId(true);
table.setShowPaging(true);
return table;
}

private TablePanel getParametersTable() {
return (TablePanel) get(ID_PARAMETERS_TABLE);
}

private List<JasperReportParameterDto> getParameters() {
TablePanel table = getParametersTable();
List<JasperReportParameterDto> params = ((ListDataProvider) table.getDataTable().getDataProvider()).getAvailableData();
return params;
}

private List<IColumn<JasperReportParameterDto, String>> initParameterColumns() {
List<IColumn<JasperReportParameterDto, String>> columns = new ArrayList<>();

//parameter name column
columns.add(new AbstractColumn(createStringResource("runReportPopupContent.param.name")) {

@Override
public void populateItem(Item item, String componentId, IModel model) {
String paramValue = new PropertyModel<String>(model, "name").getObject();
Expand All @@ -156,7 +157,7 @@ public void populateItem(Item item, String componentId, IModel model) {

//parameter class column
columns.add(new AbstractColumn(createStringResource("runReportPopupContent.param.class")) {

@Override
public void populateItem(Item item, String componentId, IModel model) {
//Do not show whole parameter class name as this is not very user friendly
Expand All @@ -168,49 +169,44 @@ public void populateItem(Item item, String componentId, IModel model) {

//parameter value editing column
columns.add(new EditablePropertyColumn<JasperReportParameterDto>(createStringResource("runReportPopupContent.param.value"), "value") {

@Override
public void populateItem(Item<ICellPopulator<JasperReportParameterDto>> cellItem, String componentId,
final IModel<JasperReportParameterDto> rowModel) {
Component component = createTypedInputPanel(componentId, rowModel, getPropertyExpression());
cellItem.add(component);
// cellItem.setOutputMarkupId(true);
}

});

return columns;
}

private Component createTypedInputPanel(String componentId, IModel<JasperReportParameterDto> model, String expression) {
JasperReportParameterDto param = model.getObject();
param.setEditing(true);

IModel label = new PropertyModel<String>(model, "name");
PropertyModel value = new PropertyModel<String>(model, expression);
String tooltipKey = model.getObject().getTypeAsString();
Class type = null;

try {
type = param.getType();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
return null;
}
InputPanel panel = null;

if (type.isEnum()) {
panel = WebMiscUtil.createEnumPanel(type, componentId, new PropertyModel(model, expression), this);
} else if (XMLGregorianCalendar.class.isAssignableFrom(type)) {
panel = new DatePanel(componentId, new PropertyModel<XMLGregorianCalendar>(model, expression));
} else if ("resourceName".equals(param.getName())) { // hardcoded for Reconc report
panel = new AutoCompleteTextPanel<String>(componentId, new PropertyModel<String>(model, expression)) {

@Override
public Iterator<String> getIterator(String input) {
return createResourceIterator();
}
};
panel = new DropDownChoicePanel(componentId, new PropertyModel(model, expression),
createResourceListModel(), new ChoiceRenderer<String>(), false);
} else {
panel = new TextPanel<String>(componentId, new PropertyModel<String>(model, expression));
}
Expand All @@ -226,31 +222,37 @@ public Iterator<String> getIterator(String input) {
}
}
return panel;

}
private Iterator<String> createResourceIterator() {

private IModel<List<String>> createResourceListModel() {
OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES);
Task task = createSimpleTask(OPERATION_LOAD_RESOURCES);
List<PrismObject<ResourceType>> resources = null;
List<String> resourceList = new ArrayList();
final List<String> resourceList = new ArrayList();

try {
resources = modelService.searchObjects(ResourceType.class, new ObjectQuery(), null, task, result);
} catch (Exception ex) {
LOGGER.error(ex.getMessage());
}

for (PrismObject<ResourceType> resource : resources) {
resourceList.add(resource.getBusinessDisplayName());
}

return resourceList.iterator();

return new AbstractReadOnlyModel<List<String>>() {

@Override
public List<String> getObject() {
return resourceList;
}
};
}

public Task createSimpleTask(String operation, PrismObject<UserType> owner) {
Task task = taskManager.createTaskInstance(operation);

if (owner == null) {
MidPointPrincipal user = SecurityUtils.getPrincipalUser();
if (user == null) {
Expand All @@ -259,34 +261,34 @@ public Task createSimpleTask(String operation, PrismObject<UserType> owner) {
owner = user.getUser().asPrismObject();
}
}

task.setOwner(owner);
task.setChannel(SchemaConstants.CHANNEL_GUI_USER_URI);

return task;
}

public Task createSimpleTask(String operation) {
MidPointPrincipal user = SecurityUtils.getPrincipalUser();
return createSimpleTask(operation, user != null ? user.getUser().asPrismObject() : null);
}

private void addFormUpdatingBehavior(FormComponent parent, String id, final IModel<JasperReportParameterDto> model) {
Component c = parent.get(id);
if (c == null) {
return;
}
c.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
}

private void runConfirmPerformed(AjaxRequestTarget target, IModel<ReportDto> model, List<JasperReportParameterDto> params) {
ReportDto reportDto = model.getObject();

// List<ReportParameterType> reportParams = new ArrayList<ReportParameterType>();
PrismContainerDefinition<ReportParameterType> paramContainterDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByElementName(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
PrismContainer<ReportParameterType> paramContainer = paramContainterDef.instantiate();
try {

ReportParameterType reportParam = new ReportParameterType();
PrismContainerValue<ReportParameterType> reportParamValue = reportParam.asPrismContainerValue();
reportParamValue.revive(getPrismContext());
Expand All @@ -301,7 +303,7 @@ private void runConfirmPerformed(AjaxRequestTarget target, IModel<ReportDto> mod
if (XmlTypeConverter.canConvert(paramClass)) {
typeName = XsdTypeMapper.toXsdType(paramClass);
} else {

if (AuditEventType.class.isAssignableFrom(paramClass)) {
paramClass = AuditEventTypeType.class;
realValue = AuditEventType.fromAuditEventType((AuditEventType) realValue);
Expand All @@ -325,25 +327,25 @@ private void runConfirmPerformed(AjaxRequestTarget target, IModel<ReportDto> mod
getPageBase().showResult(result);
return;
}

runConfirmPerformed(target, reportDto.getObject().asObjectable(), paramContainer);

}

private PrismContext getPrismContext() {
return getPageBase().getPrismContext();
}

protected void runConfirmPerformed(AjaxRequestTarget target, ReportType reportType2,
PrismContainer<ReportParameterType> reportParam) {
}

private static class EmptyOnBlurAjaxFormUpdatingBehaviour extends AjaxFormComponentUpdatingBehavior {

public EmptyOnBlurAjaxFormUpdatingBehaviour() {
super("change");
}

@Override
protected void onUpdate(AjaxRequestTarget target) {
MarkupContainer parent = getFormComponent().getParent();
Expand All @@ -353,5 +355,5 @@ protected void onUpdate(AjaxRequestTarget target) {
}
}
}

}

0 comments on commit bbcd465

Please sign in to comment.