diff options
author | Marc Englund <marc@vaadin.com> | 2012-10-16 12:47:13 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-10-16 12:47:13 +0000 |
commit | 30dc9f083b981aad4b180999d6f2bacf1207bed0 (patch) | |
tree | fff977f13b828309e4638bfbf14ec24eb0eb3087 /client | |
parent | b888fd4ff5ddb973195394d8ddcb4e0ed2ea19f0 (diff) | |
parent | 014f752f5620433cc0f429821c6464534227dfc9 (diff) | |
download | vaadin-framework-30dc9f083b981aad4b180999d6f2bacf1207bed0.tar.gz vaadin-framework-30dc9f083b981aad4b180999d6f2bacf1207bed0.zip |
Merge "Fixed primary stylename handling for Datefield and InlineDatefield #9903"
Diffstat (limited to 'client')
7 files changed, 96 insertions, 51 deletions
diff --git a/client/src/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java b/client/src/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java index 994a9e1d66..2f48d7411c 100644 --- a/client/src/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java +++ b/client/src/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java @@ -80,7 +80,7 @@ public class AbstractDateFieldConnector extends AbstractFieldConnector // Remove old stylename that indicates current resolution setWidgetStyleName( - VDateField.CLASSNAME + getWidget().getStylePrimaryName() + "-" + VDateField .resolutionToString(getWidget().currentResolution), @@ -90,7 +90,7 @@ public class AbstractDateFieldConnector extends AbstractFieldConnector // Add stylename that indicates current resolution setWidgetStyleName( - VDateField.CLASSNAME + getWidget().getStylePrimaryName() + "-" + VDateField .resolutionToString(getWidget().currentResolution), diff --git a/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java b/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java index fbc7bcc88c..b2a5b49212 100644 --- a/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java +++ b/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java @@ -144,12 +144,12 @@ public class PopupDateFieldConnector extends TextualDateConnector { // update the style change to popup calendar widget with the correct // prefix if (!styleName.startsWith("-")) { - getWidget().popup.setStyleName( - VPopupCalendar.POPUP_PRIMARY_STYLE_NAME + "-" + styleName, + getWidget().popup.setStyleName(getWidget().getStylePrimaryName() + + "-popup-" + styleName, add); } else { - getWidget().popup.setStyleName( - VPopupCalendar.POPUP_PRIMARY_STYLE_NAME + styleName, add); + getWidget().popup.setStyleName(getWidget().getStylePrimaryName() + + "-popup" + styleName, add); } } diff --git a/client/src/com/vaadin/client/ui/datefield/VCalendarPanel.java b/client/src/com/vaadin/client/ui/datefield/VCalendarPanel.java index 0d21638417..2323035e58 100644 --- a/client/src/com/vaadin/client/ui/datefield/VCalendarPanel.java +++ b/client/src/com/vaadin/client/ui/datefield/VCalendarPanel.java @@ -197,9 +197,11 @@ public class VCalendarPanel extends FocusableFlexTable implements private boolean hasFocus = false; - public VCalendarPanel() { + private VDateField parent; + + private boolean initialRenderDone = false; - setStyleName(VDateField.CLASSNAME + "-calendarpanel"); + public VCalendarPanel() { /* * Firefox auto-repeat works correctly only if we use a key press @@ -213,7 +215,10 @@ public class VCalendarPanel extends FocusableFlexTable implements } addFocusHandler(this); addBlurHandler(this); + } + public void setParentField(VDateField parent) { + this.parent = parent; } /** @@ -342,6 +347,26 @@ public class VCalendarPanel extends FocusableFlexTable implements return enabled; } + @Override + public void setStyleName(String style) { + super.setStyleName(style); + if (initialRenderDone) { + // Dynamic updates to the stylename needs to render the calendar to + // update the inner element stylenames + renderCalendar(); + } + } + + @Override + public void setStylePrimaryName(String style) { + super.setStylePrimaryName(style); + if (initialRenderDone) { + // Dynamic updates to the stylename needs to render the calendar to + // update the inner element stylenames + renderCalendar(); + } + } + private void clearCalendarBody(boolean remove) { if (!remove) { // Leave the cells in place but clear their contents @@ -368,7 +393,7 @@ public class VCalendarPanel extends FocusableFlexTable implements private void buildCalendarHeader(boolean needsMonth) { getRowFormatter().addStyleName(0, - VDateField.CLASSNAME + "-calendarpanel-header"); + parent.getStylePrimaryName() + "-calendarpanel-header"); if (prevMonth == null && needsMonth) { prevMonth = new VEventButton(); @@ -379,10 +404,6 @@ public class VCalendarPanel extends FocusableFlexTable implements nextMonth.setHTML("›"); nextMonth.setStyleName("v-button-nextmonth"); nextMonth.setTabIndex(-1); - getFlexCellFormatter().setStyleName(0, 3, - VDateField.CLASSNAME + "-calendarpanel-nextmonth"); - getFlexCellFormatter().setStyleName(0, 1, - VDateField.CLASSNAME + "-calendarpanel-prevmonth"); setWidget(0, 3, nextMonth); setWidget(0, 1, prevMonth); @@ -405,18 +426,24 @@ public class VCalendarPanel extends FocusableFlexTable implements nextYear.setTabIndex(-1); setWidget(0, 0, prevYear); setWidget(0, 4, nextYear); - getFlexCellFormatter().setStyleName(0, 0, - VDateField.CLASSNAME + "-calendarpanel-prevyear"); - getFlexCellFormatter().setStyleName(0, 4, - VDateField.CLASSNAME + "-calendarpanel-nextyear"); } final String monthName = needsMonth ? getDateTimeService().getMonth( displayedMonth.getMonth()) : ""; final int year = displayedMonth.getYear() + 1900; + getFlexCellFormatter().setStyleName(0, 2, - VDateField.CLASSNAME + "-calendarpanel-month"); - setHTML(0, 2, "<span class=\"" + VDateField.CLASSNAME + parent.getStylePrimaryName() + "-calendarpanel-month"); + getFlexCellFormatter().setStyleName(0, 0, + parent.getStylePrimaryName() + "-calendarpanel-prevyear"); + getFlexCellFormatter().setStyleName(0, 4, + parent.getStylePrimaryName() + "-calendarpanel-nextyear"); + getFlexCellFormatter().setStyleName(0, 3, + parent.getStylePrimaryName() + "-calendarpanel-nextmonth"); + getFlexCellFormatter().setStyleName(0, 1, + parent.getStylePrimaryName() + "-calendarpanel-prevmonth"); + + setHTML(0, 2, "<span class=\"" + parent.getStylePrimaryName() + "-calendarpanel-month\">" + monthName + " " + year + "</span>"); } @@ -458,7 +485,7 @@ public class VCalendarPanel extends FocusableFlexTable implements setCellSpacing(0); getFlexCellFormatter().setColSpan(1, 0, 5); getFlexCellFormatter().setStyleName(1, 0, - VDateField.CLASSNAME + "-calendarpanel-body"); + parent.getStylePrimaryName() + "-calendarpanel-body"); days.getFlexCellFormatter().setStyleName(headerRow, weekColumn, "v-week"); @@ -468,7 +495,7 @@ public class VCalendarPanel extends FocusableFlexTable implements isShowISOWeekNumbers()); days.getRowFormatter().setStyleName(headerRow, - VDateField.CLASSNAME + "-calendarpanel-weekdays"); + parent.getStylePrimaryName() + "-calendarpanel-weekdays"); if (isShowISOWeekNumbers()) { days.getFlexCellFormatter().setStyleName(headerRow, weekColumn, @@ -476,7 +503,8 @@ public class VCalendarPanel extends FocusableFlexTable implements days.getFlexCellFormatter().setStyleName(headerRow, firstWeekdayColumn, ""); days.getRowFormatter().addStyleName(headerRow, - VDateField.CLASSNAME + "-calendarpanel-weeknumbers"); + parent.getStylePrimaryName() + + "-calendarpanel-weeknumbers"); } else { days.getFlexCellFormatter().setStyleName(headerRow, weekColumn, ""); days.getFlexCellFormatter().setStyleName(headerRow, @@ -524,6 +552,8 @@ public class VCalendarPanel extends FocusableFlexTable implements // Actually write the day of month Day day = new Day((Date) curr.clone()); + day.setStyleName(parent.getStylePrimaryName() + + "-calendarpanel-day"); if (curr.equals(selectedDate)) { day.addStyleDependentName(CN_SELECTED); @@ -549,7 +579,7 @@ public class VCalendarPanel extends FocusableFlexTable implements days.getCellFormatter().setVisible(weekOfMonth, weekColumn, isShowISOWeekNumbers()); if (isShowISOWeekNumbers()) { - final String baseCssClass = VDateField.CLASSNAME + final String baseCssClass = parent.getStylePrimaryName() + "-calendarpanel-weeknumber"; String weekCssClass = baseCssClass; @@ -605,12 +635,14 @@ public class VCalendarPanel extends FocusableFlexTable implements setWidget(2, 0, time); getFlexCellFormatter().setColSpan(2, 0, 5); getFlexCellFormatter().setStyleName(2, 0, - VDateField.CLASSNAME + "-calendarpanel-time"); + parent.getStylePrimaryName() + "-calendarpanel-time"); } else if (isTimeSelectorNeeded()) { time.updateTimes(); } else if (time != null) { remove(time); } + + initialRenderDone = true; } /** @@ -1539,13 +1571,10 @@ public class VCalendarPanel extends FocusableFlexTable implements * A widget representing a single day in the calendar panel. */ private class Day extends InlineHTML { - private static final String BASECLASS = VDateField.CLASSNAME - + "-calendarpanel-day"; private final Date date; Day(Date date) { super("" + date.getDate()); - setStyleName(BASECLASS); this.date = date; addClickHandler(dayClickHandler); } diff --git a/client/src/com/vaadin/client/ui/datefield/VDateField.java b/client/src/com/vaadin/client/ui/datefield/VDateField.java index 915ac4c54d..84fe061347 100644 --- a/client/src/com/vaadin/client/ui/datefield/VDateField.java +++ b/client/src/com/vaadin/client/ui/datefield/VDateField.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not diff --git a/client/src/com/vaadin/client/ui/datefield/VDateFieldCalendar.java b/client/src/com/vaadin/client/ui/datefield/VDateFieldCalendar.java index 41b7aedae6..2f2c3b3290 100644 --- a/client/src/com/vaadin/client/ui/datefield/VDateFieldCalendar.java +++ b/client/src/com/vaadin/client/ui/datefield/VDateFieldCalendar.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -34,6 +34,7 @@ public class VDateFieldCalendar extends VDateField { public VDateFieldCalendar() { super(); calendarPanel = new VCalendarPanel(); + calendarPanel.setParentField(this); add(calendarPanel); calendarPanel.setSubmitListener(new SubmitListener() { @Override @@ -55,7 +56,7 @@ public class VDateFieldCalendar extends VDateField { } }); } - + /** * TODO refactor: almost same method as in VPopupCalendar.updateValue */ diff --git a/client/src/com/vaadin/client/ui/datefield/VPopupCalendar.java b/client/src/com/vaadin/client/ui/datefield/VPopupCalendar.java index 79ede5b013..0762b965e1 100644 --- a/client/src/com/vaadin/client/ui/datefield/VPopupCalendar.java +++ b/client/src/com/vaadin/client/ui/datefield/VPopupCalendar.java @@ -55,10 +55,7 @@ import com.vaadin.shared.ui.datefield.Resolution; public class VPopupCalendar extends VTextualDate implements Field, ClickHandler, CloseHandler<PopupPanel>, SubPartAware { - protected static final String POPUP_PRIMARY_STYLE_NAME = VDateField.CLASSNAME - + "-popup"; - - protected final Button calendarToggle; + protected final Button calendarToggle = new Button(); protected VCalendarPanel calendar; @@ -69,8 +66,6 @@ public class VPopupCalendar extends VTextualDate implements Field, public VPopupCalendar() { super(); - calendarToggle = new Button(); - calendarToggle.setStyleName(CLASSNAME + "-button"); calendarToggle.setText(""); calendarToggle.addClickHandler(this); // -2 instead of -1 to avoid FocusWidget.onAttach to reset it @@ -78,6 +73,7 @@ public class VPopupCalendar extends VTextualDate implements Field, add(calendarToggle); calendar = GWT.create(VCalendarPanel.class); + calendar.setParentField(this); calendar.setFocusOutListener(new FocusOutListener() { @Override public boolean onFocusOut(DomEvent<?> event) { @@ -106,7 +102,6 @@ public class VPopupCalendar extends VTextualDate implements Field, }); popup = new VOverlay(true, true, true); - popup.setStyleName(POPUP_PRIMARY_STYLE_NAME); popup.setWidget(calendar); popup.addCloseHandler(this); @@ -115,6 +110,7 @@ public class VPopupCalendar extends VTextualDate implements Field, sinkEvents(Event.ONKEYDOWN); + updateStyleNames(); } @SuppressWarnings("deprecation") @@ -163,8 +159,26 @@ public class VPopupCalendar extends VTextualDate implements Field, */ @Override public void setStyleName(String style) { - // make sure the style is there before size calculation - super.setStyleName(style + " " + CLASSNAME + "-popupcalendar"); + super.setStyleName(style); + updateStyleNames(); + } + + @Override + public void setStylePrimaryName(String style) { + removeStyleName(getStylePrimaryName() + "-popupcalendar"); + super.setStylePrimaryName(style); + updateStyleNames(); + } + + @Override + protected void updateStyleNames() { + super.updateStyleNames(); + if (getStylePrimaryName() != null && calendarToggle != null) { + addStyleName(getStylePrimaryName() + "-popupcalendar"); + calendarToggle.setStyleName(getStylePrimaryName() + "-button"); + popup.setStyleName(getStylePrimaryName() + "-popup"); + calendar.setStyleName(getStylePrimaryName() + "-calendarpanel"); + } } /** diff --git a/client/src/com/vaadin/client/ui/datefield/VTextualDate.java b/client/src/com/vaadin/client/ui/datefield/VTextualDate.java index e2d9962979..9bacfded13 100644 --- a/client/src/com/vaadin/client/ui/datefield/VTextualDate.java +++ b/client/src/com/vaadin/client/ui/datefield/VTextualDate.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -39,8 +39,7 @@ import com.vaadin.shared.ui.datefield.Resolution; public class VTextualDate extends VDateField implements Field, ChangeHandler, Focusable, SubPartAware { - private static final String PARSE_ERROR_CLASSNAME = CLASSNAME - + "-parseerror"; + private static final String PARSE_ERROR_CLASSNAME = "-parseerror"; protected final TextBox text; @@ -54,13 +53,8 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, private boolean prompting = false; public VTextualDate() { - super(); text = new TextBox(); - // use normal textfield styles as a basis - text.setStyleName(VTextField.CLASSNAME); - // add datefield spesific style name also - text.addStyleName(CLASSNAME + "-textfield"); text.addChangeHandler(this); text.addFocusHandler(new FocusHandler() { @Override @@ -100,6 +94,13 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, add(text); } + protected void updateStyleNames() { + if (text != null) { + text.setStyleName(VTextField.CLASSNAME); + text.addStyleName(getStylePrimaryName() + "-textfield"); + } + } + protected String getFormatString() { if (formatStr == null) { if (currentResolution == Resolution.YEAR) { @@ -153,7 +154,7 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, * is what usually is needed except for updateFromUIDL. */ protected void buildDate() { - removeStyleName(PARSE_ERROR_CLASSNAME); + removeStyleName(getStylePrimaryName() + PARSE_ERROR_CLASSNAME); // Create the initial text for the textfield String dateText; Date currentDate = getDate(); @@ -206,11 +207,11 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, } // remove possibly added invalid value indication - removeStyleName(PARSE_ERROR_CLASSNAME); + removeStyleName(getStylePrimaryName() + PARSE_ERROR_CLASSNAME); } catch (final Exception e) { VConsole.log(e); - addStyleName(PARSE_ERROR_CLASSNAME); + addStyleName(getStylePrimaryName() + PARSE_ERROR_CLASSNAME); // this is a hack that may eventually be removed getClient().updateVariable(getId(), "lastInvalidDateString", text.getText(), false); @@ -219,7 +220,7 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, } else { setDate(null); // remove possibly added invalid value indication - removeStyleName(PARSE_ERROR_CLASSNAME); + removeStyleName(getStylePrimaryName() + PARSE_ERROR_CLASSNAME); } // always send the date string getClient() |