1 11 12 package org.eclipse.ui.internal.services; 13 14 import java.util.HashMap ; 15 import java.util.HashSet ; 16 import java.util.Map ; 17 import java.util.Set ; 18 19 import org.eclipse.jface.viewers.ISelection; 20 import org.eclipse.ui.AbstractSourceProvider; 21 import org.eclipse.ui.ISources; 22 23 36 public final class MenuSourceProvider extends AbstractSourceProvider { 37 38 41 private static final String [] PROVIDED_SOURCE_NAMES = new String [] { 42 ISources.ACTIVE_MENU_NAME, ISources.ACTIVE_MENU_SELECTION_NAME, 43 ISources.ACTIVE_MENU_EDITOR_INPUT_NAME }; 44 45 49 private Set menuIds = new HashSet (); 50 51 58 public final void addShowingMenus(final Set menuIds, 59 final ISelection localSelection, final ISelection localEditorInput) { 60 this.menuIds.addAll(menuIds); 61 if (DEBUG) { 62 logDebuggingInfo("Menu ids changed to " + this.menuIds); } 64 Map m = new HashMap (); 65 m.put(ISources.ACTIVE_MENU_NAME, this.menuIds); 66 if (selection != localSelection) { 67 selection = localSelection; 68 m.put(ISources.ACTIVE_MENU_SELECTION_NAME, selection); 69 } 70 if (input != localEditorInput) { 71 input = localEditorInput; 72 m.put(ISources.ACTIVE_MENU_EDITOR_INPUT_NAME, input); 73 } 74 75 fireSourceChanged(ISources.ACTIVE_MENU, m); 76 } 77 78 public final void dispose() { 79 menuIds.clear(); 80 selection = null; 81 input = null; 82 } 83 84 public final Map getCurrentState() { 85 final Map state = new HashMap (); 86 state.put(ISources.ACTIVE_MENU_NAME, menuIds); 87 state.put(ISources.ACTIVE_MENU_SELECTION_NAME, selection); 88 state.put(ISources.ACTIVE_MENU_EDITOR_INPUT_NAME, input); 89 return state; 90 } 91 92 public final String [] getProvidedSourceNames() { 93 return PROVIDED_SOURCE_NAMES; 94 } 95 96 103 public final void removeShowingMenus(final Set menuIds, 104 final ISelection localSelection, final ISelection localEditorInput) { 105 this.menuIds.removeAll(menuIds); 106 if (DEBUG) { 107 logDebuggingInfo("Menu ids changed to " + this.menuIds); } 109 Map m = new HashMap (); 110 m.put(ISources.ACTIVE_MENU_NAME, this.menuIds); 111 if (selection != localSelection) { 112 selection = localSelection; 113 m.put(ISources.ACTIVE_MENU_SELECTION_NAME, selection); 114 } 115 if (input != localEditorInput) { 116 input = localEditorInput; 117 m.put(ISources.ACTIVE_MENU_EDITOR_INPUT_NAME, input); 118 } 119 fireSourceChanged(ISources.ACTIVE_MENU, m); 120 } 121 122 private ISelection selection = null; 123 private ISelection input = null; 124 } 125 | Popular Tags |