]> git.argeo.org Git - lgpl/argeo-commons.git/blob - base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ThreadNLS.java
2.x specific - Adapt file download service to Rap 2.x
[lgpl/argeo-commons.git] / base / runtime / org.argeo.eclipse.ui.rap / src / main / java / org / argeo / eclipse / ui / specific / ThreadNLS.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.eclipse.ui.specific;
17
18 import org.eclipse.osgi.util.NLS;
19 import org.eclipse.rap.rwt.RWT;
20
21 /** NLS attached to a given thread */
22 public class ThreadNLS<T extends NLS> extends InheritableThreadLocal<T> {
23 public final static String DEFAULT_BUNDLE_LOCATION = "/properties/plugin";
24
25 private final String bundleLocation;
26
27 private Class<T> type;
28 private Boolean utf8 = false;
29
30 public ThreadNLS(String bundleLocation, Class<T> type, Boolean utf8) {
31 this.bundleLocation = bundleLocation;
32 this.type = type;
33 this.utf8 = utf8;
34 }
35
36 public ThreadNLS(Class<T> type) {
37 this(DEFAULT_BUNDLE_LOCATION, type, false);
38 }
39
40 @SuppressWarnings("unchecked")
41 @Override
42 protected T initialValue() {
43 if (utf8)
44 return (T) RWT.NLS.getUTF8Encoded(bundleLocation, type);
45 else
46 return (T) RWT.NLS.getISO8859_1Encoded(bundleLocation, type);
47 }
48 }