public ResourceEditor createResourceEditor(IResource resource) {
   ResourceEditor editor = new ResourceEditor();
   editor.setResizable(false);
   if (resource != null) {
     openEditors.put(resource.getId(), editor);
     openEditors2.put(editor, resource.getId());
   }
   editor.addWindowListener(openEditorsListener);
   return editor;
 }
 @Override
 public void windowClosed(WindowEvent event) {
   ResourceEditor editor = (ResourceEditor) event.getSource();
   if (openEditors2.containsKey(editor)) openEditors.remove(openEditors2.get(editor));
   openEditors2.remove(editor);
   mostRecentFocusedEditors.remove(editor);
   editor.removeWindowListener(
       openEditorsListener); // not neceesary since they dispose on close?
   System.gc(); // might help? especially with media resources?
   Application.this.notifyApplicationWindowClosed(event);
 }
  public static void doCreateSnuFromMedia(IMedia media) throws Exception {
    Application app = Application.getInstance();

    // try and find an open editor for a Snu with this media.
    // if we find one, focus it and abort
    Collection<ResourceEditor> openEditors = app.getOpenEditors();
    for (ResourceEditor editor : openEditors) {
      IResource editingResource = app.getResourceForEditor(editor);
      if (editingResource == null) {
        // i suppose its reasonable that some other code might create an unattached resource editor
        // but in that case it shouldnt be in the openEditors list
        Logger.getLogger(CreateSnuAction.class)
            .info(
                "no resource for editor: " + editor.getResourceView().getResourceId(),
                new Exception("just-for-stacktrace"));
        continue;
      }
      if (editingResource instanceof ISnu) {
        IMedia editingMedia = ((ISnu) editingResource).getMainMedia();
        if (editingMedia != null && editingMedia.getId().equals(media.getId())) {
          editor.toFront();
          return;
        }
      }
      if (editingResource instanceof IMedia) {
        if (editor.getResourceView() instanceof SnuResourceView) {
          editor.toFront();
          return;
        }
      }
    }

    ResourceEditor editor = app.editNew(ResourceType.SNU, media.getId());
    SnuResourceView view = (SnuResourceView) editor.getResourceView();
    SnuHelper.initView(view, FileUtil.getFilenameWithoutExtension(media.getName()), media);
  }