Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 510357c3303b9d6f6db084948f21b82129b87daf (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
/*******************************************************************************
 * 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.command;

import org.eclipse.jst.jsf.facesconfig.ui.pageflow.util.PageflowValidation;

/**
 * Change the end of a link.
 * 
 * @author hmeng
 * 
 */
public class ReconnectConnectionCommand extends ConnectionCommand {

	public ReconnectConnectionCommand() {
		// TODO Auto-generated constructor stub
	}

	public boolean canExecute() {
		// if user didn't set PFLink object beforehand, this command can't be
		// executed.
		if (link == null || link.eContainer() == null) {
			return false;
		}

		// Reconnect both source and target
		if (oldSource != null && source != null && oldTarget != null
				&& target != null) {
			if (!PageflowValidation.getInstance().isValidLinkForCreation(
					source, target)) {
				return false;
			}
		}

		// Reconnect source
		if (oldSource != null && source != null) {
			if (!PageflowValidation.getInstance().isValidLinkForCreation(
					source, oldTarget)) {
				return false;
			}
		}
		// Reconnect target
		if (oldTarget != null && target != null) {
			if (!PageflowValidation.getInstance().isValidLinkForCreation(
					oldSource, target)) {
				return false;
			}
		}

		return true;

	}

	public void doExecute() {
		String outcome = null, action = null, largeIcon = null, smallIcon = null;
		boolean isRedirect = false;
		outcome = link.getOutcome();
		action = link.getFromaction();
		isRedirect = link.isRedirect();
		largeIcon = link.getLargeicon();
		smallIcon = link.getSmallicon();
		// It is a reconnect source command
		if (oldSource != null && source != null) {
			link.setSource(source);
		}
		// It is a reconnect target command
		if (oldTarget != null && target != null) {
			link.setTarget(target);
		}
		link.setOutcome(outcome);
		link.setFromaction(action);
		link.setLargeicon(largeIcon);
		link.setSmallicon(smallIcon);
		link.setRedirect(isRedirect);
	}

	public void undo() {
		if (canExecute()) {
			// It was a reconnect source command
			if (oldSource != null && source != null) {
				// The link source must be replaced by the oldSource
				if (link.getSource() != null) {
					link.getSource().getOutlinks().remove(link);
				}
				source.getOutlinks().remove(link);
				link.setSource(oldSource);
			}
			// It was a reconnect target command
			if (oldTarget != null && target != null) {
				// The link target must be replaced by the oldTarget
				if (link.getTarget() != null) {
					link.getTarget().getInlinks().remove(link);
				}
				target.getInlinks().remove(link);
				link.setTarget(oldTarget);
			}
		}
	}

}

Back to the top