@Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { Resolution origRes = getWidget().getCurrentResolution(); String oldLocale = getWidget().getCurrentLocale(); super.updateFromUIDL(uidl, client); if (origRes != getWidget().getCurrentResolution() || oldLocale != getWidget().getCurrentLocale()) { // force recreating format string getWidget().formatStr = null; } if (uidl.hasAttribute("format")) { getWidget().formatStr = uidl.getStringAttribute("format"); } getWidget().lenient = !uidl.getBooleanAttribute("strict"); getWidget().buildDate(); // not a FocusWidget -> needs own tabindex handling getWidget().text.setTabIndex(getState().tabIndex); if (getWidget().isReadonly()) { getWidget().text.addStyleDependentName("readonly"); } else { getWidget().text.removeStyleDependentName("readonly"); } }
public static void showNotification(ApplicationConnection client, final UIDL notification) { boolean onlyPlainText = notification.hasAttribute(UIConstants.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED); String html = ""; if (notification.hasAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_ICON)) { final String parsedUri = client.translateVaadinUri( notification.getStringAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_ICON)); html += "<img src=\"" + Util.escapeAttribute(parsedUri) + "\" alt=\"\" />"; } if (notification.hasAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_CAPTION)) { String caption = notification.getStringAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_CAPTION); if (onlyPlainText) { caption = Util.escapeHTML(caption); caption = caption.replaceAll("\\n", "<br />"); } html += "<h1>" + caption + "</h1>"; } if (notification.hasAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_MESSAGE)) { String message = notification.getStringAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_MESSAGE); if (onlyPlainText) { message = Util.escapeHTML(message); message = message.replaceAll("\\n", "<br />"); } html += "<p>" + message + "</p>"; } final String style = notification.hasAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_STYLE) ? notification.getStringAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_STYLE) : null; final int pos = notification.getIntAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_POSITION); Position position = Position.values()[pos]; final int delay = notification.getIntAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_DELAY); createNotification(delay, client.getUIConnector().getWidget()).show(html, position, style); }
/* * (non-Javadoc) * * @see com.vaadin.client.Paintable#updateFromUIDL(com.vaadin.client.UIDL, * com.vaadin.client.ApplicationConnection) */ @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { // Save details getWidget().client = client; getWidget().paintableId = uidl.getId(); getWidget().readonly = isReadOnly(); getWidget().updateReadOnly(); if (!isRealUpdate(uidl)) { return; } // Inverse logic here to make the default case (text input enabled) // work without additional UIDL messages boolean noTextInput = uidl.hasAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT) && uidl.getBooleanAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT); getWidget().setTextInputEnabled(!noTextInput); // not a FocusWidget -> needs own tabindex handling getWidget().tb.setTabIndex(getState().tabIndex); if (uidl.hasAttribute("filteringmode")) { getWidget().filteringmode = FilteringMode.valueOf(uidl.getStringAttribute("filteringmode")); } getWidget().immediate = getState().immediate; getWidget().nullSelectionAllowed = uidl.hasAttribute("nullselect"); getWidget().nullSelectItem = uidl.hasAttribute("nullselectitem") && uidl.getBooleanAttribute("nullselectitem"); getWidget().currentPage = uidl.getIntVariable("page"); if (uidl.hasAttribute("pagelength")) { getWidget().pageLength = uidl.getIntAttribute("pagelength"); } if (uidl.hasAttribute(ComboBoxConstants.ATTR_INPUTPROMPT)) { // input prompt changed from server getWidget().inputPrompt = uidl.getStringAttribute(ComboBoxConstants.ATTR_INPUTPROMPT); } else { getWidget().inputPrompt = ""; } getWidget().suggestionPopup.updateStyleNames(uidl, getState()); getWidget().allowNewItem = uidl.hasAttribute("allownewitem"); getWidget().lastNewItemString = null; final UIDL options = uidl.getChildUIDL(0); if (uidl.hasAttribute("totalMatches")) { getWidget().totalMatches = uidl.getIntAttribute("totalMatches"); } else { getWidget().totalMatches = 0; } List<FilterSelectSuggestion> newSuggestions = new ArrayList<FilterSelectSuggestion>(); for (final Iterator<?> i = options.getChildIterator(); i.hasNext(); ) { final UIDL optionUidl = (UIDL) i.next(); final FilterSelectSuggestion suggestion = getWidget().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); oldSuggestionTextMatchTheOldSelection = false; if (suggestionsChanged) { oldSuggestionTextMatchTheOldSelection = isWidgetsCurrentSelectionTextInTextBox(); getWidget().currentSuggestions.clear(); if (!getWidget().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; /* * 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(); } for (FilterSelectSuggestion suggestion : newSuggestions) { getWidget().currentSuggestions.add(suggestion); } } // handle selection (null or a single value) if (uidl.hasVariable("selected")) { String[] selectedKeys = uidl.getStringArrayVariable("selected"); if (selectedKeys.length > 0) { performSelection(selectedKeys[0]); } else { resetSelection(); } } if (getWidget().waitingForFilteringResponse && getWidget().lastFilter.toLowerCase().equals(uidl.getStringVariable("filter"))) { getWidget() .suggestionPopup .showSuggestions( getWidget().currentSuggestions, getWidget().currentPage, getWidget().totalMatches); getWidget().waitingForFilteringResponse = false; if (!getWidget().popupOpenerClicked && getWidget().selectPopupItemWhenResponseIsReceived != VFilterSelect.Select.NONE) { // we're paging w/ arrows if (getWidget().selectPopupItemWhenResponseIsReceived == VFilterSelect.Select.LAST) { getWidget().suggestionPopup.menu.selectLastItem(); } else { getWidget().suggestionPopup.menu.selectFirstItem(); } // This is used for paging so we update the keyboard selection // variable as well. MenuItem activeMenuItem = getWidget().suggestionPopup.menu.getSelectedItem(); getWidget().suggestionPopup.menu.setKeyboardSelectedItem(activeMenuItem); // Update text field to contain the correct text getWidget().setTextboxText(activeMenuItem.getText()); getWidget() .tb .setSelectionRange( getWidget().lastFilter.length(), activeMenuItem.getText().length() - getWidget().lastFilter.length()); getWidget().selectPopupItemWhenResponseIsReceived = VFilterSelect.Select.NONE; // reset } if (getWidget().updateSelectionWhenReponseIsReceived) { getWidget().suggestionPopup.menu.doPostFilterSelectedItemAction(); } } // Calculate minimum textarea width getWidget().updateSuggestionPopupMinWidth(); getWidget().popupOpenerClicked = false; if (!getWidget().initDone) { getWidget().updateRootWidth(); } // Focus dependent style names are lost during the update, so we add // them here back again if (getWidget().focused) { getWidget().addStyleDependentName("focus"); } getWidget().initDone = true; }
@Override public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { ConnectorMap paintableMap = ConnectorMap.get(getConnection()); getWidget().rendering = true; getWidget().id = getConnectorId(); boolean firstPaint = getWidget().connection == null; getWidget().connection = client; getWidget().immediate = getState().immediate; getWidget().resizeLazy = uidl.hasAttribute(UIConstants.RESIZE_LAZY); String newTheme = uidl.getStringAttribute("theme"); if (getWidget().theme != null && !newTheme.equals(getWidget().theme)) { // Complete page refresh is needed due css can affect layout // calculations etc getWidget().reloadHostPage(); } else { getWidget().theme = newTheme; } // this also implicitly removes old styles String styles = ""; styles += getWidget().getStylePrimaryName() + " "; if (ComponentStateUtil.hasStyles(getState())) { for (String style : getState().styles) { styles += style + " "; } } if (!client.getConfiguration().isStandalone()) { styles += getWidget().getStylePrimaryName() + "-embedded"; } getWidget().setStyleName(styles.trim()); getWidget().makeScrollable(); clickEventHandler.handleEventHandlerRegistration(); // Process children int childIndex = 0; // Open URL:s boolean isClosed = false; // was this window closed? while (childIndex < uidl.getChildCount() && "open".equals(uidl.getChildUIDL(childIndex).getTag())) { final UIDL open = uidl.getChildUIDL(childIndex); final String url = client.translateVaadinUri(open.getStringAttribute("src")); final String target = open.getStringAttribute("name"); if (target == null) { // source will be opened to this browser window, but we may have // to finish rendering this window in case this is a download // (and window stays open). Scheduler.get() .scheduleDeferred( new Command() { @Override public void execute() { VUI.goTo(url); } }); } else if ("_self".equals(target)) { // This window is closing (for sure). Only other opens are // relevant in this change. See #3558, #2144 isClosed = true; VUI.goTo(url); } else { String options; boolean alwaysAsPopup = true; if (open.hasAttribute("popup")) { alwaysAsPopup = open.getBooleanAttribute("popup"); } if (alwaysAsPopup) { if (open.hasAttribute("border")) { if (open.getStringAttribute("border").equals("minimal")) { options = "menubar=yes,location=no,status=no"; } else { options = "menubar=no,location=no,status=no"; } } else { options = "resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes"; } if (open.hasAttribute("width")) { int w = open.getIntAttribute("width"); options += ",width=" + w; } if (open.hasAttribute("height")) { int h = open.getIntAttribute("height"); options += ",height=" + h; } Window.open(url, target, options); } else { open(url, target); } } childIndex++; } if (isClosed) { // don't render the content, something else will be opened to this // browser view getWidget().rendering = false; return; } // Handle other UIDL children UIDL childUidl; while ((childUidl = uidl.getChildUIDL(childIndex++)) != null) { String tag = childUidl.getTag().intern(); if (tag == "actions") { if (getWidget().actionHandler == null) { getWidget().actionHandler = new ShortcutActionHandler(getWidget().id, client); } getWidget().actionHandler.updateActionMap(childUidl); } else if (tag == "notifications") { for (final Iterator<?> it = childUidl.getChildIterator(); it.hasNext(); ) { final UIDL notification = (UIDL) it.next(); VNotification.showNotification(client, notification); } } } if (uidl.hasAttribute("focused")) { // set focused component when render phase is finished Scheduler.get() .scheduleDeferred( new Command() { @Override public void execute() { ComponentConnector paintable = (ComponentConnector) uidl.getPaintableAttribute("focused", getConnection()); final Widget toBeFocused = paintable.getWidget(); /* * Two types of Widgets can be focused, either implementing * GWT HasFocus of a thinner Vaadin specific Focusable * interface. */ if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; toBeFocusedWidget.setFocus(true); } else if (toBeFocused instanceof Focusable) { ((Focusable) toBeFocused).focus(); } else { VConsole.log("Could not focus component"); } } }); } // Add window listeners on first paint, to prevent premature // variablechanges if (firstPaint) { Window.addWindowClosingHandler(getWidget()); Window.addResizeHandler(getWidget()); } if (uidl.hasAttribute("scrollTo")) { final ComponentConnector connector = (ComponentConnector) uidl.getPaintableAttribute("scrollTo", getConnection()); scrollIntoView(connector); } if (uidl.hasAttribute(UIConstants.LOCATION_VARIABLE)) { String location = uidl.getStringAttribute(UIConstants.LOCATION_VARIABLE); int fragmentIndex = location.indexOf('#'); if (fragmentIndex >= 0) { getWidget().currentFragment = location.substring(fragmentIndex + 1); } if (!getWidget().currentFragment.equals(History.getToken())) { History.newItem(getWidget().currentFragment, true); } } if (firstPaint) { // Queue the initial window size to be sent with the following // request. getWidget().sendClientResized(); } getWidget().rendering = false; }
/* * (non-Javadoc) * * @see com.vaadin.client.ui.VTextualDate#updateFromUIDL(com.vaadin * .client.UIDL, com.vaadin.client.ApplicationConnection) */ @Override @SuppressWarnings("deprecation") public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { boolean lastReadOnlyState = getWidget().isReadonly(); boolean lastEnabledState = getWidget().isEnabled(); getWidget().parsable = uidl.getBooleanAttribute("parsable"); super.updateFromUIDL(uidl, client); getWidget().calendar.setDateTimeService(getWidget().getDateTimeService()); getWidget().calendar.setShowISOWeekNumbers(getWidget().isShowISOWeekNumbers()); if (getWidget().calendar.getResolution() != getWidget().getCurrentResolution()) { getWidget().calendar.setResolution(getWidget().getCurrentResolution()); if (getWidget().calendar.getDate() != null) { getWidget().calendar.setDate((Date) getWidget().getCurrentDate().clone()); // force re-render when changing resolution only getWidget().calendar.renderCalendar(); } } getWidget().calendarToggle.setEnabled(getWidget().isEnabled()); if (getWidget().getCurrentResolution().getCalendarField() <= Resolution.MONTH.getCalendarField()) { getWidget() .calendar .setFocusChangeListener( new FocusChangeListener() { @Override public void focusChanged(Date date) { getWidget().updateValue(date); getWidget().buildDate(); Date date2 = getWidget().calendar.getDate(); date2.setYear(date.getYear()); date2.setMonth(date.getMonth()); } }); } else { getWidget().calendar.setFocusChangeListener(null); } if (getWidget().getCurrentResolution().getCalendarField() > Resolution.DAY.getCalendarField()) { getWidget() .calendar .setTimeChangeListener( new TimeChangeListener() { @Override public void changed(int hour, int min, int sec, int msec) { Date d = getWidget().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().clone(); } d.setHours(hour); d.setMinutes(min); d.setSeconds(sec); DateTimeService.setMilliseconds(d, msec); // Always update time changes to the server getWidget().updateValue(d); // Update text field getWidget().buildDate(); } }); } if (getWidget().isReadonly()) { getWidget().calendarToggle.addStyleName(VPopupCalendar.CLASSNAME + "-button-readonly"); } else { getWidget().calendarToggle.removeStyleName(VPopupCalendar.CLASSNAME + "-button-readonly"); } getWidget().calendarToggle.setEnabled(true); }