package com.thingtrack.konekti.view.module.calendar.internal; import java.awt.Color; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import org.vaadin.cssinject.CSSInject; import org.vaadin.risto.stylecalendar.DateOptionsGenerator; import org.vaadin.risto.stylecalendar.StyleCalendar; import com.vaadin.addon.colorpicker.ColorPicker; import com.vaadin.addon.colorpicker.ColorPicker.ButtonStyle; import com.vaadin.addon.colorpicker.ColorPicker.ColorChangeListener; import com.vaadin.addon.colorpicker.events.ColorChangeEvent; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.event.LayoutEvents.LayoutClickEvent; import com.vaadin.event.LayoutEvents.LayoutClickListener; import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.DropHandler; import com.vaadin.event.dd.TargetDetails; import com.vaadin.event.dd.acceptcriteria.AcceptAll; import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; import com.vaadin.terminal.Sizeable; import com.vaadin.terminal.ThemeResource; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.CheckBox; import com.vaadin.ui.DragAndDropWrapper; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.DragAndDropWrapper.DragStartMode; import com.vaadin.ui.Button; import com.vaadin.ui.GridLayout; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.Label; import com.vaadin.ui.Panel; import com.vaadin.ui.TextField; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window.CloseEvent; import com.vaadin.ui.Window.CloseListener; import com.vaadin.ui.Window.Notification; import com.vaadin.data.Property.ValueChangeListener; import com.thingtrack.konekti.domain.Calendar; import com.thingtrack.konekti.domain.CalendarCard; import com.thingtrack.konekti.domain.CalendarDetail; import com.thingtrack.konekti.domain.CalendarGroup; import com.thingtrack.konekti.knowledge.service.api.CalendarKnowledgeService; import com.thingtrack.konekti.service.api.CalendarGroupService; import com.thingtrack.konekti.service.api.CalendarService; import com.thingtrack.konekti.view.addon.data.BindingSource; import com.thingtrack.konekti.view.addon.ui.AbstractView; import com.thingtrack.konekti.view.addon.ui.NavigationToolbar; import com.thingtrack.konekti.view.addon.ui.NavigationToolbar.ClickNavigationEvent; import com.thingtrack.konekti.view.addon.ui.NavigationToolbar.ClickRefreshButtonListener; import com.thingtrack.konekti.view.addon.ui.NavigationToolbar.ClickUpButtonListener; import com.thingtrack.konekti.view.kernel.IWorkbenchContext; import com.thingtrack.konekti.view.kernel.ui.layout.IViewContainer; import com.thingtrack.konekti.view.module.calendar.addon.CalendarToolbar; import com.thingtrack.konekti.view.module.calendar.addon.CalendarToolbar.ClickSaveButtonListener; import com.thingtrack.konekti.view.module.calendar.internal.util.CalendarStyleSheetResource; import com.thingtrack.konekti.view.module.calendar.internal.util.DateGroupColor; @SuppressWarnings("serial") public class CalendarCardView extends AbstractView implements ClickRefreshButtonListener, ClickUpButtonListener, ClickSaveButtonListener { private HorizontalLayout mainLayout; private HorizontalSplitPanel horizontalSplitPanel; private GridLayout gridLayoutCalendar; private VerticalLayout serviceGroupLayout; /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */ private NavigationToolbar navigationToolbar; private CalendarToolbar calendarToolbar; private BindingSource<CalendarCard> bsCalendarCard = new BindingSource<CalendarCard>(CalendarCard.class, 1); private IViewContainer viewContainer; private IWorkbenchContext context; private Calendar calendar; private StyleCalendar cardCalendar; private StyleCalendar styleCalendarActive = null; private CalendarService calendarService; private CalendarGroupService calendarGroupService; private CalendarKnowledgeService calendarKnowledgeService; private HashMap<String, DateGroupColor> groupDays = new HashMap<String, DateGroupColor>(); private static final String DEFAULT_DATE_GROUP_COLOR = "#FFFFFF"; private static final boolean DEFAULT_FLAG_WORKING_DAY = true; private CSSInject cssDateGroup = new CSSInject(); private CalendarStyleSheetResource calendarStyleSheetResource = new CalendarStyleSheetResource(); private CSSInject css = new CSSInject(); private static final String CARD_SELECTED_COLOR = "orange"; /** * The constructor should first build the main layout, set the * composition root and then do any custom initialization. * * The constructor will not be automatically regenerated by the * visual editor. */ public CalendarCardView(IWorkbenchContext context, IViewContainer viewContainer) { buildMainLayout(); setCompositionRoot(mainLayout); // TODO add user code here this.viewContainer = viewContainer; this.context = context; this.calendarService = CalendarViewContainer.getCalendarService(); this.calendarGroupService = CalendarViewContainer.getCalendarGroupService(); this.calendarKnowledgeService = CalendarViewContainer.getCalendarKnowledgeService(); initView(); } private void initView() { // create dynamic date group color style tag in the header mainLayout.addComponent(cssDateGroup); // add active color style panel style mainLayout.addComponent(css); horizontalSplitPanel.setSplitPosition(35, Sizeable.UNITS_PERCENTAGE); horizontalSplitPanel.setLocked(true); // left split layout VerticalLayout cardLayout = new VerticalLayout(); cardLayout.setSizeFull(); // card Calendar cardCalendar = new StyleCalendar(); cardCalendar.setRenderControls(false); DragAndDropWrapper wrapper = new DragAndDropWrapper(cardCalendar); wrapper.setSizeUndefined(); wrapper.setDragStartMode(DragStartMode.WRAPPER); cardLayout.addComponent(wrapper); // gap Layout VerticalLayout gapLayout = new VerticalLayout(); gapLayout.setHeight("10px"); gapLayout.setWidth("100%"); cardLayout.addComponent(gapLayout); // add groupStyle HorizontalLayout dateGroupsLayout = buildDateGroupsMainLayout(); cardLayout.addComponent(dateGroupsLayout); // ServiceGroup Layout serviceGroupLayout = new VerticalLayout(); serviceGroupLayout.setWidth("100%"); serviceGroupLayout.setHeight("-1px"); cardLayout.addComponent(serviceGroupLayout); cardLayout.setExpandRatio(serviceGroupLayout, 1.0f); horizontalSplitPanel.setFirstComponent(cardLayout); // Create a 12 month Grid Drag&Drop Layout on the right split layout for (int i = 0; i < 4; i++) { for(int j = 0; j < 3; j++) { // Panel Calendar Layout final Panel target = new Panel(); ((VerticalLayout)target.getContent()).setMargin(false); target.getContent().setSizeFull(); target.setSizeFull(); target.setData(Integer.toString(i) + Integer.toString(j)); // Wrapped Panel Layout DragAndDropWrapper targetWrapper = new DragAndDropWrapper(target); targetWrapper.setData(Integer.toString(i) + Integer.toString(j)); targetWrapper.setSizeFull(); targetWrapper.setDropHandler(new DropHandler() { @Override public AcceptCriterion getAcceptCriterion() { return AcceptAll.get(); } @Override public void drop(DragAndDropEvent event) { //WrapperTransferable t = (WrapperTransferable)event.getTransferable(); TargetDetails td = event.getTargetDetails(); //StyleCalendar source = (StyleCalendar)t.getDraggedComponent(); DragAndDropWrapper wrapper = (DragAndDropWrapper)td.getTarget(); String cardCode = (String) wrapper.getData(); java.util.Calendar c = java.util.Calendar.getInstance(); int year = c.get(java.util.Calendar.YEAR); HorizontalLayout cardLayout = createCardLayout(cardCode, year, 1); target.removeAllComponents(); target.addComponent(cardLayout); styleCalendarActive = (StyleCalendar) cardLayout.getComponent(0); css.setValue(".card_selected_" + styleCalendarActive.getData().toString() + " { background-color:" + CARD_SELECTED_COLOR + "; }"); } }); // add for each grid layout cell gridLayoutCalendar.addComponent(targetWrapper, i, j); gridLayoutCalendar.addListener(new LayoutClickListener() { @Override public void layoutClick(LayoutClickEvent event) { if (event.getClickedComponent() instanceof StyleCalendar) { styleCalendarActive = (StyleCalendar)event.getClickedComponent(); css.setValue(".card_selected_" + styleCalendarActive.getData().toString() + " { background-color:" + CARD_SELECTED_COLOR + "; }"); } else if (event.getClickedComponent() instanceof HorizontalLayout) { HorizontalLayout layoutStyleCalendarActive = (HorizontalLayout)event.getClickedComponent(); styleCalendarActive = (StyleCalendar) layoutStyleCalendarActive.getComponent(0); css.setValue(".card_selected_" + styleCalendarActive.getData().toString() + " { background-color:" + CARD_SELECTED_COLOR + "; }"); } else styleCalendarActive = null; } }); gridLayoutCalendar.setComponentAlignment(targetWrapper, Alignment.MIDDLE_CENTER); } } } public void setCalendar(Calendar calendar) { this.calendar = calendar; // load calendar cards loadCalendarCardsSource(); // add slide toolbars injectBindingSource(); // load groupdates on the left split layout loadGroupDateSource(); // load calendar cards on the rigth split layout loadCardSource(); } private void loadCalendarCardsSource() { try { bsCalendarCard.removeAllItems(); bsCalendarCard.addAll(calendar.getCalendarCards()); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } private void injectBindingSource() { try { navigationToolbar = new NavigationToolbar(0, bsCalendarCard, viewContainer); calendarToolbar = new CalendarToolbar(1, bsCalendarCard, viewContainer); navigationToolbar.addListenerUpButton(this); navigationToolbar.setNavigationButtons(false); calendarToolbar.addListenerSaveButton(this); removeAllToolbar(); addToolbar(navigationToolbar); addToolbar(calendarToolbar); } catch (Exception ex) { ex.getMessage(); } } private void loadGroupDateSource() { groupDays.clear(); serviceGroupLayout.removeAllComponents(); for(CalendarGroup calendarGroup : calendar.getCalendarGroups()) { // create the date group color selector HorizontalLayout layout = buildAddServiceGroupLayout(calendarGroup.getColor(), calendarGroup.getDescription(), calendarGroup.isWorkingDay(), calendarGroup.getFile()); layout.setWidth("100%"); layout.setHeight("-1px"); serviceGroupLayout.addComponent(layout); // add default color style date group String selectorDateGroup = calendarStyleSheetResource.addCssRule(calendarGroup.getColor()); cssDateGroup.setValue(calendarStyleSheetResource.getCss()); // asociate the layout with the selector layout.setData(selectorDateGroup); // add a new DateGroupColor to the list groupDays.put(selectorDateGroup, new DateGroupColor(selectorDateGroup, calendarGroup)); } } private void loadCardSource() { // clear all components for (int i = 0; i < 4; i++) { for(int j = 0; j < 3; j++) { DragAndDropWrapper dragAndDropWrapperCard = (DragAndDropWrapper)gridLayoutCalendar.getComponent(i, j); Panel panelCard = (Panel) dragAndDropWrapperCard.getComponentIterator().next(); panelCard.removeAllComponents(); } } for (CalendarCard calendarCard : calendar.getCalendarCards()) { HorizontalLayout cardLayout = createCardLayout(calendarCard.getCode(), calendarCard.getYear(), calendarCard.getMonth()); // create status days for card loadGroupDays(calendarCard); int x = Integer.parseInt(calendarCard.getCode().substring(0, 1)); int y = Integer.parseInt(calendarCard.getCode().substring(1, 2)); DragAndDropWrapper dragAndDropWrapperCard = (DragAndDropWrapper) gridLayoutCalendar.getComponent(x, y); Panel panelCard = (Panel) dragAndDropWrapperCard.getComponentIterator().next(); panelCard.removeAllComponents(); panelCard.addComponent(cardLayout); // show days status StyleCalendar styleCalendarActive = (StyleCalendar)cardLayout.getComponentIterator().next(); styleCalendarActive.requestRepaint(); } } private HorizontalLayout createCardLayout(String cardCode, int year, int month) { HorizontalLayout cardLayout = new HorizontalLayout(); cardLayout.setSizeFull(); StyleCalendar copy = new StyleCalendar(); copy.setSizeFull(); copy.setImmediate(true); copy.addStyleName("calendar_card"); copy.setData(cardCode); java.util.Calendar cal = java.util.Calendar.getInstance(); cal.set(java.util.Calendar.YEAR, year); cal.set(java.util.Calendar.MONTH, month); cal.set(java.util.Calendar.DAY_OF_MONTH, 1); copy.setShowingDate(cal.getTime()); copy.setDateOptionsGenerator(new DateOptionsGenerator() { @Override public boolean isDateDisabled(Date date, StyleCalendar context) { return false; } @Override public String getTooltip(Date date, StyleCalendar context) { return null; } @SuppressWarnings("rawtypes") @Override public String getStyleName(Date date, StyleCalendar context) { Iterator i = groupDays.keySet().iterator(); while(i.hasNext()) { String selector = (String) i.next(); DateGroupColor dateGroupColor = (DateGroupColor) groupDays.get(selector); for(Date dateGroup : dateGroupColor.getDates()) { if (dateEquals(date, dateGroup)) return selector; } } return null; } }); cardLayout.addComponent(copy); cardLayout.setExpandRatio(copy, 1.0f); Button removeCard = new Button("X"); //Button removeCard = new Button(); //removeCard.setIcon(new ThemeResource("../konekti/images/icons/calendar-module/remove.png")); removeCard.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Button cardRemoveButtonSelected = (Button) event.getComponent(); Panel panelActive = (Panel) cardRemoveButtonSelected.getParent().getParent().getParent(); panelActive.removeAllComponents(); styleCalendarActive = null; } }); cardLayout.addComponent(removeCard); cardLayout.setComponentAlignment(removeCard, Alignment.TOP_RIGHT); cardLayout.addComponent(removeCard); VerticalLayout selectedLine = new VerticalLayout(); selectedLine.addStyleName("card_selected_" + cardCode); selectedLine.setHeight("100%"); selectedLine.setWidth("10px"); cardLayout.addComponent(selectedLine); cardLayout.setComponentAlignment(selectedLine, Alignment.TOP_RIGHT); return cardLayout; } private void loadGroupDays(CalendarCard calendarCard) { for (CalendarDetail calendarDetail : calendarCard.getCalendarDetails()) { List<Date> dates = getGroupDaysByColor(calendarDetail.getCalendarGroup().getColor()); if (dates != null) dates.add(calendarDetail.getDate()); } } public boolean dateEquals(Date first, Date second) { java.util.Calendar c1 = java.util.Calendar.getInstance(); java.util.Calendar c2 = java.util.Calendar.getInstance(); c1.setTime(first); c2.setTime(second); c1.set(java.util.Calendar.SECOND,0); c1.set(java.util.Calendar.MINUTE,0); c1.set(java.util.Calendar.HOUR_OF_DAY,0); c1.set(java.util.Calendar.MILLISECOND,0); c2.set(java.util.Calendar.SECOND,0); c2.set(java.util.Calendar.MINUTE,0); c2.set(java.util.Calendar.HOUR_OF_DAY,0); c2.set(java.util.Calendar.MILLISECOND,0); return c1.equals(c2); } private List<Date> getGroupDaysByColor(String color) { Iterator<String> i = groupDays.keySet().iterator(); while(i.hasNext()) { String selector = (String) i.next(); DateGroupColor dg = (DateGroupColor) groupDays.get(selector); if (dg.getCalendarGroup().getColor().equals(color)) return dg.getDates(); } return null; } @Override public void refreshButtonClick(ClickNavigationEvent event) { loadCalendarCardsSource(); injectBindingSource(); loadCardSource(); } @Override public void upButtonClick(ClickNavigationEvent event) { viewContainer.getSliderView().rollPrevious(); } @Override public void saveButtonClick(CalendarToolbar.ClickNavigationEvent event) { List<CalendarCard> newCalendarCards = new ArrayList<CalendarCard>(); for (int i = 0; i < 4; i++) { for(int j = 0; j < 3; j++) { DragAndDropWrapper dragAndDropWrapperCard = (DragAndDropWrapper)gridLayoutCalendar.getComponent(i, j); Panel panelCard = (Panel) dragAndDropWrapperCard.getComponentIterator().next(); String calendarCode = Integer.toString(i) + Integer.toString(j); // check if exist any calendar card in the cell grid layout if (panelCard.getComponentIterator().hasNext()) { // get calendar style component from calendar card HorizontalLayout layoutCard = (HorizontalLayout) panelCard.getComponentIterator().next(); StyleCalendar styleCalendar = (StyleCalendar) layoutCard.getComponentIterator().next(); // get year&month from calendar card and get the calendar card entity if exist java.util.Calendar c = java.util.Calendar.getInstance(); c.setTime(styleCalendar.getShowingDate()); int year = c.get(java.util.Calendar.YEAR); int month = c.get(java.util.Calendar.MONTH); // create a new calendar card from year&month CalendarCard calendarCard = new CalendarCard(); calendarCard.setCalendar(calendar); calendarCard.setCode(calendarCode); calendarCard.setYear(year); calendarCard.setMonth(month); newCalendarCards.add(calendarCard); // check group dates from calendarcard java.util.Calendar ch = java.util.Calendar.getInstance(); Iterator<String> it = groupDays.keySet().iterator(); while(it.hasNext()) { String selector = (String) it.next(); DateGroupColor dg = (DateGroupColor) groupDays.get(selector); for(Date date : dg.getDates()) { ch.setTime(date); if (ch.get(java.util.Calendar.YEAR) == year && ch.get(java.util.Calendar.MONTH) == month) { CalendarDetail calendarDetail = new CalendarDetail(); calendarDetail.setCalendarCard(calendarCard); calendarDetail.setDate(date); calendarDetail.setCalendarGroup(dg.getCalendarGroup()); calendarCard.addCalendarDetail(calendarDetail); } } } } } } try { // save the last calendar calendarKnowledgeService.setCalendar(calendar, newCalendarCards); calendar = calendarService.get(calendar.getCalendarId()); } catch (Exception e) { throw new RuntimeException("¡No se pudo grabar el calendario!", e); } } private DateGroupColor getDateGroupBySelector(String selector) { Iterator<String> i = groupDays.keySet().iterator(); while(i.hasNext()) { String sl = (String) i.next(); DateGroupColor dg = (DateGroupColor) groupDays.get(selector); if (sl.equals(selector)) return dg; } return null; } private boolean existColor(String color) { Iterator<String> i = groupDays.keySet().iterator(); while(i.hasNext()) { String selector = (String) i.next(); DateGroupColor dg = (DateGroupColor) groupDays.get(selector); if (dg.getCalendarGroup().getColor().equals(color)) return true; } return false; } private HorizontalLayout buildMainLayout() { // common part: create layout mainLayout = new HorizontalLayout(); mainLayout.setImmediate(false); mainLayout.setWidth("100%"); mainLayout.setHeight("100%"); mainLayout.setMargin(false); // top-level component properties setWidth("100.0%"); setHeight("100.0%"); // horizontalSplitPanel horizontalSplitPanel = buildHorizontalSplitPanel(); mainLayout.addComponent(horizontalSplitPanel); mainLayout.setExpandRatio(horizontalSplitPanel, 1.0f); return mainLayout; } private HorizontalSplitPanel buildHorizontalSplitPanel() { // common part: create layout horizontalSplitPanel = new HorizontalSplitPanel(); horizontalSplitPanel.setImmediate(false); horizontalSplitPanel.setWidth("100.0%"); horizontalSplitPanel.setHeight("100.0%"); horizontalSplitPanel.setMargin(false); // gridLayout_1 gridLayoutCalendar = new GridLayout(); gridLayoutCalendar.setImmediate(true); gridLayoutCalendar.setWidth("100.0%"); gridLayoutCalendar.setHeight("100.0%"); gridLayoutCalendar.setMargin(false); gridLayoutCalendar.setColumns(4); gridLayoutCalendar.setRows(3); horizontalSplitPanel.setSecondComponent(gridLayoutCalendar); return horizontalSplitPanel; } private HorizontalLayout buildDateGroupsMainLayout() { // common part: create layout HorizontalLayout addGroupServiceMainLayout = new HorizontalLayout(); addGroupServiceMainLayout.setImmediate(false); addGroupServiceMainLayout.setWidth("100%"); addGroupServiceMainLayout.setHeight("-1px"); addGroupServiceMainLayout.setMargin(false); // top-level component properties addGroupServiceMainLayout.setWidth("100.0%"); addGroupServiceMainLayout.setHeight("-1px"); // addGroupServiceTextBox final TextField textServiceGroup = new TextField(); textServiceGroup.setCaption("Nueva agrupación de días"); textServiceGroup.setImmediate(false); textServiceGroup.setWidth("100.0%"); textServiceGroup.setHeight("-1px"); textServiceGroup.setNullRepresentation(""); textServiceGroup.setValue(null); addGroupServiceMainLayout.addComponent(textServiceGroup); addGroupServiceMainLayout.setExpandRatio(textServiceGroup, 1.0f); // addGroupServiceButton Button btnAddGroupServiceButton = new Button(); btnAddGroupServiceButton.setCaption(" "); btnAddGroupServiceButton.setImmediate(true); btnAddGroupServiceButton.setWidth("-1px"); btnAddGroupServiceButton.setHeight("-1px"); btnAddGroupServiceButton.setIcon(new ThemeResource("../konekti/images/icons/calendar-module/add.png")); addGroupServiceMainLayout.addComponent(btnAddGroupServiceButton); addGroupServiceMainLayout.setComponentAlignment(btnAddGroupServiceButton, Alignment.BOTTOM_LEFT); btnAddGroupServiceButton.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (textServiceGroup.getValue() == null) { getWindow().showNotification("¡El nombre del grupo de servicio no puede ser nulo!", Notification.TYPE_ERROR_MESSAGE); return; } if(existColor(DEFAULT_DATE_GROUP_COLOR)) { getWindow().showNotification("¡Ya existe un grupo con ese mismo color!", Notification.TYPE_ERROR_MESSAGE); return; } String dateGroupDescription = (String) textServiceGroup.getValue(); // create the date group color selector HorizontalLayout layout = buildAddServiceGroupLayout(DEFAULT_DATE_GROUP_COLOR, dateGroupDescription, DEFAULT_FLAG_WORKING_DAY, null); layout.setWidth("100%"); layout.setHeight("-1px"); serviceGroupLayout.addComponent(layout); // add default color style date group String selectorDateGroup = calendarStyleSheetResource.addCssRule(DEFAULT_DATE_GROUP_COLOR); cssDateGroup.setValue(calendarStyleSheetResource.getCss()); // asociate the layout with the selector layout.setData(selectorDateGroup); // add a new DateGroupColor to the list CalendarGroup calendarGroup = new CalendarGroup(); calendarGroup.setCalendar(calendar); calendarGroup.setColor(DEFAULT_DATE_GROUP_COLOR); calendarGroup.setDescription(dateGroupDescription); calendarGroup.setWorkingDay(DEFAULT_FLAG_WORKING_DAY); calendarGroup.setFile(null); groupDays.put(selectorDateGroup, new DateGroupColor(selectorDateGroup, calendarGroup)); // refresh group name textfield textServiceGroup.setValue(null); } }); return addGroupServiceMainLayout; } private HorizontalLayout buildAddServiceGroupLayout(String color, String serviceGroupCaption, boolean workingDay, final byte[] file) { // common part: create layout HorizontalLayout addServiceGroupLayout = new HorizontalLayout(); addServiceGroupLayout.setImmediate(false); addServiceGroupLayout.setWidth("100%"); addServiceGroupLayout.setHeight("-1px"); addServiceGroupLayout.setMargin(false); // btnRemoveServiceGroup Button btnRemoveServiceGroup = new Button(); btnRemoveServiceGroup.setImmediate(false); btnRemoveServiceGroup.setWidth("-1px"); btnRemoveServiceGroup.setHeight("-1px"); btnRemoveServiceGroup.setIcon(new ThemeResource("../konekti/images/icons/calendar-module/remove.png")); addServiceGroupLayout.addComponent(btnRemoveServiceGroup); btnRemoveServiceGroup.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { HorizontalLayout dateGroupLayout = (HorizontalLayout) event.getButton().getParent(); String dateGroupSelector = dateGroupLayout.getData().toString(); // remove date group style from stylesheet serviceGroupLayout.removeComponent(dateGroupLayout); // remove date group and refresh calendars if (calendarStyleSheetResource.removeCssRule(dateGroupSelector)) { cssDateGroup.setValue(calendarStyleSheetResource.getCss()); getWindow().requestRepaintAll(); } groupDays.remove(dateGroupSelector); } }); // cpServiceGroup ColorPicker colorPickerDateGroup = new ColorPicker(); colorPickerDateGroup.setImmediate(true); colorPickerDateGroup.setWidth("23px"); colorPickerDateGroup.setHeight("23px"); colorPickerDateGroup.setButtonStyle(ButtonStyle.BUTTON_AREA); colorPickerDateGroup.setColor(Color.decode(color)); colorPickerDateGroup.addListener(new ColorChangeListener() { @Override public void colorChanged(ColorChangeEvent event) { ColorPicker dateGroupcolorPicker =(ColorPicker) event.getSource(); HorizontalLayout dateGroupLayout = (HorizontalLayout) dateGroupcolorPicker.getParent(); String dateGroupSelector = dateGroupLayout.getData().toString(); String color = "#" + Integer.toHexString(event.getColor().getRGB()).toUpperCase().substring(2); if(existColor(color)) { getWindow().showNotification("¡Ya existe un grupo con ese mismo color!", Notification.TYPE_ERROR_MESSAGE); DateGroupColor dateGroupColor = getDateGroupBySelector(dateGroupSelector); if (dateGroupColor != null) dateGroupcolorPicker.setColor(Color.decode(dateGroupColor.getCalendarGroup().getColor())); return; } // set date group and refresh calendars if (calendarStyleSheetResource.updateCssRule(dateGroupSelector, color)) { cssDateGroup.setValue(calendarStyleSheetResource.getCss()); // get List group days DateGroupColor dateGroupColor = (DateGroupColor) groupDays.get(dateGroupSelector); dateGroupColor.getCalendarGroup().setColor(color); getWindow().requestRepaintAll(); } } }); addServiceGroupLayout.addComponent(colorPickerDateGroup); // serviceGroupName final TextField serviceGroupName = new TextField(); serviceGroupName.setImmediate(false); serviceGroupName.setWidth("100%"); serviceGroupName.setHeight("-1px"); serviceGroupName.setValue(serviceGroupCaption); serviceGroupName.setReadOnly(true); addServiceGroupLayout.addComponent(serviceGroupName); addServiceGroupLayout.setExpandRatio(serviceGroupName, 1.0f); final Label dateGroupWorkingDayLabel = new Label("Laboral:"); dateGroupWorkingDayLabel.setWidth("-1px"); dateGroupWorkingDayLabel.setHeight("-1px"); addServiceGroupLayout.addComponent(dateGroupWorkingDayLabel); addServiceGroupLayout.setComponentAlignment(dateGroupWorkingDayLabel, Alignment.BOTTOM_LEFT); final CheckBox dateGroupWorkingDay = new CheckBox(); dateGroupWorkingDay.setImmediate(true); dateGroupWorkingDay.setWidth("-1px"); dateGroupWorkingDay.setHeight("-1px"); dateGroupWorkingDay.setValue(workingDay); addServiceGroupLayout.addComponent(dateGroupWorkingDay); addServiceGroupLayout.setComponentAlignment(dateGroupWorkingDay, Alignment.BOTTOM_LEFT); dateGroupWorkingDay.addListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { HorizontalLayout dateGroupLayout = (HorizontalLayout) dateGroupWorkingDay.getParent(); String dateGroupSelector = dateGroupLayout.getData().toString(); DateGroupColor dateGroupColor = (DateGroupColor) groupDays.get(dateGroupSelector); dateGroupColor.getCalendarGroup().setWorkingDay((Boolean) dateGroupWorkingDay.getValue()); } }); // btnAttachFileButton Button btnAttachFileButton = new Button(); btnAttachFileButton.setImmediate(false); btnAttachFileButton.setWidth("130px"); btnAttachFileButton.setHeight("-1px"); btnAttachFileButton.setCaption("Adjuntar fichero"); if (file != null) btnAttachFileButton.setIcon(new ThemeResource("../konekti/images/icons/servicedesigner-module/tick.png")); addServiceGroupLayout.addComponent(btnRemoveServiceGroup); btnAttachFileButton.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Button dateGroupColorPicker =(Button) event.getSource(); HorizontalLayout dateGroupLayout = (HorizontalLayout) dateGroupColorPicker.getParent(); final String dateGroupSelector = dateGroupLayout.getData().toString(); final UploadWindow uploadWindow = new UploadWindow(file); uploadWindow.setWidth("300px"); uploadWindow.setHeight("-1px"); uploadWindow.addListener(new CloseListener() { @Override public void windowClose(CloseEvent e) { DateGroupColor dateGroupColor = getDateGroupBySelector(dateGroupSelector); if (dateGroupColor != null) dateGroupColor.getCalendarGroup().setFile(uploadWindow.getFile()); } }); getApplication().getMainWindow().addWindow(uploadWindow); } }); addServiceGroupLayout.addComponent(btnAttachFileButton); // btnApplyGroupServiceButton final Button btnApplyGroupServiceButton = new Button(); btnApplyGroupServiceButton.setCaption("Aplicar"); btnApplyGroupServiceButton.setImmediate(true); btnApplyGroupServiceButton.setWidth("-1px"); btnApplyGroupServiceButton.setHeight("-1px"); addServiceGroupLayout.addComponent(btnApplyGroupServiceButton); addServiceGroupLayout.setComponentAlignment(btnApplyGroupServiceButton, Alignment.TOP_LEFT); btnApplyGroupServiceButton.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { HorizontalLayout dateGroupLayout = (HorizontalLayout) event.getButton().getParent(); String dateGroupSelector = dateGroupLayout.getData().toString(); if (styleCalendarActive == null) return; Date selected = (Date)styleCalendarActive.getValue(); if (selected != null) { // get group date selected DateGroupColor dateGroupColor = (DateGroupColor) groupDays.get(dateGroupSelector); // remove the selected day from any date group before add it to the new date group Iterator<String> i = groupDays.keySet().iterator(); while(i.hasNext()) { String selector = (String) i.next(); DateGroupColor dg = (DateGroupColor) groupDays.get(selector); dg.getDates().remove(selected); } dateGroupColor.getDates().add(selected); // refresh active calendar styleCalendarActive.requestRepaint(); } } }); return addServiceGroupLayout; } @Override protected void updateLabels() { // TODO Auto-generated method stub } }