r1126 - in trunk/src: main/java/org/ourproject/kune/app/client main/java/org/ourproject/kune/blogs/client main/java/org/ourproject/kune/chat/client main/java/org/ourproject/kune/docs/client main/java/org/ourproject/kune/gallery/client main/java/org/ourproject/kune/platf/client/actions/ui main/java/org/ourproject/kune/platf/client/app main/java/org/ourproject/kune/platf/client/services main/java/org/ourproject/kune/platf/client/ui/rte main/java/org/ourproject/kune/platf/client/ui/rte/basic mai
Author: vjrj Date: 2009-06-12 00:14:06 +0200 (Fri, 12 Jun 2009) New Revision: 1126 Added: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditor.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanel.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenter.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorView.java trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditorPanel.java trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditorPresenter.java trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditorView.java Removed: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEActionSndToolbar.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEActionTopToolbar.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorNew.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanelNew.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenterNew.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorViewNew.java Modified: trunk/src/main/java/org/ourproject/kune/app/client/KuneEntryPoint.java trunk/src/main/java/org/ourproject/kune/blogs/client/BlogClientActions.java trunk/src/main/java/org/ourproject/kune/chat/client/ChatEngineDefault.java trunk/src/main/java/org/ourproject/kune/docs/client/DocumentClientActions.java trunk/src/main/java/org/ourproject/kune/gallery/client/GalleryClientActions.java trunk/src/main/java/org/ourproject/kune/platf/client/actions/ui/AbstractButtonGui.java trunk/src/main/java/org/ourproject/kune/platf/client/actions/ui/MenuDescriptor.java trunk/src/main/java/org/ourproject/kune/platf/client/app/Application.java trunk/src/main/java/org/ourproject/kune/platf/client/app/ApplicationDefault.java trunk/src/main/java/org/ourproject/kune/platf/client/services/PlatformModule.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/TestRTEDialog.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditor.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPanel.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenter.java trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorView.java trunk/src/main/java/org/ourproject/kune/wiki/client/WikiClientActions.java trunk/src/main/java/org/ourproject/kune/workspace/client/AbstractFoldableContentActions.java trunk/src/main/java/org/ourproject/kune/workspace/client/WorkspaceModule.java trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditor.java trunk/src/main/java/org/ourproject/kune/workspace/client/hello/HelloWorldModule.java trunk/src/test/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenterTest.java Log: Complete - task ContentEditor action extensible Incomplete - task Hello World updated and Application Boot improved Modified: trunk/src/main/java/org/ourproject/kune/app/client/KuneEntryPoint.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/app/client/KuneEntryPoint.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/app/client/KuneEntryPoint.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -28,7 +28,6 @@ import org.ourproject.kune.wiki.client.WikiClientModule; import org.ourproject.kune.workspace.client.RegistryModule; import org.ourproject.kune.workspace.client.WorkspaceModule; -import org.ourproject.kune.workspace.client.hello.HelloWorldModule; import com.allen_sauer.gwt.log.client.Log; import com.calclab.emiteuimodule.client.EmiteUIModule; @@ -56,8 +55,5 @@ Suco.install(new CoreModule(), new RegistryModule(), new PlatformModule(), new EmiteUIModule(), new DocumentClientModule(), new BlogClientModule(), new WikiClientModule(), new GalleryClientModule(), new ChatClientModule(), new WorkspaceModule()); - - // We install our HelloWorldModule - Suco.install(new HelloWorldModule()); } } Modified: trunk/src/main/java/org/ourproject/kune/blogs/client/BlogClientActions.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/blogs/client/BlogClientActions.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/blogs/client/BlogClientActions.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -70,8 +70,8 @@ final String[] containersNoRoot = { TYPE_BLOG }; final String[] contents = { TYPE_POST, TYPE_UPLOADEDFILE }; - String parentMenuTitle = i18n.t("Post"); - String parentMenuTitleCtx = i18n.t("Blog"); + final String parentMenuTitle = i18n.t("Post"); + final String parentMenuTitleCtx = i18n.t("Blog"); createNewContainerAction(TYPE_BLOG, "images/nav/blog_add.png", i18n.t("New blog"), parentMenuTitleCtx, i18n.t("New"), i18n.t("New blog"), Position.ctx, TYPE_ROOT); Modified: trunk/src/main/java/org/ourproject/kune/chat/client/ChatEngineDefault.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/chat/client/ChatEngineDefault.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/chat/client/ChatEngineDefault.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -52,6 +52,7 @@ import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DeferredCommand; import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.Window.ClosingEvent; import com.gwtext.client.core.EventObject; import com.gwtext.client.widgets.Button; import com.gwtext.client.widgets.ToolbarButton; @@ -110,8 +111,8 @@ login(user.getChatName(), user.getChatPassword()); } }); - application.onApplicationStop(new Listener0() { - public void onEvent() { + application.onClosing(new Listener<ClosingEvent>() { + public void onEvent(final ClosingEvent event) { stop(); } }); @@ -139,7 +140,7 @@ public boolean isBuddie(final XmppURI jid) { if (roster != null) { - for (RosterItem item : roster) { + for (final RosterItem item : roster) { if (item.getJID().equalsNoResource(jid)) { return true; } @@ -168,7 +169,7 @@ if (subject != null) { DeferredCommand.addCommand(new Command() { public void execute() { - RoomUI roomUI = (RoomUI) room.getData(ChatUI.class); + final RoomUI roomUI = (RoomUI) room.getData(ChatUI.class); if (roomUI != null) { roomUI.setSubject(subject); } Modified: trunk/src/main/java/org/ourproject/kune/docs/client/DocumentClientActions.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/docs/client/DocumentClientActions.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/docs/client/DocumentClientActions.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -70,8 +70,8 @@ final String[] containersNoRoot = { TYPE_FOLDER }; final String[] contents = { TYPE_DOCUMENT, TYPE_UPLOADEDFILE }; - String parentMenuTitle = i18n.t("File"); - String parentMenuTitleCtx = i18n.t("Folder"); + final String parentMenuTitle = i18n.t("File"); + final String parentMenuTitleCtx = i18n.t("Folder"); createNewContainerAction(TYPE_FOLDER, "images/nav/folder_add.png", i18n.t("New folder"), parentMenuTitleCtx, i18n.t("New"), i18n.t("New folder"), Position.ctx, TYPE_ROOT, TYPE_FOLDER); Modified: trunk/src/main/java/org/ourproject/kune/gallery/client/GalleryClientActions.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/gallery/client/GalleryClientActions.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/gallery/client/GalleryClientActions.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -69,8 +69,8 @@ final String[] containersNoRoot = { TYPE_ALBUM }; final String[] contents = { TYPE_UPLOADEDFILE }; - String parentMenuTitle = i18n.t("File"); - String parentMenuTitleCtx = i18n.t("Album"); + final String parentMenuTitle = i18n.t("File"); + final String parentMenuTitleCtx = i18n.t("Album"); createNewContainerAction(TYPE_ALBUM, "images/nav/gallery_add.png", i18n.t("New sub-album"), parentMenuTitleCtx, i18n.t("New"), i18n.t("New sub-album"), Position.ctx, TYPE_ALBUM); Modified: trunk/src/main/java/org/ourproject/kune/platf/client/actions/ui/AbstractButtonGui.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/actions/ui/AbstractButtonGui.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/actions/ui/AbstractButtonGui.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -67,7 +67,11 @@ @Override protected void setIcon(final ImageResource imageResource) { if (imageResource != null) { - button.setIconCls(ImgConstants.CSS_SUFFIX + imageResource.getName()); + if (action.getValue(Action.NAME) == null) { + button.setIconCls(ImgConstants.CSS_SUFFIX + imageResource.getName()); + } else { + button.setIcon(ImgConstants.PATH_PREFIX + imageResource.getName() + ".png"); + } } } Modified: trunk/src/main/java/org/ourproject/kune/platf/client/actions/ui/MenuDescriptor.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/actions/ui/MenuDescriptor.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/actions/ui/MenuDescriptor.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -27,6 +27,10 @@ this(new BaseAction(text, null, icon)); } + public MenuDescriptor(final String text, final String tooltip) { + this(new BaseAction(text, tooltip, null)); + } + public MenuDescriptor(final String text, final String tooltip, final ImageResource icon) { this(new BaseAction(text, tooltip, icon)); } Modified: trunk/src/main/java/org/ourproject/kune/platf/client/app/Application.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/app/Application.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/app/Application.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -19,13 +19,15 @@ */ package org.ourproject.kune.platf.client.app; +import com.calclab.suco.client.events.Listener; import com.calclab.suco.client.events.Listener0; +import com.google.gwt.user.client.Window.ClosingEvent; public interface Application { - void onApplicationStart(Listener0 listener); + void onClosing(Listener<ClosingEvent> listener); - void onApplicationStop(Listener0 listener); + void onStarting(Listener0 listener); void start(); Modified: trunk/src/main/java/org/ourproject/kune/platf/client/app/ApplicationDefault.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/app/ApplicationDefault.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/app/ApplicationDefault.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -27,7 +27,9 @@ import org.ourproject.kune.platf.client.utils.PrefetchUtilities; import com.allen_sauer.gwt.log.client.Log; +import com.calclab.suco.client.events.Event; import com.calclab.suco.client.events.Event0; +import com.calclab.suco.client.events.Listener; import com.calclab.suco.client.events.Listener0; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DeferredCommand; @@ -40,30 +42,30 @@ public class ApplicationDefault implements Application { private final Session session; - private final Event0 onAppStart; - private final Event0 onAppStop; + private final Event0 onAppStarting; + private final Event<ClosingEvent> onAppClosing; public ApplicationDefault(final Session session) { this.session = session; - this.onAppStart = new Event0("onApplicationStart"); - this.onAppStop = new Event0("onApplicationStop"); + this.onAppStarting = new Event0("onAppStarting"); + this.onAppClosing = new Event<ClosingEvent>("onAppClossing"); Window.addWindowClosingHandler(new ClosingHandler() { public void onWindowClosing(final ClosingEvent event) { - stop(); + stop(event); } }); } - public void onApplicationStart(final Listener0 listener) { - onAppStart.add(listener); + public void onClosing(final Listener<ClosingEvent> listener) { + onAppClosing.add(listener); } - public void onApplicationStop(final Listener0 listener) { - onAppStop.add(listener); + public void onStarting(final Listener0 listener) { + onAppStarting.add(listener); } public void start() { - onAppStart.fire(); + onAppStarting.fire(); PrefetchUtilities.preFetchImpImages(); getInitData(); final Timer prefetchTimer = new Timer() { @@ -98,7 +100,7 @@ }); } - private void stop() { - onAppStop.fire(); + private void stop(final ClosingEvent event) { + onAppClosing.fire(event); } } Modified: trunk/src/main/java/org/ourproject/kune/platf/client/services/PlatformModule.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/services/PlatformModule.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/services/PlatformModule.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -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.toolbar.ActionToolbarPanel; import org.ourproject.kune.platf.client.actions.ui.BasicGuiBinding; import org.ourproject.kune.platf.client.actions.ui.GuiBindingsRegister; -import org.ourproject.kune.platf.client.actions.ui.TestButton; import org.ourproject.kune.platf.client.app.Application; import org.ourproject.kune.platf.client.app.ApplicationComponentGroup; import org.ourproject.kune.platf.client.app.ApplicationDefault; @@ -57,11 +54,9 @@ import org.ourproject.kune.platf.client.ui.palette.SimplePalettePanel; import org.ourproject.kune.platf.client.ui.palette.SimplePalettePresenter; import org.ourproject.kune.platf.client.ui.rte.TestRTEDialog; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEActionSndToolbar; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEActionTopToolbar; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorNew; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorPanelNew; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorPresenterNew; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditor; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorPanel; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorPresenter; import org.ourproject.kune.platf.client.ui.rte.edithtml.EditHtmlDialog; import org.ourproject.kune.platf.client.ui.rte.edithtml.EditHtmlDialogPanel; import org.ourproject.kune.platf.client.ui.rte.edithtml.EditHtmlDialogPresenter; @@ -119,7 +114,6 @@ import org.ourproject.kune.platf.client.ui.rte.saving.RTESavingEditorPresenter; import org.ourproject.kune.platf.client.utils.DeferredCommandWrapper; import org.ourproject.kune.platf.client.utils.TimerWrapper; -import org.ourproject.kune.workspace.client.skel.WorkspaceSkeleton; import com.calclab.suco.client.events.Listener0; import com.calclab.suco.client.ioc.decorator.NoDecoration; @@ -289,22 +283,6 @@ } }); - register(NoDecoration.class, new Factory<RTEActionTopToolbar>(RTEActionTopToolbar.class) { - @Override - public RTEActionTopToolbar create() { - final ActionToolbarPanel<Object> panel = new ActionToolbarPanel<Object>(p(ActionManager.class)); - final RTEActionTopToolbar toolbar = new RTEActionTopToolbar(panel); - return toolbar; - } - }, new Factory<RTEActionSndToolbar>(RTEActionSndToolbar.class) { - @Override - public RTEActionSndToolbar create() { - final ActionToolbarPanel<Object> panel = new ActionToolbarPanel<Object>(p(ActionManager.class), true); - final RTEActionSndToolbar toolbar = new RTEActionSndToolbar(panel); - return toolbar; - } - }); - register(Singleton.class, new Factory<TimerWrapper>(TimerWrapper.class) { @Override public TimerWrapper create() { @@ -333,14 +311,32 @@ } }); - register(NoDecoration.class,new Factory<RTEditorNew>(RTEditorNew.class) { + register(Singleton.class, new Factory<ImgResources>(ImgResources.class) { @Override - public RTEditorNew create() { - final RTEditorPresenterNew presenter = new RTEditorPresenterNew(i(I18nTranslationService.class), + public ImgResources create() { + final ImgResources instance = GWT.create(ImgResources.class); + StyleInjector.injectStylesheet(instance.css().getText()); + return instance; + } + }); + + register(Singleton.class, new Factory<RTEImgResources>(RTEImgResources.class) { + @Override + public RTEImgResources create() { + final RTEImgResources instance = GWT.create(RTEImgResources.class); + StyleInjector.injectStylesheet(instance.css().getText()); + return instance; + } + }); + + register(NoDecoration.class,new Factory<RTEditor>(RTEditor.class) { + @Override + public RTEditor create() { + final RTEditorPresenter presenter = new RTEditorPresenter(i(I18nTranslationService.class), i(Session.class), i(RTEImgResources.class), p(InsertLinkDialog.class), p(ColorWebSafePalette.class), p(EditHtmlDialog.class), p(InsertImageDialog.class), p(InsertMediaDialog.class), p(InsertTableDialog.class), p(InsertSpecialCharDialog.class), i(DeferredCommandWrapper.class)); - final RTEditorPanelNew panel = new RTEditorPanelNew(presenter, i(I18nUITranslationService.class), + final RTEditorPanel panel = new RTEditorPanel(presenter, i(I18nUITranslationService.class), i(GlobalShortcutRegister.class), i(GuiBindingsRegister.class)); presenter.init(panel); return presenter; @@ -348,10 +344,14 @@ }, new Factory<RTESavingEditor>(RTESavingEditor.class) { @Override public RTESavingEditor create() { - final RTESavingEditorPresenter presenter = new RTESavingEditorPresenter(i(RTEditorNew.class), true, - i(I18nTranslationService.class), i(StateManager.class), i(DeferredCommandWrapper.class), - i(RTEImgResources.class), i(TimerWrapper.class)); - final RTESavingEditorPanel panel = new RTESavingEditorPanel(); + final RTESavingEditorPresenter presenter = new RTESavingEditorPresenter(i(I18nTranslationService.class), + i(Session.class), i(RTEImgResources.class), p(InsertLinkDialog.class), + p(ColorWebSafePalette.class), p(EditHtmlDialog.class), p(InsertImageDialog.class), + p(InsertMediaDialog.class), p(InsertTableDialog.class), p(InsertSpecialCharDialog.class), i(DeferredCommandWrapper.class), true, + i(StateManager.class), + i(TimerWrapper.class)); + final RTESavingEditorPanel panel = new RTESavingEditorPanel(presenter, i(I18nUITranslationService.class), + i(GlobalShortcutRegister.class), i(GuiBindingsRegister.class)); presenter.init(panel); return presenter; } @@ -371,24 +371,6 @@ } }); - register(Singleton.class, new Factory<ImgResources>(ImgResources.class) { - @Override - public ImgResources create() { - final ImgResources instance = GWT.create(ImgResources.class); - StyleInjector.injectStylesheet(instance.css().getText()); - return instance; - } - }); - - register(Singleton.class, new Factory<RTEImgResources>(RTEImgResources.class) { - @Override - public RTEImgResources create() { - final RTEImgResources instance = GWT.create(RTEImgResources.class); - StyleInjector.injectStylesheet(instance.css().getText()); - return instance; - } - }); - registerDecorator(EditHtmlGroup.class, new EditHtmlGroup(container)); register(Singleton.class, new Factory<EditHtmlDialog>(EditHtmlDialog.class) { @@ -548,21 +530,16 @@ } }); - register(Singleton.class, new Factory<TestButton>(TestButton.class) { - @Override - public TestButton create() { - final TestButton btn = new TestButton(i(WorkspaceSkeleton.class), i(GuiBindingsRegister.class), i(ImgResources.class)); - return btn; - } - }); - - - // i(TestButton.class); - i(ApplicationComponentGroup.class).createAll(); i(ToolGroup.class).createAll(); i(Application.class).start(); - //i(HelloWorld.class); + // We install our HelloWorldModule + //Suco.install(new HelloWorldModule()); + + // And because nobody use this module, we get the class (to force the + // creation of the + // Helloworld instance): + //i(HelloWorld.class); } } \ No newline at end of file Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/TestRTEDialog.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/TestRTEDialog.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/TestRTEDialog.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -2,8 +2,7 @@ import org.ourproject.kune.platf.client.actions.ui.ComplexToolbar; import org.ourproject.kune.platf.client.ui.dialogs.BasicDialog; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorNew; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorPanelNew; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorPanel; import org.ourproject.kune.platf.client.ui.rte.saving.RTESavingEditor; import com.google.gwt.user.client.ui.VerticalPanel; @@ -20,10 +19,9 @@ dialog = new BasicDialog("Testing RTE", false, false, 650, 200); final VerticalPanel vp = new VerticalPanel(); - final RTEditorNew basicEditor = editor.getBasicEditor(); - vp.add((ComplexToolbar) basicEditor.getTopBar()); - vp.add((ComplexToolbar) basicEditor.getSndBar()); - final RTEditorPanelNew editorPanel = (RTEditorPanelNew) basicEditor.getEditorArea(); + vp.add((ComplexToolbar) editor.getTopBar()); + vp.add((ComplexToolbar) editor.getSndBar()); + final RTEditorPanel editorPanel = (RTEditorPanel) editor.getEditorArea(); vp.add(editorPanel); vp.setWidth("100%"); dialog.add(vp); @@ -38,11 +36,11 @@ } public void setExtended(final boolean extended) { - editor.getBasicEditor().setExtended(extended); + editor.setExtended(extended); } public void show() { - editor.getBasicEditor().attach(); + editor.attach(); dialog.show(); } } Deleted: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEActionSndToolbar.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEActionSndToolbar.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEActionSndToolbar.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -1,13 +0,0 @@ -package org.ourproject.kune.platf.client.ui.rte.basic; - -import org.ourproject.kune.platf.client.actions.toolbar.ActionToolbar; -import org.ourproject.kune.platf.client.actions.toolbar.ActionToolbarPresenter; -import org.ourproject.kune.platf.client.actions.toolbar.ActionToolbarView; - -public class RTEActionSndToolbar extends ActionToolbarPresenter<Object> implements ActionToolbar<Object> { - - public RTEActionSndToolbar(ActionToolbarView<Object> toolbar) { - super(toolbar); - } - -} \ No newline at end of file Deleted: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEActionTopToolbar.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEActionTopToolbar.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEActionTopToolbar.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -1,13 +0,0 @@ -package org.ourproject.kune.platf.client.ui.rte.basic; - -import org.ourproject.kune.platf.client.actions.toolbar.ActionToolbar; -import org.ourproject.kune.platf.client.actions.toolbar.ActionToolbarPresenter; -import org.ourproject.kune.platf.client.actions.toolbar.ActionToolbarView; - -public class RTEActionTopToolbar extends ActionToolbarPresenter<Object> implements ActionToolbar<Object> { - - public RTEActionTopToolbar(ActionToolbarView<Object> toolbar) { - super(toolbar); - } - -} \ No newline at end of file Copied: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditor.java (from rev 1123, trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorNew.java) =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorNew.java 2009-06-09 18:56:54 UTC (rev 1123) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditor.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -0,0 +1,233 @@ +package org.ourproject.kune.platf.client.ui.rte.basic; + +import org.ourproject.kune.platf.client.View; +import org.ourproject.kune.platf.client.actions.AbstractAction; +import org.ourproject.kune.platf.client.actions.KeyStroke; +import org.ourproject.kune.platf.client.actions.ui.GuiActionDescCollection; +import org.ourproject.kune.platf.client.actions.ui.GuiActionDescrip; +import org.ourproject.kune.platf.client.actions.ui.GuiAddCondition; +import org.ourproject.kune.platf.client.actions.ui.MenuDescriptor; + +import com.calclab.suco.client.events.Listener0; + +// TODO: Auto-generated Javadoc +/** + * The Interface RTEditor. + */ +public interface RTEditor { + + /** + * The TOPBAR location used in {@link GuiActionDescrip#setLocation(String)} + * for put the actions in the correct position + */ + String TOPBAR = "rte-topbar"; + + /** + * The SNDBAR location used in {@link GuiActionDescrip#setLocation(String)} + * for put the actions in the correct position + */ + String SNDBAR = "rte-sndbar"; + + /** + * The LINKCTX location used in {@link GuiActionDescrip#setLocation(String)} + * for put the actions in the links context menu + */ + String LINKCTX = "rte-linkctx"; + + /** + * Adds a action description + * + * @param action + * the action + */ + void addAction(GuiActionDescrip action); + + /** + * Adds some action descriptions + * + * @param actions + * the actions + */ + void addActionCollection(GuiActionDescCollection actions); + + /** + * Adds some action descriptions + * + * @param action + * the action + */ + void addActions(GuiActionDescrip... actions); + + /** + * Adds the on edit listener (fired when the user do some edit). + * + * @param listener + * the listener + */ + void addOnEditListener(Listener0 listener); + + /** + * Attach (used for lazy action loading) + */ + void attach(); + + /** + * Detach. + */ + void detach(); + + /** + * Gets the basic add condition (if the editor is of "basic" type). + * + * @return the basic add condition + */ + GuiAddCondition getBasicAddCondition(); + + /** + * Gets the "Edit" menu. + * + * @return the edits the menu + */ + MenuDescriptor getEditMenu(); + + /** + * Gets the editor area (used for gui layout) + * + * @return the editor area + */ + View getEditorArea(); + + /** + * Gets the extended add condition (editor can be a extended editor) + * + * @return the extended add condition + */ + GuiAddCondition getExtendedAddCondition(); + + /** + * Gets the file menu. + * + * @return the file menu + */ + MenuDescriptor getFileMenu(); + + /** + * Gets the format menu descriptor. + * + * @return the format menu + */ + MenuDescriptor getFormatMenu(); + + /** + * Gets the html of the text area. + * + * @return the html + */ + String getHtml(); + + /** + * Gets the insert menu descriptor. + * + * @return the insert menu + */ + MenuDescriptor getInsertMenu(); + + /** + * Gets the link ctx menu descriptor. + * + * @return the link ctx menu + */ + MenuDescriptor getLinkCtxMenu(); + + /** + * Gets the second bar of the editor. + * + * @return the snd bar + */ + View getSndBar(); + + /** + * Gets the text of the text area (not the html). + * + * @return the text + */ + String getText(); + + /** + * Gets the top bar. + * + * @return the top bar + */ + View getTopBar(); + + /** + * Reset. + */ + void reset(); + + /** + * Sets an action shortcut. + * + * @param key + * the key + * @param action + * the action + */ + void setActionShortcut(KeyStroke key, AbstractAction action); + + /** + * Sets some action shortcut, some principal, other similar (used when some + * UI buttons do the same action). + * + * @param key + * the key + * @param mainAction + * the main action + * @param actions + * the actions + */ + void setActionShortcut(KeyStroke key, AbstractAction mainAction, AbstractAction... actions); + + /** + * Sets that editor must be extended type (if browser permit it). + * + * @param extended + * the new extended + */ + void setExtended(boolean extended); + + /** + * Sets the focus on text editor. + * + * @param focus + * the new focus + */ + void setFocus(boolean focus); + + /** + * Sets the html of the editor. + * + * @param html + * the new html + */ + void setHtml(String html); + + /** + * We can define some location ("topbar", "second bar", etc) to action + * descriptors. + * + * @param location + * the location + * @param descripts + * the descripts + */ + void setLocation(String location, GuiActionDescrip... descripts); + + /** + * Sets the text of the editor. + * + * @param text + * the new text + */ + void setText(String text); +} Deleted: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorNew.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorNew.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorNew.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -1,66 +0,0 @@ -package org.ourproject.kune.platf.client.ui.rte.basic; - -import org.ourproject.kune.platf.client.View; -import org.ourproject.kune.platf.client.actions.AbstractAction; -import org.ourproject.kune.platf.client.actions.KeyStroke; -import org.ourproject.kune.platf.client.actions.ui.GuiActionDescCollection; -import org.ourproject.kune.platf.client.actions.ui.GuiActionDescrip; -import org.ourproject.kune.platf.client.actions.ui.GuiAddCondition; -import org.ourproject.kune.platf.client.actions.ui.MenuDescriptor; - -import com.calclab.suco.client.events.Listener0; - -public interface RTEditorNew { - - String TOPBAR = "rte-topbar"; - String SNDBAR = "rte-sndbar"; - String LINKCTX = "rte-linkctx"; - - void addAction(GuiActionDescrip action); - - void addActions(GuiActionDescCollection actions); - - void addOnEditListener(Listener0 listener); - - void attach(); - - void detach(); - - GuiAddCondition getBasicAddCondition(); - - MenuDescriptor getEditMenu(); - - View getEditorArea(); - - GuiAddCondition getExtendedAddCondition(); - - MenuDescriptor getFileMenu(); - - MenuDescriptor getFormatMenu(); - - String getHtml(); - - MenuDescriptor getInsertMenu(); - - MenuDescriptor getLinkCtxMenu(); - - View getSndBar(); - - String getText(); - - View getTopBar(); - - void reset(); - - void setActionShortcut(KeyStroke key, AbstractAction action); - - void setActionShortcut(KeyStroke key, AbstractAction mainAction, AbstractAction... actions); - - void setExtended(boolean extended); - - void setFocus(boolean focus); - - void setHtml(String html); - - void setText(String text); -} Copied: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanel.java (from rev 1124, trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanelNew.java) =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanelNew.java 2009-06-10 14:37:53 UTC (rev 1124) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanel.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -0,0 +1,518 @@ +package org.ourproject.kune.platf.client.ui.rte.basic; + +import java.util.Date; + +import org.cobogw.gwt.user.client.CSS; +import org.ourproject.kune.platf.client.View; +import org.ourproject.kune.platf.client.actions.AbstractAction; +import org.ourproject.kune.platf.client.actions.ActionEvent; +import org.ourproject.kune.platf.client.actions.ui.AbstractComplexGuiItem; +import org.ourproject.kune.platf.client.actions.ui.ComplexToolbar; +import org.ourproject.kune.platf.client.actions.ui.GuiActionDescCollection; +import org.ourproject.kune.platf.client.actions.ui.GuiActionDescrip; +import org.ourproject.kune.platf.client.actions.ui.GuiBindingsRegister; +import org.ourproject.kune.platf.client.errors.UIException; +import org.ourproject.kune.platf.client.i18n.I18nUITranslationService; +import org.ourproject.kune.platf.client.shortcuts.GlobalShortcutRegister; +import org.ourproject.kune.platf.client.ui.noti.NotifyUser; +import org.ourproject.kune.platf.client.ui.rte.RichTextArea; +import org.ourproject.kune.platf.client.ui.rte.RichTextArea.BasicFormatter; +import org.ourproject.kune.platf.client.ui.rte.RichTextArea.ExtendedFormatter; +import org.ourproject.kune.platf.client.ui.rte.RichTextArea.FontSize; +import org.ourproject.kune.platf.client.ui.rte.RichTextArea.Justification; +import org.ourproject.kune.platf.client.ui.rte.insertlink.LinkExecutableUtils; +import org.ourproject.kune.platf.client.ui.rte.insertlink.LinkInfo; +import org.xwiki.gwt.dom.client.DocumentFragment; +import org.xwiki.gwt.dom.client.Range; +import org.xwiki.gwt.dom.client.Selection; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.Node; +import com.google.gwt.event.dom.client.BlurEvent; +import com.google.gwt.event.dom.client.BlurHandler; +import com.google.gwt.event.dom.client.FocusEvent; +import com.google.gwt.event.dom.client.FocusHandler; +import com.google.gwt.event.dom.client.KeyCodes; +import com.google.gwt.user.client.Command; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.DeferredCommand; +import com.google.gwt.user.client.Event; + +public class RTEditorPanel extends AbstractComplexGuiItem implements RTEditorView, FocusHandler, BlurHandler { + + private static final Element NO_ELEMENT = null; + private final I18nUITranslationService i18n; + private final BasicFormatter basic; + private final ExtendedFormatter extended; + private final RTEditorPresenter presenter; + private final GlobalShortcutRegister globalShortcutReg; + private final RTELinkPopup linkCtxMenu; + private final RichTextArea rta; + private final ComplexToolbar topBar; + private final ComplexToolbar sndBar; + + public RTEditorPanel(final RTEditorPresenter presenter, final I18nUITranslationService i18n, + final GlobalShortcutRegister globalShortcutReg, final GuiBindingsRegister bindReg) { + super(); + this.presenter = presenter; + this.i18n = i18n; + this.globalShortcutReg = globalShortcutReg; + rta = new RichTextArea(); + basic = rta.getBasicFormatter(); + extended = rta.getExtendedFormatter(); + topBar = new ComplexToolbar(bindReg); + sndBar = new ComplexToolbar(bindReg); + sndBar.setNormalStyle(); + rta.addFocusHandler(this); + rta.addBlurHandler(this); + linkCtxMenu = new RTELinkPopup(); + initWidget(rta); + setWidth("96%"); + setHeight("100%"); + } + + public void addActions(final GuiActionDescCollection items) { + super.addAll(items); + for (final GuiActionDescrip item : items) { + final String location = item.getLocation(); + if (location == null) { + throw new UIException("Unknown location in action item: " + item); + } + if (location.equals(RTEditor.TOPBAR)) { + topBar.add(item); + } else if (location.equals(RTEditor.SNDBAR)) { + sndBar.add(item); + } else if (location.equals(RTEditor.LINKCTX)) { + linkCtxMenu.add(item); + } else { + throw new UIException("Unknown location in action item: " + item); + } + } + } + + public void adjustSize(final int height) { + setHeight(Integer.toString(height)); + } + + public boolean canBeBasic() { + return basic != null; + } + + public boolean canBeExtended() { + return extended != null; + } + + public void copy() { + extended.copy(); + } + + public void createLink(final String url) { + extended.createLink(url); + } + + public void cut() { + extended.cut(); + } + + public void delete() { + extended.delete(); + } + + public void focus() { + setFocus(true); + } + + public String getFont() { + final Element currentElement = getCurrentElement(); + return currentElement == NO_ELEMENT ? "" : currentElement.getStyle().getProperty(CSS.A.FONT_FAMILY); + } + + public String getFontSize() { + final Element currentElement = getCurrentElement(); + return currentElement == NO_ELEMENT ? "" : currentElement.getStyle().getProperty("size"); + } + + public String getHTML() { + return rta.getHTML(); + } + + public LinkInfo getLinkInfoIfHref() { + LinkInfo linkinfo = null; + final org.xwiki.gwt.dom.client.Element selectedAnchor = selectAndGetLink(); + if (selectedAnchor == null) { + linkinfo = new LinkInfo(getSelectionText()); + } else { + linkinfo = LinkInfo.parse(selectedAnchor); + } + Log.debug("Link info: " + linkinfo); + return linkinfo; + } + + public void getRangeInfo() { + // Selection selection = getSelection(); + // String info = "range count: " + selection.getRangeCount() + + // "<br/>focus offset: " + selection.getFocusOffset() + // + "<br/>anchor offset:" + selection.getAnchorOffset() + + // "<br/>range 0 as html: " + // + selection.getRangeAt(0).toHTML(); + // NotifyUser.info(info); + final String info = "range count: " + getFstRange().getCommonAncestorContainer().getFirstChild().getNodeName(); + NotifyUser.info(info); + } + + public String getSelectionText() { + return getFstRange().cloneContents().getInnerText(); + } + + public View getSndBar() { + return sndBar; + } + + public String getText() { + return rta.getText(); + } + + public View getTopBar() { + return topBar; + } + + public void hideLinkCtxMenu() { + linkCtxMenu.hide(); + } + + public void insertBlockquote() { + final DocumentFragment extracted = getFstRange().cloneContents(); + // delete(); + insertHtml("<blockquote>" + extracted.getInnerHTML() + "</blockquote>"); + focus(); + } + + public void insertComment(final String author) { + createCommentAndSelectIt(author, null); + } + + public void insertCommentNotUsingSelection(final String author) { + getFstRange().collapse(false); + createCommentAndSelectIt(author, null); + focus(); + } + + public void insertCommentUsingSelection(final String author) { + final DocumentFragment extracted = getFstRange().cloneContents(); + extended.delete(); + final String comment = extracted.getInnerText(); + createCommentAndSelectIt(author, comment); + focus(); + } + + public void insertHorizontalRule() { + extended.insertHorizontalRule(); + } + + public void insertHtml(final String html) { + extended.insertHtml(html); + } + + public void insertImage(final String url) { + extended.insertImage(url); + } + + public void insertOrderedList() { + extended.insertOrderedList(); + } + + public void insertUnorderedList() { + extended.insertUnorderedList(); + } + + public boolean isAnythingSelected() { + return !rta.getDocument().getSelection().isCollapsed(); + } + + public boolean isBold() { + return basic.isBold(); + } + + public boolean isCollapsed() { + return getFstRange().isCollapsed(); + } + + public boolean isCtxMenuVisible() { + return linkCtxMenu.isVisible(); + } + + public boolean isItalic() { + return basic.isItalic(); + } + + public boolean isLink() { + boolean isLink = false; + if (isAttached() && LinkExecutableUtils.getSelectedAnchor(rta) != null) { + isLink = true; + } + return isLink; + } + + public boolean isStrikethrough() { + return extended.isStrikethrough(); + } + + public boolean isSubscript() { + return basic.isSubscript(); + } + + public boolean isSuperscript() { + return basic.isSuperscript(); + } + + public boolean isUnderlined() { + return basic.isUnderlined(); + } + + public void justifyCenter() { + basic.setJustification(Justification.CENTER); + } + + public void justifyLeft() { + basic.setJustification(Justification.LEFT); + } + + public void justifyRight() { + basic.setJustification(Justification.RIGHT); + } + + public void leftIndent() { + extended.leftIndent(); + } + + public void onBlur(final BlurEvent event) { + presenter.onLostFocus(); + } + + @Override + public void onBrowserEvent(final Event event) { + switch (DOM.eventGetType(event)) { + case Event.ONCLICK: + updateStatus(); + updateLinkInfo(); + super.onBrowserEvent(event); + break; + case Event.ONKEYPRESS: + final AbstractAction rtaActionItem = super.getAction(event); + // FIXME + // final Action actionItem = rtaActionItem == null ? + // globalShortcutReg.get(event) : rtaActionItem; + final AbstractAction actionItem = rtaActionItem == null ? null : rtaActionItem; + if (actionItem == null) { + super.onBrowserEvent(event); + updateStatus(); + updateLinkInfo(); + if (isAnEditionKey(event.getKeyCode())) { + fireEdit(); + } + } else { + updateStatus(); + fireEdit(); + event.stopPropagation(); + event.preventDefault(); + actionItem.actionPerformed(new ActionEvent(this, event)); + updateStatus(); + } + break; + default: + // Rest of events + super.onBrowserEvent(event); + updateStatus(); + } + } + + public void onFocus(final FocusEvent event) { + presenter.onEditorFocus(); + } + + public void paste() { + extended.paste(); + } + + public void redo() { + extended.redo(); + } + + public void removeFormat() { + extended.removeFormat(); + } + + public void rightIndent() { + extended.rightIndent(); + } + + public void selectAll() { + basic.selectAll(); + } + + public void selectLink() { + selectAndGetLink(); + } + + public void setBackColor(final String color) { + basic.setBackColor(color); + } + + public void setFocus(final boolean focused) { + rta.setFocus(focused); + } + + public void setFontName(final String name) { + basic.setFontName(name); + } + + public void setFontSize(final FontSize size) { + basic.setFontSize(size); + } + + public void setForeColor(final String color) { + basic.setForeColor(color); + } + + public void setHTML(final String html) { + rta.setHTML(html); + } + + public void setText(final String text) { + rta.setText(text); + } + + public void showLinkCtxMenu() { + DeferredCommand.addCommand(new Command() { + public void execute() { + final org.xwiki.gwt.dom.client.Element selectedAnchor = LinkExecutableUtils.getSelectedAnchor(rta); + if (selectedAnchor != null) { + linkCtxMenu.show(RTEditorPanel.this.getAbsoluteLeft() + selectedAnchor.getAbsoluteLeft(), + RTEditorPanel.this.getAbsoluteTop() + selectedAnchor.getAbsoluteTop() + 20); + } + } + }); + + } + + public void toggleBold() { + basic.toggleBold(); + } + + public void toggleItalic() { + basic.toggleItalic(); + } + + public void toggleStrikethrough() { + extended.toggleStrikethrough(); + } + + public void toggleSubscript() { + basic.toggleSubscript(); + } + + public void toggleSuperscript() { + basic.toggleSuperscript(); + } + + public void toggleUnderline() { + basic.toggleUnderline(); + } + + public void undo() { + extended.undo(); + } + + public void unlink() { + extended.removeLink(); + } + + protected void fireEdit() { + presenter.fireOnEdit(); + } + + protected Element getElement(final Node inputNode) { + Node node = inputNode; + if (node.getNodeType() != Node.ELEMENT_NODE) { + node = node.getParentNode(); + } + if (node == null || node.getNodeType() != Node.ELEMENT_NODE) { + return null; + } + return Element.as(node); + } + + private void createCommentAndSelectIt(final String author, final String comment) { + final Element commentEl = createCommentElement(author, comment); + final Range innerCommentRange = rta.getDocument().createRange(); + getFstRange().insertNode(commentEl); + innerCommentRange.selectNodeContents(commentEl.getFirstChild()); + getSelection().addRange(innerCommentRange); + fireEdit(); + } + + private Element createCommentElement(final String userName, final String insertComment) { + final String time = i18n.formatDateWithLocale(new Date(), true); + final Element span = rta.getDocument().createSpanElement(); + final String comment = insertComment == null ? i18n.t("type your comment here") : insertComment; + span.setInnerHTML("<em>" + comment + "</em> -" + userName + " " + time); + DOM.setElementProperty(span.<com.google.gwt.user.client.Element> cast(), "className", "k-rte-comment"); + // insertHtml(" " + span.getString() + " "); + return span; + } + + private Element getCurrentElement() { + if (getSelection().getRangeCount() > 0) { + return getElement(getSelection().getRangeAt(0).getStartContainer()); + } else { + return NO_ELEMENT; + } + } + + private Range getFstRange() { + return getSelection().getRangeAt(0); + } + + private Selection getSelection() { + return rta.getDocument().getSelection(); + } + + private boolean isAnEditionKey(final int keyCode) { + switch (keyCode) { // NOPMD by vjrj on 5/06/09 19:14 + case KeyCodes.KEY_HOME: + case KeyCodes.KEY_END: + case KeyCodes.KEY_UP: + case KeyCodes.KEY_DOWN: + case KeyCodes.KEY_LEFT: + case KeyCodes.KEY_RIGHT: + case KeyCodes.KEY_PAGEDOWN: + case KeyCodes.KEY_PAGEUP: + case KeyCodes.KEY_ESCAPE: + return false; + default: + return true; + } + } + + private org.xwiki.gwt.dom.client.Element selectAndGetLink() { + final org.xwiki.gwt.dom.client.Element selectedAnchor = LinkExecutableUtils.getSelectedAnchor(rta); + if (selectedAnchor != null) { + final Range range = rta.getDocument().createRange(); + range.selectNode(selectedAnchor); + getSelection().addRange(range); + } + return selectedAnchor; + } + + private void updateLinkInfo() { + presenter.updateLinkInfo(); + } + + /** + * Updates the status of all the stateful buttons. + */ + private void updateStatus() { + presenter.updateStatus(); + } +} Deleted: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanelNew.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanelNew.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanelNew.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -1,518 +0,0 @@ -package org.ourproject.kune.platf.client.ui.rte.basic; - -import java.util.Date; - -import org.cobogw.gwt.user.client.CSS; -import org.ourproject.kune.platf.client.View; -import org.ourproject.kune.platf.client.actions.AbstractAction; -import org.ourproject.kune.platf.client.actions.ActionEvent; -import org.ourproject.kune.platf.client.actions.ui.AbstractComplexGuiItem; -import org.ourproject.kune.platf.client.actions.ui.ComplexToolbar; -import org.ourproject.kune.platf.client.actions.ui.GuiActionDescCollection; -import org.ourproject.kune.platf.client.actions.ui.GuiActionDescrip; -import org.ourproject.kune.platf.client.actions.ui.GuiBindingsRegister; -import org.ourproject.kune.platf.client.errors.UIException; -import org.ourproject.kune.platf.client.i18n.I18nUITranslationService; -import org.ourproject.kune.platf.client.shortcuts.GlobalShortcutRegister; -import org.ourproject.kune.platf.client.ui.noti.NotifyUser; -import org.ourproject.kune.platf.client.ui.rte.RichTextArea; -import org.ourproject.kune.platf.client.ui.rte.RichTextArea.BasicFormatter; -import org.ourproject.kune.platf.client.ui.rte.RichTextArea.ExtendedFormatter; -import org.ourproject.kune.platf.client.ui.rte.RichTextArea.FontSize; -import org.ourproject.kune.platf.client.ui.rte.RichTextArea.Justification; -import org.ourproject.kune.platf.client.ui.rte.insertlink.LinkExecutableUtils; -import org.ourproject.kune.platf.client.ui.rte.insertlink.LinkInfo; -import org.xwiki.gwt.dom.client.DocumentFragment; -import org.xwiki.gwt.dom.client.Range; -import org.xwiki.gwt.dom.client.Selection; - -import com.allen_sauer.gwt.log.client.Log; -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.Node; -import com.google.gwt.event.dom.client.BlurEvent; -import com.google.gwt.event.dom.client.BlurHandler; -import com.google.gwt.event.dom.client.FocusEvent; -import com.google.gwt.event.dom.client.FocusHandler; -import com.google.gwt.event.dom.client.KeyCodes; -import com.google.gwt.user.client.Command; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.DeferredCommand; -import com.google.gwt.user.client.Event; - -public class RTEditorPanelNew extends AbstractComplexGuiItem implements RTEditorViewNew, FocusHandler, BlurHandler { - - private static final Element NO_ELEMENT = null; - private final I18nUITranslationService i18n; - private final BasicFormatter basic; - private final ExtendedFormatter extended; - private final RTEditorPresenterNew presenter; - private final GlobalShortcutRegister globalShortcutReg; - private final RTELinkPopup linkCtxMenu; - private final RichTextArea rta; - private final ComplexToolbar topBar; - private final ComplexToolbar sndBar; - - public RTEditorPanelNew(final RTEditorPresenterNew presenter, final I18nUITranslationService i18n, - final GlobalShortcutRegister globalShortcutReg, final GuiBindingsRegister bindReg) { - super(); - this.presenter = presenter; - this.i18n = i18n; - this.globalShortcutReg = globalShortcutReg; - rta = new RichTextArea(); - basic = rta.getBasicFormatter(); - extended = rta.getExtendedFormatter(); - topBar = new ComplexToolbar(bindReg); - sndBar = new ComplexToolbar(bindReg); - sndBar.setNormalStyle(); - rta.addFocusHandler(this); - rta.addBlurHandler(this); - linkCtxMenu = new RTELinkPopup(); - initWidget(rta); - setWidth("96%"); - setHeight("100%"); - } - - public void addActions(final GuiActionDescCollection items) { - super.addAll(items); - for (final GuiActionDescrip item : items) { - final String location = item.getLocation(); - if (location == null) { - throw new UIException("Unknown location in action item: " + item); - } - if (location.equals(RTEditorNew.TOPBAR)) { - topBar.add(item); - } else if (location.equals(RTEditorNew.SNDBAR)) { - sndBar.add(item); - } else if (location.equals(RTEditorNew.LINKCTX)) { - linkCtxMenu.add(item); - } else { - throw new UIException("Unknown location in action item: " + item); - } - } - } - - public void adjustSize(final int height) { - setHeight(Integer.toString(height)); - } - - public boolean canBeBasic() { - return basic != null; - } - - public boolean canBeExtended() { - return extended != null; - } - - public void copy() { - extended.copy(); - } - - public void createLink(final String url) { - extended.createLink(url); - } - - public void cut() { - extended.cut(); - } - - public void delete() { - extended.delete(); - } - - public void focus() { - setFocus(true); - } - - public String getFont() { - final Element currentElement = getCurrentElement(); - return currentElement == NO_ELEMENT ? "" : currentElement.getStyle().getProperty(CSS.A.FONT_FAMILY); - } - - public String getFontSize() { - final Element currentElement = getCurrentElement(); - return currentElement == NO_ELEMENT ? "" : currentElement.getStyle().getProperty("size"); - } - - public String getHTML() { - return rta.getHTML(); - } - - public LinkInfo getLinkInfoIfHref() { - LinkInfo linkinfo = null; - final org.xwiki.gwt.dom.client.Element selectedAnchor = selectAndGetLink(); - if (selectedAnchor == null) { - linkinfo = new LinkInfo(getSelectionText()); - } else { - linkinfo = LinkInfo.parse(selectedAnchor); - } - Log.debug("Link info: " + linkinfo); - return linkinfo; - } - - public void getRangeInfo() { - // Selection selection = getSelection(); - // String info = "range count: " + selection.getRangeCount() + - // "<br/>focus offset: " + selection.getFocusOffset() - // + "<br/>anchor offset:" + selection.getAnchorOffset() + - // "<br/>range 0 as html: " - // + selection.getRangeAt(0).toHTML(); - // NotifyUser.info(info); - final String info = "range count: " + getFstRange().getCommonAncestorContainer().getFirstChild().getNodeName(); - NotifyUser.info(info); - } - - public String getSelectionText() { - return getFstRange().cloneContents().getInnerText(); - } - - public View getSndBar() { - return sndBar; - } - - public String getText() { - return rta.getText(); - } - - public View getTopBar() { - return topBar; - } - - public void hideLinkCtxMenu() { - linkCtxMenu.hide(); - } - - public void insertBlockquote() { - final DocumentFragment extracted = getFstRange().cloneContents(); - // delete(); - insertHtml("<blockquote>" + extracted.getInnerHTML() + "</blockquote>"); - focus(); - } - - public void insertComment(final String author) { - createCommentAndSelectIt(author, null); - } - - public void insertCommentNotUsingSelection(final String author) { - getFstRange().collapse(false); - createCommentAndSelectIt(author, null); - focus(); - } - - public void insertCommentUsingSelection(final String author) { - final DocumentFragment extracted = getFstRange().cloneContents(); - extended.delete(); - final String comment = extracted.getInnerText(); - createCommentAndSelectIt(author, comment); - focus(); - } - - public void insertHorizontalRule() { - extended.insertHorizontalRule(); - } - - public void insertHtml(final String html) { - extended.insertHtml(html); - } - - public void insertImage(final String url) { - extended.insertImage(url); - } - - public void insertOrderedList() { - extended.insertOrderedList(); - } - - public void insertUnorderedList() { - extended.insertUnorderedList(); - } - - public boolean isAnythingSelected() { - return !rta.getDocument().getSelection().isCollapsed(); - } - - public boolean isBold() { - return basic.isBold(); - } - - public boolean isCollapsed() { - return getFstRange().isCollapsed(); - } - - public boolean isCtxMenuVisible() { - return linkCtxMenu.isVisible(); - } - - public boolean isItalic() { - return basic.isItalic(); - } - - public boolean isLink() { - boolean isLink = false; - if (isAttached() && LinkExecutableUtils.getSelectedAnchor(rta) != null) { - isLink = true; - } - return isLink; - } - - public boolean isStrikethrough() { - return extended.isStrikethrough(); - } - - public boolean isSubscript() { - return basic.isSubscript(); - } - - public boolean isSuperscript() { - return basic.isSuperscript(); - } - - public boolean isUnderlined() { - return basic.isUnderlined(); - } - - public void justifyCenter() { - basic.setJustification(Justification.CENTER); - } - - public void justifyLeft() { - basic.setJustification(Justification.LEFT); - } - - public void justifyRight() { - basic.setJustification(Justification.RIGHT); - } - - public void leftIndent() { - extended.leftIndent(); - } - - public void onBlur(final BlurEvent event) { - presenter.onLostFocus(); - } - - @Override - public void onBrowserEvent(final Event event) { - switch (DOM.eventGetType(event)) { - case Event.ONCLICK: - updateStatus(); - updateLinkInfo(); - super.onBrowserEvent(event); - break; - case Event.ONKEYPRESS: - final AbstractAction rtaActionItem = super.getAction(event); - // FIXME - // final Action actionItem = rtaActionItem == null ? - // globalShortcutReg.get(event) : rtaActionItem; - final AbstractAction actionItem = rtaActionItem == null ? null : rtaActionItem; - if (actionItem == null) { - super.onBrowserEvent(event); - updateStatus(); - updateLinkInfo(); - if (isAnEditionKey(event.getKeyCode())) { - fireEdit(); - } - } else { - updateStatus(); - fireEdit(); - event.stopPropagation(); - event.preventDefault(); - actionItem.actionPerformed(new ActionEvent(this, event)); - updateStatus(); - } - break; - default: - // Rest of events - super.onBrowserEvent(event); - updateStatus(); - } - } - - public void onFocus(final FocusEvent event) { - presenter.onEditorFocus(); - } - - public void paste() { - extended.paste(); - } - - public void redo() { - extended.redo(); - } - - public void removeFormat() { - extended.removeFormat(); - } - - public void rightIndent() { - extended.rightIndent(); - } - - public void selectAll() { - basic.selectAll(); - } - - public void selectLink() { - selectAndGetLink(); - } - - public void setBackColor(final String color) { - basic.setBackColor(color); - } - - public void setFocus(final boolean focused) { - rta.setFocus(focused); - } - - public void setFontName(final String name) { - basic.setFontName(name); - } - - public void setFontSize(final FontSize size) { - basic.setFontSize(size); - } - - public void setForeColor(final String color) { - basic.setForeColor(color); - } - - public void setHTML(final String html) { - rta.setHTML(html); - } - - public void setText(final String text) { - rta.setText(text); - } - - public void showLinkCtxMenu() { - DeferredCommand.addCommand(new Command() { - public void execute() { - final org.xwiki.gwt.dom.client.Element selectedAnchor = LinkExecutableUtils.getSelectedAnchor(rta); - if (selectedAnchor != null) { - linkCtxMenu.show(RTEditorPanelNew.this.getAbsoluteLeft() + selectedAnchor.getAbsoluteLeft(), - RTEditorPanelNew.this.getAbsoluteTop() + selectedAnchor.getAbsoluteTop() + 20); - } - } - }); - - } - - public void toggleBold() { - basic.toggleBold(); - } - - public void toggleItalic() { - basic.toggleItalic(); - } - - public void toggleStrikethrough() { - extended.toggleStrikethrough(); - } - - public void toggleSubscript() { - basic.toggleSubscript(); - } - - public void toggleSuperscript() { - basic.toggleSuperscript(); - } - - public void toggleUnderline() { - basic.toggleUnderline(); - } - - public void undo() { - extended.undo(); - } - - public void unlink() { - extended.removeLink(); - } - - protected void fireEdit() { - presenter.fireOnEdit(); - } - - protected Element getElement(final Node inputNode) { - Node node = inputNode; - if (node.getNodeType() != Node.ELEMENT_NODE) { - node = node.getParentNode(); - } - if (node == null || node.getNodeType() != Node.ELEMENT_NODE) { - return null; - } - return Element.as(node); - } - - private void createCommentAndSelectIt(final String author, final String comment) { - final Element commentEl = createCommentElement(author, comment); - final Range innerCommentRange = rta.getDocument().createRange(); - getFstRange().insertNode(commentEl); - innerCommentRange.selectNodeContents(commentEl.getFirstChild()); - getSelection().addRange(innerCommentRange); - fireEdit(); - } - - private Element createCommentElement(final String userName, final String insertComment) { - final String time = i18n.formatDateWithLocale(new Date(), true); - final Element span = rta.getDocument().createSpanElement(); - final String comment = insertComment == null ? i18n.t("type your comment here") : insertComment; - span.setInnerHTML("<em>" + comment + "</em> -" + userName + " " + time); - DOM.setElementProperty(span.<com.google.gwt.user.client.Element> cast(), "className", "k-rte-comment"); - // insertHtml(" " + span.getString() + " "); - return span; - } - - private Element getCurrentElement() { - if (getSelection().getRangeCount() > 0) { - return getElement(getSelection().getRangeAt(0).getStartContainer()); - } else { - return NO_ELEMENT; - } - } - - private Range getFstRange() { - return getSelection().getRangeAt(0); - } - - private Selection getSelection() { - return rta.getDocument().getSelection(); - } - - private boolean isAnEditionKey(final int keyCode) { - switch (keyCode) { // NOPMD by vjrj on 5/06/09 19:14 - case KeyCodes.KEY_HOME: - case KeyCodes.KEY_END: - case KeyCodes.KEY_UP: - case KeyCodes.KEY_DOWN: - case KeyCodes.KEY_LEFT: - case KeyCodes.KEY_RIGHT: - case KeyCodes.KEY_PAGEDOWN: - case KeyCodes.KEY_PAGEUP: - case KeyCodes.KEY_ESCAPE: - return false; - default: - return true; - } - } - - private org.xwiki.gwt.dom.client.Element selectAndGetLink() { - final org.xwiki.gwt.dom.client.Element selectedAnchor = LinkExecutableUtils.getSelectedAnchor(rta); - if (selectedAnchor != null) { - final Range range = rta.getDocument().createRange(); - range.selectNode(selectedAnchor); - getSelection().addRange(range); - } - return selectedAnchor; - } - - private void updateLinkInfo() { - presenter.updateLinkInfo(); - } - - /** - * Updates the status of all the stateful buttons. - */ - private void updateStatus() { - presenter.updateStatus(); - } -} Copied: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenter.java (from rev 1125, trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenterNew.java) =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenterNew.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenter.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -0,0 +1,1201 @@ +package org.ourproject.kune.platf.client.ui.rte.basic; + +import static org.ourproject.kune.platf.client.actions.AbstractExtendedAction.NO_ICON; +import static org.ourproject.kune.platf.client.actions.AbstractExtendedAction.NO_TEXT; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.ourproject.kune.platf.client.View; +import org.ourproject.kune.platf.client.actions.AbstractAction; +import org.ourproject.kune.platf.client.actions.AbstractExtendedAction; +import org.ourproject.kune.platf.client.actions.Action; +import org.ourproject.kune.platf.client.actions.ActionEvent; +import org.ourproject.kune.platf.client.actions.InputMap; +import org.ourproject.kune.platf.client.actions.KeyStroke; +import org.ourproject.kune.platf.client.actions.ui.ButtonDescriptor; +import org.ourproject.kune.platf.client.actions.ui.GuiActionDescCollection; +import org.ourproject.kune.platf.client.actions.ui.GuiActionDescrip; +import org.ourproject.kune.platf.client.actions.ui.GuiAddCondition; +import org.ourproject.kune.platf.client.actions.ui.MenuCheckItemDescriptor; +import org.ourproject.kune.platf.client.actions.ui.MenuDescriptor; +import org.ourproject.kune.platf.client.actions.ui.MenuItemDescriptor; +import org.ourproject.kune.platf.client.actions.ui.MenuRadioItemDescriptor; +import org.ourproject.kune.platf.client.actions.ui.MenuSeparatorDescriptor; +import org.ourproject.kune.platf.client.actions.ui.PushButtonDescriptor; +import org.ourproject.kune.platf.client.actions.ui.ToolbarSeparatorDescriptor; +import org.ourproject.kune.platf.client.actions.ui.ToolbarSeparatorDescriptor.Type; +import org.ourproject.kune.platf.client.i18n.I18nTranslationService; +import org.ourproject.kune.platf.client.shortcuts.Keyboard; +import org.ourproject.kune.platf.client.state.Session; +import org.ourproject.kune.platf.client.ui.noti.NotifyUser; +import org.ourproject.kune.platf.client.ui.palette.ColorWebSafePalette; +import org.ourproject.kune.platf.client.ui.rte.RichTextArea; +import org.ourproject.kune.platf.client.ui.rte.edithtml.EditHtmlDialog; +import org.ourproject.kune.platf.client.ui.rte.img.RTEImgResources; +import org.ourproject.kune.platf.client.ui.rte.insertimg.ImageInfo; +import org.ourproject.kune.platf.client.ui.rte.insertimg.InsertImageDialog; +import org.ourproject.kune.platf.client.ui.rte.insertlink.InsertLinkDialog; +import org.ourproject.kune.platf.client.ui.rte.insertlink.LinkInfo; +import org.ourproject.kune.platf.client.ui.rte.insertmedia.InsertMediaDialog; +import org.ourproject.kune.platf.client.ui.rte.insertspecialchar.InsertSpecialCharDialog; +import org.ourproject.kune.platf.client.ui.rte.inserttable.InsertTableDialog; +import org.ourproject.kune.platf.client.utils.DeferredCommandWrapper; + +import com.allen_sauer.gwt.log.client.Log; +import com.calclab.suco.client.events.Event0; +import com.calclab.suco.client.events.Listener; +import com.calclab.suco.client.events.Listener0; +import com.calclab.suco.client.ioc.Provider; +import com.google.gwt.libideas.resources.client.ImageResource; +import com.google.gwt.user.client.Event; + +public class RTEditorPresenter implements RTEditor { + + public class BackgroundColorAction extends AbstractExtendedAction { + + public BackgroundColorAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + createPalette(); + final Event event = actionEvent.getEvent(); + palette.show(event.getClientX(), event.getClientY(), new Listener<String>() { + public void onEvent(final String color) { + palette.hide(); + view.setBackColor(color); + fireOnEdit(); + } + }); + } + } + + public class BlockquoteAction extends AbstractExtendedAction { + public BlockquoteAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.focus(); + view.insertBlockquote(); + fireOnEdit(); + } + } + + public class BoldAction extends AbstractExtendedAction { + public BoldAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.toggleBold(); + fireOnEdit(); + } + } + + public class CommentAction extends AbstractExtendedAction { + public CommentAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + deferred.addCommand(new Listener0() { + public void onEvent() { + view.focus(); + final String author = session.isLogged() ? session.getCurrentUser().getShortName() + : i18n.t("anonymous user"); + if (view.isAnythingSelected()) { + NotifyUser.askConfirmation(i18n.t("Insert a comment"), + i18n.t("Include the selected text in the comment?"), new Listener0() { + public void onEvent() { + // include selection in + // comment + view.insertCommentUsingSelection(author); + } + }, new Listener0() { + public void onEvent() { + // not include selection in + // comment; + view.insertCommentNotUsingSelection(author); + } + }); + } else { + // Nothing selected > create comment in + // insertion point + view.insertComment(author); + } + } + }); + } + + @Override + public boolean isEnabled() { + return session.isLogged(); + } + } + + public class CopyAction extends AbstractExtendedAction { + public CopyAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.copy(); + } + } + + public class CreateOrEditLinkAction extends AbstractExtendedAction { + public CreateOrEditLinkAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + deferred.addCommand(new Listener0() { + private InsertLinkDialog insLinkDialog; + + public void onEvent() { + if (insLinkListener == null) { + insLinkListener = new Listener<LinkInfo>() { + public void onEvent(final LinkInfo linkInfo) { + final String link = linkInfo.toString(); + Log.debug("Link: " + link); + view.focus(); + view.insertHtml(link); + fireOnEdit(); + } + }; + } + final LinkInfo linkInfo = view.getLinkInfoIfHref(); + + if (insLinkDialog == null) { + insLinkDialog = insLinkDialogPv.get(); + } + insLinkDialog.setLinkInfo(linkInfo); + insLinkDialog.setOnCreateLink(insLinkListener); + insLinkDialog.show(); + hideLinkCtxMenu(); + final String href = linkInfo.getHref(); + if (href.length() > 0) { + if (href.startsWith("mailto")) { + insLinkDialog.activateTab(2); + } else { + insLinkDialog.activateTab(1); + } + } + } + }); + } + } + + public class CutAction extends AbstractExtendedAction { + public CutAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.cut(); + fireOnEdit(); + } + } + + public class DecreaseIndentAction extends AbstractExtendedAction { + public DecreaseIndentAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.leftIndent(); + fireOnEdit(); + } + } + + public class DevInfoAction extends AbstractExtendedAction { + public DevInfoAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + deferred.addCommand(new Listener0() { + public void onEvent() { + view.getRangeInfo(); + } + }); + } + } + + public class EditHtmlAction extends AbstractExtendedAction { + private EditHtmlDialog editHtmlDialog; + + public EditHtmlAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + if (updHtmlListener == null) { + updHtmlListener = new Listener<String>() { + public void onEvent(final String html) { + view.setHTML(html); + fireOnEdit(); + } + }; + } + if (editHtmlDialog == null) { + editHtmlDialog = editHtmlDialogPv.get(); + } + editHtmlDialog.setUpdateListener(updHtmlListener); + editHtmlDialog.show(); + hideLinkCtxMenu(); + editHtmlDialog.setHtml(view.getHTML()); + } + } + + public class FontAction extends AbstractExtendedAction { + public static final String FONT_NAME = "fontname"; + + public FontAction(final String fontName, final String tooltip, final ImageResource icon) { + super("<span style=\"font-family: " + fontName + "\">" + fontName + "</span>", tooltip, icon); + super.putValue(FONT_NAME, fontName); + } + + public void actionPerformed(final ActionEvent actionEvent) { + final String fontName = getFontName(); + view.setFontName(fontName); + fontMenu.setText(fontName); + fireOnEdit(); + } + + private String getFontName() { + return (String) super.getValue(FONT_NAME); + } + } + + public class FontColorAction extends AbstractExtendedAction { + public FontColorAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + createPalette(); + final Event event = actionEvent.getEvent(); + palette.show(event.getClientX(), event.getClientY(), new Listener<String>() { + public void onEvent(final String color) { + palette.hide(); + view.setForeColor(color); + fireOnEdit(); + } + }); + hideLinkCtxMenu(); + } + } + + public class FontSizeAction extends AbstractExtendedAction { + private final int fontSize; + + public FontSizeAction(final String fontSizeName, final int fontSize, final String tooltip, + final ImageResource icon) { + super("<font size=\"" + (fontSize + 1) + "\">" + fontSizeName + "</font>", tooltip, icon); + this.fontSize = fontSize; + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.setFontSize(FONT_SIZES[fontSize]); + fireOnEdit(); + // fontSizeMenu.setText(fontSizeName); + } + } + + public class HrAction extends AbstractExtendedAction { + public HrAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.focus(); + view.insertHorizontalRule(); + fireOnEdit(); + } + } + + public class ImgAction extends AbstractExtendedAction { + public ImgAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + deferred.addCommand(new Listener0() { + private InsertImageDialog insImgDialog; + + public void onEvent() { + if (insImgListener == null) { + insImgListener = new Listener<ImageInfo>() { + public void onEvent(final ImageInfo imageInfo) { + Log.debug("Image: " + imageInfo); + view.focus(); + view.insertHtml(imageInfo.toString()); + fireOnEdit(); + } + }; + } + if (insImgDialog == null) { + insImgDialog = insImgDialogProv.get(); + } + insImgDialog.reset(); + insImgDialog.setOnCreateImage(insImgListener); + insImgDialog.show(); + hideLinkCtxMenu(); + } + }); + } + } + + public class IncreaseIndentAction extends AbstractExtendedAction { + public IncreaseIndentAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.rightIndent(); + fireOnEdit(); + } + } + + public class InsertMediaAction extends AbstractExtendedAction { + public InsertMediaAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + deferred.addCommand(new Listener0() { + private InsertMediaDialog insMediaDialog; + + public void onEvent() { + if (insMediaListener == null) { + insMediaListener = new Listener<String>() { + public void onEvent(final String html) { + Log.debug("Media: " + html); + view.focus(); + view.insertHtml(html); + fireOnEdit(); + } + }; + } + if (insMediaDialog == null) { + insMediaDialog = insMediaDialogPv.get(); + } + insMediaDialog.setOnCreate(insMediaListener); + insMediaDialog.show(); + hideLinkCtxMenu(); + } + }); + } + } + + public class InsertSpecialCharAction extends AbstractExtendedAction { + private InsertSpecialCharDialog insCharDialog; + + public InsertSpecialCharAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + NotifyUser.showProgressLoading(); + if (insCharListener == null) { + insCharListener = new Listener<String>() { + public void onEvent(final String character) { + view.insertHtml(character); + } + }; + } + if (insCharDialog == null) { + insCharDialog = insCharDialogProv.get(); + } + insCharDialog.setOnInsertSpecialChar(insCharListener); + insCharDialog.show(); + hideLinkCtxMenu(); + NotifyUser.hideProgress(); + } + } + + public class InsertTableAction extends AbstractExtendedAction { + private InsertTableDialog insTableDialog; + + public InsertTableAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + if (insTableListener == null) { + insTableListener = new Listener<String>() { + public void onEvent(final String table) { + view.insertHtml(table); + fireOnEdit(); + } + }; + } + if (insTableDialog == null) { + insTableDialog = insTableDialogPv.get(); + } + insTableDialog.setOnInsertTable(insTableListener); + insTableDialog.show(); + } + } + + public class ItalicAction extends AbstractExtendedAction { + public ItalicAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.toggleItalic(); + fireOnEdit(); + } + } + + public class JustifyCentreAction extends AbstractExtendedAction { + public JustifyCentreAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.justifyCenter(); + fireOnEdit(); + } + } + + public class JustifyLeftAction extends AbstractExtendedAction { + public JustifyLeftAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.justifyLeft(); + fireOnEdit(); + } + } + + public class JustifyRightAction extends AbstractExtendedAction { + public JustifyRightAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.justifyRight(); + fireOnEdit(); + } + } + + public class OlAction extends AbstractExtendedAction { + public OlAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.insertOrderedList(); + fireOnEdit(); + } + } + + public class PasteAction extends AbstractExtendedAction { + public PasteAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.paste(); + fireOnEdit(); + } + } + + public class RedoAction extends AbstractExtendedAction { + public RedoAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.redo(); + fireOnEdit(); + } + } + + public class RemoveFormatAction extends AbstractExtendedAction { + public RemoveFormatAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.removeFormat(); + fireOnEdit(); + } + } + + public class RemoveLinkAction extends AbstractExtendedAction { + public RemoveLinkAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + deferred.addCommand(new Listener0() { + public void onEvent() { + view.unlink(); + hideLinkCtxMenu(); + fireOnEdit(); + } + }); + } + } + + public class SelectAllAction extends AbstractExtendedAction { + public SelectAllAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.selectAll(); + } + } + + public class StrikethroughAction extends AbstractExtendedAction { + public StrikethroughAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.toggleStrikethrough(); + fireOnEdit(); + } + } + + public class SubscriptAction extends AbstractExtendedAction { + public SubscriptAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.toggleSubscript(); + fireOnEdit(); + } + } + + public class SuperscriptAction extends AbstractExtendedAction { + public SuperscriptAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.toggleSuperscript(); + fireOnEdit(); + } + } + + public class UlAction extends AbstractExtendedAction { + public UlAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.insertUnorderedList(); + fireOnEdit(); + } + } + + public class UnderlineAction extends AbstractExtendedAction { + public UnderlineAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.toggleUnderline(); + fireOnEdit(); + } + } + + public class UndoAction extends AbstractExtendedAction { + public UndoAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + view.undo(); + fireOnEdit(); + } + } + + private static final String FONT_NAMES[] = { "Times New Roman", "Arial", "Courier New", "Georgia", "Trebuchet", + "Verdana" }; + private static final String FONT_SIZE_NAMES[] = { "Extra small", "Very small (normal)", "Small", "Medium", "Large", + "Very large", "Extra large" }; + private static final RichTextArea.FontSize[] FONT_SIZES = new RichTextArea.FontSize[] { + RichTextArea.FontSize.XX_SMALL, RichTextArea.FontSize.X_SMALL, RichTextArea.FontSize.SMALL, + RichTextArea.FontSize.MEDIUM, RichTextArea.FontSize.LARGE, RichTextArea.FontSize.X_LARGE, + RichTextArea.FontSize.XX_LARGE }; + private static final String FONT_GROUP = "fontgroup"; + private static final String FONT_SIZEGROUP = "fontsizegroup"; + + private RTEditorView view; + private boolean extended; + private final I18nTranslationService i18n; + private final Session session; + private final RTEImgResources imgResources; + private final Event0 onEdit; + private final DeferredCommandWrapper deferred; + private final Provider<ColorWebSafePalette> paletteProvider; + private final Provider<InsertLinkDialog> insLinkDialogPv; + private final Provider<EditHtmlDialog> editHtmlDialogPv; + private final Provider<InsertImageDialog> insImgDialogProv; + private final Provider<InsertTableDialog> insTableDialogPv; + private final Provider<InsertSpecialCharDialog> insCharDialogProv; + private final Provider<InsertMediaDialog> insMediaDialogPv; + private Listener<String> insTableListener; + private Listener<LinkInfo> insLinkListener; + private Listener<ImageInfo> insImgListener; + private Listener<String> insMediaListener; + private Listener<String> updHtmlListener; + protected Listener<String> insCharListener; + protected ColorWebSafePalette palette; + private PushButtonDescriptor bold; + private PushButtonDescriptor italic; + private PushButtonDescriptor underline; + private PushButtonDescriptor strikethrough; + private final GuiAddCondition basicAddCond; + private final GuiAddCondition extendedAddCond; + private final InputMap inputMap; + private MenuDescriptor editMenu; + private MenuDescriptor insertMenu; + private MenuDescriptor formatMenu; + private MenuDescriptor linkCtxMenu; + private GuiActionDescCollection actions; + private MenuDescriptor fontMenu; + private MenuDescriptor fontSizeMenu; + private MenuDescriptor fileMenu; + private final List<MenuDescriptor> menus; + protected boolean attached; + private final Map<String, MenuCheckItemDescriptor> fontActions; + private MenuCheckItemDescriptor currentFontItem; + + public RTEditorPresenter(final I18nTranslationService i18n, final Session session, + final RTEImgResources imgResources, final Provider<InsertLinkDialog> insLinkDialog, + final Provider<ColorWebSafePalette> palette, final Provider<EditHtmlDialog> editHtmlDialog, + final Provider<InsertImageDialog> insertImageDialog, final Provider<InsertMediaDialog> insertMediaDialog, + final Provider<InsertTableDialog> insertTableDialog, final Provider<InsertSpecialCharDialog> insCharDialog, + final DeferredCommandWrapper deferred) { + this.i18n = i18n; + this.session = session; + this.insLinkDialogPv = insLinkDialog; + this.paletteProvider = palette; + this.editHtmlDialogPv = editHtmlDialog; + this.insImgDialogProv = insertImageDialog; + this.insMediaDialogPv = insertMediaDialog; + this.insTableDialogPv = insertTableDialog; + this.insCharDialogProv = insCharDialog; + this.deferred = deferred; + inputMap = new InputMap(); + menus = new ArrayList<MenuDescriptor>(); + + this.imgResources = imgResources; + this.onEdit = new Event0("onRTEEdit"); + extendedAddCond = new GuiAddCondition() { + public boolean mustBeAdded() { + return isAndCanBeExtended(); + } + }; + basicAddCond = new GuiAddCondition() { + public boolean mustBeAdded() { + return view.canBeBasic(); + } + }; + attached = false; + fontActions = new HashMap<String, MenuCheckItemDescriptor>(); + } + + public void addAction(final GuiActionDescrip descriptor) { + actions.add(descriptor); + checkForMenus(descriptor); + } + + public void addActionCollection(final GuiActionDescCollection descriptors) { + actions.addAll(descriptors); + for (final GuiActionDescrip descriptor : descriptors) { + checkForMenus(descriptor); + } + } + + public void addActions(final GuiActionDescrip... descriptors) { + actions.add(descriptors); + for (final GuiActionDescrip descriptor : descriptors) { + checkForMenus(descriptor); + } + } + + public void addOnEditListener(final Listener0 listener) { + onEdit.add(listener); + } + + public void adjustSize(final int height) { + view.adjustSize(height); + } + + public void attach() { + if (!attached) { + attached = true; + view.addActions(actions); + view.setInputMap(inputMap); + } + } + + public void detach() { + } + + public void fireOnEdit() { + onEdit.fire(); + } + + public GuiAddCondition getBasicAddCondition() { + return basicAddCond; + } + + public MenuDescriptor getEditMenu() { + return editMenu; + } + + public View getEditorArea() { + return view; + } + + public GuiAddCondition getExtendedAddCondition() { + return extendedAddCond; + } + + public MenuDescriptor getFileMenu() { + return fileMenu; + } + + public MenuDescriptor getFormatMenu() { + return formatMenu; + } + + public String getHtml() { + return view.getHTML(); + } + + public MenuDescriptor getInsertMenu() { + return insertMenu; + } + + public MenuDescriptor getLinkCtxMenu() { + return linkCtxMenu; + } + + public View getSndBar() { + return view.getSndBar(); + } + + public String getText() { + return view.getText(); + } + + public View getTopBar() { + return view.getTopBar(); + } + + public void init(final RTEditorView view) { + this.view = view; + createMainMenus(); + createBasicActions(); + } + + public void onEditorFocus() { + hideMenus(); + } + + public void onLostFocus() { + // Nothing for the moment + } + + public void reset() { + hideMenus(); + hideLinkCtxMenu(); + } + + public void setActionShortcut(final KeyStroke key, final AbstractAction action) { + inputMap.put(key, action); + action.putValue(Action.ACCELERATOR_KEY, key); + } + + public void setActionShortcut(final KeyStroke key, final AbstractAction mainAction, final AbstractAction... actions) { + setActionShortcut(key, mainAction); + for (final AbstractAction action : actions) { + action.putValue(Action.ACCELERATOR_KEY, key); + } + } + + public void setExtended(final boolean newValue) { + this.extended = newValue; + } + + public void setFocus(final boolean focus) { + view.setFocus(focus); + } + + public void setHtml(final String html) { + view.setHTML(html); + view.focus(); + } + + public void setLocation(final String location, final GuiActionDescrip[] descripts) { + for (final GuiActionDescrip descript : descripts) { + descript.setLocation(location); + } + } + + public void setText(final String text) { + view.setText(text); + view.focus(); + } + + public void updateLinkInfo() { + deferred.addCommand(new Listener0() { + public void onEvent() { + if (isAndCanBeExtended() && view.isLink()) { + view.showLinkCtxMenu(); + } else { + hideLinkCtxMenu(); + } + } + }); + } + + public void updateStatus() { + if (view.canBeBasic()) { + bold.setPushed(view.isBold()); + italic.setPushed(view.isItalic()); + underline.setPushed(view.isUnderlined()); + deferred.addCommand(new Listener0() { + public void onEvent() { + updateFont(); + // Log.warn(view.getFontSize()); + } + }); + } + if (isAndCanBeExtended()) { + strikethrough.setPushed(view.isStrikethrough()); + } + } + + private void checkForMenus(final GuiActionDescrip descriptor) { + if (descriptor instanceof MenuDescriptor) { + menus.add((MenuDescriptor) descriptor); + } + } + + private void createBasicActions() { + + final MenuSeparatorDescriptor editMenuSep = new MenuSeparatorDescriptor(editMenu); + final MenuSeparatorDescriptor insertMenuSep = new MenuSeparatorDescriptor(insertMenu); + final MenuSeparatorDescriptor formatMenuSep = new MenuSeparatorDescriptor(formatMenu); + insertMenuSep.setAddCondition(extendedAddCond); + + final ToolbarSeparatorDescriptor sndbarSep = new ToolbarSeparatorDescriptor(Type.separator, getSndBar()); + final ToolbarSeparatorDescriptor sndbarSepExt = new ToolbarSeparatorDescriptor(Type.separator, getSndBar()); + sndbarSepExt.setAddCondition(extendedAddCond); + + final SelectAllAction selectAllAction = new SelectAllAction(i18n.t("Select all"), + AbstractExtendedAction.NO_TEXT, imgResources.selectall()); + final MenuItemDescriptor select = new MenuItemDescriptor(editMenu, selectAllAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('A'), Keyboard.MODIFIER_CTRL), selectAllAction); + + final BoldAction boldAction = new BoldAction(NO_TEXT, i18n.t("Bold"), imgResources.bold()); + bold = new PushButtonDescriptor(boldAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('B'), Keyboard.MODIFIER_CTRL), boldAction); + + final ItalicAction italicAction = new ItalicAction(NO_TEXT, i18n.t("Italic"), imgResources.italic()); + italic = new PushButtonDescriptor(italicAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('I'), Keyboard.MODIFIER_CTRL), italicAction); + + final UnderlineAction underlineAction = new UnderlineAction(NO_TEXT, i18n.t("Underline"), + imgResources.underline()); + underline = new PushButtonDescriptor(underlineAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('U'), Keyboard.MODIFIER_CTRL), underlineAction); + + final SubscriptAction subscriptAction = new SubscriptAction(i18n.t("Subscript"), NO_TEXT, + imgResources.subscript()); + final MenuItemDescriptor subscript = new MenuItemDescriptor(formatMenu, subscriptAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf(','), Keyboard.MODIFIER_CTRL), subscriptAction); + + final SuperscriptAction superscriptAction = new SuperscriptAction(i18n.t("Superscript"), NO_TEXT, + imgResources.superscript()); + final MenuItemDescriptor superscript = new MenuItemDescriptor(formatMenu, superscriptAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('.'), Keyboard.MODIFIER_CTRL), superscriptAction); + + final JustifyLeftAction jfyLeftAction = new JustifyLeftAction(NO_TEXT, i18n.t("Left Justify"), + imgResources.alignleft()); + final ButtonDescriptor justifyLeft = new ButtonDescriptor(jfyLeftAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('L'), Keyboard.MODIFIER_CTRL), jfyLeftAction); + + final JustifyCentreAction jfyCentreAction = new JustifyCentreAction(NO_TEXT, i18n.t("Centre Justify"), + imgResources.centerpara()); + final ButtonDescriptor justifyCentre = new ButtonDescriptor(jfyCentreAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('E'), Keyboard.MODIFIER_CTRL), jfyCentreAction); + + final JustifyRightAction jfyRightAction = new JustifyRightAction(NO_TEXT, i18n.t("Right Justify"), + imgResources.alignright()); + final ButtonDescriptor justifyRight = new ButtonDescriptor(jfyRightAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('R'), Keyboard.MODIFIER_CTRL), jfyRightAction); + + final UndoAction undoAction = new UndoAction(i18n.t("Undo"), NO_TEXT, imgResources.undo()); + final UndoAction undoActionBtn = new UndoAction(NO_TEXT, i18n.t("Undo"), imgResources.undo()); + final MenuItemDescriptor undo = new MenuItemDescriptor(editMenu, undoAction); + final ButtonDescriptor undoBtn = new ButtonDescriptor(undoActionBtn); + undoBtn.setPosition(0); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('Z'), Keyboard.MODIFIER_CTRL), undoAction); + + final RedoAction redoAction = new RedoAction(i18n.t("Redo"), NO_TEXT, imgResources.redo()); + final RedoAction redoActionBtn = new RedoAction(NO_TEXT, i18n.t("Redo"), imgResources.redo()); + final MenuItemDescriptor redo = new MenuItemDescriptor(editMenu, redoAction); + final ButtonDescriptor redoBtn = new ButtonDescriptor(redoActionBtn); + redoBtn.setPosition(1); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('Y'), Keyboard.MODIFIER_CTRL), redoAction); + + final CopyAction copyAction = new CopyAction(i18n.t("Copy"), NO_TEXT, imgResources.copy()); + final MenuItemDescriptor copy = new MenuItemDescriptor(editMenu, copyAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('C'), Keyboard.MODIFIER_CTRL), copyAction); + + final CutAction cutAction = new CutAction(i18n.t("Cut"), NO_TEXT, imgResources.cut()); + final MenuItemDescriptor cut = new MenuItemDescriptor(editMenu, cutAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('X'), Keyboard.MODIFIER_CTRL), cutAction); + + final PasteAction pasteAction = new PasteAction(i18n.t("Paste"), NO_TEXT, imgResources.paste()); + final MenuItemDescriptor paste = new MenuItemDescriptor(editMenu, pasteAction); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('V'), Keyboard.MODIFIER_CTRL), pasteAction); + + final EditHtmlAction editHtmlAction = new EditHtmlAction(i18n.t("Edit HTML"), NO_TEXT, imgResources.edithtml()); + final MenuItemDescriptor editHtml = new MenuItemDescriptor(editMenu, editHtmlAction); + editHtml.setAddCondition(extendedAddCond); + + final CommentAction commentAction = new CommentAction(i18n.t("Comment"), NO_TEXT, NO_ICON); + final MenuItemDescriptor comment = new MenuItemDescriptor(insertMenu, commentAction); + comment.setAddCondition(extendedAddCond); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('M'), Keyboard.MODIFIER_CTRL), commentAction); + + final HrAction hlineAction = new HrAction(i18n.t("Horizontal line"), NO_TEXT, imgResources.hfixedline()); + final HrAction hlineBtnAction = new HrAction(NO_TEXT, i18n.t("Horizontal line"), imgResources.hfixedline()); + final MenuItemDescriptor hline = new MenuItemDescriptor(insertMenu, hlineAction); + final ButtonDescriptor hlineBtn = new ButtonDescriptor(hlineBtnAction); + hline.setAddCondition(extendedAddCond); + hlineBtn.setAddCondition(extendedAddCond); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf(' '), Keyboard.MODIFIER_CTRL + + Keyboard.MODIFIER_SHIFT), hlineAction); + + final BlockquoteAction blockquoteAction = new BlockquoteAction(i18n.t("Block Quotation"), NO_TEXT, NO_ICON); + final MenuItemDescriptor blockquote = new MenuItemDescriptor(formatMenu, blockquoteAction); + blockquote.setAddCondition(extendedAddCond); + + final StrikethroughAction strikeAction = new StrikethroughAction(NO_TEXT, i18n.t("Strikethrough"), + imgResources.strikeout()); + strikethrough = new PushButtonDescriptor(strikeAction); + strikethrough.setAddCondition(extendedAddCond); + + final DecreaseIndentAction decreIndentAction = new DecreaseIndentAction(NO_TEXT, i18n.t("Decrease Indent"), + imgResources.decrementindent()); + final ButtonDescriptor decreaseIndent = new ButtonDescriptor(decreIndentAction); + decreaseIndent.setAddCondition(extendedAddCond); + + final IncreaseIndentAction increIndentAction = new IncreaseIndentAction(NO_TEXT, i18n.t("Increase Indent"), + imgResources.incrementindent()); + final ButtonDescriptor increaseIndent = new ButtonDescriptor(increIndentAction); + increaseIndent.setAddCondition(extendedAddCond); + + final OlAction olistAction = new OlAction(NO_TEXT, i18n.t("Numbered List"), imgResources.defaultnumbering()); + final ButtonDescriptor olist = new ButtonDescriptor(olistAction); + olist.setAddCondition(extendedAddCond); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('7'), Keyboard.MODIFIER_CTRL), olistAction); + + final UlAction ulistAction = new UlAction(NO_TEXT, i18n.t("Bullet List"), imgResources.defaultbullet()); + final ButtonDescriptor ulist = new ButtonDescriptor(ulistAction); + ulist.setAddCondition(extendedAddCond); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('8'), Keyboard.MODIFIER_CTRL), ulistAction); + + final ImgAction imgAction = new ImgAction(i18n.t("Image..."), NO_TEXT, imgResources.images()); + final ImgAction imgBtnAction = new ImgAction(NO_TEXT, i18n.t("Insert Image"), imgResources.images()); + final MenuItemDescriptor img = new MenuItemDescriptor(insertMenu, imgAction); + final ButtonDescriptor imgBtn = new ButtonDescriptor(imgBtnAction); + img.setAddCondition(extendedAddCond); + imgBtn.setAddCondition(extendedAddCond); + + final InsertMediaAction insertMediaAction = new InsertMediaAction(i18n.t("Audio/Video..."), NO_TEXT, + imgResources.film()); + final MenuItemDescriptor insertMedia = new MenuItemDescriptor(insertMenu, insertMediaAction); + insertMedia.setAddCondition(extendedAddCond); + + final CreateOrEditLinkAction editLinkAction = new CreateOrEditLinkAction(i18n.t("Link..."), NO_TEXT, + imgResources.link()); + final CreateOrEditLinkAction editLinkBtnAction = new CreateOrEditLinkAction(NO_TEXT, + i18n.t("Create or Edit Link"), imgResources.link()); + final CreateOrEditLinkAction editLinkCtxAction = new CreateOrEditLinkAction(i18n.t("Change"), NO_TEXT, + imgResources.link()); + final MenuItemDescriptor editLink = new MenuItemDescriptor(insertMenu, editLinkAction); + final MenuItemDescriptor editLinkCtx = new MenuItemDescriptor(linkCtxMenu, editLinkCtxAction); + final ButtonDescriptor editLinkBtn = new ButtonDescriptor(editLinkBtnAction); + editLink.setAddCondition(extendedAddCond); + editLinkBtn.setAddCondition(extendedAddCond); + editLinkCtx.setAddCondition(extendedAddCond); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('K'), Keyboard.MODIFIER_CTRL), editLinkAction, + editLinkBtnAction); + + final KeyStroke key_SK = KeyStroke.getKeyStroke(Character.valueOf('K'), Keyboard.MODIFIER_CTRL + + Keyboard.MODIFIER_SHIFT); + final RemoveLinkAction delLinkBtnAction = new RemoveLinkAction(NO_TEXT, i18n.t("Remove Link"), + imgResources.linkbreak()); + final RemoveLinkAction delLinkCtxAction = new RemoveLinkAction(i18n.t("Remove"), NO_TEXT, + imgResources.linkbreak()); + final MenuItemDescriptor removeLinkCtx = new MenuItemDescriptor(linkCtxMenu, delLinkCtxAction); + final ButtonDescriptor removeLinkBtn = new ButtonDescriptor(delLinkBtnAction); + removeLinkBtn.setAddCondition(extendedAddCond); + removeLinkCtx.setAddCondition(extendedAddCond); + setActionShortcut(key_SK, delLinkBtnAction); + + final RemoveFormatAction remFormatAction = new RemoveFormatAction(i18n.t("Clear Formatting..."), NO_TEXT, + imgResources.removeFormat()); + final RemoveFormatAction remFormatBtnAc = new RemoveFormatAction(NO_TEXT, i18n.t("Clear Formatting..."), + imgResources.removeFormat()); + final MenuItemDescriptor removeFormat = new MenuItemDescriptor(formatMenu, remFormatAction); + final ButtonDescriptor removeFormatBtn = new ButtonDescriptor(remFormatBtnAc); + removeFormat.setAddCondition(extendedAddCond); + removeFormatBtn.setAddCondition(extendedAddCond); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf(' '), Keyboard.MODIFIER_CTRL), remFormatAction, + remFormatBtnAc); + + final InsertSpecialCharAction insCharAction = new InsertSpecialCharAction(i18n.t("Special characters..."), + NO_TEXT, imgResources.specialchars()); + final MenuItemDescriptor insertSpecialChar = new MenuItemDescriptor(insertMenu, insCharAction); + insertSpecialChar.setAddCondition(extendedAddCond); + + final InsertTableAction insTableAction = new InsertTableAction(i18n.t("Table..."), NO_TEXT, + imgResources.inserttable()); + final InsertTableAction insTableBtnAction = new InsertTableAction(NO_TEXT, i18n.t("Insert Table"), + imgResources.inserttable()); + final MenuItemDescriptor insertTable = new MenuItemDescriptor(insertMenu, insTableAction); + final ButtonDescriptor insertTableBtn = new ButtonDescriptor(insTableBtnAction); + insertTable.setAddCondition(extendedAddCond); + insertTableBtn.setAddCondition(extendedAddCond); + + final FontColorAction fontColorAction = new FontColorAction(NO_TEXT, i18n.t("Text Colour"), + imgResources.fontcolor()); + final ButtonDescriptor fontColor = new ButtonDescriptor(fontColorAction); + fontColor.setAddCondition(basicAddCond); + + final BackgroundColorAction backColorAction = new BackgroundColorAction(NO_TEXT, + i18n.t("Text Background Colour"), imgResources.backcolor()); + final ButtonDescriptor backgroundColor = new ButtonDescriptor(backColorAction); + backgroundColor.setAddCondition(basicAddCond); + + final DevInfoAction devInfoAction = new DevInfoAction(i18n.t("Developers info"), NO_TEXT, + imgResources.specialchars()); + final MenuItemDescriptor devInfo = new MenuItemDescriptor(formatMenu, devInfoAction); + devInfo.setAddCondition(extendedAddCond); + setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('I'), Keyboard.MODIFIER_ALT), devInfoAction); + + actions = new GuiActionDescCollection(); + actions.add(fileMenu, editMenu, formatMenu, insertMenu, undo, redo, editMenuSep, copy, cut, paste, editMenuSep, + select, editMenuSep, editHtml, editLink, img, insertTable, insertMedia, insertMenuSep, + insertSpecialChar, comment, hline, removeFormat, formatMenuSep, insertMenuSep, undoBtn, redoBtn, + sndbarSep, bold, italic, underline, strikethrough, sndbarSep, justifyLeft, justifyCentre, justifyRight, + decreaseIndent, increaseIndent, olist, ulist, sndbarSep, removeFormatBtn, sndbarSepExt, hlineBtn, + imgBtn, editLinkBtn, removeLinkBtn, insertTableBtn, sndbarSepExt, subscript, superscript, blockquote, + fontColor, backgroundColor, fontSizeMenu, fontMenu, editLinkCtx, removeLinkCtx); + // actions.add(devInfo); + + setLocation(TOPBAR, new GuiActionDescrip[] { fileMenu, editMenu, insertMenu, formatMenu, editMenuSep, + subscript, superscript, undo, redo, editMenuSep, copy, cut, paste, editMenuSep, select, editMenuSep, + editHtml, comment, hline, blockquote, img, insertTable, insertMedia, editLink, removeFormat, + formatMenuSep, insertMenuSep, insertSpecialChar, insertTable, devInfo }); + setLocation(SNDBAR, new GuiActionDescrip[] { undoBtn, redoBtn, sndbarSep, sndbarSepExt, bold, italic, + underline, strikethrough, justifyLeft, justifyCentre, justifyRight, undoBtn, redoBtn, hlineBtn, + decreaseIndent, increaseIndent, olist, ulist, hlineBtn, imgBtn, editLinkBtn, removeLinkBtn, + removeFormatBtn, insertTableBtn, fontColor, backgroundColor, fontMenu, fontSizeMenu }); + setLocation(LINKCTX, new GuiActionDescrip[] { removeLinkCtx, editLinkCtx }); + + for (final String fontName : FONT_NAMES) { + createFontAction(fontMenu, fontName); + } + + for (int fontSize = 0; fontSize < FONT_SIZE_NAMES.length; fontSize++) { + createFontSizeAction(fontSizeMenu, fontSize); + } + } + + private void createFontAction(final MenuDescriptor fontMenu, final String fontName) { + final FontAction fontAction = new FontAction(fontName, NO_TEXT, NO_ICON); + final MenuRadioItemDescriptor font = new MenuRadioItemDescriptor(fontMenu, fontAction, FONT_GROUP); + font.setAddCondition(basicAddCond); + font.setLocation(SNDBAR); + fontActions.put(fontName.toLowerCase(), font); + actions.add(font); + } + + private void createFontSizeAction(final MenuDescriptor fontSizeMenu, final int fontSize) { + final String fontSizeName = i18n.t(FONT_SIZE_NAMES[fontSize]); + final FontSizeAction fontSizeAction = new FontSizeAction(fontSizeName, fontSize, NO_TEXT, NO_ICON); + final MenuRadioItemDescriptor fontSizeItem = new MenuRadioItemDescriptor(fontSizeMenu, fontSizeAction, + FONT_SIZEGROUP); + fontSizeItem.setAddCondition(basicAddCond); + // setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf(((char) + // (48 + fontSize))), Keyboard.MODIFIER_CTRL), + // fontSizeAction); + fontSizeItem.setLocation(SNDBAR); + actions.add(fontSizeItem); + } + + private void createMainMenus() { + menus.add(fileMenu = new MenuDescriptor(i18n.t("File"))); + menus.add(editMenu = new MenuDescriptor(i18n.t("Edit"))); + menus.add(insertMenu = new MenuDescriptor(i18n.t("Insert"))); + menus.add(formatMenu = new MenuDescriptor(i18n.t("Format"))); + menus.add(linkCtxMenu = new MenuDescriptor(i18n.t("Change Link"))); + menus.add(fontMenu = new MenuDescriptor(NO_TEXT, i18n.t("Font"), imgResources.charfontname())); + menus.add(fontSizeMenu = new MenuDescriptor(NO_TEXT, i18n.t("Font size"), imgResources.fontheight())); + insertMenu.setAddCondition(extendedAddCond); + } + + private void createPalette() { + if (palette == null) { + palette = paletteProvider.get(); + } + } + + private void hideLinkCtxMenu() { + if (view.isCtxMenuVisible()) { + view.hideLinkCtxMenu(); + } + } + + private void hideMenus() { + for (final MenuDescriptor menu : menus) { + menu.hide(); + } + if (palette != null) { + palette.hide(); + } + } + + private boolean isAndCanBeExtended() { + return extended && view.canBeExtended(); + } + + private void updateFont() { + final String currentFont = view.getFont(); + final MenuCheckItemDescriptor item = fontActions.get(currentFont); + if (currentFontItem != null && item != currentFontItem) { + currentFontItem.setChecked(false); + } + if (item != null) { + item.setChecked(true); + currentFontItem = item; + fontMenu.setText((String) item.getValue(FontAction.FONT_NAME)); + } else { + fontMenu.setText(" "); + } + } +} Deleted: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenterNew.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenterNew.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenterNew.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -1,1196 +0,0 @@ -package org.ourproject.kune.platf.client.ui.rte.basic; - -import static org.ourproject.kune.platf.client.actions.AbstractExtendedAction.NO_ICON; -import static org.ourproject.kune.platf.client.actions.AbstractExtendedAction.NO_TEXT; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.ourproject.kune.platf.client.View; -import org.ourproject.kune.platf.client.actions.AbstractAction; -import org.ourproject.kune.platf.client.actions.AbstractExtendedAction; -import org.ourproject.kune.platf.client.actions.Action; -import org.ourproject.kune.platf.client.actions.ActionEvent; -import org.ourproject.kune.platf.client.actions.InputMap; -import org.ourproject.kune.platf.client.actions.KeyStroke; -import org.ourproject.kune.platf.client.actions.ui.ButtonDescriptor; -import org.ourproject.kune.platf.client.actions.ui.GuiActionDescCollection; -import org.ourproject.kune.platf.client.actions.ui.GuiActionDescrip; -import org.ourproject.kune.platf.client.actions.ui.GuiAddCondition; -import org.ourproject.kune.platf.client.actions.ui.MenuCheckItemDescriptor; -import org.ourproject.kune.platf.client.actions.ui.MenuDescriptor; -import org.ourproject.kune.platf.client.actions.ui.MenuItemDescriptor; -import org.ourproject.kune.platf.client.actions.ui.MenuRadioItemDescriptor; -import org.ourproject.kune.platf.client.actions.ui.MenuSeparatorDescriptor; -import org.ourproject.kune.platf.client.actions.ui.PushButtonDescriptor; -import org.ourproject.kune.platf.client.actions.ui.ToolbarSeparatorDescriptor; -import org.ourproject.kune.platf.client.actions.ui.ToolbarSeparatorDescriptor.Type; -import org.ourproject.kune.platf.client.i18n.I18nTranslationService; -import org.ourproject.kune.platf.client.shortcuts.Keyboard; -import org.ourproject.kune.platf.client.state.Session; -import org.ourproject.kune.platf.client.ui.noti.NotifyUser; -import org.ourproject.kune.platf.client.ui.palette.ColorWebSafePalette; -import org.ourproject.kune.platf.client.ui.rte.RichTextArea; -import org.ourproject.kune.platf.client.ui.rte.edithtml.EditHtmlDialog; -import org.ourproject.kune.platf.client.ui.rte.img.RTEImgResources; -import org.ourproject.kune.platf.client.ui.rte.insertimg.ImageInfo; -import org.ourproject.kune.platf.client.ui.rte.insertimg.InsertImageDialog; -import org.ourproject.kune.platf.client.ui.rte.insertlink.InsertLinkDialog; -import org.ourproject.kune.platf.client.ui.rte.insertlink.LinkInfo; -import org.ourproject.kune.platf.client.ui.rte.insertmedia.InsertMediaDialog; -import org.ourproject.kune.platf.client.ui.rte.insertspecialchar.InsertSpecialCharDialog; -import org.ourproject.kune.platf.client.ui.rte.inserttable.InsertTableDialog; -import org.ourproject.kune.platf.client.utils.DeferredCommandWrapper; - -import com.allen_sauer.gwt.log.client.Log; -import com.calclab.suco.client.events.Event0; -import com.calclab.suco.client.events.Listener; -import com.calclab.suco.client.events.Listener0; -import com.calclab.suco.client.ioc.Provider; -import com.google.gwt.libideas.resources.client.ImageResource; -import com.google.gwt.user.client.Event; - -public class RTEditorPresenterNew implements RTEditorNew { - - public class BackgroundColorAction extends AbstractExtendedAction { - - public BackgroundColorAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - createPalette(); - final Event event = actionEvent.getEvent(); - palette.show(event.getClientX(), event.getClientY(), new Listener<String>() { - public void onEvent(final String color) { - palette.hide(); - view.setBackColor(color); - fireOnEdit(); - } - }); - } - } - - public class BlockquoteAction extends AbstractExtendedAction { - public BlockquoteAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.focus(); - view.insertBlockquote(); - fireOnEdit(); - } - } - - public class BoldAction extends AbstractExtendedAction { - public BoldAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.toggleBold(); - fireOnEdit(); - } - } - - public class CommentAction extends AbstractExtendedAction { - public CommentAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - deferred.addCommand(new Listener0() { - public void onEvent() { - view.focus(); - final String author = session.isLogged() ? session.getCurrentUser().getShortName() - : i18n.t("anonymous user"); - if (view.isAnythingSelected()) { - NotifyUser.askConfirmation(i18n.t("Insert a comment"), - i18n.t("Include the selected text in the comment?"), new Listener0() { - public void onEvent() { - // include selection in - // comment - view.insertCommentUsingSelection(author); - } - }, new Listener0() { - public void onEvent() { - // not include selection in - // comment; - view.insertCommentNotUsingSelection(author); - } - }); - } else { - // Nothing selected > create comment in - // insertion point - view.insertComment(author); - } - } - }); - } - - @Override - public boolean isEnabled() { - return session.isLogged(); - } - } - - public class CopyAction extends AbstractExtendedAction { - public CopyAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.copy(); - } - } - - public class CreateOrEditLinkAction extends AbstractExtendedAction { - public CreateOrEditLinkAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - deferred.addCommand(new Listener0() { - private InsertLinkDialog insLinkDialog; - - public void onEvent() { - if (insLinkListener == null) { - insLinkListener = new Listener<LinkInfo>() { - public void onEvent(final LinkInfo linkInfo) { - final String link = linkInfo.toString(); - Log.debug("Link: " + link); - view.focus(); - view.insertHtml(link); - fireOnEdit(); - } - }; - } - final LinkInfo linkInfo = view.getLinkInfoIfHref(); - - if (insLinkDialog == null) { - insLinkDialog = insLinkDialogPv.get(); - } - insLinkDialog.setLinkInfo(linkInfo); - insLinkDialog.setOnCreateLink(insLinkListener); - insLinkDialog.show(); - hideLinkCtxMenu(); - final String href = linkInfo.getHref(); - if (href.length() > 0) { - if (href.startsWith("mailto")) { - insLinkDialog.activateTab(2); - } else { - insLinkDialog.activateTab(1); - } - } - } - }); - } - } - - public class CutAction extends AbstractExtendedAction { - public CutAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.cut(); - fireOnEdit(); - } - } - - public class DecreaseIndentAction extends AbstractExtendedAction { - public DecreaseIndentAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.leftIndent(); - fireOnEdit(); - } - } - - public class DevInfoAction extends AbstractExtendedAction { - public DevInfoAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - deferred.addCommand(new Listener0() { - public void onEvent() { - view.getRangeInfo(); - } - }); - } - } - - public class EditHtmlAction extends AbstractExtendedAction { - private EditHtmlDialog editHtmlDialog; - - public EditHtmlAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - if (updHtmlListener == null) { - updHtmlListener = new Listener<String>() { - public void onEvent(final String html) { - view.setHTML(html); - fireOnEdit(); - } - }; - } - if (editHtmlDialog == null) { - editHtmlDialog = editHtmlDialogPv.get(); - } - editHtmlDialog.setUpdateListener(updHtmlListener); - editHtmlDialog.show(); - hideLinkCtxMenu(); - editHtmlDialog.setHtml(view.getHTML()); - } - } - - public class FontAction extends AbstractExtendedAction { - public static final String FONT_NAME = "fontname"; - - public FontAction(final String fontName, final String tooltip, final ImageResource icon) { - super("<span style=\"font-family: " + fontName + "\">" + fontName + "</span>", tooltip, icon); - super.putValue(FONT_NAME, fontName); - } - - public void actionPerformed(final ActionEvent actionEvent) { - final String fontName = getFontName(); - view.setFontName(fontName); - fontMenu.setText(fontName); - fireOnEdit(); - } - - private String getFontName() { - return (String) super.getValue(FONT_NAME); - } - } - - public class FontColorAction extends AbstractExtendedAction { - public FontColorAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - createPalette(); - final Event event = actionEvent.getEvent(); - palette.show(event.getClientX(), event.getClientY(), new Listener<String>() { - public void onEvent(final String color) { - palette.hide(); - view.setForeColor(color); - fireOnEdit(); - } - }); - hideLinkCtxMenu(); - } - } - - public class FontSizeAction extends AbstractExtendedAction { - private final int fontSize; - - public FontSizeAction(final String fontSizeName, final int fontSize, final String tooltip, - final ImageResource icon) { - super("<font size=\"" + (fontSize + 1) + "\">" + fontSizeName + "</font>", tooltip, icon); - this.fontSize = fontSize; - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.setFontSize(FONT_SIZES[fontSize]); - fireOnEdit(); - // fontSizeMenu.setText(fontSizeName); - } - } - - public class HrAction extends AbstractExtendedAction { - public HrAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.focus(); - view.insertHorizontalRule(); - fireOnEdit(); - } - } - - public class ImgAction extends AbstractExtendedAction { - public ImgAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - deferred.addCommand(new Listener0() { - private InsertImageDialog insImgDialog; - - public void onEvent() { - if (insImgListener == null) { - insImgListener = new Listener<ImageInfo>() { - public void onEvent(final ImageInfo imageInfo) { - Log.debug("Image: " + imageInfo); - view.focus(); - view.insertHtml(imageInfo.toString()); - fireOnEdit(); - } - }; - } - if (insImgDialog == null) { - insImgDialog = insImgDialogProv.get(); - } - insImgDialog.reset(); - insImgDialog.setOnCreateImage(insImgListener); - insImgDialog.show(); - hideLinkCtxMenu(); - } - }); - } - } - - public class IncreaseIndentAction extends AbstractExtendedAction { - public IncreaseIndentAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.rightIndent(); - fireOnEdit(); - } - } - - public class InsertMediaAction extends AbstractExtendedAction { - public InsertMediaAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - deferred.addCommand(new Listener0() { - private InsertMediaDialog insMediaDialog; - - public void onEvent() { - if (insMediaListener == null) { - insMediaListener = new Listener<String>() { - public void onEvent(final String html) { - Log.debug("Media: " + html); - view.focus(); - view.insertHtml(html); - fireOnEdit(); - } - }; - } - if (insMediaDialog == null) { - insMediaDialog = insMediaDialogPv.get(); - } - insMediaDialog.setOnCreate(insMediaListener); - insMediaDialog.show(); - hideLinkCtxMenu(); - } - }); - } - } - - public class InsertSpecialCharAction extends AbstractExtendedAction { - private InsertSpecialCharDialog insCharDialog; - - public InsertSpecialCharAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - NotifyUser.showProgressLoading(); - if (insCharListener == null) { - insCharListener = new Listener<String>() { - public void onEvent(final String character) { - view.insertHtml(character); - } - }; - } - if (insCharDialog == null) { - insCharDialog = insCharDialogProv.get(); - } - insCharDialog.setOnInsertSpecialChar(insCharListener); - insCharDialog.show(); - hideLinkCtxMenu(); - NotifyUser.hideProgress(); - } - } - - public class InsertTableAction extends AbstractExtendedAction { - private InsertTableDialog insTableDialog; - - public InsertTableAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - if (insTableListener == null) { - insTableListener = new Listener<String>() { - public void onEvent(final String table) { - view.insertHtml(table); - fireOnEdit(); - } - }; - } - if (insTableDialog == null) { - insTableDialog = insTableDialogPv.get(); - } - insTableDialog.setOnInsertTable(insTableListener); - insTableDialog.show(); - } - } - - public class ItalicAction extends AbstractExtendedAction { - public ItalicAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.toggleItalic(); - fireOnEdit(); - } - } - - public class JustifyCentreAction extends AbstractExtendedAction { - public JustifyCentreAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.justifyCenter(); - fireOnEdit(); - } - } - - public class JustifyLeftAction extends AbstractExtendedAction { - public JustifyLeftAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.justifyLeft(); - fireOnEdit(); - } - } - - public class JustifyRightAction extends AbstractExtendedAction { - public JustifyRightAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.justifyRight(); - fireOnEdit(); - } - } - - public class OlAction extends AbstractExtendedAction { - public OlAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.insertOrderedList(); - fireOnEdit(); - } - } - - public class PasteAction extends AbstractExtendedAction { - public PasteAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.paste(); - fireOnEdit(); - } - } - - public class RedoAction extends AbstractExtendedAction { - public RedoAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.redo(); - fireOnEdit(); - } - } - - public class RemoveFormatAction extends AbstractExtendedAction { - public RemoveFormatAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.removeFormat(); - fireOnEdit(); - } - } - - public class RemoveLinkAction extends AbstractExtendedAction { - public RemoveLinkAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - deferred.addCommand(new Listener0() { - public void onEvent() { - view.unlink(); - hideLinkCtxMenu(); - fireOnEdit(); - } - }); - } - } - - public class SelectAllAction extends AbstractExtendedAction { - public SelectAllAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.selectAll(); - } - } - - public class StrikethroughAction extends AbstractExtendedAction { - public StrikethroughAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.toggleStrikethrough(); - fireOnEdit(); - } - } - - public class SubscriptAction extends AbstractExtendedAction { - public SubscriptAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.toggleSubscript(); - fireOnEdit(); - } - } - - public class SuperscriptAction extends AbstractExtendedAction { - public SuperscriptAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.toggleSuperscript(); - fireOnEdit(); - } - } - - public class UlAction extends AbstractExtendedAction { - public UlAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.insertUnorderedList(); - fireOnEdit(); - } - } - - public class UnderlineAction extends AbstractExtendedAction { - public UnderlineAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.toggleUnderline(); - fireOnEdit(); - } - } - - public class UndoAction extends AbstractExtendedAction { - public UndoAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - view.undo(); - fireOnEdit(); - } - } - - private static final String FONT_NAMES[] = { "Times New Roman", "Arial", "Courier New", "Georgia", "Trebuchet", - "Verdana" }; - private static final String FONT_SIZE_NAMES[] = { "Extra small", "Very small (normal)", "Small", "Medium", "Large", - "Very large", "Extra large" }; - private static final RichTextArea.FontSize[] FONT_SIZES = new RichTextArea.FontSize[] { - RichTextArea.FontSize.XX_SMALL, RichTextArea.FontSize.X_SMALL, RichTextArea.FontSize.SMALL, - RichTextArea.FontSize.MEDIUM, RichTextArea.FontSize.LARGE, RichTextArea.FontSize.X_LARGE, - RichTextArea.FontSize.XX_LARGE }; - private static final String FONT_GROUP = "fontgroup"; - private static final String FONT_SIZEGROUP = "fontsizegroup"; - - private RTEditorViewNew view; - private boolean extended; - private final I18nTranslationService i18n; - private final Session session; - private final RTEImgResources imgResources; - private final Event0 onEdit; - private final DeferredCommandWrapper deferred; - private final Provider<ColorWebSafePalette> paletteProvider; - private final Provider<InsertLinkDialog> insLinkDialogPv; - private final Provider<EditHtmlDialog> editHtmlDialogPv; - private final Provider<InsertImageDialog> insImgDialogProv; - private final Provider<InsertTableDialog> insTableDialogPv; - private final Provider<InsertSpecialCharDialog> insCharDialogProv; - private final Provider<InsertMediaDialog> insMediaDialogPv; - private Listener<String> insTableListener; - private Listener<LinkInfo> insLinkListener; - private Listener<ImageInfo> insImgListener; - private Listener<String> insMediaListener; - private Listener<String> updHtmlListener; - protected Listener<String> insCharListener; - protected ColorWebSafePalette palette; - private PushButtonDescriptor bold; - private PushButtonDescriptor italic; - private PushButtonDescriptor underline; - private PushButtonDescriptor strikethrough; - private final GuiAddCondition basicAddCond; - private final GuiAddCondition extendedAddCond; - private final InputMap inputMap; - private MenuDescriptor editMenu; - private MenuDescriptor insertMenu; - private MenuDescriptor formatMenu; - private MenuDescriptor linkCtxMenu; - private GuiActionDescCollection actions; - private MenuDescriptor fontMenu; - private MenuDescriptor fontSizeMenu; - private MenuDescriptor fileMenu; - private final List<MenuDescriptor> menus; - private boolean attached; - private final Map<String, MenuCheckItemDescriptor> fontActions; - private MenuCheckItemDescriptor currentFontItem; - - public RTEditorPresenterNew(final I18nTranslationService i18n, final Session session, - final RTEImgResources imgResources, final Provider<InsertLinkDialog> insLinkDialog, - final Provider<ColorWebSafePalette> palette, final Provider<EditHtmlDialog> editHtmlDialog, - final Provider<InsertImageDialog> insertImageDialog, final Provider<InsertMediaDialog> insertMediaDialog, - final Provider<InsertTableDialog> insertTableDialog, final Provider<InsertSpecialCharDialog> insCharDialog, - final DeferredCommandWrapper deferred) { - this.i18n = i18n; - this.session = session; - this.insLinkDialogPv = insLinkDialog; - this.paletteProvider = palette; - this.editHtmlDialogPv = editHtmlDialog; - this.insImgDialogProv = insertImageDialog; - this.insMediaDialogPv = insertMediaDialog; - this.insTableDialogPv = insertTableDialog; - this.insCharDialogProv = insCharDialog; - this.deferred = deferred; - inputMap = new InputMap(); - menus = new ArrayList<MenuDescriptor>(); - - this.imgResources = imgResources; - this.onEdit = new Event0("onRTEEdit"); - extendedAddCond = new GuiAddCondition() { - public boolean mustBeAdded() { - return isAndCanBeExtended(); - } - }; - basicAddCond = new GuiAddCondition() { - public boolean mustBeAdded() { - return view.canBeBasic(); - } - }; - attached = false; - fontActions = new HashMap<String, MenuCheckItemDescriptor>(); - } - - public void addAction(final GuiActionDescrip descriptor) { - actions.add(descriptor); - checkForMenus(descriptor); - } - - public void addActions(final GuiActionDescCollection descriptors) { - actions.addAll(descriptors); - for (final GuiActionDescrip descriptor : descriptors) { - checkForMenus(descriptor); - } - } - - public void addOnEditListener(final Listener0 listener) { - onEdit.add(listener); - } - - public void adjustSize(final int height) { - view.adjustSize(height); - } - - public void attach() { - if (!attached) { - attached = true; - view.addActions(actions); - view.setInputMap(inputMap); - } - } - - public void detach() { - // topBar.clear(); - // sndBar.clear(); - } - - public void fireOnEdit() { - onEdit.fire(); - } - - public GuiAddCondition getBasicAddCondition() { - return basicAddCond; - } - - public MenuDescriptor getEditMenu() { - return editMenu; - } - - public View getEditorArea() { - return view; - } - - public GuiAddCondition getExtendedAddCondition() { - return extendedAddCond; - } - - public MenuDescriptor getFileMenu() { - return fileMenu; - } - - public MenuDescriptor getFormatMenu() { - return formatMenu; - } - - public String getHtml() { - return view.getHTML(); - } - - public MenuDescriptor getInsertMenu() { - return insertMenu; - } - - public MenuDescriptor getLinkCtxMenu() { - return linkCtxMenu; - } - - public View getSndBar() { - return view.getSndBar(); - } - - public String getText() { - return view.getText(); - } - - public View getTopBar() { - return view.getTopBar(); - } - - public void init(final RTEditorViewNew view) { - this.view = view; - createMainMenus(); - createBasicActions(); - } - - public void onEditorFocus() { - hideMenus(); - } - - public void onLostFocus() { - // Nothing for the moment - } - - public void reset() { - hideMenus(); - hideLinkCtxMenu(); - } - - public void setActionShortcut(final KeyStroke key, final AbstractAction action) { - inputMap.put(key, action); - action.putValue(Action.ACCELERATOR_KEY, key); - } - - public void setActionShortcut(final KeyStroke key, final AbstractAction mainAction, final AbstractAction... actions) { - setActionShortcut(key, mainAction); - for (final AbstractAction action : actions) { - action.putValue(Action.ACCELERATOR_KEY, key); - } - } - - public void setExtended(final boolean newValue) { - this.extended = newValue; - } - - public void setFocus(final boolean focus) { - view.setFocus(focus); - } - - public void setHtml(final String html) { - view.setHTML(html); - view.focus(); - } - - public void setText(final String text) { - view.setText(text); - view.focus(); - } - - public void updateLinkInfo() { - deferred.addCommand(new Listener0() { - public void onEvent() { - if (isAndCanBeExtended() && view.isLink()) { - view.showLinkCtxMenu(); - } else { - hideLinkCtxMenu(); - } - } - }); - } - - public void updateStatus() { - if (view.canBeBasic()) { - bold.setPushed(view.isBold()); - italic.setPushed(view.isItalic()); - underline.setPushed(view.isUnderlined()); - deferred.addCommand(new Listener0() { - public void onEvent() { - updateFont(); - // Log.warn(view.getFontSize()); - } - }); - } - if (isAndCanBeExtended()) { - strikethrough.setPushed(view.isStrikethrough()); - } - } - - private void checkForMenus(final GuiActionDescrip descriptor) { - if (descriptor instanceof MenuDescriptor) { - menus.add((MenuDescriptor) descriptor); - } - } - - private void createBasicActions() { - - final MenuSeparatorDescriptor editMenuSep = new MenuSeparatorDescriptor(editMenu); - final MenuSeparatorDescriptor insertMenuSep = new MenuSeparatorDescriptor(insertMenu); - final MenuSeparatorDescriptor formatMenuSep = new MenuSeparatorDescriptor(formatMenu); - insertMenuSep.setAddCondition(extendedAddCond); - - final ToolbarSeparatorDescriptor sndbarSep = new ToolbarSeparatorDescriptor(Type.separator, getSndBar()); - final ToolbarSeparatorDescriptor sndbarSepExt = new ToolbarSeparatorDescriptor(Type.separator, getSndBar()); - sndbarSepExt.setAddCondition(extendedAddCond); - - final SelectAllAction selectAllAction = new SelectAllAction(i18n.t("Select all"), AbstractExtendedAction.NO_TEXT, - imgResources.selectall()); - final MenuItemDescriptor select = new MenuItemDescriptor(editMenu, selectAllAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('A'), Keyboard.MODIFIER_CTRL), selectAllAction); - - final BoldAction boldAction = new BoldAction(NO_TEXT, i18n.t("Bold"), imgResources.bold()); - bold = new PushButtonDescriptor(boldAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('B'), Keyboard.MODIFIER_CTRL), boldAction); - - final ItalicAction italicAction = new ItalicAction(NO_TEXT, i18n.t("Italic"), imgResources.italic()); - italic = new PushButtonDescriptor(italicAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('I'), Keyboard.MODIFIER_CTRL), italicAction); - - final UnderlineAction underlineAction = new UnderlineAction(NO_TEXT, i18n.t("Underline"), - imgResources.underline()); - underline = new PushButtonDescriptor(underlineAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('U'), Keyboard.MODIFIER_CTRL), underlineAction); - - final SubscriptAction subscriptAction = new SubscriptAction(i18n.t("Subscript"), NO_TEXT, - imgResources.subscript()); - final MenuItemDescriptor subscript = new MenuItemDescriptor(formatMenu, subscriptAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf(','), Keyboard.MODIFIER_CTRL), subscriptAction); - - final SuperscriptAction superscriptAction = new SuperscriptAction(i18n.t("Superscript"), NO_TEXT, - imgResources.superscript()); - final MenuItemDescriptor superscript = new MenuItemDescriptor(formatMenu, superscriptAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('.'), Keyboard.MODIFIER_CTRL), superscriptAction); - - final JustifyLeftAction jfyLeftAction = new JustifyLeftAction(NO_TEXT, i18n.t("Left Justify"), - imgResources.alignleft()); - final ButtonDescriptor justifyLeft = new ButtonDescriptor(jfyLeftAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('L'), Keyboard.MODIFIER_CTRL), jfyLeftAction); - - final JustifyCentreAction jfyCentreAction = new JustifyCentreAction(NO_TEXT, i18n.t("Centre Justify"), - imgResources.centerpara()); - final ButtonDescriptor justifyCentre = new ButtonDescriptor(jfyCentreAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('E'), Keyboard.MODIFIER_CTRL), jfyCentreAction); - - final JustifyRightAction jfyRightAction = new JustifyRightAction(NO_TEXT, i18n.t("Right Justify"), - imgResources.alignright()); - final ButtonDescriptor justifyRight = new ButtonDescriptor(jfyRightAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('R'), Keyboard.MODIFIER_CTRL), jfyRightAction); - - final UndoAction undoAction = new UndoAction(i18n.t("Undo"), NO_TEXT, imgResources.undo()); - final UndoAction undoActionBtn = new UndoAction(NO_TEXT, i18n.t("Undo"), imgResources.undo()); - final MenuItemDescriptor undo = new MenuItemDescriptor(editMenu, undoAction); - final ButtonDescriptor undoBtn = new ButtonDescriptor(undoActionBtn); - undoBtn.setPosition(0); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('Z'), Keyboard.MODIFIER_CTRL), undoAction); - - final RedoAction redoAction = new RedoAction(i18n.t("Redo"), NO_TEXT, imgResources.redo()); - final RedoAction redoActionBtn = new RedoAction(NO_TEXT, i18n.t("Redo"), imgResources.redo()); - final MenuItemDescriptor redo = new MenuItemDescriptor(editMenu, redoAction); - final ButtonDescriptor redoBtn = new ButtonDescriptor(redoActionBtn); - redoBtn.setPosition(1); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('Y'), Keyboard.MODIFIER_CTRL), redoAction); - - final CopyAction copyAction = new CopyAction(i18n.t("Copy"), NO_TEXT, imgResources.copy()); - final MenuItemDescriptor copy = new MenuItemDescriptor(editMenu, copyAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('C'), Keyboard.MODIFIER_CTRL), copyAction); - - final CutAction cutAction = new CutAction(i18n.t("Cut"), NO_TEXT, imgResources.cut()); - final MenuItemDescriptor cut = new MenuItemDescriptor(editMenu, cutAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('X'), Keyboard.MODIFIER_CTRL), cutAction); - - final PasteAction pasteAction = new PasteAction(i18n.t("Paste"), NO_TEXT, imgResources.paste()); - final MenuItemDescriptor paste = new MenuItemDescriptor(editMenu, pasteAction); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('V'), Keyboard.MODIFIER_CTRL), pasteAction); - - final EditHtmlAction editHtmlAction = new EditHtmlAction(i18n.t("Edit HTML"), NO_TEXT, imgResources.edithtml()); - final MenuItemDescriptor editHtml = new MenuItemDescriptor(editMenu, editHtmlAction); - editHtml.setAddCondition(extendedAddCond); - - final CommentAction commentAction = new CommentAction(i18n.t("Comment"), NO_TEXT, NO_ICON); - final MenuItemDescriptor comment = new MenuItemDescriptor(insertMenu, commentAction); - comment.setAddCondition(extendedAddCond); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('M'), Keyboard.MODIFIER_CTRL), commentAction); - - final HrAction hlineAction = new HrAction(i18n.t("Horizontal line"), NO_TEXT, imgResources.hfixedline()); - final HrAction hlineBtnAction = new HrAction(NO_TEXT, i18n.t("Horizontal line"), imgResources.hfixedline()); - final MenuItemDescriptor hline = new MenuItemDescriptor(insertMenu, hlineAction); - final ButtonDescriptor hlineBtn = new ButtonDescriptor(hlineBtnAction); - hline.setAddCondition(extendedAddCond); - hlineBtn.setAddCondition(extendedAddCond); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf(' '), Keyboard.MODIFIER_CTRL - + Keyboard.MODIFIER_SHIFT), hlineAction); - - final BlockquoteAction blockquoteAction = new BlockquoteAction(i18n.t("Block Quotation"), NO_TEXT, NO_ICON); - final MenuItemDescriptor blockquote = new MenuItemDescriptor(formatMenu, blockquoteAction); - blockquote.setAddCondition(extendedAddCond); - - final StrikethroughAction strikeAction = new StrikethroughAction(NO_TEXT, i18n.t("Strikethrough"), - imgResources.strikeout()); - strikethrough = new PushButtonDescriptor(strikeAction); - strikethrough.setAddCondition(extendedAddCond); - - final DecreaseIndentAction decreIndentAction = new DecreaseIndentAction(NO_TEXT, i18n.t("Decrease Indent"), - imgResources.decrementindent()); - final ButtonDescriptor decreaseIndent = new ButtonDescriptor(decreIndentAction); - decreaseIndent.setAddCondition(extendedAddCond); - - final IncreaseIndentAction increIndentAction = new IncreaseIndentAction(NO_TEXT, i18n.t("Increase Indent"), - imgResources.incrementindent()); - final ButtonDescriptor increaseIndent = new ButtonDescriptor(increIndentAction); - increaseIndent.setAddCondition(extendedAddCond); - - final OlAction olistAction = new OlAction(NO_TEXT, i18n.t("Numbered List"), imgResources.defaultnumbering()); - final ButtonDescriptor olist = new ButtonDescriptor(olistAction); - olist.setAddCondition(extendedAddCond); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('7'), Keyboard.MODIFIER_CTRL), olistAction); - - final UlAction ulistAction = new UlAction(NO_TEXT, i18n.t("Bullet List"), imgResources.defaultbullet()); - final ButtonDescriptor ulist = new ButtonDescriptor(ulistAction); - ulist.setAddCondition(extendedAddCond); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('8'), Keyboard.MODIFIER_CTRL), ulistAction); - - final ImgAction imgAction = new ImgAction(i18n.t("Image..."), NO_TEXT, imgResources.images()); - final ImgAction imgBtnAction = new ImgAction(NO_TEXT, i18n.t("Insert Image"), imgResources.images()); - final MenuItemDescriptor img = new MenuItemDescriptor(insertMenu, imgAction); - final ButtonDescriptor imgBtn = new ButtonDescriptor(imgBtnAction); - img.setAddCondition(extendedAddCond); - imgBtn.setAddCondition(extendedAddCond); - - final InsertMediaAction insertMediaAction = new InsertMediaAction(i18n.t("Audio/Video..."), NO_TEXT, - imgResources.film()); - final MenuItemDescriptor insertMedia = new MenuItemDescriptor(insertMenu, insertMediaAction); - insertMedia.setAddCondition(extendedAddCond); - - final CreateOrEditLinkAction editLinkAction = new CreateOrEditLinkAction(i18n.t("Link..."), NO_TEXT, - imgResources.link()); - final CreateOrEditLinkAction editLinkBtnAction = new CreateOrEditLinkAction(NO_TEXT, - i18n.t("Create or Edit Link"), imgResources.link()); - final CreateOrEditLinkAction editLinkCtxAction = new CreateOrEditLinkAction(i18n.t("Change"), NO_TEXT, - imgResources.link()); - final MenuItemDescriptor editLink = new MenuItemDescriptor(insertMenu, editLinkAction); - final MenuItemDescriptor editLinkCtx = new MenuItemDescriptor(linkCtxMenu, editLinkCtxAction); - final ButtonDescriptor editLinkBtn = new ButtonDescriptor(editLinkBtnAction); - editLink.setAddCondition(extendedAddCond); - editLinkBtn.setAddCondition(extendedAddCond); - editLinkCtx.setAddCondition(extendedAddCond); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('K'), Keyboard.MODIFIER_CTRL), editLinkAction, - editLinkBtnAction); - - final KeyStroke key_SK = KeyStroke.getKeyStroke(Character.valueOf('K'), Keyboard.MODIFIER_CTRL - + Keyboard.MODIFIER_SHIFT); - final RemoveLinkAction delLinkBtnAction = new RemoveLinkAction(NO_TEXT, i18n.t("Remove Link"), - imgResources.linkbreak()); - final RemoveLinkAction delLinkCtxAction = new RemoveLinkAction(i18n.t("Remove"), NO_TEXT, - imgResources.linkbreak()); - final MenuItemDescriptor removeLinkCtx = new MenuItemDescriptor(linkCtxMenu, delLinkCtxAction); - final ButtonDescriptor removeLinkBtn = new ButtonDescriptor(delLinkBtnAction); - removeLinkBtn.setAddCondition(extendedAddCond); - removeLinkCtx.setAddCondition(extendedAddCond); - setActionShortcut(key_SK, delLinkBtnAction); - - final RemoveFormatAction remFormatAction = new RemoveFormatAction(i18n.t("Clear Formatting..."), NO_TEXT, - imgResources.removeFormat()); - final RemoveFormatAction remFormatBtnAc = new RemoveFormatAction(NO_TEXT, i18n.t("Clear Formatting..."), - imgResources.removeFormat()); - final MenuItemDescriptor removeFormat = new MenuItemDescriptor(formatMenu, remFormatAction); - final ButtonDescriptor removeFormatBtn = new ButtonDescriptor(remFormatBtnAc); - removeFormat.setAddCondition(extendedAddCond); - removeFormatBtn.setAddCondition(extendedAddCond); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf(' '), Keyboard.MODIFIER_CTRL), remFormatAction, - remFormatBtnAc); - - final InsertSpecialCharAction insCharAction = new InsertSpecialCharAction(i18n.t("Special characters..."), - NO_TEXT, imgResources.specialchars()); - final MenuItemDescriptor insertSpecialChar = new MenuItemDescriptor(insertMenu, insCharAction); - insertSpecialChar.setAddCondition(extendedAddCond); - - final InsertTableAction insTableAction = new InsertTableAction(i18n.t("Table..."), NO_TEXT, - imgResources.inserttable()); - final InsertTableAction insTableBtnAction = new InsertTableAction(NO_TEXT, i18n.t("Insert Table"), - imgResources.inserttable()); - final MenuItemDescriptor insertTable = new MenuItemDescriptor(insertMenu, insTableAction); - final ButtonDescriptor insertTableBtn = new ButtonDescriptor(insTableBtnAction); - insertTable.setAddCondition(extendedAddCond); - insertTableBtn.setAddCondition(extendedAddCond); - - final FontColorAction fontColorAction = new FontColorAction(NO_TEXT, i18n.t("Text Colour"), - imgResources.fontcolor()); - final ButtonDescriptor fontColor = new ButtonDescriptor(fontColorAction); - fontColor.setAddCondition(basicAddCond); - - final BackgroundColorAction backColorAction = new BackgroundColorAction(NO_TEXT, - i18n.t("Text Background Colour"), imgResources.backcolor()); - final ButtonDescriptor backgroundColor = new ButtonDescriptor(backColorAction); - backgroundColor.setAddCondition(basicAddCond); - - final DevInfoAction devInfoAction = new DevInfoAction(i18n.t("Developers info"), NO_TEXT, - imgResources.specialchars()); - final MenuItemDescriptor devInfo = new MenuItemDescriptor(formatMenu, devInfoAction); - devInfo.setAddCondition(extendedAddCond); - setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf('I'), Keyboard.MODIFIER_ALT), devInfoAction); - - actions = new GuiActionDescCollection(); - actions.add(fileMenu, editMenu, formatMenu, insertMenu, undo, redo, editMenuSep, copy, cut, paste, editMenuSep, - select, editMenuSep, editHtml, editLink, img, insertTable, insertMedia, insertMenuSep, - insertSpecialChar, comment, hline, removeFormat, formatMenuSep, insertMenuSep, undoBtn, redoBtn, - sndbarSep, bold, italic, underline, strikethrough, sndbarSep, justifyLeft, justifyCentre, justifyRight, - decreaseIndent, increaseIndent, olist, ulist, sndbarSep, removeFormatBtn, sndbarSepExt, hlineBtn, - imgBtn, editLinkBtn, removeLinkBtn, insertTableBtn, sndbarSepExt, subscript, superscript, blockquote, - fontColor, backgroundColor, fontSizeMenu, fontMenu, editLinkCtx, removeLinkCtx); - // actions.add(devInfo); - - setLocation(TOPBAR, new GuiActionDescrip[] { fileMenu, editMenu, insertMenu, formatMenu, editMenuSep, - subscript, superscript, undo, redo, editMenuSep, copy, cut, paste, editMenuSep, select, editMenuSep, - editHtml, comment, hline, blockquote, img, insertTable, insertMedia, editLink, removeFormat, - formatMenuSep, insertMenuSep, insertSpecialChar, insertTable, devInfo }); - setLocation(SNDBAR, new GuiActionDescrip[] { undoBtn, redoBtn, sndbarSep, sndbarSepExt, bold, italic, - underline, strikethrough, justifyLeft, justifyCentre, justifyRight, undoBtn, redoBtn, hlineBtn, - decreaseIndent, increaseIndent, olist, ulist, hlineBtn, imgBtn, editLinkBtn, removeLinkBtn, - removeFormatBtn, insertTableBtn, fontColor, backgroundColor, fontMenu, fontSizeMenu }); - setLocation(LINKCTX, new GuiActionDescrip[] { removeLinkCtx, editLinkCtx }); - - for (final String fontName : FONT_NAMES) { - createFontAction(fontMenu, fontName); - } - - for (int fontSize = 0; fontSize < FONT_SIZE_NAMES.length; fontSize++) { - createFontSizeAction(fontSizeMenu, fontSize); - } - } - - private void createFontAction(final MenuDescriptor fontMenu, final String fontName) { - final FontAction fontAction = new FontAction(fontName, NO_TEXT, NO_ICON); - final MenuRadioItemDescriptor font = new MenuRadioItemDescriptor(fontMenu, fontAction, FONT_GROUP); - font.setAddCondition(basicAddCond); - font.setLocation(SNDBAR); - fontActions.put(fontName.toLowerCase(), font); - actions.add(font); - } - - private void createFontSizeAction(final MenuDescriptor fontSizeMenu, final int fontSize) { - final String fontSizeName = i18n.t(FONT_SIZE_NAMES[fontSize]); - final FontSizeAction fontSizeAction = new FontSizeAction(fontSizeName, fontSize, NO_TEXT, NO_ICON); - final MenuRadioItemDescriptor fontSizeItem = new MenuRadioItemDescriptor(fontSizeMenu, fontSizeAction, - FONT_SIZEGROUP); - fontSizeItem.setAddCondition(basicAddCond); - // setActionShortcut(KeyStroke.getKeyStroke(Character.valueOf(((char) - // (48 + fontSize))), Keyboard.MODIFIER_CTRL), - // fontSizeAction); - fontSizeItem.setLocation(SNDBAR); - actions.add(fontSizeItem); - } - - private void createMainMenus() { - menus.add(fileMenu = new MenuDescriptor(i18n.t("File"))); - menus.add(editMenu = new MenuDescriptor(i18n.t("Edit"))); - menus.add(insertMenu = new MenuDescriptor(i18n.t("Insert"))); - menus.add(formatMenu = new MenuDescriptor(i18n.t("Format"))); - menus.add(linkCtxMenu = new MenuDescriptor(i18n.t("Change Link"))); - menus.add(fontMenu = new MenuDescriptor(NO_TEXT, i18n.t("Font"), imgResources.charfontname())); - menus.add(fontSizeMenu = new MenuDescriptor(NO_TEXT, i18n.t("Font size"), imgResources.fontheight())); - insertMenu.setAddCondition(extendedAddCond); - } - - private void createPalette() { - if (palette == null) { - palette = paletteProvider.get(); - } - } - - private void hideLinkCtxMenu() { - if (view.isCtxMenuVisible()) { - view.hideLinkCtxMenu(); - } - } - - private void hideMenus() { - for (final MenuDescriptor menu : menus) { - menu.hide(); - } - if (palette != null) { - palette.hide(); - } - } - - private boolean isAndCanBeExtended() { - return extended && view.canBeExtended(); - } - - private void setLocation(final String location, final GuiActionDescrip[] descripts) { - for (final GuiActionDescrip descript : descripts) { - descript.setLocation(location); - } - } - - private void updateFont() { - final String currentFont = view.getFont(); - final MenuCheckItemDescriptor item = fontActions.get(currentFont); - if (currentFontItem != null && item != currentFontItem) { - currentFontItem.setChecked(false); - } - if (item != null) { - item.setChecked(true); - currentFontItem = item; - fontMenu.setText((String) item.getValue(FontAction.FONT_NAME)); - } else { - fontMenu.setText(" "); - } - } -} Copied: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorView.java (from rev 1124, trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorViewNew.java) =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorViewNew.java 2009-06-10 14:37:53 UTC (rev 1124) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorView.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -0,0 +1,140 @@ +package org.ourproject.kune.platf.client.ui.rte.basic; + +import org.ourproject.kune.platf.client.View; +import org.ourproject.kune.platf.client.actions.InputMap; +import org.ourproject.kune.platf.client.actions.ui.GuiActionDescCollection; +import org.ourproject.kune.platf.client.ui.rte.RichTextArea.FontSize; +import org.ourproject.kune.platf.client.ui.rte.insertlink.LinkInfo; + +public interface RTEditorView extends View { + + void addActions(GuiActionDescCollection actions); + + void adjustSize(int height); + + boolean canBeBasic(); + + boolean canBeExtended(); + + void copy(); + + void createLink(String url); + + void cut(); + + void delete(); + + void focus(); + + String getFont(); + + String getFontSize(); + + String getHTML(); + + LinkInfo getLinkInfoIfHref(); + + void getRangeInfo(); + + String getSelectionText(); + + View getSndBar(); + + String getText(); + + View getTopBar(); + + void hideLinkCtxMenu(); + + void insertBlockquote(); + + void insertComment(String author); + + void insertCommentNotUsingSelection(String author); + + void insertCommentUsingSelection(String author); + + void insertHorizontalRule(); + + void insertHtml(String html); + + void insertImage(String url); + + void insertOrderedList(); + + void insertUnorderedList(); + + boolean isAnythingSelected(); + + boolean isAttached(); + + boolean isBold(); + + boolean isCtxMenuVisible(); + + boolean isItalic(); + + boolean isLink(); + + boolean isStrikethrough(); + + boolean isSubscript(); + + boolean isSuperscript(); + + boolean isUnderlined(); + + void justifyCenter(); + + void justifyLeft(); + + void justifyRight(); + + void leftIndent(); + + void paste(); + + void redo(); + + void removeFormat(); + + void rightIndent(); + + void selectAll(); + + void selectLink(); + + void setBackColor(String color); + + void setFocus(boolean focus); + + void setFontName(String name); + + void setFontSize(FontSize fontSize); + + void setForeColor(String color); + + void setHTML(String html); + + void setInputMap(InputMap inputMap); + + void setText(String text); + + void showLinkCtxMenu(); + + void toggleBold(); + + void toggleItalic(); + + void toggleStrikethrough(); + + void toggleSubscript(); + + void toggleSuperscript(); + + void toggleUnderline(); + + void undo(); + + void unlink(); +} Deleted: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorViewNew.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorViewNew.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorViewNew.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -1,140 +0,0 @@ -package org.ourproject.kune.platf.client.ui.rte.basic; - -import org.ourproject.kune.platf.client.View; -import org.ourproject.kune.platf.client.actions.InputMap; -import org.ourproject.kune.platf.client.actions.ui.GuiActionDescCollection; -import org.ourproject.kune.platf.client.ui.rte.RichTextArea.FontSize; -import org.ourproject.kune.platf.client.ui.rte.insertlink.LinkInfo; - -public interface RTEditorViewNew extends View { - - void addActions(GuiActionDescCollection actions); - - void adjustSize(int height); - - boolean canBeBasic(); - - boolean canBeExtended(); - - void copy(); - - void createLink(String url); - - void cut(); - - void delete(); - - void focus(); - - String getFont(); - - String getFontSize(); - - String getHTML(); - - LinkInfo getLinkInfoIfHref(); - - void getRangeInfo(); - - String getSelectionText(); - - View getSndBar(); - - String getText(); - - View getTopBar(); - - void hideLinkCtxMenu(); - - void insertBlockquote(); - - void insertComment(String author); - - void insertCommentNotUsingSelection(String author); - - void insertCommentUsingSelection(String author); - - void insertHorizontalRule(); - - void insertHtml(String html); - - void insertImage(String url); - - void insertOrderedList(); - - void insertUnorderedList(); - - boolean isAnythingSelected(); - - boolean isAttached(); - - boolean isBold(); - - boolean isCtxMenuVisible(); - - boolean isItalic(); - - boolean isLink(); - - boolean isStrikethrough(); - - boolean isSubscript(); - - boolean isSuperscript(); - - boolean isUnderlined(); - - void justifyCenter(); - - void justifyLeft(); - - void justifyRight(); - - void leftIndent(); - - void paste(); - - void redo(); - - void removeFormat(); - - void rightIndent(); - - void selectAll(); - - void selectLink(); - - void setBackColor(String color); - - void setFocus(boolean focus); - - void setFontName(String name); - - void setFontSize(FontSize fontSize); - - void setForeColor(String color); - - void setHTML(String html); - - void setInputMap(InputMap inputMap); - - void setText(String text); - - void showLinkCtxMenu(); - - void toggleBold(); - - void toggleItalic(); - - void toggleStrikethrough(); - - void toggleSubscript(); - - void toggleSuperscript(); - - void toggleUnderline(); - - void undo(); - - void unlink(); -} Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditor.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditor.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditor.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -1,12 +1,12 @@ package org.ourproject.kune.platf.client.ui.rte.saving; import org.ourproject.kune.platf.client.actions.BeforeActionListener; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorNew; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditor; import com.calclab.suco.client.events.Listener; import com.calclab.suco.client.events.Listener0; -public interface RTESavingEditor { +public interface RTESavingEditor extends RTEditor { /** * Start to edit some html code @@ -20,8 +20,6 @@ */ void edit(String html, Listener<String> onSave, Listener0 onEditCancelled); - RTEditorNew getBasicEditor(); - /** * This is used for listen to changes that affect the edition as url * changes, window close, to save/cancel or stop these actions @@ -30,6 +28,11 @@ */ BeforeActionListener getBeforeSavingListener(); + /** + * Checks if is save is pending. + * + * @return true, if is save pending + */ boolean isSavePending(); /** Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPanel.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPanel.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPanel.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -1,13 +1,23 @@ package org.ourproject.kune.platf.client.ui.rte.saving; +import org.ourproject.kune.platf.client.actions.ui.GuiBindingsRegister; +import org.ourproject.kune.platf.client.i18n.I18nUITranslationService; +import org.ourproject.kune.platf.client.shortcuts.GlobalShortcutRegister; import org.ourproject.kune.platf.client.ui.noti.NotifyUser; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorPanel; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorPresenter; import com.calclab.suco.client.events.Listener0; -public class RTESavingEditorPanel implements RTESavingEditorView { +public class RTESavingEditorPanel extends RTEditorPanel implements RTESavingEditorView { - public void askConfirmation(String confirmationTitle, String confirmationText, Listener0 onConfirm, - Listener0 onCancel) { + public RTESavingEditorPanel(final RTEditorPresenter presenter, final I18nUITranslationService i18n, + final GlobalShortcutRegister globalShortcutReg, final GuiBindingsRegister bindReg) { + super(presenter, i18n, globalShortcutReg, bindReg); + } + + public void askConfirmation(final String confirmationTitle, final String confirmationText, + final Listener0 onConfirm, final Listener0 onCancel) { NotifyUser.askConfirmation(confirmationTitle, confirmationText, onConfirm, onCancel); } Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenter.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenter.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenter.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -12,17 +12,27 @@ import org.ourproject.kune.platf.client.actions.ui.MenuItemDescriptor; import org.ourproject.kune.platf.client.i18n.I18nTranslationService; import org.ourproject.kune.platf.client.shortcuts.Keyboard; +import org.ourproject.kune.platf.client.state.Session; import org.ourproject.kune.platf.client.state.StateManager; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorNew; +import org.ourproject.kune.platf.client.ui.palette.ColorWebSafePalette; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditor; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorPresenter; +import org.ourproject.kune.platf.client.ui.rte.edithtml.EditHtmlDialog; import org.ourproject.kune.platf.client.ui.rte.img.RTEImgResources; +import org.ourproject.kune.platf.client.ui.rte.insertimg.InsertImageDialog; +import org.ourproject.kune.platf.client.ui.rte.insertlink.InsertLinkDialog; +import org.ourproject.kune.platf.client.ui.rte.insertmedia.InsertMediaDialog; +import org.ourproject.kune.platf.client.ui.rte.insertspecialchar.InsertSpecialCharDialog; +import org.ourproject.kune.platf.client.ui.rte.inserttable.InsertTableDialog; import org.ourproject.kune.platf.client.utils.DeferredCommandWrapper; import org.ourproject.kune.platf.client.utils.TimerWrapper; import com.calclab.suco.client.events.Listener; import com.calclab.suco.client.events.Listener0; +import com.calclab.suco.client.ioc.Provider; import com.google.gwt.libideas.resources.client.ImageResource; -public class RTESavingEditorPresenter implements RTESavingEditor { +public class RTESavingEditorPresenter extends RTEditorPresenter implements RTESavingEditor { public class AutoSaveAction extends AbstractExtendedAction { public AutoSaveAction(final String text, final String tooltip, final ImageResource icon) { @@ -76,7 +86,6 @@ public static final int AUTOSAVE_AFTER_FAIL_MILLS = 20000; public static final int AUTOSAVE_IN_MILLIS = 10000; - private final RTEditorNew editor; private boolean autoSave; private boolean savePending; private boolean saveCloseConfirmed; @@ -93,18 +102,21 @@ SaveAction saveAction; private SaveAction saveMenuAction; - public RTESavingEditorPresenter(final RTEditorNew editor, final boolean autoSave, final I18nTranslationService i18n, - final StateManager stateManager, final DeferredCommandWrapper deferredCommandWrapper, - final RTEImgResources imgResources, final TimerWrapper timer) { - this.editor = editor; + public RTESavingEditorPresenter(final I18nTranslationService i18n, final Session session, + final RTEImgResources imgResources, final Provider<InsertLinkDialog> insLinkDialog, + final Provider<ColorWebSafePalette> palette, final Provider<EditHtmlDialog> editHtmlDialog, + final Provider<InsertImageDialog> insertImageDialog, final Provider<InsertMediaDialog> insertMediaDialog, + final Provider<InsertTableDialog> insertTableDialog, final Provider<InsertSpecialCharDialog> insCharDialog, + final DeferredCommandWrapper deferred, final boolean autoSave, + final StateManager stateManager, final TimerWrapper timer) { + super(i18n, session, imgResources, insLinkDialog, palette, editHtmlDialog, insertImageDialog, insertMediaDialog, insertTableDialog, insCharDialog, deferred); this.autoSave = autoSave; this.i18n = i18n; this.stateManager = stateManager; - this.deferred = deferredCommandWrapper; + this.deferred = deferred; this.imgResources = imgResources; this.savePending = false; this.saveCloseConfirmed = false; - createActions(); this.timer = timer; timer.configure(new Listener0() {; @@ -113,7 +125,7 @@ } }); - editor.addOnEditListener(new Listener0() { + super.addOnEditListener(new Listener0() { public void onEvent() { onEdit(); } @@ -128,22 +140,20 @@ public void edit(final String html, final Listener<String> onSave, final Listener0 onEditCancelled) { this.onSave = onSave; this.onEditCancelled = onEditCancelled; - editor.setHtml(html); - editor.attach(); + super.setHtml(html); + super.attach(); stateManager.addBeforeStateChangeListener(beforeStateChg); enableSaveBtn(false); } - public RTEditorNew getBasicEditor() { - return editor; - } - public BeforeActionListener getBeforeSavingListener() { return beforeStateChg; } public void init(final RTESavingEditorView view) { + super.init(view); this.view = view; + createActions(); } public boolean isSavePending() { @@ -169,6 +179,15 @@ } } + @Override + public void reset() { + timer.cancel(); + savePending = false; + saveCloseConfirmed = false; + enableSaveBtn(false); + super.reset(); + } + protected void onAutoSave() { onDoSave(); } @@ -216,39 +235,39 @@ final ButtonDescriptor saveBtn = new ButtonDescriptor(saveAction); final KeyStroke key_S = KeyStroke.getKeyStroke(Keyboard.KEY_S, Keyboard.MODIFIER_CTRL); saveBtn.setPosition(0); - saveBtn.setLocation(RTEditorNew.SNDBAR); + saveBtn.setLocation(RTEditor.SNDBAR); saveMenuAction = new SaveAction(i18n.t("Save"),NO_TEXT, imgResources.save()); - final MenuItemDescriptor saveMenu = new MenuItemDescriptor(editor.getFileMenu(), saveMenuAction); + final MenuItemDescriptor saveMenu = new MenuItemDescriptor(super.getFileMenu(), saveMenuAction); saveMenu.setPosition(0); - saveMenu.setLocation(RTEditorNew.TOPBAR); + saveMenu.setLocation(RTEditor.TOPBAR); - editor.setActionShortcut(key_S, saveAction, saveMenuAction); + super.setActionShortcut(key_S, saveAction, saveMenuAction); final AutoSaveAction autoSaveAction = new AutoSaveAction(i18n.t("Autosave"), NO_TEXT, NO_ICON); - final MenuCheckItemDescriptor autoSaveItem = new MenuCheckItemDescriptor(editor.getFileMenu(), autoSaveAction) { @Override + final MenuCheckItemDescriptor autoSaveItem = new MenuCheckItemDescriptor(super.getFileMenu(), autoSaveAction) { @Override public boolean isChecked() { //autoSaveItem.setChecked(autoSave); return autoSave; }}; - autoSaveItem.setLocation(RTEditorNew.TOPBAR); + autoSaveItem.setLocation(RTEditor.TOPBAR); final CloseAction closeAction = new CloseAction(i18n.t("Close"), NO_TEXT, NO_ICON); - final MenuItemDescriptor closeItem = new MenuItemDescriptor(editor.getFileMenu(), closeAction); - closeItem.setLocation(RTEditorNew.TOPBAR); + final MenuItemDescriptor closeItem = new MenuItemDescriptor(super.getFileMenu(), closeAction); + closeItem.setLocation(RTEditor.TOPBAR); final SaveCloseAction saveCloseAction = new SaveCloseAction(i18n.t("Save & Close"), NO_TEXT, NO_ICON); - final MenuItemDescriptor saveClose = new MenuItemDescriptor(editor.getFileMenu(), saveCloseAction); + final MenuItemDescriptor saveClose = new MenuItemDescriptor(super.getFileMenu(), saveCloseAction); final ButtonDescriptor saveCloseBtn = new ButtonDescriptor(saveCloseAction); - saveClose.setLocation(RTEditorNew.TOPBAR); - saveCloseBtn.setLocation(RTEditorNew.TOPBAR); + saveClose.setLocation(RTEditor.TOPBAR); + saveCloseBtn.setLocation(RTEditor.TOPBAR); - editor.addAction(saveMenu); - editor.addAction(saveBtn); - editor.addAction(autoSaveItem); - editor.addAction(saveClose); - editor.addAction(saveCloseBtn); - editor.addAction(closeItem); + super.addAction(saveMenu); + super.addAction(saveBtn); + super.addAction(autoSaveItem); + super.addAction(saveClose); + super.addAction(saveCloseBtn); + super.addAction(closeItem); } private void enableSaveBtn(final boolean enabled) { @@ -260,7 +279,7 @@ stateManager.removeBeforeStateChangeListener(beforeStateChg); stateManager.resumeTokenChange(); reset(); - editor.detach(); + super.detach(); onDoEditCancelled(); } @@ -294,15 +313,6 @@ } private void onDoSaveImpl() { - final String html = editor.getHtml(); - onSave.onEvent(html); + onSave.onEvent(super.getHtml()); } - - private void reset() { - timer.cancel(); - savePending = false; - saveCloseConfirmed = false; - enableSaveBtn(false); - editor.reset(); - } } Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorView.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorView.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorView.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -1,10 +1,10 @@ package org.ourproject.kune.platf.client.ui.rte.saving; -import org.ourproject.kune.platf.client.View; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorView; import com.calclab.suco.client.events.Listener0; -public interface RTESavingEditorView extends View { +public interface RTESavingEditorView extends RTEditorView { void askConfirmation(String confirmationTitle, String confirmationText, Listener0 onConfirm, Listener0 onCancel); } Modified: trunk/src/main/java/org/ourproject/kune/wiki/client/WikiClientActions.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/wiki/client/WikiClientActions.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/wiki/client/WikiClientActions.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -70,8 +70,8 @@ final String[] containersNoRoot = { TYPE_FOLDER }; final String[] contents = { TYPE_WIKIPAGE, TYPE_UPLOADEDFILE }; - String parentMenuTitle = i18n.t("Wikipage"); - String parentMenuTitleCtx = i18n.t("Wiki"); + final String parentMenuTitle = i18n.t("Wikipage"); + final String parentMenuTitleCtx = i18n.t("Wiki"); createNewContainerAction(TYPE_FOLDER, "images/nav/folder_add.png", i18n.t("New folder"), parentMenuTitleCtx, i18n.t("New"), i18n.t("New folder"), Position.ctx, TYPE_ROOT, TYPE_FOLDER); Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/AbstractFoldableContentActions.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/workspace/client/AbstractFoldableContentActions.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/workspace/client/AbstractFoldableContentActions.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -207,7 +207,7 @@ } protected void createDownloadActions(final String typeUploadedfile) { - ActionToolbarButtonDescriptor<StateToken> download = new ActionToolbarButtonDescriptor<StateToken>( + final ActionToolbarButtonDescriptor<StateToken> download = new ActionToolbarButtonDescriptor<StateToken>( AccessRolDTO.Viewer, CONTENT_TOPBAR, new Listener<StateToken>() { public void onEvent(final StateToken token) { downloadContent(token); @@ -218,7 +218,7 @@ download.setToolTip(i18n.t("Download this file")); download.setIconUrl("images/nav/download.png"); - ActionMenuItemDescriptor<StateToken> downloadCtx = new ActionMenuItemDescriptor<StateToken>( + final ActionMenuItemDescriptor<StateToken> downloadCtx = new ActionMenuItemDescriptor<StateToken>( AccessRolDTO.Viewer, new Listener<StateToken>() { public void onEvent(final StateToken token) { downloadContent(token); @@ -234,7 +234,7 @@ protected ActionToolbarButtonDescriptor<StateToken> createEditAction(final String fileMenuTitle, final String... registerInTypes) { - ActionToolbarButtonDescriptor<StateToken> editContent = new ActionToolbarButtonDescriptor<StateToken>( + final ActionToolbarButtonDescriptor<StateToken> editContent = new ActionToolbarButtonDescriptor<StateToken>( AccessRolDTO.Editor, CONTENT_TOPBAR, new Listener<StateToken>() { public void onEvent(final StateToken stateToken) { NotifyUser.showProgressProcessing(); @@ -298,7 +298,7 @@ } protected ActionMenuItemDescriptor<StateToken> createGoAction(final String... registerInTypes) { - ActionMenuItemDescriptor<StateToken> go = new ActionMenuItemDescriptor<StateToken>(AccessRolDTO.Viewer, + final ActionMenuItemDescriptor<StateToken> go = new ActionMenuItemDescriptor<StateToken>(AccessRolDTO.Viewer, new Listener<StateToken>() { public void onEvent(final StateToken token) { stateManager.gotoToken(token); @@ -312,7 +312,7 @@ } protected ActionToolbarButtonDescriptor<StateToken> createGoHomeAction(final String... registerInTypes) { - ActionToolbarButtonDescriptor<StateToken> goGroupHome = new ActionToolbarButtonDescriptor<StateToken>( + final ActionToolbarButtonDescriptor<StateToken> goGroupHome = new ActionToolbarButtonDescriptor<StateToken>( AccessRolDTO.Viewer, CONTEXT_TOPBAR, new Listener<StateToken>() { public void onEvent(final StateToken token) { stateManager.gotoToken(token.getGroup()); @@ -465,7 +465,7 @@ }, "ContentRadioStatus", new RadioMustBeChecked() { public boolean mustBeChecked() { if (session.getContainerState() instanceof StateContentDTO) { - ContentStatusDTO currentStatus = session.getContentState().getStatus(); + final ContentStatusDTO currentStatus = session.getContentState().getStatus(); return status.equals(currentStatus); } return false; @@ -478,10 +478,10 @@ } protected void createShowDeletedItems(final String parentMenuTitle, final String... registerInTypes) { - ActionToolbarMenuCheckItemDescriptor<StateToken> showDeletedItems = new ActionToolbarMenuCheckItemDescriptor<StateToken>( + final ActionToolbarMenuCheckItemDescriptor<StateToken> showDeletedItems = new ActionToolbarMenuCheckItemDescriptor<StateToken>( AccessRolDTO.Editor, CONTEXT_TOPBAR, new Listener0() { public void onEvent() { - boolean mustShow = !session.getCurrentUserInfo().getShowDeletedContent(); + final boolean mustShow = !session.getCurrentUserInfo().getShowDeletedContent(); session.getCurrentUserInfo().setShowDeletedContent(mustShow); if (!mustShow && session.isCurrentStateAContent() && session.getContentState().getStatus().equals(ContentStatusDTO.inTheDustbin)) { @@ -503,7 +503,7 @@ protected ActionToolbarMenuDescriptor<StateToken> createTranslateAction(final String fileMenuTitle, final String... registerInTypes) { - ActionToolbarMenuDescriptor<StateToken> translateContent = new ActionToolbarMenuDescriptor<StateToken>( + final ActionToolbarMenuDescriptor<StateToken> translateContent = new ActionToolbarMenuDescriptor<StateToken>( AccessRolDTO.Editor, CONTENT_TOPBAR, new Listener<StateToken>() { public void onEvent(final StateToken stateToken) { NotifyUser.important(i18n.t("Sorry, this functionality is currently in development")); @@ -543,7 +543,7 @@ } protected ActionToolbarButtonAndItemDescriptor<StateToken> createUploadMediaAction(final String... registerInTypes) { - ActionToolbarButtonAndItemDescriptor<StateToken> uploadMedia = createUploadAction(i18n.t("Upload media"), + final ActionToolbarButtonAndItemDescriptor<StateToken> uploadMedia = createUploadAction(i18n.t("Upload media"), "images/nav/upload.png", i18n.t("Upload some media (images, videos...)"), session.getGalleryPermittedExtensions()); contextActionRegistry.addAction(uploadMedia, registerInTypes); Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/WorkspaceModule.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/workspace/client/WorkspaceModule.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/workspace/client/WorkspaceModule.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -22,6 +22,7 @@ import org.ourproject.kune.chat.client.ChatEngine; import org.ourproject.kune.platf.client.actions.ActionManager; import org.ourproject.kune.platf.client.actions.toolbar.ActionToolbarPanel; +import org.ourproject.kune.platf.client.actions.ui.GuiBindingsRegister; import org.ourproject.kune.platf.client.app.ApplicationComponentGroup; import org.ourproject.kune.platf.client.app.EntityOptionsGroup; import org.ourproject.kune.platf.client.dto.StateToken; @@ -49,8 +50,9 @@ import org.ourproject.kune.platf.client.state.StateManager; import org.ourproject.kune.platf.client.ui.download.FileDownloadUtils; import org.ourproject.kune.platf.client.ui.noti.NotifyUser; +import org.ourproject.kune.platf.client.ui.palette.ColorWebSafePalette; import org.ourproject.kune.platf.client.ui.rte.TestRTEDialog; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorNew; +import org.ourproject.kune.platf.client.ui.rte.edithtml.EditHtmlDialog; import org.ourproject.kune.platf.client.ui.rte.img.RTEImgResources; import org.ourproject.kune.platf.client.ui.rte.insertimg.InsertImageDialog; import org.ourproject.kune.platf.client.ui.rte.insertimg.InsertImageGroup; @@ -59,7 +61,8 @@ import org.ourproject.kune.platf.client.ui.rte.insertmedia.InsertMediaDialog; import org.ourproject.kune.platf.client.ui.rte.insertmedia.InsertMediaGroup; import org.ourproject.kune.platf.client.ui.rte.insertmedia.abstractmedia.MediaUtils; -import org.ourproject.kune.platf.client.ui.rte.saving.RTESavingEditorPanel; +import org.ourproject.kune.platf.client.ui.rte.insertspecialchar.InsertSpecialCharDialog; +import org.ourproject.kune.platf.client.ui.rte.inserttable.InsertTableDialog; import org.ourproject.kune.platf.client.utils.DeferredCommandWrapper; import org.ourproject.kune.platf.client.utils.TimerWrapper; import org.ourproject.kune.workspace.client.cnt.ActionContentToolbar; @@ -76,6 +79,8 @@ import org.ourproject.kune.workspace.client.cxt.ContextPropEditorPresenter; import org.ourproject.kune.workspace.client.cxt.ContextPropEditorView; import org.ourproject.kune.workspace.client.editor.ContentEditor; +import org.ourproject.kune.workspace.client.editor.ContentEditorPanel; +import org.ourproject.kune.workspace.client.editor.ContentEditorPresenter; import org.ourproject.kune.workspace.client.editor.insertlocalimg.InsertImageLocal; import org.ourproject.kune.workspace.client.editor.insertlocalimg.InsertImageLocalPanel; import org.ourproject.kune.workspace.client.editor.insertlocalimg.InsertImageLocalPresenter; @@ -873,10 +878,16 @@ register(Singleton.class, new Factory<ContentEditor>(ContentEditor.class) { @Override public ContentEditor create() { - return new ContentEditor(i(RTEditorNew.class), true, i(I18nTranslationService.class), - i(StateManager.class), i(SiteSignOutLink.class), i(DeferredCommandWrapper.class), - i(RTEImgResources.class), i(WorkspaceSkeleton.class), i(TimerWrapper.class), - new RTESavingEditorPanel(), i(EntityTitle.class)); + final ContentEditorPresenter presenter = new ContentEditorPresenter(i(I18nTranslationService.class), + i(Session.class), i(RTEImgResources.class), p(InsertLinkDialog.class), + p(ColorWebSafePalette.class), p(EditHtmlDialog.class), p(InsertImageDialog.class), + p(InsertMediaDialog.class), p(InsertTableDialog.class), p(InsertSpecialCharDialog.class), + i(DeferredCommandWrapper.class), true, i(StateManager.class), i(SiteSignOutLink.class), + i(WorkspaceSkeleton.class), i(TimerWrapper.class), i(EntityTitle.class)); + final ContentEditorPanel panel = new ContentEditorPanel(presenter, i(I18nUITranslationService.class), + i(GlobalShortcutRegister.class), i(GuiBindingsRegister.class)); + presenter.init(panel); + return presenter; } }); register(NoDecoration.class, new Factory<ActionContextTopToolbar>(ActionContextTopToolbar.class) { Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditor.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditor.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditor.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -1,138 +1,16 @@ package org.ourproject.kune.workspace.client.editor; -import static org.ourproject.kune.platf.client.actions.AbstractExtendedAction.NO_ICON; -import static org.ourproject.kune.platf.client.actions.AbstractExtendedAction.NO_TEXT; +import org.ourproject.kune.platf.client.ui.rte.saving.RTESavingEditor; -import org.ourproject.kune.platf.client.actions.AbstractExtendedAction; -import org.ourproject.kune.platf.client.actions.Action; -import org.ourproject.kune.platf.client.actions.ActionEvent; -import org.ourproject.kune.platf.client.actions.KeyStroke; -import org.ourproject.kune.platf.client.actions.ui.ComplexToolbar; -import org.ourproject.kune.platf.client.actions.ui.MenuItemDescriptor; -import org.ourproject.kune.platf.client.i18n.I18nTranslationService; -import org.ourproject.kune.platf.client.shortcuts.Keyboard; -import org.ourproject.kune.platf.client.state.StateManager; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorNew; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorPanelNew; -import org.ourproject.kune.platf.client.ui.rte.img.RTEImgResources; -import org.ourproject.kune.platf.client.ui.rte.saving.RTESavingEditorPresenter; -import org.ourproject.kune.platf.client.ui.rte.saving.RTESavingEditorView; -import org.ourproject.kune.platf.client.utils.DeferredCommandWrapper; -import org.ourproject.kune.platf.client.utils.TimerWrapper; -import org.ourproject.kune.workspace.client.sitebar.sitesign.SiteSignOutLink; -import org.ourproject.kune.workspace.client.skel.Toolbar; -import org.ourproject.kune.workspace.client.skel.WorkspaceSkeleton; -import org.ourproject.kune.workspace.client.title.EntityTitle; +public interface ContentEditor extends RTESavingEditor { -import com.calclab.suco.client.events.Listener; -import com.calclab.suco.client.events.Listener0; -import com.google.gwt.libideas.resources.client.ImageResource; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.Window.ClosingEvent; -import com.google.gwt.user.client.Window.ClosingHandler; -import com.google.gwt.user.client.ui.VerticalPanel; -import com.gwtext.client.widgets.BoxComponent; -import com.gwtext.client.widgets.event.ContainerListenerAdapter; + /** + * Sets the "File" menu title (some times you want a "Post" or "Wikipage" + * menu instead of a "File" menu). + * + * @param title + * the new file menu title + */ + void setFileMenuTitle(String title); -public class ContentEditor extends RTESavingEditorPresenter { - - public class RenameAction extends AbstractExtendedAction { - public RenameAction(final String text, final String tooltip, final ImageResource icon) { - super(text, tooltip, icon); - } - - public void actionPerformed(final ActionEvent actionEvent) { - entityTitle.edit(); - } - } - - private final WorkspaceSkeleton ws; - private final VerticalPanel vp; - private final RTEditorNew basicEditor; - private final RTEditorPanelNew editorPanel; - private final ComplexToolbar topbar; - private final SiteSignOutLink siteSignOutLink; - private final I18nTranslationService i18n; - private final EntityTitle entityTitle; - private final ComplexToolbar sndbar; - - public ContentEditor(final RTEditorNew editor, final boolean autoSave, final I18nTranslationService i18n, - final StateManager stateManager, final SiteSignOutLink siteSignOutLink, - final DeferredCommandWrapper deferredCommandWrapper, final RTEImgResources imgResources, - final WorkspaceSkeleton ws, final TimerWrapper timer, final RTESavingEditorView view, - final EntityTitle entityTitle) { - super(editor, autoSave, i18n, stateManager, deferredCommandWrapper, imgResources, timer); - this.i18n = i18n; - this.siteSignOutLink = siteSignOutLink; - this.entityTitle = entityTitle; - super.init(view); - this.ws = ws; - Window.addWindowClosingHandler(new ClosingHandler() { - public void onWindowClosing(final ClosingEvent event) { - if (isSavePending()) { - event.setMessage(i18n.t("You have changes without save. Are you sure?")); - } - // onDoSaveAndClose(); - } - }); - vp = new VerticalPanel(); - basicEditor = super.getBasicEditor(); - addContentActions(); - editorPanel = (RTEditorPanelNew) basicEditor.getEditorArea(); - topbar = ((ComplexToolbar) basicEditor.getTopBar()); - sndbar = ((ComplexToolbar) basicEditor.getSndBar()); - vp.add(sndbar); - vp.add(editorPanel); - basicEditor.setExtended(true); - vp.setWidth("100%"); - ws.getEntityWorkspace().addContentListener(new ContainerListenerAdapter() { - @Override - public void onResize(final BoxComponent component, final int adjWidth, final int adjHeight, - final int rawWidth, final int rawHeight) { - adjHeight(adjHeight); - } - }); - - } - - @Override - public void edit(final String html, final Listener<String> onSave, final Listener0 onEditCancelled) { - final Toolbar contentTopBar = ws.getEntityWorkspace().getContentTopBar(); - contentTopBar.removeAll(); - contentTopBar.add(topbar); - ws.getEntityWorkspace().setContent(vp); - super.edit(html, onSave, onEditCancelled); - adjHeight(ws.getEntityWorkspace().getContentHeight()); - siteSignOutLink.addBeforeSignOut(getBeforeSavingListener()); - } - - public void setFileMenuTitle(final String fileMenuTitleNew) { - basicEditor.getFileMenu().setText(fileMenuTitleNew); - } - - @Override - protected void onCancelConfirmed() { - ws.getEntityWorkspace().clearContent(); - super.onCancelConfirmed(); - siteSignOutLink.addBeforeSignOut(getBeforeSavingListener()); - } - - private void addContentActions() { - final RenameAction renameAction = new RenameAction(i18n.t("Rename"), NO_TEXT, NO_ICON); - final MenuItemDescriptor renameItem = new MenuItemDescriptor(basicEditor.getFileMenu(), renameAction); - renameItem.setLocation(RTEditorNew.TOPBAR); - final KeyStroke key = KeyStroke.getKeyStroke(Keyboard.KEY_F2, 0); - renameAction.putValue(Action.ACCELERATOR_KEY, key); - basicEditor.setActionShortcut(key, renameAction); - basicEditor.addAction(renameItem); - } - - private void adjHeight(final int height) { - final int barHeight = sndbar.getOffsetHeight(); - final int newHeight = height - 20 - barHeight; - // Log.debug("Sndbar height: " + barHeight + " new height: " + - // newHeight); - editorPanel.adjustSize(newHeight); - vp.setCellHeight(editorPanel, "" + newHeight); - } } Added: trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditorPanel.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditorPanel.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditorPanel.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -0,0 +1,15 @@ +package org.ourproject.kune.workspace.client.editor; + +import org.ourproject.kune.platf.client.actions.ui.GuiBindingsRegister; +import org.ourproject.kune.platf.client.i18n.I18nUITranslationService; +import org.ourproject.kune.platf.client.shortcuts.GlobalShortcutRegister; +import org.ourproject.kune.platf.client.ui.rte.saving.RTESavingEditorPanel; + +public class ContentEditorPanel extends RTESavingEditorPanel implements ContentEditorView { + + public ContentEditorPanel(final ContentEditorPresenter presenter, final I18nUITranslationService i18n, + final GlobalShortcutRegister globalShortcutReg, final GuiBindingsRegister bindReg) { + super(presenter, i18n, globalShortcutReg, bindReg); + } + +} Copied: trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditorPresenter.java (from rev 1125, trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditor.java) =================================================================== --- trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditor.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditorPresenter.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -0,0 +1,152 @@ +package org.ourproject.kune.workspace.client.editor; + +import static org.ourproject.kune.platf.client.actions.AbstractExtendedAction.NO_ICON; +import static org.ourproject.kune.platf.client.actions.AbstractExtendedAction.NO_TEXT; + +import org.ourproject.kune.platf.client.actions.AbstractExtendedAction; +import org.ourproject.kune.platf.client.actions.Action; +import org.ourproject.kune.platf.client.actions.ActionEvent; +import org.ourproject.kune.platf.client.actions.KeyStroke; +import org.ourproject.kune.platf.client.actions.ui.ComplexToolbar; +import org.ourproject.kune.platf.client.actions.ui.MenuItemDescriptor; +import org.ourproject.kune.platf.client.i18n.I18nTranslationService; +import org.ourproject.kune.platf.client.shortcuts.Keyboard; +import org.ourproject.kune.platf.client.state.Session; +import org.ourproject.kune.platf.client.state.StateManager; +import org.ourproject.kune.platf.client.ui.palette.ColorWebSafePalette; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditor; +import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorPanel; +import org.ourproject.kune.platf.client.ui.rte.edithtml.EditHtmlDialog; +import org.ourproject.kune.platf.client.ui.rte.img.RTEImgResources; +import org.ourproject.kune.platf.client.ui.rte.insertimg.InsertImageDialog; +import org.ourproject.kune.platf.client.ui.rte.insertlink.InsertLinkDialog; +import org.ourproject.kune.platf.client.ui.rte.insertmedia.InsertMediaDialog; +import org.ourproject.kune.platf.client.ui.rte.insertspecialchar.InsertSpecialCharDialog; +import org.ourproject.kune.platf.client.ui.rte.inserttable.InsertTableDialog; +import org.ourproject.kune.platf.client.ui.rte.saving.RTESavingEditorPresenter; +import org.ourproject.kune.platf.client.utils.DeferredCommandWrapper; +import org.ourproject.kune.platf.client.utils.TimerWrapper; +import org.ourproject.kune.workspace.client.sitebar.sitesign.SiteSignOutLink; +import org.ourproject.kune.workspace.client.skel.Toolbar; +import org.ourproject.kune.workspace.client.skel.WorkspaceSkeleton; +import org.ourproject.kune.workspace.client.title.EntityTitle; + +import com.calclab.suco.client.events.Listener; +import com.calclab.suco.client.events.Listener0; +import com.calclab.suco.client.ioc.Provider; +import com.google.gwt.libideas.resources.client.ImageResource; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.Window.ClosingEvent; +import com.google.gwt.user.client.Window.ClosingHandler; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.gwtext.client.widgets.BoxComponent; +import com.gwtext.client.widgets.event.ContainerListenerAdapter; + +public class ContentEditorPresenter extends RTESavingEditorPresenter implements ContentEditor { + + public class RenameAction extends AbstractExtendedAction { + public RenameAction(final String text, final String tooltip, final ImageResource icon) { + super(text, tooltip, icon); + } + + public void actionPerformed(final ActionEvent actionEvent) { + entityTitle.edit(); + } + } + + private final WorkspaceSkeleton wspace; + private VerticalPanel vpanel; + private RTEditorPanel editorPanel; + private final SiteSignOutLink siteSignOutLink; + private final I18nTranslationService i18n; + private final EntityTitle entityTitle; + private ComplexToolbar topbar; + private ComplexToolbar sndbar; + + public ContentEditorPresenter(final I18nTranslationService i18n, final Session session, + final RTEImgResources imgResources, final Provider<InsertLinkDialog> insLinkDialog, + final Provider<ColorWebSafePalette> palette, final Provider<EditHtmlDialog> editHtmlDialog, + final Provider<InsertImageDialog> insertImageDialog, final Provider<InsertMediaDialog> insertMediaDialog, + final Provider<InsertTableDialog> insertTableDialog, final Provider<InsertSpecialCharDialog> insCharDialog, + final DeferredCommandWrapper deferred, final boolean autoSave, final StateManager stateManager, + final SiteSignOutLink siteSignOutLink, final WorkspaceSkeleton wspace, final TimerWrapper timer, + final EntityTitle entityTitle) { + super(i18n, session, imgResources, insLinkDialog, palette, editHtmlDialog, insertImageDialog, + insertMediaDialog, insertTableDialog, insCharDialog, deferred, autoSave, stateManager, timer); + super.setExtended(true); + this.i18n = i18n; + this.siteSignOutLink = siteSignOutLink; + this.entityTitle = entityTitle; + this.wspace = wspace; + Window.addWindowClosingHandler(new ClosingHandler() { + public void onWindowClosing(final ClosingEvent event) { + if (isSavePending()) { + event.setMessage(i18n.t("You have changes without save. Are you sure?")); + } + // onDoSaveAndClose(); + } + }); + wspace.getEntityWorkspace().addContentListener(new ContainerListenerAdapter() { + @Override + public void onResize(final BoxComponent component, final int adjWidth, final int adjHeight, + final int rawWidth, final int rawHeight) { + adjHeight(adjHeight); + } + }); + + } + + @Override + public void edit(final String html, final Listener<String> onSave, final Listener0 onEditCancelled) { + super.edit(html, onSave, onEditCancelled); + final Toolbar contentTopBar = wspace.getEntityWorkspace().getContentTopBar(); + contentTopBar.removeAll(); + contentTopBar.add(topbar); + wspace.getEntityWorkspace().setContent(vpanel); + adjHeight(wspace.getEntityWorkspace().getContentHeight()); + siteSignOutLink.addBeforeSignOut(getBeforeSavingListener()); + } + + public void init(final ContentEditorView view) { + super.init(view); + addContentActions(); + vpanel = new VerticalPanel(); + editorPanel = (RTEditorPanel) super.getEditorArea(); + topbar = ((ComplexToolbar) super.getTopBar()); + sndbar = ((ComplexToolbar) super.getSndBar()); + vpanel.add(sndbar); + vpanel.add(editorPanel); + vpanel.setWidth("100%"); + } + + public void setFileMenuTitle(final String fileMenuTitleNew) { + super.getFileMenu().setText(fileMenuTitleNew); + } + + @Override + protected void onCancelConfirmed() { + wspace.getEntityWorkspace().clearContent(); + super.onCancelConfirmed(); + siteSignOutLink.addBeforeSignOut(getBeforeSavingListener()); + } + + private void addContentActions() { + final RenameAction renameAction = new RenameAction(i18n.t("Rename"), NO_TEXT, NO_ICON); + final MenuItemDescriptor renameItem = new MenuItemDescriptor(super.getFileMenu(), renameAction); + renameItem.setLocation(RTEditor.TOPBAR); + final KeyStroke key = KeyStroke.getKeyStroke(Keyboard.KEY_F2, 0); + renameAction.putValue(Action.ACCELERATOR_KEY, key); + super.setActionShortcut(key, renameAction); + super.addAction(renameItem); + } + + private void adjHeight(final int height) { + final int barHeight = sndbar.getOffsetHeight(); + final int newHeight = height - 20 - barHeight; + // Log.debug("Sndbar height: " + barHeight + " new height: " + + // newHeight); + editorPanel.adjustSize(newHeight); + vpanel.setCellHeight(editorPanel, String.valueOf(newHeight)); + } + +} Added: trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditorView.java =================================================================== --- trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditorView.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditorView.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -0,0 +1,7 @@ +package org.ourproject.kune.workspace.client.editor; + +import org.ourproject.kune.platf.client.ui.rte.saving.RTESavingEditorView; + +public interface ContentEditorView extends RTESavingEditorView { + +} Modified: 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-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/main/java/org/ourproject/kune/workspace/client/hello/HelloWorldModule.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -20,25 +20,32 @@ 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.dto.AccessRolDTO; -import org.ourproject.kune.platf.client.dto.UserSimpleDTO; +import org.ourproject.kune.platf.client.actions.AbstractAction; +import org.ourproject.kune.platf.client.actions.Action; +import org.ourproject.kune.platf.client.actions.ActionEvent; +import org.ourproject.kune.platf.client.actions.ui.MenuCheckItemDescriptor; +import org.ourproject.kune.platf.client.actions.ui.MenuDescriptor; +import org.ourproject.kune.platf.client.actions.ui.MenuItemDescriptor; +import org.ourproject.kune.platf.client.actions.ui.MenuRadioItemDescriptor; +import org.ourproject.kune.platf.client.actions.ui.MenuSeparatorDescriptor; +import org.ourproject.kune.platf.client.actions.ui.PushButtonDescriptor; import org.ourproject.kune.platf.client.i18n.I18nTranslationService; import org.ourproject.kune.platf.client.i18n.I18nTranslationServiceMocked; import org.ourproject.kune.platf.client.services.AbstractExtendedModule; import org.ourproject.kune.platf.client.shortcuts.GlobalShortcutRegister; import org.ourproject.kune.platf.client.shortcuts.ShortcutDescriptor; +import org.ourproject.kune.platf.client.ui.img.ImgResources; import org.ourproject.kune.platf.client.ui.noti.NotifyUser; -import org.ourproject.kune.workspace.client.AbstractFoldableContentActions; +import org.ourproject.kune.workspace.client.editor.ContentEditor; +import org.ourproject.kune.workspace.client.hello.HelloWorldModule.HelloWorldPanel.HelloWorldPresenter; import org.ourproject.kune.workspace.client.skel.WorkspaceSkeleton; -import org.ourproject.kune.workspace.client.socialnet.UserActionRegistry; import com.allen_sauer.gwt.log.client.Log; -import com.calclab.suco.client.events.Listener; import com.calclab.suco.client.events.Listener0; import com.calclab.suco.client.ioc.Provider; import com.calclab.suco.client.ioc.decorator.Singleton; import com.calclab.suco.client.ioc.module.Factory; +import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.Label; /** @@ -70,69 +77,121 @@ * */ public static class HelloWorldPanel implements HelloWorldView { - private final I18nTranslationService i18n; + public static class HelloWorldPresenter implements HelloWorld { - 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!"))); - } + private HelloWorldView view; - public void showMessage() { - /** i18n use with parameters **/ - NotifyUser.info(i18n.t("Hello [%s]!", "world")); - } - } + public HelloWorldPresenter(final I18nTranslationService i18n, + final Provider<ContentEditor> contentEditorProv, final ImgResources img) { + // Or add some actions to the general content editor: + createActions(contentEditorProv, img, i18n); + } - public static class HelloWorldPresenter implements HelloWorld { + public View getView() { + return view; + } - private HelloWorldView view; - private final Provider<UserActionRegistry> actionRegistry; - private final I18nTranslationService i18n; + public void init(final HelloWorldView view) { + this.view = view; + } - public HelloWorldPresenter(final I18nTranslationService i18n, final Provider<UserActionRegistry> actionRegistry) { - this.i18n = i18n; - this.actionRegistry = actionRegistry; - createActions(); - } + /** + * We can add some gui action items to the content editor + * + * Summary) + * + * @param i18n + **/ + private void createActions(final Provider<ContentEditor> contentEditorProv, final ImgResources img, + final I18nTranslationService i18n) { - public View getView() { - return view; - } + final HelloWorldAction action = new HelloWorldAction(img); - public void init(final HelloWorldView view) { - this.view = view; + // We describe some gui items and all will use the same action: + + final PushButtonDescriptor btn = new PushButtonDescriptor(action); + + // We no use i18n.t() in most of these gui widgets but it's is + // recommended the use in real code + final MenuDescriptor menu = new MenuDescriptor(i18n.t("File"), "File menu tooltip"); + + final MenuItemDescriptor menuitem = new MenuItemDescriptor(menu, action); + final MenuItemDescriptor menuitem2 = new MenuItemDescriptor(menu, action); + + // A submenu + final MenuDescriptor submenu = new MenuDescriptor("Options", "Submenu tooltip"); + submenu.setParent(menu); + + // A menu check item + final MenuItemDescriptor menuitem3 = new MenuItemDescriptor(submenu, action); + final MenuCheckItemDescriptor menuitem4 = new MenuCheckItemDescriptor(submenu, action); + menuitem4.setChecked(true); + + // Some menu radio items + final String radioGroup = "helloworldradiogroup"; + final MenuRadioItemDescriptor menuitem5 = new MenuRadioItemDescriptor(submenu, action, radioGroup); + final MenuRadioItemDescriptor menuitem6 = new MenuRadioItemDescriptor(submenu, action, radioGroup); + menuitem5.setChecked(true); + + // We can define also some menu separators + final MenuSeparatorDescriptor menuSeparator = new MenuSeparatorDescriptor(menu); + final MenuSeparatorDescriptor otherSeparator = new MenuSeparatorDescriptor(submenu); + + // 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. + final ContentEditor contentEditor = contentEditorProv.get(); + + // We want to add some items to the topbar and other to the + // second bar + contentEditor.setLocation(ContentEditor.TOPBAR, menu, menuitem, menuSeparator, menuitem2, submenu, + menuitem3, menuitem4, otherSeparator, menuitem5, menuitem6); + contentEditor.setLocation(ContentEditor.SNDBAR, btn); + + // And finally we add the action descriptors to the editor: + contentEditor.addActions(btn, menu, menuitem); + + // Also individually + contentEditor.addAction(menuSeparator); + + // It's important to add the menus before its menu items + contentEditor.addActions(menuitem2, submenu, menuitem3, menuitem4, otherSeparator, menuitem5, menuitem6); + + // We can change descriptors properties and are changed in the + // UI + btn.setPushed(true); + + // After some time we can change the common action or some other + // properties + new Timer() { + @Override + public void run() { + // The text of the action (in the menu or in the button) + action.putValue(Action.NAME, "hello world new"); + // And the tooltip (on over message): + action.putValue(Action.SHORT_DESCRIPTION, "hello world new"); + btn.setPushed(false); + } + }.schedule(10000); + } } - /** - * We add an menu action to users menus (like the buddies in Buddies - * Summary) - **/ - private void createActions() { - final ActionToolbarMenuDescriptor<UserSimpleDTO> helloWorldBuddiesAction = new ActionToolbarMenuDescriptor<UserSimpleDTO>( - AccessRolDTO.Viewer, AbstractFoldableContentActions.CONTENT_TOPBAR, new Listener<UserSimpleDTO>() { - public void onEvent(final 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"); + private final I18nTranslationService i18n; - // 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); + public HelloWorldPanel(final HelloWorldPresenter presenter, final WorkspaceSkeleton wspace, + final I18nTranslationService i18n) { + this.i18n = i18n; + // We can directly insert something in the workspace skeleton + wspace.getEntityWorkspace().getSubTitle().add(new Label(i18n.t("Hello world!"))); } + + public void showMessage() { + /** i18n use with parameters **/ + NotifyUser.info(i18n.t("Hello [%s]!", "world")); + } } /** @@ -143,6 +202,22 @@ void showMessage(); } + static class HelloWorldAction extends AbstractAction { + public HelloWorldAction(final ImgResources img) { + super(); + super.putValue(Action.NAME, "helloword"); + super.putValue(Action.SHORT_DESCRIPTION, "helloworld item"); + super.putValue(Action.SMALL_ICON, img.info()); + } + + public void actionPerformed(final ActionEvent actionEvent) { + if (actionEvent.getEvent().getCtrlKey()) { + NotifyUser.info("Hello world action fired with ctrl key pressed"); + } + NotifyUser.info("Hello world action fired"); + } + } + /** * 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 @@ -175,7 +250,7 @@ @Override public HelloWorld create() { final HelloWorldPresenter presenter = new HelloWorldPresenter(i(I18nTranslationServiceMocked.class), - p(UserActionRegistry.class)); + p(ContentEditor.class), i(ImgResources.class)); final HelloWorldPanel panel = new HelloWorldPanel(presenter, i(WorkspaceSkeleton.class), i(I18nTranslationServiceMocked.class)); presenter.init(panel); @@ -213,10 +288,5 @@ NotifyUser.info("Global Ctrl+S pressed"); } }); - - // And because nobody use this module, we get the class (to force the - // creation of the - // Helloworld instance): - // i(HelloWorld.class); } } \ No newline at end of file Modified: trunk/src/test/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenterTest.java =================================================================== --- trunk/src/test/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenterTest.java 2009-06-11 18:28:19 UTC (rev 1125) +++ trunk/src/test/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenterTest.java 2009-06-11 22:14:06 UTC (rev 1126) @@ -11,7 +11,6 @@ import org.ourproject.kune.platf.client.i18n.I18nTranslationServiceMocked; import org.ourproject.kune.platf.client.i18n.Resources; import org.ourproject.kune.platf.client.state.StateManager; -import org.ourproject.kune.platf.client.ui.rte.basic.RTEditorNew; import org.ourproject.kune.platf.client.ui.rte.img.RTEImgResources; import org.ourproject.kune.platf.client.utils.DeferredCommandWrapper; import org.ourproject.kune.platf.client.utils.TimerWrapper; @@ -28,9 +27,7 @@ private MockedListener0 cancelListener; private StateManager stateManager; private DeferredCommandWrapper deferredCommandWrapper; - private RTEditorNew rteEditor; private TimerWrapper timer; - // private ComplexToolbar sndbar; private RTESavingEditorView view; @Before @@ -39,17 +36,16 @@ new Resources(i18n); stateManager = Mockito.mock(StateManager.class); deferredCommandWrapper = Mockito.mock(DeferredCommandWrapper.class); - rteEditor = Mockito.mock(RTEditorNew.class); + final RTEImgResources imgResources = Mockito.mock(RTEImgResources.class); - final ImageResource imageResource = Mockito.mock(ImageResource.class); - Mockito.when(imageResource.getName()).thenReturn("save"); - Mockito.when(imgResources.save()).thenReturn(imageResource); - // sndbar = Mockito.mock(ComplexToolbar.class); - // Mockito.when(rteEditor.getSndBar()).thenReturn(sndbar); + final ImageResource img = Mockito.mock(ImageResource.class); + Mockito.when(img.getName()).thenReturn("save"); + Mockito.when(imgResources.save()).thenReturn(img); timer = Mockito.mock(TimerWrapper.class); view = Mockito.mock(RTESavingEditorView.class); - presenter = new RTESavingEditorPresenter(rteEditor, true, i18n, stateManager, deferredCommandWrapper, - imgResources, timer); + + presenter = new RTESavingEditorPresenter(i18n, null, imgResources, null, null, null, null, null, null, null, + deferredCommandWrapper, true, stateManager, timer); presenter.init(view); saveListener = new MockedListener<String>(); cancelListener = new MockedListener0(); @@ -100,12 +96,10 @@ public void initialEditWithEditionAndSave() { presenter.edit("Text to edit", saveListener, cancelListener); final String textModified = "Text modified"; - Mockito.when(rteEditor.getHtml()).thenReturn(textModified); presenter.onEdit(); presenter.onDoSave(); presenter.onSavedSuccessful(); checkSaveBtnDisabled(); - assertTrue(saveListener.isCalledWithEquals(textModified)); assertTrue(cancelListener.isNotCalled()); } @@ -113,7 +107,6 @@ public void testSavePendingAndCancel() { presenter.edit("Text to edit", saveListener, cancelListener); final String textModified = "Text modified"; - Mockito.when(rteEditor.getHtml()).thenReturn(textModified); presenter.onEdit(); presenter.onCancel(); presenter.onCancelConfirmed(); @@ -125,7 +118,6 @@ public void testSavePendingAndSaveFails() { presenter.edit("Text to edit", saveListener, cancelListener); final String textModified = "Text modified"; - Mockito.when(rteEditor.getHtml()).thenReturn(textModified); presenter.onEdit(); presenter.onDoSave(); presenter.onSaveFailed();
participants (1)
-
vjrj