use of org.eclipse.jface.bindings.Binding 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.jface.bindings.Binding 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.jface.bindings.Binding in project dbeaver by serge-rider.
the class ActionUtils method findCommandDescription.
@Nullable
public static String findCommandDescription(String commandId, IServiceLocator serviceLocator, boolean shortcutOnly) {
String commandName = null;
String shortcut = null;
ICommandService commandService = serviceLocator.getService(ICommandService.class);
if (commandService != null) {
Command command = commandService.getCommand(commandId);
if (command != null && command.isDefined()) {
try {
commandName = command.getName();
} catch (NotDefinedException e) {
log.debug(e);
}
}
}
IBindingService bindingService = serviceLocator.getService(IBindingService.class);
if (bindingService != null) {
TriggerSequence sequence = null;
for (Binding b : bindingService.getBindings()) {
ParameterizedCommand parameterizedCommand = b.getParameterizedCommand();
if (parameterizedCommand != null && commandId.equals(parameterizedCommand.getId())) {
sequence = b.getTriggerSequence();
}
}
if (sequence == null) {
sequence = bindingService.getBestActiveBindingFor(commandId);
}
if (sequence != null) {
shortcut = sequence.format();
}
}
if (shortcutOnly) {
return shortcut == null ? "?" : shortcut;
}
if (shortcut == null) {
return commandName;
}
if (commandName == null) {
return shortcut;
}
return commandName + " (" + shortcut + ")";
}
use of org.eclipse.jface.bindings.Binding 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);
}
use of org.eclipse.jface.bindings.Binding in project translationstudio8 by heartsome.
the class ConflictModel2 method updateConflictsFor.
public void updateConflictsFor(BindingElement newValue, TriggerSequence oldTrigger, TriggerSequence newTrigger, boolean removal) {
Collection matches = (Collection) conflictsMap.get(newValue);
if (matches != null) {
if (newTrigger == null || removal) {
// we need to clear this match
matches.remove(newValue);
conflictsMap.remove(newValue);
if (matches == conflicts) {
controller.firePropertyChange(this, PROP_CONFLICTS_REMOVE, null, newValue);
}
if (matches.size() == 1) {
BindingElement tbe = (BindingElement) matches.iterator().next();
conflictsMap.remove(tbe);
tbe.setConflict(Boolean.FALSE);
if (matches == conflicts) {
setConflicts(null);
}
}
return;
} else if (oldTrigger != null && !newTrigger.equals(oldTrigger)) {
// we need to clear this match
matches.remove(newValue);
conflictsMap.remove(newValue);
if (matches == conflicts) {
controller.firePropertyChange(this, PROP_CONFLICTS_REMOVE, null, newValue);
}
if (matches.size() == 1) {
BindingElement tbe = (BindingElement) matches.iterator().next();
conflictsMap.remove(tbe);
tbe.setConflict(Boolean.FALSE);
if (matches == conflicts) {
setConflicts(null);
}
}
} else {
return;
}
}
if (newValue.getTrigger() == null || !(newValue.getModelObject() instanceof Binding)) {
return;
}
Binding binding = (Binding) newValue.getModelObject();
TriggerSequence trigger = binding.getTriggerSequence();
matches = (Collection) bindingManager.getActiveBindingsDisregardingContext().get(trigger);
ArrayList localConflicts = new ArrayList();
if (matches != null) {
localConflicts.add(newValue);
Iterator i = matches.iterator();
while (i.hasNext()) {
Binding b = (Binding) i.next();
// Bug #2740 快捷键--快捷键设置问题:修改验证冲突快捷键的方法,使用以下的方式,原来使用的是上面注释的方式
if (binding != b && !b.getParameterizedCommand().getCommand().toString().equals(binding.getParameterizedCommand().getCommand().toString())) {
Object element = bindingModel.getBindingToElement().get(b);
if (element != null) {
localConflicts.add(element);
}
}
}
}
if (localConflicts.size() > 1) {
// first find if it is already a conflict collection
Collection knownConflicts = null;
Iterator i = localConflicts.iterator();
while (i.hasNext() && knownConflicts == null) {
BindingElement tbe = (BindingElement) i.next();
knownConflicts = (Collection) conflictsMap.get(tbe);
}
if (knownConflicts != null) {
knownConflicts.add(newValue);
conflictsMap.put(newValue, knownConflicts);
newValue.setConflict(Boolean.TRUE);
if (knownConflicts == conflicts) {
controller.firePropertyChange(this, PROP_CONFLICTS_ADD, null, newValue);
} else if (newValue == getSelectedElement()) {
setConflicts(knownConflicts);
}
return;
}
boolean isSelected = false;
i = localConflicts.iterator();
while (i.hasNext()) {
BindingElement tbe = (BindingElement) i.next();
if (tbe != null) {
conflictsMap.put(tbe, localConflicts);
tbe.setConflict(Boolean.TRUE);
}
if (tbe == getSelectedElement()) {
isSelected = true;
}
}
if (isSelected) {
setConflicts(localConflicts);
}
}
}
Aggregations