1 11 package org.eclipse.jdt.internal.ui.compare; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.jface.action.IMenuManager; 16 import org.eclipse.jface.action.MenuManager; 17 18 import org.eclipse.ui.actions.ActionGroup; 19 import org.eclipse.ui.PlatformUI; 20 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 21 import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; 22 23 public class LocalHistoryActionGroup extends ActionGroup { 24 25 private String fGroupName; 26 27 private JavaHistoryAction fCompareWith; 28 private JavaHistoryAction fReplaceWithPrevious; 29 private JavaHistoryAction fReplaceWith; 30 private JavaHistoryAction fAddFrom; 31 32 public LocalHistoryActionGroup(CompilationUnitEditor editor, String groupName) { 33 Assert.isNotNull(groupName); 34 fGroupName= groupName; 35 fCompareWith= new JavaCompareWithEditionAction(); 36 fCompareWith.init(editor, 37 CompareMessages.LocalHistoryActionGroup_action_compare_with, 38 CompareMessages.LocalHistoryActionGroup_action_compare_with_title, 39 CompareMessages.LocalHistoryActionGroup_action_compare_with_message); 40 PlatformUI.getWorkbench().getHelpSystem().setHelp(fCompareWith, IJavaHelpContextIds.COMPARE_WITH_HISTORY_ACTION); 41 42 fReplaceWithPrevious= new JavaReplaceWithPreviousEditionAction(); 43 fReplaceWithPrevious.init(editor, 44 CompareMessages.LocalHistoryActionGroup_action_replace_with_previous, 45 CompareMessages.LocalHistoryActionGroup_action_replace_with_previous_title, 46 CompareMessages.LocalHistoryActionGroup_action_replace_with_previous_message); 47 PlatformUI.getWorkbench().getHelpSystem().setHelp(fReplaceWithPrevious, IJavaHelpContextIds.REPLACE_WITH_PREVIOUS_FROM_HISTORY_ACTION); 48 49 fReplaceWith= new JavaReplaceWithEditionAction(); 50 fReplaceWith.init(editor, 51 CompareMessages.LocalHistoryActionGroup_action_replace_with, 52 CompareMessages.LocalHistoryActionGroup_action_replace_with_title, 53 CompareMessages.LocalHistoryActionGroup_action_replace_with_message); 54 PlatformUI.getWorkbench().getHelpSystem().setHelp(fReplaceWith, IJavaHelpContextIds.REPLACE_WITH_HISTORY_ACTION); 55 56 fAddFrom= new JavaAddElementFromHistory(); 57 fAddFrom.init(editor, 58 CompareMessages.LocalHistoryActionGroup_action_add, 59 CompareMessages.LocalHistoryActionGroup_action_add_title, 60 CompareMessages.LocalHistoryActionGroup_action_add_message); 61 PlatformUI.getWorkbench().getHelpSystem().setHelp(fAddFrom, IJavaHelpContextIds.ADD_FROM_HISTORY_ACTION); 62 } 63 64 public void fillContextMenu(IMenuManager menu) { 65 super.fillContextMenu(menu); 66 IMenuManager localMenu= new MenuManager(CompareMessages.LocalHistoryActionGroup_menu_local_history); 67 int added= 0; 68 added+= addAction(localMenu, fCompareWith); 69 added+= addAction(localMenu, fReplaceWithPrevious); 70 added+= addAction(localMenu, fReplaceWith); 71 added+= addAction(localMenu, fAddFrom); 72 if (added > 0) 73 menu.appendToGroup(fGroupName, localMenu); 74 } 75 76 private int addAction(IMenuManager menu, JavaHistoryAction action) { 77 action.update(); 78 if (action.isEnabled()) { 79 menu.add(action); 80 return 1; 81 } 82 return 0; 83 } 84 } 85 | Popular Tags |