r1025 - in trunk: . src/main/java/org/ourproject/kune/app/client src/main/java/org/ourproject/kune/platf/client/services src/main/java/org/ourproject/kune/workspace/client src/main/java/org/ourproject/kune/workspace/client/hello
Author: vjrj Date: 2009-01-04 00:30:40 +0100 (Sun, 04 Jan 2009) New Revision: 1025 Added: trunk/src/main/java/org/ourproject/kune/workspace/client/hello/ trunk/src/main/java/org/ourproject/kune/workspace/client/hello/HelloWorldModule.java Modified: trunk/TODO trunk/src/main/java/org/ourproject/kune/app/client/KuneEntryPoint.java trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneRegistryModule.java Log: Incomplete - task 186: HelloWorldModule http://ourproject.org/tracker/?group_id=407&func=detail&atid=139&aid=186 Modified: trunk/TODO =================================================================== --- trunk/TODO 2009-01-03 18:45:49 UTC (rev 1024) +++ trunk/TODO 2009-01-03 23:30:40 UTC (rev 1025) @@ -62,6 +62,7 @@ * MIND-TERM ** vjrj <v> Login: Follow incubation recomendations. See: http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/e8e14... +** TODO <d> Inform to translators when original content changes ** TODO <v> extjs i18n http://extjs.com/deploy/ext/examples/locale/dutch-form.js http://groups.google.com/group/gwt-ext/browse_thread/thread/ebec316effea2b80... Modified: trunk/src/main/java/org/ourproject/kune/app/client/KuneEntryPoint.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/app/client/KuneEntryPoint.java 2009-01-03 18:45:49 UTC (rev 1024) +++ trunk/src/main/java/org/ourproject/kune/app/client/KuneEntryPoint.java 2009-01-03 23:30:40 UTC (rev 1025) @@ -29,6 +29,7 @@ import org.ourproject.kune.platf.client.services.KuneRegistryModule; import org.ourproject.kune.platf.client.services.KuneWorkspaceModule; import org.ourproject.kune.wiki.client.WikiClientModule; +import org.ourproject.kune.workspace.client.hello.HelloWorldModule; import com.allen_sauer.gwt.log.client.Log; import com.calclab.emiteuimodule.client.EmiteUIModule; @@ -66,5 +67,8 @@ Suco.install(new KuneCoreModule(), new KuneRegistryModule(), new KunePlatformModule(), new KuneWorkspaceModule(), new EmiteUIModule(), new DocumentClientModule(), new BlogClientModule(), new WikiClientModule(), new GalleryClientModule(), new ChatClientModule(), new KuneModule()); + + // We install our HelloWorldModule + Suco.install(new HelloWorldModule()); } } Modified: trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java 2009-01-03 18:45:49 UTC (rev 1024) +++ trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java 2009-01-03 23:30:40 UTC (rev 1025) @@ -19,11 +19,8 @@ */package org.ourproject.kune.platf.client.services; import org.ourproject.kune.platf.client.actions.ActionManager; -import org.ourproject.kune.platf.client.actions.ContentActionRegistry; import org.ourproject.kune.platf.client.actions.ContentIconsRegistry; import org.ourproject.kune.platf.client.actions.ContextActionRegistry; -import org.ourproject.kune.platf.client.actions.GroupActionRegistry; -import org.ourproject.kune.platf.client.actions.UserActionRegistry; import org.ourproject.kune.platf.client.actions.toolbar.ActionBuddiesSummaryToolbar; import org.ourproject.kune.platf.client.actions.toolbar.ActionBuddiesSummaryToolbarPresenter; import org.ourproject.kune.platf.client.actions.toolbar.ActionCntCtxToolbarPanel; @@ -91,6 +88,7 @@ import org.ourproject.kune.workspace.client.editor.insert.linklocal.TextEditorInsertLinkLocal; import org.ourproject.kune.workspace.client.editor.insert.linklocal.TextEditorInsertLinkLocalPanel; import org.ourproject.kune.workspace.client.editor.insert.linklocal.TextEditorInsertLinkLocalPresenter; +import org.ourproject.kune.workspace.client.hello.HelloWorldModule.HelloWorld; import org.ourproject.kune.workspace.client.i18n.I18nTranslator; import org.ourproject.kune.workspace.client.i18n.I18nTranslatorPanel; import org.ourproject.kune.workspace.client.i18n.I18nTranslatorPresenter; @@ -462,34 +460,6 @@ } }); - register(Singleton.class, new Factory<ContextActionRegistry>(ContextActionRegistry.class) { - @Override - public ContextActionRegistry create() { - return new ContextActionRegistry(); - } - }); - - register(Singleton.class, new Factory<ContentActionRegistry>(ContentActionRegistry.class) { - @Override - public ContentActionRegistry create() { - return new ContentActionRegistry(); - } - }); - - register(Singleton.class, new Factory<GroupActionRegistry>(GroupActionRegistry.class) { - @Override - public GroupActionRegistry create() { - return new GroupActionRegistry(); - } - }); - - register(Singleton.class, new Factory<UserActionRegistry>(UserActionRegistry.class) { - @Override - public UserActionRegistry create() { - return new UserActionRegistry(); - } - }); - register(NoDecoration.class, new Factory<ActionContentToolbar>(ActionContentToolbar.class) { @Override public ActionContentToolbar create() { @@ -600,5 +570,6 @@ $(ApplicationComponentGroup.class).createAll(); $(ToolGroup.class).createAll(); $(Application.class).start(); + $(HelloWorld.class); } } Modified: trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneRegistryModule.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneRegistryModule.java 2009-01-03 18:45:49 UTC (rev 1024) +++ trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneRegistryModule.java 2009-01-03 23:30:40 UTC (rev 1025) @@ -1,6 +1,10 @@ package org.ourproject.kune.platf.client.services; +import org.ourproject.kune.platf.client.actions.ContentActionRegistry; import org.ourproject.kune.platf.client.actions.ContentIconsRegistry; +import org.ourproject.kune.platf.client.actions.ContextActionRegistry; +import org.ourproject.kune.platf.client.actions.GroupActionRegistry; +import org.ourproject.kune.platf.client.actions.UserActionRegistry; import org.ourproject.kune.platf.client.registry.AclEditableRegistry; import org.ourproject.kune.platf.client.registry.AuthorableRegistry; import org.ourproject.kune.platf.client.registry.CanBeHomepageRegistry; @@ -158,6 +162,32 @@ } }); + register(Singleton.class, new Factory<ContextActionRegistry>(ContextActionRegistry.class) { + @Override + public ContextActionRegistry create() { + return new ContextActionRegistry(); + } + }); + + register(Singleton.class, new Factory<ContentActionRegistry>(ContentActionRegistry.class) { + @Override + public ContentActionRegistry create() { + return new ContentActionRegistry(); + } + }); + + register(Singleton.class, new Factory<GroupActionRegistry>(GroupActionRegistry.class) { + @Override + public GroupActionRegistry create() { + return new GroupActionRegistry(); + } + }); + + register(Singleton.class, new Factory<UserActionRegistry>(UserActionRegistry.class) { + @Override + public UserActionRegistry create() { + return new UserActionRegistry(); + } + }); } - } Added: trunk/src/main/java/org/ourproject/kune/workspace/client/hello/HelloWorldModule.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/workspace/client/hello/HelloWorldModule.java 2009-01-03 18:45:49 UTC (rev 1024) +++ trunk/src/main/java/org/ourproject/kune/workspace/client/hello/HelloWorldModule.java 2009-01-03 23:30:40 UTC (rev 1025) @@ -0,0 +1,191 @@ +package org.ourproject.kune.workspace.client.hello; + +import org.ourproject.kune.platf.client.View; +import org.ourproject.kune.platf.client.actions.ActionToolbarMenuDescriptor; +import org.ourproject.kune.platf.client.actions.ActionToolbarPosition; +import org.ourproject.kune.platf.client.actions.UserActionRegistry; +import org.ourproject.kune.platf.client.dto.AccessRolDTO; +import org.ourproject.kune.platf.client.dto.UserSimpleDTO; +import org.ourproject.kune.platf.client.services.I18nTranslationService; +import org.ourproject.kune.platf.client.services.I18nTranslationServiceMocked; +import org.ourproject.kune.workspace.client.site.Site; +import org.ourproject.kune.workspace.client.skel.WorkspaceSkeleton; + +import com.allen_sauer.gwt.log.client.Log; +import com.calclab.suco.client.ioc.Provider; +import com.calclab.suco.client.ioc.decorator.Singleton; +import com.calclab.suco.client.ioc.module.AbstractModule; +import com.calclab.suco.client.ioc.module.Factory; +import com.calclab.suco.client.listener.Listener; +import com.google.gwt.user.client.ui.Label; + +/** + * This module is installed via Suco.install(new HelloWorldModule()). In kune we + * do this normally in KuneEntryPoint.onModuleLoadCont() + */ +public class HelloWorldModule extends AbstractModule { + + /** + * + * In this Module we include the HelloWorld/View/Panel/Presenter classes + * only for commodity reasons. They reflect our use of the MVN pattern. + * + * Normally we generate a snippet for this pattern using: + * + * <pre> + * script / generateBasicUIElements.sh + * </pre> + * + * HelloWorld is the external interface of this four classes. We use it if + * other classes have to interact with HelloWorld. + * + */ + public interface HelloWorld { + } + + /** + * In the Panel classes we do all the UI stuff (with none business logic) + * + */ + public class HelloWorldPanel implements HelloWorldView { + private final I18nTranslationService i18n; + + public HelloWorldPanel(final HelloWorldPresenter presenter, final WorkspaceSkeleton ws, + final I18nTranslationService i18n) { + this.i18n = i18n; + /** We can directly insert something in the workspace skeleton **/ + ws.getEntityWorkspace().getSubTitle().add(new Label(i18n.t("Hello world!"))); + } + + public void showMessage() { + /** i18n use with parameters **/ + Site.info(i18n.t("Hello [%s]!", "world")); + } + } + + public class HelloWorldPresenter implements HelloWorld { + + private HelloWorldView view; + private final Provider<UserActionRegistry> actionRegistry; + private final I18nTranslationService i18n; + + public HelloWorldPresenter(I18nTranslationService i18n, Provider<UserActionRegistry> actionRegistry) { + this.i18n = i18n; + this.actionRegistry = actionRegistry; + createActions(); + } + + public View getView() { + return view; + } + + public void init(HelloWorldView view) { + this.view = view; + } + + /** + * We add an menu action to users menus (like the buddies in Buddies + * Summary) + **/ + private void createActions() { + ActionToolbarMenuDescriptor<UserSimpleDTO> helloWorldBuddiesAction = new ActionToolbarMenuDescriptor<UserSimpleDTO>( + AccessRolDTO.Viewer, ActionToolbarPosition.bottombar, new Listener<UserSimpleDTO>() { + public void onEvent(UserSimpleDTO parameter) { + // We clicked: + view.showMessage(); + } + }); + // AccessRolDTO.Viewer: any user can see this option and without be + // authenticated: + helloWorldBuddiesAction.setMustBeAuthenticated(false); + // We add a submenu in Options menu: + helloWorldBuddiesAction.setParentMenuTitle(i18n.t("Options")); + helloWorldBuddiesAction.setParentSubMenuTitle(i18n.t("Hello world submenu")); + helloWorldBuddiesAction.setTextDescription(i18n.t("Hello world menu item")); + helloWorldBuddiesAction.setIconUrl("images/info.gif"); + + // Lazy creation of objects: + // + // Using Provider<Class> we do lazy instantiation. When we call + // actionRegistry.get() it creates the instance if is not created + // yet. + actionRegistry.get().addAction(helloWorldBuddiesAction); + } + } + + /** + * We use this interface between the Presenter and the Panel. In tests it + * cat be easy mocked. + */ + public interface HelloWorldView extends View { + void showMessage(); + } + + /** + * This is the real part of the module (when we do how and when to create + * the above classes, how many instances (singleton, one per use), and so + * on). + * + * The above clases are included here only for commodity purposes + */ + @Override + protected void onInstall() { + /** + * + * Now we register how to create instances of HelloWorld, and later we + * can use then from other objects. + * + * If we want to use HelloWorld from other modules we can use: + * $(HelloWorld.class) to get a instance or $$(HelloWorld.class) to get + * a provider of the instance. This is useful when we want to do lazy + * creation of objects: http://en.wikipedia.org/wiki/Lazy_initialization + * + **/ + register(Singleton.class, new Factory<HelloWorld>(HelloWorld.class) { + /** + * Singleton.class decorator: creates only one instance of + * HelloWorld.class and when we use it the provider returns always + * the same instance. + * + * NoDecorator.class: Use it if we need to create a new instance of + * HelloWorld.class in every use. + */ + @Override + public HelloWorld create() { + final HelloWorldPresenter presenter = new HelloWorldPresenter($(I18nTranslationServiceMocked.class), + $$(UserActionRegistry.class)); + final HelloWorldPanel panel = new HelloWorldPanel(presenter, $(WorkspaceSkeleton.class), + $(I18nTranslationServiceMocked.class)); + presenter.init(panel); + return presenter; + // now Suco knows how to create HelloWorld instance when we use + // $(HelloWorld.class) or $$(HelloWorld.class in a module. + } + + /** + * Optionally: we can do something after the instance is created + **/ + @Override + public void onAfterCreated(HelloWorld instance) { + Log.info("HelloWorld singleton instance created"); + } + }); + + /** + * we use a mock for i18n in this sample because we don't really want to + * translate this module messages. Normally we use: + * I18nTranslationService.class instead of the mock + **/ + register(Singleton.class, new Factory<I18nTranslationServiceMocked>(I18nTranslationServiceMocked.class) { + @Override + public I18nTranslationServiceMocked create() { + return new I18nTranslationServiceMocked(); + } + }); + + // And because nobody use this module, we get the class (to force the + // creation of the + // Helloworld instance): + // $(HelloWorld.class); + } +} \ No newline at end of file
participants (1)
-
vjrj