1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.editor.xmlEditor.actions;
13 import java.util.Map;
14
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.ui.IEditorPart;
18
19 import sk.uniba.euromath.document.XMLAccess;
20 import sk.uniba.euromath.document.NamespaceManager.NodeCount;
21 import sk.uniba.euromath.editor.MultiViewXMLEditor;
22 import sk.uniba.euromath.editor.actions.MultiViewActionContributor;
23 import sk.uniba.euromath.editor.xmlEditor.actions.lang.Messages;
24 /***
25 * Shows some info about current document - location, namespaces, number of
26 * elements and attributes, etc etc.
27 * @author Martin Vysny
28 */
29 public class ShowDocumentPropertiesAction extends Action {
30 /***
31 * Owner contributor.
32 */
33 private final MultiViewActionContributor contributor;
34 /***
35 * Action constructor.
36 * @param contributor owner contributor.
37 */
38 public ShowDocumentPropertiesAction(
39 final MultiViewActionContributor contributor) {
40 super(ActionConsts.SHOW_DOCUMENT_PROPERTIES_TEXT);
41 this.contributor = contributor;
42
43 setId(ActionConsts.SHOW_DOCUMENT_PROPERTIES_ACTION);
44
45
46 setActionDefinitionId(ActionConsts.SHOW_DOCUMENT_PROPERTIES_ACTION);
47 }
48
49
50
51
52 @Override
53 public void run() {
54 final IEditorPart activeEditor = getContributor().getPage()
55 .getActiveEditor();
56 if (!(activeEditor instanceof MultiViewXMLEditor)) {
57 return;
58 }
59 final XMLAccess xml = ((MultiViewXMLEditor)activeEditor).getXMLAccess();
60
61 final StringBuilder builder = new StringBuilder();
62 builder.append(Messages.getString("ShowDocumentPropertiesAction.location")).append(xml.getDocumentURL().toString())
63 .append("\n");
64 builder.append(Messages.getString("ShowDocumentPropertiesAction.encoding")).append(xml.getEncoding()).append("\n\n");
65 builder.append(Messages.getString("ShowDocumentPropertiesAction.namespaces"));
66 final Map<String, NodeCount> nodeCount = xml.getNsManager().getCounts();
67 for (final String ns : nodeCount.keySet()) {
68 builder.append(Messages.getString("ShowDocumentPropertiesAction.namespace")).append(ns).append("}\n");
69 builder.append(Messages.getString("ShowDocumentPropertiesAction.prefixMapping")).append(
70 xml.getNsManager().getPrefix(ns)).append("\n");
71 final NodeCount nc = nodeCount.get(ns);
72 builder.append(Messages.getString("ShowDocumentPropertiesAction.elements")).append(nc.elements).append(
73 Messages.getString("ShowDocumentPropertiesAction.attributes")).append(nc.attributes).append("\n\n");
74 }
75
76 MessageDialog.openInformation(getContributor().getPage()
77 .getWorkbenchWindow().getShell(), xml.getFileName()
78 + Messages.getString("ShowDocumentPropertiesAction.properties"), builder.toString());
79 }
80 /***
81 * @return Returns the contributor.
82 */
83 protected MultiViewActionContributor getContributor() {
84 return this.contributor;
85 }
86 }