Ejemplo n.º 1
0
 private ICommand createCompositeStateCommand(ConfigureRequest req) {
   Region region = SGraphFactory.eINSTANCE.createRegion();
   region.setName("r1");
   return new SetValueCommand(
       new SetRequest(
           req.getElementToConfigure(), SGraphPackage.Literals.STATE__SUB_REGIONS, region));
 }
Ejemplo n.º 2
0
 private ICommand createSubmachineStateCommand(ConfigureRequest req) {
   SelectSubmachineDialog dialog =
       new SelectSubmachineDialog(new Shell(), req.getElementToConfigure().eResource());
   dialog.setElements(new Object[] {req.getElementToConfigure()});
   if (Dialog.OK == dialog.open()) {
     QualifiedName selectedSubmachine = dialog.getSelectedSubmachine();
     if (selectedSubmachine != null) {
       return new SetValueCommand(
           new SetRequest(
               req.getElementToConfigure(),
               SGraphPackage.Literals.STATE__SUBSTATECHART_ID,
               selectedSubmachine.toString()));
     }
   }
   return null;
 }
Ejemplo n.º 3
0
 private ICommand createOrthogonalState(ConfigureRequest req) {
   Region region = SGraphFactory.eINSTANCE.createRegion();
   region.setName("r1");
   Region region2 = SGraphFactory.eINSTANCE.createRegion();
   region2.setName("r2");
   return new SetValueCommand(
       new SetRequest(
           req.getElementToConfigure(),
           SGraphPackage.Literals.STATE__SUB_REGIONS,
           com.google.common.collect.Lists.newArrayList(region, region2)));
 }
  /** {@inheritDoc} */
  @Override
  public ICommand create(ConfigureRequest request) {

    ICommand configureCommand = null;

    Shell shell = Display.getDefault().getActiveShell();
    // Start dialog to identify the new part type
    Property part = (Property) request.getElementToConfigure();
    Package partPkg = part.getNearestPackage();

    CreateOrSelectBlockPropertyTypeDialog dialog =
        new CreateOrSelectBlockPropertyTypeDialog(shell, partPkg);
    dialog.open();
    if (dialog.getReturnCode() == Window.OK) {

      final ICommand typeCreationCommand = dialog.getNewTypeCreateCommand();
      final Type partType = (Type) dialog.getExistingType();

      // Abort if type creation command exists but is not executable
      if ((typeCreationCommand != null) && (!typeCreationCommand.canExecute())) {
        return cancelCommand(request);
      } else {
        configureCommand = CompositeCommand.compose(configureCommand, typeCreationCommand);
      }

      // Create the configure command that will set the part type
      ICommand setTypeCommand =
          new ConfigureElementCommand(request) {

            @Override
            protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
                throws ExecutionException {

              Property part = (Property) getElementToEdit();
              if (partType != null) {
                part.setType(partType);
              } else {
                Type newType = (Type) GMFCommandUtils.getCommandEObjectResult(typeCreationCommand);
                part.setType(newType);
              }
              return CommandResult.newOKCommandResult(part);
            }
          };

      configureCommand = CompositeCommand.compose(configureCommand, setTypeCommand);
      return configureCommand;
    }

    return cancelCommand(request);
  }