KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > console > editors > HQLDocumentProvider


1 package org.hibernate.eclipse.console.editors;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4
5 import org.eclipse.core.runtime.CoreException;
6 import org.eclipse.jface.text.IDocument;
7 import org.eclipse.jface.text.IDocumentPartitioner;
8 import org.eclipse.jface.text.rules.DefaultPartitioner;
9 import org.eclipse.ui.IEditorInput;
10 import org.eclipse.ui.editors.text.FileDocumentProvider;
11
12 public class HQLDocumentProvider extends FileDocumentProvider {
13
14     protected IDocument createDocument(Object JavaDoc element) throws CoreException {
15         IDocument document = super.createDocument(element);
16         if (document != null) {
17             IDocumentPartitioner partitioner =
18                 new DefaultPartitioner(
19                     new HQLPartitionScanner(),
20                     new String JavaDoc[] {
21                         HQLPartitionScanner.HQL_TAG,
22                         HQLPartitionScanner.HQL_COMMENT });
23             partitioner.connect(document);
24             document.setDocumentPartitioner(partitioner);
25         }
26         return document;
27     }
28     
29     public boolean setDocumentContent(IDocument document, IEditorInput editorInput, String JavaDoc encoding) throws CoreException {
30         if(!super.setDocumentContent(document, editorInput, encoding)) {
31             if(editorInput instanceof HQLEditorInput) {
32                 setDocumentContent(document, new ByteArrayInputStream JavaDoc(((HQLEditorInput)editorInput).getQueryString().getBytes()), null);
33                 return true;
34             } else {
35                 return false;
36             }
37         } else {
38             return true;
39         }
40     }
41     
42     public boolean isModifiable(Object JavaDoc element) {
43         return true;
44     }
45     
46     
47 }
Popular Tags