From: Alexander Oppermann Date: Wed, 20 Aug 2014 14:04:41 +0000 (+0000) Subject: Added Default Language Selection for the TaxonomicEditor to fix #4358 X-Git-Tag: 3.6.0~487 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/4afd9d974d2b9203bbf3376775f42939eed52a08 Added Default Language Selection for the TaxonomicEditor to fix #4358 --- diff --git a/.gitattributes b/.gitattributes index cc961909e..64ace7d21 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1307,6 +1307,7 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/parser/ParseHa eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/CdmPreferences.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/DefaultFeatureTreePreferenecs.java -text +eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/DefaultLanguageEditorPreferencePage.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/DescriptionPreferences.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureTreePreferences.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java -text @@ -1365,6 +1366,7 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/internal eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/bar/AuthenticatedUserBar.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/EnumComboElement.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java -text +eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DefaultLanguageDialog.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/LoginDialog.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/UriDialog.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmEnumSelectionDialog.java -text diff --git a/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java b/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java index 00a48ec53..b6ed686bf 100644 --- a/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java +++ b/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java @@ -36,7 +36,8 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { } /** {@inheritDoc} */ - public ActionBarAdvisor createActionBarAdvisor( + @Override + public ActionBarAdvisor createActionBarAdvisor( IActionBarConfigurer configurer) { return new ApplicationActionBarAdvisor(configurer); } @@ -44,7 +45,8 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { /** *

preWindowOpen

