Browse Source

#8448 Replaced id and connection setters with parameters to the init method and refactored RootConnector initialization to be compatible with this

tags/7.0.0.alpha2
Artur Signell 12 years ago
parent
commit
039069727f

+ 7
- 0
src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java View File

@@ -241,6 +241,13 @@ public class ApplicationConfiguration implements EntryPoint {
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;
}

+ 20
- 27
src/com/vaadin/terminal/gwt/client/ApplicationConnection.java View File

@@ -169,7 +169,6 @@ public class ApplicationConnection {

public ApplicationConnection() {
view = GWT.create(RootConnector.class);
view.setConnection(this);
}

public void init(WidgetSet widgetSet, ApplicationConfiguration cnf) {
@@ -1058,36 +1057,32 @@ public class ApplicationConnection {
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);
}
@@ -1708,10 +1703,8 @@ public class ApplicationConnection {
// 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;
}

+ 5
- 29
src/com/vaadin/terminal/gwt/client/Connector.java View File

@@ -41,44 +41,20 @@ public interface Connector {

/**
* 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
@@ -91,10 +67,10 @@ public interface Connector {

/**
*
* 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);

}

+ 0
- 1
src/com/vaadin/terminal/gwt/client/MeasuredSize.java View File

@@ -184,7 +184,6 @@ public class MeasuredSize {
setOuterHeight(requiredHeight + marginHeight);

int requiredWidth = Util.getRequiredWidth(element);
VConsole.log("Width of " + element.toString() + " is " + requiredWidth);
int marginWidth = sumWidths(margins);
setOuterWidth(requiredWidth + marginWidth);


+ 11
- 46
src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java View File

@@ -9,19 +9,20 @@ import com.google.gwt.user.client.ui.FocusWidget;
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
@@ -36,8 +37,6 @@ public abstract class AbstractComponentConnector implements ComponentConnector {
public static final String ATTRIBUTE_HIDEERRORS = "hideErrors";

private Widget widget;
private ApplicationConnection connection;
private String id;

/* State variables */
private boolean enabled = true;
@@ -55,12 +54,6 @@ public abstract class AbstractComponentConnector implements ComponentConnector {
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.
@@ -83,34 +76,6 @@ public abstract class AbstractComponentConnector implements ComponentConnector {
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.
*
@@ -156,7 +121,8 @@ public abstract class AbstractComponentConnector implements ComponentConnector {
return null;
}
if (paintableMap.isConnector(w)) {
return (ComponentContainerConnector) paintableMap.getConnector(w);
return (ComponentContainerConnector) paintableMap
.getConnector(w);
}
}
}
@@ -184,8 +150,8 @@ public abstract class AbstractComponentConnector implements ComponentConnector {
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()) {
@@ -203,8 +169,7 @@ public abstract class AbstractComponentConnector implements ComponentConnector {
* 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"));
}
@@ -471,6 +436,6 @@ public abstract class AbstractComponentConnector implements ComponentConnector {
}

public LayoutManager getLayoutManager() {
return LayoutManager.get(connection);
return LayoutManager.get(getConnection());
}
}

+ 64
- 0
src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java View File

@@ -0,0 +1,64 @@
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() {

}

}

+ 4
- 13
src/com/vaadin/terminal/gwt/client/ui/RootConnector.java View File

@@ -34,10 +34,7 @@ public class RootConnector extends AbstractComponentContainerConnector {
@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;

@@ -275,15 +272,9 @@ public class RootConnector extends AbstractComponentContainerConnector {
// 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());


Loading…
Cancel
Save