/**
   * @param definitions
   * @return
   */
  private static FontDefinition[] addDefaulted(FontDefinition[] definitions) {
    IThemeRegistry registry = WorkbenchPlugin.getDefault().getThemeRegistry();
    FontDefinition[] allDefs = registry.getFonts();

    SortedSet set = addDefaulted(definitions, allDefs);
    return (FontDefinition[]) set.toArray(new FontDefinition[set.size()]);
  }
  private void adjustOutsideActions() {
    final ActionSetRegistry reg = WorkbenchPlugin.getDefault().getActionSetRegistry();
    final IActionSetDescriptor[] actionSets = reg.getActionSets();
    final String[] removeActionSets =
        new String[] {
          "org.eclipse.search.searchActionSet", "org.eclipse.ui.cheatsheets.actionSet",
          "org.eclipse.ui.actionSet.keyBindings", "org.eclipse.ui.edit.text.actionSet.navigation",
          "org.eclipse.ui.edit.text.actionSet.annotationNavigation",
              "org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo",
          "org.eclipse.ui.edit.text.actionSet.openExternalFile",
              "org.eclipse.ui.externaltools.ExternalToolsSet",
          "org.eclipse.ui.WorkingSetActionSet", "org.eclipse.update.ui.softwareUpdates",
          "org.eclipse.ui.actionSet.openFiles", "org.eclipse.mylyn.tasks.ui.navigation",
        };

    for (int i = 0; i < actionSets.length; i++) {
      boolean found = false;
      for (int j = 0; j < removeActionSets.length; j++) {
        if (removeActionSets[j].equals(actionSets[i].getId())) {
          found = true;
        }
      }
      if (!found) {
        continue;
      }
      final IExtension ext = actionSets[i].getConfigurationElement().getDeclaringExtension();
      reg.removeExtension(ext, new Object[] {actionSets[i]});
    }
  }
  /**
   * Tests whether the preference store will be read automatically when a change to the preference
   * store is made.
   *
   * @throws ParseException If "ALT+SHIFT+Q A" cannot be parsed by KeySequence.
   */
  public final void testAutoLoad() throws ParseException {
    // Get the services.
    ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class);
    IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class);
    bindingService.readRegistryAndPreferences(commandService);

    // Check the pre-conditions.
    final String emacsSchemeId = EMACS_SCHEME_ID;
    assertFalse(
        "The active scheme should be Emacs yet",
        emacsSchemeId.equals(bindingService.getActiveScheme().getId()));
    final KeySequence formalKeySequence = KeySequence.getInstance("ALT+SHIFT+Q A");
    final String commandId = "org.eclipse.ui.views.showView";
    Binding[] bindings = bindingService.getBindings();
    int i;
    for (i = 0; i < bindings.length; i++) {
      final Binding binding = bindings[i];
      if ((binding.getType() == Binding.USER)
          && (formalKeySequence.equals(binding.getTriggerSequence()))) {
        final ParameterizedCommand command = binding.getParameterizedCommand();
        final String actualCommandId = (command == null) ? null : command.getCommand().getId();
        assertFalse("The command should not yet be bound", commandId.equals(actualCommandId));
        break;
      }
    }
    assertEquals("There shouldn't be a matching command yet", bindings.length, i);

    // Modify the preference store.
    final IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
    store.setValue(
        "org.eclipse.ui.commands",
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?><org.eclipse.ui.commands><activeKeyConfiguration keyConfigurationId=\""
            + emacsSchemeId
            + "\"/><keyBinding commandId=\""
            + commandId
            + "\" contextId=\"org.eclipse.ui.contexts.window\" keyConfigurationId=\"org.eclipse.ui.defaultAcceleratorConfiguration\" keySequence=\""
            + formalKeySequence
            + "\"/></org.eclipse.ui.commands>");

    // Check that the values have changed.
    assertEquals(
        "The active scheme should now be Emacs",
        emacsSchemeId,
        bindingService.getActiveScheme().getId());
    bindings = bindingService.getBindings();
    for (i = 0; i < bindings.length; i++) {
      final Binding binding = bindings[i];
      if ((binding.getType() == Binding.USER)
          && (formalKeySequence.equals(binding.getTriggerSequence()))) {
        final ParameterizedCommand command = binding.getParameterizedCommand();
        final String actualCommandId = (command == null) ? null : command.getCommand().getId();
        assertEquals("The command should be bound to 'ALT+SHIFT+Q A'", commandId, actualCommandId);
        break;
      }
    }
    assertFalse("There should be a matching command now", (bindings.length == i));
  }
  /**
   * Return the definitions that should have their default preference value set but nothing else.
   *
   * @param definitions the definitions that will be fully handled
   * @return the remaining definitions that should be defaulted
   */
  private static FontDefinition[] getDefaults(FontDefinition[] definitions) {
    IThemeRegistry registry = WorkbenchPlugin.getDefault().getThemeRegistry();
    FontDefinition[] allDefs = registry.getFonts();

    SortedSet set = new TreeSet(IThemeRegistry.ID_COMPARATOR);
    set.addAll(Arrays.asList(allDefs));
    set.removeAll(Arrays.asList(definitions));
    return (FontDefinition[]) set.toArray(new FontDefinition[set.size()]);
  }
 public ExportBarWizard() {
   setDefaultPageImageDescriptor(Pics.getWizban());
   setNeedsProgressMonitor(true);
   IDialogSettings workbenchSettings = WorkbenchPlugin.getDefault().getDialogSettings();
   IDialogSettings wizardSettings = workbenchSettings.getSection("ExportBarWizard"); // $NON-NLS-1$
   if (wizardSettings == null) {
     wizardSettings = workbenchSettings.addNewSection("ExportBarWizard"); // $NON-NLS-1$
   }
   setDialogSettings(wizardSettings);
   setWindowTitle(Messages.buildTitle);
 }
  @Override
  protected IDialogSettings getDialogBoundsSettings() {
    final String settingsName = getClass().getCanonicalName();

    IDialogSettings workbenchSettings = WorkbenchPlugin.getDefault().getDialogSettings();
    IDialogSettings section = workbenchSettings.getSection(settingsName);

    if (section == null) {
      section = workbenchSettings.addNewSection(settingsName);
    }

    return section;
  }
  /**
   * Create a new instance of this class.
   *
   * @param composite parent composite
   * @param currentSelection the initial working set selection to pass to the {@link
   *     WorkingSetConfigurationBlock}
   * @param workingSetTypes the types of working sets that can be selected by the {@link
   *     WorkingSetConfigurationBlock}
   */
  public WorkingSetGroup(
      Composite composite, IStructuredSelection currentSelection, String[] workingSetTypes) {
    Group workingSetGroup = new Group(composite, SWT.NONE);
    workingSetGroup.setFont(composite.getFont());
    workingSetGroup.setText(WorkbenchMessages.WorkingSetGroup_WorkingSets_group);
    workingSetGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    workingSetGroup.setLayout(new GridLayout(1, false));

    workingSetBlock =
        new WorkingSetConfigurationBlock(
            WorkbenchPlugin.getDefault().getDialogSettings(), workingSetTypes);
    workingSetBlock.setWorkingSets(workingSetBlock.findApplicableWorkingSets(currentSelection));
    workingSetBlock.createContent(workingSetGroup);
  }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.tests.harness.util.UITestCase#doTearDown()
   */
  protected void doTearDown() throws Exception {
    final IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
    store.setValue(
        "org.eclipse.ui.commands",
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?><org.eclipse.ui.commands><activeKeyConfiguration keyConfigurationId=\""
            + IBindingService.DEFAULT_DEFAULT_ACTIVE_SCHEME_ID
            + "\"/></org.eclipse.ui.commands>");
    IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class);

    // reset keybindings
    bindingService.readRegistryAndPreferences(null);
    final Scheme activeScheme =
        bindingService.getScheme(IBindingService.DEFAULT_DEFAULT_ACTIVE_SCHEME_ID);
    final Binding[] originalBindings = bindingService.getBindings();
    bindingService.savePreferences(activeScheme, originalBindings);
    super.doTearDown();
  }
