/*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.presentations.AbstractPresentationFactory#createViewPresentation(org.eclipse.swt.widgets.Composite,
   *      org.eclipse.ui.presentations.IStackPresentationSite)
   */
  public StackPresentation createViewPresentation(Composite parent, IStackPresentationSite site) {

    DefaultTabFolder folder =
        new DefaultTabFolder(
            parent,
            viewTabPosition | SWT.BORDER,
            site.supportsState(IStackPresentationSite.STATE_MINIMIZED),
            site.supportsState(IStackPresentationSite.STATE_MAXIMIZED));

    final IPreferenceStore store = PlatformUI.getPreferenceStore();
    final int minimumCharacters =
        store.getInt(IWorkbenchPreferenceConstants.VIEW_MINIMUM_CHARACTERS);
    if (minimumCharacters >= 0) {
      folder.setMinimumCharacters(minimumCharacters);
    }

    PresentablePartFolder partFolder = new PresentablePartFolder(folder);

    folder.setUnselectedCloseVisible(false);
    folder.setUnselectedImageVisible(true);

    TabbedStackPresentation result =
        new TabbedStackPresentation(site, partFolder, new StandardViewSystemMenu(site));

    DefaultThemeListener themeListener = new DefaultThemeListener(folder, result.getTheme());
    result.getTheme().addListener(themeListener);

    // RAP [bm]: not needed as tab style does not change
    //		new DefaultSimpleTabListener(result.getApiPreferences(),
    //				IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
    //				folder);
    // RAPEND: [bm]

    return result;
  }
  /* (non-Javadoc)
   * @see org.eclipse.ui.presentations.AbstractPresentationFactory#createEditorPresentation(org.eclipse.swt.widgets.Composite, org.eclipse.ui.presentations.IStackPresentationSite)
   */
  public StackPresentation createEditorPresentation(Composite parent, IStackPresentationSite site) {
    DefaultTabFolder folder =
        new DefaultTabFolder(
            parent,
            editorTabPosition | SWT.BORDER,
            site.supportsState(IStackPresentationSite.STATE_MINIMIZED),
            site.supportsState(IStackPresentationSite.STATE_MAXIMIZED));

    /*
     * Set the minimum characters to display, if the preference is something
     * other than the default. This is mainly intended for RCP applications
     * or for expert users (i.e., via the plug-in customization file).
     *
     * Bug 32789.
     */
    final IPreferenceStore store = PlatformUI.getPreferenceStore();
    if (store.contains(IWorkbenchPreferenceConstants.EDITOR_MINIMUM_CHARACTERS)) {
      final int minimumCharacters =
          store.getInt(IWorkbenchPreferenceConstants.EDITOR_MINIMUM_CHARACTERS);
      if (minimumCharacters >= 0) {
        folder.setMinimumCharacters(minimumCharacters);
      }
    }

    PresentablePartFolder partFolder = new PresentablePartFolder(folder);

    TabbedStackPresentation result =
        new TabbedStackPresentation(site, partFolder, new StandardEditorSystemMenu(site));

    DefaultThemeListener themeListener = new DefaultThemeListener(folder, result.getTheme());
    result.getTheme().addListener(themeListener);

    IDynamicPropertyMap workbenchPreferences =
        result.getPluginPreferences(WorkbenchPlugin.getDefault());

    // RAP [bm]:
    if (!Workbench.getInstance().isClosing()) {
      final DefaultMultiTabListener defaultMultiTabListener =
          new DefaultMultiTabListener(
              workbenchPreferences,
              IWorkbenchPreferenceConstants.SHOW_MULTIPLE_EDITOR_TABS,
              folder);
      result
          .getControl()
          .addDisposeListener(
              new DisposeListener() {
                public void widgetDisposed(DisposeEvent event) {
                  defaultMultiTabListener.attach(
                      null, IWorkbenchPreferenceConstants.SHOW_MULTIPLE_EDITOR_TABS, true);
                }
              });
    }
    // RAPEND: [bm]

    // RAP [bm]: tab style cannot change
    //		new DefaultSimpleTabListener(result.getApiPreferences(),
    //				IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
    //				folder);
    //		TODO: needs SessionStoreListener too when activated
    // RAPEND: [bm]

    return result;
  }