View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.console.panels;
20  
21  import java.util.List;
22  import java.util.stream.Collectors;
23  import java.util.stream.Stream;
24  import org.apache.syncope.client.console.wicket.markup.html.form.AjaxCharacterFieldPanel;
25  import org.apache.syncope.client.console.wizards.CSVPullWizardBuilder;
26  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxCheckBoxPanel;
27  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxDropDownChoicePanel;
28  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
29  import org.apache.syncope.common.rest.api.beans.AbstractCSVSpec;
30  import org.apache.wicket.markup.html.form.IChoiceRenderer;
31  import org.apache.wicket.markup.html.panel.Panel;
32  import org.apache.wicket.model.IModel;
33  import org.apache.wicket.model.PropertyModel;
34  import org.apache.wicket.validation.validator.StringValidator;
35  
36  public class CSVConfPanel extends Panel {
37  
38      private static final long serialVersionUID = -1562409114958459620L;
39  
40      public CSVConfPanel(final String id, final AbstractCSVSpec spec) {
41          super(id);
42  
43          AjaxCharacterFieldPanel columnSeparator = new AjaxCharacterFieldPanel(
44                  "columnSeparator", "columnSeparator", new PropertyModel<>(spec, "columnSeparator"));
45          columnSeparator.setChoices(List.of(',', ';', ' '));
46          columnSeparator.setRequired(true);
47          add(columnSeparator);
48  
49          AjaxTextFieldPanel arrayElementSeparator = new AjaxTextFieldPanel(
50                  "arrayElementSeparator", "arrayElementSeparator",
51                  new PropertyModel<>(spec, "arrayElementSeparator"));
52          arrayElementSeparator.setChoices(List.of(";"));
53          arrayElementSeparator.setRequired(true);
54          arrayElementSeparator.addValidator(new StringValidator(1, 1));
55          add(arrayElementSeparator);
56  
57          AjaxCharacterFieldPanel quoteChar = new AjaxCharacterFieldPanel(
58                  "quoteChar", "quoteChar", new PropertyModel<>(spec, "quoteChar"));
59          quoteChar.setChoices(List.of('"'));
60          quoteChar.setRequired(true);
61          add(quoteChar);
62  
63          AjaxCharacterFieldPanel escapeChar = new AjaxCharacterFieldPanel(
64                  "escapeChar", "escapeChar", new PropertyModel<>(spec, "escapeChar"));
65          escapeChar.setRequired(false);
66          add(escapeChar);
67  
68          AjaxDropDownChoicePanel<String> lineSeparator = new AjaxDropDownChoicePanel<>(
69                  "lineSeparator", "lineSeparator", new PropertyModel<>(spec, "lineSeparator"), false);
70          lineSeparator.setChoices(Stream.of(CSVPullWizardBuilder.LineSeparator.values()).
71                  map(CSVPullWizardBuilder.LineSeparator::name).collect(Collectors.toList()));
72          lineSeparator.setChoiceRenderer(new IChoiceRenderer<>() {
73  
74              private static final long serialVersionUID = 8551710814349123350L;
75  
76              @Override
77              public Object getDisplayValue(final String object) {
78                  return CSVPullWizardBuilder.LineSeparator.valueOf(object).name();
79              }
80  
81              @Override
82              public String getIdValue(final String object, final int index) {
83                  return object;
84              }
85  
86              @Override
87              public String getObject(
88                  final String id, final IModel<? extends List<? extends String>> choices) {
89  
90                  return CSVPullWizardBuilder.LineSeparator.valueOf(id).getRepr();
91              }
92          });
93          lineSeparator.setRequired(true);
94          add(lineSeparator);
95  
96          AjaxTextFieldPanel nullValue = new AjaxTextFieldPanel(
97                  "nullValue", "nullValue", new PropertyModel<>(spec, "nullValue"));
98          nullValue.setRequired(false);
99          add(nullValue);
100 
101         AjaxCheckBoxPanel allowComments = new AjaxCheckBoxPanel(
102                 "allowComments", "allowComments", new PropertyModel<>(spec, "allowComments"), true);
103         add(allowComments);
104     }
105 }