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.ui.commons.markup.html.form;
20  
21  import com.googlecode.wicket.kendo.ui.form.datetime.AjaxDateTimePicker;
22  import java.text.DateFormat;
23  import java.util.Date;
24  import java.util.Locale;
25  import org.apache.commons.lang3.time.FastDateFormat;
26  import org.apache.wicket.Session;
27  import org.apache.wicket.model.IModel;
28  import org.apache.wicket.model.Model;
29  import org.apache.wicket.model.ResourceModel;
30  
31  public class AjaxDateTimeFieldPanel extends DateFieldPanel {
32  
33      private static final long serialVersionUID = -428975732068281726L;
34  
35      public AjaxDateTimeFieldPanel(
36              final String id,
37              final String name,
38              final IModel<Date> model,
39              final FastDateFormat dateTimePattern) {
40  
41          super(id, name, model, dateTimePattern);
42  
43          // dateTimePattern should be spit into separate date and time pattern strings in order to be passed to the
44          // AjaxDateTimePicker constructor, but there is no safe way to do that - ignoring
45          Locale locale = Session.get().getLocale();
46          field = new AjaxDateTimePicker(
47                  "field",
48                  model,
49                  locale,
50                  FastDateFormat.getDateInstance(DateFormat.SHORT, locale).getPattern().replace("yy", "yyyy"),
51                  FastDateFormat.getTimeInstance(DateFormat.SHORT, locale).getPattern());
52          add(field.setLabel(new ResourceModel(name, name)).setOutputMarkupId(true));
53      }
54  
55      @Override
56      public FieldPanel<Date> clone() {
57          FieldPanel<Date> panel = new AjaxDateTimeFieldPanel(
58                  getId(),
59                  name,
60                  new Model<>(null),
61                  fmt);
62          panel.setRequired(isRequired());
63          panel.setReadOnly(isReadOnly());
64          panel.setTitle(title);
65  
66          if (isRequiredLabelAdded) {
67              panel.addRequiredLabel();
68          }
69  
70          return panel;
71      }
72  }