forked from ariatemplates/editor-frontend-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPOCDocumentProvider.java
More file actions
68 lines (47 loc) · 1.91 KB
/
POCDocumentProvider.java
File metadata and controls
68 lines (47 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package poc.document;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.editors.text.FileDocumentProvider;
import org.eclipse.ui.part.FileEditorInput;
import poc.Backend;
import poc.BackendException;
public class POCDocumentProvider extends FileDocumentProvider {
// FIXME Should be inferred from extension or something like that
private static final String mode = "athtml";
private static final String METHOD_INIT = "init";
private static final String ARGUMENT_MODE = "mode";
private static final String ARGUMENT_SOURCE = "source";
@Override
protected IDocument createDocument(Object element) throws CoreException {
// Document creation (client side) -------------------------------------
// In practice `element` is a FileEditorInput
POCDocument document = (POCDocument) super.createDocument(element);
if (document == null) {
return null;
}
document.setFile(((FileEditorInput) element).getFile());
// Document registration (backend side) --------------------------------
try {
Map<String, Object> argument = new HashMap<String, Object>();
argument.put(POCDocumentProvider.ARGUMENT_MODE, mode);
argument.put(POCDocumentProvider.ARGUMENT_SOURCE, document.get());
Map<String, Object> result = Backend.get().editor(POCDocumentProvider.METHOD_INIT, argument);
document.setGUID(result);
} catch (BackendException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
// Document configuration ----------------------------------------------
document.setDocumentPartitioner(new POCDocumentPartitioner());
document.addDocumentListener(new POCDocumentListener(document));
// Return --------------------------------------------------------------
return document;
}
@Override
protected IDocument createEmptyDocument() {
return new POCDocument();
}
}