/machinelearning/4.0.x/drools-eclipse3.3/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/policy/ElementNodeEditPolicy.java

https://github.com/droolsjbpm/droolsjbpm-contributed-experiments · Java · 77 lines · 48 code · 9 blank · 20 comment · 0 complexity · 9ca83e2c3ba340ba2009de6c98b00d47 MD5 · raw file

  1. package org.drools.eclipse.flow.common.editor.policy;
  2. /*
  3. * Copyright 2005 JBoss Inc
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import org.drools.eclipse.flow.common.editor.core.ElementConnection;
  18. import org.drools.eclipse.flow.common.editor.core.ElementWrapper;
  19. import org.drools.eclipse.flow.common.editor.core.command.ElementConnectionCreateCommand;
  20. import org.drools.eclipse.flow.common.editor.core.command.ReconnectElementConnectionSourceCommand;
  21. import org.drools.eclipse.flow.common.editor.core.command.ReconnectElementConnectionTargetCommand;
  22. import org.drools.eclipse.flow.common.editor.editpart.ElementEditPart;
  23. import org.eclipse.gef.commands.Command;
  24. import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
  25. import org.eclipse.gef.requests.CreateConnectionRequest;
  26. import org.eclipse.gef.requests.ReconnectRequest;
  27. /**
  28. * Policy for editing an element node.
  29. *
  30. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  31. */
  32. public class ElementNodeEditPolicy extends GraphicalNodeEditPolicy {
  33. protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
  34. ElementConnectionCreateCommand cmd =
  35. (ElementConnectionCreateCommand) request.getStartCommand();
  36. cmd.setConnection((ElementConnection) request.getNewObject());
  37. cmd.setTarget(getElement());
  38. return cmd;
  39. }
  40. protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
  41. ElementConnectionCreateCommand cmd =
  42. new ElementConnectionCreateCommand();
  43. cmd.setConnection((ElementConnection) request.getNewObject());
  44. cmd.setSource(getElement());
  45. request.setStartCommand(cmd);
  46. return cmd;
  47. }
  48. protected ElementEditPart getActivityPart() {
  49. return (ElementEditPart) getHost();
  50. }
  51. protected ElementWrapper getElement() {
  52. return (ElementWrapper) getHost().getModel();
  53. }
  54. protected Command getReconnectSourceCommand(ReconnectRequest request) {
  55. ReconnectElementConnectionSourceCommand cmd
  56. = new ReconnectElementConnectionSourceCommand();
  57. cmd.setConnection((ElementConnection) request.getConnectionEditPart().getModel());
  58. cmd.setSource(getElement());
  59. return cmd;
  60. }
  61. protected Command getReconnectTargetCommand(ReconnectRequest request) {
  62. ReconnectElementConnectionTargetCommand cmd
  63. = new ReconnectElementConnectionTargetCommand();
  64. cmd.setConnection((ElementConnection) request.getConnectionEditPart().getModel());
  65. cmd.setTarget(getElement());
  66. return cmd;
  67. }
  68. }