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.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;
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;
- }
+ PreferencesUtil preferencesUtil = new PreferencesUtil();
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
@Override
public void widgetSelected(SelectionEvent e) {
try {
- writeConfigAndRestart(combo.getSelectionIndex());
+ preferencesUtil.writePropertyToConfigFile(combo.getSelectionIndex());
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
- 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 boolean performOk() {
try {
- writeConfigAndRestart(combo.getSelectionIndex());
+ preferencesUtil.writePropertyToConfigFile(combo.getSelectionIndex());
} catch (IOException e) {
e.printStackTrace();
}
package eu.etaxonomy.taxeditor.preference;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import java.util.UUID;
return configurator;
}
+ /**
+ * This method will write language properties to the config.ini located in the configuration folder
+ * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
+ *
+ * @param setLanguage 0 is for german and 1 for english.
+ * @throws IOException
+ */
+ public void writePropertyToConfigFile(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);
+ }
+
+ /**
+ * This method loads a property from a given file and returns it.
+ *
+ * @param filename
+ * @return
+ * @throws IOException
+ */
+ private Properties load(String filename) throws IOException {
+ FileInputStream in = new FileInputStream(filename);
+ Properties prop = new Properties();
+ prop.load(in);
+ in.close();
+ return prop;
+ }
+
+ /**
+ * This method saves a property to the specified file.
+ *
+ * @param filename
+ * @param properties
+ * @throws IOException
+ */
+ private void save(String filename, Properties properties) throws IOException{
+ FileOutputStream fos = new FileOutputStream(filename);
+ properties.store(fos, "");
+ fos.close();
+ }
+
}
*/
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.widgets.Control;
import org.eclipse.swt.widgets.Shell;
-import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
private CCombo combo;
+ final PreferencesUtil preferencesUtil = new PreferencesUtil();
+
/**
* @param parentShell
*/
return composite;
}
-
/**
*
+ * @param parent
*/
private void createComboElement(Composite parent) {
Composite container1 = new Composite(parent, SWT.NONE);
@Override
public void widgetSelected(SelectionEvent e) {
try {
- writeConfigAndRestart(combo.getSelectionIndex());
+ preferencesUtil.writePropertyToConfigFile(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;
+ try {
+ preferencesUtil.writePropertyToConfigFile(combo.getSelectionIndex());
+ } catch (IOException e) {
+ e.printStackTrace();
}
- 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();
+ super.okPressed();
}
private enum Language{
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;
- }
}