mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 20:28:00 +08:00
PL-7433 Implement Calendar with data binding to collection datasource
This commit is contained in:
parent
3feff69844
commit
078834de59
353
modules/gui/src/com/haulmont/cuba/gui/components/Calendar.java
Normal file
353
modules/gui/src/com/haulmont/cuba/gui/components/Calendar.java
Normal file
@ -0,0 +1,353 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.gui.components;
|
||||
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.gui.components.calendar.CalendarEvent;
|
||||
import com.haulmont.cuba.gui.components.calendar.CalendarEventProvider;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public interface Calendar extends Component.BelongToFrame, Component.HasCaption, Component.HasIcon {
|
||||
String NAME = "calendar";
|
||||
|
||||
/**
|
||||
* Set start date for the calendar range.
|
||||
*/
|
||||
void setStartDate(Date date);
|
||||
/**
|
||||
* @return the start date for the calendar range.
|
||||
*/
|
||||
Date getStartDate();
|
||||
|
||||
/**
|
||||
* Set end date for the calendar's range.
|
||||
*/
|
||||
void setEndDate(Date date);
|
||||
/**
|
||||
* @return the last date for the calendar range.
|
||||
*/
|
||||
Date getEndDate();
|
||||
|
||||
/**
|
||||
* Set timezone.
|
||||
*/
|
||||
void setTimeZone(TimeZone zone);
|
||||
/**
|
||||
* @return timezone.
|
||||
*/
|
||||
TimeZone getTimeZone();
|
||||
|
||||
/**
|
||||
* Set collection datasource for the calendar component with a collection of events.
|
||||
*/
|
||||
void setDatasource(CollectionDatasource datasource);
|
||||
CollectionDatasource getDatasource();
|
||||
|
||||
/**
|
||||
* Set format for time. 12H/24H.
|
||||
*/
|
||||
void setTimeFormat(TimeFormat format);
|
||||
/**
|
||||
* @return enumeration of ite format.
|
||||
*/
|
||||
TimeFormat getTimeFormat();
|
||||
|
||||
/**
|
||||
* Set first day of the week to show.
|
||||
*/
|
||||
void setFirstVisibleDayOfWeek(int firstDay);
|
||||
/**
|
||||
* @return first showed day of the week.
|
||||
*/
|
||||
int getFirstVisibleDayOfWeek();
|
||||
|
||||
/**
|
||||
* Set last day of the week to show.
|
||||
*/
|
||||
void setLastVisibleDayOfWeek(int lastDay);
|
||||
/**
|
||||
* @return last showed day of the week.
|
||||
*/
|
||||
int getLastVisibleDayOfWeek();
|
||||
|
||||
/**
|
||||
* Set first hour of the day to show.
|
||||
*/
|
||||
void setFirstVisibleHourOfDay(int firstHour);
|
||||
/**
|
||||
* @return first showed hour of the day.
|
||||
*/
|
||||
int getFirstVisibleHourOfDay();
|
||||
|
||||
/**
|
||||
* Set last hour of the day to show.
|
||||
*/
|
||||
void setLastVisibleHourOfDay(int lastHour);
|
||||
/**
|
||||
* @return last showed hour of the day.
|
||||
*/
|
||||
int getLastVisibleHourOfDay();
|
||||
|
||||
/**
|
||||
* Set date caption format for the weekly view.
|
||||
*/
|
||||
void setWeeklyCaptionFormat(String dateFormatPattern);
|
||||
/**
|
||||
* @return date pattern of captions.
|
||||
*/
|
||||
String getWeeklyCaptionFormat();
|
||||
|
||||
/**
|
||||
* Set the calendar event provider. Provider can contain calendar events.
|
||||
*/
|
||||
void setEventProvider(CalendarEventProvider calendarEventProvider);
|
||||
/**
|
||||
* @return calendar event provider.
|
||||
*/
|
||||
CalendarEventProvider getEventProvider();
|
||||
|
||||
|
||||
void addDateClickListener(CalendarDateClickListener listener);
|
||||
void removeDateClickListener(CalendarDateClickListener listener);
|
||||
|
||||
void addEventClickListener(CalendarEventClickListener listener);
|
||||
void removeEventClickListener(CalendarEventClickListener listener);
|
||||
|
||||
void addEventResizeListener(CalendarEventResizeListener listener);
|
||||
void removeEventResizeListener(CalendarEventResizeListener listener);
|
||||
|
||||
void addEventMoveListener(CalendarEventMoveListener listener);
|
||||
void removeEventMoveListener(CalendarEventMoveListener listener);
|
||||
|
||||
void addWeekClickListener(CalendarWeekClickListener listener);
|
||||
void removeWeekClickListener(CalendarWeekClickListener listener);
|
||||
|
||||
void addForwardClickListener(CalendarForwardClickListener listener);
|
||||
void removeForwardClickListener(CalendarForwardClickListener listener);
|
||||
|
||||
void addBackwardClickListener(CalendarBackwardClickListener listener);
|
||||
void removeBackwardClickListener(CalendarBackwardClickListener listener);
|
||||
|
||||
enum TimeFormat {
|
||||
FORMAT_12H, FORMAT_24H
|
||||
}
|
||||
|
||||
/**
|
||||
* Event mouse drag listener.
|
||||
*/
|
||||
interface CalendarEventMoveListener {
|
||||
void eventMove(CalendarEventMoveEvent event);
|
||||
}
|
||||
|
||||
class CalendarEventMoveEvent {
|
||||
protected Calendar calendar;
|
||||
protected CalendarEvent calendarEvent;
|
||||
protected Date newStart;
|
||||
|
||||
public CalendarEventMoveEvent(Calendar calendar, CalendarEvent calendarEvent, Date newStart) {
|
||||
this.calendar = calendar;
|
||||
this.calendarEvent = calendarEvent;
|
||||
this.newStart = newStart;
|
||||
}
|
||||
|
||||
public Calendar getCalendar() {
|
||||
return calendar;
|
||||
}
|
||||
|
||||
public CalendarEvent getCalendarEvent() {
|
||||
return calendarEvent;
|
||||
}
|
||||
|
||||
public Date getNewStart() {
|
||||
return newStart;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Backward icon click listener.
|
||||
*/
|
||||
interface CalendarBackwardClickListener {
|
||||
void backwardClick(CalendarBackwardClickEvent event);
|
||||
}
|
||||
|
||||
class CalendarBackwardClickEvent {
|
||||
protected Calendar calendar;
|
||||
|
||||
public CalendarBackwardClickEvent(Calendar calendar) {
|
||||
this.calendar = calendar;
|
||||
}
|
||||
|
||||
public Calendar getCalendar() {
|
||||
return calendar;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Date labels click listener of the component.
|
||||
*/
|
||||
interface CalendarDateClickListener {
|
||||
void dateClick(CalendarDateClickEvent event);
|
||||
}
|
||||
|
||||
class CalendarDateClickEvent {
|
||||
protected Calendar calendar;
|
||||
protected Date date;
|
||||
|
||||
public CalendarDateClickEvent(Calendar calendar, Date date) {
|
||||
this.calendar = calendar;
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public Calendar getCalendar() {
|
||||
return calendar;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event labels click listener of the component.
|
||||
*/
|
||||
interface CalendarEventClickListener {
|
||||
void eventClick(CalendarEventClickEvent event);
|
||||
}
|
||||
|
||||
class CalendarEventClickEvent {
|
||||
protected Calendar calendar;
|
||||
protected CalendarEvent calendarEvent;
|
||||
protected Entity entity;
|
||||
|
||||
public CalendarEventClickEvent(Calendar calendar, CalendarEvent calendarEvent, @Nullable Entity entity) {
|
||||
this.calendar = calendar;
|
||||
this.calendarEvent = calendarEvent;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public CalendarEvent getCalendarEvent() {
|
||||
return calendarEvent;
|
||||
}
|
||||
|
||||
public Calendar getCalendar() {
|
||||
return calendar;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward icon click listener.
|
||||
*/
|
||||
interface CalendarForwardClickListener {
|
||||
void forwardClick(CalendarForwardClickEvent event);
|
||||
}
|
||||
|
||||
class CalendarForwardClickEvent {
|
||||
protected Calendar calendar;
|
||||
|
||||
public CalendarForwardClickEvent(Calendar calendar) {
|
||||
this.calendar = calendar;
|
||||
}
|
||||
|
||||
public Calendar getCalendar() {
|
||||
return calendar;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event range change listener.
|
||||
*/
|
||||
interface CalendarEventResizeListener {
|
||||
void eventResize(CalendarEventResizeEvent event);
|
||||
}
|
||||
|
||||
class CalendarEventResizeEvent {
|
||||
protected Calendar calendar;
|
||||
protected CalendarEvent calendarEvent;
|
||||
protected Date newStart;
|
||||
protected Date newEnd;
|
||||
protected Entity entity;
|
||||
|
||||
public CalendarEventResizeEvent(Calendar calendar, CalendarEvent calendarEvent, Date newStart,
|
||||
Date newEnd, @Nullable Entity entity) {
|
||||
this.calendar = calendar;
|
||||
this.calendarEvent = calendarEvent;
|
||||
this.newEnd = newEnd;
|
||||
this.newStart = newStart;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public CalendarEvent getCalendarEvent() {
|
||||
return calendarEvent;
|
||||
}
|
||||
|
||||
public Calendar getCalendar() {
|
||||
return calendar;
|
||||
}
|
||||
|
||||
public Date getNewStart() {
|
||||
return newStart;
|
||||
}
|
||||
|
||||
public Date getNewEnd() {
|
||||
return newEnd;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Week labels click listener.
|
||||
*/
|
||||
interface CalendarWeekClickListener {
|
||||
void weekClick(CalendarWeekClickEvent event);
|
||||
}
|
||||
|
||||
class CalendarWeekClickEvent {
|
||||
protected Calendar calendar;
|
||||
protected int week;
|
||||
protected int year;
|
||||
|
||||
public CalendarWeekClickEvent(Calendar calendar, int week, int year) {
|
||||
this.calendar = calendar;
|
||||
this.week = week;
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public Calendar getCalendar() {
|
||||
return calendar;
|
||||
}
|
||||
|
||||
public int getWeek() {
|
||||
return week;
|
||||
}
|
||||
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.gui.components.calendar;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
public interface CalendarEvent extends Serializable {
|
||||
Date getStart();
|
||||
void setStart(Date start);
|
||||
|
||||
Date getEnd();
|
||||
void setEnd(Date end);
|
||||
|
||||
String getCaption();
|
||||
void setCaption(String caption);
|
||||
|
||||
void setDescription(String description);
|
||||
String getDescription();
|
||||
|
||||
String getStyleName();
|
||||
void setStyleName(String styleName);
|
||||
|
||||
boolean isAllDay();
|
||||
void setAllDay(boolean isAllDay);
|
||||
|
||||
void addEventChangeListener(EventChangeListener listener);
|
||||
void removeEventChangeListener(EventChangeListener listener);
|
||||
|
||||
class EventChangeEvent implements Serializable {
|
||||
|
||||
private CalendarEvent source;
|
||||
|
||||
public EventChangeEvent(CalendarEvent source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public CalendarEvent getCalendarEvent() {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
interface EventChangeListener extends Serializable {
|
||||
|
||||
void eventChange(EventChangeEvent eventChangeEvent);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.gui.components.calendar;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Calendar;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public interface CalendarEventProvider {
|
||||
|
||||
void addEvent(CalendarEvent event);
|
||||
void removeEvent(CalendarEvent event);
|
||||
|
||||
void setCalendar(Calendar calendar);
|
||||
|
||||
void addEventSetChangeListener(EventSetChangeListener listener);
|
||||
void removeEventSetChangeListener(EventSetChangeListener listener);
|
||||
|
||||
List<CalendarEvent> getEvents();
|
||||
|
||||
class EventSetChangeEvent implements Serializable {
|
||||
private CalendarEventProvider source;
|
||||
|
||||
public EventSetChangeEvent(CalendarEventProvider source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public CalendarEventProvider getProvider() {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
interface EventSetChangeListener extends Serializable {
|
||||
|
||||
void eventSetChange(EventSetChangeEvent changeEvent);
|
||||
}
|
||||
}
|
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.gui.components.calendar;
|
||||
|
||||
import com.haulmont.chile.core.model.Instance;
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class EntityCalendarEvent implements CalendarEvent {
|
||||
|
||||
protected final Entity entity;
|
||||
protected final EntityCalendarEventProvider provider;
|
||||
protected List<EventChangeListener> eventChangeListeners;
|
||||
|
||||
public EntityCalendarEvent(Entity entity, EntityCalendarEventProvider provider) {
|
||||
this.entity = entity;
|
||||
this.provider = provider;
|
||||
|
||||
this.entity.addPropertyChangeListener(new Instance.PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChanged(Instance.PropertyChangeEvent e) {
|
||||
fireEventChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void fireEventChanged() {
|
||||
if (eventChangeListeners != null) {
|
||||
EventChangeEvent eventChangeEvent = new EventChangeEvent(this);
|
||||
for (EventChangeListener listener : eventChangeListeners) {
|
||||
listener.eventChange(eventChangeEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStart() {
|
||||
if (provider.getStartDateProperty() != null) {
|
||||
return entity.getValue(provider.getStartDateProperty());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStart(Date start) {
|
||||
entity.setValue(provider.getStartDateProperty(), start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getEnd() {
|
||||
if (provider.getEndDateProperty() != null) {
|
||||
return entity.getValue(provider.getEndDateProperty());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnd(Date end) {
|
||||
entity.setValue(provider.getEndDateProperty(), end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
if (provider.getCaptionProperty() != null) {
|
||||
return entity.getValue(provider.getCaptionProperty());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCaption(String caption) {
|
||||
entity.setValue(provider.getCaptionProperty(), caption);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
entity.setValue(provider.getDescriptionProperty(), description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
if (provider.getDescriptionProperty() != null) {
|
||||
return entity.getValue(provider.getDescriptionProperty());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStyleName() {
|
||||
if (provider.getStyleNameProperty() != null) {
|
||||
return entity.getValue(provider.getStyleNameProperty());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStyleName(String styleName) {
|
||||
entity.setValue(provider.getStyleNameProperty(), styleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllDay() {
|
||||
if (provider.getIsAllDayProperty() != null) {
|
||||
return BooleanUtils.isTrue(entity.getValue(provider.getIsAllDayProperty()));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllDay(boolean isAllDay) {
|
||||
entity.setValue(provider.getIsAllDayProperty(), isAllDay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventChangeListener(EventChangeListener listener) {
|
||||
if (eventChangeListeners == null) {
|
||||
eventChangeListeners = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (!eventChangeListeners.contains(listener)) {
|
||||
eventChangeListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventChangeListener(EventChangeListener listener) {
|
||||
if (eventChangeListeners != null) {
|
||||
eventChangeListeners.remove(listener);
|
||||
|
||||
if (eventChangeListeners.isEmpty()) {
|
||||
eventChangeListeners = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.gui.components.calendar;
|
||||
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.gui.components.Calendar;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class EntityCalendarEventProvider implements CalendarEventProvider, Serializable {
|
||||
protected List<CalendarEvent> itemsCache;
|
||||
protected CollectionDatasource datasource;
|
||||
protected List<EventSetChangeListener> listeners;
|
||||
protected Calendar calendar;
|
||||
|
||||
protected String startDateProperty;
|
||||
protected String endDateProperty;
|
||||
protected String captionProperty;
|
||||
protected String descriptionProperty;
|
||||
protected String styleNameProperty;
|
||||
protected String allDayProperty;
|
||||
|
||||
protected CollectionDatasource.CollectionChangeListener collectionChangeListener;
|
||||
protected Datasource.ItemPropertyChangeListener itemPropertyChangeListener;
|
||||
|
||||
public EntityCalendarEventProvider (CollectionDatasource datasource) {
|
||||
this.datasource = datasource;
|
||||
|
||||
collectionChangeListener = e -> {
|
||||
itemsCache = null;
|
||||
fireDataChanged();
|
||||
};
|
||||
|
||||
itemPropertyChangeListener = e -> {
|
||||
if (e.getProperty() != null) {
|
||||
if (e.getProperty().equals(startDateProperty)
|
||||
|| e.getProperty().equals(endDateProperty)
|
||||
|| e.getProperty().equals(captionProperty)
|
||||
|| e.getProperty().equals(descriptionProperty)
|
||||
|| e.getProperty().equals(styleNameProperty)
|
||||
|| e.getProperty().equals(allDayProperty)) {
|
||||
itemsCache = null;
|
||||
fireDataChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
datasource.addCollectionChangeListener(collectionChangeListener);
|
||||
datasource.addItemPropertyChangeListener(itemPropertyChangeListener);
|
||||
}
|
||||
|
||||
protected void fireDataChanged() {
|
||||
if (listeners != null) {
|
||||
EventSetChangeEvent eventSetChangeEvent = new EventSetChangeEvent(this);
|
||||
|
||||
for (EventSetChangeListener eventSetChangeListener : listeners) {
|
||||
eventSetChangeListener.eventSetChange(eventSetChangeEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEvent(CalendarEvent event) {
|
||||
throw new UnsupportedOperationException("Use datasource for changing data items of EntityCalendarEventProvider");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEvent(CalendarEvent event) {
|
||||
throw new UnsupportedOperationException("Use datasource for changing data items of EntityCalendarEventProvider");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCalendar(Calendar calendar) {
|
||||
this.calendar = calendar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventSetChangeListener(EventSetChangeListener listener) {
|
||||
if (listeners == null) {
|
||||
listeners = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (!listeners.contains(listener)) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventSetChangeListener(EventSetChangeListener listener) {
|
||||
if (listeners != null) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CalendarEvent> getEvents() {
|
||||
if (startDateProperty == null || endDateProperty == null || captionProperty == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
if (itemsCache == null) {
|
||||
itemsCache = new ArrayList<>();
|
||||
for (Entity entity : (Collection<Entity>) datasource.getItems()) {
|
||||
itemsCache.add(new EntityCalendarEvent(entity, this));
|
||||
}
|
||||
return itemsCache;
|
||||
} else {
|
||||
return itemsCache;
|
||||
}
|
||||
}
|
||||
|
||||
public void setStartDateProperty(String startDateProperty) {
|
||||
this.startDateProperty = startDateProperty;
|
||||
}
|
||||
|
||||
public String getStartDateProperty() {
|
||||
return startDateProperty;
|
||||
}
|
||||
|
||||
public void setEndDateProperty(String endDateProperty) {
|
||||
this.endDateProperty = endDateProperty;
|
||||
}
|
||||
|
||||
public String getEndDateProperty() {
|
||||
return endDateProperty;
|
||||
}
|
||||
|
||||
public void setCaptionProperty(String captionProperty) {
|
||||
this.captionProperty = captionProperty;
|
||||
}
|
||||
|
||||
public String getCaptionProperty() {
|
||||
return captionProperty;
|
||||
}
|
||||
|
||||
public void setDescriptionProperty(String descriptionProperty) {
|
||||
this.descriptionProperty = descriptionProperty;
|
||||
}
|
||||
|
||||
public String getDescriptionProperty() {
|
||||
return descriptionProperty;
|
||||
}
|
||||
|
||||
public void setStyleNameProperty(String styleNameProperty) {
|
||||
this.styleNameProperty = styleNameProperty;
|
||||
}
|
||||
|
||||
public String getStyleNameProperty() {
|
||||
return styleNameProperty;
|
||||
}
|
||||
|
||||
public void setAllDayProperty(String allDayProperty) {
|
||||
this.allDayProperty = allDayProperty;
|
||||
}
|
||||
|
||||
public String getIsAllDayProperty() {
|
||||
return allDayProperty;
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
datasource.removeCollectionChangeListener(collectionChangeListener);
|
||||
datasource.removeItemPropertyChangeListener(itemPropertyChangeListener);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.gui.components.calendar;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Calendar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListCalendarEventProvider implements CalendarEventProvider {
|
||||
|
||||
protected List<CalendarEvent> eventList = new ArrayList<>();
|
||||
protected List<EventSetChangeListener> listeners;
|
||||
protected Calendar calendar;
|
||||
protected CalendarEvent.EventChangeListener eventChangeListener =
|
||||
(CalendarEvent.EventChangeListener) eventChangeEvent ->
|
||||
fireEventSetChange();
|
||||
|
||||
protected void fireEventSetChange() {
|
||||
if (listeners != null) {
|
||||
EventSetChangeEvent eventSetChangeEvent = new EventSetChangeEvent(this);
|
||||
|
||||
for (EventSetChangeListener eventSetChangeListener : listeners) {
|
||||
eventSetChangeListener.eventSetChange(eventSetChangeEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CalendarEvent> getEvents() {
|
||||
return eventList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEvent(CalendarEvent calendarEvent) {
|
||||
calendarEvent.addEventChangeListener(eventChangeListener);
|
||||
eventList.add(calendarEvent);
|
||||
fireEventSetChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEvent(CalendarEvent calendarEvent) {
|
||||
calendarEvent.removeEventChangeListener(eventChangeListener);
|
||||
eventList.remove(calendarEvent);
|
||||
fireEventSetChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCalendar(Calendar calendar) {
|
||||
this.calendar = calendar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventSetChangeListener(EventSetChangeListener listener) {
|
||||
if (listeners == null) {
|
||||
listeners = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (!listeners.contains(listener)) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventSetChangeListener(EventSetChangeListener listener) {
|
||||
if (listeners != null) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.gui.components.calendar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleCalendarEvent implements CalendarEvent {
|
||||
protected Date start;
|
||||
protected Date end;
|
||||
protected String caption;
|
||||
protected String description;
|
||||
protected String styleName;
|
||||
protected boolean isAllDay;
|
||||
|
||||
protected List<EventChangeListener> eventChangeListeners;
|
||||
|
||||
protected void fireDataChanged() {
|
||||
if (eventChangeListeners != null) {
|
||||
EventChangeEvent eventChangeEvent = new EventChangeEvent(this);
|
||||
for (EventChangeListener eventChangeListener : eventChangeListeners) {
|
||||
eventChangeListener.eventChange(eventChangeEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStart(Date start) {
|
||||
this.start = start;
|
||||
fireDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnd(Date end) {
|
||||
this.end = end;
|
||||
fireDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
return caption;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCaption(String caption) {
|
||||
this.caption = caption;
|
||||
fireDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
fireDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStyleName() {
|
||||
return styleName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStyleName(String styleName) {
|
||||
this.styleName = styleName;
|
||||
fireDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllDay() {
|
||||
return isAllDay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllDay(boolean isAllDay) {
|
||||
this.isAllDay = isAllDay;
|
||||
fireDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventChangeListener(EventChangeListener listener) {
|
||||
if (eventChangeListeners == null) {
|
||||
eventChangeListeners = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (!eventChangeListeners.contains(listener)) {
|
||||
eventChangeListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventChangeListener(EventChangeListener listener) {
|
||||
if (eventChangeListeners != null) {
|
||||
eventChangeListeners.remove(listener);
|
||||
|
||||
if (eventChangeListeners.isEmpty()) {
|
||||
eventChangeListeners = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -724,6 +724,29 @@
|
||||
</xs:complexContent>
|
||||
</xs:complexType>
|
||||
|
||||
<!-- Calendar -->
|
||||
<xs:complexType name="calendarComponent">
|
||||
<xs:attributeGroup ref="hasId"/>
|
||||
|
||||
<xs:attributeGroup ref="hasCaption"/>
|
||||
<xs:attributeGroup ref="hasIcon"/>
|
||||
<xs:attributeGroup ref="hasSize"/>
|
||||
<xs:attributeGroup ref="hasStyle"/>
|
||||
<xs:attributeGroup ref="hasVisibility"/>
|
||||
|
||||
<xs:attributeGroup ref="hasDatasource"/>
|
||||
|
||||
<xs:attribute name="startDate" type="xs:string"/>
|
||||
<xs:attribute name="endDate" type="xs:string"/>
|
||||
|
||||
<xs:attribute name="startDateProperty" type="xs:string"/>
|
||||
<xs:attribute name="endDateProperty" type="xs:string"/>
|
||||
<xs:attribute name="captionProperty" type="xs:string"/>
|
||||
<xs:attribute name="descriptionProperty" type="xs:string"/>
|
||||
<xs:attribute name="stylenameProperty" type="xs:string"/>
|
||||
<xs:attribute name="isAllDayProperty" type="xs:string"/>
|
||||
</xs:complexType>
|
||||
|
||||
<!-- TextField -->
|
||||
<xs:complexType name="textFieldComponent">
|
||||
<xs:complexContent>
|
||||
@ -1982,6 +2005,7 @@
|
||||
<xs:element name="treeTable" type="tableComponent"/>
|
||||
<xs:element name="groupTable" type="groupTableComponent"/>
|
||||
<xs:element name="buttonsPanel" type="buttonsPanelComponent"/>
|
||||
<xs:element name="calendar" type="calendarComponent"/>
|
||||
|
||||
<xs:element name="filter" type="filterComponent"/>
|
||||
|
||||
|
@ -89,6 +89,8 @@ public class LayoutLoaderConfig {
|
||||
config.register(TreeTable.NAME, TreeTableLoader.class);
|
||||
config.register(GroupTable.NAME, GroupTableLoader.class);
|
||||
|
||||
config.register(Calendar.NAME, CalendarLoader.class);
|
||||
|
||||
config.register(Frame.NAME, FrameComponentLoader.class);
|
||||
config.register("iframe", FrameComponentLoader.class); // for backward compatibility
|
||||
config.register(RuntimePropertiesFrame.NAME, RuntimePropertiesFrameLoader.class);
|
||||
|
@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.GuiDevelopmentException;
|
||||
import com.haulmont.cuba.gui.components.Calendar;
|
||||
import com.haulmont.cuba.gui.components.calendar.EntityCalendarEventProvider;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class CalendarLoader extends AbstractComponentLoader<Calendar> {
|
||||
protected static final String DATE_PATTERN_DAY = "yyyy-MM-dd";
|
||||
protected static final String DATE_PATTERN_MIN = "yyyy-MM-dd hh:mm";
|
||||
|
||||
protected static final String TIME_FORMAT_12H = "12H";
|
||||
protected static final String TIME_FORMAT_24H = "24H";
|
||||
|
||||
@Override
|
||||
public void createComponent() {
|
||||
resultComponent = (Calendar) factory.createComponent(Calendar.NAME);
|
||||
loadId(resultComponent, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadComponent() {
|
||||
loadCaption(resultComponent, element);
|
||||
loadDescription(resultComponent, element);
|
||||
loadHeight(resultComponent, element);
|
||||
loadWidth(resultComponent, element);
|
||||
|
||||
loadStyleName(resultComponent, element);
|
||||
loadIcon(resultComponent, element);
|
||||
|
||||
loadEditable(resultComponent, element);
|
||||
loadDatasource(resultComponent, element);
|
||||
loadTimeFormat(resultComponent, element);
|
||||
loadEndDate(resultComponent, element);
|
||||
loadStartDate(resultComponent, element);
|
||||
}
|
||||
|
||||
protected void loadDatasource(Calendar component, Element element) {
|
||||
final String datasource = element.attributeValue("datasource");
|
||||
if (!StringUtils.isEmpty(datasource)) {
|
||||
CollectionDatasource ds = (CollectionDatasource) context.getDsContext().get(datasource);
|
||||
if (ds == null) {
|
||||
throw new GuiDevelopmentException(String.format("Datasource '%s' is not defined", datasource),
|
||||
getContext().getFullFrameId(), "Component ID", component.getId());
|
||||
}
|
||||
|
||||
component.setDatasource(ds);
|
||||
|
||||
if (component.getEventProvider() instanceof EntityCalendarEventProvider) {
|
||||
EntityCalendarEventProvider eventProvider = (EntityCalendarEventProvider) component.getEventProvider();
|
||||
|
||||
String startDateProperty = element.attributeValue("startDateProperty");
|
||||
if (StringUtils.isNotEmpty(startDateProperty)) {
|
||||
eventProvider.setStartDateProperty(startDateProperty);
|
||||
}
|
||||
|
||||
String endDateProperty = element.attributeValue("endDateProperty");
|
||||
if (StringUtils.isNotEmpty(endDateProperty)) {
|
||||
eventProvider.setEndDateProperty(endDateProperty);
|
||||
}
|
||||
|
||||
String captionProperty = element.attributeValue("captionProperty");
|
||||
if (StringUtils.isNotEmpty(captionProperty)) {
|
||||
eventProvider.setCaptionProperty(captionProperty);
|
||||
}
|
||||
|
||||
String descriptionProperty = element.attributeValue("descriptionProperty");
|
||||
if (StringUtils.isNotEmpty(descriptionProperty)) {
|
||||
eventProvider.setDescriptionProperty(descriptionProperty);
|
||||
}
|
||||
|
||||
String styleNameProperty = element.attributeValue("stylenameProperty");
|
||||
if (StringUtils.isNotEmpty(styleNameProperty)) {
|
||||
eventProvider.setStyleNameProperty(styleNameProperty);
|
||||
}
|
||||
|
||||
String allDayProperty = element.attributeValue("isAllDayProperty");
|
||||
if (StringUtils.isNotEmpty(allDayProperty)) {
|
||||
eventProvider.setAllDayProperty(allDayProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadStartDate(Calendar resultComponent, Element element) {
|
||||
String startDate = element.attributeValue("startDate");
|
||||
if (StringUtils.isNotEmpty(startDate)) {
|
||||
try {
|
||||
resultComponent.setStartDate(parseDateOrDateTime(startDate));
|
||||
} catch (ParseException e) {
|
||||
throw new GuiDevelopmentException(
|
||||
"'startDate' parsing error for calendar: " +
|
||||
startDate, context.getFullFrameId(), "Calendar ID", resultComponent.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadEndDate(Calendar resultComponent, Element element) {
|
||||
String endDate = element.attributeValue("endDate");
|
||||
if (StringUtils.isNotEmpty(endDate)) {
|
||||
try {
|
||||
resultComponent.setEndDate(parseDateOrDateTime(endDate));
|
||||
} catch (ParseException e) {
|
||||
throw new GuiDevelopmentException(
|
||||
"'endDate' parsing error for calendar: " +
|
||||
endDate, context.getFullFrameId(), "Calendar ID", resultComponent.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Date parseDateOrDateTime(String value) throws ParseException {
|
||||
SimpleDateFormat rangeDF;
|
||||
if (value.length() == 10) {
|
||||
rangeDF = new SimpleDateFormat(DATE_PATTERN_DAY);
|
||||
} else {
|
||||
rangeDF = new SimpleDateFormat(DATE_PATTERN_MIN);
|
||||
}
|
||||
return rangeDF.parse(value);
|
||||
}
|
||||
|
||||
protected void loadTimeFormat(Calendar resultComponent, Element element) {
|
||||
String timeFormat = element.attributeValue("timeFormat");
|
||||
if (StringUtils.isNotEmpty(timeFormat)) {
|
||||
if (timeFormat.equals(TIME_FORMAT_12H)) {
|
||||
resultComponent.setTimeFormat(Calendar.TimeFormat.FORMAT_12H);
|
||||
} else if (timeFormat.equals(TIME_FORMAT_24H)) {
|
||||
resultComponent.setTimeFormat(Calendar.TimeFormat.FORMAT_24H);
|
||||
} else {
|
||||
throw new GuiDevelopmentException("'timeFormat' must be '12H' or '24H'",
|
||||
context.getFullFrameId(), "Calendar ID", resultComponent.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -81,6 +81,7 @@ public class WebComponentsFactory implements ComponentsFactory {
|
||||
classes.put(Tree.NAME, WebTree.class);
|
||||
classes.put(TabSheet.NAME, WebTabSheet.class);
|
||||
classes.put(Accordion.NAME, WebAccordion.class);
|
||||
classes.put(Calendar.NAME, WebCalendar.class);
|
||||
classes.put(Embedded.NAME, WebEmbedded.class);
|
||||
classes.put(Filter.NAME, WebFilter.class);
|
||||
classes.put(ButtonsPanel.NAME, WebButtonsPanel.class);
|
||||
|
@ -0,0 +1,495 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.web.gui.components;
|
||||
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.Messages;
|
||||
import com.haulmont.cuba.core.global.UserSessionSource;
|
||||
import com.haulmont.cuba.gui.components.Calendar;
|
||||
import com.haulmont.cuba.gui.components.calendar.CalendarEventProvider;
|
||||
import com.haulmont.cuba.gui.components.calendar.EntityCalendarEvent;
|
||||
import com.haulmont.cuba.gui.components.calendar.EntityCalendarEventProvider;
|
||||
import com.haulmont.cuba.gui.components.calendar.ListCalendarEventProvider;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.data.impl.CollectionDsHelper;
|
||||
import com.haulmont.cuba.web.gui.components.calendar.CalendarEventProviderWrapper;
|
||||
import com.haulmont.cuba.web.gui.components.calendar.CalendarEventWrapper;
|
||||
import com.haulmont.cuba.web.toolkit.ui.CubaCalendar;
|
||||
import com.vaadin.ui.components.calendar.CalendarComponentEvents;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class WebCalendar extends WebAbstractComponent<CubaCalendar> implements Calendar {
|
||||
private CollectionDatasource datasource;
|
||||
|
||||
protected final String TIME_FORMAT_12H = "12H";
|
||||
protected final String TIME_FORMAT_24H = "24H";
|
||||
|
||||
protected CalendarEventProvider calendarEventProvider;
|
||||
protected List<CalendarDateClickListener> dateClickListeners;
|
||||
protected List<CalendarWeekClickListener> weekClickListeners;
|
||||
protected List<CalendarEventClickListener> eventClickListeners;
|
||||
protected List<CalendarEventResizeListener> eventResizeListeners;
|
||||
protected List<CalendarForwardClickListener> forwardClickListeners;
|
||||
protected List<CalendarBackwardClickListener> backwardClickListeners;
|
||||
protected List<CalendarEventMoveListener> eventMoveListeners;
|
||||
|
||||
public WebCalendar() {
|
||||
component = createComponent();
|
||||
|
||||
Messages messages = AppBeans.get(Messages.NAME);
|
||||
String [] monthNamesShort = new String[12];
|
||||
monthNamesShort[0] = messages.getMainMessage("calendar.januaryCaption");
|
||||
monthNamesShort[1] = messages.getMainMessage("calendar.februaryCaption");
|
||||
monthNamesShort[2] = messages.getMainMessage("calendar.marchCaption");
|
||||
monthNamesShort[3] = messages.getMainMessage("calendar.aprilCaption");
|
||||
monthNamesShort[4] = messages.getMainMessage("calendar.mayCaption");
|
||||
monthNamesShort[5] = messages.getMainMessage("calendar.juneCaption");
|
||||
monthNamesShort[6] = messages.getMainMessage("calendar.julyCaption");
|
||||
monthNamesShort[7] = messages.getMainMessage("calendar.augustCaption");
|
||||
monthNamesShort[8] = messages.getMainMessage("calendar.septemberCaption");
|
||||
monthNamesShort[9] = messages.getMainMessage("calendar.octoberCaption");
|
||||
monthNamesShort[10] = messages.getMainMessage("calendar.novemberCaption");
|
||||
monthNamesShort[11] = messages.getMainMessage("calendar.decemberCaption");
|
||||
component.setMonthNamesShort(monthNamesShort);
|
||||
|
||||
String [] dayNamesShort = new String[7];
|
||||
dayNamesShort[0] = messages.getMainMessage("calendar.sundayCaption");
|
||||
dayNamesShort[1] = messages.getMainMessage("calendar.mondayCaption");
|
||||
dayNamesShort[2] = messages.getMainMessage("calendar.tuesdayCaption");
|
||||
dayNamesShort[3] = messages.getMainMessage("calendar.wednesdayCaption");
|
||||
dayNamesShort[4] = messages.getMainMessage("calendar.thursdayCaption");
|
||||
dayNamesShort[5] = messages.getMainMessage("calendar.fridayCaption");
|
||||
dayNamesShort[6] = messages.getMainMessage("calendar.saturdayCaption");
|
||||
component.setDayNamesShort(dayNamesShort);
|
||||
|
||||
if (TIME_FORMAT_12H.equals(messages.getMainMessage("calendar.timeFormat"))) {
|
||||
setTimeFormat(TimeFormat.FORMAT_12H);
|
||||
} else if (TIME_FORMAT_24H.equals(messages.getMainMessage("calendar.timeFormat"))) {
|
||||
setTimeFormat(TimeFormat.FORMAT_24H);
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
String.format("Can't set time format '%s'", messages.getMainMessage("calendar.timeFormat")));
|
||||
}
|
||||
|
||||
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
|
||||
TimeZone userTimeZone = userSessionSource.getUserSession().getTimeZone();
|
||||
if (userTimeZone != null) {
|
||||
setTimeZone(userTimeZone);
|
||||
}
|
||||
|
||||
calendarEventProvider = new ListCalendarEventProvider();
|
||||
calendarEventProvider.setCalendar(this);
|
||||
|
||||
component.setEventProvider(new CalendarEventProviderWrapper(calendarEventProvider));
|
||||
|
||||
component.setHandler(new CalendarComponentEvents.DateClickHandler() {
|
||||
@Override
|
||||
public void dateClick(CalendarComponentEvents.DateClickEvent event) {
|
||||
if (dateClickListeners != null) {
|
||||
for (CalendarDateClickListener calendarDateClickListener : dateClickListeners) {
|
||||
calendarDateClickListener.dateClick(new CalendarDateClickEvent(WebCalendar.this, event.getDate()));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
component.setHandler(new CalendarComponentEvents.EventClickHandler() {
|
||||
@Override
|
||||
public void eventClick(CalendarComponentEvents.EventClick event) {
|
||||
if (eventClickListeners != null) {
|
||||
com.vaadin.ui.components.calendar.event.CalendarEvent calendarEvent = event.getCalendarEvent();
|
||||
if (calendarEvent instanceof CalendarEventWrapper) {
|
||||
Entity entity = null;
|
||||
if (((CalendarEventWrapper) calendarEvent).getCalendarEvent() instanceof EntityCalendarEvent) {
|
||||
entity = ((EntityCalendarEvent) ((CalendarEventWrapper) calendarEvent)
|
||||
.getCalendarEvent())
|
||||
.getEntity();
|
||||
}
|
||||
|
||||
for (CalendarEventClickListener calendarEventClickListener : eventClickListeners) {
|
||||
calendarEventClickListener.eventClick(new CalendarEventClickEvent(
|
||||
WebCalendar.this,
|
||||
((CalendarEventWrapper) calendarEvent).getCalendarEvent(),
|
||||
entity
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
component.setHandler(new CalendarComponentEvents.WeekClickHandler() {
|
||||
@Override
|
||||
public void weekClick(CalendarComponentEvents.WeekClick event) {
|
||||
if (weekClickListeners != null) {
|
||||
for (CalendarWeekClickListener calendarWeekClickListener : weekClickListeners) {
|
||||
calendarWeekClickListener.weekClick(new CalendarWeekClickEvent(
|
||||
WebCalendar.this,
|
||||
event.getWeek(),
|
||||
event.getYear()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
component.setHandler(new CalendarComponentEvents.EventResizeHandler() {
|
||||
@Override
|
||||
public void eventResize(CalendarComponentEvents.EventResize event) {
|
||||
if (eventResizeListeners != null) {
|
||||
com.vaadin.ui.components.calendar.event.CalendarEvent calendarEvent = event.getCalendarEvent();
|
||||
if (calendarEvent instanceof CalendarEventWrapper) {
|
||||
Entity entity = null;
|
||||
if (((CalendarEventWrapper) calendarEvent).getCalendarEvent() instanceof EntityCalendarEvent) {
|
||||
entity = ((EntityCalendarEvent) ((CalendarEventWrapper) calendarEvent)
|
||||
.getCalendarEvent())
|
||||
.getEntity();
|
||||
}
|
||||
|
||||
for (CalendarEventResizeListener calendarEventResizeListener : eventResizeListeners) {
|
||||
calendarEventResizeListener.eventResize(new CalendarEventResizeEvent(
|
||||
WebCalendar.this,
|
||||
((CalendarEventWrapper) calendarEvent).getCalendarEvent(),
|
||||
event.getNewStart(),
|
||||
event.getNewEnd(),
|
||||
entity
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
component.setHandler(new CalendarComponentEvents.ForwardHandler() {
|
||||
@Override
|
||||
public void forward(CalendarComponentEvents.ForwardEvent event) {
|
||||
if (forwardClickListeners != null) {
|
||||
for (CalendarForwardClickListener calendarForwardClickListener : forwardClickListeners) {
|
||||
calendarForwardClickListener.forwardClick(new CalendarForwardClickEvent(WebCalendar.this));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
component.setHandler(new CalendarComponentEvents.BackwardHandler() {
|
||||
@Override
|
||||
public void backward(CalendarComponentEvents.BackwardEvent event) {
|
||||
if (backwardClickListeners != null) {
|
||||
for (CalendarBackwardClickListener calendarBackwardClickListener : backwardClickListeners) {
|
||||
calendarBackwardClickListener.backwardClick(new CalendarBackwardClickEvent(WebCalendar.this));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
component.setHandler(new CalendarComponentEvents.EventMoveHandler() {
|
||||
@Override
|
||||
public void eventMove(CalendarComponentEvents.MoveEvent event) {
|
||||
if (eventMoveListeners != null) {
|
||||
com.vaadin.ui.components.calendar.event.CalendarEvent calendarEvent = event.getCalendarEvent();
|
||||
for (CalendarEventMoveListener calendarEventMoveListener : eventMoveListeners) {
|
||||
calendarEventMoveListener.eventMove(new CalendarEventMoveEvent(
|
||||
WebCalendar.this,
|
||||
((CalendarEventWrapper) calendarEvent).getCalendarEvent(),
|
||||
event.getNewStart()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected CubaCalendar createComponent() {
|
||||
return new CubaCalendar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStartDate(Date date) {
|
||||
component.setStartDate(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStartDate() {
|
||||
return component.getStartDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEndDate(Date date) {
|
||||
component.setEndDate(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getEndDate() {
|
||||
return component.getEndDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimeZone(TimeZone zone) {
|
||||
component.setTimeZone(zone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZone getTimeZone() {
|
||||
return component.getTimeZone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDatasource(CollectionDatasource datasource) {
|
||||
this.datasource = datasource;
|
||||
|
||||
if (datasource == null) {
|
||||
setEventProvider(null);
|
||||
} else {
|
||||
CollectionDsHelper.autoRefreshInvalid(datasource, true);
|
||||
setEventProvider(new EntityCalendarEventProvider(datasource));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionDatasource getDatasource() {
|
||||
return datasource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimeFormat(TimeFormat format) {
|
||||
if (format == TimeFormat.FORMAT_12H) {
|
||||
component.setTimeFormat(com.vaadin.ui.Calendar.TimeFormat.Format12H);
|
||||
} else {
|
||||
component.setTimeFormat(com.vaadin.ui.Calendar.TimeFormat.Format24H);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeFormat getTimeFormat() {
|
||||
if (component.getTimeFormat() == com.vaadin.ui.Calendar.TimeFormat.Format12H) {
|
||||
return TimeFormat.FORMAT_12H;
|
||||
} else {
|
||||
return TimeFormat.FORMAT_24H;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFirstVisibleDayOfWeek(int firstDay) {
|
||||
component.setFirstVisibleDayOfWeek(firstDay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFirstVisibleDayOfWeek() {
|
||||
return component.getFirstVisibleDayOfWeek();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastVisibleDayOfWeek(int lastDay) {
|
||||
component.setLastVisibleDayOfWeek(lastDay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLastVisibleDayOfWeek() {
|
||||
return component.getLastVisibleDayOfWeek();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFirstVisibleHourOfDay(int firstHour) {
|
||||
component.setFirstVisibleHourOfDay(firstHour);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFirstVisibleHourOfDay() {
|
||||
return component.getFirstVisibleHourOfDay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastVisibleHourOfDay(int lastHour) {
|
||||
component.setLastVisibleHourOfDay(lastHour);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLastVisibleHourOfDay() {
|
||||
return component.getLastVisibleHourOfDay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeeklyCaptionFormat(String dateFormatPattern) {
|
||||
component.setWeeklyCaptionFormat(dateFormatPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWeeklyCaptionFormat() {
|
||||
return component.getWeeklyCaptionFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEventProvider(CalendarEventProvider calendarEventProvider) {
|
||||
if (this.calendarEventProvider instanceof EntityCalendarEventProvider) {
|
||||
((EntityCalendarEventProvider) this.calendarEventProvider).unbind();
|
||||
}
|
||||
|
||||
this.calendarEventProvider = calendarEventProvider;
|
||||
if (calendarEventProvider != null) {
|
||||
calendarEventProvider.setCalendar(this);
|
||||
component.setEventProvider(new CalendarEventProviderWrapper(calendarEventProvider));
|
||||
} else {
|
||||
component.setEventProvider(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDateClickListener(CalendarDateClickListener listener) {
|
||||
if (dateClickListeners == null) {
|
||||
dateClickListeners = new ArrayList<>();
|
||||
}
|
||||
if (!dateClickListeners.contains(listener)) {
|
||||
dateClickListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDateClickListener(CalendarDateClickListener listener) {
|
||||
if (!dateClickListeners.isEmpty()) {
|
||||
dateClickListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventClickListener(CalendarEventClickListener listener) {
|
||||
if (eventClickListeners == null) {
|
||||
eventClickListeners = new ArrayList<>();
|
||||
}
|
||||
if (!eventClickListeners.contains(listener)) {
|
||||
eventClickListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventClickListener(CalendarEventClickListener listener) {
|
||||
if (!eventClickListeners.isEmpty()) {
|
||||
eventClickListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventResizeListener(CalendarEventResizeListener listener) {
|
||||
if (eventResizeListeners == null) {
|
||||
eventResizeListeners = new ArrayList<>();
|
||||
}
|
||||
if (!eventResizeListeners.contains(listener)) {
|
||||
eventResizeListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventResizeListener(CalendarEventResizeListener listener) {
|
||||
if (!eventResizeListeners.isEmpty()) {
|
||||
eventResizeListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventMoveListener(CalendarEventMoveListener listener) {
|
||||
if (eventMoveListeners == null) {
|
||||
eventMoveListeners = new ArrayList<>();
|
||||
}
|
||||
if (!eventMoveListeners.contains(listener)) {
|
||||
eventMoveListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventMoveListener(CalendarEventMoveListener listener) {
|
||||
if (!eventMoveListeners.contains(listener)) {
|
||||
eventMoveListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWeekClickListener(CalendarWeekClickListener listener) {
|
||||
if (weekClickListeners == null) {
|
||||
weekClickListeners = new ArrayList<>();
|
||||
}
|
||||
if (!weekClickListeners.contains(listener)) {
|
||||
weekClickListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeWeekClickListener(CalendarWeekClickListener listener) {
|
||||
if (!weekClickListeners.isEmpty()) {
|
||||
weekClickListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addForwardClickListener(CalendarForwardClickListener listener) {
|
||||
if (forwardClickListeners == null) {
|
||||
forwardClickListeners = new ArrayList<>();
|
||||
}
|
||||
if (!forwardClickListeners.contains(listener)) {
|
||||
forwardClickListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeForwardClickListener(CalendarForwardClickListener listener) {
|
||||
if (!forwardClickListeners.isEmpty()) {
|
||||
forwardClickListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBackwardClickListener(CalendarBackwardClickListener listener) {
|
||||
if (backwardClickListeners == null) {
|
||||
backwardClickListeners = new ArrayList<>();
|
||||
}
|
||||
if (!backwardClickListeners.contains(listener)) {
|
||||
backwardClickListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBackwardClickListener(CalendarBackwardClickListener listener) {
|
||||
if (!backwardClickListeners.isEmpty()) {
|
||||
backwardClickListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalendarEventProvider getEventProvider() {
|
||||
return ((CalendarEventProviderWrapper) component.getEventProvider()).getCalendarEventProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
return component.getCaption();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCaption(String caption) {
|
||||
component.setCaption(caption);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return component.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
component.setDescription(description);
|
||||
}
|
||||
}
|
@ -40,6 +40,7 @@ import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.util.*;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class WebDateField extends WebAbstractField<CubaDateFieldWrapper> implements DateField {
|
||||
|
||||
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.web.gui.components.calendar;
|
||||
|
||||
import com.haulmont.cuba.gui.components.calendar.CalendarEventProvider;
|
||||
import com.vaadin.ui.components.calendar.event.CalendarEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class CalendarEventProviderWrapper
|
||||
implements
|
||||
com.vaadin.ui.components.calendar.event.CalendarEditableEventProvider,
|
||||
com.vaadin.ui.components.calendar.event.CalendarEventProvider.EventSetChangeNotifier {
|
||||
|
||||
protected CalendarEventProvider calendarEventProvider;
|
||||
protected List<CalendarEvent> itemsCache = new ArrayList<>();
|
||||
private List<EventSetChangeListener> listeners = new ArrayList<>();
|
||||
|
||||
public CalendarEventProviderWrapper(CalendarEventProvider calendarEventProvider) {
|
||||
this.calendarEventProvider = calendarEventProvider;
|
||||
calendarEventProvider.addEventSetChangeListener(new CalendarEventProvider.EventSetChangeListener() {
|
||||
@Override
|
||||
public void eventSetChange(CalendarEventProvider.EventSetChangeEvent changeEvent) {
|
||||
fireEventSetChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void fireEventSetChange() {
|
||||
EventSetChangeEvent event = new EventSetChangeEvent(this);
|
||||
|
||||
for (EventSetChangeListener listener : listeners) {
|
||||
listener.eventSetChange(event);
|
||||
}
|
||||
}
|
||||
|
||||
public CalendarEventProvider getCalendarEventProvider() {
|
||||
return calendarEventProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEvent(CalendarEvent event) {
|
||||
throw new UnsupportedOperationException("Wrapper does not support direct access");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEvent(CalendarEvent event) {
|
||||
throw new UnsupportedOperationException("Wrapper does not support direct access");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CalendarEvent> getEvents(Date startDate, Date endDate) {
|
||||
if (itemsCache.isEmpty()) {
|
||||
for (com.haulmont.cuba.gui.components.calendar.CalendarEvent calendarEvent : calendarEventProvider.getEvents()) {
|
||||
CalendarEventWrapper calendarEventWrapper = new CalendarEventWrapper(calendarEvent);
|
||||
itemsCache.add(calendarEventWrapper);
|
||||
}
|
||||
|
||||
return itemsCache;
|
||||
} else {
|
||||
return itemsCache;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventSetChangeListener(EventSetChangeListener listener) {
|
||||
listeners.add(listener);
|
||||
calendarEventProvider.addEventSetChangeListener((CalendarEventProvider.EventSetChangeListener) changeEvent -> itemsCache.clear());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventSetChangeListener(EventSetChangeListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.web.gui.components.calendar;
|
||||
|
||||
import com.haulmont.cuba.gui.components.calendar.CalendarEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class CalendarEventWrapper implements com.vaadin.ui.components.calendar.event.CalendarEvent, com.vaadin.ui.components.calendar.event.CalendarEvent.EventChangeNotifier {
|
||||
protected CalendarEvent calendarEvent;
|
||||
protected List<EventChangeListener> eventChangeListeners;
|
||||
|
||||
public CalendarEventWrapper(CalendarEvent calendarEvent) {
|
||||
this.calendarEvent = calendarEvent;
|
||||
|
||||
calendarEvent.addEventChangeListener((CalendarEvent.EventChangeListener) eventChangeEvent ->
|
||||
fireItemChanged()
|
||||
);
|
||||
}
|
||||
|
||||
protected void fireItemChanged() {
|
||||
if (eventChangeListeners != null) {
|
||||
EventChangeEvent event = new EventChangeEvent(this);
|
||||
|
||||
for (EventChangeListener listener : eventChangeListeners) {
|
||||
listener.eventChange(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStart() {
|
||||
return calendarEvent.getStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getEnd() {
|
||||
return calendarEvent.getEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
return calendarEvent.getCaption();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return calendarEvent.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStyleName() {
|
||||
return calendarEvent.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllDay() {
|
||||
return calendarEvent.isAllDay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return calendarEvent == ((CalendarEventWrapper) obj).getCalendarEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getCalendarEvent().hashCode();
|
||||
}
|
||||
|
||||
public CalendarEvent getCalendarEvent() {
|
||||
return calendarEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventChangeListener(EventChangeListener listener) {
|
||||
if (eventChangeListeners == null) {
|
||||
eventChangeListeners = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (!eventChangeListeners.contains(listener)) {
|
||||
eventChangeListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEventChangeListener(EventChangeListener listener) {
|
||||
if (eventChangeListeners != null) {
|
||||
eventChangeListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
}
|
@ -64,6 +64,28 @@ colorPicker.hueSliderCaption = Hue
|
||||
colorPicker.saturationSliderCaption = Saturation
|
||||
colorPicker.valueSliderCaption = Value
|
||||
|
||||
calendar.timeFormat = 12H
|
||||
calendar.januaryCaption = January
|
||||
calendar.februaryCaption = February
|
||||
calendar.marchCaption = March
|
||||
calendar.aprilCaption = April
|
||||
calendar.mayCaption = May
|
||||
calendar.juneCaption = June
|
||||
calendar.julyCaption = July
|
||||
calendar.augustCaption = August
|
||||
calendar.septemberCaption = September
|
||||
calendar.octoberCaption = October
|
||||
calendar.novemberCaption = November
|
||||
calendar.decemberCaption = December
|
||||
|
||||
calendar.mondayCaption = Monday
|
||||
calendar.tuesdayCaption = Tuesday
|
||||
calendar.wednesdayCaption = Wednesday
|
||||
calendar.thursdayCaption = Thursday
|
||||
calendar.fridayCaption = Friday
|
||||
calendar.saturdayCaption = Saturday
|
||||
calendar.sundayCaption = Sunday
|
||||
|
||||
richTextArea.backgroundLabel = Background
|
||||
richTextArea.foregroundLabel = Foreground
|
||||
richTextArea.blackLabel = Black
|
||||
|
@ -58,6 +58,28 @@ colorPicker.lookupRed = Оттенки красного
|
||||
colorPicker.lookupGreen = Оттенки зелёного
|
||||
colorPicker.lookupBlue = Оттенки синего
|
||||
|
||||
calendar.timeFormat = 24H
|
||||
calendar.januaryCaption = Январь
|
||||
calendar.februaryCaption = Февраль
|
||||
calendar.marchCaption = Март
|
||||
calendar.aprilCaption = Апрель
|
||||
calendar.mayCaption = Май
|
||||
calendar.juneCaption = Июнь
|
||||
calendar.julyCaption = Июль
|
||||
calendar.augustCaption = Август
|
||||
calendar.septemberCaption = Сентябрь
|
||||
calendar.octoberCaption = Октябрь
|
||||
calendar.novemberCaption = Ноябрь
|
||||
calendar.decemberCaption = Декабрь
|
||||
|
||||
calendar.mondayCaption = Понедельник
|
||||
calendar.tuesdayCaption = Вторник
|
||||
calendar.wednesdayCaption = Среда
|
||||
calendar.thursdayCaption = Четверг
|
||||
calendar.fridayCaption = Пятница
|
||||
calendar.saturdayCaption = Суббота
|
||||
calendar.sundayCaption = Воскресенье
|
||||
|
||||
richTextArea.backgroundLabel = Выделение
|
||||
richTextArea.foregroundLabel = Текст
|
||||
richTextArea.blackLabel = Черный
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed 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 com.haulmont.cuba.web.toolkit.ui;
|
||||
|
||||
import com.vaadin.ui.Calendar;
|
||||
|
||||
public class CubaCalendar extends Calendar {
|
||||
protected String[] dayNamesShort;
|
||||
protected String[] monthNamesShort;
|
||||
|
||||
@Override
|
||||
public String[] getDayNamesShort() {
|
||||
if (dayNamesShort != null) {
|
||||
return dayNamesShort;
|
||||
} else {
|
||||
return super.getDayNamesShort();
|
||||
}
|
||||
}
|
||||
|
||||
public void setDayNamesShort(String[] dayNamesShort) {
|
||||
this.dayNamesShort = dayNamesShort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getMonthNamesShort() {
|
||||
if (monthNamesShort != null) {
|
||||
return monthNamesShort;
|
||||
} else {
|
||||
return super.getMonthNamesShort();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMonthNamesShort(String[] monthNamesShort) {
|
||||
this.monthNamesShort = monthNamesShort;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user