source: java/FramclipsePlugin/src/main/java/com/framsticks/framclipse/editors/configuration/FramclipseDocumentSetupParticipant.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain
File size: 1.8 KB
Line 
1package com.framsticks.framclipse.editors.configuration;
2
3import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
4import org.eclipse.jface.text.IDocument;
5import org.eclipse.jface.text.IDocumentExtension3;
6import org.eclipse.jface.text.IDocumentPartitioner;
7import org.eclipse.jface.text.rules.FastPartitioner;
8import org.jdom.Attribute;
9import org.jdom.Document;
10import org.jdom.Element;
11import org.jdom.xpath.XPath;
12
13import com.framsticks.framclipse.Framclipse;
14import com.framsticks.framclipse.editors.EditorType;
15
16
17public class FramclipseDocumentSetupParticipant implements IDocumentSetupParticipant {
18
19        private final EditorType editorType;
20
21        public FramclipseDocumentSetupParticipant(EditorType editorType) {
22                this.editorType = editorType;
23        }
24
25        /*
26         * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
27         */
28        public void setup(IDocument document) {
29                if (document instanceof IDocumentExtension3) {
30                        IDocumentExtension3 extension3 = (IDocumentExtension3) document;
31                        FramscriptPartitionScanner scanner = Framclipse.getDefault()
32                                        .getFramscriptPartitionScanner(getCodeFieldName());
33                        IDocumentPartitioner partitioner = new FastPartitioner(scanner,
34                                        FramscriptPartitionScanner.PARTITION_TYPES);
35                        extension3.setDocumentPartitioner(Framclipse.FRAMSCRIPT_PARTITIONING, partitioner);
36                        partitioner.connect(document);
37                }
38        }
39
40        private String getCodeFieldName() {
41                Document context = Framclipse.getDefault().getFramscriptContext();
42                try {
43                        String query = "//file[@pattern='*." + editorType.getExtension() + "']/code";
44                        XPath xpath = XPath.newInstance(query);
45                        Element code = (Element) xpath.selectSingleNode(context);
46                        Attribute codeFieldNameAttribute = code.getAttribute("member");
47                        return codeFieldNameAttribute.getValue();
48                } catch (Exception e) {
49                        e.printStackTrace();
50                }
51                return "";
52        }
53}
Note: See TracBrowser for help on using the repository browser.