예제 #9
0
  @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);
  }
  /**
   * @param theme
   * @param property
   * @return
   */
  public static String[] splitPropertyName(Theme theme, String property) {
    IThemeDescriptor[] descriptors = WorkbenchPlugin.getDefault().getThemeRegistry().getThemes();
    for (int i = 0; i < descriptors.length; i++) {
      IThemeDescriptor themeDescriptor = descriptors[i];
      String id = themeDescriptor.getId();
      if (property.startsWith(id + '.')) { // the property starts with
        // a known theme ID -
        // extract and return it and
        // the remaining property
        return new String[] {
          property.substring(0, id.length()), property.substring(id.length() + 1)
        };
      }
    }

    // default is simply return the default theme ID and the raw property
    return new String[] {IThemeManager.DEFAULT_THEME, property};
  }
예제 #11
0
  private void createToolBar(Composite parent) {
    final Composite toolbarComposite = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(1).applyTo(toolbarComposite);
    toolbarComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    CoolBarManager coolBarManager = new CoolBarManager(SWT.HORIZONTAL | SWT.FLAT);
    {
      ToolBarManager manager = new ToolBarManager(SWT.HORIZONTAL | SWT.FLAT);
      IAction homeAction =
          new Action() {
            @Override
            public void run() {
              close();
            }
          };
      homeAction.setToolTipText(Messages.ControlPanelWindow_ReturnActionTooltip);
      homeAction.setImageDescriptor(Images.getImageDescriptor(Images.PANEL_HOME));
      manager.add(homeAction);

      IAction saveAction =
          new Action() {
            @Override
            public void run() {
              if (getModel() != null) {
                save();
              } else {
                saveAs();
              }
            }
          };

      saveAction.setMenuCreator(
          new ActionMenuCreator() {
            @Override
            protected void fill(MenuManager manager) {
              manager.add(
                  new Action(Messages.ControlPanelWindow_SaveAction) {
                    {
                      dbc.bindValue(
                          Actions.observeEnabled(this),
                          new ComputedValue() {
                            @Override
                            protected Object calculate() {
                              return getModel() != null;
                            }
                          });
                    }

                    @Override
                    public void run() {
                      save();
                    }
                  });
              manager.add(
                  new Action(Messages.ControlPanelWindow_SaveAsAction) {
                    @Override
                    public void run() {
                      saveAs();
                    }
                  });
            }
          });
      dbc.bindValue(
          Actions.observeToolTipText(saveAction),
          new ComputedValue() {
            @Override
            protected Object calculate() {
              if (getModel() != null) {
                return Messages.ControlPanelWindow_SaveAction;
              } else {
                return Messages.ControlPanelWindow_SaveAsAction;
              }
            }
          });
      ISharedImages sharedImages = WorkbenchPlugin.getDefault().getSharedImages();
      saveAction.setImageDescriptor(
          sharedImages.getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT));
      saveAction.setDisabledImageDescriptor(
          sharedImages.getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT_DISABLED));
      manager.add(saveAction);
      coolBarManager.add(manager);
    }
    {
      ToolBarManager manager = new ToolBarManager(SWT.HORIZONTAL | SWT.FLAT);
      manager.add(createRecordAction());
      manager.add(createReplayAction());
      coolBarManager.add(manager);
    }
    {
      ToolBarManager manager = new ToolBarManager(SWT.HORIZONTAL | SWT.FLAT);
      manager.add(createRecordingModeAction());
      manager.add(createAssertingModeAction());
      if (Q7UIPlugin.isImageRecognitionAllowed()) {
        manager.add(createImageRecognitionModeAction());
      }
      coolBarManager.add(manager);
    }
    coolBar = coolBarManager.createControl(toolbarComposite);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(coolBar);
    coolBar.addListener(
        SWT.Resize,
        new Listener() {
          public void handleEvent(Event event) {
            getShell().layout();
          }
        });
  }
