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

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
import org.eclipse.gef.requests.CreateConnectionRequest;
import org.eclipse.gef.requests.ReconnectRequest;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jst.jsf.facesconfig.ui.EditorPlugin;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.action.OpenEditorAction;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.command.ConnectionCommand;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.command.ConnectionCommandFactory;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.command.OpenEditorCommand;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.editpart.PageflowNodeEditPart;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.figure.PageflowNodeFigure;
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.impl.PageflowNodeImpl;
import org.eclipse.jst.jsf.facesconfig.ui.preference.GEMPreferences;

public class PageflowNodeEditPolicy extends GraphicalNodeEditPolicy {
	/*
	 * (non-Javadoc)
	 * 
	 * @see GraphicalNodeEditPolicy#createDummyConnection()
	 */
	protected Connection createDummyConnection(Request req) {
		PolylineConnection conn = new PolylineConnection();
		conn.setLineWidth(getLineWidth());
		conn.setForegroundColor(ColorConstants.black);

		return conn;
	}

	/**
	 * get the connection line width from preference.
	 */
	private int getLineWidth() {
		IPreferenceStore store = EditorPlugin.getDefault().getPreferenceStore();
		int lineWidth = store.getInt(GEMPreferences.LINE_WIDTH);
		return lineWidth;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see GraphicalNodeEditPolicy#getConnectionCompleteCommand()
	 */
	protected Command getConnectionCompleteCommand(
			CreateConnectionRequest request) {
		ConnectionCommand command = (ConnectionCommand) request
				.getStartCommand();
		// ConnectionAnchor anchor =
		// getPageflowNodeEditPart().getTargetConnectionAnchor(request);

		command.setTarget(getPageflowNode());

		return command;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see GraphicalNodeEditPolicy#getConnectionCreateCommand()
	 */
	protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
		ConnectionCommand command = ConnectionCommandFactory
				.createCommand(request);
		command.setPFLink((PageflowLink) request.getNewObject());
		PageflowNode flowObject = getPageflowNode();
		command.setSource(flowObject);
		request.setStartCommand(command);
		return command;
	}

	/**
	 * get the edit part of pageflow node
	 * 
	 * @return - the edit part of pageflow node
	 */
	protected PageflowNodeEditPart getPageflowNodeEditPart() {
		return (PageflowNodeEditPart) getHost();
	}

	/**
	 * get the pageflow node
	 * 
	 * @return - the pageflow node
	 */
	protected PageflowNode getPageflowNode() {
		return (PageflowNode) getHost().getModel();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see GraphicalNodeEditPolicy#getReconnectTargetCommand()
	 */
	protected Command getReconnectTargetCommand(ReconnectRequest request) {
		ConnectionCommand cmd = ConnectionCommandFactory.createCommand(request);
		cmd
				.setPFLink((PageflowLink) request.getConnectionEditPart()
						.getModel());
		cmd.setTarget(getPageflowNode());
		return cmd;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see GraphicalNodeEditPolicy#getReconnectSourceCommand()
	 */
	protected Command getReconnectSourceCommand(ReconnectRequest request) {
		ConnectionCommand cmd = ConnectionCommandFactory.createCommand(request);
		cmd
				.setPFLink((PageflowLink) request.getConnectionEditPart()
						.getModel());
		cmd.setSource(getPageflowNode());
		return cmd;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see GraphicalNodeEditPolicy#getCommand()
	 */
	public Command getCommand(Request request) {
		if (OpenEditorAction.OPEN_EDITOR_REQUEST.equals(request.getType())) {
			OpenEditorCommand command = new OpenEditorCommand(getHost());

			command.setChild((PageflowNodeImpl) getHost().getModel());

			return command;
		}

		return super.getCommand(request);
	}

	/**
	 * return the pageflow node figure
	 * 
	 * @return - the pageflow node's figure
	 */
	protected PageflowNodeFigure getPageflowNodeFigure() {
		return (PageflowNodeFigure) ((GraphicalEditPart) getHost()).getFigure();
	}
}

Back to the top