Java tutorial
/******************************************************************************* * Copyright (c) 2009 Siemens AG * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Kai Tdter - initial API and implementation *******************************************************************************/ package com.siemens.ct.mp3m; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.ICoolBarManager; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.action.ToolBarContributionItem; import org.eclipse.jface.action.ToolBarManager; import org.eclipse.swt.SWT; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.actions.ContributionItemFactory; import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; public class ApplicationActionBarAdvisor extends ActionBarAdvisor { private IWorkbenchAction exitAction; private IWorkbenchAction aboutAction; private IWorkbenchAction helpAction; private IWorkbenchAction helpSearchAction; private IWorkbenchAction closeAction; private IWorkbenchAction closeAllAction; private IWorkbenchAction saveAction; private IWorkbenchAction saveAllAction; private IWorkbenchAction saveAsAction; private IWorkbenchAction newWindowAction; private IWorkbenchAction newEditorAction; private IWorkbenchAction preferencesAction; private IContributionItem viewsAction; public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { super(configurer); } @Override protected void makeActions(final IWorkbenchWindow window) { // Creates the actions and registers them. // Registering is needed to ensure that key bindings work. // The corresponding commands keybindings are defined in the plugin.xml // file. // Registering also provides automatic disposal of the actions when // the window is closed. closeAction = ActionFactory.CLOSE.create(window); register(closeAction); closeAllAction = ActionFactory.CLOSE_ALL.create(window); register(closeAllAction); saveAction = ActionFactory.SAVE.create(window); register(saveAction); saveAsAction = ActionFactory.SAVE_AS.create(window); register(saveAsAction); saveAllAction = ActionFactory.SAVE_ALL.create(window); register(saveAllAction); exitAction = ActionFactory.QUIT.create(window); register(exitAction); helpAction = ActionFactory.HELP_CONTENTS.create(window); register(helpAction); helpSearchAction = ActionFactory.HELP_SEARCH.create(window); register(helpSearchAction); aboutAction = ActionFactory.ABOUT.create(window); register(aboutAction); newWindowAction = ActionFactory.OPEN_NEW_WINDOW.create(window); register(newWindowAction); newEditorAction = ActionFactory.NEW_EDITOR.create(window); register(newEditorAction); preferencesAction = ActionFactory.PREFERENCES.create(window); register(preferencesAction); viewsAction = ContributionItemFactory.VIEWS_SHORTLIST.create(window); } @Override protected void fillMenuBar(IMenuManager menuBar) { MenuManager fileMenu = new MenuManager(Messages.getString("ApplicationActionBarAdvisor.file"), //$NON-NLS-1$ IWorkbenchActionConstants.M_FILE); MenuManager windowMenu = new MenuManager(Messages.getString("ApplicationActionBarAdvisor.window"), //$NON-NLS-1$ IWorkbenchActionConstants.M_WINDOW); MenuManager helpMenu = new MenuManager(Messages.getString("ApplicationActionBarAdvisor.help"), //$NON-NLS-1$ IWorkbenchActionConstants.M_HELP); menuBar.add(fileMenu); // Add a group marker indicating where action set menus will appear. menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); menuBar.add(windowMenu); menuBar.add(helpMenu); // File fileMenu.add(newWindowAction); fileMenu.add(new Separator()); fileMenu.add(closeAction); fileMenu.add(closeAllAction); fileMenu.add(new Separator()); fileMenu.add(saveAction); fileMenu.add(saveAsAction); fileMenu.add(saveAllAction); fileMenu.add(new Separator()); fileMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); fileMenu.add(new Separator()); fileMenu.add(exitAction); // Window windowMenu.add(newWindowAction); windowMenu.add(newEditorAction); windowMenu.add(new Separator()); MenuManager viewsMenu = new MenuManager(Messages.getString("ApplicationActionBarAdvisor.openViews"), "openViews"); viewsMenu.add(viewsAction); windowMenu.add(viewsMenu); windowMenu.add(new Separator()); windowMenu.add(preferencesAction); // Help helpMenu.add(helpAction); helpMenu.add(helpSearchAction); helpMenu.add(new Separator()); helpMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); helpMenu.add(new Separator()); helpMenu.add(aboutAction); } @Override protected void fillCoolBar(ICoolBarManager coolBar) { IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT); coolBar.add(new ToolBarContributionItem(toolbar, "main")); //$NON-NLS-1$ toolbar.add(saveAction); toolbar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); toolbar.add(new GroupMarker("mp3m.test")); } }