/** Deletes a method on an RPC async or sync interface. */
@SuppressWarnings("restriction")
public class DeleteMethodProposal extends ASTRewriteCorrectionProposal {

  private static final Image ICON =
      WorkbenchPlugin.getDefault().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);

  private static final int RELEVANCE = 99;

  public static List<IJavaCompletionProposal> createProposalsForProblemOnAsyncType(
      ASTNode problemNode, String extraSyncMethodBindingKey) {
    TypeDeclaration asyncTypeDecl =
        (TypeDeclaration) ASTResolving.findAncestor(problemNode, ASTNode.TYPE_DECLARATION);
    assert (asyncTypeDecl != null);

    IType syncType = RemoteServiceUtilities.findSyncType(asyncTypeDecl);
    if (syncType == null) {
      return null;
    }

    MethodDeclaration extraSyncMethodDecl =
        JavaASTUtils.findMethodDeclaration(
            syncType.getCompilationUnit(), extraSyncMethodBindingKey);
    if (extraSyncMethodDecl == null) {
      return null;
    }

    return Collections.<IJavaCompletionProposal>singletonList(
        new DeleteMethodProposal(syncType.getCompilationUnit(), extraSyncMethodDecl));
  }

  public static List<IJavaCompletionProposal> createProposalsForProblemOnExtraMethod(
      ASTNode problemNode) {
    MethodDeclaration methodDecl = ASTResolving.findParentMethodDeclaration(problemNode);

    return Collections.<IJavaCompletionProposal>singletonList(
        new DeleteMethodProposal(JavaASTUtils.getCompilationUnit(methodDecl), methodDecl));
  }

  public static List<IJavaCompletionProposal> createProposalsForProblemOnSyncType(
      ASTNode problemNode, String extraAsyncMethodBindingKey) {
    TypeDeclaration syncTypeDecl =
        (TypeDeclaration) ASTResolving.findAncestor(problemNode, ASTNode.TYPE_DECLARATION);
    assert (syncTypeDecl != null);

    IType asyncType = RemoteServiceUtilities.findAsyncType(syncTypeDecl);
    if (asyncType == null) {
      return null;
    }

    MethodDeclaration extraAsyncMethodDecl =
        JavaASTUtils.findMethodDeclaration(
            asyncType.getCompilationUnit(), extraAsyncMethodBindingKey);
    if (extraAsyncMethodDecl == null) {
      return null;
    }

    return Collections.<IJavaCompletionProposal>singletonList(
        new DeleteMethodProposal(asyncType.getCompilationUnit(), extraAsyncMethodDecl));
  }

  private static String generateDisplayName(MethodDeclaration methodDecl) {
    TypeDeclaration typeDecl = (TypeDeclaration) ASTResolving.findParentType(methodDecl);
    return MessageFormat.format(
        "Remove method ''{0}'' from type ''{1}''",
        methodDecl.getName().getIdentifier(), typeDecl.getName().getIdentifier());
  }

  private final MethodDeclaration methodDecl;

  private DeleteMethodProposal(ICompilationUnit cu, MethodDeclaration methodDecl) {
    super(generateDisplayName(methodDecl), cu, null, RELEVANCE, ICON);
    this.methodDecl = methodDecl;
  }

  @Override
  protected ASTRewrite getRewrite() throws CoreException {
    CompilationUnit targetAstRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
    createImportRewrite(targetAstRoot);

    ASTRewrite rewrite = ASTRewrite.create(targetAstRoot.getAST());

    // Find the method declaration in the AST we just generated (the one that
    // the AST rewriter is hooked up to).
    MethodDeclaration rewriterAstMethodDecl =
        JavaASTUtils.findMethodDeclaration(targetAstRoot, methodDecl.resolveBinding().getKey());
    if (rewriterAstMethodDecl == null) {
      return null;
    }

    // Remove the extra method declaration
    rewrite.remove(rewriterAstMethodDecl, null);

    return rewrite;
  }
}
  /* (non-Javadoc)
   * @see org.eclipse.ui.tests.dnd.TestDropTarget#getName()
   */
  public String toString() {
    IViewDescriptor desc = WorkbenchPlugin.getDefault().getViewRegistry().find(targetPart);
    String title = desc.getLabel();

    return title + " view title area";
  }
  /* (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;
  }
/**
 * The default presentation factory for the Workbench.
 *
 * @since 1.0
 */
