1 package eu
.etaxonomy
.taxeditor
.prototype2
.view
.nameviewersupport
;
3 import java
.util
.Scanner
;
5 import org
.eclipse
.jface
.text
.BadLocationException
;
6 import org
.eclipse
.jface
.text
.DocumentEvent
;
7 import org
.eclipse
.jface
.text
.IDocument
;
8 import org
.eclipse
.jface
.text
.IDocumentPartitioner
;
9 import org
.eclipse
.jface
.text
.ITypedRegion
;
10 import org
.eclipse
.swt
.custom
.StyledText
;
11 import org
.eclipse
.swt
.widgets
.Control
;
13 import eu
.etaxonomy
.taxeditor
.prototype2
.view
.NameEditorView
;
15 public class SimpleNamePartitioner
implements IDocumentPartitioner
{
17 private NameEditorView nameEditorView
;
18 private Control precedingControl
;
20 public SimpleNamePartitioner(NameEditorView nameEditorView
, Control precedingControl
) {
21 this.nameEditorView
= nameEditorView
;
22 this.precedingControl
= precedingControl
;
25 public ITypedRegion
[] computePartitioning(int offset
, int length
) {
26 // TODO Auto-generated method stub
30 public void connect(IDocument document
) {
31 // TODO Auto-generated method stub
35 public void disconnect() {
36 // TODO Auto-generated method stub
40 public void documentAboutToBeChanged(DocumentEvent e
) {
42 String text
= e
.getText();
43 int length
= e
.getLength();
44 int offset
= e
.getOffset();
45 int docLength
= e
.getDocument().getLength(); // length of doc BEFORE insert
47 if (text
.contains(System
.getProperty("line.separator"))) {
48 if (offset
< docLength
) {
49 // remove text following insert from document,
52 text
+= e
.getDocument().get(offset
, docLength
- offset
);
53 e
.getDocument().replace(offset
, docLength
- offset
, "");
54 } catch (BadLocationException e1
) {
55 System
.out
.println(e1
.getMessage());
60 Scanner scanner
= new Scanner( text
);
61 scanner
.useDelimiter (System
.getProperty("line.separator"));
63 StyledText SText
= (StyledText
) precedingControl
;
64 nameEditorView
.createRelatedName(SText
, "test");
65 StyledText lastSText
= null;
66 while (scanner
.hasNext()) {
67 if (lastSText
== null)
68 e
.getDocument().set(scanner
.next());
70 SText
= nameEditorView
.createRelatedName(SText
, scanner
.next()).
77 // put cursor at EOL of last sourceviewer
78 SText
.setCaretOffset(SText
.getText().length());
82 public boolean documentChanged(DocumentEvent event
) {
83 // TODO Auto-generated method stub
87 public String
getContentType(int offset
) {
88 // TODO Auto-generated method stub
92 public String
[] getLegalContentTypes() {
93 // TODO Auto-generated method stub
97 public ITypedRegion
getPartition(int offset
) {
98 // TODO Auto-generated method stub