1 11 package org.eclipse.debug.internal.ui.views.variables.details; 12 13 14 import java.util.Iterator ; 15 import java.util.Set ; 16 17 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 18 import org.eclipse.jface.action.Action; 19 import org.eclipse.jface.action.ActionContributionItem; 20 import org.eclipse.jface.action.IAction; 21 import org.eclipse.jface.action.IMenuCreator; 22 import org.eclipse.swt.widgets.Control; 23 import org.eclipse.swt.widgets.Menu; 24 import org.eclipse.ui.PlatformUI; 25 26 32 public class AvailableDetailPanesAction extends Action implements IMenuCreator { 33 34 private Menu fMenu; 35 private Set fAvailableIDs; 36 private IDetailPaneContainer fDetailPaneContainer; 37 38 46 private class SetDetailPaneAction extends Action { 47 48 private String fPaneID; 49 private Set fPossiblePaneIDs; 50 51 public SetDetailPaneAction(String name, String paneID, Set possiblePaneIDs){ 52 super(name,AS_RADIO_BUTTON); 53 fPaneID = paneID; 54 fPossiblePaneIDs = possiblePaneIDs; 55 } 56 57 public void run() { 58 if (isChecked() && !fDetailPaneContainer.getCurrentPaneID().equals(fPaneID)){ 60 DetailPaneManager.getDefault().setPreferredDetailPane(fPossiblePaneIDs, fPaneID); 61 fDetailPaneContainer.refreshDetailPaneContents(); 62 } 63 } 64 65 } 66 67 public AvailableDetailPanesAction(IDetailPaneContainer detailPaneContainer) { 68 fDetailPaneContainer = detailPaneContainer; 69 setText(DetailMessages.AvailableDetailPanesAction_0); 70 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.VARIABLES_SELECT_DETAIL_PANE); 71 72 setEnabled(false); 73 setMenuCreator(this); 74 init(); 75 } 76 77 80 public void run() { 81 } 82 83 86 public void dispose() { 87 if (fMenu != null) { 88 fMenu.dispose(); 89 } 90 fAvailableIDs.clear(); 91 } 92 93 96 public Menu getMenu(Control parent) { 97 return null; 98 } 99 100 protected void addActionToMenu(Menu parent, IAction action) { 101 ActionContributionItem item= new ActionContributionItem(action); 102 item.fill(parent, -1); 103 } 104 105 108 public Menu getMenu(Menu parent) { 109 if (fMenu != null) { 110 fMenu.dispose(); 111 } 112 113 fMenu= new Menu(parent); 114 115 Iterator iter = fAvailableIDs.iterator(); 116 int i = 0; 117 while (iter.hasNext()) { 118 String currentID = (String ) iter.next(); 119 120 StringBuffer name = new StringBuffer (); 121 i++; 123 if (i < 9) { 124 name.append('&'); 125 name.append(i); 126 name.append(' '); 127 } 128 129 String typeName = DetailPaneManager.getDefault().getNameFromID(currentID); 130 if (typeName != null && typeName.length() > 0){ 131 name.append(typeName); 132 } else { 133 name.append(currentID); 134 } 135 136 IAction action = new SetDetailPaneAction(name.toString(),currentID,fAvailableIDs); 137 138 if (currentID.equals(fDetailPaneContainer.getCurrentPaneID())){ 139 action.setChecked(true); 140 } 141 142 addActionToMenu(fMenu, action); 143 } 144 145 return fMenu; 146 } 147 148 151 public void init() { 152 fAvailableIDs = DetailPaneManager.getDefault().getAvailablePaneIDs(fDetailPaneContainer.getCurrentSelection()); 153 if (fAvailableIDs.size() > 1){ 154 setEnabled(true); 155 } 156 } 157 } 158 | Popular Tags |