Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: efea43c1dbefe9acae078f9835c485ef02a89870 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/**
 * Copyright (c) 2008, 2009 Oracle Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Oracle Corporation - initial API and implementation
 */
package org.eclipse.jst.jsf.apache.trinidad.tagsupport.converter.operations;

import java.util.Iterator;
import java.util.List;

import org.eclipse.jst.jsf.apache.trinidad.tagsupport.Messages;
import org.eclipse.jst.jsf.apache.trinidad.tagsupport.model.SelectItem;
import org.eclipse.jst.jsf.apache.trinidad.tagsupport.model.SelectItemModel;
import org.eclipse.jst.pagedesigner.converter.ConvertPosition;
import org.w3c.dom.Element;

/**
 * ITransformOperation implementation specifically for "selectManyShuttle" and
 * "selectOrderShuttle" JSF Elements.
 * 
 * <br><b>Note:</b> requires ITransformOperation.setTagConverterContext(...) to
 * have been called to provide a valid ITagConverterContext instance prior to
 * a call to the transform(...) method.
 * 
 * @author Ian Trimble - Oracle
 */
public class SelectShuttleOperation extends AbstractTrinidadTransformOperation {

	private static final String STYLECLASS_OUTERTABLE = "af_selectManyShuttle p_AFRequired"; //$NON-NLS-1$
	private static final String STYLECLASS_HEADER = "OraShuttleHeader"; //$NON-NLS-1$
	private static final String STYLECLASS_REQUIRED = "AFRequiredIconStyle"; //$NON-NLS-1$
	private static final String STYLECLASS_LISTCOLUMN = "af_selectManyShuttle_box-content"; //$NON-NLS-1$
	private static final String STYLECLASS_SELECT = "af_selectManyListbox_content"; //$NON-NLS-1$
	private static final String STYLECLASS_DESCRIPTION = "AFInstructionText"; //$NON-NLS-1$
	private static final String STYLECLASS_LINK = "OraLinkText"; //$NON-NLS-1$
	private static final String DEFAULT_SIZE = "10"; //$NON-NLS-1$

	private static final String[] LINKS_MOVE = new String[]{
		Messages.SelectShuttleOperation_LinkMove,
		Messages.SelectShuttleOperation_LinkMoveAll,
		Messages.SelectShuttleOperation_LinkRemove,
		Messages.SelectShuttleOperation_LinkRemoveAll
	};
	private static final String[] LINKS_ORDER = new String[]{
		Messages.SelectShuttleOperation_LinkTop,
		Messages.SelectShuttleOperation_LinkUp,
		Messages.SelectShuttleOperation_LinkDown,
		Messages.SelectShuttleOperation_LinkBottom
	};

	private boolean showOrderLinks;

	/* (non-Javadoc)
	 * @see org.eclipse.jst.pagedesigner.dtmanager.converter.operations.AbstractTransformOperation#transform(org.w3c.dom.Element, org.w3c.dom.Element)
	 */
	@Override
	public Element transform(Element srcElement, Element curElement) {
		//get parameter
		if (getParameters().length < 1) {
			getLog().error("Warning.TransformOperationFactory.TooFewParameters", getTransformOperationID()); //$NON-NLS-1$
			return null;
		} else {
			showOrderLinks = Boolean.parseBoolean(getParameters()[0]);
		}
		
		//build outer table element
		Element outerTableElement = createElement("table"); //$NON-NLS-1$
		appendAttribute(outerTableElement, "cellpadding", "0"); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(outerTableElement, "cellspacing", "0"); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(outerTableElement, "border", "0"); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(outerTableElement, "width", "10%"); //$NON-NLS-1$ //$NON-NLS-2$
		String inlineStyle = srcElement.getAttribute("inlineStyle"); //$NON-NLS-1$
		if (inlineStyle != null && inlineStyle.length() > 0) {
			appendAttribute(outerTableElement, "style", inlineStyle); //$NON-NLS-1$
		}
		String styleClass = srcElement.getAttribute("styleClass"); //$NON-NLS-1$
		if (styleClass != null && styleClass.length() > 0) {
			appendAttribute(outerTableElement, "class", styleClass + " " + STYLECLASS_OUTERTABLE); //$NON-NLS-1$ //$NON-NLS-2$
		} else {
			appendAttribute(outerTableElement, "class", STYLECLASS_OUTERTABLE); //$NON-NLS-1$
		}

		//build header row
		Element trHeaderElement = appendChildElement("tr", outerTableElement); //$NON-NLS-1$
		Element tdLeadingHeaderElement = appendChildElement("td", trHeaderElement); //$NON-NLS-1$
		String leadingHeader = srcElement.getAttribute("leadingHeader"); //$NON-NLS-1$
		if (leadingHeader != null && leadingHeader.length() > 0) {
			appendAttribute(tdLeadingHeaderElement, "class", STYLECLASS_HEADER); //$NON-NLS-1$
			appendAttribute(tdLeadingHeaderElement, "valign", "bottom"); //$NON-NLS-1$ //$NON-NLS-2$
			appendChildText(leadingHeader, tdLeadingHeaderElement);
		}
		appendChildElement("td", trHeaderElement); //$NON-NLS-1$
		Element tdTrailingHeaderElement = appendChildElement("td", trHeaderElement); //$NON-NLS-1$
		String required = srcElement.getAttribute("required"); //$NON-NLS-1$
		String trailingHeader = srcElement.getAttribute("trailingHeader"); //$NON-NLS-1$
		if ((required != null && Boolean.parseBoolean(required)) || (trailingHeader != null && trailingHeader.length() > 0)) {
			appendAttribute(tdTrailingHeaderElement, "class", STYLECLASS_HEADER); //$NON-NLS-1$
			appendAttribute(tdTrailingHeaderElement, "valign", "bottom"); //$NON-NLS-1$ //$NON-NLS-2$
			if (required != null && Boolean.parseBoolean(required)) {
				Element spanRequiredElement = appendChildElement("span", tdTrailingHeaderElement); //$NON-NLS-1$
				appendAttribute(spanRequiredElement, "class", STYLECLASS_REQUIRED); //$NON-NLS-1$
				appendChildText("*", spanRequiredElement); //$NON-NLS-1$
			}
			if (trailingHeader != null && trailingHeader.length() > 0) {
				appendChildText(trailingHeader, tdTrailingHeaderElement);
			}
		}

		//build content row
		Element trContentElement = appendChildElement("tr", outerTableElement); //$NON-NLS-1$
		buildListColumn(srcElement, trContentElement, true);
		buildLinkColumn(trContentElement, LINKS_MOVE);
		buildListColumn(srcElement, trContentElement, false);

		return outerTableElement;
	}

