Skip to main content
summaryrefslogtreecommitdiffstats
blob: 327af05c9148a9dc0492848b08208bb239610035 (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
/*******************************************************************************
 * Copyright (c) 2004, 2005 Sybase, Inc. 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:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/

package org.eclipse.jst.jsf.facesconfig.ui.pageflow.util;

import org.eclipse.jst.jsf.facesconfig.emf.DescriptionType;
import org.eclipse.jst.jsf.facesconfig.emf.DisplayNameType;
import org.eclipse.jst.jsf.facesconfig.emf.IconType;
import org.eclipse.jst.jsf.facesconfig.emf.NavigationCaseType;
import org.eclipse.jst.jsf.facesconfig.emf.NavigationRuleType;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.model.Pageflow;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.model.PageflowPage;

/**
 * The tranform between pageflow and navigation rules in faces-config file.
 * 
 * @author Xiao-guang Zhang
 */
public class PageflowTransform {

	/** The shared singleton instance. */
	private static PageflowTransform transform;

	private PageflowTransform() {
		// private contructor
	}

	/**
	 * Returns the shared singleton instance.
	 * @return  the singleton transform instance
	 */
	public static PageflowTransform getInstance() {
		if (transform == null) {
			transform = new PageflowTransform();
		}
		return transform;
	}

	/**
	 * Update source PFPage with Faces-config model.
	 * 
	 * @param sourcePage
	 * @param navigationRuleFC
	 * @author sfshi
	 */
	public void updatePageflowSourcePage(PageflowPage sourcePage,
			NavigationRuleType navigationRuleFC) {
		// set the descriiption of link
		if (navigationRuleFC.getDescription() != null
				&& navigationRuleFC.getDescription().size() > 0) {
			String description = ((DescriptionType) navigationRuleFC
					.getDescription().get(0)).getTextContent();
			sourcePage.setComment(description);
		}
		// set the display-name of link
		if (navigationRuleFC.getDisplayName() != null
				&& navigationRuleFC.getDisplayName().size() > 0) {
			String displayName = ((DisplayNameType) navigationRuleFC
					.getDisplayName().get(0)).getTextContent();
			sourcePage.setName(displayName);
		}

		// Set the icon of link
		if (navigationRuleFC.getIcon() != null
				&& navigationRuleFC.getIcon().size() > 0) {
			boolean largeUpdated = false;
			boolean smallUpdated = false;
			for (int i = 0; i < navigationRuleFC.getIcon().size(); i++) {
				IconType icon = (IconType) navigationRuleFC.getIcon().get(i);
				if (!largeUpdated && icon.getLargeIcon() != null) {
					sourcePage.setLargeicon(icon.getLargeIcon()
							.getTextContent());
					largeUpdated = true;
				}

				if (!smallUpdated && icon.getSmallIcon() != null) {
					sourcePage.setSmallicon(icon.getSmallIcon()
							.getTextContent());
					smallUpdated = true;
				}
				if (largeUpdated && smallUpdated) {
					return;
				}
			}
		}
	}

	/**
	 * Update target PFPage with Faces-config model.
	 * 
	 * @param targetPage
	 * @param navigationCaseFC
	 * @author sfshi
	 */
	public void updatePageflowTargetPage(PageflowPage targetPage,
			NavigationCaseType navigationCaseFC) {
		// set the descriiption of link
		if (navigationCaseFC.getDescription() != null
				&& navigationCaseFC.getDescription().size() > 0) {
			String description = ((DescriptionType) navigationCaseFC
					.getDescription().get(0)).getTextContent();
			targetPage.setComment(description);
		}
		// set the display-name of link
		if (navigationCaseFC.getDisplayName() != null
				&& navigationCaseFC.getDisplayName().size() > 0) {
			String displayName = ((DisplayNameType) navigationCaseFC
					.getDisplayName().get(0)).getTextContent();
			targetPage.setName(displayName);
		}

		// Set the icon of link
		if (navigationCaseFC.getIcon() != null
				&& navigationCaseFC.getIcon().size() > 0) {
			boolean largeUpdated = false;
			boolean smallUpdated = false;
			for (int i = 0; i < navigationCaseFC.getIcon().size(); i++) {
				IconType icon = (IconType) navigationCaseFC.getIcon().get(0);
				if (!largeUpdated && icon.getLargeIcon() != null) {
					targetPage.setLargeicon(icon.getLargeIcon()
							.getTextContent());
					largeUpdated = true;
				}

				if (!smallUpdated && icon.getSmallIcon() != null) {
					targetPage.setSmallicon(icon.getSmallIcon()
							.getTextContent());
					smallUpdated = true;
				}
				if (largeUpdated && smallUpdated) {
					return;
				}
			}
		}
	}

	/**
	 * update the pageflow model 's information, including pageflow's name,
	 * description and related config file
	 * 
	 * @param newPageflow
	 * @param oldPageflow
	 */
	public static void updatePageflowModelInfo(Pageflow newPageflow,
			Pageflow oldPageflow) {
		if (newPageflow == null || oldPageflow == null) {
			return;
		}
		newPageflow.setName(oldPageflow.getName());
		newPageflow.setComment(oldPageflow.getComment());
		newPageflow.setConfigfile(oldPageflow.getConfigfile());

	}
}
// PageflowTransform

Back to the top