You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2015/07/05 16:30:16 UTC
[4/4] syncope git commit: Removing Date-related panels to avoid usage
in 2.0.0
Removing Date-related panels to avoid usage in 2.0.0
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/b96bb5a6
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/b96bb5a6
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/b96bb5a6
Branch: refs/heads/master
Commit: b96bb5a6172c52e46edb391236ae17eef95411c6
Parents: 89f5ead
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Sun Jul 5 16:30:03 2015 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Sun Jul 5 16:30:03 2015 +0200
----------------------------------------------------------------------
.../wicket/markup/html/form/DateFieldPanel.java | 132 ------------
.../markup/html/form/DateTextFieldPanel.java | 88 --------
.../markup/html/form/DateTimeFieldPanel.java | 201 -------------------
3 files changed, 421 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/b96bb5a6/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateFieldPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateFieldPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateFieldPanel.java
deleted file mode 100644
index 1f5aaf6..0000000
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateFieldPanel.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.syncope.client.console.wicket.markup.html.form;
-
-import java.io.Serializable;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import org.apache.syncope.common.lib.SyncopeConstants;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-import org.springframework.util.StringUtils;
-
-public class DateFieldPanel extends FieldPanel<Date> {
-
- private static final long serialVersionUID = -428975732068281726L;
-
- protected final String name;
-
- protected final String datePattern;
-
- protected DateFieldPanel(final String id, final String name, final IModel<Date> model, final String datePattern) {
- super(id, model);
- this.name = name;
- this.datePattern = datePattern;
- }
-
- @Override
- public FieldPanel<Date> setNewModel(final List<Serializable> list) {
- final SimpleDateFormat formatter = datePattern == null
- ? new SimpleDateFormat(SyncopeConstants.DEFAULT_DATE_PATTERN, Locale.getDefault())
- : new SimpleDateFormat(datePattern, Locale.getDefault());
-
- setNewModel(new Model<Date>() {
-
- private static final long serialVersionUID = 527651414610325237L;
-
- @Override
- public Date getObject() {
- Date date = null;
-
- if (list != null && !list.isEmpty() && StringUtils.hasText(list.get(0).toString())) {
- try {
- // Parse string using datePattern
- date = formatter.parse(list.get(0).toString());
- } catch (ParseException e) {
- LOG.error("invalid parse exception", e);
- }
- }
-
- return date;
- }
-
- @Override
- public void setObject(final Date object) {
- list.clear();
- if (object != null) {
- list.add(formatter.format(object));
- }
- }
- });
-
- return this;
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public FieldPanel<Date> setNewModel(final ListItem item) {
- final SimpleDateFormat formatter = datePattern == null
- ? new SimpleDateFormat(SyncopeConstants.DEFAULT_DATE_PATTERN, Locale.getDefault())
- : new SimpleDateFormat(datePattern, Locale.getDefault());
-
- IModel<Date> model = new Model<Date>() {
-
- private static final long serialVersionUID = 6799404673615637845L;
-
- @Override
- public Date getObject() {
- Date date = null;
-
- final Object obj = item.getModelObject();
-
- if (obj != null && !obj.toString().isEmpty()) {
- if (obj instanceof String) {
- // Parse string using datePattern
- try {
- date = formatter.parse(obj.toString());
- } catch (ParseException e) {
- LOG.error("While parsing date", e);
- }
- } else if (obj instanceof Date) {
- // Don't parse anything
- date = (Date) obj;
- } else {
- // consider Long
- date = new Date((Long) obj);
- }
- }
-
- return date;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public void setObject(final Date object) {
- item.setModelObject(object != null ? formatter.format(object) : null);
- }
- };
-
- field.setModel(model);
- return this;
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/b96bb5a6/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateTextFieldPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateTextFieldPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateTextFieldPanel.java
deleted file mode 100644
index add3de6..0000000
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateTextFieldPanel.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.syncope.client.console.wicket.markup.html.form;
-
-import java.util.Date;
-import org.apache.syncope.client.console.commons.Constants;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
-import org.apache.wicket.datetime.markup.html.form.DateTextField;
-import org.apache.wicket.extensions.yui.calendar.DatePicker;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-
-public class DateTextFieldPanel extends DateFieldPanel {
-
- private static final long serialVersionUID = 1919852712185883648L;
-
- public DateTextFieldPanel(final String id, final String name, final IModel<Date> model, final String datePattern) {
- super(id, name, model, datePattern);
-
- field = DateTextField.forDatePattern("field", model, datePattern);
-
- if (!isReadOnly()) {
- field.add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
-
- private static final long serialVersionUID = -1107858522700306810L;
-
- @Override
- protected void onUpdate(final AjaxRequestTarget target) {
- // nothing to do
- }
- });
- }
-
- field.add(getDatePicker());
-
- add(field.setLabel(new Model<String>(name)).setOutputMarkupId(true));
- }
-
- /**
- * Setup a DatePicker component.
- */
- private DatePicker getDatePicker() {
- final DatePicker picker = new DatePicker() {
-
- private static final long serialVersionUID = 4166072895162221956L;
-
- @Override
- protected boolean enableMonthYearSelection() {
- return true;
- }
- };
-
- picker.setShowOnFieldClick(true);
-
- return picker;
- }
-
- @Override
- public FieldPanel<Date> clone() {
- final FieldPanel<Date> panel = new DateTextFieldPanel(getId(), name, new Model<Date>(), datePattern);
- panel.setRequired(isRequired());
- panel.setReadOnly(isReadOnly());
- panel.setTitle(title);
-
- if (isRequiredLabelAdded) {
- panel.addRequiredLabel();
- }
-
- return panel;
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/b96bb5a6/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateTimeFieldPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateTimeFieldPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateTimeFieldPanel.java
deleted file mode 100644
index 67d72d1..0000000
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateTimeFieldPanel.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.syncope.client.console.wicket.markup.html.form;
-
-import java.util.Calendar;
-import java.util.Date;
-import org.apache.syncope.client.console.commons.Constants;
-import org.apache.wicket.AttributeModifier;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
-import org.apache.wicket.extensions.yui.calendar.DateTimeField;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.FormComponent;
-import org.apache.wicket.markup.html.form.validation.AbstractFormValidator;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-import org.apache.wicket.validation.IValidationError;
-import org.apache.wicket.validation.ValidationError;
-
-public class DateTimeFieldPanel extends DateFieldPanel {
-
- private static final long serialVersionUID = -428975732068281726L;
-
- private Form<?> form = null;
-
- public DateTimeFieldPanel(final String id, final String name, final IModel<Date> model, final String datePattern) {
- super(id, name, model, datePattern);
-
- field = new DateTimeField("field", model);
-
- final Calendar cal = Calendar.getInstance();
-
- field.get("hours").add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
-
- private static final long serialVersionUID = -1107858522700306810L;
-
- @SuppressWarnings("deprecation")
- @Override
- protected void onUpdate(final AjaxRequestTarget target) {
- final Integer hours = ((DateTimeField) field).getHours();
- if (hours != null) {
- cal.set(hours > 12 ? Calendar.HOUR_OF_DAY : Calendar.HOUR, hours);
- field.setModelObject(cal.getTime());
- }
- }
- });
-
- field.get("minutes").add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
-
- private static final long serialVersionUID = -1107858522700306810L;
-
- @SuppressWarnings("deprecation")
- @Override
- protected void onUpdate(final AjaxRequestTarget target) {
- final Integer minutes = ((DateTimeField) field).getMinutes();
- if (minutes != null) {
- cal.set(Calendar.MINUTE, minutes);
- field.setModelObject(cal.getTime());
- }
- }
- });
-
- field.get("date").add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
-
- private static final long serialVersionUID = -1107858522700306810L;
-
- @SuppressWarnings("deprecation")
- @Override
- protected void onUpdate(final AjaxRequestTarget target) {
- final Date date = ((DateTimeField) field).getDate();
- if (date == null) {
- field.setModelObject(null);
- } else {
- cal.setTime(date);
- cal.set(Calendar.AM_PM, "PM".equals("" + ((DateTimeField) field).getAmOrPm())
- ? Calendar.PM
- : Calendar.AM);
- field.setModelObject(cal.getTime());
- }
- }
- });
-
- field.get("amOrPmChoice").add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
-
- private static final long serialVersionUID = -1107858522700306810L;
-
- @SuppressWarnings("deprecation")
- @Override
- protected void onUpdate(final AjaxRequestTarget target) {
- cal.set(Calendar.AM_PM, "PM".equals("" + ((DateTimeField) field).getAmOrPm()) ? Calendar.PM
- : Calendar.AM);
- field.setModelObject(cal.getTime());
- }
- });
-
- add(field.setLabel(new Model<String>(name)).setOutputMarkupId(true));
- }
-
- /**
- * Custom form validator for registering and handling DateTimeField components that are in it.
- */
- private class DateTimeFormValidator extends AbstractFormValidator {
-
- private static final long serialVersionUID = 6842264694946633582L;
-
- private FormComponent<?>[] dateTimeComponents;
-
- public DateTimeFormValidator(final DateTimeField dateTimeComponent) {
- if (dateTimeComponent == null) {
- throw new IllegalArgumentException("argument dateTimeComponent cannot be null");
- }
-
- dateTimeComponents = new FormComponent<?>[] { dateTimeComponent };
- }
-
- @Override
- public FormComponent<?>[] getDependentFormComponents() {
- return dateTimeComponents;
- }
-
- /**
- * Validation rule : all 3 fields (date,hours,minutes) must be not-null.
- *
- * @param form
- */
- @SuppressWarnings("deprecation")
- @Override
- public void validate(final Form<?> form) {
- final DateTimeField dateTimeField = (DateTimeField) dateTimeComponents[0];
-
- if (!(dateTimeField.getDate() != null && dateTimeField.getHours() != null
- && dateTimeField.getMinutes() != null)) {
-
- ValidationError ve = new ValidationError();
- ve.setVariables(DateTimeFormValidator.this.variablesMap());
- ve.addKey(resourceKey());
- dateTimeComponents[0].error((IValidationError) ve);
- }
- }
- }
-
- @SuppressWarnings("rawtypes")
- public FieldPanel<Date> setFormValidator(final Form<?> form) {
- if (field == null) {
- LOG.error("Error setting form validator");
- } else {
- form.add(new DateTimeFormValidator(((DateTimeField) field)));
- this.form = form;
- }
-
- return this;
- }
-
- @Override
- public FieldPanel<Date> setStyleSheet(final String classes) {
- field.get("date").add(AttributeModifier.replace("class", (classes == null ? "" : classes) + " date_size"));
-
- field.get("hours").add(AttributeModifier.replace("class", classes == null ? "" : classes));
-
- field.get("minutes").add(AttributeModifier.replace("class", classes == null ? "" : classes));
-
- field.get("amOrPmChoice").add(AttributeModifier.replace("class", classes == null ? "" : classes));
-
- return this;
- }
-
- @Override
- public FieldPanel<Date> clone() {
- final FieldPanel<Date> panel = new DateTimeFieldPanel(getId(), name, new Model<Date>(null), datePattern);
-
- panel.setRequired(isRequired());
- panel.setReadOnly(isReadOnly());
- panel.setTitle(title);
-
- if (isRequiredLabelAdded) {
- panel.addRequiredLabel();
- }
-
- if (form != null && isRequired()) {
- ((DateTimeFieldPanel) panel).setFormValidator(form);
- }
-
- return panel;
- }
-}