示例#1
0
  /**
   * Saves an encoded image from this viewer.
   *
   * @param format one of SWT.IMAGE_BMP, SWT.IMAGE_BMP_RLE, SWT.IMAGE_GIF SWT.IMAGE_ICO,
   *     SWT.IMAGE_JPEG or SWT.IMAGE_PNG
   * @return the bytes of an encoded image for the specified viewer
   */
  public void saveImage(final IFile file, final int format) {
    WorkspaceModifyOperation op =
        new WorkspaceModifyOperation() {
          @Override
          public void execute(final IProgressMonitor monitor) throws CoreException {
            try {
              if (file.exists()) {
                file.setContents(
                    new ByteArrayInputStream(editor.createImage(format)), true, false, monitor);
              } else {
                file.create(new ByteArrayInputStream(editor.createImage(format)), true, monitor);
              }
            } catch (CoreException e) {
              ErrorDialog.openError(
                  getWorkbenchPart().getSite().getShell(),
                  BeansGraphPlugin.getResourceString("Editor.SaveError.title"),
                  BeansGraphPlugin //$NON-NLS-1$
                      .getResourceString("Editor.SaveError.text"),
                  e.getStatus()); // $NON-NLS-1$
            }
          }
        };

    try {
      Shell shell = getWorkbenchPart().getSite().getWorkbenchWindow().getShell();
      new ProgressMonitorDialog(shell).run(false, true, op);
    } catch (InvocationTargetException e) {
      BeansGraphPlugin.log(e);
    } catch (InterruptedException e) {
    }
  }
示例#2
0
 @Override
 public void run() {
   SaveAsDialog dialog = new SaveAsDialog(getWorkbenchPart().getSite().getShell());
   dialog.setOriginalName(Messages.ExportAction_JPEG_ORIGINAL_TITLE);
   dialog.create();
   dialog.setMessage(
       BeansGraphPlugin.getResourceString("Editor.SaveAsDialog.message")); // $NON-NLS-1$
   dialog.setOriginalName(Messages.ExportAction_PNG_ORIGINAL_TITLE);
   dialog.open();
   IPath path = dialog.getResult();
   if (path != null) {
     IWorkspace workspace = ResourcesPlugin.getWorkspace();
     IFile file = workspace.getRoot().getFile(path);
     String ext = file.getFileExtension();
     if (ext == null
         || ext.length() == 0
         || !(ext.equalsIgnoreCase("jpg")
             || ext.equalsIgnoreCase("bmp")
             || ext.equalsIgnoreCase("png"))) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
       ErrorDialog.openError(
           getWorkbenchPart().getSite().getShell(),
           BeansGraphPlugin.getResourceString("Editor.SaveError.title"),
           null,
           BeansGraphPlugin //$NON-NLS-1$
               .createErrorStatus(
               BeansGraphPlugin.getResourceString("Editor.SaveAsDialog.error"))); // $NON-NLS-1$
     } else if (ext.equalsIgnoreCase("PNG")
         && !SpringCoreUtils.isEclipseSameOrNewer(3, 3)) { // $NON-NLS-1$
       ErrorDialog.openError(
           getWorkbenchPart().getSite().getShell(),
           Messages.ExportAction_ERROR_TITLE,
           Messages.ExportAction_ERROR_PNG_EXPORT_33_OR_NEWER,
           BeansGraphPlugin.createErrorStatus(
               BeansGraphPlugin.getResourceString("Editor.SaveAsDialog.error"))); // $NON-NLS-1$
     } else {
       if ("PNG".equalsIgnoreCase(ext)) { // $NON-NLS-1$
         saveImage(file, SWT.IMAGE_PNG);
       } else if ("JPG".equalsIgnoreCase(ext)
           || "JPEG".equalsIgnoreCase(ext)) { // $NON-NLS-1$ //$NON-NLS-2$
         saveImage(file, SWT.IMAGE_JPEG);
       } else if ("BMP".equalsIgnoreCase(ext)) { // $NON-NLS-1$
         saveImage(file, SWT.IMAGE_BMP);
       }
     }
   }
 }