Browse Source

Move ComboBox communication to connector (#19929)

This change extracts the client to server communication
methods of VFilterSelect and moves them to the connector.

Change-Id: If9b10455d1d32e11bfd6077dcaccbc4841b300f0
tags/8.0.0.alpha1
Henri Sara 8 years ago
parent
commit
44010cfbfb

+ 15
- 25
client/src/main/java/com/vaadin/client/ui/VFilterSelect.java View File

@@ -67,9 +67,7 @@ import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.BrowserInfo;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ComputedStyle;
import com.vaadin.client.ConnectorMap;
import com.vaadin.client.DeferredWorker;
import com.vaadin.client.Focusable;
import com.vaadin.client.UIDL;
@@ -79,6 +77,7 @@ import com.vaadin.client.ui.aria.AriaHelper;
import com.vaadin.client.ui.aria.HandlesAriaCaption;
import com.vaadin.client.ui.aria.HandlesAriaInvalid;
import com.vaadin.client.ui.aria.HandlesAriaRequired;
import com.vaadin.client.ui.combobox.ComboBoxConnector;
import com.vaadin.client.ui.menubar.MenuBar;
import com.vaadin.client.ui.menubar.MenuItem;
import com.vaadin.shared.AbstractComponentState;
@@ -133,6 +132,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
@Override
public String getDisplayString() {
final StringBuffer sb = new StringBuffer();
ApplicationConnection client = connector.getConnection();
final Icon icon = client.getIcon(client
.translateVaadinUri(untranslatedIconUri));
if (icon != null) {
@@ -174,6 +174,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
* @return
*/
public String getIconUri() {
ApplicationConnection client = connector.getConnection();
return client.translateVaadinUri(untranslatedIconUri);
}

@@ -1143,10 +1144,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
}
// null is not visible on pages != 0, and not visible when
// filtering: handle separately
client.updateVariable(paintableId, "filter", "", false);
client.updateVariable(paintableId, "page", 0, false);
client.updateVariable(paintableId, "selected", new String[] {},
immediate);
connector.requestFirstPage();
afterUpdateClientVariables();

suggestionPopup.hide();
@@ -1195,8 +1193,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
* Store last sent new item string to avoid double sends
*/
lastNewItemString = enteredItemValue;
client.updateVariable(paintableId, "newitem",
enteredItemValue, immediate);
connector.sendNewItem(enteredItemValue);
afterUpdateClientVariables();
}
} else if (item != null
@@ -1454,7 +1451,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
private IconWidget selectedItemIcon;

/** For internal use only. May be removed or replaced in the future. */
public ApplicationConnection client;
public ComboBoxConnector connector;

/** For internal use only. May be removed or replaced in the future. */
public String paintableId;
@@ -1470,9 +1467,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
*/
public final List<FilterSelectSuggestion> currentSuggestions = new ArrayList<FilterSelectSuggestion>();

/** For internal use only. May be removed or replaced in the future. */
public boolean immediate;

/** For internal use only. May be removed or replaced in the future. */
public String selectedOptionKey;

@@ -1743,8 +1737,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
}

waitingForFilteringResponse = true;
client.updateVariable(paintableId, "filter", filter, false);
client.updateVariable(paintableId, "page", page, immediate);
connector.requestPage(filter, page);
afterUpdateClientVariables();

lastFilter = filter;
@@ -1865,8 +1858,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,

if (!(newKey.equals(selectedOptionKey) || ("".equals(newKey) && selectedOptionKey == null))) {
selectedOptionKey = newKey;
client.updateVariable(paintableId, "selected",
new String[] { selectedOptionKey }, immediate);
connector.sendSelection(new String[] { selectedOptionKey });
afterUpdateClientVariables();

// currentPage = -1; // forget the page
@@ -1878,8 +1870,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
// hard to interpret that new clause added here :-(
selectedOptionKey = newKey;
explicitSelectedCaption = null;
client.updateVariable(paintableId, "selected",
new String[] { selectedOptionKey }, immediate);
connector.sendSelection(new String[] { selectedOptionKey });
afterUpdateClientVariables();
}

