1 package eu
.etaxonomy
.taxeditor
.prototype2
.view
.nameviewersupport
;
3 import java
.beans
.PropertyDescriptor
;
4 import java
.lang
.reflect
.Field
;
6 import org
.eclipse
.core
.databinding
.beans
.BeansObservables
;
7 import org
.eclipse
.core
.databinding
.observable
.value
.IObservableValue
;
8 import org
.eclipse
.core
.runtime
.Assert
;
9 import org
.eclipse
.jface
.text
.BadLocationException
;
10 import org
.eclipse
.jface
.text
.BadPositionCategoryException
;
11 import org
.eclipse
.jface
.text
.DocumentEvent
;
12 import org
.eclipse
.jface
.text
.IDocument
;
13 import org
.eclipse
.jface
.text
.IDocumentPartitioner
;
14 import org
.eclipse
.jface
.text
.ITypedRegion
;
15 import org
.eclipse
.jface
.text
.TypedPosition
;
16 import org
.eclipse
.jface
.text
.rules
.FastPartitioner
;
17 import org
.eclipse
.jface
.text
.rules
.IPartitionTokenScanner
;
20 public class NamePartitioner__
implements IDocumentPartitioner
{
22 private static final String NAME_CONTENT_TYPES_CATEGORY
= "__name_content_types_category";
24 * The position category this partitioner uses to store the document's partitioning information.
26 private final String fPositionCategory
;
27 private NameDocument fDocument
;
28 private String
[] contentTypes
= {"genus","specificEpithet"};
30 public NamePartitioner__() {
31 fPositionCategory
= NAME_CONTENT_TYPES_CATEGORY
+ hashCode();
34 public ITypedRegion
[] computePartitioning(int offset
, int length
) {
35 // TODO Auto-generated method stub
39 public void connect(IDocument document
) {
40 Assert
.isTrue(document
instanceof NameDocument
,
41 "NamePartitioner__ requires a NameDocument");
42 this.fDocument
= (NameDocument
) document
;
43 this.fDocument
.addPositionCategory(fPositionCategory
);
45 TaxonName tn
= fDocument
.getTaxonName();
48 // find matching pattern to init TaxonName
52 // construct partitions from TaxonName
55 TypedPosition
[] positions
= new TypedPosition
[contentTypes
.length
];
59 for (int i
= 0; i
< contentTypes
.length
; i
++) {
60 String field
= contentTypes
[i
];
62 IObservableValue observeValue
= BeansObservables
.observeValue(tn
, field
);
64 String value
= (String
) observeValue
.getValue();
65 int length
= value
.length();
67 TypedPosition p
= new TypedPosition(offset
, length
, field
);
74 for (int i
= 0; i
< positions
.length
; i
++)
75 fDocument
.addPosition(fPositionCategory
, positions
[i
]);
76 // } catch (BadLocationException e) {
77 // // TODO Auto-generated catch block
78 // e.printStackTrace();
79 // } catch (SecurityException e) {
80 // // TODO Auto-generated catch block
81 // e.printStackTrace();
82 // } catch (NoSuchFieldException e) {
83 // // TODO Auto-generated catch block
84 // e.printStackTrace();
85 // } catch (IllegalArgumentException e) {
86 // // TODO Auto-generated catch block
87 // e.printStackTrace();
88 // } catch (IllegalAccessException e) {
89 // // TODO Auto-generated catch block
90 // e.printStackTrace();
91 // } catch (BadPositionCategoryException e) {
92 // // TODO Auto-generated catch block
93 // e.printStackTrace();
94 } catch (Exception e
) {
96 System
.out
.println(e
.getMessage());
101 public void disconnect() {
102 // TODO Auto-generated method stub
106 public void documentAboutToBeChanged(DocumentEvent event
) {
107 System
.out
.println("You are here: " + getContentType(event
.fOffset
));
108 // System.out.println("You are here: " + event.fOffset);
111 public boolean documentChanged(DocumentEvent event
) {
112 // TODO Auto-generated method stub
116 public String
getContentType(int offset
) {
117 ITypedRegion region
= null;
119 region
= fDocument
.getPartition(offset
);
120 } catch (BadLocationException e
) {
121 // TODO Auto-generated catch block
124 return region
.getType();
127 public String
[] getLegalContentTypes() {
131 public ITypedRegion
getPartition(int offset
) {
132 ITypedRegion region
= null;
134 region
= fDocument
.getPartition(offset
);
135 } catch (BadLocationException e
) {
136 // TODO Auto-generated catch block