summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/terminal/AbstractClientConnector.java
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/com/vaadin/terminal/AbstractClientConnector.java')
-rw-r--r--server/src/com/vaadin/terminal/AbstractClientConnector.java110
1 files changed, 77 insertions, 33 deletions
diff --git a/server/src/com/vaadin/terminal/AbstractClientConnector.java b/server/src/com/vaadin/terminal/AbstractClientConnector.java
index bc1cd2af1a..157bd17e41 100644
--- a/server/src/com/vaadin/terminal/AbstractClientConnector.java
+++ b/server/src/com/vaadin/terminal/AbstractClientConnector.java
@@ -31,16 +31,19 @@ import java.util.NoSuchElementException;
import java.util.logging.Logger;
import com.vaadin.Application;
+import com.vaadin.external.json.JSONException;
+import com.vaadin.external.json.JSONObject;
import com.vaadin.shared.communication.ClientRpc;
import com.vaadin.shared.communication.ServerRpc;
import com.vaadin.shared.communication.SharedState;
+import com.vaadin.terminal.gwt.server.AbstractCommunicationManager;
import com.vaadin.terminal.gwt.server.ClientConnector;
import com.vaadin.terminal.gwt.server.ClientMethodInvocation;
import com.vaadin.terminal.gwt.server.RpcManager;
import com.vaadin.terminal.gwt.server.RpcTarget;
import com.vaadin.terminal.gwt.server.ServerRpcManager;
import com.vaadin.ui.HasComponents;
-import com.vaadin.ui.Root;
+import com.vaadin.ui.UI;
/**
* An abstract base class for ClientConnector implementations. This class
@@ -68,6 +71,8 @@ public abstract class AbstractClientConnector implements ClientConnector {
*/
private SharedState sharedState;
+ private Class<? extends SharedState> stateType;
+
/**
* Pending RPC method invocations to be sent.
*/
@@ -80,11 +85,18 @@ public abstract class AbstractClientConnector implements ClientConnector {
private ClientConnector parent;
/* Documentation copied from interface */
+ @Deprecated
@Override
public void requestRepaint() {
- Root root = getRoot();
- if (root != null) {
- root.getConnectorTracker().markDirty(this);
+ markAsDirty();
+ }
+
+ /* Documentation copied from interface */
+ @Override
+ public void markAsDirty() {
+ UI uI = getUI();
+ if (uI != null) {
+ uI.getConnectorTracker().markDirty(this);
}
}
@@ -137,14 +149,24 @@ public abstract class AbstractClientConnector implements ClientConnector {
registerRpc(implementation, type);
}
- @Override
- public SharedState getState() {
+ protected SharedState getState() {
if (null == sharedState) {
sharedState = createState();
}
+
+ UI uI = getUI();
+ if (uI != null && !uI.getConnectorTracker().isDirty(this)) {
+ requestRepaint();
+ }
+
return sharedState;
}
+ @Override
+ public JSONObject encodeState() throws JSONException {
+ return AbstractCommunicationManager.encodeState(this, getState());
+ }
+
/**
* Creates the shared state bean to be used in server to client
* communication.
@@ -172,17 +194,33 @@ public abstract class AbstractClientConnector implements ClientConnector {
}
}
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.terminal.gwt.server.ClientConnector#getStateType()
- */
@Override
public Class<? extends SharedState> getStateType() {
+ // Lazy load because finding type can be expensive because of the
+ // exceptions flying around
+ if (stateType == null) {
+ stateType = findStateType();
+ }
+
+ return stateType;
+ }
+
+ private Class<? extends SharedState> findStateType() {
try {
- Method m = getClass().getMethod("getState", (Class[]) null);
- Class<?> type = m.getReturnType();
- return type.asSubclass(SharedState.class);
+ Class<?> class1 = getClass();
+ while (class1 != null) {
+ try {
+ Method m = class1.getDeclaredMethod("getState",
+ (Class[]) null);
+ Class<?> type = m.getReturnType();
+ return type.asSubclass(SharedState.class);
+ } catch (NoSuchMethodException nsme) {
+ // Try in superclass instead
+ class1 = class1.getSuperclass();
+ }
+ }
+ throw new NoSuchMethodException(getClass().getCanonicalName()
+ + ".getState()");
} catch (Exception e) {
throw new RuntimeException("Error finding state type for "
+ getClass().getName(), e);
@@ -255,8 +293,6 @@ public abstract class AbstractClientConnector implements ClientConnector {
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
addMethodInvocationToQueue(rpcInterfaceName, method, args);
- // TODO no need to do full repaint if only RPC calls
- requestRepaint();
return null;
}
@@ -279,6 +315,8 @@ public abstract class AbstractClientConnector implements ClientConnector {
// add to queue
pendingInvocations.add(new ClientMethodInvocation(this, interfaceName,
method, parameters));
+ // TODO no need to do full repaint if only RPC calls
+ requestRepaint();
}
/**
@@ -325,28 +363,28 @@ public abstract class AbstractClientConnector implements ClientConnector {
* @return The connector's application, or <code>null</code> if not attached
*/
protected Application getApplication() {
- Root root = getRoot();
- if (root == null) {
+ UI uI = getUI();
+ if (uI == null) {
return null;
} else {
- return root.getApplication();
+ return uI.getApplication();
}
}
/**
- * Finds a Root ancestor of this connector. <code>null</code> is returned if
- * no Root ancestor is found (typically because the connector is not
+ * Finds a UI ancestor of this connector. <code>null</code> is returned if
+ * no UI ancestor is found (typically because the connector is not
* attached to a proper hierarchy).
*
- * @return the Root ancestor of this connector, or <code>null</code> if none
+ * @return the UI ancestor of this connector, or <code>null</code> if none
* is found.
*/
@Override
- public Root getRoot() {
+ public UI getUI() {
ClientConnector connector = this;
while (connector != null) {
- if (connector instanceof Root) {
- return (Root) connector;
+ if (connector instanceof UI) {
+ return (UI) connector;
}
connector = connector.getParent();
}
@@ -358,11 +396,17 @@ public abstract class AbstractClientConnector implements ClientConnector {
}
@Override
+ @Deprecated
public void requestRepaintAll() {
- requestRepaint();
+ markAsDirtyRecursive();
+ }
+
+ @Override
+ public void markAsDirtyRecursive() {
+ markAsDirty();
for (ClientConnector connector : getAllChildrenIterable(this)) {
- connector.requestRepaintAll();
+ connector.markAsDirtyRecursive();
}
}
@@ -438,14 +482,14 @@ public abstract class AbstractClientConnector implements ClientConnector {
extensions.add(extension);
extension.setParent(this);
- requestRepaint();
+ markAsDirty();
}
@Override
public void removeExtension(Extension extension) {
extension.setParent(null);
extensions.remove(extension);
- requestRepaint();
+ markAsDirty();
}
@Override
@@ -482,9 +526,9 @@ public abstract class AbstractClientConnector implements ClientConnector {
@Override
public void attach() {
- requestRepaint();
+ markAsDirty();
- getRoot().getConnectorTracker().registerConnector(this);
+ getUI().getConnectorTracker().registerConnector(this);
for (ClientConnector connector : getAllChildrenIterable(this)) {
connector.attach();
@@ -496,7 +540,7 @@ public abstract class AbstractClientConnector implements ClientConnector {
* {@inheritDoc}
*
* <p>
- * The {@link #getApplication()} and {@link #getRoot()} methods might return
+ * The {@link #getApplication()} and {@link #getUI()} methods might return
* <code>null</code> after this method is called.
* </p>
*/
@@ -506,7 +550,7 @@ public abstract class AbstractClientConnector implements ClientConnector {
connector.detach();
}
- getRoot().getConnectorTracker().unregisterConnector(this);
+ getUI().getConnectorTracker().unregisterConnector(this);
}
@Override