	private void buildListColumn(Element srcElement, Element parentElement, boolean isLeadingColumn) {
		//build outer structure
		Element tdElement0 = appendChildElement("td", parentElement); //$NON-NLS-1$
		Element tableElement0 = appendChildElement("table", tdElement0); //$NON-NLS-1$
		appendAttribute(tableElement0, "style", "width:100%;"); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(tableElement0, "cellpadding", "0"); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(tableElement0, "cellspacing", "0"); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(tableElement0, "border", "0"); //$NON-NLS-1$ //$NON-NLS-2$
		Element tbodyElement0 = appendChildElement("tbody", tableElement0); //$NON-NLS-1$
		Element trElement0 = appendChildElement("tr", tbodyElement0); //$NON-NLS-1$
		Element tdElement1 = appendChildElement("td", trElement0); //$NON-NLS-1$
		Element divElement0 = appendChildElement("div", tdElement1); //$NON-NLS-1$
		appendAttribute(divElement0, "class", STYLECLASS_LISTCOLUMN); //$NON-NLS-1$
		Element tableElement1 = appendChildElement("table", divElement0); //$NON-NLS-1$
		appendAttribute(tableElement1, "cellpadding", "0"); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(tableElement1, "border", "0"); //$NON-NLS-1$ //$NON-NLS-2$

		//build filter structure
		if (isLeadingColumn) {
			Element filterFacet = getChildFacetByName(srcElement, "filter"); //$NON-NLS-1$
			if (filterFacet != null) {
				Element trFilterElement = appendChildElement("tr", tableElement1); //$NON-NLS-1$
				Element tdFilterElement = appendChildElement("td", trFilterElement); //$NON-NLS-1$
				appendAttribute(tdFilterElement, "nowrap", ""); //$NON-NLS-1$ //$NON-NLS-2$
				appendAttribute(tdFilterElement, "valign", "middle"); //$NON-NLS-1$ //$NON-NLS-2$
				appendAttribute(tdFilterElement, "colspan", "3"); //$NON-NLS-1$ //$NON-NLS-2$
				tagConverterContext.addChild(filterFacet, new ConvertPosition(tdFilterElement, 0));
			}
		}

		//build select element structure
		Element trSelectElement = appendChildElement("tr", tableElement1); //$NON-NLS-1$
		Element tdSelectElement = appendChildElement("td", trSelectElement); //$NON-NLS-1$
		appendAttribute(tdSelectElement, "nowrap", ""); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(tdSelectElement, "valign", "middle"); //$NON-NLS-1$ //$NON-NLS-2$
		Element spanSelectElement = appendChildElement("span", tdSelectElement); //$NON-NLS-1$
		Element selectElement = appendChildElement("select", spanSelectElement); //$NON-NLS-1$
		appendAttribute(selectElement, "multiple", ""); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(selectElement, "class", STYLECLASS_SELECT); //$NON-NLS-1$
		appendAttribute(selectElement, "size", getSizeString(srcElement)); //$NON-NLS-1$

		if (isLeadingColumn) {
			List<SelectItem> selectItems = SelectItemModel.getModel(srcElement);
			Iterator<SelectItem> itSelectItems = selectItems.iterator();
			while (itSelectItems.hasNext()) {
				SelectItem selectItem = itSelectItems.next();
				Element optionElement = appendChildElement("option", selectElement); //$NON-NLS-1$
				appendChildText(selectItem.getLabel(), optionElement);
			}
		}
		Element optionElement = appendChildElement("option", selectElement); //$NON-NLS-1$
		appendChildText("_______________", optionElement); //$NON-NLS-1$

		//build order links
		if (!isLeadingColumn && showOrderLinks) {
			buildLinkColumn(trSelectElement, LINKS_ORDER);
		}

		//build description structure
		boolean showDesc = false;
		String showDescAttrName;
		if (isLeadingColumn) {
			showDescAttrName = "leadingDescShown"; //$NON-NLS-1$
		} else {
			showDescAttrName = "trailingDescShown"; //$NON-NLS-1$
		}
		String showDescAttr = srcElement.getAttribute(showDescAttrName);
		if (showDescAttr != null && showDescAttr.length() > 0) {
			showDesc = Boolean.parseBoolean(showDescAttr);
		}
		if (showDesc) {
			Element trDescElement = appendChildElement("tr", tableElement1); //$NON-NLS-1$
			Element tdDescElement = appendChildElement("td", trDescElement); //$NON-NLS-1$
			appendAttribute(tdDescElement, "nowrap", ""); //$NON-NLS-1$ //$NON-NLS-2$
			appendAttribute(tdDescElement, "valign", "middle"); //$NON-NLS-1$ //$NON-NLS-2$
			appendAttribute(tdDescElement, "colspan", "3"); //$NON-NLS-1$ //$NON-NLS-2$
			Element spanDescElement = appendChildElement("span", tdDescElement); //$NON-NLS-1$
			appendAttribute(spanDescElement, "class", STYLECLASS_DESCRIPTION); //$NON-NLS-1$
			appendChildText(Messages.SelectShuttleOperation_Description, spanDescElement);
			appendChildElement("div", tdDescElement); //$NON-NLS-1$
			Element textareaElement = appendChildElement("textarea", tdDescElement); //$NON-NLS-1$
			appendAttribute(textareaElement, "rows", "2"); //$NON-NLS-1$ //$NON-NLS-2$
			appendAttribute(textareaElement, "cols", "18"); //$NON-NLS-1$ //$NON-NLS-2$
			appendAttribute(textareaElement, "readonly", ""); //$NON-NLS-1$ //$NON-NLS-2$
		}

		//build footer structure
		String footerFacetName;
		if (isLeadingColumn) {
			footerFacetName = "leadingFooter"; //$NON-NLS-1$
		} else {
			footerFacetName = "trailingFooter"; //$NON-NLS-1$
		}
		Element footerFacet = getChildFacetByName(srcElement, footerFacetName); 
		if (footerFacet != null) {
			Element trFooterElement = appendChildElement("tr", tableElement1); //$NON-NLS-1$
			Element tdFooterElement = appendChildElement("td", trFooterElement); //$NON-NLS-1$
			appendAttribute(tdFooterElement, "nowrap", ""); //$NON-NLS-1$ //$NON-NLS-2$
			appendAttribute(tdFooterElement, "valign", "middle"); //$NON-NLS-1$ //$NON-NLS-2$
			appendAttribute(tdFooterElement, "colspan", "3"); //$NON-NLS-1$ //$NON-NLS-2$
			tagConverterContext.addChild(footerFacet, new ConvertPosition(tdFooterElement, 0));
		}
	}

