/machinelearning/4.0.x/drools-eclipse3.3/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/core/ActionWrapper.java

https://github.com/droolsjbpm/droolsjbpm-contributed-experiments · Java · 92 lines · 58 code · 14 blank · 20 comment · 8 complexity · a34e5c81f18913a1e63fb7012c15fa90 MD5 · raw file

  1. package org.drools.eclipse.flow.ruleflow.core;
  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.DefaultElementWrapper;
  18. import org.drools.eclipse.flow.common.editor.core.ElementConnection;
  19. import org.drools.eclipse.flow.ruleflow.view.property.action.ActionPropertyDescriptor;
  20. import org.drools.ruleflow.core.ActionNode;
  21. import org.drools.ruleflow.core.impl.ActionNodeImpl;
  22. import org.eclipse.ui.views.properties.IPropertyDescriptor;
  23. /**
  24. * Wrapper for an action node.
  25. *
  26. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  27. */
  28. public class ActionWrapper extends NodeWrapper {
  29. private static final long serialVersionUID = -3618183280436588589L;
  30. private IPropertyDescriptor[] descriptors;
  31. public static final String ACTION = "Action";
  32. public ActionWrapper() {
  33. setNode(new ActionNodeImpl());
  34. getActionNode().setName("Action");
  35. }
  36. private void setDescriptors() {
  37. descriptors = new IPropertyDescriptor[DefaultElementWrapper.descriptors.length + 1];
  38. System.arraycopy(DefaultElementWrapper.descriptors, 0, descriptors, 0, DefaultElementWrapper.descriptors.length);
  39. descriptors[descriptors.length - 1] =
  40. new ActionPropertyDescriptor(ACTION, "Action", getActionNode(), ((RuleFlowProcessWrapper) getParent()).getRuleFlowProcess());
  41. }
  42. public ActionNode getActionNode() {
  43. return (ActionNode) getNode();
  44. }
  45. public IPropertyDescriptor[] getPropertyDescriptors() {
  46. if (descriptors == null) {
  47. setDescriptors();
  48. }
  49. return descriptors;
  50. }
  51. public boolean acceptsIncomingConnection(ElementConnection connection) {
  52. return getIncomingConnections().isEmpty();
  53. }
  54. public boolean acceptsOutgoingConnection(ElementConnection connection) {
  55. return getOutgoingConnections().isEmpty();
  56. }
  57. public Object getPropertyValue(Object id) {
  58. if (ACTION.equals(id)) {
  59. Object action = getActionNode().getAction();
  60. return action == null ? "" : action.toString();
  61. }
  62. return super.getPropertyValue(id);
  63. }
  64. public void resetPropertyValue(Object id) {
  65. if (ACTION.equals(id)) {
  66. getActionNode().setAction(null);
  67. } else {
  68. super.resetPropertyValue(id);
  69. }
  70. }
  71. public void setPropertyValue(Object id, Object value) {
  72. if (ACTION.equals(id)) {
  73. getActionNode().setAction(value);
  74. } else {
  75. super.setPropertyValue(id, value);
  76. }
  77. }
  78. }