1 11 package org.eclipse.debug.internal.ui.actions.breakpointGroups; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.debug.internal.ui.DebugPluginImages; 18 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 19 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointOrganizerManager; 20 import org.eclipse.debug.internal.ui.views.breakpoints.IBreakpointOrganizer; 21 import org.eclipse.debug.ui.IDebugUIConstants; 22 import org.eclipse.jface.action.ActionContributionItem; 23 import org.eclipse.jface.action.IAction; 24 import org.eclipse.jface.action.IMenuCreator; 25 import org.eclipse.jface.viewers.ISelection; 26 import org.eclipse.swt.events.MenuAdapter; 27 import org.eclipse.swt.events.MenuEvent; 28 import org.eclipse.swt.widgets.Control; 29 import org.eclipse.swt.widgets.Menu; 30 import org.eclipse.swt.widgets.MenuItem; 31 32 35 public class GroupBreakpointsByAction extends AbstractBreakpointsViewAction implements IMenuCreator { 36 37 private IAction fAction= null; 38 39 public GroupBreakpointsByAction() { 40 } 41 42 45 public void run(IAction action) { 46 } 47 48 51 public void dispose() { 52 } 53 54 57 public Menu getMenu(Control parent) { 58 return null; 60 } 61 62 65 public Menu getMenu(Menu parent) { 66 Menu menu = new Menu(parent); 67 menu.addMenuListener(new MenuAdapter() { 68 public void menuShown(MenuEvent e) { 69 Menu m = (Menu)e.widget; 70 MenuItem[] items = m.getItems(); 71 for (int i=0; i < items.length; i++) { 72 items[i].dispose(); 73 } 74 fillMenu(m); 75 } 76 }); 77 return menu; 78 } 79 80 83 private void fillMenu(Menu menu) { 84 IBreakpointOrganizer[] organizers = fView.getBreakpointOrganizers(); 86 boolean none = false; 87 boolean advanced = false; 88 IBreakpointOrganizer organizer = null; 89 if (organizers == null || organizers.length == 0) { 90 none = true; 91 } else if (organizers.length > 1) { 92 advanced = true; 93 } else { 94 organizer = organizers[0]; 95 } 96 97 int accel = 1; 98 IAction action = new GroupBreakpointsAction(null, fView); 100 addAccel(accel, action, BreakpointGroupMessages.GroupBreakpointsByAction_0); 101 accel++; 102 action.setImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_VIEW_BREAKPOINTS)); 103 action.setChecked(none); 104 ActionContributionItem item= new ActionContributionItem(action); 105 item.fill(menu, -1); 106 107 List actions = getActions(accel); 109 accel = accel + actions.size(); 110 Iterator actionIter = actions.iterator(); 111 while (actionIter.hasNext()) { 112 GroupBreakpointsAction bpAction = (GroupBreakpointsAction) actionIter.next(); 113 bpAction.setChecked(bpAction.getOrganizer().equals(organizer)); 114 item= new ActionContributionItem(bpAction); 115 item.fill(menu, -1); 116 } 117 118 AdvancedGroupBreakpointsByAction advancedAction = new AdvancedGroupBreakpointsByAction(fView); 120 addAccel(accel, advancedAction,BreakpointGroupMessages.GroupBreakpointsByAction_1); 121 advancedAction.setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_HIERARCHICAL)); 122 advancedAction.setChecked(advanced); 123 item= new ActionContributionItem(advancedAction); 124 item.fill(menu, -1); 125 } 126 127 public List getActions(int accel) { 128 List actions= new ArrayList (); 129 IBreakpointOrganizer[] organizers = BreakpointOrganizerManager.getDefault().getOrganizers(); 130 for (int i = 0; i < organizers.length; i++) { 131 IBreakpointOrganizer organizer = organizers[i]; 132 IAction action = new GroupBreakpointsAction(organizer, fView); 133 addAccel(accel, action, organizer.getLabel()); 134 accel++; 135 action.setImageDescriptor(organizer.getImageDescriptor()); 136 actions.add(action); 137 } 138 return actions; 139 } 140 141 private void addAccel(int accel, IAction action, String label) { 142 StringBuffer actionLabel= new StringBuffer (); 143 if (accel != 10) { 144 if (accel < 10) { 145 actionLabel.append('&'); 147 } 148 actionLabel.append(accel); 149 } else { 150 actionLabel.append("1&0"); } 152 accel++; 153 actionLabel.append(' '); 154 actionLabel.append(label); 155 action.setText(actionLabel.toString()); 156 } 157 158 161 public void selectionChanged(IAction action, ISelection selection) { 162 if (action != fAction) { 163 action.setMenuCreator(this); 164 fAction= action; 165 } 166 } 167 } 168 | Popular Tags |