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
.BadPositionCategoryException
;
7 import org
.eclipse
.jface
.text
.DocumentEvent
;
8 import org
.eclipse
.jface
.text
.IRegion
;
9 import org
.eclipse
.jface
.text
.ITypedRegion
;
10 import org
.eclipse
.jface
.text
.rules
.FastPartitioner
;
11 import org
.eclipse
.jface
.text
.rules
.IPartitionTokenScanner
;
12 import org
.eclipse
.swt
.custom
.StyledText
;
13 import org
.eclipse
.swt
.widgets
.Control
;
15 import eu
.etaxonomy
.taxeditor
.prototype2
.view
.NameEditorView
;
17 public class NamePartitioner
extends FastPartitioner
{
19 private NameEditorView nameEditorView
;
20 private Control precedingControl
;
22 public NamePartitioner(IPartitionTokenScanner scanner
,
23 String
[] legalContentTypes
,
24 NameEditorView nameEditorView
, Control precedingControl
) {
25 super(scanner
, legalContentTypes
);
26 this.nameEditorView
= nameEditorView
;
27 this.precedingControl
= precedingControl
;
30 protected void initialize() {
32 // if there is unparsed text, put it in the document's taxonname
33 // fDocument.addPosition(new Position());
37 System
.out
.println(this.getPositions().length
+ " positions in new sourceviewer");
38 } catch (BadPositionCategoryException e
) {
39 // TODO Auto-generated catch block
44 public IRegion
documentChanged2_(DocumentEvent e
) {
46 System
.out
.println("we're in");
48 String text
= e
.getText();
49 int length
= e
.getLength();
50 int offset
= e
.getOffset();
51 int docLength
= e
.getDocument().getLength(); // length of doc BEFORE insert
53 if (text
.contains(System
.getProperty("line.separator"))) {
54 if (offset
< docLength
) {
55 // remove text following insert from document,
58 text
+= e
.getDocument().get(offset
, docLength
- offset
);
59 e
.getDocument().replace(offset
, docLength
- offset
, "");
60 } catch (BadLocationException e1
) {
61 System
.out
.println(e1
.getMessage());
66 Scanner scanner
= new Scanner( text
);
67 scanner
.useDelimiter (System
.getProperty("line.separator"));
69 StyledText SText
= (StyledText
) precedingControl
;
70 nameEditorView
.createRelatedName(SText
, "test");
71 StyledText lastSText
= null;
72 while (scanner
.hasNext()) {
73 if (lastSText
== null)
74 e
.getDocument().set(scanner
.next());
76 SText
= nameEditorView
.createRelatedName(SText
, scanner
.next()).
83 // put cursor at EOL of last sourceviewer
84 SText
.setCaretOffset(SText
.getText().length());
89 // System.out.println("we made it this far");
91 return super.documentChanged2(e
);
94 public ITypedRegion
[] computePartitioning(int offset
, int length
, boolean includeZeroLengthPartitions
) {
95 System
.out
.println("computePartitioning called\n\t" + offset
+ "\n\t" + length
+ "\n\t" + includeZeroLengthPartitions
);
96 return super.computePartitioning(offset
, length
, includeZeroLengthPartitions
);