use of org.eclipse.core.commands.contexts.Context in project eclipse.platform.ui by eclipse-platform.
the class ContextProcessingAddon method defineContexts.
private void defineContexts(MBindingContext parent, MBindingContext current) {
if (current.getName() == null || current.getElementId() == null) {
// $NON-NLS-1$
logger.error("Binding context name or id is null for: " + current);
return;
}
Context context = contextManager.getContext(current.getElementId());
if (!context.isDefined()) {
String localizedName = LocalizationHelper.getLocalized(current.getName(), current, application.getContext());
String localizedDescriptor = LocalizationHelper.getLocalized(current.getDescription(), current, application.getContext());
context.define(localizedName, localizedDescriptor, parent == null ? null : parent.getElementId());
}
for (MBindingContext child : current.getChildren()) {
defineContexts(current, child);
}
}
use of org.eclipse.core.commands.contexts.Context in project eclipse.platform.ui by eclipse-platform.
the class ContextProcessingAddon method undefineContext.
private void undefineContext(MBindingContext current) {
Context context = contextManager.getContext(current.getElementId());
context.undefine();
}
use of org.eclipse.core.commands.contexts.Context in project eclipse.platform.ui by eclipse-platform.
the class ContextPersistence method readContextsFromRegistry.
/**
* Reads all of the command definitions from the commands extension point.
*
* @param configurationElements The configuration elements in the commands
* extension point; must not be
* <code>null</code>, but may be empty.
* @param configurationElementCount The number of configuration elements that
* are really in the array.
* @param contextManager The context manager to which the commands
* should be added; must not be
* <code>null</code>.
*/
private static void readContextsFromRegistry(final IConfigurationElement[] configurationElements, final int configurationElementCount, final ContextManager contextManager) {
final List<IStatus> warningsToLog = new ArrayList<>(1);
for (int i = 0; i < configurationElementCount; i++) {
final IConfigurationElement configurationElement = configurationElements[i];
// Read out the command identifier.
// $NON-NLS-1$
final String contextId = readRequired(configurationElement, ATT_ID, warningsToLog, "Contexts need an id");
if (contextId == null) {
continue;
}
// Read out the name.
final String name = readRequired(// $NON-NLS-1$
configurationElement, // $NON-NLS-1$
ATT_NAME, // $NON-NLS-1$
warningsToLog, // $NON-NLS-1$
"Contexts need a name", contextId);
if (name == null) {
continue;
}
// Read out the description.
final String description = readOptional(configurationElement, ATT_DESCRIPTION);
// Read out the parent id.
String parentId = configurationElement.getAttribute(ATT_PARENT_ID);
if ((parentId == null) || (parentId.isEmpty())) {
parentId = configurationElement.getAttribute(ATT_PARENT);
if ((parentId == null) || (parentId.isEmpty())) {
parentId = configurationElement.getAttribute(ATT_PARENT_SCOPE);
}
}
if ((parentId != null) && (parentId.isEmpty())) {
parentId = null;
}
final Context context = contextManager.getContext(contextId);
if (!context.isDefined()) {
context.define(name, description, parentId);
}
}
logWarnings(warningsToLog, // $NON-NLS-1$
"Warnings while parsing the contexts from the 'org.eclipse.ui.contexts', 'org.eclipse.ui.commands' and 'org.eclipse.ui.acceleratorScopes' extension points.");
}
use of org.eclipse.core.commands.contexts.Context in project eclipse.platform.ui by eclipse-platform.
the class BindingTableTests method testContextSetSibling.
@Test
public void testContextSetSibling() {
BindingTableManager manager = ContextInjectionFactory.make(BindingTableManager.class, workbenchContext);
ArrayList<Context> all = new ArrayList<>();
for (int i = 0; i < CONTEXTS.length; i += 3) {
Context context = contextManager.getContext(CONTEXTS[i]);
all.add(context);
}
ContextSet set = manager.createContextSet(all);
assertContextSet(set, ORDERED_IDS);
}
use of org.eclipse.core.commands.contexts.Context in project eclipse.platform.ui by eclipse-platform.
the class BindingTableTests method testContextSet.
@Test
public void testContextSet() {
BindingTableManager manager = ContextInjectionFactory.make(BindingTableManager.class, workbenchContext);
ArrayList<Context> window = new ArrayList<>();
Context winContext = contextManager.getContext(ID_WINDOW);
Context dawContext = contextManager.getContext(ID_DIALOG_AND_WINDOW);
window.add(winContext);
window.add(dawContext);
ContextSet windowSet = manager.createContextSet(window);
assertContextSet(windowSet, new String[] { ID_DIALOG_AND_WINDOW, ID_WINDOW });
ArrayList<Context> text = new ArrayList<>(window);
Context textContext = contextManager.getContext(ID_TEXT);
text.add(textContext);
ContextSet textSet = manager.createContextSet(text);
assertContextSet(textSet, new String[] { ID_DIALOG_AND_WINDOW, ID_WINDOW, ID_TEXT });
}
Aggregations