下面列出了怎么用org.eclipse.jface.action.LegacyActionTools的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Tests that the Top Level Elements
*/
@Test
public void testTopLevelElementsEntryNoDuplicates() {
IActionBars actionBars = projectExplorer.getViewSite().getActionBars();
IMenuManager menuManager = actionBars.getMenuManager();
int topLevelElementsEntriesFound = 0;
for (IContributionItem item : menuManager.getItems()) {
if (item instanceof MenuManager) {
String escapedMenuText = LegacyActionTools.removeMnemonics(((MenuManager) item).getMenuText());
if (escapedMenuText.equals("Top Level Elements")) {
topLevelElementsEntriesFound++;
}
}
}
assertEquals("There was more than one 'Top Level Elements' entry in the navigator action bar.",
topLevelElementsEntriesFound, 1);
}
/**
* Returns the menu contribution titles of the project navigator context menu.
*
* This only includes {@link ActionContributionItem}s and {@link MenuManager}s.
*/
private List<String> getContextMenuContributions() {
MenuManager menu = new MenuManager();
projectExplorer.getNavigatorActionService().fillContextMenu(menu);
return Arrays.asList(menu.getItems()).stream()
.map(i -> {
if (i instanceof ActionContributionItem) {
// use action name
return ((ActionContributionItem) i).getAction().getText();
} else if (i instanceof MenuManager) {
// use sub-menu title
return ((MenuManager) i).getMenuText();
} else {
// null for other types of contributions
return null;
}
})
.filter(t -> null != t)
// remove mnemonics (e.g. Close &Project -> Close Project))
.map(text -> LegacyActionTools.removeMnemonics(text))
.collect(Collectors.toList());
}
/**
* Stores the button and its mnemonic in {@link #fMnemonicButtonMap}.
*
* @param button
* button whose mnemonic has to be stored
*/
private void storeButtonWithMnemonicInMap(Button button) {
char mnemonic = LegacyActionTools.extractMnemonic(button.getText());
if (mnemonic != LegacyActionTools.MNEMONIC_NONE) {
fMnemonicButtonMap.put(new Character(Character.toLowerCase(mnemonic)), button);
}
}
/**
* Constructs a new instance of PreferenceTreeNode according to the parameters.
* <p>
* The <code>label</code> and the <code>key</code> must not be <code>null</code> if the node
* has a corresponding UI control.
* </p>
*
* @param label the label text
* @param key the key
* @param controlType the type of UI control.
* @param showAllChildren tells whether all children should be shown even if just one child
* matches the filter.
*/
public PreferenceTreeNode(String label, Key key, int controlType, boolean showAllChildren) {
super();
if (controlType != NONE && (label == null || key == null)) {
throw new IllegalArgumentException();
}
if (label == null) {
label= ""; //$NON-NLS-1$
}
fLabel= LegacyActionTools.removeMnemonics(label);
fKey= key;
fControlType= controlType;
fShowAllChildren= showAllChildren;
}
public static String removeMnemonicIndicator(String string) {
return LegacyActionTools.removeMnemonics(string);
}
/**
* Sets the given text and image to the label.
*
* @param text
* the new text or null
* @param image
* the new image
*/
private void doRefresh(String text, Image image) {
if ( text != null ) {
text = LegacyActionTools.escapeMnemonics(text);
}
label.setText(text);
label.setImage(image);
}
/**
* Returns the name of the described extension
* without mnemonic hint in order to be displayed
* in a message.
*
* @return Returns the name
*/
public String getDisplayName() {
return LegacyActionTools.removeMnemonics(fName);
}