1 package eu
.etaxonomy
.taxeditor
.prototype1
.view
;
3 import org
.eclipse
.core
.databinding
.DataBindingContext
;
4 import org
.eclipse
.core
.databinding
.observable
.value
.IObservableValue
;
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
;
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
;
29 public class NameEditorView
extends EditorPart
{
33 private Text txtGenus_1
;
34 private TaxonName taxonname
;
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$
42 * Create contents of the editor part
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
);
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
);
59 final Label lblGenus
= new Label(container
, SWT
.NONE
);
60 lblGenus
.setLayoutData(new GridData());
61 lblGenus
.setText("Genus:");
62 new Label(container
, SWT
.NONE
);
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
);
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
);
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
);
77 final Label lblAuthor
= new Label(container
, SWT
.NONE
);
78 lblAuthor
.setLayoutData(new GridData());
79 lblAuthor
.setText("Authorship:");
80 new Label(container
, SWT
.NONE
);
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
);
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
);
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
);
100 final Label lblGenus_1
= new Label(container_1
, SWT
.NONE
);
101 lblGenus_1
.setLayoutData(new GridData());
102 lblGenus_1
.setText("Genus:");
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
);
108 final Button btnSaveName_1
= new Button(container_1
, SWT
.NONE
);
109 btnSaveName_1
.addMouseListener(new MouseAdapter() {
110 public void mouseDown(final MouseEvent e
) {
112 taxonname
.setGenus(txtGenus
.getText());
113 taxonname
.setSpecificEpithet(txtSpEpi
.getText());
115 new SaveNameAction(taxonname
).run();
118 final GridData gd_btnSaveName_1
= new GridData();
119 btnSaveName_1
.setLayoutData(gd_btnSaveName_1
);
120 btnSaveName_1
.setText("Save Name");
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);
134 deleteNameButton
.setText("Delete Name");
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
);
144 final Label gLabel
= new Label(newTaxonAreaGroup
, SWT
.NONE
);
145 gLabel
.setLayoutData(new GridData());
148 g
= new Text(newTaxonAreaGroup
, SWT
.BORDER
);
150 g
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
152 final Label seLabel
= new Label(newTaxonAreaGroup
, SWT
.NONE
);
153 seLabel
.setText("SE");
155 se
= new Text(newTaxonAreaGroup
, SWT
.BORDER
);
157 se
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
158 new Label(newTaxonAreaGroup
, SWT
.NONE
);
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();
166 createNewNameButton
.setText("Create New Name");
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() {
177 //// public void verifyText(VerifyEvent e) {
178 //// e.doit = Character.isDigit(e.character);
181 // txtPlay.addSelectionListener(new SelectionListener() {
184 // public void widgetDefaultSelected(SelectionEvent e) {
185 // // TODO Auto-generated method stub
190 // public void widgetSelected(SelectionEvent e) {
191 // System.out.println(e.toString());
198 // txtPlay.addKeyListener(new KeyListener() {
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);
207 //// Combo list = new Combo(shell, SWT.H_SCROLL | SWT.V_SCROLL);
209 // // Add the items to the list
210 // String[] OPTIONS = { "Create homo. syn.",
211 // "Create hetero. syn.",
212 // "Create mis. name",
213 // "Create homonym"};
215 // list.setItems(OPTIONS);
217 // // Open the list and get the selected item
218 // String selected = list.open(txtPlay.getBounds());
220 // // Print the item to the console
221 // System.out.println(selected);
226 // public void keyReleased(KeyEvent e) {
227 // // TODO Auto-generated method stub
236 private void populateForm() {
238 String fulltext
= "";
240 if (taxonname
.getGenus() != null) {
241 txtGenus
.setText(taxonname
.getGenus());
242 txtGenus_1
.setText(taxonname
.getGenus());
243 fulltext
= taxonname
.getGenus();
246 if (taxonname
.getSpecificEpithet() != null) {
247 txtSpEpi
.setText(taxonname
.getSpecificEpithet());
248 fulltext
+= " " + taxonname
.getSpecificEpithet();
251 if (taxonname
.getAuthorship() != null) {
252 txtAuthor
.setText(taxonname
.getAuthorship());
253 fulltext
+= " " + taxonname
.getAuthorship();
256 this.setPartName(taxonname
.getName());
260 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
262 if (!(input
instanceof IEditorInput
))
263 throw new PartInitException(
264 "Invalid Input: Must be IFileEditorInput");
266 if (input
.getAdapter(TaxonName
.class) != null) {
267 taxonname
= (TaxonName
) input
.getAdapter(TaxonName
.class);
277 public boolean isDirty() {
282 public boolean isSaveAsAllowed() {
286 protected DataBindingContext
initDataBindings() {
287 IObservableValue txtGenus_1TextObserveWidget
= SWTObservables
.observeText(txtGenus_1
, SWT
.Modify
);
288 IObservableValue txtGenusTextObserveWidget
= SWTObservables
.observeText(txtGenus
, SWT
.Modify
);
291 DataBindingContext bindingContext
= new DataBindingContext();
293 bindingContext
.bindValue(txtGenusTextObserveWidget
, txtGenus_1TextObserveWidget
, null, null);
296 return bindingContext
;
300 public void doSave(IProgressMonitor monitor
) {
301 // TODO Auto-generated method stub
306 public void doSaveAs() {
307 // TODO Auto-generated method stub
312 public void setFocus() {
313 // TODO Auto-generated method stub