return appUri;
}
+ public String getThemeName() {
+ String uri = getThemeUri();
+ String themeName = uri.substring(uri.lastIndexOf('/'));
+ themeName = themeName.replaceAll("[^a-zA-Z0-9]", "");
+ return themeName;
+ }
+
public String getThemeUri() {
return themeUri;
}
public ApplicationConnection() {
view = GWT.create(RootConnector.class);
- view.setConnection(this);
}
public void init(WidgetSet widgetSet, ApplicationConfiguration cnf) {
try {
final UIDL change = changes.get(i).cast();
final UIDL uidl = change.getChildUIDL(0);
- String paintableId = uidl.getId();
- // TODO optimize
+ String connectorId = uidl.getId();
+
+ if (!connectorMap.hasConnector(connectorId)
+ && uidl.getTag().equals(
+ configuration.getEncodedWindowTag())) {
+ // First RootConnector update. Up until this
+ // point the connectorId for RootConnector has
+ // not been known
+ connectorMap.registerConnector(connectorId, view);
+ view.doInit(connectorId, ApplicationConnection.this);
+ }
+
final ComponentConnector paintable = (ComponentConnector) connectorMap
- .getConnector(paintableId);
+ .getConnector(connectorId);
if (paintable != null) {
paintable.updateFromUIDL(uidl,
ApplicationConnection.this);
updatedComponentConnectors.add(paintable);
} else {
- if (!uidl.getTag().equals(
- configuration.getEncodedWindowTag())) {
- VConsole.error("Received update for "
- + uidl.getTag()
- + ", but there is no such paintable ("
- + paintableId + ") rendered.");
- } else {
- String pid = uidl.getId();
- if (!connectorMap.hasConnector(pid)) {
- connectorMap.registerConnector(pid, view);
- }
- // VView does not call updateComponent so we
- // register any event listeners here
- connectorMap.registerEventListenersFromUIDL(
- pid, uidl);
-
- // Finally allow VView to update itself
- view.updateFromUIDL(uidl,
- ApplicationConnection.this);
- }
+ VConsole.error("Received update for "
+ + uidl.getTag()
+ + ", but there is no such paintable ("
+ + connectorId + ") rendered.");
+
}
+
} catch (final Throwable e) {
VConsole.error(e);
}
// Create and register a new connector with the given type
ComponentConnector p = widgetSet.createWidget(connectorType,
configuration);
- p.setConnection(this);
- p.setId(connectorId);
- p.init();
connectorMap.registerConnector(connectorId, p);
+ p.doInit(connectorId, this);
return p;
}
/**
* Returns the id for this connector. This must always be what has been set
- * using {@link #setId(String)}.
+ * in {@link #init(String, ApplicationConnection)} and must never change.
*
* @return The id for the connector.
*/
public String getId();
- /**
- * Sets the id for the connector. This method is called once by the
- * framework when the connector is initialized and should never be called
- * otherwise.
- * <p>
- * The connector id is used to map the server and the client side together.
- * It is unique in this Root and assigned by the framework.
- * </p>
- *
- * @param id
- * The id of the connector.
- */
- public void setId(String id);
-
/**
* Gets ApplicationConnection instance that created this connector.
*
* @return The ApplicationConnection as set by
- * {@link #setConnection(ApplicationConnection)}
+ * {@link #init(String, ApplicationConnection)}
*/
public ApplicationConnection getConnection();
- /**
- * Sets the reference to ApplicationConnection. This method is called by the
- * framework when the connector is created and should never be called
- * otherwise.
- *
- * @param connection
- * The ApplicationConnection that created this connector
- */
- public void setConnection(ApplicationConnection connection);
-
/**
* Tests whether the component is enabled or not. A user can not interact
* with disabled components. Disabled components are rendered in a style
/**
*
- * Called once when the connection and id has been set.
+ * Called once by the framework to initialize the connector.
*
- * Note that the shared state is not yet available during init().
+ * Note that the shared state is not yet available at this point.
*/
- public void init();
+ public void doInit(String connectorId, ApplicationConnection connection);
}
setOuterHeight(requiredHeight + marginHeight);
int requiredWidth = Util.getRequiredWidth(element);
- VConsole.log("Width of " + element.toString() + " is " + requiredWidth);
int marginWidth = sumWidths(margins);
setOuterWidth(requiredWidth + marginWidth);
import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ComponentConnector;
+import com.vaadin.terminal.gwt.client.ComponentContainerConnector;
import com.vaadin.terminal.gwt.client.ComponentState;
+import com.vaadin.terminal.gwt.client.ConnectorMap;
import com.vaadin.terminal.gwt.client.LayoutManager;
import com.vaadin.terminal.gwt.client.TooltipInfo;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VConsole;
-import com.vaadin.terminal.gwt.client.ConnectorMap;
-import com.vaadin.terminal.gwt.client.ComponentConnector;
-import com.vaadin.terminal.gwt.client.ComponentContainerConnector;
import com.vaadin.terminal.gwt.client.communication.ClientToServerRpc;
import com.vaadin.terminal.gwt.client.communication.ClientToServerRpc.InitializableClientToServerRpc;
import com.vaadin.terminal.gwt.client.communication.SharedState;
-public abstract class AbstractComponentConnector implements ComponentConnector {
+public abstract class AbstractComponentConnector extends AbstractConnector
+ implements ComponentConnector {
// Generic UIDL parameter names, to be moved to shared state.
// Attributes are here mainly if they apply to all paintable widgets or
public static final String ATTRIBUTE_HIDEERRORS = "hideErrors";
private Widget widget;
- private ApplicationConnection connection;
- private String id;
/* State variables */
private boolean enabled = true;
public AbstractComponentConnector() {
}
- /**
- * Called after the application connection reference has been set up
- */
- public void init() {
- }
-
/**
* Creates and returns the widget for this VPaintableWidget. This method
* should only be called once when initializing the paintable.
return widget;
}
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.terminal.gwt.client.VPaintable#getConnection()
- */
- public final ApplicationConnection getConnection() {
- return connection;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.vaadin.terminal.gwt.client.VPaintable#setConnection(com.vaadin.terminal
- * .gwt.client.ApplicationConnection)
- */
- public final void setConnection(ApplicationConnection connection) {
- this.connection = connection;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
/**
* Returns the shared state object for a paintable widget.
*
return null;
}
if (paintableMap.isConnector(w)) {
- return (ComponentContainerConnector) paintableMap.getConnector(w);
+ return (ComponentContainerConnector) paintableMap
+ .getConnector(w);
}
}
}
setVisible(!uidl.getBooleanAttribute("invisible"), uidl);
if (uidl.getId().startsWith("PID_S")) {
- DOM.setElementProperty(getWidget().getElement(), "id",
- uidl.getId().substring(5));
+ DOM.setElementProperty(getWidget().getElement(), "id", uidl.getId()
+ .substring(5));
}
if (!isVisible()) {
* Disabled state may affect (override) tabindex so the order must be
* first setting tabindex, then enabled state.
*/
- if (uidl.hasAttribute("tabindex")
- && getWidget() instanceof Focusable) {
+ if (uidl.hasAttribute("tabindex") && getWidget() instanceof Focusable) {
((Focusable) getWidget()).setTabIndex(uidl
.getIntAttribute("tabindex"));
}
}
public LayoutManager getLayoutManager() {
- return LayoutManager.get(connection);
+ return LayoutManager.get(getConnection());
}
}
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui;
+
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.Connector;
+
+public abstract class AbstractConnector implements Connector {
+
+ private ApplicationConnection connection;
+ private String id;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.terminal.gwt.client.VPaintable#getConnection()
+ */
+ public final ApplicationConnection getConnection() {
+ return connection;
+ }
+
+ private final void setConnection(ApplicationConnection connection) {
+ this.connection = connection;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.terminal.gwt.client.Connector#getId()
+ */
+ public String getId() {
+ return id;
+ }
+
+ private void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ *
+ * Called once by the framework to initialize the connector.
+ *
+ * Custom widgets should not override this method, override init instead;
+ *
+ * Note that the shared state is not yet available at this point.
+ */
+ public final void doInit(String connectorId,
+ ApplicationConnection connection) {
+ setConnection(connection);
+ setId(connectorId);
+
+ init();
+ }
+
+ /**
+ * Called when the connector has been initialized. Override this method to
+ * perform initialization of the connector.
+ */
+ // FIXME: It might make sense to make this abstract to force users to use
+ // init instead of constructor, where connection and id has not yet been
+ // set.
+ protected void init() {
+
+ }
+
+}
@Override
public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
getWidget().rendering = true;
- // As VView is not created in the same way as all other paintables we
- // have to set the id here
- setId(uidl.getId());
- getWidget().id = uidl.getId();
+ getWidget().id = getId();
boolean firstPaint = getWidget().connection == null;
getWidget().connection = client;
// Remove the v-app-loading or any splash screen added inside the div by
// the user
root.getElement().setInnerHTML("");
- // For backwards compatibility with static index pages only.
- // No longer added by AbstractApplicationServlet/Portlet
- root.removeStyleName("v-app-loading");
-
- String themeUri = applicationConnection.getConfiguration()
- .getThemeUri();
- String themeName = themeUri.substring(themeUri.lastIndexOf('/'));
- themeName = themeName.replaceAll("[^a-zA-Z0-9]", "");
- root.addStyleName("v-theme-" + themeName);
+
+ root.addStyleName("v-theme-"
+ + applicationConnection.getConfiguration().getThemeName());
root.add(getWidget());