Skip to content

Commit

Permalink
Issue CruxFramework#2 - Make Showcase project compatible with Crux 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Cardoso committed Dec 16, 2015
1 parent 01453e6 commit f591dde
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 48 deletions.
6 changes: 3 additions & 3 deletions showcase-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cruxVersion>5.4-SNAPSHOT</cruxVersion>
<smartfacesVersion>1.3-SNAPSHOT</smartfacesVersion>
<widgetsVersion>5.4-SNAPSHOT</widgetsVersion>
<cruxVersion>5.4.0</cruxVersion>
<smartfacesVersion>1.3.0</smartfacesVersion>
<widgetsVersion>5.4.0</widgetsVersion>
<java.source.version>1.7</java.source.version>
<java.target.version>1.7</java.target.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package org.cruxframework.showcasecore.client.controller.showcase;

import org.cruxframework.crux.core.client.screen.views.View;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Widget;

public class LanguageManager
{
private Widget langToggler;
private Widget langEn;
private Widget langPt;

public LanguageManager(Widget langToggler, Widget langEn, Widget langPt)
{
this.langEn = langEn;
this.langPt = langPt;
this.langToggler = langToggler;
}

public void verifyAndToggleLanguage()
{
String uriLocale = Window.Location.getParameter("locale");
Expand All @@ -17,14 +26,9 @@ public void switchLocaleToggle(String locale)
{
if(locale == null)
{
return;
locale = getBrowserLocale();
}

Widget langToggler = View.of(this).getWidget("langToggler");

Widget langEn = View.of(this).getWidget("langEn");
Widget langPt = View.of(this).getWidget("langPt");

if(locale.contains("pt_BR"))
{
langEn.removeStyleName("active");
Expand All @@ -37,11 +41,15 @@ public void switchLocaleToggle(String locale)
langEn.addStyleName("active");
}
}

private native String getBrowserLocale()/*-{
if($wnd.navigator.language == "pt-br")
if($wnd.navigator !== undefined && $wnd.navigator.language !== undefined)
{
return "pt_BR";
if($wnd.navigator.language == "pt" || ($wnd.navigator.language.indexOf("pt-") > -1) || ($wnd.navigator.language.indexOf("pt_") > -1))
{
return "pt_BR";
}
}
return "en_US";
}-*/;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.cruxframework.showcasecore.client.resource.ShowcaseCoreMessages;
import org.cruxframework.showcasecore.client.resource.common.ShowcaseResourcesCommon;
import org.cruxframework.showcasecore.client.util.LoadingCallback;
import org.cruxframework.showcasecore.client.util.VisualBoxLogHandler;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
Expand All @@ -51,9 +50,8 @@ public class MainController

private Logger logger = Logger.getLogger("");

@Inject
private LanguageManager languageManager;

@Expose
public void replaceText(AttachEvent event)
{
Expand All @@ -74,9 +72,12 @@ public void setWidgets(MyWidgetAccessor widgets)
public static interface MyWidgetAccessor extends WidgetAccessor
{
MenuTabsDisposal menuDisposal();
Filter filter();
Widget langToggler();
Widget langEn();
Widget langPt();
}


@Expose
public void switchLocaleUrl()
{
Expand All @@ -98,33 +99,34 @@ public void loadShowcaseUrl()
}

@Expose
public void wellcome()
public void onLoad()
{
languageManager = new LanguageManager(widgets.langToggler(), widgets.langEn(), widgets.langPt());

//add the event log window
if(Screen.getCurrentDevice().getSize().equals(Size.large))
{
logger.addHandler(new VisualBoxLogHandler(messages.enableLog(), messages.disableLog()));
}
//if(Screen.getCurrentDevice().getSize().equals(Size.large))
//{
// logger.addHandler(new VisualBoxLogHandler(messages.enableLog(), messages.disableLog()));
//}

String hash = Window.Location.getHash();
MenuTabsDisposal menuDisposal = (MenuTabsDisposal) Screen.get("menuDisposal");

if(!StringUtils.isEmpty(hash))
{
String viewName = hash.split(":")[1];

if(!"wellcome".equals(viewName))
{
menuDisposal.showView(viewName, Direction.FORWARD);
widgets.menuDisposal().showView(viewName, Direction.FORWARD);
}
else
{
menuDisposal.showView("wellcome", Direction.FORWARD);
widgets.menuDisposal().showView("wellcome", Direction.FORWARD);
}
}
else
{
menuDisposal.showView("wellcome", Direction.FORWARD);
widgets.menuDisposal().showView("wellcome", Direction.FORWARD);
}

//Call method to verify browser language
Expand All @@ -133,14 +135,14 @@ public void wellcome()
if(Screen.getCurrentDevice().getSize().equals(Size.large))
{
//Setup the top filters
setupFilters(menuDisposal);
setupFilters();
}
}

private void setupFilters(final MenuTabsDisposal menuDisposal)
private void setupFilters()
{
final Filter filter = (Filter) Screen.get("filter");

final Filter filter = widgets.filter();
filter.setFilterable(new Filterable<String>()
{
@Override
Expand Down Expand Up @@ -212,7 +214,7 @@ public List<FilterResult<String>> filter(String query)
@Override
public void onSelectItem(String selectedItem)
{
menuDisposal.showView(selectedItem, null);
widgets.menuDisposal().showView(selectedItem, null);
filter.setText("");
}

Expand All @@ -222,8 +224,7 @@ public void onSelectItem(String selectedItem)
@Expose
public void showMenu()
{
MenuTabsDisposal menuDisposal = (MenuTabsDisposal) Screen.get("menuDisposal");
menuDisposal.showMenu();
widgets.menuDisposal().showMenu();
}

@Expose
Expand All @@ -241,8 +242,7 @@ public void navigateToProject()
@Expose
public void viewSourceCode()
{
MenuTabsDisposal menuDisposal = (MenuTabsDisposal) Screen.get("menuDisposal");
String viewId = menuDisposal.getCurrentView();
String viewId = widgets.menuDisposal().getCurrentView();

service.listSourceFilesForView(viewId, new LoadingCallback<ArrayList<String>>()
{
Expand Down Expand Up @@ -349,9 +349,4 @@ public void setMessages(ShowcaseCoreMessages messages)
{
this.messages = messages;
}

public void setLanguageManager(LanguageManager languageManager)
{
this.languageManager = languageManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@
@MessageName("messages_core")
public interface ShowcaseCoreMessages extends Messages
{
@DefaultMessage("O seu navegador não suporta a criação de bancos de dados locais.")
//TODO fix this: https://github.com/CruxFramework/crux/issues/913
// @DefaultMessage("O seu navegador não suporta a criação de bancos de dados locais.")
@DefaultMessage("Database not supported by your browser")
String databaseNotSupportedError();

@DefaultMessage("Ver Código Fonte")
// @DefaultMessage("Código Fonte")
@DefaultMessage("Source")
String viewSourceCode();

@DefaultMessage("Carregando")
// @DefaultMessage("Carregando")
@DefaultMessage("Loading")
String loading();

// @DefaultMessage("Enable Log")
@DefaultMessage("Enable Log")
String enableLog();

// @DefaultMessage("X")
@DefaultMessage("X")
String disableLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,19 @@ body
{
background-repeat: no-repeat;
background-position: top;
padding-top: 80px;
background-image: logoLargeUrl;
background-position: center 25px;
padding-top: 120px;
background: logoLargeUrl no-repeat 0 10px #ececec;
background-position: center 18px;
}

.viewFilter
{
position: absolute;
z-index: 1;
width: 266px;
margin-left: 16px;
margin-top: 86px;
height: 29px;
}

.layoutSectionIcon
Expand Down

0 comments on commit f591dde

Please sign in to comment.