01: /*******************************************************************************
02: * Copyright (c) 2000, 2004 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Common Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/cpl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.openwfe.gpe.policies;
11:
12: import java.util.List;
13:
14: import org.eclipse.gef.EditPart;
15: import org.eclipse.gef.EditPolicy;
16: import org.eclipse.gef.Request;
17: import org.eclipse.gef.commands.Command;
18: import org.eclipse.gef.commands.CompoundCommand;
19: import org.eclipse.gef.editpolicies.LayoutEditPolicy;
20: import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
21: import org.eclipse.gef.requests.ChangeBoundsRequest;
22: import org.eclipse.gef.requests.CreateRequest;
23:
24: import org.openwfe.gpe.model.CompositeOrOneChild;
25: import org.openwfe.gpe.model.FlowElement;
26: import org.openwfe.gpe.model.commands.AddCommand;
27: import org.openwfe.gpe.model.commands.CreateCommand;
28: import org.openwfe.gpe.parts.NoChildPart;
29:
30: /**
31: * @author Daniel Lee
32: */
33: public class StructuredActivityLayoutEditPolicy extends
34: LayoutEditPolicy {
35:
36: protected Command createAddCommand(EditPart child) {
37: FlowElement activity = (FlowElement) child.getModel();
38: AddCommand add = new AddCommand();
39: add.setParent((CompositeOrOneChild) getHost().getModel());
40: add.setChild(activity);
41: return add;
42: }
43:
44: /**
45: * @see org.eclipse.gef.editpolicies.OrderedLayoutEditPolicy#createChildEditPolicy(org.eclipse.gef.EditPart)
46: */
47: protected EditPolicy createChildEditPolicy(EditPart child) {
48: if (child instanceof NoChildPart)
49: return new SimpleActivitySelectionEditPolicy();
50: return new NonResizableEditPolicy();
51: }
52:
53: protected Command createMoveChildCommand(EditPart child,
54: EditPart after) {
55: return null;
56: }
57:
58: protected Command getAddCommand(Request req) {
59: ChangeBoundsRequest request = (ChangeBoundsRequest) req;
60: List editParts = request.getEditParts();
61: CompoundCommand command = new CompoundCommand();
62: for (int i = 0; i < editParts.size(); i++) {
63: EditPart child = (EditPart) editParts.get(i);
64: command.add(createAddCommand(child));
65: }
66: return command.unwrap();
67: }
68:
69: /**
70: * @see LayoutEditPolicy#getCreateCommand(org.eclipse.gef.requests.CreateRequest)
71: */
72: protected Command getCreateCommand(CreateRequest request) {
73: CreateCommand command = new CreateCommand();
74: command.setParent((CompositeOrOneChild) getHost().getModel());
75: command.setChild((FlowElement) request.getNewObject());
76: return command;
77: }
78:
79: /**
80: * @see LayoutEditPolicy#getDeleteDependantCommand(org.eclipse.gef.Request)
81: */
82: protected Command getDeleteDependantCommand(Request request) {
83: return null;
84: }
85:
86: /**
87: * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getMoveChildrenCommand(org.eclipse.gef.Request)
88: */
89: protected Command getMoveChildrenCommand(Request request) {
90: return null;
91: }
92:
93: }
|