Exemple #1
0
  public void save_Event() {
    FileDialog fd = new FileDialog(ZestDebuggerView.this.getSite().getShell(), SWT.SAVE);
    fd.setText("Save");
    fd.setFilterPath("C:/");
    String[] filterExt = {"*.jpg"};
    fd.setFilterExtensions(filterExt);
    String selected = fd.open();
    System.out.println(selected);

    if (selected != null) {
      GC gc = new GC(viewer.getControl());
      org.eclipse.swt.graphics.Rectangle bounds = viewer.getControl().getBounds();

      Image image = new Image(viewer.getControl().getDisplay(), bounds);
      try {
        gc.copyArea(image, 0, 0);
        ImageLoader imageLoader = new ImageLoader();
        imageLoader.data = new ImageData[] {image.getImageData()};
        imageLoader.save(selected, SWT.IMAGE_JPEG);
        MessageDialog.openInformation(
            ZestDebuggerView.this.getSite().getShell(),
            "Success",
            "The image has been saved successfully");
      } catch (Exception e) {
        e.printStackTrace();
        MessageDialog.openError(
            ZestDebuggerView.this.getSite().getShell(), "Failure", "The image can't be saved");
      } finally {
        image.dispose();
        gc.dispose();
      }
    }
  }
  @Override
  public void createPartControl(Composite parent) {
    viewer = new GraphViewer(parent, SWT.NONE);
    viewer.setContentProvider(new ViewContentProvider());
    viewer.setLabelProvider(new ViewLabelProvider());
    viewer.setInput(getViewSite());
    viewer.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
    ResourcesPlugin.getWorkspace()
        .addResourceChangeListener(
            new IResourceChangeListener() {
              public void resourceChanged(IResourceChangeEvent event) {
                Display.getDefault()
                    .asyncExec(
                        new Runnable() {
                          public void run() {
                            viewer.refresh();
                            viewer.applyLayout();
                          }
                        });
              }
            });
    getSite().setSelectionProvider(viewer);

    // Create the help context id for the viewer's control
    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(viewer.getControl(), "com.javadude.dependencies2.viewer");
  }
 @Override
 public void setFocus() {
   viewer.getControl().setFocus();
 }