use of org.eclipse.jface.bindings.Binding in project translationstudio8 by heartsome.
the class KeysPreferencePage method applyData.
public void applyData(Object data) {
// }
if (data instanceof ModelElement) {
model.setSelectedElement((ModelElement) data);
}
if (data instanceof Binding && fFilteredTree != null) {
BindingElement be = (BindingElement) model.getBindingToElement().get(data);
fFilteredTree.getViewer().setSelection(new StructuredSelection(be), true);
}
if (data instanceof ParameterizedCommand) {
Map commandToElement = model.getCommandToElement();
BindingElement be = (BindingElement) commandToElement.get(data);
if (be != null) {
fFilteredTree.getViewer().setSelection(new StructuredSelection(be), true);
}
}
}
use of org.eclipse.jface.bindings.Binding in project translationstudio8 by heartsome.
the class BindingModel2 method refresh.
/**
* Refreshes the binding model to be in sync with the {@link BindingManager}.
* @param contextModel
*/
public void refresh(ContextModel contextModel, List<String> lstRemove) {
Set cmdsForBindings = new HashSet();
Iterator<BindingElement> iterator = bindingElements.iterator();
while (iterator.hasNext()) {
BindingElement bindingElement = iterator.next();
if (lstRemove.contains(bindingElement.getId())) {
iterator.remove();
}
}
Iterator<Entry<Binding, BindingElement>> it = bindingToElement.entrySet().iterator();
while (it.hasNext()) {
Entry<Binding, BindingElement> entry = (Entry<Binding, BindingElement>) it.next();
if (lstRemove.contains(entry.getValue().getId())) {
it.remove();
}
}
Collection activeManagerBindings = bindingManager.getActiveBindingsDisregardingContextFlat();
// add any bindings that we don't already have.
Iterator i = activeManagerBindings.iterator();
Map<String, BindingElement> temp = new HashMap<String, BindingElement>();
while (i.hasNext()) {
KeyBinding b = (KeyBinding) i.next();
ParameterizedCommand parameterizedCommand = b.getParameterizedCommand();
cmdsForBindings.add(parameterizedCommand);
if (!bindingToElement.containsKey(b)) {
BindingElement be = new BindingElement(controller);
be.init(b, contextModel);
be.setParent(this);
bindingElements.add(be);
bindingToElement.put(b, be);
controller.firePropertyChange(this, PROP_BINDING_ADD, null, be);
// 去掉添加重复的情况
temp.put(parameterizedCommand.getId(), be);
if (commandToElement.containsKey(parameterizedCommand) && be.getUserDelta().intValue() == Binding.SYSTEM) {
Object remove = commandToElement.remove(parameterizedCommand);
bindingElements.remove(remove);
controller.firePropertyChange(this, PROP_BINDING_REMOVE, null, remove);
}
}
}
// 修改在恢复默认设置,出现两个相同的选项
i = bindingElements.iterator();
while (i.hasNext()) {
BindingElement be = (BindingElement) i.next();
Object obj = be.getModelObject();
if (temp.containsKey(be.getId())) {
if (!(obj instanceof Binding)) {
System.out.println("remove");
i.remove();
controller.firePropertyChange(this, PROP_BINDING_REMOVE, null, be);
}
}
}
// remove bindings that shouldn't be there
i = bindingElements.iterator();
while (i.hasNext()) {
BindingElement be = (BindingElement) i.next();
Object obj = be.getModelObject();
if (obj instanceof Binding) {
Binding b = (Binding) obj;
if (!activeManagerBindings.contains(b) || lstRemove.contains(be.getId())) {
be.fill(b.getParameterizedCommand());
bindingToElement.remove(b);
i.remove();
controller.firePropertyChange(this, PROP_BINDING_REMOVE, null, be);
}
} else {
cmdsForBindings.add(obj);
}
}
// If we removed the last binding for a parameterized command,
// put back the CMD
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);
if (lstRemove.contains(be.getId())) {
continue;
}
bindingElements.add(be);
commandToElement.put(cmd, be);
controller.firePropertyChange(this, PROP_BINDING_ADD, null, be);
}
}
}
use of org.eclipse.jface.bindings.Binding in project translationstudio8 by heartsome.
the class KeyController2 method updateTrigger.
/**
* @param activeBinding
* @param oldSequence
* @param keySequence
*/
public void updateTrigger(BindingElement activeBinding, KeySequence oldSequence, KeySequence keySequence) {
if (activeBinding == null) {
return;
}
Object obj = activeBinding.getModelObject();
if (obj instanceof KeyBinding) {
KeyBinding keyBinding = (KeyBinding) obj;
if (!keyBinding.getKeySequence().equals(keySequence)) {
if (keySequence != null && !keySequence.isEmpty()) {
String activeSchemeId = fSchemeModel.getSelectedElement().getId();
ModelElement selectedElement = contextModel.getSelectedElement();
String activeContextId = selectedElement == null ? IContextService.CONTEXT_ID_WINDOW : selectedElement.getId();
final KeyBinding binding = new KeyBinding(keySequence, keyBinding.getParameterizedCommand(), activeSchemeId, activeContextId, null, null, null, Binding.USER);
Map bindingToElement = bindingModel.getBindingToElement();
bindingToElement.remove(keyBinding);
if (keyBinding.getType() == Binding.USER) {
fBindingManager.removeBinding(keyBinding);
} else {
fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding.getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER));
}
fBindingManager.addBinding(binding);
activeBinding.fill(binding, contextModel);
bindingModel.getBindingToElement().put(binding, activeBinding);
// Remove binding for any system conflicts
Object[] keys = bindingToElement.keySet().toArray();
for (int i = 0; i < keys.length; i++) {
Binding bindingKey = (Binding) keys[i];
if (oldSequence.equals(bindingKey.getTriggerSequence()) && bindingKey.getType() == Binding.SYSTEM) {
BindingElement be = (BindingElement) bindingToElement.get(bindingKey);
bindingModel.remove(be);
}
}
bindingModel.setSelectedElement(activeBinding);
} else {
bindingModel.getBindingToElement().remove(keyBinding);
if (keyBinding.getType() == Binding.USER) {
fBindingManager.removeBinding(keyBinding);
} else {
fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding.getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER));
}
activeBinding.fill(keyBinding.getParameterizedCommand());
}
}
} else if (obj instanceof ParameterizedCommand) {
ParameterizedCommand cmd = (ParameterizedCommand) obj;
if (keySequence != null && !keySequence.isEmpty()) {
String activeSchemeId = fSchemeModel.getSelectedElement().getId();
ModelElement selectedElement = contextModel.getSelectedElement();
String activeContextId = selectedElement == null ? IContextService.CONTEXT_ID_WINDOW : selectedElement.getId();
final KeyBinding binding = new KeyBinding(keySequence, cmd, activeSchemeId, activeContextId, null, null, null, Binding.USER);
fBindingManager.addBinding(binding);
activeBinding.fill(binding, contextModel);
bindingModel.getBindingToElement().put(binding, activeBinding);
}
}
}
use of org.eclipse.jface.bindings.Binding 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.jface.bindings.Binding 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);
}
Aggregations