	private void buildLinkColumn(Element parentElement, String[] linkText) {
		Element tdElement = appendChildElement("td", parentElement); //$NON-NLS-1$
		appendAttribute(tdElement, "align", "center"); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(tdElement, "valign", "middle"); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(tdElement, "nowrap", ""); //$NON-NLS-1$ //$NON-NLS-2$
		appendAttribute(tdElement, "style", "padding:5px;"); //$NON-NLS-1$ //$NON-NLS-2$
		for (int i = 0; i < linkText.length; i++) {
			Element aElement = appendChildElement("a", tdElement); //$NON-NLS-1$
			appendAttribute(aElement, "href", "#"); //$NON-NLS-1$ //$NON-NLS-2$
			appendAttribute(aElement, "class", STYLECLASS_LINK); //$NON-NLS-1$
			appendChildText(linkText[i], aElement);
			if (i < linkText.length - 1) {
				appendChildElement("br", tdElement); //$NON-NLS-1$
			}
		}
	}

	private String getSizeString(Element srcElement) {
		String size = DEFAULT_SIZE;
		String sizeAttr = srcElement.getAttribute("size"); //$NON-NLS-1$
		if (sizeAttr != null && sizeAttr.length() > 0) {
			try {
				int iSize = Integer.parseInt(sizeAttr);
				iSize = Math.max(iSize, 10);
				iSize = Math.min(iSize, 20);
				size = String.valueOf(iSize);
			} catch(NumberFormatException nfe) {
				//ignore - default of "10" will be returned
			}
		}
		return size;
	}

}

Back to the top