KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > filtereditor > FilterCharacterPairMatcher


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.common.filtereditor;
22
23
24 // TODO: Refactor Filter Editor
25
import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
26 import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
27
28 import org.eclipse.jface.text.IDocument;
29 import org.eclipse.jface.text.IRegion;
30 import org.eclipse.jface.text.Region;
31 import org.eclipse.jface.text.source.ICharacterPairMatcher;
32 import org.eclipse.jface.text.source.ISourceViewer;
33
34
35 public class FilterCharacterPairMatcher implements ICharacterPairMatcher
36 {
37
38     private ISourceViewer sourceViewer;
39
40     private LdapFilterParser parser;
41
42     private int anchor;
43
44
45     public FilterCharacterPairMatcher( ISourceViewer sourceViewer, LdapFilterParser parser )
46     {
47         super();
48         this.sourceViewer = sourceViewer;
49         this.parser = parser;
50         this.clear();
51     }
52
53
54     public void dispose()
55     {
56     }
57
58
59     public void clear()
60     {
61         this.anchor = LEFT;
62     }
63
64
65     public IRegion match( IDocument document, int offset )
66     {
67
68         LdapFilter model = this.parser.getModel();
69         if ( model != null )
70         {
71             LdapFilter filter = this.parser.getModel().getFilter( offset - 1 );
72
73             if ( filter != null && filter.getStartToken() != null && filter.getStopToken() != null )
74             {
75
76                 int left = filter.getStartToken().getOffset();
77                 int right = filter.getStopToken().getOffset();
78
79                 if ( left == offset - 1 )
80                 {
81                     this.anchor = LEFT;
82                     IRegion region = new Region( left, right - left + 1 );
83                     return region;
84                 }
85                 if ( right == offset - 1 )
86                 {
87                     this.anchor = RIGHT;
88                     IRegion region = new Region( left, right - left + 1 );
89                     return region;
90                 }
91             }
92         }
93
94         return null;
95     }
96
97
98     public int getAnchor()
99     {
100         return this.anchor;
101     }
102
103 }
104
Popular Tags