@Override
 public void execute(ICustomContext context) {
   PictogramElement[] pes = context.getPictogramElements();
   if (pes != null && pes.length == 1) {
     Object bo = getBusinessObjectForPictogramElement(pes[0]);
     if (bo instanceof EClass) {
       EClass eClass = (EClass) bo;
       String currentName = eClass.getName();
       // ask user for a new class name
       String newName = ExampleUtil.askString(getName(), getDescription(), currentName);
       if (newName != null && !newName.equals(currentName)) {
         this.hasDoneChanges = true;
         // eClass.setName(newName);
         System.out.println(newName);
         // TutorialAddEClassFeature a = new TutorialAddEClassFeature(prov);
         // IAddContext b = new AddContext();
         // if (a.canAdd(b) == true){
         // a.add(b);
         // }
         updatePictogramElement(pes[0]);
       }
     }
   }
 }
Exemplo n.º 2
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};
  }