コード例 #1
0
  @Override
  public boolean performFinish() {
    try {
      final IDocument doc =
          createDocument(typePage.getDocumentType(), typePage.getRootElementName());

      final Style style =
          VexPlugin.getDefault().getPreferences().getPreferredStyle(typePage.getDocumentType());
      if (style == null) {
        MessageDialog.openError(
            getShell(),
            Messages.getString("NewDocumentWizard.noStyles.title"),
            Messages.getString("NewDocumentWizard.noStyles.message")); // $NON-NLS-1$ //$NON-NLS-2$
        return false;
        // TODO: don't allow selection of types with no stylesheets
      }

      final ByteArrayOutputStream baos = new ByteArrayOutputStream();
      final DocumentWriter writer = new DocumentWriter();
      writer.setWhitespacePolicy(new CssWhitespacePolicy(style.getStyleSheet()));
      writer.write(doc, baos);
      baos.close();
      final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

      filePage.setInitialContents(bais);
      final IFile file = filePage.createNewFile();
      IDE.setDefaultEditor(file, VexEditor.ID);
      this.selectAndReveal(file);

      registerEditorForFilename("*." + file.getFileExtension(), VexEditor.ID); // $NON-NLS-1$

      // Open editor on new file.
      final IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
      if (dw != null) {
        final IWorkbenchPage page = dw.getActivePage();
        if (page != null) {
          IDE.openEditor(page, file, true);
        }
      }

      typePage.saveSettings();

      return true;

    } catch (final Exception ex) {
      final String message =
          MessageFormat.format(
              Messages.getString("NewDocumentWizard.errorLoading.message"),
              new Object[] {filePage.getFileName(), ex.getMessage()});
      VexPlugin.getDefault().log(IStatus.ERROR, message, ex);
      MessageDialog.openError(
          getShell(),
          Messages.getString("NewDocumentWizard.errorLoading.title"),
          "Unable to create " + filePage.getFileName()); // $NON-NLS-1$ //$NON-NLS-2$
      return false;
    }
  }
コード例 #2
0
  @Override
  public void init(final IWorkbench workbench, final IStructuredSelection currentSelection) {

    super.init(workbench, currentSelection);
    setWindowTitle(Messages.getString("NewDocumentWizard.title")); // $NON-NLS-1$
  }