diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-08-17 19:22:16 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-08-22 19:25:31 +0300 |
commit | a34ddd875812ca2c3d1006555a33b72a4e438da3 (patch) | |
tree | d971d1098c906b141a50e0d74d93ac8251b1f31e /client | |
parent | 1a7d126e358d92850a41060b06d53309f2ac58f0 (diff) | |
download | vaadin-framework-a34ddd875812ca2c3d1006555a33b72a4e438da3.tar.gz vaadin-framework-a34ddd875812ca2c3d1006555a33b72a4e438da3.zip |
Use ConnectorBundle for creating state and widget (#9371)
Diffstat (limited to 'client')
8 files changed, 20 insertions, 165 deletions
diff --git a/client/src/com/vaadin/Vaadin.gwt.xml b/client/src/com/vaadin/Vaadin.gwt.xml index 5a9909a29c..4bac60b472 100644 --- a/client/src/com/vaadin/Vaadin.gwt.xml +++ b/client/src/com/vaadin/Vaadin.gwt.xml @@ -61,18 +61,6 @@ <when-type-assignable class="com.vaadin.terminal.gwt.client.communication.GeneratedRpcMethodProvider" /> </generate-with> - - <generate-with - class="com.vaadin.terminal.gwt.widgetsetutils.ConnectorWidgetFactoryGenerator"> - <when-type-assignable - class="com.vaadin.terminal.gwt.client.ui.ConnectorWidgetFactory" /> - </generate-with> - - <generate-with - class="com.vaadin.terminal.gwt.widgetsetutils.ConnectorStateFactoryGenerator"> - <when-type-assignable - class="com.vaadin.terminal.gwt.client.ui.ConnectorStateFactory" /> - </generate-with> <generate-with class="com.vaadin.terminal.gwt.widgetsetutils.ConnectorBundleLoaderFactory"> <when-type-assignable class="com.vaadin.terminal.gwt.client.metadata.ConnectorBundleLoader" /> diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 9a14e5434e..8ba8f0afab 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -68,6 +68,7 @@ import com.vaadin.terminal.gwt.client.communication.RpcManager; import com.vaadin.terminal.gwt.client.communication.SerializerMap; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.extensions.AbstractExtensionConnector; +import com.vaadin.terminal.gwt.client.metadata.ConnectorBundleLoader; import com.vaadin.terminal.gwt.client.metadata.Type; import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; import com.vaadin.terminal.gwt.client.ui.VContextMenu; @@ -240,6 +241,10 @@ public class ApplicationConnection { initializeClientHooks(); + // Assuming Root data is eagerly loaded + ConnectorBundleLoader.get().loadBundle( + ConnectorBundleLoader.EAGER_BUNDLE_NAME, null); + rootConnector.init(cnf.getRootPanelId(), this); showLoadingIndicator(); } diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/ConnectorBundleLoader.java b/client/src/com/vaadin/terminal/gwt/client/metadata/ConnectorBundleLoader.java index 48a8430312..ab1462efc1 100644 --- a/client/src/com/vaadin/terminal/gwt/client/metadata/ConnectorBundleLoader.java +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/ConnectorBundleLoader.java @@ -67,7 +67,9 @@ public abstract class ConnectorBundleLoader { List<BundleLoadCallback> callbacks = asyncBlockLoaders.get(packageName) .setLoaded(); for (BundleLoadCallback callback : callbacks) { - callback.loaded(); + if (callback != null) { + callback.loaded(); + } } } diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java index 48842e29a0..4f14ee550b 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java @@ -37,6 +37,8 @@ import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; +import com.vaadin.terminal.gwt.client.metadata.Type; +import com.vaadin.terminal.gwt.client.metadata.TypeData; import com.vaadin.terminal.gwt.client.ui.datefield.PopupDateFieldConnector; import com.vaadin.terminal.gwt.client.ui.root.RootConnector; @@ -77,7 +79,10 @@ public abstract class AbstractComponentConnector extends AbstractConnector * @return */ protected Widget createWidget() { - return ConnectorWidgetFactory.createWidget(getClass()); + Type type = TypeData.getType(getClass()); + Type widgetType = type.getMethod("getWidget").getReturnType(); + Object instance = widgetType.createInstance(); + return (Widget) instance; } /** diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java index 435fff8a5b..9efa7bad0d 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java @@ -33,6 +33,8 @@ import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent.StateChangeHandler; +import com.vaadin.terminal.gwt.client.metadata.Type; +import com.vaadin.terminal.gwt.client.metadata.TypeData; /** * An abstract implementation of Connector. @@ -265,7 +267,10 @@ public abstract class AbstractConnector implements ServerConnector, * @return A new state object */ protected SharedState createState() { - return ConnectorStateFactory.createState(getClass()); + Type connectorType = TypeData.getType(getClass()); + Type stateType = connectorType.getMethod("getState").getReturnType(); + Object stateInstance = stateType.createInstance(); + return (SharedState) stateInstance; } @Override diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/ConnectorClassBasedFactory.java b/client/src/com/vaadin/terminal/gwt/client/ui/ConnectorClassBasedFactory.java deleted file mode 100644 index 698d8e6e61..0000000000 --- a/client/src/com/vaadin/terminal/gwt/client/ui/ConnectorClassBasedFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.terminal.gwt.client.ui; - -import java.util.HashMap; -import java.util.Map; - -import com.vaadin.shared.Connector; - -public abstract class ConnectorClassBasedFactory<T> { - public interface Creator<T> { - public T create(); - } - - private Map<Class<? extends Connector>, Creator<? extends T>> creators = new HashMap<Class<? extends Connector>, Creator<? extends T>>(); - - protected void addCreator(Class<? extends Connector> cls, - Creator<? extends T> creator) { - creators.put(cls, creator); - } - - /** - * Creates a widget using GWT.create for the given connector, based on its - * {@link AbstractComponentConnector#getWidget()} return type. - * - * @param connector - * @return - */ - public T create(Class<? extends Connector> connector) { - Creator<? extends T> foo = creators.get(connector); - if (foo == null) { - throw new RuntimeException(getClass().getName() - + " could not find a creator for connector of type " - + connector.getName()); - } - return foo.create(); - } - -} diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/ConnectorStateFactory.java b/client/src/com/vaadin/terminal/gwt/client/ui/ConnectorStateFactory.java deleted file mode 100644 index b04daa6910..0000000000 --- a/client/src/com/vaadin/terminal/gwt/client/ui/ConnectorStateFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.terminal.gwt.client.ui; - -import com.google.gwt.core.client.GWT; -import com.vaadin.shared.Connector; -import com.vaadin.shared.communication.SharedState; - -public abstract class ConnectorStateFactory extends - ConnectorClassBasedFactory<SharedState> { - private static ConnectorStateFactory impl = null; - - /** - * Creates a SharedState using GWT.create for the given connector, based on - * its {@link AbstractComponentConnector#getSharedState ()} return type. - * - * @param connector - * @return - */ - public static SharedState createState(Class<? extends Connector> connector) { - return getImpl().create(connector); - } - - private static ConnectorStateFactory getImpl() { - if (impl == null) { - impl = GWT.create(ConnectorStateFactory.class); - } - return impl; - } -} diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/ConnectorWidgetFactory.java b/client/src/com/vaadin/terminal/gwt/client/ui/ConnectorWidgetFactory.java deleted file mode 100644 index 073e36cabb..0000000000 --- a/client/src/com/vaadin/terminal/gwt/client/ui/ConnectorWidgetFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.terminal.gwt.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ui.textfield.TextFieldConnector; -import com.vaadin.terminal.gwt.client.ui.textfield.VTextField; - -public abstract class ConnectorWidgetFactory extends - ConnectorClassBasedFactory<Widget> { - private static ConnectorWidgetFactory impl = null; - - // TODO Move to generator - { - addCreator(TextFieldConnector.class, new Creator<Widget>() { - @Override - public Widget create() { - return GWT.create(VTextField.class); - } - }); - } - - /** - * Creates a widget using GWT.create for the given connector, based on its - * {@link AbstractComponentConnector#getWidget()} return type. - * - * @param connector - * @return - */ - public static Widget createWidget( - Class<? extends AbstractComponentConnector> connector) { - return getImpl().create(connector); - } - - private static ConnectorWidgetFactory getImpl() { - if (impl == null) { - impl = GWT.create(ConnectorWidgetFactory.class); - } - return impl; - } -} |