diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-10-31 18:51:22 +0100 |
---|---|---|
committer | Pekka Maanpää <pekkamaa@vaadin.com> | 2017-10-31 19:51:22 +0200 |
commit | 04905e1e2eb81770d813abda6a516254e541443d (patch) | |
tree | c7b7f1defd8dc908971dfaec0251195707003d22 /compatibility-client | |
parent | d44a5e217d1fc2852adb84cc6ce1c0146ac603f2 (diff) | |
download | vaadin-framework-04905e1e2eb81770d813abda6a516254e541443d.tar.gz vaadin-framework-04905e1e2eb81770d813abda6a516254e541443d.zip |
Use local variable for getWidget(). (#10253)
In some places, getWidget() is called many times, and I believe this can
have a litte performance improvement, since in some cases
super.getWidget() is called more than once.
Diffstat (limited to 'compatibility-client')
10 files changed, 290 insertions, 282 deletions
diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/connectors/GridConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/connectors/GridConnector.java index 57179b678c..06981feac5 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/connectors/GridConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/connectors/GridConnector.java @@ -772,6 +772,7 @@ public class GridConnector extends AbstractHasComponentsConnector protected void init() { super.init(); + Grid<JsonObject> grid = getWidget(); // All scroll RPC calls are executed finally to avoid issues on init registerRpc(GridClientRpc.class, new GridClientRpc() { @Override @@ -783,7 +784,7 @@ public class GridConnector extends AbstractHasComponentsConnector Scheduler.get().scheduleFinally(new ScheduledCommand() { @Override public void execute() { - getWidget().scrollToStart(); + grid.scrollToStart(); } }); } @@ -793,7 +794,7 @@ public class GridConnector extends AbstractHasComponentsConnector Scheduler.get().scheduleFinally(new ScheduledCommand() { @Override public void execute() { - getWidget().scrollToEnd(); + grid.scrollToEnd(); // Scrolls further if details opens. lazyDetailsScroller.scrollToRow(dataSource.size() - 1, ScrollDestination.END); @@ -807,7 +808,7 @@ public class GridConnector extends AbstractHasComponentsConnector Scheduler.get().scheduleFinally(new ScheduledCommand() { @Override public void execute() { - getWidget().scrollToRow(row, destination); + grid.scrollToRow(row, destination); // Scrolls a bit further if details opens. lazyDetailsScroller.scrollToRow(row, destination); } @@ -816,19 +817,19 @@ public class GridConnector extends AbstractHasComponentsConnector @Override public void recalculateColumnWidths() { - getWidget().recalculateColumnWidths(); + grid.recalculateColumnWidths(); } }); /* Item click events */ - getWidget().addBodyClickHandler(itemClickHandler); - getWidget().addBodyDoubleClickHandler(itemClickHandler); + grid.addBodyClickHandler(itemClickHandler); + grid.addBodyDoubleClickHandler(itemClickHandler); /* Style Generators */ - getWidget().setCellStyleGenerator(styleGenerator); - getWidget().setRowStyleGenerator(styleGenerator); + grid.setCellStyleGenerator(styleGenerator); + grid.setRowStyleGenerator(styleGenerator); - getWidget().addSortHandler(new SortHandler<JsonObject>() { + grid.addSortHandler(new SortHandler<JsonObject>() { @Override public void sort(SortEvent<JsonObject> event) { List<SortOrder> order = event.getOrder(); @@ -852,19 +853,19 @@ public class GridConnector extends AbstractHasComponentsConnector } }); - getWidget().setEditorHandler(editorHandler); - getWidget().addColumnReorderHandler(columnReorderHandler); - getWidget().addColumnVisibilityChangeHandler( + grid.setEditorHandler(editorHandler); + grid.addColumnReorderHandler(columnReorderHandler); + grid.addColumnVisibilityChangeHandler( columnVisibilityChangeHandler); - getWidget().addColumnResizeHandler(columnResizeHandler); + grid.addColumnResizeHandler(columnResizeHandler); ConnectorFocusAndBlurHandler.addHandlers(this); - getWidget().setDetailsGenerator(customDetailsGenerator); - getLayoutManager().registerDependency(this, getWidget().getElement()); + grid.setDetailsGenerator(customDetailsGenerator); + getLayoutManager().registerDependency(this, grid.getElement()); // Handling row height changes - getWidget().addRowHeightChangedHandler(new RowHeightChangedHandler() { + grid.addRowHeightChangedHandler(new RowHeightChangedHandler() { @Override public void onRowHeightChanged(RowHeightChangedEvent event) { getLayoutManager() @@ -970,17 +971,18 @@ public class GridConnector extends AbstractHasComponentsConnector } private void updateHeaderFromState(GridStaticSectionState state) { - getWidget().setHeaderVisible(state.visible); + Grid<JsonObject> grid = getWidget(); + grid.setHeaderVisible(state.visible); - while (getWidget().getHeaderRowCount() > 0) { - getWidget().removeHeaderRow(0); + while (grid.getHeaderRowCount() > 0) { + grid.removeHeaderRow(0); } for (RowState rowState : state.rows) { - HeaderRow row = getWidget().appendHeaderRow(); + HeaderRow row = grid.appendHeaderRow(); if (rowState.defaultRow) { - getWidget().setDefaultHeaderRow(row); + grid.setDefaultHeaderRow(row); } for (CellState cellState : rowState.cells) { @@ -1035,14 +1037,15 @@ public class GridConnector extends AbstractHasComponentsConnector } private void updateFooterFromState(GridStaticSectionState state) { - getWidget().setFooterVisible(state.visible); + Grid<JsonObject> grid = getWidget(); + grid.setFooterVisible(state.visible); - while (getWidget().getFooterRowCount() > 0) { - getWidget().removeFooterRow(0); + while (grid.getFooterRowCount() > 0) { + grid.removeFooterRow(0); } for (RowState rowState : state.rows) { - FooterRow row = getWidget().appendFooterRow(); + FooterRow row = grid.appendFooterRow(); for (CellState cellState : rowState.cells) { CustomGridColumn column = columnIdToColumn diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/calendar/CalendarConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/calendar/CalendarConnector.java index 7c3910c009..a9e5341206 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/calendar/CalendarConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/calendar/CalendarConnector.java @@ -137,16 +137,17 @@ public class CalendarConnector extends AbstractLegacyComponentConnector * events. */ protected void registerListeners() { - getWidget().setListener(new DateClickListener() { + VCalendar calendar = getWidget(); + calendar.setListener(new DateClickListener() { @Override public void dateClick(String date) { - if (!getWidget().isDisabled() + if (!calendar.isDisabled() && hasEventListener(CalendarEventId.DATECLICK)) { rpc.dateClick(date); } } }); - getWidget().setListener(new ForwardListener() { + calendar.setListener(new ForwardListener() { @Override public void forward() { if (hasEventListener(CalendarEventId.FORWARD)) { @@ -154,7 +155,7 @@ public class CalendarConnector extends AbstractLegacyComponentConnector } } }); - getWidget().setListener(new BackwardListener() { + calendar.setListener(new BackwardListener() { @Override public void backward() { if (hasEventListener(CalendarEventId.BACKWARD)) { @@ -162,7 +163,7 @@ public class CalendarConnector extends AbstractLegacyComponentConnector } } }); - getWidget().setListener(new RangeSelectListener() { + calendar.setListener(new RangeSelectListener() { @Override public void rangeSelected(String value) { if (hasEventListener(CalendarEventId.RANGESELECT)) { @@ -170,16 +171,16 @@ public class CalendarConnector extends AbstractLegacyComponentConnector } } }); - getWidget().setListener(new WeekClickListener() { + calendar.setListener(new WeekClickListener() { @Override public void weekClick(String event) { - if (!getWidget().isDisabled() + if (!calendar.isDisabled() && hasEventListener(CalendarEventId.WEEKCLICK)) { rpc.weekClick(event); } } }); - getWidget().setListener(new EventMovedListener() { + calendar.setListener(new EventMovedListener() { @Override public void eventMoved(CalendarEvent event) { if (hasEventListener(CalendarEventId.EVENTMOVE)) { @@ -192,7 +193,7 @@ public class CalendarConnector extends AbstractLegacyComponentConnector } } }); - getWidget().setListener(new EventResizeListener() { + calendar.setListener(new EventResizeListener() { @Override public void eventResized(CalendarEvent event) { if (hasEventListener(CalendarEventId.EVENTRESIZE)) { @@ -219,14 +220,14 @@ public class CalendarConnector extends AbstractLegacyComponentConnector } } }); - getWidget().setListener(new VCalendar.ScrollListener() { + calendar.setListener(new VCalendar.ScrollListener() { @Override public void scroll(int scrollPosition) { // This call is @Delayed (== non-immediate) rpc.scroll(scrollPosition); } }); - getWidget().setListener(new EventClickListener() { + calendar.setListener(new EventClickListener() { @Override public void eventClick(CalendarEvent event) { if (hasEventListener(CalendarEventId.EVENTCLICK)) { @@ -234,7 +235,7 @@ public class CalendarConnector extends AbstractLegacyComponentConnector } } }); - getWidget().setListener(new MouseEventListener() { + calendar.setListener(new MouseEventListener() { @Override public void contextMenu(ContextMenuEvent event, final Widget widget) { @@ -327,54 +328,56 @@ public class CalendarConnector extends AbstractLegacyComponentConnector super.onStateChanged(stateChangeEvent); CalendarState state = getState(); - VCalendar widget = getWidget(); + VCalendar calendar = getWidget(); // Enable or disable the forward and backward navigation buttons - widget.setForwardNavigationEnabled( + calendar.setForwardNavigationEnabled( hasEventListener(CalendarEventId.FORWARD)); - widget.setBackwardNavigationEnabled( + calendar.setBackwardNavigationEnabled( hasEventListener(CalendarEventId.BACKWARD)); - widget.set24HFormat(state.format24H); - widget.setDayNames(state.dayNames); - widget.setMonthNames(state.monthNames); - widget.setFirstDayNumber(state.firstVisibleDayOfWeek); - widget.setLastDayNumber(state.lastVisibleDayOfWeek); - widget.setFirstHourOfTheDay(state.firstHourOfDay); - widget.setLastHourOfTheDay(state.lastHourOfDay); - widget.setReadOnly(state.readOnly); - widget.setDisabled(!state.enabled); - - widget.setRangeSelectAllowed( + calendar.set24HFormat(state.format24H); + calendar.setDayNames(state.dayNames); + calendar.setMonthNames(state.monthNames); + calendar.setFirstDayNumber(state.firstVisibleDayOfWeek); + calendar.setLastDayNumber(state.lastVisibleDayOfWeek); + calendar.setFirstHourOfTheDay(state.firstHourOfDay); + calendar.setLastHourOfTheDay(state.lastHourOfDay); + calendar.setReadOnly(state.readOnly); + calendar.setDisabled(!state.enabled); + + calendar.setRangeSelectAllowed( hasEventListener(CalendarEventId.RANGESELECT)); - widget.setRangeMoveAllowed(hasEventListener(CalendarEventId.EVENTMOVE)); - widget.setEventMoveAllowed(hasEventListener(CalendarEventId.EVENTMOVE)); - widget.setEventResizeAllowed( + calendar.setRangeMoveAllowed( + hasEventListener(CalendarEventId.EVENTMOVE)); + calendar.setEventMoveAllowed( + hasEventListener(CalendarEventId.EVENTMOVE)); + calendar.setEventResizeAllowed( hasEventListener(CalendarEventId.EVENTRESIZE)); - widget.setEventCaptionAsHtml(state.eventCaptionAsHtml); + calendar.setEventCaptionAsHtml(state.eventCaptionAsHtml); - EventSortOrder oldOrder = getWidget().getSortOrder(); + EventSortOrder oldOrder = calendar.getSortOrder(); if (!SharedUtil.equals(oldOrder, getState().eventSortOrder)) { - getWidget().setSortOrder(getState().eventSortOrder); + calendar.setSortOrder(getState().eventSortOrder); } updateEventsInView(); List<CalendarState.Day> days = state.days; List<CalendarState.Event> events = state.events; - CalendarDropHandler dropHandler = getWidget().getDropHandler(); + CalendarDropHandler dropHandler = calendar.getDropHandler(); if (showingMonthView()) { updateMonthView(days, events); if (dropHandler != null && !(dropHandler instanceof CalendarMonthDropHandler)) { - getWidget().setDropHandler(new CalendarMonthDropHandler(this)); + calendar.setDropHandler(new CalendarMonthDropHandler(this)); } } else { updateWeekView(days, events); if (dropHandler != null && !(dropHandler instanceof CalendarWeekDropHandler)) { - getWidget().setDropHandler(new CalendarWeekDropHandler(this)); + calendar.setDropHandler(new CalendarWeekDropHandler(this)); } } diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/combobox/ComboBoxConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/combobox/ComboBoxConnector.java index e064eb9dad..7b5cd4eaf6 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/combobox/ComboBoxConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/combobox/ComboBoxConnector.java @@ -50,12 +50,13 @@ public class ComboBoxConnector extends AbstractFieldConnector */ @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + VFilterSelect widget = getWidget(); // Save details - getWidget().client = client; - getWidget().paintableId = uidl.getId(); + widget.client = client; + widget.paintableId = uidl.getId(); - getWidget().readonly = isReadOnly(); - getWidget().updateReadOnly(); + widget.readonly = isReadOnly(); + widget.updateReadOnly(); if (!isRealUpdate(uidl)) { return; @@ -67,75 +68,75 @@ public class ComboBoxConnector extends AbstractFieldConnector .hasAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT) && uidl.getBooleanAttribute( ComboBoxConstants.ATTR_NO_TEXT_INPUT); - getWidget().setTextInputEnabled(!noTextInput); + widget.setTextInputEnabled(!noTextInput); // not a FocusWidget -> needs own tabindex handling - getWidget().tb.setTabIndex(getState().tabIndex); + widget.tb.setTabIndex(getState().tabIndex); if (uidl.hasAttribute("filteringmode")) { - getWidget().filteringmode = FilteringMode + widget.filteringmode = FilteringMode .valueOf(uidl.getStringAttribute("filteringmode")); } - getWidget().immediate = getState().immediate; + widget.immediate = getState().immediate; - getWidget().nullSelectionAllowed = uidl.hasAttribute("nullselect"); + widget.nullSelectionAllowed = uidl.hasAttribute("nullselect"); - getWidget().nullSelectItem = uidl.hasAttribute("nullselectitem") + widget.nullSelectItem = uidl.hasAttribute("nullselectitem") && uidl.getBooleanAttribute("nullselectitem"); - getWidget().currentPage = uidl.getIntVariable("page"); + widget.currentPage = uidl.getIntVariable("page"); if (uidl.hasAttribute("pagelength")) { - getWidget().pageLength = uidl.getIntAttribute("pagelength"); + widget.pageLength = uidl.getIntAttribute("pagelength"); } if (uidl.hasAttribute(ComboBoxConstants.ATTR_INPUTPROMPT)) { // input prompt changed from server - getWidget().inputPrompt = uidl + widget.inputPrompt = uidl .getStringAttribute(ComboBoxConstants.ATTR_INPUTPROMPT); } else { - getWidget().inputPrompt = ""; + widget.inputPrompt = ""; } if (uidl.hasAttribute("suggestionPopupWidth")) { - getWidget().suggestionPopupWidth = uidl + widget.suggestionPopupWidth = uidl .getStringAttribute("suggestionPopupWidth"); } else { - getWidget().suggestionPopupWidth = null; + widget.suggestionPopupWidth = null; } if (uidl.hasAttribute("suggestionPopupWidth")) { - getWidget().suggestionPopupWidth = uidl + widget.suggestionPopupWidth = uidl .getStringAttribute("suggestionPopupWidth"); } else { - getWidget().suggestionPopupWidth = null; + widget.suggestionPopupWidth = null; } - getWidget().suggestionPopup.updateStyleNames(uidl, getState()); + widget.suggestionPopup.updateStyleNames(uidl, getState()); - getWidget().allowNewItem = uidl.hasAttribute("allownewitem"); - getWidget().lastNewItemString = null; + widget.allowNewItem = uidl.hasAttribute("allownewitem"); + widget.lastNewItemString = null; final UIDL options = uidl.getChildUIDL(0); if (uidl.hasAttribute("totalMatches")) { - getWidget().totalMatches = uidl.getIntAttribute("totalMatches"); + widget.totalMatches = uidl.getIntAttribute("totalMatches"); } else { - getWidget().totalMatches = 0; + widget.totalMatches = 0; } List<FilterSelectSuggestion> newSuggestions = new ArrayList<FilterSelectSuggestion>(); for (final Object child : options) { final UIDL optionUidl = (UIDL) child; - final FilterSelectSuggestion suggestion = getWidget().new FilterSelectSuggestion( + final FilterSelectSuggestion suggestion = widget.new FilterSelectSuggestion( optionUidl); newSuggestions.add(suggestion); } // only close the popup if the suggestions list has actually changed - boolean suggestionsChanged = !getWidget().initDone - || !newSuggestions.equals(getWidget().currentSuggestions); + boolean suggestionsChanged = !widget.initDone + || !newSuggestions.equals(widget.currentSuggestions); // An ItemSetChangeEvent on server side clears the current suggestion // popup. Popup needs to be repopulated with suggestions from UIDL. @@ -145,28 +146,28 @@ public class ComboBoxConnector extends AbstractFieldConnector if (suggestionsChanged) { oldSuggestionTextMatchTheOldSelection = isWidgetsCurrentSelectionTextInTextBox(); - getWidget().currentSuggestions.clear(); + widget.currentSuggestions.clear(); - if (!getWidget().waitingForFilteringResponse) { + if (!widget.waitingForFilteringResponse) { /* * Clear the current suggestions as the server response always * includes the new ones. Exception is when filtering, then we * need to retain the value if the user does not select any of * the options matching the filter. */ - getWidget().currentSuggestion = null; + widget.currentSuggestion = null; /* * Also ensure no old items in menu. Unless cleared the old * values may cause odd effects on blur events. Suggestions in * menu might not necessary exist in select at all anymore. */ - getWidget().suggestionPopup.menu.clearItems(); - popupOpenAndCleared = getWidget().suggestionPopup.isAttached(); + widget.suggestionPopup.menu.clearItems(); + popupOpenAndCleared = widget.suggestionPopup.isAttached(); } for (FilterSelectSuggestion suggestion : newSuggestions) { - getWidget().currentSuggestions.add(suggestion); + widget.currentSuggestions.add(suggestion); } } @@ -175,7 +176,7 @@ public class ComboBoxConnector extends AbstractFieldConnector // In case we're switching page no need to update the selection as the // selection process didn't finish. - // && getWidget().selectPopupItemWhenResponseIsReceived == + // && widget.selectPopupItemWhenResponseIsReceived == // VFilterSelect.Select.NONE // ) { @@ -190,32 +191,31 @@ public class ComboBoxConnector extends AbstractFieldConnector performSelection(selectedKeys[0]); // if selected key is available, assume caption is know based on // it as well and clear selected caption - getWidget().setSelectedCaption(null); + widget.setSelectedCaption(null); - } else if (!getWidget().waitingForFilteringResponse + } else if (!widget.waitingForFilteringResponse && uidl.hasAttribute("selectedCaption")) { // scrolling to correct page is disabled, caption is passed as a // special parameter - getWidget().setSelectedCaption( + widget.setSelectedCaption( uidl.getStringAttribute("selectedCaption")); } else { resetSelection(); } } - if ((getWidget().waitingForFilteringResponse - && getWidget().lastFilter.toLowerCase(Locale.ROOT) + if ((widget.waitingForFilteringResponse + && widget.lastFilter.toLowerCase(Locale.ROOT) .equals(uidl.getStringVariable("filter"))) || popupOpenAndCleared) { - getWidget().suggestionPopup.showSuggestions( - getWidget().currentSuggestions, getWidget().currentPage, - getWidget().totalMatches); + widget.suggestionPopup.showSuggestions(widget.currentSuggestions, + widget.currentPage, widget.totalMatches); - getWidget().waitingForFilteringResponse = false; + widget.waitingForFilteringResponse = false; - if (!getWidget().popupOpenerClicked - && getWidget().selectPopupItemWhenResponseIsReceived != VFilterSelect.Select.NONE) { + if (!widget.popupOpenerClicked + && widget.selectPopupItemWhenResponseIsReceived != VFilterSelect.Select.NONE) { // we're paging w/ arrows Scheduler.get().scheduleDeferred(new ScheduledCommand() { @@ -226,32 +226,32 @@ public class ComboBoxConnector extends AbstractFieldConnector }); } - if (getWidget().updateSelectionWhenReponseIsReceived) { - getWidget().suggestionPopup.menu + if (widget.updateSelectionWhenReponseIsReceived) { + widget.suggestionPopup.menu .doPostFilterSelectedItemAction(); } } // Calculate minimum textarea width - getWidget().updateSuggestionPopupMinWidth(); + widget.updateSuggestionPopupMinWidth(); - getWidget().popupOpenerClicked = false; + widget.popupOpenerClicked = false; /* * if this is our first time we need to recalculate the root width. */ - if (!getWidget().initDone) { + if (!widget.initDone) { - getWidget().updateRootWidth(); + widget.updateRootWidth(); } // Focus dependent style names are lost during the update, so we add // them here back again - if (getWidget().focused) { - getWidget().addStyleDependentName("focus"); + if (widget.focused) { + widget.addStyleDependentName("focus"); } - getWidget().initDone = true; + widget.initDone = true; } /* @@ -277,30 +277,31 @@ public class ComboBoxConnector extends AbstractFieldConnector } private void performSelection(String selectedKey) { + VFilterSelect widget = getWidget(); // some item selected - for (FilterSelectSuggestion suggestion : getWidget().currentSuggestions) { + for (FilterSelectSuggestion suggestion : widget.currentSuggestions) { String suggestionKey = suggestion.getOptionKey(); if (!suggestionKey.equals(selectedKey)) { continue; } - if (!getWidget().waitingForFilteringResponse - || getWidget().popupOpenerClicked) { - if (!suggestionKey.equals(getWidget().selectedOptionKey) + if (!widget.waitingForFilteringResponse + || widget.popupOpenerClicked) { + if (!suggestionKey.equals(widget.selectedOptionKey) || suggestion.getReplacementString() - .equals(getWidget().tb.getText()) + .equals(widget.tb.getText()) || oldSuggestionTextMatchTheOldSelection) { // Update text field if we've got a new // selection // Also update if we've got the same text to // retain old text selection behavior // OR if selected item caption is changed. - getWidget() + widget .setPromptingOff(suggestion.getReplacementString()); - getWidget().selectedOptionKey = suggestionKey; + widget.selectedOptionKey = suggestionKey; } } - getWidget().currentSuggestion = suggestion; - getWidget().setSelectedItemIcon(suggestion.getIconUri()); + widget.currentSuggestion = suggestion; + widget.setSelectedItemIcon(suggestion.getIconUri()); // only a single item can be selected break; } @@ -313,41 +314,39 @@ public class ComboBoxConnector extends AbstractFieldConnector } private void resetSelection() { - if (!getWidget().waitingForFilteringResponse - || getWidget().popupOpenerClicked) { + VFilterSelect widget = getWidget(); + if (!widget.waitingForFilteringResponse || widget.popupOpenerClicked) { // select nulled - if (!getWidget().focused) { + if (!widget.focused) { /* * client.updateComponent overwrites all styles so we must * ALWAYS set the prompting style at this point, even though we * think it has been set already... */ - getWidget().setPromptingOff(""); - if (getWidget().enabled && !getWidget().readonly) { - getWidget().setPromptingOn(); + widget.setPromptingOff(""); + if (widget.enabled && !widget.readonly) { + widget.setPromptingOn(); } } else { // we have focus in field, prompting can't be set on, instead // just clear the input if the value has changed from something // else to null - if (getWidget().selectedOptionKey != null - || (getWidget().allowNewItem - && !getWidget().tb.getValue().isEmpty())) { + if (widget.selectedOptionKey != null || (widget.allowNewItem + && !widget.tb.getValue().isEmpty())) { - boolean openedPopupWithNonScrollingMode = (getWidget().popupOpenerClicked - && getWidget().getSelectedCaption() != null); + boolean openedPopupWithNonScrollingMode = (widget.popupOpenerClicked + && widget.getSelectedCaption() != null); if (!openedPopupWithNonScrollingMode) { - getWidget().tb.setValue(""); + widget.tb.setValue(""); } else { - getWidget().tb - .setValue(getWidget().getSelectedCaption()); - getWidget().tb.selectAll(); + widget.tb.setValue(widget.getSelectedCaption()); + widget.tb.selectAll(); } } } - getWidget().currentSuggestion = null; // #13217 - getWidget().setSelectedItemIcon(null); - getWidget().selectedOptionKey = null; + widget.currentSuggestion = null; // #13217 + widget.setSelectedItemIcon(null); + widget.selectedOptionKey = null; } } diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/DateFieldConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/DateFieldConnector.java index 746af3043d..3266c8aa05 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/DateFieldConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/DateFieldConnector.java @@ -70,67 +70,66 @@ public class DateFieldConnector extends TextualDateConnector { @SuppressWarnings("deprecation") public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - String oldLocale = getWidget().getCurrentLocale(); + VPopupCalendar widget = getWidget(); + String oldLocale = widget.getCurrentLocale(); - getWidget().parsable = uidl.getBooleanAttribute("parsable"); + widget.parsable = uidl.getBooleanAttribute("parsable"); super.updateFromUIDL(uidl, client); - getWidget().calendar - .setDateTimeService(getWidget().getDateTimeService()); - getWidget().calendar - .setShowISOWeekNumbers(getWidget().isShowISOWeekNumbers()); - if (getWidget().calendar.getResolution() != getWidget() + widget.calendar.setDateTimeService(widget.getDateTimeService()); + widget.calendar + .setShowISOWeekNumbers(widget.isShowISOWeekNumbers()); + if (widget.calendar.getResolution() != widget .getCurrentResolution()) { boolean hasSelectedDate = false; - getWidget().calendar - .setResolution(getWidget().getCurrentResolution()); - if (getWidget().calendar.getDate() != null - && getWidget().getCurrentDate() != null) { + widget.calendar.setResolution(widget.getCurrentResolution()); + if (widget.calendar.getDate() != null + && widget.getCurrentDate() != null) { hasSelectedDate = true; - getWidget().calendar - .setDate((Date) getWidget().getCurrentDate().clone()); + widget.calendar + .setDate((Date) widget.getCurrentDate().clone()); } // force re-render when changing resolution only - getWidget().calendar.renderCalendar(hasSelectedDate); + widget.calendar.renderCalendar(hasSelectedDate); } // Force re-render of calendar if locale has changed (#12153) - if (!getWidget().getCurrentLocale().equals(oldLocale)) { - getWidget().calendar.renderCalendar(); + if (!widget.getCurrentLocale().equals(oldLocale)) { + widget.calendar.renderCalendar(); } - if (getWidget().getCurrentResolution() + if (widget.getCurrentResolution() .getCalendarField() <= Resolution.MONTH.getCalendarField()) { - getWidget().calendar + widget.calendar .setFocusChangeListener(new FocusChangeListener() { @Override public void focusChanged(Date date) { - getWidget().updateValue(date); - getWidget().buildDate(); - Date date2 = getWidget().calendar.getDate(); + widget.updateValue(date); + widget.buildDate(); + Date date2 = widget.calendar.getDate(); date2.setYear(date.getYear()); date2.setMonth(date.getMonth()); } }); } else { - getWidget().calendar.setFocusChangeListener(null); + widget.calendar.setFocusChangeListener(null); } - if (getWidget().getCurrentResolution() + if (widget.getCurrentResolution() .getCalendarField() > Resolution.DAY.getCalendarField()) { - getWidget().calendar + widget.calendar .setTimeChangeListener(new TimeChangeListener() { @Override public void changed(int hour, int min, int sec, int msec) { - Date d = getWidget().getDate(); + Date d = widget.getDate(); if (d == null) { // date currently null, use the value from // calendarPanel // (~ client time at the init of the widget) - d = (Date) getWidget().calendar.getDate() + d = (Date) widget.calendar.getDate() .clone(); } d.setHours(hour); @@ -139,26 +138,26 @@ public class DateFieldConnector extends TextualDateConnector { DateTimeService.setMilliseconds(d, msec); // Always update time changes to the server - getWidget().updateValue(d); + widget.updateValue(d); // Update text field - getWidget().buildDate(); + widget.buildDate(); } }); } - if (getWidget().isReadonly()) { - getWidget().calendarToggle.addStyleName( + if (widget.isReadonly()) { + widget.calendarToggle.addStyleName( VPopupCalendar.CLASSNAME + "-button-readonly"); } else { - getWidget().calendarToggle.removeStyleName( + widget.calendarToggle.removeStyleName( VPopupCalendar.CLASSNAME + "-button-readonly"); } - getWidget().setDescriptionForAssistiveDevices( + widget.setDescriptionForAssistiveDevices( getState().descriptionForAssistiveDevices); - getWidget().setTextFieldTabIndex(); + widget.setTextFieldTabIndex(); } @Override diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/InlineDateFieldConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/InlineDateFieldConnector.java index ddf72a0705..080b3d69fe 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/InlineDateFieldConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/InlineDateFieldConnector.java @@ -22,6 +22,7 @@ import com.vaadin.client.DateTimeService; import com.vaadin.client.UIDL; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.shared.ui.Connect; +import com.vaadin.v7.client.ui.VCalendarPanel; import com.vaadin.v7.client.ui.VCalendarPanel.FocusChangeListener; import com.vaadin.v7.client.ui.VCalendarPanel.TimeChangeListener; import com.vaadin.v7.client.ui.VDateFieldCalendar; @@ -40,32 +41,31 @@ public class InlineDateFieldConnector extends AbstractDateFieldConnector { return; } - getWidget().calendarPanel - .setShowISOWeekNumbers(getWidget().isShowISOWeekNumbers()); - getWidget().calendarPanel - .setDateTimeService(getWidget().getDateTimeService()); - getWidget().calendarPanel - .setResolution(getWidget().getCurrentResolution()); - Date currentDate = getWidget().getCurrentDate(); + VDateFieldCalendar calendar = getWidget(); + VCalendarPanel panel = calendar.calendarPanel; + panel.setShowISOWeekNumbers(calendar.isShowISOWeekNumbers()); + panel.setDateTimeService(calendar.getDateTimeService()); + panel.setResolution(calendar.getCurrentResolution()); + Date currentDate = calendar.getCurrentDate(); if (currentDate != null) { - getWidget().calendarPanel.setDate(new Date(currentDate.getTime())); + panel.setDate(new Date(currentDate.getTime())); } else { - getWidget().calendarPanel.setDate(null); + panel.setDate(null); } - if (getWidget().getCurrentResolution() + if (calendar.getCurrentResolution() .getCalendarField() > Resolution.DAY.getCalendarField()) { - getWidget().calendarPanel + panel .setTimeChangeListener(new TimeChangeListener() { @Override public void changed(int hour, int min, int sec, int msec) { - Date d = getWidget().getDate(); + Date d = calendar.getDate(); if (d == null) { // date currently null, use the value from // calendarPanel // (~ client time at the init of the widget) - d = (Date) getWidget().calendarPanel.getDate() + d = (Date) panel.getDate() .clone(); } d.setHours(hour); @@ -74,21 +74,21 @@ public class InlineDateFieldConnector extends AbstractDateFieldConnector { DateTimeService.setMilliseconds(d, msec); // Always update time changes to the server - getWidget().calendarPanel.setDate(d); - getWidget().updateValueFromPanel(); + panel.setDate(d); + calendar.updateValueFromPanel(); } }); } - if (getWidget().getCurrentResolution() + if (calendar.getCurrentResolution() .getCalendarField() <= Resolution.MONTH.getCalendarField()) { - getWidget().calendarPanel + panel .setFocusChangeListener(new FocusChangeListener() { @Override public void focusChanged(Date date) { Date date2 = new Date(); - if (getWidget().calendarPanel.getDate() != null) { - date2.setTime(getWidget().calendarPanel + if (panel.getDate() != null) { + date2.setTime(panel .getDate().getTime()); } /* @@ -96,19 +96,19 @@ public class InlineDateFieldConnector extends AbstractDateFieldConnector { */ date2.setYear(date.getYear()); date2.setMonth(date.getMonth()); - getWidget().calendarPanel.setDate(date2); + panel.setDate(date2); /* * Then update the value from panel to server */ - getWidget().updateValueFromPanel(); + calendar.updateValueFromPanel(); } }); } else { - getWidget().calendarPanel.setFocusChangeListener(null); + panel.setFocusChangeListener(null); } // Update possible changes - getWidget().calendarPanel.renderCalendar(); + panel.renderCalendar(); } @Override diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/TextualDateConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/TextualDateConnector.java index a41fca521f..52a57552c1 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/TextualDateConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/TextualDateConnector.java @@ -26,33 +26,33 @@ public class TextualDateConnector extends AbstractDateFieldConnector { @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - Resolution origRes = getWidget().getCurrentResolution(); - String oldLocale = getWidget().getCurrentLocale(); + VTextualDate date = getWidget(); + Resolution origRes = date.getCurrentResolution(); + String oldLocale = date.getCurrentLocale(); super.updateFromUIDL(uidl, client); - if (origRes != getWidget().getCurrentResolution() - || oldLocale != getWidget().getCurrentLocale()) { + if (origRes != date.getCurrentResolution() + || oldLocale != date.getCurrentLocale()) { // force recreating format string - getWidget().formatStr = null; + date.formatStr = null; } if (uidl.hasAttribute("format")) { - getWidget().formatStr = uidl.getStringAttribute("format"); + date.formatStr = uidl.getStringAttribute("format"); } - getWidget().inputPrompt = uidl + date.inputPrompt = uidl .getStringAttribute(VTextualDate.ATTR_INPUTPROMPT); - getWidget().lenient = !uidl.getBooleanAttribute("strict"); + date.lenient = !uidl.getBooleanAttribute("strict"); - getWidget().buildDate(); + date.buildDate(); // not a FocusWidget -> needs own tabindex handling - getWidget().text.setTabIndex(getState().tabIndex); + date.text.setTabIndex(getState().tabIndex); - if (getWidget().isReadonly()) { - getWidget().text.addStyleDependentName("readonly"); + if (date.isReadonly()) { + date.text.addStyleDependentName("readonly"); } else { - getWidget().text.removeStyleDependentName("readonly"); + date.text.removeStyleDependentName("readonly"); } - } @Override diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/form/FormConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/form/FormConnector.java index ab28118c66..661d729f07 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/form/FormConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/form/FormConnector.java @@ -95,8 +95,9 @@ public class FormConnector extends AbstractComponentContainerConnector @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - getWidget().client = client; - getWidget().id = uidl.getId(); + VForm form = getWidget(); + form.client = client; + form.id = uidl.getId(); if (!isRealUpdate(uidl)) { return; @@ -104,67 +105,67 @@ public class FormConnector extends AbstractComponentContainerConnector boolean legendEmpty = true; if (getState().caption != null) { - VCaption.setCaptionText(getWidget().caption, getState()); + VCaption.setCaptionText(form.caption, getState()); legendEmpty = false; } else { - getWidget().caption.setInnerText(""); + form.caption.setInnerText(""); } - if (getWidget().icon != null) { - getWidget().legend.removeChild(getWidget().icon.getElement()); + if (form.icon != null) { + form.legend.removeChild(form.icon.getElement()); } if (getIconUri() != null) { - getWidget().icon = client.getIcon(getIconUri()); - getWidget().legend.insertFirst(getWidget().icon.getElement()); + form.icon = client.getIcon(getIconUri()); + form.legend.insertFirst(form.icon.getElement()); legendEmpty = false; } if (legendEmpty) { - getWidget().addStyleDependentName("nocaption"); + form.addStyleDependentName("nocaption"); } else { - getWidget().removeStyleDependentName("nocaption"); + form.removeStyleDependentName("nocaption"); } if (null != getState().errorMessage) { - getWidget().errorMessage.updateMessage(getState().errorMessage); - getWidget().errorMessage.updateErrorLevel(getState().errorLevel); - getWidget().errorMessage.setVisible(true); + form.errorMessage.updateMessage(getState().errorMessage); + form.errorMessage.updateErrorLevel(getState().errorLevel); + form.errorMessage.setVisible(true); } else { - getWidget().errorMessage.setVisible(false); + form.errorMessage.setVisible(false); } if (ComponentStateUtil.hasDescription(getState())) { - getWidget().desc.setInnerHTML(getState().description); - if (getWidget().desc.getParentElement() == null) { - getWidget().fieldSet.insertAfter(getWidget().desc, - getWidget().legend); + form.desc.setInnerHTML(getState().description); + if (form.desc.getParentElement() == null) { + form.fieldSet.insertAfter(form.desc, + form.legend); } } else { - getWidget().desc.setInnerHTML(""); - if (getWidget().desc.getParentElement() != null) { - getWidget().fieldSet.removeChild(getWidget().desc); + form.desc.setInnerHTML(""); + if (form.desc.getParentElement() != null) { + form.fieldSet.removeChild(form.desc); } } // also recalculates size of the footer if undefined size form - see // #3710 - client.runDescendentsLayout(getWidget()); + client.runDescendentsLayout(form); // We may have actions attached if (uidl.getChildCount() >= 1) { UIDL childUidl = uidl.getChildByTagName("actions"); if (childUidl != null) { - if (getWidget().shortcutHandler == null) { - getWidget().shortcutHandler = new ShortcutActionHandler( + if (form.shortcutHandler == null) { + form.shortcutHandler = new ShortcutActionHandler( getConnectorId(), client); - getWidget().keyDownRegistration = getWidget() - .addDomHandler(getWidget(), KeyDownEvent.getType()); + form.keyDownRegistration = form + .addDomHandler(form, KeyDownEvent.getType()); } - getWidget().shortcutHandler.updateActionMap(childUidl); + form.shortcutHandler.updateActionMap(childUidl); } - } else if (getWidget().shortcutHandler != null) { - getWidget().keyDownRegistration.removeHandler(); - getWidget().shortcutHandler = null; - getWidget().keyDownRegistration = null; + } else if (form.shortcutHandler != null) { + form.keyDownRegistration.removeHandler(); + form.shortcutHandler = null; + form.keyDownRegistration = null; } } diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/label/LabelConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/label/LabelConnector.java index 9ef43775bf..0527cbe4fa 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/label/LabelConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/label/LabelConnector.java @@ -40,28 +40,29 @@ public class LabelConnector extends AbstractLegacyComponentConnector { super.onStateChanged(stateChangeEvent); boolean sinkOnloads = false; Profiler.enter("LabelConnector.onStateChanged update content"); + VLabel widget = getWidget(); switch (getState().contentMode) { case PREFORMATTED: PreElement preElement = Document.get().createPreElement(); preElement.setInnerText(getState().text); // clear existing content - getWidget().setHTML(""); + widget.setHTML(""); // add preformatted text to dom - getWidget().getElement().appendChild(preElement); + widget.getElement().appendChild(preElement); break; case TEXT: - getWidget().setText(getState().text); + widget.setText(getState().text); break; case HTML: case RAW: sinkOnloads = true; case XML: - getWidget().setHTML(getState().text); + widget.setHTML(getState().text); break; default: - getWidget().setText(""); + widget.setText(""); break; } @@ -69,7 +70,7 @@ public class LabelConnector extends AbstractLegacyComponentConnector { if (sinkOnloads) { Profiler.enter("LabelConnector.onStateChanged sinkOnloads"); - WidgetUtil.sinkOnloadForImages(getWidget().getElement()); + WidgetUtil.sinkOnloadForImages(widget.getElement()); Profiler.leave("LabelConnector.onStateChanged sinkOnloads"); } } diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/textfield/TextFieldConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/textfield/TextFieldConnector.java index 15037d4b50..480e0f7d0a 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/textfield/TextFieldConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/textfield/TextFieldConnector.java @@ -42,40 +42,41 @@ public class TextFieldConnector extends AbstractFieldConnector @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + VTextField textField = getWidget(); // Save details - getWidget().client = client; - getWidget().paintableId = uidl.getId(); + textField.client = client; + textField.paintableId = uidl.getId(); if (!isRealUpdate(uidl)) { return; } - getWidget().setReadOnly(isReadOnly()); + textField.setReadOnly(isReadOnly()); - getWidget().setInputPrompt(getState().inputPrompt); - getWidget().setMaxLength(getState().maxLength); - getWidget().setImmediate(getState().immediate); + textField.setInputPrompt(getState().inputPrompt); + textField.setMaxLength(getState().maxLength); + textField.setImmediate(getState().immediate); - getWidget().listenTextChangeEvents = hasEventListener("ie"); - if (getWidget().listenTextChangeEvents) { - getWidget().textChangeEventMode = uidl.getStringAttribute( + textField.listenTextChangeEvents = hasEventListener("ie"); + if (textField.listenTextChangeEvents) { + textField.textChangeEventMode = uidl.getStringAttribute( TextFieldConstants.ATTR_TEXTCHANGE_EVENTMODE); - if (getWidget().textChangeEventMode + if (textField.textChangeEventMode .equals(TextFieldConstants.TEXTCHANGE_MODE_EAGER)) { - getWidget().textChangeEventTimeout = 1; + textField.textChangeEventTimeout = 1; } else { - getWidget().textChangeEventTimeout = uidl.getIntAttribute( + textField.textChangeEventTimeout = uidl.getIntAttribute( TextFieldConstants.ATTR_TEXTCHANGE_TIMEOUT); - if (getWidget().textChangeEventTimeout < 1) { + if (textField.textChangeEventTimeout < 1) { // Sanitize and allow lazy/timeout with timeout set to 0 to // work as eager - getWidget().textChangeEventTimeout = 1; + textField.textChangeEventTimeout = 1; } } - getWidget().sinkEvents(VTextField.TEXTCHANGE_EVENTS); - getWidget().attachCutEventListener(getWidget().getElement()); + textField.sinkEvents(VTextField.TEXTCHANGE_EVENTS); + textField.attachCutEventListener(textField.getElement()); } - getWidget().setColumns(getState().columns); + textField.setColumns(getState().columns); String text = getState().text; if (text == null) { @@ -88,12 +89,12 @@ public class TextFieldConnector extends AbstractFieldConnector * side value). <input> is updated only when it looses focus, so we * force updating if not focused. Lost focus issue appeared in (#15144) */ - if (Util.getFocusedElement() != getWidget().getElement() + if (Util.getFocusedElement() != textField.getElement() || !uidl.getBooleanAttribute( TextFieldConstants.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS) - || getWidget().valueBeforeEdit == null - || !text.equals(getWidget().valueBeforeEdit)) { - getWidget().updateFieldContent(text); + || textField.valueBeforeEdit == null + || !text.equals(textField.valueBeforeEdit)) { + textField.updateFieldContent(text); } if (uidl.hasAttribute("selpos")) { @@ -105,7 +106,7 @@ public class TextFieldConnector extends AbstractFieldConnector Scheduler.get().scheduleDeferred(new Command() { @Override public void execute() { - getWidget().setSelectionRange(pos, length); + textField.setSelectionRange(pos, length); } }); } diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/upload/UploadConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/upload/UploadConnector.java index eefbe60a1a..ab09bb69f2 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/upload/UploadConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/upload/UploadConnector.java @@ -63,32 +63,33 @@ public class UploadConnector extends AbstractLegacyComponentConnector if (!isRealUpdate(uidl)) { return; } + VUpload upload = getWidget(); if (uidl.hasAttribute("notStarted")) { - getWidget().t.schedule(400); + upload.t.schedule(400); return; } - getWidget().setImmediate(getState().immediate); - getWidget().client = client; - getWidget().paintableId = uidl.getId(); - getWidget().nextUploadId = uidl.getIntAttribute("nextid"); + upload.setImmediate(getState().immediate); + upload.client = client; + upload.paintableId = uidl.getId(); + upload.nextUploadId = uidl.getIntAttribute("nextid"); final String action = client .translateVaadinUri(uidl.getStringVariable("action")); - getWidget().element.setAction(action); + upload.element.setAction(action); if (uidl.hasAttribute("buttoncaption")) { - getWidget().submitButton + upload.submitButton .setText(uidl.getStringAttribute("buttoncaption")); - getWidget().submitButton.setVisible(true); + upload.submitButton.setVisible(true); } else { - getWidget().submitButton.setVisible(false); + upload.submitButton.setVisible(false); } - getWidget().fu.setName(getWidget().paintableId + "_file"); + upload.fu.setName(upload.paintableId + "_file"); if (!isEnabled() || isReadOnly()) { - getWidget().disableUpload(); + upload.disableUpload(); } else if (!uidl.getBooleanAttribute("state")) { // Enable the button only if an upload is not in progress - getWidget().enableUpload(); - getWidget().ensureTargetFrame(); + upload.enableUpload(); + upload.ensureTargetFrame(); } } |