Skip to content

Commit

Permalink
don't throw classcast exception for languages in virtualkeyboard that…
Browse files Browse the repository at this point in the history
… don't have an ISO code (fixes #447)
  • Loading branch information
thomaskrause committed Sep 22, 2015
1 parent 72e6b2c commit 8e5c6d4
Showing 1 changed file with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,29 @@
import com.vaadin.shared.JavaScriptExtensionState;
import com.vaadin.ui.JavaScriptFunction;
import elemental.json.JsonArray;
import elemental.json.impl.JreJsonNull;
import org.json.JSONException;

/**
*
* @author Thomas Krause <[email protected]>
*/
@StyleSheet({"keyboard.css"})
@JavaScript({"vaadin://jquery.js","keyboard.js", "virtualkeyboard_codeeditor.js"})
@StyleSheet(
{
"keyboard.css"
})
@JavaScript(
{
"vaadin://jquery.js", "keyboard.js", "virtualkeyboard_codeeditor.js"
})
public class VirtualKeyboardCodeEditor extends AbstractJavaScriptExtension
{

public VirtualKeyboardCodeEditor()
{
addFunction("updateLang", new UpdateLangJSFunction());
}

@Override
protected Class<? extends ClientConnector> getSupportedParentType()
{
Expand All @@ -47,27 +55,28 @@ protected Class<? extends ClientConnector> getSupportedParentType()
public void extend(AqlCodeEditor target)
{
super.extend(target);

}

@Override
protected VKState getState()
{
return (VKState) super.getState();
}

public void show()
{
callFunction("show");
}

public void setKeyboardLayout(String layout)
{
getState().setKeyboardLayout(layout);
}

public static class VKState extends JavaScriptExtensionState
{

private String keyboardLayout = "";

public String getKeyboardLayout()
Expand All @@ -79,7 +88,7 @@ public void setKeyboardLayout(String keyboardLayout)
{
this.keyboardLayout = keyboardLayout;
}

}

private class UpdateLangJSFunction implements JavaScriptFunction
Expand All @@ -92,8 +101,15 @@ public UpdateLangJSFunction()
@Override
public void call(JsonArray arguments) throws JSONException
{
((VKState) getState()).setKeyboardLayout(arguments.getString(0));
if (arguments.length() > 0 && !(arguments.get(0) instanceof JreJsonNull))
{
((VKState) getState()).setKeyboardLayout(arguments.getString(0));
}
else
{
((VKState) getState()).setKeyboardLayout(null);
}
}
}

}

0 comments on commit 8e5c6d4

Please sign in to comment.