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

return appUri; 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() { public String getThemeUri() {
return themeUri; return themeUri;
} }

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



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


public void init(WidgetSet widgetSet, ApplicationConfiguration cnf) { public void init(WidgetSet widgetSet, ApplicationConfiguration cnf) {
try { try {
final UIDL change = changes.get(i).cast(); final UIDL change = changes.get(i).cast();
final UIDL uidl = change.getChildUIDL(0); 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 final ComponentConnector paintable = (ComponentConnector) connectorMap
.getConnector(paintableId);
.getConnector(connectorId);
if (paintable != null) { if (paintable != null) {
paintable.updateFromUIDL(uidl, paintable.updateFromUIDL(uidl,
ApplicationConnection.this); ApplicationConnection.this);
updatedComponentConnectors.add(paintable); updatedComponentConnectors.add(paintable);
} else { } 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) { } catch (final Throwable e) {
VConsole.error(e); VConsole.error(e);
} }
// Create and register a new connector with the given type // Create and register a new connector with the given type
ComponentConnector p = widgetSet.createWidget(connectorType, ComponentConnector p = widgetSet.createWidget(connectorType,
configuration); configuration);
p.setConnection(this);
p.setId(connectorId);
p.init();
connectorMap.registerConnector(connectorId, p); connectorMap.registerConnector(connectorId, p);
p.doInit(connectorId, this);


return p; return p;
} }

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



/** /**
* Returns the id for this connector. This must always be what has been set * 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. * @return The id for the connector.
*/ */
public String getId(); 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. * Gets ApplicationConnection instance that created this connector.
* *
* @return The ApplicationConnection as set by * @return The ApplicationConnection as set by
* {@link #setConnection(ApplicationConnection)}
* {@link #init(String, ApplicationConnection)}
*/ */
public ApplicationConnection getConnection(); 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 * Tests whether the component is enabled or not. A user can not interact
* with disabled components. Disabled components are rendered in a style * 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);


} }

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

setOuterHeight(requiredHeight + marginHeight); setOuterHeight(requiredHeight + marginHeight);


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



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

import com.google.gwt.user.client.ui.Focusable; import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection; 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.ComponentState;
import com.vaadin.terminal.gwt.client.ConnectorMap;
import com.vaadin.terminal.gwt.client.LayoutManager; import com.vaadin.terminal.gwt.client.LayoutManager;
import com.vaadin.terminal.gwt.client.TooltipInfo; import com.vaadin.terminal.gwt.client.TooltipInfo;
import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VConsole; 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;
import com.vaadin.terminal.gwt.client.communication.ClientToServerRpc.InitializableClientToServerRpc; import com.vaadin.terminal.gwt.client.communication.ClientToServerRpc.InitializableClientToServerRpc;
import com.vaadin.terminal.gwt.client.communication.SharedState; 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. // Generic UIDL parameter names, to be moved to shared state.
// Attributes are here mainly if they apply to all paintable widgets or // Attributes are here mainly if they apply to all paintable widgets or
public static final String ATTRIBUTE_HIDEERRORS = "hideErrors"; public static final String ATTRIBUTE_HIDEERRORS = "hideErrors";


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


/* State variables */ /* State variables */
private boolean enabled = true; private boolean enabled = true;
public AbstractComponentConnector() { 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 * Creates and returns the widget for this VPaintableWidget. This method
* should only be called once when initializing the paintable. * should only be called once when initializing the paintable.
return widget; 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. * Returns the shared state object for a paintable widget.
* *
return null; return null;
} }
if (paintableMap.isConnector(w)) { if (paintableMap.isConnector(w)) {
return (ComponentContainerConnector) paintableMap.getConnector(w);
return (ComponentContainerConnector) paintableMap
.getConnector(w);
} }
} }
} }
setVisible(!uidl.getBooleanAttribute("invisible"), uidl); setVisible(!uidl.getBooleanAttribute("invisible"), uidl);


if (uidl.getId().startsWith("PID_S")) { 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()) { if (!isVisible()) {
* Disabled state may affect (override) tabindex so the order must be * Disabled state may affect (override) tabindex so the order must be
* first setting tabindex, then enabled state. * first setting tabindex, then enabled state.
*/ */
if (uidl.hasAttribute("tabindex")
&& getWidget() instanceof Focusable) {
if (uidl.hasAttribute("tabindex") && getWidget() instanceof Focusable) {
((Focusable) getWidget()).setTabIndex(uidl ((Focusable) getWidget()).setTabIndex(uidl
.getIntAttribute("tabindex")); .getIntAttribute("tabindex"));
} }
} }


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

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

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

@Override @Override
public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
getWidget().rendering = true; 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; boolean firstPaint = getWidget().connection == null;
getWidget().connection = client; getWidget().connection = client;


// Remove the v-app-loading or any splash screen added inside the div by // Remove the v-app-loading or any splash screen added inside the div by
// the user // the user
root.getElement().setInnerHTML(""); 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()); root.add(getWidget());



Loading…
Cancel
Save