org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy 中一个方法
1 /**
2 * Method getCreateElementAndViewCommand.
3 *
4 * @param request
5 * @return Command Which creates the sematnic and the view command for the
6 * given CreateViewAndElementRequest
7 */
8 protected Command getCreateElementAndViewCommand(CreateViewAndElementRequest request) {
9 // get the element descriptor
10 CreateElementRequestAdapter requestAdapter =
11 request.getViewAndElementDescriptor().getCreateElementRequestAdapter();
12
13 // get the semantic request
14 CreateElementRequest createElementRequest =
15 (CreateElementRequest) requestAdapter.getAdapter(
16 CreateElementRequest.class);
17
18 if (createElementRequest.getContainer() == null) {
19 // complete the semantic request by filling in the host's semantic
20 // element as the context
21 View view = (View)getHost().getModel();
22 EObject hostElement = ViewUtil.resolveSemanticElement(view);
23
24 if (hostElement == null && view.getElement() == null) {
25 hostElement = view;
26 }
27
28 // Returns null if host is unresolvable so that trying to create a
29 // new element in an unresolved shape will not be allowed.
30 if (hostElement == null) {
31 return null;
32 }
33 createElementRequest.setContainer(hostElement);
34 }
35
36 // get the create element command based on the elementdescriptor's
37 // request
38 Command createElementCommand =
39 getHost().getCommand(
40 new EditCommandRequestWrapper(
41 (CreateElementRequest)requestAdapter.getAdapter(
42 CreateElementRequest.class), request.getExtendedData()));
43
44 if (createElementCommand == null)
45 return UnexecutableCommand.INSTANCE;
46
47 // create the semantic create wrapper command
48 SemanticCreateCommand semanticCommand =
49 new SemanticCreateCommand(requestAdapter, createElementCommand);
50 Command viewCommand = getCreateCommand(request);
51
52 Command refreshConnectionCommand =
53 getHost().getCommand(
54 new RefreshConnectionsRequest(((List)request.getNewObject())));
55
56
57 // form the compound command and return
58 CompositeCommand cc = new CompositeCommand(semanticCommand.getLabel());
59 cc.compose(semanticCommand);
60 cc.compose(new CommandProxy(viewCommand));
61 if ( refreshConnectionCommand != null ) {
62 cc.compose(new CommandProxy(refreshConnectionCommand));
63 }
64
65 return new ICommandProxy(cc);
66 }
2 * Method getCreateElementAndViewCommand.
3 *
4 * @param request
5 * @return Command Which creates the sematnic and the view command for the
6 * given CreateViewAndElementRequest
7 */
8 protected Command getCreateElementAndViewCommand(CreateViewAndElementRequest request) {
9 // get the element descriptor
10 CreateElementRequestAdapter requestAdapter =
11 request.getViewAndElementDescriptor().getCreateElementRequestAdapter();
12
13 // get the semantic request
14 CreateElementRequest createElementRequest =
15 (CreateElementRequest) requestAdapter.getAdapter(
16 CreateElementRequest.class);
17
18 if (createElementRequest.getContainer() == null) {
19 // complete the semantic request by filling in the host's semantic
20 // element as the context
21 View view = (View)getHost().getModel();
22 EObject hostElement = ViewUtil.resolveSemanticElement(view);
23
24 if (hostElement == null && view.getElement() == null) {
25 hostElement = view;
26 }
27
28 // Returns null if host is unresolvable so that trying to create a
29 // new element in an unresolved shape will not be allowed.
30 if (hostElement == null) {
31 return null;
32 }
33 createElementRequest.setContainer(hostElement);
34 }
35
36 // get the create element command based on the elementdescriptor's
37 // request
38 Command createElementCommand =
39 getHost().getCommand(
40 new EditCommandRequestWrapper(
41 (CreateElementRequest)requestAdapter.getAdapter(
42 CreateElementRequest.class), request.getExtendedData()));
43
44 if (createElementCommand == null)
45 return UnexecutableCommand.INSTANCE;
46
47 // create the semantic create wrapper command
48 SemanticCreateCommand semanticCommand =
49 new SemanticCreateCommand(requestAdapter, createElementCommand);
50 Command viewCommand = getCreateCommand(request);
51
52 Command refreshConnectionCommand =
53 getHost().getCommand(
54 new RefreshConnectionsRequest(((List)request.getNewObject())));
55
56
57 // form the compound command and return
58 CompositeCommand cc = new CompositeCommand(semanticCommand.getLabel());
59 cc.compose(semanticCommand);
60 cc.compose(new CommandProxy(viewCommand));
61 if ( refreshConnectionCommand != null ) {
62 cc.compose(new CommandProxy(refreshConnectionCommand));
63 }
64
65 return new ICommandProxy(cc);
66 }