提交 adb48728 编写于 作者: S serge-rider

#2458 Platform language model. Locale selection persistence.


Former-commit-id: 3ee1ea54
上级 5be16185
......@@ -22,6 +22,7 @@ extension-point.org.jkiss.dbeaver.sql.covertname = SQL text conversions
extension-point.org.jkiss.dbeaver.tools.name = Tools
extension-point.org.jkiss.dbeaver.product.bundles.name = Product bundles
extension-point.org.jkiss.dbeaver.workbenchHandler.name = Workbench handlers
extension-point.org.jkiss.dbeaver.language.name = Language
content-type.org.jkiss.dbeaver.sql.name = SQL Script
content-type.org.jkiss.dbeaver.bookmark.name = Bookmark
......@@ -36,6 +37,12 @@ view.database.output.title=Output
menu.navigate=Navigate
language.en.label=English
language.zh.label=Chinese
language.ru.label=Russian
language.it.label=Italian
language.de.label=German
editor.sql.name=SQL Editor
editor.folder.name=Folder Editor
editor.entity.name=Entity Editor
......
......@@ -39,6 +39,7 @@
<extension-point id="org.jkiss.dbeaver.tools" name="%extension-point.org.jkiss.dbeaver.tools.name" schema="schema/org.jkiss.dbeaver.tools.exsd"/>
<extension-point id="org.jkiss.dbeaver.product.bundles" name="%extension-point.org.jkiss.dbeaver.product.bundles.name" schema="schema/org.jkiss.dbeaver.product.bundles.exsd"/>
<extension-point id="org.jkiss.dbeaver.workbenchHandler" name="%extension-point.org.jkiss.dbeaver.workbenchHandler.name" schema="schema/org.jkiss.dbeaver.workbenchHandler.exsd"/>
<extension-point id="org.jkiss.dbeaver.language" name="%extension-point.org.jkiss.dbeaver.language.name" schema="schema/org.jkiss.dbeaver.language.exsd"/>
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type
......@@ -3611,6 +3612,14 @@
class="org.jkiss.dbeaver.ui.editors.sql.convert.impl.HTMLSQLConverter"/>
</extension>
<extension point="org.jkiss.dbeaver.language">
<language code="en" label="%language.en.label"/>
<language code="zh" label="%language.zh.label"/>
<language code="ru" label="%language.ru.label"/>
<language code="it" label="%language.it.label"/>
<language code="de" label="%language.de.label"/>
</extension>
<extension
point="org.eclipse.search.searchPages">
<page
......
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.jkiss.dbeaver.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.jkiss.dbeaver.core" id="org.jkiss.dbeaver.language" name="Language description"/>
</appInfo>
<documentation>
Plugin Service
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence>
<element ref="language" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="language">
<complexType>
<attribute name="class" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.jkiss.dbeaver.runtime.IPluginService"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
......@@ -47,6 +47,7 @@ import org.jkiss.dbeaver.registry.PluginServiceRegistry;
import org.jkiss.dbeaver.registry.ProjectRegistry;
import org.jkiss.dbeaver.registry.datatype.DataTypeProviderRegistry;
import org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry;
import org.jkiss.dbeaver.registry.language.PlatformLanguageRegistry;
import org.jkiss.dbeaver.registry.sql.SQLFormatterConfigurationRegistry;
import org.jkiss.dbeaver.runtime.IPluginService;
import org.jkiss.dbeaver.runtime.jobs.KeepAliveJob;
......@@ -79,7 +80,7 @@ public class DBeaverCore implements DBPPlatform {
private static final Log log = Log.getLog(DBeaverCore.class);
public static final String TEMP_PROJECT_NAME = ".dbeaver-temp"; //$NON-NLS-1$
public static final String RUNTIME_LOCALE_PROP = "runtime-locale"; //$NON-NLS-1$
public static final String PLATFORM_LANGUAGE_PROP = "platform-language"; //$NON-NLS-1$
private static final DBPApplication DEFAULT_APPLICATION = new EclipseApplication();
......@@ -91,7 +92,7 @@ public class DBeaverCore implements DBPPlatform {
private File tempFolder;
private IWorkspace workspace;
private Locale runtimeLocale = Locale.getDefault();
private DBPPlatformLanguage language;
private OSDescriptor localSystem;
private DBNModel navigatorModel;
......@@ -192,16 +193,18 @@ public class DBeaverCore implements DBPPlatform {
this.localSystem = new OSDescriptor(Platform.getOS(), Platform.getOSArch());
{
String runtimeLocaleString = prefsStore.getString(RUNTIME_LOCALE_PROP);
String runtimeLocaleString = prefsStore.getString(PLATFORM_LANGUAGE_PROP);
if (!CommonUtils.isEmpty(runtimeLocaleString)) {
this.runtimeLocale = Locale.forLanguageTag(runtimeLocaleString);
if (this.runtimeLocale == null) {
this.language = PlatformLanguageRegistry.getInstance().getLanguage(Locale.forLanguageTag(runtimeLocaleString));
if (this.language == null) {
log.warn("Runtime locale '" + runtimeLocaleString + "' not found");
this.runtimeLocale = Locale.getDefault();
} else {
changeRuntimeLocale(runtimeLocale);
changeRuntimeLocale(this.language);
}
}
if (this.language == null) {
this.language = PlatformLanguageRegistry.getInstance().getLanguage(Locale.ENGLISH);
}
}
QMUtils.initApplication(this);
......@@ -346,21 +349,24 @@ public class DBeaverCore implements DBPPlatform {
@NotNull
@Override
public Locale getRuntimeLocale() {
return runtimeLocale;
public DBPPlatformLanguage getLanguage() {
return language;
}
public void setRuntimeLocale(@NotNull Locale runtimeLocale) {
changeRuntimeLocale(runtimeLocale);
this.runtimeLocale = runtimeLocale;
getGlobalPreferenceStore().setValue(RUNTIME_LOCALE_PROP, runtimeLocale.toString());
public void setPlatformLanguage(@NotNull DBPPlatformLanguage language) {
if (CommonUtils.equalObjects(language, this.language)) {
return;
}
changeRuntimeLocale(language);
this.language = language;
getGlobalPreferenceStore().setValue(PLATFORM_LANGUAGE_PROP, language.getCode());
}
private void changeRuntimeLocale(@NotNull Locale runtimeLocale) {
private void changeRuntimeLocale(@NotNull DBPPlatformLanguage runtimeLocale) {
// Check locale
ILocaleChangeService localeService = PlatformUI.getWorkbench().getService(ILocaleChangeService.class);
if (localeService != null) {
localeService.changeApplicationLocale(runtimeLocale);
localeService.changeApplicationLocale(runtimeLocale.getCode());
} else {
log.warn("Can't resolve locale change service");
}
......
......@@ -77,6 +77,7 @@ public class RegistryConstants {
public static final String ATTR_DRIVER = "driver"; //$NON-NLS-1$
public static final String ATTR_BUNDLE = "bundle"; //$NON-NLS-1$
public static final String ATTR_CODE = "code"; //$NON-NLS-1$
public static final String ATTR_LABEL = "label"; //$NON-NLS-1$
public static final String ATTR_DEFAULT_PORT = "defaultPort"; //$NON-NLS-1$
public static final String ATTR_SAMPLE_URL = "sampleURL"; //$NON-NLS-1$
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* 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 org.jkiss.dbeaver.registry.language;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.app.DBPPlatformLanguage;
import org.jkiss.dbeaver.registry.AbstractContextDescriptor;
import org.jkiss.dbeaver.registry.RegistryConstants;
/**
* PlatformLanguageDescriptor
*/
public class PlatformLanguageDescriptor extends AbstractContextDescriptor implements DBPPlatformLanguage
{
public static final String EXTENSION_ID = "org.jkiss.dbeaver.language"; //$NON-NLS-1$
private final String code;
private final String label;
private final String description;
public PlatformLanguageDescriptor(
IConfigurationElement config)
{
super(config);
this.code = config.getAttribute(RegistryConstants.ATTR_CODE);
this.label = config.getAttribute(RegistryConstants.ATTR_LABEL);
this.description = config.getAttribute(RegistryConstants.ATTR_DESCRIPTION);
}
@NotNull
@Override
public String getCode() {
return code;
}
@NotNull
@Override
public String getLabel()
{
return label;
}
public String getDescription()
{
return description;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* 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 org.jkiss.dbeaver.registry.language;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class PlatformLanguageRegistry
{
private static PlatformLanguageRegistry instance = null;
public synchronized static PlatformLanguageRegistry getInstance()
{
if (instance == null) {
instance = new PlatformLanguageRegistry(Platform.getExtensionRegistry());
}
return instance;
}
private final List<PlatformLanguageDescriptor> descriptors = new ArrayList<>();
private PlatformLanguageRegistry(IExtensionRegistry registry)
{
// Load data descriptors from external plugins
{
IConfigurationElement[] extElements = registry.getConfigurationElementsFor(PlatformLanguageDescriptor.EXTENSION_ID);
for (IConfigurationElement ext : extElements) {
PlatformLanguageDescriptor formatterDescriptor = new PlatformLanguageDescriptor(ext);
descriptors.add(formatterDescriptor);
}
}
}
public List<PlatformLanguageDescriptor> getLanguages()
{
return descriptors;
}
public PlatformLanguageDescriptor getLanguage(String id)
{
for (PlatformLanguageDescriptor descriptor : descriptors) {
if (descriptor.getCode().equals(id)) {
return descriptor;
}
}
return null;
}
public PlatformLanguageDescriptor getLanguage(Locale locale)
{
for (PlatformLanguageDescriptor descriptor : descriptors) {
if (descriptor.getCode().equals(locale.getLanguage())) {
return descriptor;
}
}
return null;
}
}
......@@ -33,13 +33,19 @@ import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.app.DBPPlatformLanguage;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.registry.language.PlatformLanguageDescriptor;
import org.jkiss.dbeaver.registry.language.PlatformLanguageRegistry;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.TextWithOpenFile;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.utils.PrefUtils;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import org.jkiss.dbeaver.utils.SystemVariablesResolver;
import org.jkiss.utils.CommonUtils;
import java.util.List;
/**
* PrefPageDatabaseGeneral
......@@ -49,6 +55,7 @@ public class PrefPageDatabaseGeneral extends AbstractPrefPage implements IWorkbe
public static final String PAGE_ID = "org.jkiss.dbeaver.preferences.main.common"; //$NON-NLS-1$
private Button automaticUpdateCheck;
private Combo workspaceLanguage;
private Button longOperationsCheck;
private Spinner longOperationsTimeout;
......@@ -76,9 +83,23 @@ public class PrefPageDatabaseGeneral extends AbstractPrefPage implements IWorkbe
Composite composite = UIUtils.createPlaceholder(parent, 1, 5);
{
Group groupObjects = UIUtils.createControlGroup(composite, CoreMessages.pref_page_ui_general_group_general, 1, GridData.VERTICAL_ALIGN_BEGINNING, 300);
automaticUpdateCheck = UIUtils.createCheckbox(groupObjects, CoreMessages.pref_page_ui_general_checkbox_automatic_updates, false);
automaticUpdateCheck.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, true, false, 2, 1));
Group groupObjects = UIUtils.createControlGroup(composite, CoreMessages.pref_page_ui_general_group_general, 2, GridData.VERTICAL_ALIGN_BEGINNING, 300);
automaticUpdateCheck = UIUtils.createCheckbox(groupObjects, CoreMessages.pref_page_ui_general_checkbox_automatic_updates, null, false, 2);
//automaticUpdateCheck.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, true, false, 2, 1));
workspaceLanguage = UIUtils.createLabelCombo(groupObjects, "Language", "Application language - used for UI localization", SWT.READ_ONLY | SWT.DROP_DOWN);
List<PlatformLanguageDescriptor> languages = PlatformLanguageRegistry.getInstance().getLanguages();
DBPPlatformLanguage pLanguage = DBeaverCore.getInstance().getLanguage();
for (int i = 0; i < languages.size(); i++) {
PlatformLanguageDescriptor lang = languages.get(i);
workspaceLanguage.add(lang.getLabel());
if (CommonUtils.equalObjects(pLanguage, lang)) {
workspaceLanguage.select(i);
}
}
if (workspaceLanguage.getSelectionIndex() < 0) {
workspaceLanguage.select(0);
}
}
// Agent settings
......@@ -165,6 +186,10 @@ public class PrefPageDatabaseGeneral extends AbstractPrefPage implements IWorkbe
@Override
public boolean performOk()
{
if (workspaceLanguage.getSelectionIndex() >= 0) {
PlatformLanguageDescriptor language = PlatformLanguageRegistry.getInstance().getLanguages().get(workspaceLanguage.getSelectionIndex());
DBeaverCore.getInstance().setPlatformLanguage(language);
}
DBPPreferenceStore store = DBeaverCore.getGlobalPreferenceStore();
store.setValue(DBeaverPreferences.UI_AUTO_UPDATE_CHECK, automaticUpdateCheck.getSelection());
......
......@@ -42,7 +42,7 @@ public interface DBPPlatform
DBPApplication getApplication();
@NotNull
Locale getRuntimeLocale();
DBPPlatformLanguage getLanguage();
@NotNull
DBNModel getNavigatorModel();
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* 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 org.jkiss.dbeaver.model.app;
/**
* DBPPlatformLanguage
*/
public interface DBPPlatformLanguage
{
String getCode();
String getLabel();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册