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