@@ -1905,7 +1896,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
if (selectedItemIcon != null) {
panel.remove(selectedItemIcon);
}
selectedItemIcon = new IconWidget(client.getIcon(iconUri));
selectedItemIcon = new IconWidget(connector.getConnection()
.getIcon(iconUri));
// Older IE versions don't scale icon correctly if DOM
// contains height and width attributes.
selectedItemIcon.getElement().removeAttribute("height");
@@ -2225,6 +2217,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
// If a focus event is not going to be sent, send the options
// request immediately; otherwise queue in the same burst as the
// focus event. Fixes #8321.
ApplicationConnection client = connector.getConnection();
boolean immediate = focused
|| !client.hasEventListeners(this, EventId.FOCUS);
filterOptions(-1, "", immediate);
@@ -2321,13 +2314,12 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
}
addStyleDependentName("focus");

ApplicationConnection client = connector.getConnection();
if (client.hasEventListeners(this, EventId.FOCUS)) {
client.updateVariable(paintableId, EventId.FOCUS, "", true);
afterUpdateClientVariables();
}

ComponentConnector connector = ConnectorMap.get(client).getConnector(
this);
client.getVTooltip().showAssistive(
connector.getTooltipInfo(getElement()));
}
@@ -2391,6 +2383,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
}
removeStyleDependentName("focus");

ApplicationConnection client = connector.getConnection();
if (client.hasEventListeners(this, EventId.BLUR)) {
client.updateVariable(paintableId, EventId.BLUR, "", true);
afterUpdateClientVariables();
@@ -2420,10 +2413,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
* For internal use only. May be removed or replaced in the future.
*/
public void updateRootWidth() {
ComponentConnector paintable = ConnectorMap.get(client).getConnector(
this);

if (paintable.isUndefinedWidth()) {
if (connector.isUndefinedWidth()) {

/*
* When the select has a undefined with we need to check that we are

+ 80
- 2
client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java View File

@@ -49,6 +49,14 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
// update textbox text by a changed item caption.
private boolean oldSuggestionTextMatchTheOldSelection;

private boolean immediate;

@Override
protected void init() {
super.init();
getWidget().connector = this;
}

@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
@@ -58,7 +66,7 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
getWidget().readonly = isReadOnly();
getWidget().updateReadOnly();

getWidget().immediate = getState().immediate;
immediate = getState().immediate;

getWidget().setTextInputEnabled(getState().textInputAllowed);

@@ -80,7 +88,6 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// Save details
getWidget().client = client;
getWidget().paintableId = uidl.getId();

if (!isRealUpdate(uidl)) {
@@ -376,4 +383,75 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
getWidget().tb.setEnabled(widgetEnabled);
}

/*
* These methods exist to move communications out of VFilterSelect, and may
* be refactored/removed in the future
*/

/**
* Send a message about a newly created item to the server.
*
* This method is for internal use only and may be removed in future
* versions.
*
* @since
* @param itemValue
* user entered string value for the new item
*/
public void sendNewItem(String itemValue) {
getConnection().updateVariable(getConnectorId(), "newitem", itemValue,
immediate);
}

/**
* Send a message to the server to request the first page of items without
* filtering or selection.
*
* This method is for internal use only and may be removed in future
* versions.
*
* @since
*/
public void requestFirstPage() {
getConnection().updateVariable(getConnectorId(), "filter", "", false);
getConnection().updateVariable(getConnectorId(), "page", 0, false);
getConnection().updateVariable(getConnectorId(), "selected",
new String[] {}, immediate);
}

/**
* Send a message to the server to request a page of items with a given
* filter.
*
* This method is for internal use only and may be removed in future
* versions.
*
* @since
* @param filter
* the current filter string
* @param page
* the page number to get
*/
public void requestPage(String filter, int page) {
getConnection().updateVariable(getConnectorId(), "filter", filter,
false);
getConnection().updateVariable(getConnectorId(), "page", page,
immediate);
}

/**
* Send a message to the server updating the current selection.
*
* This method is for internal use only and may be removed in future
* versions.
*
* @since
* @param selection
* the current selection
*/
public void sendSelection(String[] selection) {
getConnection().updateVariable(getConnectorId(), "selected", selection,
immediate);
}

}

Loading…
Cancel
Save