Skip to main content
summaryrefslogtreecommitdiffstats
blob: d2b40b9920bbeb8b62674e45ebdc31bbb46fe22c (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
/*******************************************************************************
 * Copyright (c) 2004, 2006 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.synchronization;

import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jst.jsf.facesconfig.emf.FacesConfigType;
import org.eclipse.jst.jsf.facesconfig.emf.FromOutcomeType;
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.PageflowLink;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.model.PageflowNode;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.model.PageflowPage;

/**
 * The util for pageflow and faces-config transforming
 * 
 * @author hmeng
 */

public class TransformUtil {

	/**
	 * To see if the faces-config element is on a valid hirachy.
	 * @param object 
	 * @return true if object's root ancestor is a facesConfig model
	 */
	public static boolean isValidFacesConfigElement(EObject object) {
		EObject parent = EcoreUtil.getRootContainer(object);
		boolean result = parent instanceof FacesConfigType;
		return result;
	}

	/**
	 * To see if the pageflow element is on a valid hirachy.
	 * @param element 
	 * @return true if element's root ancestor is a page flow element
	 */
	public static boolean isValidPageflowElement(EObject element) {
		EObject root = EcoreUtil.getRootContainer(element);
		boolean result = root instanceof Pageflow;
		return result;
	}

	/**
	 * @param link
	 * @return true the link is valid
	 */
	public static boolean isValidLink(PageflowLink link) {
		return isValidPageflowElement(link) && link.getSource() != null
				&& link.getTarget() != null;
	}

	/**
	 * @param rule
	 * @return gets the from-view-id from rule
	 */
	public static String getFromViewID(NavigationRuleType rule) {
		String result = "*"; //$NON-NLS-1$
		if (rule.getFromViewId() != null) {
			result = rule.getFromViewId().getTextContent();
		}
		return result;
	}

	/**
	 * @param navCase
	 * @return gets the to-view-id from navCase
	 */
	public static String getToViewID(NavigationCaseType navCase) {
		String result = "*"; //$NON-NLS-1$
		if (navCase.getToViewId() != null) {
			result = navCase.getToViewId().getTextContent();
		}
		return result;
	}

	/**
	 * @param path
	 * @param pageflow
	 * @return get pageflowpage in pageflow corresponding to path
	 */
	public static PageflowPage findPage(String path, Pageflow pageflow) {
		List nodes = pageflow.getNodes();
		for (int i = 0; i < nodes.size(); i++) {
			if (nodes.get(i) instanceof PageflowPage) {
				if (path != null) {
					if (path.equals(((PageflowPage) nodes.get(i)).getPath())) {
						return (PageflowPage) nodes.get(i);
					}
				}
			}
		}
		return null;
	}

	/**
	 * @param action
	 * @param outcome
	 * @param pageflow
	 * @return find the end case
	 */
	public static PageflowNode findCaseEnd(PageflowPage action,
			FromOutcomeType outcome, Pageflow pageflow) {
		// TODO: find a case end in pageflow model
		List links = action.getOutlinks();
		for (int i = 0; i < links.size(); i++) {
			PageflowLink link = (PageflowLink) links.get(i);
			String outcomeStr = ""; //$NON-NLS-1$
			if (outcome != null) {
				outcomeStr = outcome.getTextContent();
			}
			if (link.getOutcome().equals(outcomeStr)) {
				return link.getTarget();
			}
		}
		return null;
	}
}

Back to the top