KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > mapper > editors > HBMXMLStructuredTextViewerConfiguration


1 package org.hibernate.eclipse.mapper.editors;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.eclipse.core.resources.IFile;
7 import org.eclipse.core.resources.IProject;
8 import org.eclipse.jdt.core.IJavaProject;
9 import org.eclipse.jdt.core.JavaCore;
10 import org.eclipse.jface.text.contentassist.ContentAssistant;
11 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
12 import org.eclipse.jface.text.contentassist.IContentAssistant;
13 import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
14 import org.eclipse.jface.text.source.ISourceViewer;
15 import org.eclipse.ui.IEditorInput;
16 import org.eclipse.ui.IFileEditorInput;
17 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
18 import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitionTypes;
19 import org.eclipse.wst.xml.core.internal.provisional.text.IXMLPartitions;
20 import org.eclipse.wst.xml.ui.internal.contentassist.NoRegionContentAssistProcessor;
21 import org.eclipse.wst.xml.ui.internal.provisional.StructuredTextViewerConfigurationXML;
22
23 public class HBMXMLStructuredTextViewerConfiguration extends StructuredTextViewerConfigurationXML {
24
25     public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
26         IContentAssistant ca = super.getContentAssistant(sourceViewer);
27         if (ca != null && ca instanceof ContentAssistant) {
28             ContentAssistant contentAssistant = (ContentAssistant) ca;
29             IContentAssistProcessor xmlContentAssistProcessor = new HBMXMLContentAssistProcessor(findJavaProject());
30             IContentAssistProcessor noRegionProcessor = new NoRegionContentAssistProcessor();
31             setContentAssistProcessor(contentAssistant, xmlContentAssistProcessor, IStructuredPartitionTypes.DEFAULT_PARTITION);
32             setContentAssistProcessor(contentAssistant, xmlContentAssistProcessor, IXMLPartitions.XML_DEFAULT);
33             setContentAssistProcessor(contentAssistant, noRegionProcessor, IStructuredPartitionTypes.UNKNOWN_PARTITION);
34         }
35         return ca;
36     }
37     
38     
39     /**
40      * @return
41      */

42     private IJavaProject findJavaProject() {
43         if (getEditorPart() != null) {
44              IFile file = null;
45              IProject project = null;
46              IJavaProject jProject = null;
47
48              IEditorInput input = this.getEditorPart().getEditorInput();
49              
50              if (input instanceof IFileEditorInput)
51              {
52                 IFileEditorInput fileInput = (IFileEditorInput) input;
53                 file = fileInput.getFile();
54                 project = file.getProject();
55                 jProject = JavaCore.create(project);
56              }
57
58              return jProject;
59           }
60
61         return null;
62     }
63     
64     public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
65         if (sourceViewer == null || !fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
66             return null;
67         
68         List JavaDoc allDetectors = new ArrayList JavaDoc(0);
69         allDetectors.add(new HBMXMLHyperlinkDetector(findJavaProject()));
70         
71         IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer);
72         for (int m = 0; m < superDetectors.length; m++) {
73             IHyperlinkDetector detector = superDetectors[m];
74             if (!allDetectors.contains(detector)) {
75                 allDetectors.add(detector);
76             }
77         }
78         return (IHyperlinkDetector[]) allDetectors.toArray(new IHyperlinkDetector[0]);
79     }
80 }
81
Popular Tags