diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/OpenBIS.gwt.xml b/openbis/source/java/ch/systemsx/cisd/openbis/OpenBIS.gwt.xml index 85c5dd85ac04d82cd3e477be441fe5a39167260f..e8a7ae29ed8166a59fcbea7a56ef5ffa6cf31f13 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/OpenBIS.gwt.xml +++ b/openbis/source/java/ch/systemsx/cisd/openbis/OpenBIS.gwt.xml @@ -21,6 +21,9 @@ --> <source path="generic/client/web/client" /> <!--source path="plugin/hcs/client/web/client" /--> + + <public path="public"/> + <public path="generic/client/web/public"/> <!-- Do not define servlets here, use web.xml --> diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java index f51c5db842761ffe0a497bf011c7c7f547191373..e2e27c2d961237eba2d71cf7b470c1147413c18a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java @@ -20,6 +20,9 @@ import com.extjs.gxt.ui.client.widget.button.Button; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.DictonaryBasedMessageProvider; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider; + /** * * @@ -30,7 +33,8 @@ public class Client implements EntryPoint public void onModuleLoad() { - RootPanel.get().add(new Button("openBIS comong soon...")); + IMessageProvider messageProvider = new DictonaryBasedMessageProvider("generic"); + RootPanel.get().add(new Button(messageProvider.getMessage("message", "openBIS"))); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/DictonaryBasedMessageProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/DictonaryBasedMessageProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..a53197dd2f8b1ef6e95d634d86f98a5fd4128649 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/DictonaryBasedMessageProvider.java @@ -0,0 +1,63 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.client.web.client.application.util; + +import java.util.Set; + +import com.google.gwt.i18n.client.Dictionary; + +/** + * Message provider based on a {@link Dictionary} instance. The messages are dynamically loaded + * at runtime from a JavaScript file. + * + * @author Franz-Josef Elmer + */ +public class DictonaryBasedMessageProvider implements IMessageProvider +{ + private Dictionary dictionary; + + /** + * Creates a new instance for the specified dictionary name. + */ + public DictonaryBasedMessageProvider(String dictonaryName) + { + dictionary = Dictionary.getDictionary(dictonaryName); + } + + public Set<String> keySet() + { + return dictionary.keySet(); + } + + public String getMessage(String key, String... parameters) + { + String message; + try + { + message = dictionary.get(key); + } catch (Exception ex) + { + return "Unknown key '" + key + "' in " + dictionary + "."; + } + for (int i = 0; i < parameters.length; i++) + { + message = message.replace("{" + i + "}", parameters[i]); + } + return message; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/IMessageProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/IMessageProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..a5e41fd66add46c296e1af4d6978243ebb11fd9e --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/IMessageProvider.java @@ -0,0 +1,42 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.client.web.client.application.util; + +import java.util.Set; + +/** + * Interface of objects providing messages. + * + * @author Franz-Josef Elmer + */ +public interface IMessageProvider +{ + /** + * Returns the set of all known keys. + */ + public Set<String> keySet(); + + /** + * Returns the message specified by a key. Optional parameters are used to render the message by + * replacing <code>{0}</code> by the first parameter, <code>{1}</code> by the second one + * etc. + * <p> + * If a message couldn't be found an error message is returned which includes the invalid key + * and information about the message source of this provider. + */ + public String getMessage(String key, String... parameters); +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/public/generic-dictionary.js b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/public/generic-dictionary.js new file mode 100644 index 0000000000000000000000000000000000000000..26eceb44022be63b2dc4f7fda2b3a5087cf77b3c --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/public/generic-dictionary.js @@ -0,0 +1,2 @@ +// override or add key-value pair +generic["message"] = "generic {0} is coming soon..."; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js new file mode 100644 index 0000000000000000000000000000000000000000..df6f56eda61d55bced09a6e9cbce7bc2e4e5a7f3 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js @@ -0,0 +1,4 @@ +// Dictionaries +var generic = { + message: "openBIS is coming soon..." +}; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/index.html b/openbis/source/java/ch/systemsx/cisd/openbis/public/index.html index 37ee668a0a1244c9e5f9f4931ae25f8da4330f96..ce3f296e4e9d4a2ed0d999b8722b915030e47374 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/public/index.html +++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/index.html @@ -2,6 +2,12 @@ <html> <head> <title>openBIS</title> +<!-- +// The following scripts loads dictionaries which are used for all text messages. +--> +<script language="javascript" src="common-dictionary.js"></script> +<script language="javascript" src="generic-dictionary.js"></script> + <!-- // This script loads your compiled module. If you add any GWT meta tags, they must be added before this line. -->