diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/RunReportPopupPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/RunReportPopupPanel.java index 85d202bc4b7..8463bd24e89 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/RunReportPopupPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/RunReportPopupPanel.java @@ -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; @@ -55,73 +55,74 @@ 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 { - + @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 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(false) { - + @Override protected ReportDto load() { return new ReportDto(reportType, true); } }; - + ISortableDataProvider provider = new ListDataProvider<>(this, new PropertyModel>(reportModel, "jasperReportDto.parameters")); TablePanel table = new TablePanel<>(ID_PARAMETERS_TABLE, provider, initParameterColumns()); @@ -129,23 +130,23 @@ protected ReportDto load() { table.setShowPaging(true); return table; } - + private TablePanel getParametersTable() { return (TablePanel) get(ID_PARAMETERS_TABLE); } - + private List getParameters() { TablePanel table = getParametersTable(); List params = ((ListDataProvider) table.getDataTable().getDataProvider()).getAvailableData(); return params; } - + private List> initParameterColumns() { List> 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(model, "name").getObject(); @@ -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 @@ -168,7 +169,7 @@ public void populateItem(Item item, String componentId, IModel model) { //parameter value editing column columns.add(new EditablePropertyColumn(createStringResource("runReportPopupContent.param.value"), "value") { - + @Override public void populateItem(Item> cellItem, String componentId, final IModel rowModel) { @@ -176,21 +177,21 @@ public void populateItem(Item> cellItem cellItem.add(component); // cellItem.setOutputMarkupId(true); } - + }); - + return columns; } - + private Component createTypedInputPanel(String componentId, IModel model, String expression) { JasperReportParameterDto param = model.getObject(); param.setEditing(true); - + IModel label = new PropertyModel(model, "name"); PropertyModel value = new PropertyModel(model, expression); String tooltipKey = model.getObject().getTypeAsString(); Class type = null; - + try { type = param.getType(); } catch (ClassNotFoundException e) { @@ -198,19 +199,14 @@ private Component createTypedInputPanel(String componentId, IModel(model, expression)); } else if ("resourceName".equals(param.getName())) { // hardcoded for Reconc report - panel = new AutoCompleteTextPanel(componentId, new PropertyModel(model, expression)) { - - @Override - public Iterator getIterator(String input) { - return createResourceIterator(); - } - }; + panel = new DropDownChoicePanel(componentId, new PropertyModel(model, expression), + createResourceListModel(), new ChoiceRenderer(), false); } else { panel = new TextPanel(componentId, new PropertyModel(model, expression)); } @@ -226,31 +222,37 @@ public Iterator getIterator(String input) { } } return panel; - + } - - private Iterator createResourceIterator() { + + private IModel> createResourceListModel() { OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES); Task task = createSimpleTask(OPERATION_LOAD_RESOURCES); List> resources = null; - List resourceList = new ArrayList(); - + final List resourceList = new ArrayList(); + try { resources = modelService.searchObjects(ResourceType.class, new ObjectQuery(), null, task, result); } catch (Exception ex) { LOGGER.error(ex.getMessage()); } - + for (PrismObject resource : resources) { resourceList.add(resource.getBusinessDisplayName()); } - - return resourceList.iterator(); + + return new AbstractReadOnlyModel>() { + + @Override + public List getObject() { + return resourceList; + } + }; } - + public Task createSimpleTask(String operation, PrismObject owner) { Task task = taskManager.createTaskInstance(operation); - + if (owner == null) { MidPointPrincipal user = SecurityUtils.getPrincipalUser(); if (user == null) { @@ -259,18 +261,18 @@ public Task createSimpleTask(String operation, PrismObject 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 model) { Component c = parent.get(id); if (c == null) { @@ -278,7 +280,7 @@ private void addFormUpdatingBehavior(FormComponent parent, String id, final IMod } c.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); } - + private void runConfirmPerformed(AjaxRequestTarget target, IModel model, List params) { ReportDto reportDto = model.getObject(); @@ -286,7 +288,7 @@ private void runConfirmPerformed(AjaxRequestTarget target, IModel mod PrismContainerDefinition paramContainterDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByElementName(ReportConstants.REPORT_PARAMS_PROPERTY_NAME); PrismContainer paramContainer = paramContainterDef.instantiate(); try { - + ReportParameterType reportParam = new ReportParameterType(); PrismContainerValue reportParamValue = reportParam.asPrismContainerValue(); reportParamValue.revive(getPrismContext()); @@ -301,7 +303,7 @@ private void runConfirmPerformed(AjaxRequestTarget target, IModel mod if (XmlTypeConverter.canConvert(paramClass)) { typeName = XsdTypeMapper.toXsdType(paramClass); } else { - + if (AuditEventType.class.isAssignableFrom(paramClass)) { paramClass = AuditEventTypeType.class; realValue = AuditEventType.fromAuditEventType((AuditEventType) realValue); @@ -325,25 +327,25 @@ private void runConfirmPerformed(AjaxRequestTarget target, IModel 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 reportParam) { } - + private static class EmptyOnBlurAjaxFormUpdatingBehaviour extends AjaxFormComponentUpdatingBehavior { - + public EmptyOnBlurAjaxFormUpdatingBehaviour() { super("change"); } - + @Override protected void onUpdate(AjaxRequestTarget target) { MarkupContainer parent = getFormComponent().getParent(); @@ -353,5 +355,5 @@ protected void onUpdate(AjaxRequestTarget target) { } } } - + }