Esempio n. 1
0
  @Override
  public void doRun(
      IStructuredSelection selection, Event event, UIInstrumentationBuilder instrumentation) {

    instrumentation.metric("command", command);

    if (!selection.isEmpty() && selection.getFirstElement() instanceof IResource) {
      Object object = selection.getFirstElement();
      if (object instanceof IFile) {
        object = ((IFile) object).getParent();
      }
      while (object != null
          && ((IContainer) object).findMember(DartCore.PUBSPEC_FILE_NAME) == null) {
        object = ((IContainer) object).getParent();
      }
      if (object instanceof IContainer) {
        IContainer container = (IContainer) object;
        instrumentation.data("name", container.getName());
        savePubspecFile(container);
        runPubJob(container);
        return;
      } else {
        instrumentation.metric("Problem", "Object was null").log();
      }
    }

    instrumentation.metric("Problem", "pubspec.yaml file not selected, showing dialog");

    MessageDialog.openError(
        getShell(), ActionMessages.RunPubAction_fail, ActionMessages.RunPubAction_fileNotFound);

    instrumentation.log();
  }
  // Assert that the two containers have equal contents
  protected void assertEquals(IContainer container1, IContainer container2) throws CoreException {
    assertEquals(container1.getName(), container2.getName());
    List members1 = new ArrayList();
    members1.addAll(Arrays.asList(container1.members()));

    List members2 = new ArrayList();
    members2.addAll(Arrays.asList(container2.members()));

    assertTrue(members1.size() == members2.size());
    for (int i = 0; i < members1.size(); i++) {
      IResource member1 = (IResource) members1.get(i);
      IResource member2 = container2.findMember(member1.getName());
      assertNotNull(member2);
      assertEquals(member1, member2);
    }
  }
  /**
   * handler when the relationships Model name field changes. This updates the status label under
   * the modelName entry field
   */
  void handleSetModelName() {

    // get the text from the Text field
    String nameText = txtModelName.getText();

    // validate it
    if (isValidModelName(nameText)) {
      newModelName = nameText;

      if (getOkButton() != null) {
        getOkButton().addSelectionListener(getOKSelectionListener());

        getOkButton().setEnabled(true);
      }
      String message = getModelNameStatus(nameText);
      updateDialogMessage(message, false);
    } else {
      if (getOkButton() != null) {
        getOkButton().removeSelectionListener(getOKSelectionListener());

        getOkButton().setEnabled(false);
      }

      // if the name has zero length, reapply the 'create' message
      if (nameText.trim().length() == 0) {
        if (newModelParent != null) {
          String msg =
              getString(
                  "modelCreateInstruction.message", //$NON-NLS-1$
                  newModelInfo.getModelTypeDisplayName(),
                  newModelParent.getName());
          updateDialogMessage(msg, true);
        }
      } else {
        // use the message from the character validation
        String message = getModelNameStatus(nameText);
        updateDialogMessage(message, true);
      }
    }
  }
  public void Reverse_Engineering(URI fileURI)
      throws IOException, CoreException, BackingStoreException {
    // Create Modular Project
    XMI_File filemodel = new XMI_File(fileURI, true);
    WTComponents root = (WTComponents) filemodel.Get_Root();
    WTComponentsProjectFeatures feat =
        new WTComponentsProjectFeatures(root.getId(), root.getAuthor());
    WTComponentsNewProjectInfo project = new WTComponentsNewProjectInfo(feat);
    project.Create_Project();

    // Folders & Files
    TreeIterator<EObject> model_tree = filemodel.getFile_res().getAllContents();

    String path = "";
    URI path_uri = null;
    URI parent_uri = null;
    IFolder fol = null;
    IContainer parent = null;
    XMI_File xmi_file = null;
    XMI_File xmi_parent = null;
    EObject eObject = null;
    EObject eObject_root = null;
    String name_folder = null;
    boolean isFile = false;

    model_tree.next(); // The first element(Root) was added already

    while (model_tree.hasNext()) {

      eObject = (EObject) model_tree.next();

      // Parent path
      path = GetObjectPath(eObject);

      // Folders
      name_folder = IsFolder(eObject);
      if (name_folder != null) {
        // Create Folder
        fol = project.Create_Folder(path);
        parent = fol.getParent();
        // Path to Create XMI File
        path = path.concat("/").concat(name_folder.concat(".xmi"));
        // Create File for Folder
        path_uri = URI.createFileURI(project.getProject().getFullPath().toString().concat(path));
        name_folder = null;
      } else {
        // Files
        parent = project.Create_Folder(path);
        if (eObject instanceof ComponentImpl)
          path = path.concat(((ComponentImpl) eObject).getName().toString());
        if (eObject instanceof StateMachineImpl)
          path = path.concat(((StateMachineImpl) eObject).getName().toString());
        // Create File
        path_uri = URI.createFileURI(project.getProject().getFullPath().toString().concat(path));
        isFile = true;
      }

      // Object to add
      if (isFile) {
        Copier copier = new Copier();
        eObject_root = copier.copy(eObject);
        copier.copyReferences();
        model_tree.prune();
      } else eObject_root = GetObjectRoot(eObject);

      // Create XMI File
      xmi_file = XMI_File.Get_Create_XMI(path_uri, eObject_root);
      // Include Parent
      parent_uri =
          URI.createURI(
              parent.getFullPath().toString().concat("/" + parent.getName().concat(".xmi")));
      xmi_parent = new XMI_File(parent_uri, xmi_file.getFile_reset());
      ((EList<EObject>) xmi_parent.Get_Root().eGet(eObject.eContainingFeature()))
          .add(xmi_file.Get_Root());
      xmi_parent.Save_XMI();

      path = "";
      path_uri = null;
      fol = null;
      isFile = false;
    }
    System.out.println("Reverse_Engineering_Create_Project_Complete");
  }