diff --git a/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java b/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java index 4e8a302..b5c4dcd 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java +++ b/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java @@ -4,6 +4,7 @@ package org.gcube.portlets.user.td.client; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import org.gcube.portlets.user.td.chartswidget.client.ChartsWidgetTD; @@ -80,6 +81,8 @@ import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.RunAsyncCallback; import com.google.gwt.event.shared.SimpleEventBus; +import com.google.gwt.i18n.client.LocaleInfo; +import com.google.gwt.user.client.Cookies; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -98,6 +101,7 @@ import com.sencha.gxt.widget.core.client.event.DialogHideEvent.DialogHideHandler */ public class TabularDataController { + private static final String TD_LANG_COOKIE = "TDLangCookie"; private SimpleEventBus eventBus; private MainBoxPanel mainBoxPanel; private UIStateType uiState = UIStateType.START; @@ -339,8 +343,39 @@ public class TabularDataController { } + protected void checkLocale() { + String[] locales = LocaleInfo.getAvailableLocaleNames(); + + for (String locale : locales) { + Log.debug("Locale avaible:" + locale); + } + + String currentLocaleCookie = Cookies.getCookie(LocaleInfo + .getLocaleCookieName()); + Log.debug(TD_LANG_COOKIE+":" + currentLocaleCookie); + + LocaleInfo currentLocaleInfo = LocaleInfo.getCurrentLocale(); + Log.debug("Current Locale:" + currentLocaleInfo.getLocaleName()); + + } + + protected void changeLanguage(String localeName) { + Date now = new Date(); + long nowLong = now.getTime(); + nowLong = nowLong + (1000 * 60 * 60 * 24 * 21); + now.setTime(nowLong); + String cookieLang=Cookies.getCookie(TD_LANG_COOKIE); + if(cookieLang!=null){ + Cookies.removeCookie(TD_LANG_COOKIE); + } + Cookies.setCookie(TD_LANG_COOKIE, localeName, now); + com.google.gwt.user.client.Window.Location.reload(); + } + // public void restoreUISession() { + checkLocale(); + String value = com.google.gwt.user.client.Window.Location .getParameter("TabularResourceId"); TRId startTRId = new TRId(value); @@ -655,7 +690,6 @@ public class TabularDataController { eventBus.fireEvent(dataViewRequestEvent); } - private void deleteTabularResource() { final ConfirmMessageBox mb = new ConfirmMessageBox("Confirm", @@ -761,7 +795,7 @@ public class TabularDataController { case LOGS: openLogsWindow(); break; - + case DUPLICATE_DETECTION: openDuplicatesRowsDetection(); break; @@ -916,7 +950,15 @@ public class TabularDataController { case CREATE_GIS_MAP: openCreateMapWizard(); break; - + case LANGUAGE_EN: + changeLanguage("en"); + break; + case LANGUAGE_ES: + changeLanguage("es"); + break; + case LANGUAGE_IT: + changeLanguage("it"); + break; default: break; } @@ -938,7 +980,6 @@ public class TabularDataController { } } - private void doWidgetRequestCommand(WidgetRequestEvent event) { WidgetRequestType widgetRequestType = event.getWidgetRequestType(); switch (widgetRequestType) { @@ -2004,7 +2045,7 @@ public class TabularDataController { UtilsGXT3.alert("Error", "No tabular resource present"); } } - + private void openDuplicatesRowsDelete() { Log.debug("Request Duplicates Rows Delete Tab"); if (trId != null) { @@ -2017,8 +2058,6 @@ public class TabularDataController { UtilsGXT3.alert("Error", "No tabular resource present"); } } - - private void openGeospatialCSquare() { Log.debug("Request Geospatial Create C-Square Coordiantes Tab"); diff --git a/src/main/java/org/gcube/portlets/user/td/client/TabularDataPortlet.java b/src/main/java/org/gcube/portlets/user/td/client/TabularDataPortlet.java index 4deb91e..b7d0a55 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/TabularDataPortlet.java +++ b/src/main/java/org/gcube/portlets/user/td/client/TabularDataPortlet.java @@ -11,7 +11,6 @@ import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.i18n.client.LocaleInfo; import com.google.gwt.user.client.ui.RootPanel; import com.google.web.bindery.event.shared.EventBus; import com.sencha.gxt.core.client.util.Margins; @@ -73,17 +72,7 @@ public class TabularDataPortlet implements EntryPoint { } - protected void loadMainPanel() { - String[] locales=LocaleInfo.getAvailableLocaleNames(); - - for(String locale:locales){ - Log.debug("Locale avaible:"+locale); - } - - LocaleInfo currentLocale = LocaleInfo.getCurrentLocale(); - Log.debug("Current Locale:"+currentLocale.getLocaleName()); - - + protected void loadMainPanel() { TabularDataController controller = new TabularDataController(); EventBus eventBus = controller.getEventBus(); diff --git a/src/main/java/org/gcube/portlets/user/td/client/resource/TabularDataResources.java b/src/main/java/org/gcube/portlets/user/td/client/resource/TabularDataResources.java index c580d9b..e66c840 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/resource/TabularDataResources.java +++ b/src/main/java/org/gcube/portlets/user/td/client/resource/TabularDataResources.java @@ -489,4 +489,19 @@ public interface TabularDataResources extends ClientBundle { @Source("point.png") ImageResource geometryPoint(); + @Source("flag_gb.png") + ImageResource flagGB(); + + @Source("flag_it.png") + ImageResource flagIT(); + + @Source("flag_es.png") + ImageResource flagES(); + + @Source("language_32.png") + ImageResource language32(); + + @Source("language.png") + ImageResource language(); + } diff --git a/src/main/java/org/gcube/portlets/user/td/client/resource/flag_es.png b/src/main/java/org/gcube/portlets/user/td/client/resource/flag_es.png new file mode 100755 index 0000000..c2de2d7 Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/td/client/resource/flag_es.png differ diff --git a/src/main/java/org/gcube/portlets/user/td/client/resource/flag_gb.png b/src/main/java/org/gcube/portlets/user/td/client/resource/flag_gb.png new file mode 100644 index 0000000..ff701e1 Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/td/client/resource/flag_gb.png differ diff --git a/src/main/java/org/gcube/portlets/user/td/client/resource/flag_it.png b/src/main/java/org/gcube/portlets/user/td/client/resource/flag_it.png new file mode 100755 index 0000000..89692f7 Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/td/client/resource/flag_it.png differ diff --git a/src/main/java/org/gcube/portlets/user/td/client/resource/language.png b/src/main/java/org/gcube/portlets/user/td/client/resource/language.png new file mode 100644 index 0000000..12e2a51 Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/td/client/resource/language.png differ diff --git a/src/main/java/org/gcube/portlets/user/td/client/resource/language_32.png b/src/main/java/org/gcube/portlets/user/td/client/resource/language_32.png new file mode 100644 index 0000000..649c913 Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/td/client/resource/language_32.png differ diff --git a/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBar.java b/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBar.java index ad87e55..dd921c8 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBar.java +++ b/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBar.java @@ -14,6 +14,8 @@ import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NodeList; +import com.google.gwt.event.logical.shared.SelectionEvent; +import com.google.gwt.event.logical.shared.SelectionHandler; import com.google.gwt.user.client.ui.FlexTable; import com.google.web.bindery.event.shared.EventBus; import com.sencha.gxt.cell.core.client.ButtonCell.ButtonArrowAlign; @@ -24,6 +26,9 @@ import com.sencha.gxt.widget.core.client.button.ButtonGroup; import com.sencha.gxt.widget.core.client.button.TextButton; import com.sencha.gxt.widget.core.client.event.SelectEvent; import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; +import com.sencha.gxt.widget.core.client.menu.Item; +import com.sencha.gxt.widget.core.client.menu.Menu; +import com.sencha.gxt.widget.core.client.menu.MenuItem; import com.sencha.gxt.widget.core.client.toolbar.ToolBar; /** @@ -33,7 +38,7 @@ import com.sencha.gxt.widget.core.client.toolbar.ToolBar; * */ public class FileToolBar { - + private FileToolBarMessages msgs; private EventBus eventBus; private ToolBar toolBar; @@ -60,13 +65,22 @@ public class FileToolBar { // History private TextButton historyButton; private TextButton undoButton; - + + //Help private TextButton helpButton; + private TextButton languageButton; //private TextButton logsButton; + //Language Menu + private MenuItem enItem; + private MenuItem itItem; + private MenuItem esItem; + + public FileToolBar(EventBus eventBus) { this.eventBus = eventBus; + msgs = GWT.create(FileToolBarMessages.class); build(); } @@ -75,7 +89,7 @@ public class FileToolBar { } protected void build() { - FileToolBarMessages msgs = GWT.create(FileToolBarMessages.class); + toolBar = new ToolBar(); toolBar.setSpacing(1); @@ -416,6 +430,21 @@ public class FileToolBar { FlexTable helpLayout = new FlexTable(); helpGroup.add(helpLayout); + + + languageButton = new TextButton(msgs.languageButton(), + TabularDataResources.INSTANCE.language32()); + languageButton.enable(); + languageButton.setScale(ButtonScale.LARGE); + languageButton.setIconAlign(IconAlign.TOP); + languageButton.setToolTip(msgs.languageButtonToolTip()); + languageButton.setArrowAlign(ButtonArrowAlign.RIGHT); + languageButton.setMenu(createLanguageMenu()); + + helpLayout.setWidget(0, 0, languageButton); + helpLayout.getFlexCellFormatter().setRowSpan(0, 0, 2); + + helpButton = new TextButton(msgs.helpButton(), TabularDataResources.INSTANCE.help32()); helpButton.enable(); @@ -430,8 +459,8 @@ public class FileToolBar { } }); - helpLayout.setWidget(0, 0, helpButton); - helpLayout.getFlexCellFormatter().setRowSpan(0, 0, 2); + helpLayout.setWidget(0, 1, helpButton); + helpLayout.getFlexCellFormatter().setRowSpan(0, 1, 2); /* logsButton = new TextButton("Logs", @@ -475,6 +504,56 @@ public class FileToolBar { } } } + + + private Menu createLanguageMenu() { + Menu menuReplace = new Menu(); + enItem = new MenuItem(msgs.english(), + TabularDataResources.INSTANCE.flagGB()); + itItem = new MenuItem(msgs.italian(), + TabularDataResources.INSTANCE.flagIT()); + esItem = new MenuItem(msgs.spanish(), + TabularDataResources.INSTANCE.flagES()); + + enItem + .addSelectionHandler(new SelectionHandler() { + + @Override + public void onSelection(SelectionEvent event) { + eventBus.fireEvent(new RibbonEvent( + RibbonType.LANGUAGE_EN)); + + } + }); + + itItem + .addSelectionHandler(new SelectionHandler() { + + @Override + public void onSelection(SelectionEvent event) { + eventBus.fireEvent(new RibbonEvent( + RibbonType.LANGUAGE_IT)); + + } + }); + + esItem + .addSelectionHandler(new SelectionHandler() { + + @Override + public void onSelection(SelectionEvent event) { + eventBus.fireEvent(new RibbonEvent( + RibbonType.LANGUAGE_ES)); + + } + }); + + menuReplace.add(enItem); + menuReplace.add(itItem); + menuReplace.add(esItem); + return menuReplace; + } + public void setUI(UIStateEvent event) { UIStateType uiStateType = event.getUIStateType(); diff --git a/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBarMessages.java b/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBarMessages.java index 23a0826..6b968bb 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBarMessages.java +++ b/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBarMessages.java @@ -141,5 +141,20 @@ public interface FileToolBarMessages extends Messages { @DefaultMessage("Help") String helpButtonToolTip(); + @DefaultMessage("Language") + String languageButton(); + + @DefaultMessage("Language") + String languageButtonToolTip(); + + // + @DefaultMessage("English") + String english(); + + @DefaultMessage("Italian") + String italian(); + + @DefaultMessage("Spanish") + String spanish(); } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/client/ribbon/TabularDataRibbon.java b/src/main/java/org/gcube/portlets/user/td/client/ribbon/TabularDataRibbon.java index d92c616..a84beea 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/ribbon/TabularDataRibbon.java +++ b/src/main/java/org/gcube/portlets/user/td/client/ribbon/TabularDataRibbon.java @@ -57,12 +57,12 @@ public class TabularDataRibbon { con = new VerticalLayoutContainer(); con.add(modifyToolBar.getToolBar(), vldata); ribbon.add(con, msgs.modify()); - + /* ruleToolBar = new RuleToolBar(eventBus); con = new VerticalLayoutContainer(); con.add(ruleToolBar.getToolBar(), vldata); ribbon.add(con, msgs.rule()); - + */ templateToolBar = new TemplateToolBar(eventBus); con = new VerticalLayoutContainer(); con.add(templateToolBar.getToolBar(), vldata); diff --git a/src/main/java/org/gcube/portlets/user/td/tabulardataportlet.gwt.xml b/src/main/java/org/gcube/portlets/user/td/tabulardataportlet.gwt.xml index 8ab92b4..97abd0c 100644 --- a/src/main/java/org/gcube/portlets/user/td/tabulardataportlet.gwt.xml +++ b/src/main/java/org/gcube/portlets/user/td/tabulardataportlet.gwt.xml @@ -70,10 +70,10 @@ - + + value="TDLang" /> + value="TDLangCookie" /> + value="TDLang" /> - + -->