1 package eu
.etaxonomy
.taxeditor
.prototype2
.view
.nameviewersupport
;
3 import org
.eclipse
.core
.runtime
.Assert
;
4 import org
.eclipse
.swt
.SWT
;
5 import org
.eclipse
.swt
.custom
.StyledText
;
6 import org
.eclipse
.swt
.events
.KeyEvent
;
7 import org
.eclipse
.swt
.events
.KeyListener
;
9 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
10 import eu
.etaxonomy
.taxeditor
.prototype2
.controller
.ActionAddSynonymToTaxon
;
13 * The only purpose of this listener is to catch carriage returns
14 * at end-of-line, and create new empty name viewers.
16 * Carriage returns in the middle of a line are caught by
17 * NameViewerModifyListener.
22 public class NameViewerKeyListener
implements KeyListener
{
26 public NameViewerKeyListener(Taxon taxon
) {
28 Assert
.isNotNull(taxon
);
32 public void keyPressed(KeyEvent e
) {
33 StyledText sText
= (StyledText
) e
.widget
;
35 // If user has pressed carriage return at EOL,
36 // the modifyListener doesn't catch it -
37 // make new source viewer
38 if (e
.character
== SWT
.CR
&&
39 sText
.getCaretOffset() == sText
.getText().length()) {
40 new ActionAddSynonymToTaxon(taxon
, "").run();
43 public void keyReleased(KeyEvent e
) { }