Example #1
0
 private void setInitialInput() {
   if (firstSelection instanceof IFile) {
     IFile file = (IFile) firstSelection;
     if (file.getName().endsWith("." + Constants.ABS_FILE_EXTENSION)) {
       page.setInitialFileResource(file);
     }
   } else if (firstSelection instanceof InternalASTNode<?>) {
     InternalASTNode<?> node = (InternalASTNode<?>) firstSelection;
     if (node.hasASTNodeOfType(ModuleDecl.class)) {
       ModuleDecl m = (ModuleDecl) node.getASTNode();
       page.setInitialValue(m.getName() + ".");
       IFile file = UtilityFunctions.getFileOfModuleDecl(m);
       page.setInitialFileResource(file);
     }
   } else if (firstSelection instanceof ModulePath) {
     ModulePath mp = (ModulePath) firstSelection;
     page.setInitialValue(mp.getModulePath() + ".");
     InternalASTNode<ModuleDecl> moduleDecl = mp.getModuleDecl();
     if (moduleDecl.hasASTNodeOfType(ModuleDecl.class)) {
       IFile fileOfModuleDecl =
           UtilityFunctions.getFileOfModuleDecl(mp.getModuleDecl().getASTNode());
       page.setInitialFileResource(fileOfModuleDecl);
     }
   }
 }
Example #2
0
  @Override
  public boolean performFinish() {
    IFile resultFile = page.getResultFile();
    if (resultFile != null) {
      ABSEditor editor =
          UtilityFunctions.openABSEditorForFile(resultFile.getLocation(), resultFile.getProject());
      IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());

      // modules are always added the the end of the document
      final int off = document.getLength();

      try {
        document.replace(off, 0, insertType.getInsertionString(page.getResult()));
        final int insertOffset = insertType.getInsertOffset(page.getResult());

        WizardUtil.saveEditorAndGotoOffset(editor, insertOffset);

        return true;
      } catch (BadLocationException e) {
        MessageDialog.openError(
            getShell(),
            "Error",
            "Fatal error: The insertion position for the new module does not longer exist. Please save the target file and try again.");
        e.printStackTrace();
        return false;
      }
    } else {
      MessageDialog.openError(
          getShell(),
          "Error",
          "Fatal error: No file reference was passed by the wizard. Please try again to use the wizard and select a valid file.");
      return false;
    }
  }
Example #3
0
 @Override
 public void addPages() {
   page = new NewModuleWizardPage("New Module", project);
   setInitialInput();
   page.setDescription("Create a new ABS Module in an existing ABS file");
   page.setTitle("New ABS Module");
   addPage(page);
 }