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

import org.eclipse.gef.commands.Command;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.PageflowMessages;
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.synchronization.TransformUtil;

/**
 * This is the connection command for pageflow editpart
 * 
 * @author Xiao-guang Zhang, hmeng
 */
public abstract class ConnectionCommand extends Command {
	/** Old source pageflow node */
	protected PageflowNode oldSource;

	/** Old target pageflow node */
	protected PageflowNode oldTarget;

	/** New source pageflow node */
	protected PageflowNode source;

	/** New target pageflow node */
	protected PageflowNode target;

	/** pageflow link */
	protected PageflowLink link;

	/**
	 * Default constructor
	 */
	public ConnectionCommand() {
		super(PageflowMessages.Pageflow_Commands_ConnectionCommand_Label);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see Command#canExecute()
	 */
	public boolean canExecute() {
		return TransformUtil.isValidPageflowElement(link);
	}

	/**
	 * perform the main command execution.  Sub-classes should override.
	 */
	protected void doExecute() {
	    // do nothing; sub-class can over-ride
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see Command#execute()
	 */
	public final void execute() {
		if (canExecute()) {
			doExecute();
		} else {
			link = null;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see Command#redo()
	 */
	public void redo() {
		execute();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ommand#undo()
	 */
	public void undo() {
        // do nothing
	}

	/**
	 * Get the source pageflow node
	 * 
	 * @return - the source pageflow node
	 */
	public PageflowNode getSource() {
		return source;
	}

	/**
	 * Get the target pageflow node
	 * 
	 * @return - the target pageflow node.
	 */
	public PageflowNode getTarget() {
		return target;
	}

	/**
	 * Get the pageflow link
	 * 
	 * @return - the pageflow link.
	 */
	public PageflowLink getPFLink() {
		return link;
	}

	/**
	 * Set the source pageflow node
	 * 
	 * @param newSource -
	 *            new source pageflow node
	 */
	public void setSource(PageflowNode newSource) {
		source = newSource;
	}

	/**
	 * Set the target pageflow node
	 * 
	 * @param newTarget -
	 *            new target pageflow node
	 */
	public void setTarget(PageflowNode newTarget) {
		target = newTarget;
	}

	/**
	 * Set the pageflow link
	 * 
	 * @param link -
	 *            new pageflow link
	 */
	public void setPFLink(PageflowLink link) {
		this.link = link;
		oldSource = link.getSource();
		oldTarget = link.getTarget();
	}
}

Back to the top