Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0094d182a048eb9034276bd29661d5e77edecc32 (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
/*******************************************************************************
 * Copyright (c) 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.pagedesigner.validation.caret;

import java.util.Arrays;

import org.eclipse.jst.pagedesigner.IHTMLConstants;
import org.eclipse.jst.pagedesigner.IJSFConstants;
import org.eclipse.jst.pagedesigner.dom.EditModelQuery;
import org.w3c.dom.Node;

/**
 * @author mengbo
 */
public class ContainerMoveInAndOutRule extends DefaultMovementRule {
	public final String[] HTML_CONTAINERS = { IHTMLConstants.TAG_TABLE };

	public final String[] NONE_HTML_CONTAINERS = {};

	public final String[] SPECIAL_HTML_CONTAINERS = {
			IJSFConstants.TAG_OUTPUTLINK, IJSFConstants.TAG_COMMANDLINK,
			IJSFConstants.TAG_FACET, IJSFConstants.TAG_VERBATIM };

	/**
	 * @param actionData
	 */
	public ContainerMoveInAndOutRule(ActionData actionData) {
		super(actionData);
		// TODO Auto-generated constructor stub
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.caret.IMovementRule#canEnter(org.w3c.dom.Node)
	 */
	public boolean allowsMoveIn(Target target) {
		Node node = target.getNode();
		if (node.getLocalName() != null && //
				(Arrays.asList(HTML_CONTAINERS).contains(node.getLocalName()
						.toLowerCase())) || //
				Arrays.asList(NONE_HTML_CONTAINERS).contains(
						node.getLocalName()) || //
				Arrays.asList(SPECIAL_HTML_CONTAINERS).contains(
						node.getLocalName())) {
			return false;
		}
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.caret.IMovementRule#canMoveOut(org.eclipse.gef.EditPart)
	 */
	public boolean allowsMoveOut(Target target) {
		Node node = target.getNode();
		if (EditModelQuery.isDocument(node)) {
			return false;
		}

		if (_actionData.getActionType() == ActionData.INLINE_EDIT
				&& (IHTMLConstants.TAG_TD.equalsIgnoreCase(node.getLocalName()) || IHTMLConstants.TAG_TH
						.equalsIgnoreCase(node.getLocalName()))) {
			return false;
		}
		if (node.getLocalName() != null && //
				(Arrays.asList(HTML_CONTAINERS).contains(node.getLocalName()
						.toLowerCase())) || //
				Arrays.asList(NONE_HTML_CONTAINERS).contains(
						node.getLocalName())) {
			return false;
		}

		if (node.getLocalName() != null
				&& (Arrays.asList(
						RootContainerPositionRule.HTML_ROOT_CONTAINERS)
						.contains(node.getLocalName().toLowerCase()) || //
				Arrays.asList(JSFRootContainerPositionRule.JSF_ROOT_CONTAINERS)
						.contains(node.getLocalName()))) {
			if (!EditModelQuery.isChild(
					JSFRootContainerPositionRule.JSF_ROOT_CONTAINERS, node,
					false, true)
					&& //
					!EditModelQuery.isChild(
							RootContainerPositionRule.HTML_ROOT_CONTAINERS,
							node, true, true)) {
				return false;
			}
		}
		return true;
	}
}

Back to the top