[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] Re: How to enable Window menu/functionality

There are two main classes that have all the standard Eclipse actions.  They 
are ActionFactory and ContributionItemFactory.  Whatever standard actions 
you are looking for should be defined in one of these classes (statically, 
you don't have to instantiate).  Most actions are in ActionFactory, except 
for actions or items that are filled during runtime.  For example, the view 
list and perspective list is available in ContributionItemFactory, while the 
save and close actions are available in ActionFactory.

Regarding, how to easily add the same action to multiple places (menu, 
toolbar, etc), I suggest creating a sort of ActionManager or ActionBuilder 
class.  That way you let this class manage creating and maintaining the 
actions and then just grab the actions out to populate your menu or toolbar.

Below is code from my WorkbenchAdvisor that creates the Window menu.  It 
should be very similar to the Eclipse one with almost all the same items.

-Chris

(One note, I've changed all the perspective actions to use the word 
"dashboard".  The word "perspective" scares our users.  The word "dashboard" 
gets them excited.)

 private MenuManager createWindowMenu(IWorkbenchWindow window, 
IActionBarConfigurer configurer) {
  MenuManager menu = new MenuManager("Window", //$NON-NLS-1$
    IWorkbenchActionConstants.M_WINDOW);

  menu.add(ActionFactory.OPEN_NEW_WINDOW.create(window));

  menu.add(new Separator());
  MenuManager perspectiveMenu = new MenuManager("Open Dashboard", 
"openPerspective"); //$NON-NLS-1$ //$NON-NLS-2$
  IContributionItem perspectiveList = 
ContributionItemFactory.PERSPECTIVES_SHORTLIST.create(window);
  perspectiveMenu.add(perspectiveList);
  menu.add(perspectiveMenu);

  MenuManager viewMenu = new MenuManager("Show View");
  IContributionItem viewList = 
ContributionItemFactory.VIEWS_SHORTLIST.create(window);
  viewMenu.add(viewList);
  menu.add(viewMenu);

  menu.add(new Separator());

  savePerspectiveAction = ActionFactory.SAVE_PERSPECTIVE.create(window);
  savePerspectiveAction.setText("Save Dashboard As...");
  menu.add(savePerspectiveAction);
  configurer.registerGlobalAction(savePerspectiveAction);
  resetPerspectiveAction = ActionFactory.RESET_PERSPECTIVE.create(window);
  resetPerspectiveAction.setText("Reset Dashboard");
  menu.add(resetPerspectiveAction);
  configurer.registerGlobalAction(resetPerspectiveAction);

  closePerspAction = ActionFactory.CLOSE_PERSPECTIVE.create(window);
  closePerspAction.setText("Close Dashboard");
  menu.add(closePerspAction);
  configurer.registerGlobalAction(closePerspAction);
  closeAllPerspsAction = 
ActionFactory.CLOSE_ALL_PERSPECTIVES.create(window);
  closeAllPerspsAction.setText("Close All Dashboards");
  menu.add(closeAllPerspsAction);
  configurer.registerGlobalAction(closeAllPerspsAction);

  menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));

  IAction preferences = ActionFactory.PREFERENCES.create(window);
  menu.add(preferences);
  configurer.registerGlobalAction(preferences);

  menu.add(ContributionItemFactory.OPEN_WINDOWS.create(window));


  return menu;
 }



"Nils Meyer" <nils.meyer@xxxxxxxxx> wrote in message 
news:ck1jrv$h4f$1@xxxxxxxxxxxxxx
> Hi,
>
> I'm having a similar problem to Martin's. I got the thing work with the 
> menuitems but now I'm stuck with the toolbar. How can I easily add the 
> standard stuff like new, save and so on there? Is there perhaps a way to 
> get all the actions a editor usually reacts on (save, save as, save all, 
> close, close all) to the menu and toolbar in one step?
>
> Thanks
> Nils
>
> Schneider Alexander wrote:
>> sorry, last post was a accident:(
>>
>> ok, now I know what you mean! I will help you and show a code snipe which
>> add's the window item. I'am not sure how many experinace you have with
>> this platform. So ask again, when the example are not clears all 
>> questions.
>>
>> The following methods are part of my workbench advisor class definition. 
>> It was called from framework!
>>
>> /* (non-Javadoc)
>>  * @see org.eclipse.ui.application.WorkbenchAdvisor#fillActionBars
>>  * (org.eclipse.ui.IWorkbenchWindow,
>>  * org.eclipse.ui.application.IActionBarConfigurer, int)
>>  */
>> public void fillActionBars(IWorkbenchWindow window, IActionBarConfigurer 
>> configurer, int flags) {
>>     super.fillActionBars(window, configurer, flags);
>>     System.out.println("CBasisWorkbenchAdvisor.fillActionBars()");
>>     if((flags & FILL_MENU_BAR) != 0) {    initDefaultMenuBar(window, 
>> configurer);
>>     }
>>     if((flags & FILL_COOL_BAR) != 0);
>>     if((flags & FILL_STATUS_LINE) != 0);
>>     if((flags & FILL_PROXY) != 0);
>> }
>>
>> private void initDefaultMenuBar(IWorkbenchWindow window, 
>> IActionBarConfigurer configurer)
>> {
>>  System.out.println("CBasisWorkbenchAdvisor.initDefaultMenus()"); 
>> IMenuManager manager = configurer.getMenuManager();
>>  manager.add(createFileMenu(window));
>>  manager.add(createWindowMenu(window));
>>  manager.add(ActionFactory.OPEN_NEW_WINDOW.create(window));
>>  manager.add(createHelpMenu(window));
>> }
>>
>> You will see the creation OPEN_NEW_WINDOW in "initDefaultMenuBar" with
>> Help of the ActionFactory class. These class provice more standard 
>> menuitems. Have a look into help system for "retargetable" action. That 
>> is a set of
>> Action which you can reuse by platform. regards alexander
>>
>>>Martin Kersten wrote:
>>
>>
>>>>>I'am not sure what you mean.
>>
>>
>>>>Well actually I am looking for a way to add the Window menu item your
>>>>ordinary Eclipse IDE provides. You know the menu you are using
>>>>to open new windows, open the workbench preferences dialog, customize
>>>>your perspective and open new views.
>>
>>
>>>>Thanks,
>>
>>
>>>>Martin (Kersten)
>>
>>
>>>>>Let's try to help you with some examples
>>>>> - ActionFactory.OPEN_NEW_WINDOW.create(window) // creates standards
>>>>>actions
>>>>> - Extension point org.eclipse.ui.popupMenus
>>>>> - Extension point org.eclipse.ui.actionSets
>>>>> - ....
>>>>>
>>>>>regards
>>>>>
>>>>>alexander
>>>>>
>>>>> ActionFactory.FILE
>>>>>
>>>>>Martin Kersten wrote:
>>>>>
>>>>>
>>>>>>Hi there,
>>>>>
>>>>>>   I am writing a RCP and I am wondering how I can add the
>>
>> functionality
>>
>>>>>>the normal Window-menu adds within the normal Eclipse IDE.
>>>>>
>>>>>>You know having a window item where to add/save perspectives, set
>>>>>>properties and everything... .
>>>>>
>>>>>
>>>>>>Thanks,
>>>>>
>>>>>>Martin (Kersten)
>>>>>
>>>>>
>>