use of org.eclipse.core.commands.ParameterizedCommand in project translationstudio8 by heartsome.
the class KeyController2 method setDefaultBindings.
/**
* Sets the bindings to default.
* @param bindingService
* @throws NotDefinedException
*/
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
// Fix the scheme in the local changes.
final String defaultSchemeId = bindingService.getDefaultSchemeId();
final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
try {
fBindingManager.setActiveScheme(defaultScheme);
} catch (final NotDefinedException e) {
// At least we tried....
}
// Restore any User defined bindings
Binding[] bindings = fBindingManager.getBindings();
for (int i = 0; i < bindings.length; i++) {
ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
String commandId = null;
if (pCommand != null) {
commandId = pCommand.getCommand().getId();
}
if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
fBindingManager.removeBinding(bindings[i]);
}
}
bindingModel.refresh(contextModel, lstRemove);
saveBindings(bindingService);
}
use of org.eclipse.core.commands.ParameterizedCommand in project translationstudio8 by heartsome.
the class BindingModel2 method copy.
/**
* Makes a copy of the
* @param element
*/
public void copy(BindingElement element) {
if (element == null || !(element.getModelObject() instanceof Binding)) {
return;
}
BindingElement be = new BindingElement(controller);
ParameterizedCommand parameterizedCommand = ((Binding) element.getModelObject()).getParameterizedCommand();
be.init(parameterizedCommand);
be.setParent(this);
bindingElements.add(be);
commandToElement.put(parameterizedCommand, be);
controller.firePropertyChange(this, PROP_BINDING_ADD, null, be);
setSelectedElement(be);
}
use of org.eclipse.core.commands.ParameterizedCommand in project translationstudio8 by heartsome.
the class BindingModel2 method restoreBinding.
/**
* Restores the specified BindingElement. A refresh should be performed afterwards. The refresh may be done after
* several elements have been restored.
* @param element
*/
public void restoreBinding(BindingElement element) {
if (element == null) {
return;
}
Object modelObject = element.getModelObject();
ParameterizedCommand cmd = null;
if (modelObject instanceof ParameterizedCommand) {
cmd = (ParameterizedCommand) modelObject;
TriggerSequence trigger = bindingManager.getBestActiveBindingFor(cmd.getId());
Binding binding = bindingManager.getPerfectMatch(trigger);
if (binding != null && binding.getType() == Binding.SYSTEM) {
return;
}
} else if (modelObject instanceof KeyBinding) {
cmd = ((KeyBinding) modelObject).getParameterizedCommand();
}
// Remove any USER bindings
Binding[] managerBindings = bindingManager.getBindings();
ArrayList systemBindings = new ArrayList();
ArrayList removalBindings = new ArrayList();
for (int i = 0; i < managerBindings.length; i++) {
if (managerBindings[i].getParameterizedCommand() == null) {
removalBindings.add(managerBindings[i]);
} else if (managerBindings[i].getParameterizedCommand().equals(cmd)) {
if (managerBindings[i].getType() == Binding.USER) {
bindingManager.removeBinding(managerBindings[i]);
} else if (managerBindings[i].getType() == Binding.SYSTEM) {
systemBindings.add(managerBindings[i]);
}
}
}
// Clear the USER bindings for parameterized commands
Iterator i = systemBindings.iterator();
while (i.hasNext()) {
Binding sys = (Binding) i.next();
Iterator j = removalBindings.iterator();
while (j.hasNext()) {
Binding del = (Binding) j.next();
if (deletes(del, sys) && del.getType() == Binding.USER) {
bindingManager.removeBinding(del);
}
}
}
setSelectedElement(null);
bindingElements.remove(element);
bindingToElement.remove(modelObject);
commandToElement.remove(modelObject);
controller.firePropertyChange(this, PROP_BINDING_REMOVE, null, element);
}
use of org.eclipse.core.commands.ParameterizedCommand in project translationstudio8 by heartsome.
the class BindingModel2 method init.
/**
* The initialization only.
* @param locator
* @param manager
* @param model
*/
public void init(IServiceLocator locator, BindingManager manager, ContextModel model) {
Set cmdsForBindings = new HashSet();
bindingToElement = new HashMap();
commandToElement = new HashMap();
bindingElements = new HashSet();
bindingManager = manager;
Iterator i = manager.getActiveBindingsDisregardingContextFlat().iterator();
while (i.hasNext()) {
Binding b = (Binding) i.next();
BindingElement be = new BindingElement(controller);
be.init(b, model);
be.setParent(this);
bindingElements.add(be);
bindingToElement.put(b, be);
cmdsForBindings.add(b.getParameterizedCommand());
}
ICommandService commandService = (ICommandService) locator.getService(ICommandService.class);
final Collection commandIds = commandService.getDefinedCommandIds();
allParameterizedCommands = new HashSet();
final Iterator commandIdItr = commandIds.iterator();
while (commandIdItr.hasNext()) {
final String currentCommandId = (String) commandIdItr.next();
final Command currentCommand = commandService.getCommand(currentCommandId);
try {
allParameterizedCommands.addAll(ParameterizedCommand.generateCombinations(currentCommand));
} catch (final NotDefinedException e) {
// It is safe to just ignore undefined commands.
}
}
i = allParameterizedCommands.iterator();
while (i.hasNext()) {
ParameterizedCommand cmd = (ParameterizedCommand) i.next();
if (!cmdsForBindings.contains(cmd)) {
BindingElement be = new BindingElement(controller);
be.init(cmd);
be.setParent(this);
bindingElements.add(be);
commandToElement.put(cmd, be);
}
}
}
use of org.eclipse.core.commands.ParameterizedCommand in project translationstudio8 by heartsome.
the class BindingModel2 method remove.
/**
* Removes the <code>bindingElement</code> binding.
* @param bindingElement
*/
public void remove(BindingElement bindingElement) {
if (bindingElement == null || !(bindingElement.getModelObject() instanceof Binding)) {
return;
}
KeyBinding keyBinding = (KeyBinding) bindingElement.getModelObject();
if (keyBinding.getType() == Binding.USER) {
bindingManager.removeBinding(keyBinding);
} else {
KeySequence keySequence = keyBinding.getKeySequence();
// Add the delete binding
bindingManager.addBinding(new KeyBinding(keySequence, null, keyBinding.getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER));
// Unbind any conflicts affected by the delete binding
ConflictModel conflictModel = controller.getConflictModel();
conflictModel.updateConflictsFor(bindingElement);
Collection conflictsList = conflictModel.getConflicts();
if (conflictsList != null) {
Object[] conflicts = conflictsList.toArray();
for (int i = 0; i < conflicts.length; i++) {
BindingElement be = (BindingElement) conflicts[i];
if (be == bindingElement) {
continue;
}
Object modelObject = be.getModelObject();
if (modelObject instanceof Binding) {
Binding binding = (Binding) modelObject;
if (binding.getType() != Binding.SYSTEM) {
continue;
}
ParameterizedCommand pCommand = binding.getParameterizedCommand();
be.fill(pCommand);
commandToElement.put(pCommand, be);
}
}
}
}
ParameterizedCommand parameterizedCommand = keyBinding.getParameterizedCommand();
bindingElement.fill(parameterizedCommand);
commandToElement.put(parameterizedCommand, bindingElement);
controller.firePropertyChange(this, PROP_CONFLICT_ELEMENT_MAP, null, bindingElement);
}
Aggregations