Revision 86cc5c9a
Added by Alexander Oppermann over 9 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/DefaultLanguageEditorPreferencePage.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
package eu.etaxonomy.taxeditor.preference; |
12 | 12 |
|
13 |
import java.io.File; |
|
14 |
import java.io.FileInputStream; |
|
15 |
import java.io.FileOutputStream; |
|
16 | 13 |
import java.io.IOException; |
17 |
import java.util.Properties; |
|
18 | 14 |
|
19 | 15 |
import org.apache.commons.lang.StringUtils; |
20 | 16 |
import org.eclipse.jface.preference.PreferencePage; |
... | ... | |
24 | 20 |
import org.eclipse.swt.events.SelectionListener; |
25 | 21 |
import org.eclipse.swt.layout.GridData; |
26 | 22 |
import org.eclipse.swt.layout.GridLayout; |
27 |
import org.eclipse.swt.layout.RowLayout; |
|
28 | 23 |
import org.eclipse.swt.widgets.Composite; |
29 | 24 |
import org.eclipse.swt.widgets.Control; |
30 | 25 |
import org.eclipse.swt.widgets.Label; |
... | ... | |
39 | 34 |
public class DefaultLanguageEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage{ |
40 | 35 |
|
41 | 36 |
private CCombo combo; |
42 |
|
|
43 |
private Composite createComposite(Composite parent){ |
|
44 |
Composite composite = new Composite(parent, SWT.NULL); |
|
45 |
composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1)); |
|
46 |
composite.setLayout(new RowLayout(SWT.HORIZONTAL)); |
|
47 |
return composite; |
|
48 |
} |
|
37 |
PreferencesUtil preferencesUtil = new PreferencesUtil(); |
|
49 | 38 |
|
50 | 39 |
/* (non-Javadoc) |
51 | 40 |
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) |
... | ... | |
83 | 72 |
@Override |
84 | 73 |
public void widgetSelected(SelectionEvent e) { |
85 | 74 |
try { |
86 |
writeConfigAndRestart(combo.getSelectionIndex());
|
|
75 |
preferencesUtil.writePropertyToConfigFile(combo.getSelectionIndex());
|
|
87 | 76 |
} catch (IOException e1) { |
88 | 77 |
e1.printStackTrace(); |
89 | 78 |
} |
... | ... | |
127 | 116 |
} |
128 | 117 |
} |
129 | 118 |
|
130 |
private void writeConfigAndRestart(int setLanguage) throws IOException { |
|
131 |
File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile(); |
|
132 |
Properties properties = load(file.getAbsolutePath()+"/config.ini"); |
|
133 |
switch(setLanguage){ |
|
134 |
case 0: |
|
135 |
properties.setProperty("osgi.nl", "de"); |
|
136 |
PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de"); |
|
137 |
break; |
|
138 |
case 1: |
|
139 |
properties.setProperty("osgi.nl", "en"); |
|
140 |
PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en"); |
|
141 |
break; |
|
142 |
default: |
|
143 |
break; |
|
144 |
} |
|
145 |
save(file+"/config.ini", properties); |
|
146 |
} |
|
147 |
|
|
148 |
private Properties load(String filename) throws IOException { |
|
149 |
FileInputStream in = new FileInputStream(filename); |
|
150 |
Properties prop = new Properties(); |
|
151 |
prop.load(in); |
|
152 |
in.close(); |
|
153 |
return prop; |
|
154 |
} |
|
155 |
|
|
156 |
private void save(String filename, Properties properties) throws IOException{ |
|
157 |
FileOutputStream fos = new FileOutputStream(filename); |
|
158 |
properties.store(fos, ""); |
|
159 |
fos.close(); |
|
160 |
} |
|
161 |
|
|
162 | 119 |
/* (non-Javadoc) |
163 | 120 |
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) |
164 | 121 |
*/ |
... | ... | |
173 | 130 |
@Override |
174 | 131 |
public boolean performOk() { |
175 | 132 |
try { |
176 |
writeConfigAndRestart(combo.getSelectionIndex());
|
|
133 |
preferencesUtil.writePropertyToConfigFile(combo.getSelectionIndex());
|
|
177 | 134 |
} catch (IOException e) { |
178 | 135 |
e.printStackTrace(); |
179 | 136 |
} |
Also available in: Unified diff
refactored default language selection methods.