public void dispose() {
unregsiterModelListeners();
}
private void registerModelListeners() {
additionHandler = new EventHandler() {
public void handleEvent(Event event) {
Object elementObj = event
.getProperty(UIEvents.EventTags.ELEMENT);
if (elementObj instanceof MApplication) {
Object newObj = event
.getProperty(UIEvents.EventTags.NEW_VALUE);
if (UIEvents.EventTypes.ADD.equals(event
.getProperty(UIEvents.EventTags.TYPE))
&& newObj instanceof MBindingTable) {
MBindingTable bt = (MBindingTable) newObj;
final Context bindingContext = contextManager
.getContext(bt.getBindingContext()
.getElementId());
final BindingTable table = new BindingTable(
bindingContext);
bindingTables.addTable(table);
List<MKeyBinding> bindings = bt.getBindings();
for (MKeyBinding binding : bindings) {
Binding keyBinding = createBinding(bindingContext,
binding.getCommand(),
binding.getParameters(),
binding.getKeySequence(), binding);
if (keyBinding != null) {
table.addBinding(keyBinding);
}
}
}
} else if (elementObj instanceof MBindingTable) {
Object newObj = event
.getProperty(UIEvents.EventTags.NEW_VALUE);
Object oldObj = event
.getProperty(UIEvents.EventTags.OLD_VALUE);
// adding a binding
if (UIEvents.EventTypes.ADD.equals(event
.getProperty(UIEvents.EventTags.TYPE))
&& newObj instanceof MKeyBinding) {
MKeyBinding binding = (MKeyBinding) newObj;
updateBinding(binding, true, elementObj);
}
// removing a binding
else if (UIEvents.EventTypes.REMOVE.equals(event
.getProperty(UIEvents.EventTags.TYPE))
&& oldObj instanceof MKeyBinding) {
MKeyBinding binding = (MKeyBinding) oldObj;
updateBinding(binding, false, elementObj);
}
} else if (elementObj instanceof MKeyBinding) {
MKeyBinding binding = (MKeyBinding) elementObj;
String attrName = (String) event
.getProperty(UIEvents.EventTags.ATTNAME);
if (UIEvents.EventTypes.SET.equals(event
.getProperty(UIEvents.EventTags.TYPE))) {
Object oldObj = event
.getProperty(UIEvents.EventTags.OLD_VALUE);
if (UIEvents.KeyBinding.COMMAND.equals(attrName)) {
MKeyBinding oldBinding = (MKeyBinding) EcoreUtil
.copy((EObject) binding);
oldBinding.setCommand((MCommand) oldObj);
updateBinding(oldBinding, false,
((EObject) binding).eContainer());
updateBinding(binding, true, null);
} else if (UIEvents.KeySequence.KEYSEQUENCE
.equals(attrName)) {
MKeyBinding oldBinding = (MKeyBinding) EcoreUtil
.copy((EObject) binding);
oldBinding.setKeySequence((String) oldObj);
updateBinding(oldBinding, false,
((EObject) binding).eContainer());
updateBinding(binding, true, null);
}
} else if (UIEvents.KeyBinding.PARAMETERS.equals(attrName)) {
if (UIEvents.EventTypes.ADD.equals(event
.getProperty(UIEvents.EventTags.TYPE))) {
Object newObj = event
.getProperty(UIEvents.EventTags.NEW_VALUE);
MKeyBinding oldBinding = (MKeyBinding) EcoreUtil
.copy((EObject) binding);
oldBinding.getParameters().remove(newObj);
updateBinding(oldBinding, false,
((EObject) binding).eContainer());
updateBinding(binding, true, null);
} else if (UIEvents.EventTypes.REMOVE.equals(event
.getProperty(UIEvents.EventTags.TYPE))) {
Object oldObj = event
.getProperty(UIEvents.EventTags.OLD_VALUE);
MKeyBinding oldBinding = (MKeyBinding) EcoreUtil
.copy((EObject) binding);
oldBinding.getParameters().add((MParameter) oldObj);
updateBinding(oldBinding, false,
((EObject) binding).eContainer());
updateBinding(binding, true, null);
}
}
// if we've updated the tags for an MKeyBinding
else if (UIEvents.ApplicationElement.TAGS.equals(attrName)) {
List<String> tags = binding.getTags();
// if we added a deleted tag to the MKeyBinding, then
// remove it from the runtime binding tables
if (tags.contains(EBindingService.DELETED_BINDING_TAG)) {
updateBinding(binding, false, elementObj);
}
// else we're adding the binding to the runtime tables
else {
updateBinding(binding, true, elementObj);
}
}
}
}
};
broker.subscribe(UIEvents.BindingTableContainer.TOPIC_BINDINGTABLES,
additionHandler);
broker.subscribe(UIEvents.BindingTable.TOPIC_BINDINGS, additionHandler);
broker.subscribe(UIEvents.KeyBinding.TOPIC_COMMAND, additionHandler);
broker.subscribe(UIEvents.KeyBinding.TOPIC_PARAMETERS, additionHandler);
broker.subscribe(UIEvents.KeySequence.TOPIC_KEYSEQUENCE,
additionHandler);
broker.subscribe(UIEvents.ApplicationElement.TOPIC_TAGS,
additionHandler);
contextHandler = new EventHandler() {
public void handleEvent(Event event) {
Object elementObj = event
.getProperty(UIEvents.EventTags.ELEMENT);
Object newObj = event.getProperty(UIEvents.EventTags.NEW_VALUE);
if (UIEvents.EventTypes.SET.equals(event