@SuppressWarnings({"unchecked", "rawtypes"})
    public Task createBusinessObject(ICreateContext context) {
      Task task = super.createBusinessObject(context);
      final String name = customTaskDescriptor.getName();
      if (name != null && !name.isEmpty()) {
        task.setName(name.trim());
      }

      // make sure the ioSpecification has both a default InputSet and OutputSet
      InputOutputSpecification ioSpecification = task.getIoSpecification();
      if (ioSpecification != null) {
        Resource resource = getResource(context);
        if (ioSpecification.getInputSets().size() == 0) {
          InputSet is = Bpmn2ModelerFactory.createObject(resource, InputSet.class);
          ioSpecification.getInputSets().add(is);
        }
        if (ioSpecification.getOutputSets().size() == 0) {
          OutputSet os = Bpmn2ModelerFactory.createObject(resource, OutputSet.class);
          ioSpecification.getOutputSets().add(os);
        }
      }

      // Create the ItemDefinitions for each I/O parameter if needed
      JBPM5RuntimeExtension rx =
          (JBPM5RuntimeExtension) customTaskDescriptor.getRuntime().getRuntimeExtension();
      String id = customTaskDescriptor.getId();
      WorkItemDefinition wid = rx.getWorkItemDefinition(id);
      if (ioSpecification != null && wid != null) {
        for (DataInput input : ioSpecification.getDataInputs()) {
          for (Entry<String, String> entry : wid.getParameters().entrySet()) {
            if (input.getName().equals(entry.getKey())) {
              if (entry.getValue() != null)
                input.setItemSubjectRef(
                    JbpmModelUtil.getDataType(context.getTargetContainer(), entry.getValue()));
              break;
            }
          }
        }
        for (DataOutput output : ioSpecification.getDataOutputs()) {
          for (Entry<String, String> entry : wid.getResults().entrySet()) {
            if (output.getName().equals(entry.getKey())) {
              if (entry.getValue() != null)
                output.setItemSubjectRef(
                    JbpmModelUtil.getDataType(context.getTargetContainer(), entry.getValue()));
              break;
            }
          }
        }
      }
      return task;
    }
      @Override
      public Object[] create(ICreateContext context) {
        // create SPP
        SPPRef spp = RoomFactory.eINSTANCE.createSPPRef();
        spp.setName("");

        ActorContainerClass acc =
            (ActorContainerClass)
                context.getTargetContainer().getLink().getBusinessObjects().get(0);

        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        SPPPropertyDialog dlg = new SPPPropertyDialog(shell, spp, acc, true, false);
        if (dlg.open() != Window.OK)
          // find a method to abort creation
          // throw new RuntimeException();
          return EMPTY;

        doneChanges = true;

        acc.getIfSPPs().add(spp);

        // do the add
        addGraphicalRepresentation(context, spp);

        // return newly created business object(s)
        return new Object[] {spp};
      }
 public boolean canCreate(ICreateContext context) {
   Object parentObject = getBusinessObjectForPictogramElement(context.getTargetContainer());
   if (parentObject instanceof Activity && parentObject instanceof SubProcess == false) {
     return true;
   }
   return false;
 }
 @Override
 protected Task createFlowElement(ICreateContext context) {
   EObject target =
       Graphiti.getLinkService()
           .getBusinessObjectForLinkedPictogramElement(context.getTargetContainer());
   return (Task) customTaskDescriptor.createObject(target);
 }
 @Override
 public boolean canCreate(ICreateContext context) {
   EObject bo =
       Graphiti.getLinkService()
           .getBusinessObjectForLinkedPictogramElement(context.getTargetContainer());
   //		System.out.println("CreatePortFeature.canCreate: modelObject=" + modelObject);
   return (actorEditModel != null)
       && actorEditModel.isEntity(bo, EntityViewModel.EntityKind.ACTOR);
 }
 protected ExpansionRegion getTargetExpansionRegion(ICreateContext context) {
   Object object = getBusinessObjectForPictogramElement(context.getTargetContainer());
   if (object != null) {
     if (object instanceof ExpansionRegion) {
       return (ExpansionRegion) object;
     }
   }
   return null;
 }
 @Override
 public boolean canCreate(ICreateContext context) {
   final Object bo = getBusinessObjectForPictogramElement(context.getTargetContainer());
   if (bo instanceof Composite
       && !getDiagramBehavior().getEditingDomain().isReadOnly(((Composite) bo).eResource())) {
     return true;
   }
   return false;
 }
    @Override
    public Object[] create(ICreateContext context) {
      String state = Selectstate(BPMNToolBehaviorProvider.id_v);
      if (state.compareTo("Working") == 0) {
        SubProcess element = createBusinessObject(context);
        // if (element instanceof Task)
        // System.out.println("selectTaskId()"+selectTaskId());
        String id = selectTaskId();
        element.setId("VA" + id + "-1");
        UpdateTaskId(id);
        if (element != null) {
          changesDone = true;
          try {
            ModelHandler handler = ModelHandler.getInstance(getDiagram());
            if (FeatureSupport.isTargetLane(context) && element instanceof FlowNode) {
              ((FlowNode) element)
                  .getLanes()
                  .add((Lane) getBusinessObjectForPictogramElement(context.getTargetContainer()));
            }
            handler.addFlowElement(
                getBusinessObjectForPictogramElement(context.getTargetContainer()), element);
          } catch (IOException e) {
            Activator.logError(e);
          }
          PictogramElement pe = null;
          pe = addGraphicalRepresentation(context, element);
          return new Object[] {element, pe};
        } else changesDone = false;
        return new Object[] {null};
      } else {
        System.out.println("01102015tttttttttttt");
        JOptionPane.showMessageDialog(
            null,
            "Operation is not allowed because the version of process "
                + BPMNToolBehaviorProvider.id_v
                + " is Stable",
            "Error",
            JOptionPane.ERROR_MESSAGE);

        return new Object[] {null};
      }
    }
 protected ActorViewModel.PortKind getIOPortKind(ICreateContext context) {
   int x = context.getX(); // , y = context.getY();
   GraphicsAlgorithm parentGa = context.getTargetContainer().getGraphicsAlgorithm();
   int width = parentGa.getWidth(); // , height = parentShape.getHeight();
   if (x < width / 3) {
     return ActorViewModel.PortKind.INPUT;
   } else if (x > width * 2 / 3) {
     return ActorViewModel.PortKind.OUTPUT;
   }
   return ioKind;
 }
 @Override
 public Object[] create(ICreateContext context) {
   BaseElement element = null;
   try {
     ModelHandler handler = ModelHandlerLocator.getModelHandler(getDiagram().eResource());
     element = add(context.getTargetContainer(), handler);
   } catch (IOException e) {
     Activator.logError(e);
   }
   addGraphicalRepresentation(context, element);
   return new Object[] {element};
 }
    @Override
    public boolean canCreate(ICreateContext context) {
      if (!super.canCreate(context)) {
        return false;
      }

      Event e = (Event) getBusinessObjectForPictogramElement(context.getTargetContainer());
      if (e instanceof ThrowEvent) {
        return false;
      }

      return true;
    }
  public Object[] create(ICreateContext context) {
    BoundaryEvent boundaryEvent = new BoundaryEvent();
    CompensateEventDefinition compensateEvent = new CompensateEventDefinition();
    boundaryEvent.getEventDefinitions().add(compensateEvent);

    Object parentObject = getBusinessObjectForPictogramElement(context.getTargetContainer());
    ((Activity) parentObject).getBoundaryEvents().add(boundaryEvent);
    boundaryEvent.setAttachedToRef((Activity) parentObject);

    addObjectToContainer(context, boundaryEvent, "Compensate");

    // return newly created business object(s)
    return new Object[] {boundaryEvent};
  }
  public EObject[] create(ICreateContext context) {
    EObject parent =
        Graphiti.getLinkService()
            .getBusinessObjectForLinkedPictogramElement(context.getTargetContainer());
    ActorViewModel.PortKind ioKind = getIOPortKind(context);
    String name = actorEditModel.getUniqueName(parent, ioKind.name().toLowerCase());
    EObject newPort = actorEditModel.createPort(ioKind, name, parent);
    if (multi != null) {
      actorEditModel.setMultiPort(newPort, multi.booleanValue());
    }
    addGraphicalRepresentation(context, newPort);

    return new EObject[] {newPort};
  }
  public boolean canCreate(ICreateContext context) {

    ContainerShape targetContainer = context.getTargetContainer();

    if (targetContainer instanceof Diagram) {
      return true;
    }

    if (getBusinessObjectForPictogramElement(targetContainer) instanceof EPackage) {
      return true;
    }

    return false;
  }
  public Object[] create(ICreateContext context) {
    // get the container business element
    List<EObject> containerObjects = context.getTargetContainer().getLink().getBusinessObjects();
    if (containerObjects.isEmpty() || !(containerObjects.get(0) instanceof Score)) {
      throw new IllegalStateException("The diagram does not contain a Coro score.");
    }

    Score score = (Score) containerObjects.get(0);
    Part part = ScoreFactory.eINSTANCE.createPart();
    score.getParts().add(part);

    // add the corresponding graphical representation
    addGraphicalRepresentation(context, part);

    return new Object[] {part};
  }
  @Override
  public Object[] create(ICreateContext context) {
    Service newService = null;
    Composite composite =
        (Composite) getBusinessObjectForPictogramElement(context.getTargetContainer());
    BaseNewContractWizard wizard =
        new BaseNewContractWizard(
            "New Service",
            "Specify details for the new service.",
            ScaPackage.eINSTANCE.getService());
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    WizardDialog wizDialog = new WizardDialog(shell, wizard);
    wizard.init(composite);
    int rtn_code = wizDialog.open();
    if (rtn_code == Window.OK) {
      newService = (Service) wizard.getContract();
    } else {
      _hasDoneChanges = false;
      return EMPTY;
    }

    composite.getService().add(newService);

    // do the add
    PictogramElement pe = addGraphicalRepresentation(context, newService);
    if (pe instanceof Shape) {
      // make sure the new service is positioned correctly.
      layoutPictogramElement(((Shape) pe).getContainer());
    }

    // activate direct editing after object creation
    getFeatureProvider().getDirectEditingInfo().setActive(true);

    // make sure we look like we actually did something.
    _hasDoneChanges = true;

    // return newly created business object(s)
    return new Object[] {newService};
  }
  @Override
  public Object[] create(ICreateContext context) {
    Reference newReference = null;
    Composite composite =
        (Composite) getBusinessObjectForPictogramElement(context.getTargetContainer());
    BaseNewContractWizard wizard =
        new BaseNewContractWizard(
            Messages.title_newCompositeReference,
            Messages.description_newCompositeReference,
            ScaPackage.eINSTANCE.getReference());
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    WizardDialog wizDialog = new WizardDialog(shell, wizard);
    wizard.init(composite);
    int rtn_code = wizDialog.open();
    if (rtn_code == Window.OK) {
      newReference = (Reference) wizard.getContract();
      newReference.setMultiplicity(Multiplicity._01);
    } else {
      _hasDoneChanges = false;
      return EMPTY;
    }

    composite.getReference().add(newReference);

    // do the add
    PictogramElement pe = addGraphicalRepresentation(context, newReference);
    if (pe instanceof Shape) {
      // make sure the new reference is positioned correctly.
      layoutPictogramElement(((Shape) pe).getContainer());
    }

    // make sure we look like we actually did something.
    _hasDoneChanges = true;

    // return newly created business object(s)
    return new Object[] {newReference};
  }
예제 #18
0
  public Object[] create(ICreateContext context) {

    String newClassName = ExampleUtil.askString(TITLE, USER_QUESTION, "");

    if (newClassName == null || newClassName.trim().length() == 0) {
      return EMPTY;
    }
    if (!Utils.isNameValid(newClassName)) {
      Utils.showError("Invalid name, please respect naming rules", "");
      return null;
    }

    if (Utils.nameExists(newClassName, Utils.getRootComponent(context.getTargetContainer()))
        != null) {
      Utils.showError("Invalid name, already exists in the model", "");
      return null;
    }
    Bus newClass = TasteFactory.eINSTANCE.createBus();
    getDiagram().eResource().getContents().add(newClass);
    newClass.setName(newClassName);
    addGraphicalRepresentation(context, newClass);

    return new Object[] {newClass};
  }
 @Override
 public boolean canCreate(ICreateContext context) {
   return context.getTargetContainer() instanceof Diagram;
 }