Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 53d0d8c9df5d16bff253a56a0b9a44740fb32a3a (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
/*******************************************************************************
 * 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.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.ResizableEditPolicy;
import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.command.AddNodeCommand;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.command.CreateNodeCommand;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.command.SetConstraintCommand;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.editpart.PageflowNodeEditPart;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.model.Pageflow;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.model.PageflowNode;

public class PageflowXYLayoutEditPolicy extends XYLayoutEditPolicy {
	/*
	 * (non-Javadoc)
	 * 
	 * @see XYLayoutEditPolicy#createAddCommand()
	 */
	protected Command createAddCommand(EditPart childEditPart, Object constraint) {
		PageflowNode part = (PageflowNode) childEditPart.getModel();
		Rectangle rect = (Rectangle) constraint;

		AddNodeCommand add = new AddNodeCommand();
		add.setParent((Pageflow) getHost().getModel());
		add.setChild(part);
		add.setLabel("add");
		add.setDebugLabel("PageFlowXYEP add subpart"); //$NON-NLS-1$

		SetConstraintCommand setConstraint = new SetConstraintCommand();

		setConstraint.setLocation(rect);
		setConstraint.setPart(part);
		setConstraint.setLabel("add");
		setConstraint.setDebugLabel("PageFlowXYEP setConstraint"); //$NON-NLS-1$
		return add.chain(setConstraint);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see XYLayoutEditPolicy#createChangeConstraintCommand()
	 */
	protected Command createChangeConstraintCommand(EditPart child,
			Object constraint) {
		SetConstraintCommand locationCommand = new SetConstraintCommand();
		locationCommand.setPart((PageflowNode) child.getModel());
		locationCommand.setLocation((Rectangle) constraint);
		return locationCommand;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see XYLayoutEditPolicy#createChildEditPolicy()
	 */
	protected EditPolicy createChildEditPolicy(EditPart child) {
		if (child instanceof PageflowNodeEditPart) {
			return new PageflowNodeSelectionEditPolicy();
		}

		return new ResizableEditPolicy();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see XYLayoutEditPolicy#getCreateCommand()
	 */
	protected Command getCreateCommand(CreateRequest request) {
		CreateNodeCommand create = new CreateNodeCommand();
		create.setParent((Pageflow) getHost().getModel());
		create.setChild((PageflowNode) request.getNewObject());
		Rectangle constraint = (Rectangle) getConstraintFor(request);
		create.setLocation(constraint);
		create.setLabel("Add");
		return create;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see XYLayoutEditPolicy#getDeleteDependantCommand()
	 */
	protected Command getDeleteDependantCommand(Request request) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see XYLayoutEditPolicy#getOrphanChildrenCommand()
	 */
	protected Command getOrphanChildrenCommand(Request request) {
		return null;
	}
}

Back to the top