ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / DefaultLanguageDialog.java
1 /**
2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.ui.dialog;
10
11 import java.io.IOException;
12
13 import org.eclipse.jface.dialogs.IMessageProvider;
14 import org.eclipse.jface.dialogs.TitleAreaDialog;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.custom.CCombo;
17 import org.eclipse.swt.custom.CLabel;
18 import org.eclipse.swt.events.SelectionEvent;
19 import org.eclipse.swt.events.SelectionListener;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.Shell;
25
26 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
27
28
29 /**
30 * @author alex
31 * @date 19.08.2014
32 *
33 */
34 public class DefaultLanguageDialog extends TitleAreaDialog{
35
36
37 private CCombo combo;
38 final PreferencesUtil preferencesUtil = new PreferencesUtil();
39
40 /**
41 * @param parentShell
42 */
43 public DefaultLanguageDialog(Shell parentShell) {
44 super(parentShell);
45 }
46
47 @Override
48 protected void configureShell(Shell shell) {
49 super.configureShell(shell);
50 }
51
52 /* (non-Javadoc)
53 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
54 */
55 @Override
56 protected Control createDialogArea(Composite parent) {
57 // TODO Auto-generated method stub
58 setTitle("Select your default Language");
59 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);
60 Composite composite = (Composite)super.createDialogArea(parent);
61 Composite container = new Composite(parent, SWT.NONE);
62 container.setLayoutData(new GridData(SWT.TOP));
63
64 GridLayout layout = new GridLayout(1, false);
65 container.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, true));
66 container.setLayout(layout);
67
68 final CLabel titleLabel = new CLabel(container, SWT.NONE);
69 titleLabel.setText("After this the editor will restart, " +
70 "with your selection loaded. ");
71
72
73 createComboElement(container);
74
75 return composite;
76 }
77
78 /**
79 *
80 * @param parent
81 */
82 private void createComboElement(Composite parent) {
83 Composite container1 = new Composite(parent, SWT.NONE);
84 container1.setLayoutData(new GridData(GridData.FILL_BOTH));
85
86 GridLayout layout1 = new GridLayout(2, false);
87 container1.setLayoutData(new GridData(SWT.RIGHT, SWT.RIGHT, true, true));
88 container1.setLayout(layout1);
89
90
91 final CLabel comboLabel = new CLabel(container1, SWT.NONE);
92 comboLabel.setText("Please choose your default language: ");
93
94 GridData oneLine = new GridData();
95 oneLine.grabExcessHorizontalSpace = true;
96 oneLine.horizontalAlignment = GridData.FILL;
97
98 combo = new CCombo(container1, SWT.NONE);
99 combo.setLayoutData(oneLine);
100
101 combo.add(Language.GERMAN.getLabel(), 0);
102 combo.add(Language.ENGLISH.getLabel(), 1);
103 combo.select(1);
104 combo.addSelectionListener(new SelectionListener() {
105
106 @Override
107 public void widgetSelected(SelectionEvent e) {
108 try {
109 preferencesUtil.writePropertyToConfigFile(combo.getSelectionIndex());
110 } catch (IOException e1) {
111 e1.printStackTrace();
112 }
113 }
114
115 @Override
116 public void widgetDefaultSelected(SelectionEvent e) {
117 }
118 });
119 }
120
121 @Override
122 protected void okPressed() {
123 try {
124 preferencesUtil.writePropertyToConfigFile(combo.getSelectionIndex());
125 } catch (IOException e) {
126 e.printStackTrace();
127 }
128 super.okPressed();
129 }
130
131 private enum Language{
132
133 GERMAN("Deutsch"), ENGLISH("English");
134 private String label;
135 private Language(String label){
136 this.label = label;
137 }
138
139 /**
140 * @return the label
141 */
142 public String getLabel() {
143 return label;
144 }
145 }
146 }