public class WorkbenchPresentationFactory extends AbstractPresentationFactory {

  // don't reset these dynamically, so just keep the information static.
  // see bug:
  // 75422 [Presentations] Switching presentation to R21 switches immediately,
  // but only partially
  private static int editorTabPosition =
      WorkbenchPlugin.getDefault()
          .getPreferenceStore()
          .getInt(IWorkbenchPreferenceConstants.EDITOR_TAB_POSITION);
  private static int viewTabPosition =
      WorkbenchPlugin.getDefault()
          .getPreferenceStore()
          .getInt(IWorkbenchPreferenceConstants.VIEW_TAB_POSITION);

  /* (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;
  }

  /*
   * (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#createStandaloneViewPresentation(org.eclipse.swt.widgets.Composite,
   *      org.eclipse.ui.presentations.IStackPresentationSite, boolean)
   */
  public StackPresentation createStandaloneViewPresentation(
      Composite parent, IStackPresentationSite site, boolean showTitle) {

    if (showTitle) {
      return createViewPresentation(parent, site);
    }
    EmptyTabFolder folder = new EmptyTabFolder(parent, true);
    TabbedStackPresentation presentation =
        new TabbedStackPresentation(site, folder, new StandardViewSystemMenu(site));

    return presentation;
  }
}
/**
 * A stack presentation using native widgets.
 *
 * <p>EXPERIMENTAL
 *
 * @since 3.0
 */
public class NativeStackPresentation extends StackPresentation {

  private TabFolder tabFolder;

  private Listener dragListener;

  private IPresentablePart current;

  private MenuManager systemMenuManager = new MenuManager();

  private static IPreferenceStore preferenceStore =
      WorkbenchPlugin.getDefault().getPreferenceStore();

  // don't reset this dynamically, so just keep the information static.
  // see bug:
  //   75422 [Presentations] Switching presentation to R21 switches immediately, but only partially
  private static int tabPos =
      preferenceStore.getInt(IWorkbenchPreferenceConstants.VIEW_TAB_POSITION);

  private static final String TAB_DATA =
      NativeStackPresentation.class.getName() + ".partId"; // $NON-NLS-1$

  private MouseListener mouseListener =
      new MouseAdapter() {
        public void mouseDown(MouseEvent e) {
          //			// PR#1GDEZ25 - If selection will change in mouse up ignore mouse down.
          //			// Else, set focus.
          //			TabItem newItem = tabFolder.getItem(new Point(e.x, e.y));
          //			if (newItem != null) {
          //				TabItem oldItem = tabFolder.getSelection();
          //				if (newItem != oldItem)
          //					return;
          //			}
          if (current != null) {
            current.setFocus();
          }
        }
      };

  private Listener menuListener =
      new Listener() {
        /* (non-Javadoc)
         * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
         */
        public void handleEvent(Event event) {
          Point pos = new Point(event.x, event.y);
          //			TabItem item = tabFolder.getItem(pos);
          TabItem item = null;
          IPresentablePart part = null;
          if (item != null) {
            part = getPartForTab(item);
          }
          showPaneMenu(part, pos);
        }
      };

  private Listener selectionListener =
      new Listener() {
        public void handleEvent(Event e) {
          IPresentablePart item = getPartForTab((TabItem) e.item);
          if (item != null) {
            getSite().selectPart(item);
            //				item.setFocus();
          }
        }
      };

  private Listener resizeListener =
      new Listener() {
        public void handleEvent(Event e) {
          setControlSize();
        }
      };

  private IPropertyListener childPropertyChangeListener =
      new IPropertyListener() {
        public void propertyChanged(Object source, int property) {

          if (isDisposed()) {
            return;
          }

          if (source instanceof IPresentablePart) {
            IPresentablePart part = (IPresentablePart) source;
            childPropertyChanged(part, property);
          }
        }
      };

