blob: 52de0e75453be6f96573d3fd14526db49cec8c34 (
plain) (
blame)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*******************************************************************************
* Copyright (c) 2011 Florian Thienel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Florian Thienel - initial API and implementation
*******************************************************************************/
package org.eclipse.vex.ui.internal.editor;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.vex.core.internal.io.DocumentContentModel;
import org.eclipse.vex.core.internal.io.IWhitespacePolicy;
import org.eclipse.vex.core.internal.widget.CssWhitespacePolicy;
import org.eclipse.vex.core.provisional.dom.IElement;
import org.eclipse.vex.ui.internal.VexPlugin;
import org.eclipse.vex.ui.internal.config.DocumentType;
import org.eclipse.vex.ui.internal.config.Style;
/**
* @author Florian Thienel
*/
public class VexDocumentContentModel extends DocumentContentModel {
private final Shell shell;
private DocumentType documentType;
private Style style;
private boolean shouldAssignInferredDocumentType;
public VexDocumentContentModel(final Shell shell) {
this.shell = shell;
}
@Override
public void initialize(final String baseUri, final String publicId, final String systemId, final IElement rootElement) {
super.initialize(baseUri, publicId, systemId, rootElement);
final String mainDocumentTypeIdentifier = getMainDocumentTypeIdentifier();
documentType = getRegisteredDocumentType();
if (documentType == null) {
documentType = queryUserForDocumentType();
}
if (documentType == null) {
throw new NoRegisteredDoctypeException(mainDocumentTypeIdentifier);
}
// TODO verify documentType URL???
// final URL url = documentType.getResourceUrl();
// if (url == null) {
// final String message = MessageFormat.format(Messages.getString("VexEditor.noUrlForDoctype"), mainDocumentTypeIdentifier);
// throw new RuntimeException(message);
// }
style = VexPlugin.getDefault().getPreferences().getPreferredStyle(documentType.getPublicId());
if (style == null) {
throw new NoStyleForDoctypeException();
}
}
private DocumentType getRegisteredDocumentType() {
return VexPlugin.getDefault().getConfigurationRegistry().getDocumentType(getMainDocumentTypeIdentifier());
}
private DocumentType queryUserForDocumentType() {
final DocumentTypeSelectionDialog dialog = DocumentTypeSelectionDialog.create(shell, getMainDocumentTypeIdentifier());
dialog.open();
if (dialog.alwaysUseThisDoctype()) {
shouldAssignInferredDocumentType = true;
}
return dialog.getDoctype();
}
@Override
public IWhitespacePolicy getWhitespacePolicy() {
if (style == null) {
return super.getWhitespacePolicy();
}
return new CssWhitespacePolicy(style.getStyleSheet());
}
public DocumentType getDocumentType() {
return documentType;
}
public Style getStyle() {
return style;
}
public boolean shouldAssignInferredDocumentType() {
return shouldAssignInferredDocumentType;
}
}
|