Now works with cdmLibrary 0.2.5.
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor.prototype1 / src / eu / etaxonomy / taxeditor / prototype1 / view / NameEditorView.java
1 package eu.etaxonomy.taxeditor.prototype1.view;
2
3 import org.eclipse.core.databinding.DataBindingContext;
4 import org.eclipse.core.databinding.observable.value.IObservableValue;
5
6 import org.eclipse.core.runtime.IProgressMonitor;
7 import org.eclipse.jface.databinding.swt.SWTObservables;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.events.MouseAdapter;
10 import org.eclipse.swt.events.MouseEvent;
11 import org.eclipse.swt.layout.GridData;
12 import org.eclipse.swt.layout.GridLayout;
13 import org.eclipse.swt.widgets.Button;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Group;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.swt.widgets.Text;
18 import org.eclipse.ui.IEditorInput;
19 import org.eclipse.ui.IEditorSite;
20 import org.eclipse.ui.PartInitException;
21 import org.eclipse.ui.part.EditorPart;
22 import com.swtdesigner.SWTResourceManager;
23
24 import eu.etaxonomy.taxeditor.prototype1.controller.CreateNameAction;
25 import eu.etaxonomy.taxeditor.prototype1.controller.DeleteNameAction;
26 import eu.etaxonomy.taxeditor.prototype1.controller.SaveNameAction;
27 import eu.etaxonomy.cdm.model.name.TaxonName;
28
29 public class NameEditorView extends EditorPart {
30
31 private Text se;
32 private Text g;
33 private Text txtGenus_1;
34 private TaxonName taxonname;
35
36 private Text txtGenus;
37 private Text txtSpEpi;
38 private Text txtAuthor;
39 public static final String ID = "eu.etaxonomy.taxeditor.prototype1.view.NameEditorView"; //$NON-NLS-1$
40
41 /**
42 * Create contents of the editor part
43 * @param parent
44 */
45 @Override
46 public void createPartControl(Composite parent) {
47 Composite container = new Composite(parent, SWT.NONE);
48 final GridLayout gridLayout = new GridLayout();
49 gridLayout.numColumns = 3;
50 container.setLayout(gridLayout);
51
52 final Label liveUpdateLabel = new Label(container, SWT.NONE);
53 liveUpdateLabel.setFont(SWTResourceManager.getFont("", 10, SWT.BOLD));
54 final GridData gd_liveUpdateLabel = new GridData();
55 liveUpdateLabel.setLayoutData(gd_liveUpdateLabel);
56 new Label(container, SWT.NONE);
57 new Label(container, SWT.NONE);
58
59 final Label lblGenus = new Label(container, SWT.NONE);
60 lblGenus.setLayoutData(new GridData());
61 lblGenus.setText("Genus:");
62 new Label(container, SWT.NONE);
63
64 txtGenus = new Text(container, SWT.BORDER);
65 final GridData gd_txtGenus = new GridData(SWT.FILL, SWT.CENTER, true, false);
66 txtGenus.setLayoutData(gd_txtGenus);
67
68 final Label lblSpEpi = new Label(container, SWT.NONE);
69 lblSpEpi.setLayoutData(new GridData());
70 lblSpEpi.setText("Sp. Epithet:");
71 new Label(container, SWT.NONE);
72
73 txtSpEpi = new Text(container, SWT.BORDER);
74 final GridData gd_txtSpEpi = new GridData(SWT.FILL, SWT.CENTER, true, false);
75 txtSpEpi.setLayoutData(gd_txtSpEpi);
76
77 final Label lblAuthor = new Label(container, SWT.NONE);
78 lblAuthor.setLayoutData(new GridData());
79 lblAuthor.setText("Authorship:");
80 new Label(container, SWT.NONE);
81
82 txtAuthor = new Text(container, SWT.BORDER);
83 final GridData gd_txtAuthor = new GridData(SWT.FILL, SWT.CENTER, true, false);
84 txtAuthor.setLayoutData(gd_txtAuthor);
85
86 final Composite container_1 = new Composite(container, SWT.NONE);
87 final GridData gd_container_1 = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
88 gd_container_1.widthHint = 389;
89 container_1.setLayoutData(gd_container_1);
90 final GridLayout gridLayout_1 = new GridLayout();
91 gridLayout_1.numColumns = 2;
92 container_1.setLayout(gridLayout_1);
93
94 final Label liveUpdateLabel_1 = new Label(container_1, SWT.NONE);
95 final GridData gd_liveUpdateLabel_1 = new GridData();
96 liveUpdateLabel_1.setLayoutData(gd_liveUpdateLabel_1);
97 liveUpdateLabel_1.setFont(SWTResourceManager.getFont("", 10, SWT.BOLD));
98 new Label(container_1, SWT.NONE);
99
100 final Label lblGenus_1 = new Label(container_1, SWT.NONE);
101 lblGenus_1.setLayoutData(new GridData());
102 lblGenus_1.setText("Genus:");
103
104 txtGenus_1 = new Text(container_1, SWT.BORDER);
105 final GridData gd_txtGenus_1 = new GridData(SWT.FILL, SWT.CENTER, true, false);
106 txtGenus_1.setLayoutData(gd_txtGenus_1);
107
108 final Button btnSaveName_1 = new Button(container_1, SWT.NONE);
109 btnSaveName_1.addMouseListener(new MouseAdapter() {
110 public void mouseDown(final MouseEvent e) {
111
112 taxonname.setGenus(txtGenus.getText());
113 taxonname.setSpecificEpithet(txtSpEpi.getText());
114
115 new SaveNameAction(taxonname).run();
116 }
117 });
118 final GridData gd_btnSaveName_1 = new GridData();
119 btnSaveName_1.setLayoutData(gd_btnSaveName_1);
120 btnSaveName_1.setText("Save Name");
121
122 final Button deleteNameButton = new Button(container_1, SWT.NONE);
123 deleteNameButton.addMouseListener(new MouseAdapter() {
124 public void mouseDown(final MouseEvent e) {
125 new DeleteNameAction(taxonname).run();
126 txtGenus.setEditable(false);
127 txtSpEpi.setEditable(false);
128 txtAuthor.setEditable(false);
129 txtGenus_1.setEditable(false);
130 btnSaveName_1.setEnabled(false);
131 deleteNameButton.setEnabled(false);
132 }
133 });
134 deleteNameButton.setText("Delete Name");
135
136 final Group newTaxonAreaGroup = new Group(container, SWT.NONE);
137 final GridLayout gridLayout_2 = new GridLayout();
138 gridLayout_2.numColumns = 2;
139 newTaxonAreaGroup.setLayout(gridLayout_2);
140 newTaxonAreaGroup.setText("New taxon area");
141 final GridData gd_newTaxonAreaGroup = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
142 newTaxonAreaGroup.setLayoutData(gd_newTaxonAreaGroup);
143
144 final Label gLabel = new Label(newTaxonAreaGroup, SWT.NONE);
145 gLabel.setLayoutData(new GridData());
146 gLabel.setText("G");
147
148 g = new Text(newTaxonAreaGroup, SWT.BORDER);
149 g.setText("Test");
150 g.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
151
152 final Label seLabel = new Label(newTaxonAreaGroup, SWT.NONE);
153 seLabel.setText("SE");
154
155 se = new Text(newTaxonAreaGroup, SWT.BORDER);
156 se.setText("me");
157 se.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
158 new Label(newTaxonAreaGroup, SWT.NONE);
159
160 final Button createNewNameButton = new Button(newTaxonAreaGroup, SWT.NONE);
161 createNewNameButton.addMouseListener(new MouseAdapter() {
162 public void mouseDown(final MouseEvent e) {
163 new CreateNameAction(g.getText(),se.getText()).run();
164 }
165 });
166 createNewNameButton.setText("Create New Name");
167 //
168
169
170 // txtPlay = new Text(container, SWT.BORDER);
171 // txtPlay.setCapture(true);
172 // final GridData gd_txtPlay = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
173 // gd_txtPlay.heightHint = 96;
174 // txtPlay.setLayoutData(gd_txtPlay);
175 //// txtPlay.addVerifyListener(new VerifyListener() {
176 //// @Override
177 //// public void verifyText(VerifyEvent e) {
178 //// e.doit = Character.isDigit(e.character);
179 //// }
180 //// });
181 // txtPlay.addSelectionListener(new SelectionListener() {
182 //
183 // @Override
184 // public void widgetDefaultSelected(SelectionEvent e) {
185 // // TODO Auto-generated method stub
186 //
187 // }
188 //
189 // @Override
190 // public void widgetSelected(SelectionEvent e) {
191 // System.out.println(e.toString());
192 // }
193 //
194 //
195 // });
196 //
197 //
198 // txtPlay.addKeyListener(new KeyListener() {
199 //
200 // public void keyPressed(KeyEvent e) {
201 // System.out.println(e.character);
202 // if (e.character == '=') {
203 // Shell shell = Activator.getDefault().getWorkbench().
204 // getActiveWorkbenchWindow().getShell();
205 // PopupList list = new PopupList(shell, SWT.H_SCROLL | SWT.V_SCROLL);
206 //
207 //// Combo list = new Combo(shell, SWT.H_SCROLL | SWT.V_SCROLL);
208 //
209 // // Add the items to the list
210 // String[] OPTIONS = { "Create homo. syn.",
211 // "Create hetero. syn.",
212 // "Create mis. name",
213 // "Create homonym"};
214 //
215 // list.setItems(OPTIONS);
216 //
217 // // Open the list and get the selected item
218 // String selected = list.open(txtPlay.getBounds());
219 //
220 // // Print the item to the console
221 // System.out.println(selected);
222 // }
223 //
224 // }
225 //
226 // public void keyReleased(KeyEvent e) {
227 // // TODO Auto-generated method stub
228 //
229 // }
230 // });
231
232 populateForm();
233 initDataBindings();
234 }
235
236 private void populateForm() {
237
238 String fulltext = "";
239
240 if (taxonname.getGenus() != null) {
241 txtGenus.setText(taxonname.getGenus());
242 txtGenus_1.setText(taxonname.getGenus());
243 fulltext = taxonname.getGenus();
244 }
245
246 if (taxonname.getSpecificEpithet() != null) {
247 txtSpEpi.setText(taxonname.getSpecificEpithet());
248 fulltext += " " + taxonname.getSpecificEpithet();
249 }
250
251 if (taxonname.getAuthorship() != null) {
252 txtAuthor.setText(taxonname.getAuthorship());
253 fulltext += " " + taxonname.getAuthorship();
254 }
255
256 this.setPartName(taxonname.getName());
257 }
258
259 @Override
260 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
261
262 if (!(input instanceof IEditorInput))
263 throw new PartInitException(
264 "Invalid Input: Must be IFileEditorInput");
265
266 if (input.getAdapter(TaxonName.class) != null) {
267 taxonname = (TaxonName) input.getAdapter(TaxonName.class);
268 } else {
269 taxonname = null;
270 }
271
272 setSite(site);
273 setInput(input);
274 }
275
276 @Override
277 public boolean isDirty() {
278 return false;
279 }
280
281 @Override
282 public boolean isSaveAsAllowed() {
283 return false;
284 }
285
286 protected DataBindingContext initDataBindings() {
287 IObservableValue txtGenus_1TextObserveWidget = SWTObservables.observeText(txtGenus_1, SWT.Modify);
288 IObservableValue txtGenusTextObserveWidget = SWTObservables.observeText(txtGenus, SWT.Modify);
289 //
290 //
291 DataBindingContext bindingContext = new DataBindingContext();
292 //
293 bindingContext.bindValue(txtGenusTextObserveWidget, txtGenus_1TextObserveWidget, null, null);
294 //
295
296 return bindingContext;
297 }
298
299 @Override
300 public void doSave(IProgressMonitor monitor) {
301 // TODO Auto-generated method stub
302
303 }
304
305 @Override
306 public void doSaveAs() {
307 // TODO Auto-generated method stub
308
309 }
310
311 @Override
312 public void setFocus() {
313 // TODO Auto-generated method stub
314
315 }
316
317 }