use of org.eclipse.debug.internal.ui.actions.LaunchShortcutAction in project dbeaver by dbeaver.
the class DebugUIInternals method createShortcutActions.
public static Map<IAction, String> createShortcutActions(Object[] selected, String mode, int accelerator) {
Map<IAction, String> result = new LinkedHashMap<IAction, String>();
if (selected == null) {
return result;
}
List<Object> selection = Arrays.asList(selected);
IEvaluationContext context = DebugUIPlugin.createEvaluationContext(selection);
context.setAllowPluginActivation(true);
// $NON-NLS-1$
context.addVariable("selection", selection);
List<LaunchShortcutExtension> allShortCuts = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchShortcuts();
List<LaunchShortcutExtension> filteredShortCuts = new ArrayList<LaunchShortcutExtension>();
Iterator<LaunchShortcutExtension> iter = allShortCuts.iterator();
while (iter.hasNext()) {
LaunchShortcutExtension ext = iter.next();
if (WorkbenchActivityHelper.filterItem(ext)) {
continue;
}
try {
Expression expr = ext.getContextualLaunchEnablementExpression();
if (ext.evalEnablementExpression(context, expr)) {
filteredShortCuts.add(ext);
}
} catch (CoreException e) {
IStatus status = new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), // $NON-NLS-1$
"Launch shortcut '" + ext.getId() + "' enablement expression caused exception. Shortcut was removed.", // $NON-NLS-1$
e);
DebugUIPlugin.log(status);
iter.remove();
}
}
for (LaunchShortcutExtension ext : filteredShortCuts) {
for (String supported : ext.getModes()) {
if (supported.equals(mode)) {
LaunchShortcutAction action = new LaunchShortcutAction(supported, ext);
// $NON-NLS-1$
action.setActionDefinitionId(ext.getId() + "." + supported);
String helpContextId = ext.getHelpContextId();
if (helpContextId != null) {
PlatformUI.getWorkbench().getHelpSystem().setHelp(action, helpContextId);
}
StringBuffer label = new StringBuffer();
if (accelerator >= 0 && accelerator < 10) {
// add the numerical accelerator
label.append('&');
label.append(accelerator);
label.append(' ');
}
String contextLabel = ext.getContextLabel(supported);
// replace default action label with context label if
// specified.
label.append((contextLabel != null) ? contextLabel : action.getText());
action.setText(label.toString());
String category = ext.getCategory();
result.put(action, category);
accelerator++;
}
}
}
return result;
}
use of org.eclipse.debug.internal.ui.actions.LaunchShortcutAction in project dbeaver by dbeaver.
the class DebugUIInternals method createShortcutActions.
public static Map<IAction, String> createShortcutActions(Object[] selected, String mode, int accelerator) {
Map<IAction, String> result = new LinkedHashMap<IAction, String>();
if (selected == null) {
return result;
}
List<Object> selection = Arrays.asList(selected);
IEvaluationContext context = DebugUIPlugin.createEvaluationContext(selection);
context.setAllowPluginActivation(true);
// $NON-NLS-1$
context.addVariable("selection", selection);
List<LaunchShortcutExtension> allShortCuts = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchShortcuts();
List<LaunchShortcutExtension> filteredShortCuts = new ArrayList<LaunchShortcutExtension>();
Iterator<LaunchShortcutExtension> iter = allShortCuts.iterator();
while (iter.hasNext()) {
LaunchShortcutExtension ext = iter.next();
if (WorkbenchActivityHelper.filterItem(ext)) {
continue;
}
try {
Expression expr = ext.getContextualLaunchEnablementExpression();
if (ext.evalEnablementExpression(context, expr)) {
filteredShortCuts.add(ext);
}
} catch (CoreException e) {
IStatus status = new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), // $NON-NLS-1$
"Launch shortcut '" + ext.getId() + "' enablement expression caused exception. Shortcut was removed.", // $NON-NLS-1$
e);
DebugUIPlugin.log(status);
iter.remove();
}
}
for (LaunchShortcutExtension ext : filteredShortCuts) {
for (String supported : ext.getModes()) {
if (supported.equals(mode)) {
LaunchShortcutAction action = new LaunchShortcutAction(supported, ext);
// $NON-NLS-1$
action.setActionDefinitionId(ext.getId() + "." + supported);
String helpContextId = ext.getHelpContextId();
if (helpContextId != null) {
PlatformUI.getWorkbench().getHelpSystem().setHelp(action, helpContextId);
}
StringBuffer label = new StringBuffer();
if (accelerator >= 0 && accelerator < 10) {
// add the numerical accelerator
label.append('&');
label.append(accelerator);
label.append(' ');
}
String contextLabel = ext.getContextLabel(supported);
// replace default action label with context label if
// specified.
label.append((contextLabel != null) ? contextLabel : action.getText());
action.setText(label.toString());
String category = ext.getCategory();
result.put(action, category);
accelerator++;
}
}
}
return result;
}
use of org.eclipse.debug.internal.ui.actions.LaunchShortcutAction in project dbeaver by serge-rider.
the class DebugUIInternals method createShortcutActions.
public static Map<IAction, String> createShortcutActions(Object[] selected, String mode, int accelerator) {
Map<IAction, String> result = new LinkedHashMap<IAction, String>();
if (selected == null) {
return result;
}
List<Object> selection = Arrays.asList(selected);
IEvaluationContext context = DebugUIPlugin.createEvaluationContext(selection);
context.setAllowPluginActivation(true);
// $NON-NLS-1$
context.addVariable("selection", selection);
List<LaunchShortcutExtension> allShortCuts = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchShortcuts();
List<LaunchShortcutExtension> filteredShortCuts = new ArrayList<LaunchShortcutExtension>();
Iterator<LaunchShortcutExtension> iter = allShortCuts.iterator();
while (iter.hasNext()) {
LaunchShortcutExtension ext = iter.next();
if (WorkbenchActivityHelper.filterItem(ext)) {
continue;
}
try {
Expression expr = ext.getContextualLaunchEnablementExpression();
if (ext.evalEnablementExpression(context, expr)) {
filteredShortCuts.add(ext);
}
} catch (CoreException e) {
IStatus status = new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), // $NON-NLS-1$
"Launch shortcut '" + ext.getId() + "' enablement expression caused exception. Shortcut was removed.", // $NON-NLS-1$
e);
DebugUIPlugin.log(status);
iter.remove();
}
}
for (LaunchShortcutExtension ext : filteredShortCuts) {
for (String supported : ext.getModes()) {
if (supported.equals(mode)) {
LaunchShortcutAction action = new LaunchShortcutAction(supported, ext);
// $NON-NLS-1$
action.setActionDefinitionId(ext.getId() + "." + supported);
String helpContextId = ext.getHelpContextId();
if (helpContextId != null) {
PlatformUI.getWorkbench().getHelpSystem().setHelp(action, helpContextId);
}
StringBuffer label = new StringBuffer();
if (accelerator >= 0 && accelerator < 10) {
// add the numerical accelerator
label.append('&');
label.append(accelerator);
label.append(' ');
}
String contextLabel = ext.getContextLabel(supported);
// replace default action label with context label if
// specified.
label.append((contextLabel != null) ? contextLabel : action.getText());
action.setText(label.toString());
String category = ext.getCategory();
result.put(action, category);
accelerator++;
}
}
}
return result;
}
Aggregations