r1308 - in trunk/src/main/java/cc/kune: common/client/actions/gwtui common/client/tooltip common/client/utils core/client/sitebar/spaces core/client/sn core/client/state gspace/client/ui/footer/license
Author: vjrj_ Date: 2011-04-13 10:48:35 +0200 (Wed, 13 Apr 2011) New Revision: 1308 Added: trunk/src/main/java/cc/kune/common/client/tooltip/TooltipTimers.java trunk/src/main/java/cc/kune/common/client/tooltip/TooltipTimersTest.java Modified: trunk/src/main/java/cc/kune/common/client/actions/gwtui/AbstractGwtMenuItemGui.java trunk/src/main/java/cc/kune/common/client/actions/gwtui/GwtMenuGui.java trunk/src/main/java/cc/kune/common/client/tooltip/Tooltip.java trunk/src/main/java/cc/kune/common/client/utils/TimerWrapper.java trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorPresenter.java trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorViewImpl.java trunk/src/main/java/cc/kune/core/client/sn/AbstractSNPanel.java trunk/src/main/java/cc/kune/core/client/sn/GroupSNPanel.java trunk/src/main/java/cc/kune/core/client/sn/UserSNPanel.java trunk/src/main/java/cc/kune/core/client/state/SiteTokenListeners.java trunk/src/main/java/cc/kune/gspace/client/ui/footer/license/EntityLicensePanel.java Log: CLOSED - # 37: Implement a GWT Tooltip widget similar to qtip or others http://kune.ourproject.org/issues/ticket/37 Modified: trunk/src/main/java/cc/kune/common/client/actions/gwtui/AbstractGwtMenuItemGui.java =================================================================== --- trunk/src/main/java/cc/kune/common/client/actions/gwtui/AbstractGwtMenuItemGui.java 2011-04-12 18:38:37 UTC (rev 1307) +++ trunk/src/main/java/cc/kune/common/client/actions/gwtui/AbstractGwtMenuItemGui.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -34,6 +34,7 @@ import cc.kune.common.client.actions.ui.descrip.MenuTitleItemDescriptor; import cc.kune.common.client.errors.UIException; import cc.kune.common.client.resources.CommonIconResources; +import cc.kune.common.client.tooltip.Tooltip; import cc.kune.common.client.ui.IconLabel; import com.google.gwt.resources.client.ImageResource; @@ -209,7 +210,9 @@ @Override protected void setToolTipText(final String text) { if (text != null) { - item.setTitle(text); + final KeyStroke key = (KeyStroke) descriptor.getValue(Action.ACCELERATOR_KEY); + Tooltip.to(iconLabel, key == null ? text : text + key.toString()); + layout(); } } Modified: trunk/src/main/java/cc/kune/common/client/actions/gwtui/GwtMenuGui.java =================================================================== --- trunk/src/main/java/cc/kune/common/client/actions/gwtui/GwtMenuGui.java 2011-04-12 18:38:37 UTC (rev 1307) +++ trunk/src/main/java/cc/kune/common/client/actions/gwtui/GwtMenuGui.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -23,6 +23,7 @@ import cc.kune.common.client.actions.ui.ParentWidget; import cc.kune.common.client.actions.ui.descrip.GuiActionDescrip; import cc.kune.common.client.actions.ui.descrip.MenuDescriptor; +import cc.kune.common.client.tooltip.Tooltip; import cc.kune.common.client.ui.IconLabel; import com.google.gwt.event.dom.client.ClickEvent; @@ -118,8 +119,7 @@ @Override public void setToolTipText(final String tooltip) { if (notStandAlone) { - // button.setTooltip(tooltip); - button.setTitle(tooltip); + Tooltip.to(button, tooltip); } } Modified: trunk/src/main/java/cc/kune/common/client/tooltip/Tooltip.java =================================================================== --- trunk/src/main/java/cc/kune/common/client/tooltip/Tooltip.java 2011-04-12 18:38:37 UTC (rev 1307) +++ trunk/src/main/java/cc/kune/common/client/tooltip/Tooltip.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -1,6 +1,8 @@ package cc.kune.common.client.tooltip; import cc.kune.common.client.utils.TextUtils; +import cc.kune.common.client.utils.TimerWrapper; +import cc.kune.common.client.utils.TimerWrapper.Executer; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Style.Unit; @@ -10,7 +12,6 @@ import com.google.gwt.event.dom.client.MouseOverHandler; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HTMLPanel; @@ -50,9 +51,8 @@ FlowPanel content; @UiField FlowPanel flow; - private final boolean isOver; private Widget ofWidget; - private final Timer timer; + private final TooltipTimers timers; @UiField InlineLabel title; @UiField @@ -62,14 +62,21 @@ super.add(uiBinder.createAndBindUi(this)); super.setAutoHideEnabled(false); super.setAnimationEnabled(false); - isOver = false; - timer = new Timer() { - + final TimerWrapper overTimer = new TimerWrapper(); + overTimer.configure(new Executer() { @Override - public void run() { + public void execute() { + show(); + } + }); + final TimerWrapper outTimer = new TimerWrapper(); + outTimer.configure(new Executer() { + @Override + public void execute() { hide(); } - }; + }); + timers = new TooltipTimers(overTimer, outTimer); } protected int getHeight() { @@ -85,7 +92,7 @@ content.add(widget); } - private void setText(final String text) { + public void setText(final String text) { content.clear(); content.add(new Label(text)); } @@ -140,14 +147,13 @@ ofWidget.addDomHandler(new MouseOverHandler() { @Override public void onMouseOver(final MouseOverEvent event) { - timer.cancel(); - show(); + timers.onOver(); } }, MouseOverEvent.getType()); ofWidget.addDomHandler(new MouseOutHandler() { @Override public void onMouseOut(final MouseOutEvent event) { - timer.schedule(750); + timers.onOut(); } }, MouseOutEvent.getType()); } Added: trunk/src/main/java/cc/kune/common/client/tooltip/TooltipTimers.java =================================================================== --- trunk/src/main/java/cc/kune/common/client/tooltip/TooltipTimers.java (rev 0) +++ trunk/src/main/java/cc/kune/common/client/tooltip/TooltipTimers.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -0,0 +1,32 @@ +package cc.kune.common.client.tooltip; + +import cc.kune.common.client.utils.TimerWrapper; + +public class TooltipTimers { + + private final TimerWrapper hideTimer; + private final TimerWrapper showTimer; + + public TooltipTimers(final TimerWrapper showTimer, final TimerWrapper hideTimer) { + this.showTimer = showTimer; + this.hideTimer = hideTimer; + } + + public void onOut() { + if (showTimer.isScheduled()) { + showTimer.cancel(); + } + if (!hideTimer.isScheduled()) { + hideTimer.schedule(650); + } + } + + public void onOver() { + if (!showTimer.isScheduled()) { + showTimer.schedule(500); + } + if (hideTimer.isScheduled()) { + hideTimer.cancel(); + } + } +} Property changes on: trunk/src/main/java/cc/kune/common/client/tooltip/TooltipTimers.java ___________________________________________________________________ Name: svn:mime-type + text/plain Added: trunk/src/main/java/cc/kune/common/client/tooltip/TooltipTimersTest.java =================================================================== --- trunk/src/main/java/cc/kune/common/client/tooltip/TooltipTimersTest.java (rev 0) +++ trunk/src/main/java/cc/kune/common/client/tooltip/TooltipTimersTest.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -0,0 +1,104 @@ +package cc.kune.common.client.tooltip; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import cc.kune.common.client.utils.TimerWrapper; + +public class TooltipTimersTest { + private TimerWrapper hideTimer; + protected boolean hideTimerScheduled = false; + private TimerWrapper showTimer; + protected boolean showTimerScheduled = false; + private TooltipTimers timers; + + @Before + public void before() { + showTimer = Mockito.mock(TimerWrapper.class); + hideTimer = Mockito.mock(TimerWrapper.class); + timers = new TooltipTimers(showTimer, hideTimer); + Mockito.doAnswer(new Answer<Object>() { + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable { + showTimerScheduled = true; + return null; + } + }).when(showTimer).schedule(Mockito.anyInt()); + Mockito.doAnswer(new Answer<Object>() { + + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable { + return showTimerScheduled; + } + }).when(showTimer).isScheduled(); + Mockito.doAnswer(new Answer<Object>() { + + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable { + showTimerScheduled = false; + return null; + } + }).when(showTimer).cancel(); + Mockito.doAnswer(new Answer<Object>() { + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable { + hideTimerScheduled = true; + return null; + } + }).when(hideTimer).schedule(Mockito.anyInt()); + Mockito.doAnswer(new Answer<Object>() { + + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable { + return hideTimerScheduled; + } + }).when(hideTimer).isScheduled(); + Mockito.doAnswer(new Answer<Object>() { + + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable { + hideTimerScheduled = false; + return null; + } + }).when(hideTimer).cancel(); + } + + @Test + public void testSeveralOverAndOutsOnlyOneTimerEach() { + timers.onOver(); + timers.onOver(); + timers.onOver(); + timers.onOut(); + timers.onOut(); + Mockito.verify(showTimer, Mockito.times(1)).schedule(Mockito.anyInt()); + Mockito.verify(showTimer, Mockito.times(1)).cancel(); + Mockito.verify(hideTimer, Mockito.times(1)).schedule(Mockito.anyInt()); + } + + @Test + public void testSeveralOverOnlyOneTimer() { + timers.onOver(); + timers.onOver(); + Mockito.verify(showTimer, Mockito.times(1)).schedule(Mockito.anyInt()); + Mockito.verify(hideTimer, Mockito.times(0)).cancel(); + } + + @Test + public void testSeveralOverOutsAndOverOnlyOneTimerEach() { + timers.onOver(); + timers.onOver(); + timers.onOver(); + timers.onOut(); + timers.onOut(); + timers.onOver(); + timers.onOver(); + timers.onOver(); + Mockito.verify(showTimer, Mockito.times(2)).schedule(Mockito.anyInt()); + Mockito.verify(showTimer, Mockito.times(1)).cancel(); + Mockito.verify(hideTimer, Mockito.times(1)).schedule(Mockito.anyInt()); + Mockito.verify(hideTimer, Mockito.times(1)).cancel(); + } +} Property changes on: trunk/src/main/java/cc/kune/common/client/tooltip/TooltipTimersTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Modified: trunk/src/main/java/cc/kune/common/client/utils/TimerWrapper.java =================================================================== --- trunk/src/main/java/cc/kune/common/client/utils/TimerWrapper.java 2011-04-12 18:38:37 UTC (rev 1307) +++ trunk/src/main/java/cc/kune/common/client/utils/TimerWrapper.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -29,12 +29,15 @@ void execute(); } + private boolean isScheduled; private Timer timer; public TimerWrapper() { + isScheduled = false; } public void cancel() { + isScheduled = false; timer.cancel(); } @@ -42,20 +45,27 @@ timer = new Timer() { @Override public void run() { + isScheduled = false; onTime.execute(); } }; } + public boolean isScheduled() { + return isScheduled; + } + public void run() { timer.run(); } public void schedule(final int delayMillis) { + isScheduled = true; timer.schedule(delayMillis); } public void scheduleRepeating(final int delayMillis) { + isScheduled = true; timer.scheduleRepeating(delayMillis); } } Modified: trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorPresenter.java =================================================================== --- trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorPresenter.java 2011-04-12 18:38:37 UTC (rev 1307) +++ trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorPresenter.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -57,8 +57,6 @@ HasClickHandlers getUserBtn(); - void hideTooltip(); - void setGroupBtnDown(boolean down); void setHomeBtnDown(boolean down); @@ -66,8 +64,6 @@ void setPublicBtnDown(boolean down); void setUserBtnDown(boolean down); - - void showTooltip(); } private final WsArmor armor; @@ -221,8 +217,4 @@ protected void revealInParent() { RevealRootContentEvent.fire(this, this); } - - public void showTooltip() { - getView().showTooltip(); - } } \ No newline at end of file Modified: trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorViewImpl.java =================================================================== --- trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorViewImpl.java 2011-04-12 18:38:37 UTC (rev 1307) +++ trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorViewImpl.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -29,10 +29,7 @@ import com.google.gwt.event.dom.client.HasClickHandlers; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.Image; -import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.ToggleButton; import com.google.gwt.user.client.ui.Widget; import com.google.inject.Inject; @@ -50,27 +47,19 @@ HorizontalPanel panel; @UiField ToggleButton publicButton; - private final Tooltip tooltip; @UiField ToggleButton userButton; @Inject public SpaceSelectorViewImpl(final WsArmor armor, final I18nTranslationService i18n, final WsArmorResources res) { armor.getSitebar().insert(uiBinder.createAndBindUi(this), 0); - final Grid grid = new Grid(4, 2); - grid.setWidget(0, 1, new Label(i18n.t("Home page of this site"))); - grid.setWidget(1, 1, new Label(i18n.t("User space: it shows a list of all your documents and contents " - + "in which you participate"))); - grid.setWidget(2, 1, new Label(i18n.t("Group and personal space: Where you can create " - + "and publish contents for your personal or group web spaces"))); - grid.setWidget(3, 1, new Label(i18n.t("Public space: In this space you can see a preview of how the Personal o" - + "r Group Space looks like on the web, outside this site"))); - grid.setWidget(0, 0, new Image(res.homeSpaceEnabled())); - grid.setWidget(1, 0, new Image(res.userSpaceEnabled())); - grid.setWidget(2, 0, new Image(res.groupSpaceEnabled())); - grid.setWidget(3, 0, new Image(res.publicSpaceEnabled())); - grid.addStyleName("k-space-tooltip"); - tooltip = Tooltip.to(panel, grid); + Tooltip.to(homeButton, i18n.t("Your home page in this site")); + Tooltip.to(userButton, i18n.t("User space: it shows a list of all your documents and contents " + + "in which you participate")); + Tooltip.to(groupButton, i18n.t("Group and personal space: Where you can create " + + "and publish contents for your personal or group web spaces")); + Tooltip.to(publicButton, i18n.t("Public space: In this space you can see a preview of how the Personal o" + + "r Group Space looks like on the web, outside this site")); } @Override @@ -99,11 +88,6 @@ } @Override - public void hideTooltip() { - tooltip.hide(); - } - - @Override public void setGroupBtnDown(final boolean down) { groupButton.setDown(down); } @@ -122,9 +106,4 @@ public void setUserBtnDown(final boolean down) { userButton.setDown(down); } - - @Override - public void showTooltip() { - tooltip.show(); - } } Modified: trunk/src/main/java/cc/kune/core/client/sn/AbstractSNPanel.java =================================================================== --- trunk/src/main/java/cc/kune/core/client/sn/AbstractSNPanel.java 2011-04-12 18:38:37 UTC (rev 1307) +++ trunk/src/main/java/cc/kune/core/client/sn/AbstractSNPanel.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -93,11 +93,6 @@ return widget; } - protected void setTooltip(DockLayoutPanel panel, String title) { - Tooltip.to(panel, title); - } - - public void clear() { trdCategoryFlow.clear(); firstCategoryFlow.clear(); @@ -142,6 +137,10 @@ sndCategoryPanel.setHeight(visible ? CATEG_HEIGHT : "0px"); } + protected void setTooltip(final Widget widget, final String title) { + Tooltip.to(widget, title); + } + public void setTrdCategoryVisible(final boolean visible) { trdCategoryPanel.setVisible(visible); trdCategoryPanel.setHeight(visible ? CATEG_HEIGHT : "0px"); Modified: trunk/src/main/java/cc/kune/core/client/sn/GroupSNPanel.java =================================================================== --- trunk/src/main/java/cc/kune/core/client/sn/GroupSNPanel.java 2011-04-12 18:38:37 UTC (rev 1307) +++ trunk/src/main/java/cc/kune/core/client/sn/GroupSNPanel.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -21,11 +21,11 @@ mainTitle.setText(i18n.t("Group members")); Tooltip.to(mainTitle, i18n.t("People and groups collaborating in this group")); firstCategoryLabel.setText(i18n.t("Admins")); - setTooltip(firstCategoryPanel, i18n.t("People that can admin this group")); + setTooltip(firstCategoryLabel, i18n.t("People that can admin this group")); sndCategoryLabel.setText(i18n.t("Collaborators")); - setTooltip(sndCategoryPanel, i18n.t("Other people that collaborate with this group")); + setTooltip(sndCategoryLabel, i18n.t("Other people that collaborate with this group")); trdCategoryLabel.setText(i18n.t("Pending")); - setTooltip(trdCategoryPanel, i18n.t("People pending to be accepted in this group by the admins")); + setTooltip(trdCategoryLabel, i18n.t("People pending to be accepted in this group by the admins")); sndDeckLabel.setText(i18n.t("This is an orphaned project, if you are interested please request to join to work on it")); firstDeckLabel.setText(i18n.t("The members of this group are not public")); bottomActionsToolbar = new ActionFlowPanel(guiProvider); Modified: trunk/src/main/java/cc/kune/core/client/sn/UserSNPanel.java =================================================================== --- trunk/src/main/java/cc/kune/core/client/sn/UserSNPanel.java 2011-04-12 18:38:37 UTC (rev 1307) +++ trunk/src/main/java/cc/kune/core/client/sn/UserSNPanel.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -22,12 +22,12 @@ mainTitle.setText(i18n.t("His/her network:")); mainTitle.setTitle(i18n.t("This user buddies and groups where participes")); firstCategoryLabel.setText(i18n.t("Buddies")); - setTooltip(firstCategoryPanel, i18n.t("This user buddies")); + setTooltip(firstCategoryLabel, i18n.t("This user buddies")); sndCategoryLabel.setText(i18n.t("Participates in")); - setTooltip(sndCategoryPanel, i18n.t("Groups in which this user participates")); + setTooltip(sndCategoryLabel, i18n.t("Groups in which this user participates")); firstDeckLabel.setText(i18n.t(CoreMessages.BUDDIES_NOT_PUBLIC)); trdCategoryLabel.setText("NOT USED"); - setTooltip(trdCategoryPanel, "NOT USED"); + setTooltip(trdCategoryLabel, "NOT USED"); super.setTrdCategoryVisible(false); sndDeckLabel.setText("NOT USED"); bottomActionsToolbar = new ActionFlowPanel(guiProvider); Modified: trunk/src/main/java/cc/kune/core/client/state/SiteTokenListeners.java =================================================================== --- trunk/src/main/java/cc/kune/core/client/state/SiteTokenListeners.java 2011-04-12 18:38:37 UTC (rev 1307) +++ trunk/src/main/java/cc/kune/core/client/state/SiteTokenListeners.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -27,7 +27,6 @@ import cc.kune.core.client.sitebar.AboutKuneDialog; import cc.kune.core.client.sitebar.spaces.Space; import cc.kune.core.client.sitebar.spaces.SpaceSelectEvent; -import cc.kune.core.client.sitebar.spaces.SpaceSelectorPresenter; import com.google.gwt.event.shared.EventBus; import com.google.inject.Inject; @@ -39,18 +38,16 @@ private final Provider<NewGroup> newGroup; private final Provider<Register> register; private final Provider<SignIn> signIn; - private final Provider<SpaceSelectorPresenter> spaceSelector; @Inject public SiteTokenListeners(final Session session, final EventBus eventBus, final Provider<SignIn> signIn, final Provider<Register> register, final Provider<NewGroup> newGroup, - final Provider<AboutKuneDialog> aboutKuneDialog, final Provider<SpaceSelectorPresenter> spaceSelector) { + final Provider<AboutKuneDialog> aboutKuneDialog) { this.eventBus = eventBus; this.signIn = signIn; this.register = register; this.newGroup = newGroup; this.aboutKuneDialog = aboutKuneDialog; - this.spaceSelector = spaceSelector; init(); } @@ -59,7 +56,6 @@ @Override public void onHistoryToken() { SpaceSelectEvent.fire(eventBus, Space.homeSpace); - // spaceSelector.get().showTooltip(); } }); put(SiteTokens.WAVEINBOX, new HistoryTokenCallback() { Modified: trunk/src/main/java/cc/kune/gspace/client/ui/footer/license/EntityLicensePanel.java =================================================================== --- trunk/src/main/java/cc/kune/gspace/client/ui/footer/license/EntityLicensePanel.java 2011-04-12 18:38:37 UTC (rev 1307) +++ trunk/src/main/java/cc/kune/gspace/client/ui/footer/license/EntityLicensePanel.java 2011-04-13 08:48:35 UTC (rev 1308) @@ -38,6 +38,7 @@ private final I18nTranslationService i18n; private final FlowPanel licenseBar; private final Image licenseImage; + private final Tooltip tooltip; @Inject public EntityLicensePanel(final I18nTranslationService i18n, final WsArmor armor) { @@ -48,6 +49,7 @@ licenseBar.add(licenseImage); licenseImage.addStyleName("k-footer-license-img"); armor.getEntityFooter().add(licenseBar); + tooltip = Tooltip.to(licenseImage, "."); } @Override @@ -80,6 +82,6 @@ final String licenseText = i18n.t("© [%s], under license: [%s]", groupName, licenseDTO.getLongName()); // KuneUiUtils.setQuickTip(licenseLabel, licenseText); licenseImage.setUrl(licenseDTO.getImageUrl()); - Tooltip.to(licenseImage, licenseText); + tooltip.setText(licenseText); } }
participants (1)
-
Vicente J. Ruiz Jurado