  private DisposeListener tabDisposeListener =
      new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
          if (e.widget instanceof TabItem) {
            TabItem item = (TabItem) e.widget;
            IPresentablePart part = getPartForTab(item);
            part.removePropertyListener(childPropertyChangeListener);
          }
        }
      };

  public NativeStackPresentation(Composite parent, IStackPresentationSite stackSite) {
    super(stackSite);

    tabFolder = new TabFolder(parent, tabPos);

    // listener to switch between visible tabItems
    tabFolder.addListener(SWT.Selection, selectionListener);

    // listener to resize visible components
    tabFolder.addListener(SWT.Resize, resizeListener);

    // listen for mouse down on tab to set focus.
    tabFolder.addMouseListener(mouseListener);

    tabFolder.addListener(SWT.MenuDetect, menuListener);

    dragListener =
        new Listener() {
          public void handleEvent(Event event) {
            Point localPos = new Point(event.x, event.y);
            //				TabItem tabUnderPointer = tabFolder.getItem(localPos);
            TabItem tabUnderPointer = null;

            if (tabUnderPointer == null) {
              return;
            }

            IPresentablePart part = getPartForTab(tabUnderPointer);

            if (getSite().isPartMoveable(part)) {
              getSite().dragStart(part, tabFolder.toDisplay(localPos), false);
            }
          }
        };

    PresentationUtil.addDragListener(tabFolder, dragListener);
  }

  /**
   * Returns the index of the tab for the given part, or returns tabFolder.getItemCount() if there
   * is no such tab.
   *
   * @param part part being searched for
   * @return the index of the tab for the given part, or the number of tabs if there is no such tab
   */
  private final int indexOf(IPresentablePart part) {
    if (part == null) {
      return tabFolder.getItemCount();
    }

    TabItem[] items = tabFolder.getItems();

    for (int idx = 0; idx < items.length; idx++) {
      IPresentablePart tabPart = getPartForTab(items[idx]);

      if (part == tabPart) {
        return idx;
      }
    }

    return items.length;
  }

  /**
   * Returns the tab for the given part, or null if there is no such tab
   *
   * @param part the part being searched for
   * @return the tab for the given part, or null if there is no such tab
   */
  protected final TabItem getTab(IPresentablePart part) {
    TabItem[] items = tabFolder.getItems();

    int idx = indexOf(part);

    if (idx < items.length) {
      return items[idx];
    }

    return null;
  }

  /**
   * @param part
   * @param property
   */
  protected void childPropertyChanged(IPresentablePart part, int property) {
    TabItem tab = getTab(part);
    initTab(tab, part);
  }

  protected final IPresentablePart getPartForTab(TabItem item) {
    IPresentablePart part = (IPresentablePart) item.getData(TAB_DATA);
    return part;
  }

  protected TabFolder getTabFolder() {
    return tabFolder;
  }

  public boolean isDisposed() {
    return tabFolder == null || tabFolder.isDisposed();
  }

  /** Set the size of a page in the folder. */
  private void setControlSize() {
    if (current == null || tabFolder == null) {
      return;
    }
    //		Rectangle bounds;
    // @issue as above, the mere presence of a theme should not change the behaviour
    //		if ((mapTabToPart.size() > 1)
    //			|| ((tabThemeDescriptor != null) && (mapTabToPart.size() >= 1)))
    //			bounds = calculatePageBounds(tabFolder);
    //		else
    //			bounds = tabFolder.getBounds();
    current.setBounds(calculatePageBounds(tabFolder));
    // current.moveAbove(tabFolder);
  }

  public static Rectangle calculatePageBounds(TabFolder folder) {
    if (folder == null) {
      return new Rectangle(0, 0, 0, 0);
    }
    Rectangle bounds = folder.getBounds();
    Rectangle offset = folder.getClientArea();
    bounds.x += offset.x;
    bounds.y += offset.y;
    bounds.width = offset.width;
    bounds.height = offset.height;
    return bounds;
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.skins.Presentation#dispose()
   */
  public void dispose() {
    if (isDisposed()) {
      return;
    }
    PresentationUtil.removeDragListener(tabFolder, dragListener);

    // systemMenuManager.dispose();

    tabFolder.dispose();
    tabFolder = null;
  }

  private TabItem createPartTab(IPresentablePart part, int tabIndex) {
    TabItem tabItem = new TabItem(tabFolder, SWT.NONE, tabIndex);
    tabItem.setData(TAB_DATA, part);
    part.addPropertyListener(childPropertyChangeListener);
    tabItem.addDisposeListener(tabDisposeListener);
    initTab(tabItem, part);
    return tabItem;
  }

  /**
   * Initializes a tab for the given part. Sets the text, icon, tool tip, etc. This will also be
   * called whenever a relevant property changes in the part to reflect those changes in the tab.
   * Subclasses may override to change the appearance of tabs for a particular part.
   *
   * @param tabItem tab for the part
   * @param part the part being displayed
   */
  protected void initTab(TabItem tabItem, IPresentablePart part) {
    tabItem.setText(part.getName());
    tabItem.setToolTipText(part.getTitleToolTip());

    Image tabImage = part.getTitleImage();
    if (tabImage != tabItem.getImage()) {
      tabItem.setImage(tabImage);
    }
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.skins.StackPresentation#addPart(org.eclipse.ui.internal.skins.IPresentablePart, org.eclipse.ui.internal.skins.IPresentablePart)
   */
  public void addPart(IPresentablePart newPart, Object cookie) {
    createPartTab(newPart, tabFolder.getItemCount());
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.skins.StackPresentation#removePart(org.eclipse.ui.internal.skins.IPresentablePart)
   */
  public void removePart(IPresentablePart oldPart) {
    TabItem item = getTab(oldPart);
    if (item == null) {
      return;
    }
    oldPart.setVisible(false);

    item.dispose();
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.skins.StackPresentation#selectPart(org.eclipse.ui.internal.skins.IPresentablePart)
   */
  public void selectPart(IPresentablePart toSelect) {
    if (toSelect == current) {
      return;
    }

    if (current != null) {
      current.setVisible(false);
    }

    current = toSelect;

    if (current != null) {
      tabFolder.setSelection(indexOf(current));
      current.setVisible(true);
      setControlSize();
    }
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.skins.Presentation#setBounds(org.eclipse.swt.graphics.Rectangle)
   */
  public void setBounds(Rectangle bounds) {
    tabFolder.setBounds(bounds);
    setControlSize();
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.skins.Presentation#computeMinimumSize()
   */
  public Point computeMinimumSize() {
    return Geometry.getSize(tabFolder.computeTrim(0, 0, 0, 0));
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.skins.Presentation#setVisible(boolean)
   */
  public void setVisible(boolean isVisible) {
    if (current != null) {
      current.setVisible(isVisible);
    }
    tabFolder.setVisible(isVisible);
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.skins.Presentation#setState(int)
   */
  public void setState(int state) {
    //		tabFolder.setMinimized(state == IPresentationSite.STATE_MINIMIZED);
    //		tabFolder.setMaximized(state == IPresentationSite.STATE_MAXIMIZED);
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.skins.Presentation#getSystemMenuManager()
   */
  public IMenuManager getSystemMenuManager() {
    return systemMenuManager;
  }

  /**
   * @param part
   * @param point
   */
  protected void showPaneMenu(IPresentablePart part, Point point) {
    systemMenuManager.update(false);
    Menu aMenu = systemMenuManager.createContextMenu(tabFolder.getParent());
    aMenu.setLocation(point.x, point.y);
    aMenu.setVisible(true);
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.skins.Presentation#getControl()
   */
  public Control getControl() {
    return tabFolder;
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.skins.StackPresentation#dragOver(org.eclipse.swt.widgets.Control, org.eclipse.swt.graphics.Point)
   */
  public StackDropResult dragOver(Control currentControl, Point location) {

    // Determine which tab we're currently dragging over
    //		Point localPos = tabFolder.toControl(location);
    //		final TabItem tabUnderPointer = tabFolder.getItem(localPos);
    final TabItem tabUnderPointer = null;

    // This drop target only deals with tabs... if we're not dragging over
    // a tab, exit.
    if (tabUnderPointer == null) {
      return null;
    }

    //		return new StackDropResult(Geometry.toDisplay(tabFolder, tabUnderPointer.getBounds()),
    //			tabFolder.indexOf(tabUnderPointer));
    return null;
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.presentations.StackPresentation#showSystemMenu()
   */
  public void showSystemMenu() {
    // TODO Auto-generated method stub

  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.presentations.StackPresentation#showPaneMenu()
   */
  public void showPaneMenu() {
    // TODO Auto-generated method stub

  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.presentations.StackPresentation#getTabList(IPresentablePart)
   */
  public Control[] getTabList(IPresentablePart part) {
    ArrayList list = new ArrayList();
    if (getControl() != null) {
      list.add(getControl());
    }
    if (part.getToolBar() != null) {
      list.add(part.getToolBar());
    }
    if (part.getControl() != null) {
      list.add(part.getControl());
    }
    return (Control[]) list.toArray(new Control[list.size()]);
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.presentations.StackPresentation#getCurrentPart()
   */
  public IPresentablePart getCurrentPart() {
    return current;
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.presentations.StackPresentation#setActive(int)
   */
  public void setActive(int newState) {}
}
public class WorkbenchPreview implements IThemePreview {

  private static IPreferenceStore preferenceStore =
      WorkbenchPlugin.getDefault().getPreferenceStore();

  // don't reset this dynamically, so just keep the information static.
  // see bug:
  //   75422 [Presentations] Switching presentation to R21 switches immediately, but only partially
  private static int tabPos =
      preferenceStore.getInt(IWorkbenchPreferenceConstants.VIEW_TAB_POSITION);

  // RAP [bm]:
  //    private IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore();

  private boolean disposed = false;

  private CTabFolder folder;

  private ITheme theme;

  private ToolBar toolBar;

  private CLabel viewMessage;

  private ViewForm viewForm;

  private IPropertyChangeListener fontAndColorListener =
      new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
          if (!disposed) {
            setColorsAndFonts();
            // viewMessage.setSize(viewMessage.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
            viewForm.layout(true);
          }
        }
      };

  /* (non-Javadoc)
   * @see org.eclipse.ui.IPresentationPreview#createControl(org.eclipse.swt.widgets.Composite, org.eclipse.ui.themes.ITheme)
   */
  public void createControl(Composite parent, ITheme currentTheme) {
    this.theme = currentTheme;
    folder = new CTabFolder(parent, SWT.BORDER);
    folder.setUnselectedCloseVisible(false);
    folder.setEnabled(false);
    folder.setMaximizeVisible(true);
    folder.setMinimizeVisible(true);

    viewForm = new ViewForm(folder, SWT.NONE);
    viewForm.marginHeight = 0;
    viewForm.marginWidth = 0;
    viewForm.verticalSpacing = 0;
    viewForm.setBorderVisible(false);
    toolBar = new ToolBar(viewForm, SWT.FLAT | SWT.WRAP);
    ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);

    Image hoverImage = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
    toolItem.setImage(hoverImage);

    viewForm.setTopRight(toolBar);

    viewMessage = new CLabel(viewForm, SWT.NONE);
    viewMessage.setText("Etu?"); // $NON-NLS-1$
    viewForm.setTopLeft(viewMessage);

    CTabItem item = new CTabItem(folder, SWT.CLOSE);
    item.setText("Lorem"); // $NON-NLS-1$
    Label text = new Label(viewForm, SWT.NONE);
    viewForm.setContent(text);
    text.setText("Lorem ipsum dolor sit amet"); // $NON-NLS-1$
    text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    item = new CTabItem(folder, SWT.CLOSE);
    item.setText("Ipsum"); // $NON-NLS-1$
    item.setControl(viewForm);
    item.setImage(WorkbenchImages.getImage(ISharedImages.IMG_TOOL_COPY));

    folder.setSelection(item);

    item = new CTabItem(folder, SWT.CLOSE);
    item.setText("Dolor"); // $NON-NLS-1$
    item = new CTabItem(folder, SWT.CLOSE);
    item.setText("Sit"); // $NON-NLS-1$

    currentTheme.addPropertyChangeListener(fontAndColorListener);
    setColorsAndFonts();
    setTabPosition();
    setTabStyle();
  }

  /** Set the tab style from preferences. */
  protected void setTabStyle() {
    // RAP [bm]: CTabFolder#setSimple
    //        boolean traditionalTab = apiStore
    //                .getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS);
    //        folder.setSimple(traditionalTab);
    // RAPEND: [bm]
  }

  /** Set the tab location from preferences. */
  protected void setTabPosition() {
    tabPos = preferenceStore.getInt(IWorkbenchPreferenceConstants.VIEW_TAB_POSITION);
    folder.setTabPosition(tabPos);
  }

  /** Set the folder colors and fonts */
  private void setColorsAndFonts() {
    folder.setSelectionForeground(
        theme.getColorRegistry().get(IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR));
    folder.setForeground(
        theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR));

    Color[] colors = new Color[2];
    colors[0] = theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
    colors[1] = theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
    colors[0] = theme.getColorRegistry().get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START);
    colors[1] = theme.getColorRegistry().get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END);
    // RAP [bm]: CTabFolder gradient
    //        folder.setSelectionBackground(colors, new int[] { theme
    //                .getInt(IWorkbenchThemeConstants.ACTIVE_TAB_PERCENT) }, theme
    //                .getBoolean(IWorkbenchThemeConstants.ACTIVE_TAB_VERTICAL));
    folder.setSelectionBackground(colors[0]);
    // RAPEND: [bm]

    folder.setFont(theme.getFontRegistry().get(IWorkbenchThemeConstants.TAB_TEXT_FONT));
    viewMessage.setFont(
        theme.getFontRegistry().get(IWorkbenchThemeConstants.VIEW_MESSAGE_TEXT_FONT));
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.IPresentationPreview#dispose()
   */
  public void dispose() {
    disposed = true;
    theme.removePropertyChangeListener(fontAndColorListener);
  }
}
  /**
   * Creates the history toolbar and initializes <code>historyToolbar</code>.
   *
   * @param historyBar
   * @param manager
   * @return the control of the history toolbar
   */
  public ToolBar createHistoryControls(ToolBar historyBar, ToolBarManager manager) {

    historyToolbar = manager;
    /** Superclass of the two for-/backward actions for the history. */
    abstract class HistoryNavigationAction extends Action implements IMenuCreator {
      private Menu lastMenu;

      protected static final int MAX_ENTRIES = 5;

      HistoryNavigationAction() {
        super("", IAction.AS_DROP_DOWN_MENU); // $NON-NLS-1$
      }

      public IMenuCreator getMenuCreator() {
        return this;
      }

      public void dispose() {
        if (lastMenu != null) {
          lastMenu.dispose();
          lastMenu = null;
        }
      }

      public Menu getMenu(Control parent) {
        if (lastMenu != null) {
          lastMenu.dispose();
        }
        lastMenu = new Menu(parent);
        createEntries(lastMenu);
        return lastMenu;
      }

      public Menu getMenu(Menu parent) {
        return null;
      }

      protected void addActionToMenu(Menu parent, IAction action) {
        ActionContributionItem item = new ActionContributionItem(action);
        item.fill(parent, -1);
      }

      protected abstract void createEntries(Menu menu);
    }

    /**
     * Menu entry for the toolbar dropdowns. Instances are direct-jump entries in the navigation
     * history.
     */
    class HistoryItemAction extends Action {

      private final int index;

      HistoryItemAction(int index, String label) {
        super(label, IAction.AS_PUSH_BUTTON);
        this.index = index;
      }

      public void run() {
        jumpToHistory(index);
      }
    }

    HistoryNavigationAction backward =
        new HistoryNavigationAction() {
          public void run() {
            jumpToHistory(historyIndex - 1);
          }

          public boolean isEnabled() {
            boolean enabled = historyIndex > 0;
            if (enabled) {
              setToolTipText(
                  NLS.bind(
                      WorkbenchMessages.get().NavigationHistoryAction_backward_toolTipName,
                      getHistoryEntry(historyIndex - 1).getLabel()));
            }
            return enabled;
          }

          protected void createEntries(Menu menu) {
            int limit = Math.max(0, historyIndex - MAX_ENTRIES);
            for (int i = historyIndex - 1; i >= limit; i--) {
              IAction action = new HistoryItemAction(i, getHistoryEntry(i).getLabel());
              addActionToMenu(menu, action);
            }
          }
        };
    backward.setText(WorkbenchMessages.get().NavigationHistoryAction_backward_text);
    backward.setActionDefinitionId("org.eclipse.ui.navigate.backwardHistory"); // $NON-NLS-1$
    backward.setImageDescriptor(
        WorkbenchPlugin.getDefault()
            .getSharedImages()
            .getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
    backward.setDisabledImageDescriptor(
        WorkbenchPlugin.getDefault()
            .getSharedImages()
            .getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
    registerKeybindings(backward);
    historyToolbar.add(backward);

    HistoryNavigationAction forward =
        new HistoryNavigationAction() {
          public void run() {
            jumpToHistory(historyIndex + 1);
          }

          public boolean isEnabled() {
            boolean enabled = historyIndex < history.size() - 1;
            if (enabled) {
              setToolTipText(
                  NLS.bind(
                      WorkbenchMessages.get().NavigationHistoryAction_forward_toolTipName,
                      getHistoryEntry(historyIndex + 1).getLabel()));
            }
            return enabled;
          }

          protected void createEntries(Menu menu) {
            int limit = Math.min(history.size(), historyIndex + MAX_ENTRIES + 1);
            for (int i = historyIndex + 1; i < limit; i++) {
              IAction action = new HistoryItemAction(i, getHistoryEntry(i).getLabel());
              addActionToMenu(menu, action);
            }
          }
        };
    forward.setText(WorkbenchMessages.get().NavigationHistoryAction_forward_text);
    forward.setActionDefinitionId("org.eclipse.ui.navigate.forwardHistory"); // $NON-NLS-1$
    forward.setImageDescriptor(
        WorkbenchPlugin.getDefault()
            .getSharedImages()
            .getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
    forward.setDisabledImageDescriptor(
        WorkbenchPlugin.getDefault()
            .getSharedImages()
            .getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
    registerKeybindings(forward);
    historyToolbar.add(forward);

    return historyBar;
  }
예제 #19
0
 /**
  * Dispose the decorator instance and remove listeners as appropirate.
  *
  * @param disposedDecorator
  */
 protected void disposeCachedDecorator(IBaseLabelProvider disposedDecorator) {
   disposedDecorator.removeListener(WorkbenchPlugin.getDefault().getDecoratorManager());
   disposedDecorator.dispose();
 }
예제 #20
0
  protected void openStartupMap(IProgressMonitor monitor) {
    if (!hasOpenedEditors()) {
      int action = CathyPlugin.getDefault().getPreferenceStore().getInt(CathyPlugin.STARTUP_ACTION);
      if (action == CathyPlugin.STARTUP_ACTION_HOME) {
        monitor.subTask(WorkbenchMessages.StartupJob_OpenHomeMap);
        SafeRunner.run(
            new SafeRunnable() {
              public void run() throws Exception {
                workbench
                    .getDisplay()
                    .syncExec(
                        new Runnable() {
                          public void run() {
                            IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
                            if (window != null) {
                              final IWorkbenchPage page = window.getActivePage();
                              Shell shell = window.getShell();
                              if (page != null) {
                                OpenHomeMapAction.openHomeMap(shell, page);
                              }
                            }
                          }
                        });
              }
            });
      } else if (action == CathyPlugin.STARTUP_ACTION_BLANK) {
        monitor.subTask(WorkbenchMessages.StartupJob_OpenBlankMap);
        openBlankMap();
      } else if (action == CathyPlugin.STARTUP_ACTION_LAST) {
        IPath editorStatusPath =
            WorkbenchPlugin.getDefault()
                .getDataLocation()
                .append("XMind_Editors.xml"); // $NON-NLS-1$
        // open unclosed editors in the last session.
        final File stateFile = editorStatusPath.toFile();
        if (stateFile.exists())
          workbench
              .getDisplay()
              .syncExec(
                  new Runnable() {
                    public void run() {
                      SafeRunner.run(
                          new SafeRunnable() {
                            public void run() throws Exception {
                              IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
                              if (window != null) {
                                IWorkbenchPage page = window.getActivePage();
                                if (page != null) {
                                  openUnclosedMapLastSession(stateFile, page);
                                }
                              }
                            }
                          });
                    }
                  });
      }

      if (!hasOpenedEditors()) {
        showStartupDialog();
      }
    }
    monitor.worked(1);
  }