Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: c35883d375f2166c943e297b56ef22ef0234d88e (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.html.ui.views.contentoutline;



import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.wst.common.contentmodel.CMNode;
import org.eclipse.wst.common.contentmodel.util.DOMContentBuilder;
import org.eclipse.wst.common.encoding.content.IContentTypeIdentifier;
import org.eclipse.wst.html.core.HTMLCMProperties;
import org.eclipse.wst.html.core.PreferenceNames;
import org.eclipse.wst.html.core.format.HTMLFormatProcessorImpl;
import org.eclipse.wst.html.core.preferences.HTMLContentBuilder;
import org.eclipse.wst.sse.core.IStructuredModel;
import org.eclipse.wst.sse.core.format.IStructuredFormatProcessor;
import org.eclipse.wst.sse.core.preferences.CommonModelPreferenceNames;
import org.eclipse.wst.xml.ui.views.contentoutline.XMLNodeActionManager;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

/**
 * 
 */
public class HTMLNodeActionManager extends XMLNodeActionManager {
	protected String fTagCase;
	protected String fAttrCase;

	public HTMLNodeActionManager(IStructuredModel model, Viewer viewer) {
		super(model, viewer);
		updateCase();
	}

	/**
	 * If neccessary, employ a DOMContentBuilder that understands how to
	 * change the case of HTML tags (but NOT taglib derived tags).
	 */
	public DOMContentBuilder createDOMContentBuilder(Document document) {
		DOMContentBuilder builder = null;
		if (model.getModelHandler().getId().equals(IContentTypeIdentifier.ContentTypeID_HTML))
			builder = new HTMLContentBuilder(document);
		else
			builder = super.createDOMContentBuilder(document);

		return builder;
	}

	private boolean shouldIgnoreCase(CMNode cmnode) {
		if (!cmnode.supports(HTMLCMProperties.SHOULD_IGNORE_CASE))
			return false;
		return ((Boolean) cmnode.getProperty(HTMLCMProperties.SHOULD_IGNORE_CASE)).booleanValue();
	}

	/**
	 * Modify the displayed menuitem label to change the case of HTML children
	 * but neither XML nor taglib-derived children.
	 */
	public String getLabel(Node parent, CMNode cmnode) {
		String result = null;
		//CMNode cmnode = action.getCMNode();
		// don't change the case unless we're certain it is meaningless
		if (shouldIgnoreCase(cmnode)) {
			String name = cmnode.getNodeName();
			if (cmnode.getNodeType() == CMNode.ELEMENT_DECLARATION) {
				if (fTagCase.length() > 0) {
					if (fTagCase.equals(PreferenceNames.LOWER))
						name = name.toLowerCase();
					else if (fTagCase.equals(PreferenceNames.UPPER))
						name = name.toUpperCase();
					// else do nothing
				}
			}
			else if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
				if (fAttrCase.length() > 0) {
					if (fAttrCase.equals(PreferenceNames.LOWER))
						name = name.toLowerCase();
					else if (fAttrCase.equals(PreferenceNames.UPPER))
						name = name.toUpperCase();
					// else do nothing
				}
			}
			result = name;
		}
		else {
			result = super.getLabel(parent, cmnode);
		}

		return result;
	}

	/**
	 * Another HTML specific detail. 
	 */
	protected void updateCase() {
		if (model.getModelHandler().getAssociatedContentTypeId().equals(IContentTypeIdentifier.ContentTypeID_HTML)) {
			Preferences prefs = Platform.getPlugin("com.ibm.sse.model.html").getPluginPreferences(); //$NON-NLS-1$
			fTagCase = prefs.getString(CommonModelPreferenceNames.TAG_NAME_CASE);
			fAttrCase = prefs.getString(CommonModelPreferenceNames.ATTR_NAME_CASE);
			//		Element caseSettings = HTMLPreferenceManager.getHTMLInstance().getElement(PreferenceNames.PREFERRED_CASE);
			//		fTagCase = caseSettings.getAttribute(PreferenceNames.TAGNAME);
			//		fAttrCase = caseSettings.getAttribute(PreferenceNames.ATTRIBUTENAME);
		}
		else {
			fTagCase = "";//$NON-NLS-1$
			fAttrCase = "";//$NON-NLS-1$
		}
	}

	/* (non-Javadoc)
	 * @see com.ibm.sse.editor.xml.ui.actions.AbstractNodeActionManager#reformat(org.w3c.dom.Node, boolean)
	 */
	public void reformat(Node newElement, boolean deep) {
		try {
			// tell the model that we are about to make a big model change
			model.aboutToChangeModel();

			// format selected node
			IStructuredFormatProcessor formatProcessor = new HTMLFormatProcessorImpl();
			formatProcessor.formatNode(newElement);
		}
		finally {
			// tell the model that we are done with the big model change
			model.changedModel();
		}
	}
}

Back to the top