KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > ldifeditor > editor > text > LdifTextHover


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.ldifeditor.editor.text;
22
23
24 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
25 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart;
26 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
27 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifValueLineBase;
28 import org.apache.directory.ldapstudio.ldifeditor.editor.ILdifEditor;
29
30 import org.eclipse.jface.text.IRegion;
31 import org.eclipse.jface.text.ITextHover;
32 import org.eclipse.jface.text.ITextViewer;
33 import org.eclipse.jface.text.Region;
34
35
36 public class LdifTextHover implements ITextHover
37 {
38
39     private ILdifEditor editor;
40
41
42     public LdifTextHover( ILdifEditor editor )
43     {
44         this.editor = editor;
45     }
46
47
48     public String JavaDoc getHoverInfo( ITextViewer textViewer, IRegion hoverRegion )
49     {
50
51         if ( this.editor != null )
52         {
53
54             LdifContainer container = LdifFile.getContainer( this.editor.getLdifModel(), hoverRegion.getOffset() );
55             if ( container != null )
56             {
57                 LdifPart part = LdifFile.getContainerContent( container, hoverRegion.getOffset() );
58                 if ( part != null )
59                 {
60                     if ( part instanceof LdifValueLineBase )
61                     {
62                         LdifValueLineBase line = ( LdifValueLineBase ) part;
63                         if ( line.isValueTypeBase64() )
64                         {
65                             return line.getValueAsString();
66                         }
67                     }
68                 }
69             }
70         }
71
72         return null;
73     }
74
75
76     public IRegion getHoverRegion( ITextViewer textViewer, int offset )
77     {
78
79         if ( this.editor != null )
80         {
81             return new Region( offset, 0 );
82         }
83
84         return null;
85     }
86
87 }
88
Popular Tags