KickJava   Java API By Example, From Geeks To Geeks.

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


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

38     private IJavaProject findJavaProject() {
39         if (getEditorPart() != null) {
40              IFile file = null;
41              IProject project = null;
42              IJavaProject jProject = null;
43
44              IEditorInput input = this.getEditorPart().getEditorInput();
45              
46              if (input instanceof IFileEditorInput)
47              {
48                 IFileEditorInput fileInput = (IFileEditorInput) input;
49                 file = fileInput.getFile();
50                 project = file.getProject();
51                 jProject = JavaCore.create(project);
52              }
53
54              return jProject;
55           }
56
57         return null;
58     }
59     
60 }
61
Popular Tags