@Override
    public ImageDescriptor getImageDescriptor(Object object) {
      if (object instanceof IFileStore) {
        IFileStore fileStore = (IFileStore) object;

        try {
          if (fileStore.fetchInfo().isDirectory()) {
            return PlatformUI.getWorkbench()
                .getSharedImages()
                .getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
          }

          IEditorDescriptor descriptor = IDE.getEditorDescriptor(fileStore.getName());

          if (descriptor != null) {
            return descriptor.getImageDescriptor();
          } else {
            return PlatformUI.getWorkbench()
                .getSharedImages()
                .getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
          }
        } catch (PartInitException e) {

        }
      }

      return null;
    }
  @Override
  public Image getImage(Object element) {
    if (element instanceof SampleCategory) {
      String iconFile = ((SampleCategory) element).getIconFile();
      if (iconFile != null) {
        File file = new File(iconFile);
        if (file.exists()) {
          String iconFilename = file.getAbsolutePath();
          Image image = imageRegistry.get(iconFilename);
          if (image == null) {
            image = new Image(Display.getDefault(), iconFilename);
            imageRegistry.put(iconFilename, image);
          }
          return image;
        }
      }
      // uses folder as the default image
      return IMAGE_FOLDER;
    }
    if (element instanceof SampleEntry) {
      File file = ((SampleEntry) element).getFile();
      if (file != null) {
        if (file.isDirectory()) {
          return IMAGE_FOLDER;
        }

        IEditorDescriptor editorDescriptor =
            WorkbenchPlugin.getDefault().getEditorRegistry().getDefaultEditor(file.getName());
        if (editorDescriptor == null || editorDescriptor.getImageDescriptor() == null) {
          return IMAGE_FILE;
        }
        String key = editorDescriptor.getId();
        Image image = imageRegistry.get(key);
        if (image == null) {
          image = editorDescriptor.getImageDescriptor().createImage();
          imageRegistry.put(key, image);
        }
        return image;
      }
    }
    if (element instanceof SamplesReference) {
      return SamplesUIPlugin.getImage(ICON_REMOTE);
    }
    return super.getImage(element);
  }
Esempio n. 3
0
 /** Returns the image descriptor for the given editor descriptor, or null if it has no image. */
 private ImageDescriptor getImageDescriptor(IEditorDescriptor editorDesc) {
   ImageDescriptor imageDesc = null;
   if (editorDesc == null) {
     imageDesc = registry.getImageDescriptor(getFileRevision().getName());
     // TODO: is this case valid, and if so, what are the implications
     // for content-type editor bindings?
   } else {
     imageDesc = editorDesc.getImageDescriptor();
   }
   if (imageDesc == null) {
     if (editorDesc.getId().equals(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID)) {
       imageDesc = registry.getSystemExternalEditorImageDescriptor(getFileRevision().getName());
     }
   }
   return imageDesc;
 }
Esempio n. 4
0
  private void initializeTitle(IEditorInput input) {

    Image oldImage = fTitleImage;
    fTitleImage = null;
    String title = ""; // $NON-NLS-1$

    if (input != null) {
      IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
      IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
      ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;

      fTitleImage = imageDesc != null ? imageDesc.createImage() : null;
      title = input.getName();
    }

    setTitleImage(fTitleImage);
    setPartName(title);

    firePropertyChange(PROP_DIRTY);

    if (oldImage != null && !oldImage.isDisposed()) oldImage.dispose();
  }