p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor.prototype2 / src / eu / etaxonomy / taxeditor / prototype2 / view / nameviewersupport / SimpleNamePartitioner.java
1 package eu.etaxonomy.taxeditor.prototype2.view.nameviewersupport;
2
3 import java.util.Scanner;
4
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;
12
13 import eu.etaxonomy.taxeditor.prototype2.view.NameEditorView;
14
15 public class SimpleNamePartitioner implements IDocumentPartitioner {
16
17 private NameEditorView nameEditorView;
18 private Control precedingControl;
19
20 public SimpleNamePartitioner(NameEditorView nameEditorView, Control precedingControl) {
21 this.nameEditorView = nameEditorView;
22 this.precedingControl = precedingControl;
23 }
24
25 public ITypedRegion[] computePartitioning(int offset, int length) {
26 // TODO Auto-generated method stub
27 return null;
28 }
29
30 public void connect(IDocument document) {
31 // TODO Auto-generated method stub
32
33 }
34
35 public void disconnect() {
36 // TODO Auto-generated method stub
37
38 }
39
40 public void documentAboutToBeChanged(DocumentEvent e) {
41
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
46
47 if (text.contains(System.getProperty("line.separator"))) {
48 if (offset < docLength) {
49 // remove text following insert from document,
50 // add to insert text
51 try {
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());
56 e1.printStackTrace();
57 }
58 }
59
60 Scanner scanner = new Scanner( text );
61 scanner.useDelimiter (System.getProperty("line.separator"));
62
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());
69 else
70 SText = nameEditorView.createRelatedName(SText, scanner.next()).
71 getTextWidget();
72 lastSText = SText;
73 }
74
75 SText.setFocus();
76
77 // put cursor at EOL of last sourceviewer
78 SText.setCaretOffset(SText.getText().length());
79 }
80 }
81
82 public boolean documentChanged(DocumentEvent event) {
83 // TODO Auto-generated method stub
84 return false;
85 }
86
87 public String getContentType(int offset) {
88 // TODO Auto-generated method stub
89 return null;
90 }
91
92 public String[] getLegalContentTypes() {
93 // TODO Auto-generated method stub
94 return null;
95 }
96
97 public ITypedRegion getPartition(int offset) {
98 // TODO Auto-generated method stub
99 return null;
100 }
101
102 }