*/ - public void preWindowOpen() { + @Override + public void preWindowOpen() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); configurer.setInitialSize(new Point(963, 637)); configurer.setShowCoolBar(true); @@ -57,13 +59,15 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { /** *

postWindowOpen

*/ - public void postWindowOpen() { + @Override + public void postWindowOpen() { PreferencesUtil.checkNomenclaturalCode(); - if(PreferencesUtil.shouldConnectAtStartUp()) - CdmStore.connect(); + if(PreferencesUtil.shouldConnectAtStartUp()) { + CdmStore.connect(); + } -// automaticUpdate(); + PreferencesUtil.checkDefaultLanguage(); } @@ -78,8 +82,9 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { ServiceReference sr = Activator.context.getServiceReference(IProvisioningAgentProvider.SERVICE_NAME); IProvisioningAgentProvider agentProvider = null; - if (sr == null) - return; + if (sr == null) { + return; + } agentProvider = (IProvisioningAgentProvider) Activator.context.getService(sr); IProvisioningAgent agent = null; try { @@ -95,7 +100,9 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { } catch (ProvisionException e) { MessagingUtils.error(getClass(), e); } finally { - if(agent != null) agent.stop(); + if(agent != null) { + agent.stop(); + } } } } diff --git a/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF index 07a0fb8de..fc61dc076 100644 --- a/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF +++ b/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF @@ -64,6 +64,7 @@ Import-Package: org.eclipse.core.commands, org.eclipse.core.expressions, org.eclipse.core.runtime, org.eclipse.core.runtime.jobs, + org.eclipse.core.runtime.preferences; org.eclipse.jface.action, org.eclipse.jface.dialogs, org.eclipse.jface.preference, diff --git a/eu.etaxonomy.taxeditor.store/plugin.xml b/eu.etaxonomy.taxeditor.store/plugin.xml index cb91bc2fc..ffa8680a5 100644 --- a/eu.etaxonomy.taxeditor.store/plugin.xml +++ b/eu.etaxonomy.taxeditor.store/plugin.xml @@ -193,6 +193,12 @@ id="eu.etaxonomy.taxeditor.preference.TemplatePreferencePage" name="Editor Profile"> + + diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/DefaultLanguageEditorPreferencePage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/DefaultLanguageEditorPreferencePage.java new file mode 100644 index 000000000..99a719961 --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/DefaultLanguageEditorPreferencePage.java @@ -0,0 +1,182 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.preference; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +import org.apache.commons.lang.StringUtils; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * @author n.hoffmann + * @created Dec 3, 2010 + * @version 1.0 + */ +public class DefaultLanguageEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage{ + + private CCombo combo; + + private Composite createComposite(Composite parent){ + Composite composite = new Composite(parent, SWT.NULL); + composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1)); + composite.setLayout(new RowLayout(SWT.HORIZONTAL)); + return composite; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createContents(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + final GridLayout gridLayout = new GridLayout(); + container.setLayout(gridLayout); + createEditorDefaultLanguage(container); + return container; + } + + /** + * @param container + */ + private void createEditorDefaultLanguage(Composite container) { + // TODO Auto-generated method stub + final Label label = new Label(container, SWT.NONE); + label.setText("Please choose your default language: "); + + GridData oneLine = new GridData(); + oneLine.grabExcessHorizontalSpace = true; + oneLine.horizontalAlignment = GridData.FILL; + + combo = new CCombo(container, SWT.NONE); + combo.setLayoutData(oneLine); + + combo.add(Language.GERMAN.getLabel(), 0); + combo.add(Language.ENGLISH.getLabel(), 1); + restoreSavedSelection(); + + combo.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + try { + writeConfigAndRestart(combo.getSelectionIndex()); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + + } + }); + } + + /** + * TODO: This method is not taking advantages of the enum field yet + */ + private void restoreSavedSelection() { + String rememberedValue = PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR); + if(StringUtils.isNotEmpty(rememberedValue)&& StringUtils.isNotBlank(rememberedValue)){ + if(rememberedValue.equalsIgnoreCase("en")){ + combo.select(1); + }else if(rememberedValue.equalsIgnoreCase("de")){ + combo.select(0); + } + } + } + + private enum Language{ + + GERMAN("Deutsch"), ENGLISH("English"); + private final String label; + private Language(String label){ + this.label = label; + } + + /** + * @return the label + */ + public String getLabel() { + return label; + } + } + + private void writeConfigAndRestart(int setLanguage) throws IOException { + File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile(); + Properties properties = load(file.getAbsolutePath()+"/config.ini"); + switch(setLanguage){ + case 0: + properties.setProperty("osgi.nl", "de"); + PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de"); + break; + case 1: + properties.setProperty("osgi.nl", "en"); + PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en"); + break; + default: + break; + } + save(file+"/config.ini", properties); + } + + private Properties load(String filename) throws IOException { + FileInputStream in = new FileInputStream(filename); + Properties prop = new Properties(); + prop.load(in); + in.close(); + return prop; + } + + private void save(String filename, Properties properties) throws IOException{ + FileOutputStream fos = new FileOutputStream(filename); + properties.store(fos, ""); + fos.close(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + */ + @Override + public void init(IWorkbench workbench) { + setPreferenceStore(PreferencesUtil.getPreferenceStore()); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performOk() + */ + @Override + public boolean performOk() { + try { + writeConfigAndRestart(combo.getSelectionIndex()); + } catch (IOException e) { + e.printStackTrace(); + } + return super.performOk(); + } +} diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java index 1f7a15b6b..66ce091b7 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java @@ -129,4 +129,6 @@ public interface IPreferenceKeys { // TODO RL public static final String IS_RL = "eu.etaxonomy.taxeditor.isRL"; + public static final String DEFAULT_LANGUAGE_EDITOR = "eu.etaxonomy.taxeditor.default.language"; + } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java index 9a0e836a4..095623cc4 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java @@ -16,10 +16,10 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.MessageDialog; +import org.apache.commons.lang.StringUtils; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator; import eu.etaxonomy.cdm.api.service.IFeatureTreeService; @@ -43,7 +43,9 @@ import eu.etaxonomy.cdm.strategy.match.MatchMode; import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper; import eu.etaxonomy.taxeditor.store.CdmStore; +import eu.etaxonomy.taxeditor.store.StoreUtil; import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; +import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog; /** *

@@ -107,6 +109,14 @@ public class PreferencesUtil implements IPreferenceKeys { return null; } + public static String getPreferredDefaultLangugae(){ + String preferredLanguage = getPreferenceStore().getString(DEFAULT_LANGUAGE_EDITOR); + if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){ + return preferredLanguage; + } + return null; + } + /** * Get the match strategy for the given class that was stored in preferences * or the default strategy if it was not stored in preferences @@ -378,8 +388,8 @@ public class PreferencesUtil implements IPreferenceKeys { */ public static void checkNomenclaturalCode() { // First time Editor is opened, no nomenclatural code has been set - - + + if (PreferencesUtil.getPreferredNomenclaturalCode() == null) { PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP); /* @@ -406,6 +416,19 @@ public class PreferencesUtil implements IPreferenceKeys { } } + public static void checkDefaultLanguage(){ + if(PreferencesUtil.getPreferredDefaultLangugae() == null){ + Shell shell = StoreUtil.getShell(); + int open = new DefaultLanguageDialog(shell).open(); + if(open == 0){//FIXME:window performed ok. Find variable for it + PlatformUI.getWorkbench().restart(); + } + }else{ + //TODO:In case of a reinstall, the config.ini will be overwritten + // here you create config.ini with the stored key from preferences + } + } + /** *

* getMapServiceAccessPoint diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DefaultLanguageDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DefaultLanguageDialog.java new file mode 100644 index 000000000..1f836ce04 --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DefaultLanguageDialog.java @@ -0,0 +1,195 @@ +// $Id$ +/** +* Copyright (C) 2014 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ +package eu.etaxonomy.taxeditor.ui.dialog; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; +import eu.etaxonomy.taxeditor.preference.PreferencesUtil; + + +/** + * @author alex + * @date 19.08.2014 + * + */ +public class DefaultLanguageDialog extends TitleAreaDialog{ + + + private CCombo combo; + /** + * @param parentShell + */ + public DefaultLanguageDialog(Shell parentShell) { + super(parentShell); + } + + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createDialogArea(Composite parent) { + // TODO Auto-generated method stub + setTitle("Select your default Language"); + setMessage("This is will set your default langauge once.\n You will be able to change this in the prefrence menue at any time.", IMessageProvider.INFORMATION); + Composite composite = (Composite)super.createDialogArea(parent); + Composite container = new Composite(parent, SWT.NONE); + container.setLayoutData(new GridData(SWT.TOP)); + + GridLayout layout = new GridLayout(1, false); + container.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, true)); + container.setLayout(layout); + + final CLabel titleLabel = new CLabel(container, SWT.NONE); + titleLabel.setText("After this the editor will restart, " + + "with your selection loaded. "); + + + createComboElement(container); + + return composite; + } + + + /** + * + */ + private void createComboElement(Composite parent) { + Composite container1 = new Composite(parent, SWT.NONE); + container1.setLayoutData(new GridData(GridData.FILL_BOTH)); + + GridLayout layout1 = new GridLayout(2, false); + container1.setLayoutData(new GridData(SWT.RIGHT, SWT.RIGHT, true, true)); + container1.setLayout(layout1); + + + final CLabel comboLabel = new CLabel(container1, SWT.NONE); + comboLabel.setText("Please choose your default language: "); + + GridData oneLine = new GridData(); + oneLine.grabExcessHorizontalSpace = true; + oneLine.horizontalAlignment = GridData.FILL; + + combo = new CCombo(container1, SWT.NONE); + combo.setLayoutData(oneLine); + + combo.add(Language.GERMAN.getLabel(), 0); + combo.add(Language.ENGLISH.getLabel(), 1); + combo.select(1); + combo.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + try { + writeConfigAndRestart(combo.getSelectionIndex()); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + + } + }); + } + + @Override + protected void okPressed() { + try { + writeConfigAndRestart(combo.getSelectionIndex()); + } catch (IOException e) { + e.printStackTrace(); + } + super.okPressed(); + } + + + private void writeConfigAndRestart(int setLanguage) throws IOException { + File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile(); + Properties properties = load(file.getAbsolutePath()+"/config.ini"); + switch(setLanguage){ + case 0: + properties.setProperty("osgi.nl", "de"); + PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de"); + break; + case 1: + properties.setProperty("osgi.nl", "en"); + PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en"); + break; + default: + break; + } + save(file+"/config.ini", properties); + } + + private Properties load(String filename) throws IOException { + FileInputStream in = new FileInputStream(filename); + Properties prop = new Properties(); + prop.load(in); + in.close(); + return prop; + } + + private void save(String filename, Properties properties) throws IOException{ + FileOutputStream fos = new FileOutputStream(filename); + properties.store(fos, ""); + fos.close(); + } + + private enum Language{ + + GERMAN("Deutsch"), ENGLISH("English"); + private String label; + private Language(String label){ + this.label = label; + } + + /** + * @return the label + */ + public String getLabel() { + return label; + } + } + private static final GridLayout GRID_LAYOUT (int columns, boolean equalwidth){ + GridLayout layout = new GridLayout(); + layout.marginTop = 0; + layout.marginRight = 0; + layout.marginBottom = 0; + layout.marginLeft = 0; + layout.numColumns = columns; + layout.makeColumnsEqualWidth = equalwidth; + return layout; + } +}