@Override
 public void run() {
   InputDialog inputDialog =
       new InputDialog(
           null,
           Messages.RenameActionProvider_ProvideNameTitle,
           Messages.RenameActionProvider_ProvideNameDescription,
           eclass.getName(),
           null);
   int open = inputDialog.open();
   if (open == Dialog.OK) {
     String newName = inputDialog.getValue();
     Resource resource = eclass.eResource();
     ResourceSet resourceSet = resource.getResourceSet();
     TransactionalEditingDomain domain =
         TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(resourceSet);
     try {
       if (domain != null) {
         Command setCommand =
             domain.createCommand(
                 SetCommand.class,
                 new CommandParameter(
                     eclass, EcorePackage.Literals.ENAMED_ELEMENT__NAME, newName));
         domain.getCommandStack().execute(setCommand);
         try {
           resource.save(Collections.emptyMap());
         } catch (IOException e) {
           e.printStackTrace();
         }
       }
     } finally {
       domain.dispose();
     }
   }
 }
Example #2
0
  private EClass findEClass(
      EClass eReferenceType, JsonNode node, JsonNode root, Resource resource) {
    if (eReferenceType.isAbstract() || node.get(EJS_TYPE_KEYWORD) != null) {

      if (node.has(EJS_REF_KEYWORD)) {

        URI refURI = getEObjectURI(node.get(EJS_REF_KEYWORD), resource.getURI(), nsMap);
        EObject eObject = resourceSet.getEObject(refURI, false);
        if (eObject != null) {
          return resourceSet.getEObject(refURI, false).eClass();
        }

        if (node.has(EJS_TYPE_KEYWORD)) {
          refURI = URI.createURI(node.get(EJS_TYPE_KEYWORD).asText());
          eObject = resourceSet.getEObject(refURI, false);
          if (eObject != null) {
            return (EClass) eObject;
          }
        }

        JsonNode refNode = findNode(refURI, eReferenceType, rootNode);
        if (refNode != null) {
          return findEClass(eReferenceType, refNode, root, resource);
        }

      } else if (node.has(EJS_TYPE_KEYWORD)) {
        final URI typeURI =
            getEObjectURI(node.get(EJS_TYPE_KEYWORD), eReferenceType.eResource().getURI(), nsMap);

        if (typeURI.fragment().equals(eReferenceType.getName())) {
          return eReferenceType;
        } else {
          try {
            return (EClass) this.resourceSet.getEObject(typeURI, false);
          } catch (ClassCastException e) {
            e.printStackTrace();
            return null;
          }
        }
      }
    }
    return eReferenceType;
  }
 @Override
 public void fillContextMenu(IMenuManager menu) {
   super.fillContextMenu(menu);
   ISelection selection = getContext().getSelection();
   if (selection.isEmpty()) return;
   if (selection instanceof IStructuredSelection) {
     IStructuredSelection sel = (IStructuredSelection) selection;
     Object el = sel.getFirstElement();
     if (el instanceof EClass) {
       EClass eclass = (EClass) el;
       String platformString = eclass.eResource().getURI().toPlatformString(true);
       Path path = new Path(platformString);
       IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
       if (file == null) return;
       IProject project = file.getProject();
       try {
         if (!project.hasNature(ExampleProjectNature.NATURE_ID)) return;
       } catch (CoreException e) {
         e.printStackTrace();
       }
       menu.appendToGroup(ICommonMenuConstants.GROUP_ADDITIONS, getAction(eclass));
     }
   }
 }