Page 1 of 1

Editor gains focus, while conref is edited

Posted: Thu Jul 11, 2013 12:57 pm
by SSC
Hello,

in our cms we allow the user to edit the attributes of a xml document directly. This means while the user is typing the new value for an attribute the typed letters are directly inserted.

The problem is when the user types a new value for the conref attribute, the editor gains the focus so that the user continues to write content in the xml document and therefore has to focus the Text Widget again each letter :(

Would it be possible to avoid that the editor gains the focus when it resolves a conref?

Currently as a workaround we turned off the feature that conrefs are resolved automatically in the preferences.

Best regards,

Simon

Re: Editor gains focus, while conref is edited

Posted: Thu Jul 11, 2013 2:07 pm
by Radu
Hi Simon,

I cannot quite reproduce the behavior on my side.
So you are referring to the Author mode, right?
Did you create some kind of custom Attributes view which uses our AuthorDocumentController API to set attributes to the current XML element?

Are you sure that the custom code you added for setting the attribute does not request focus in the document at some point?
Because I added some logging on our side and modifying the @conref attribute or any other attribute does not seem to set focus back to the Author mode control.
I had a view in which I added an action and that action used the AuthorDocumentController to modify an attribute in the document, the focus remained in the view after the modification occured.

The focus is requested in the Author mode control only when saving the content (CTRL-S).

Regards,
Radu

Re: Editor gains focus, while conref is edited

Posted: Thu Jul 11, 2013 6:04 pm
by SSC
Radu wrote: I cannot quite reproduce the behavior on my side.
So you are referring to the Author mode, right?
That´s right.
Radu wrote: Did you create some kind of custom Attributes view which uses our AuthorDocumentController API to set attributes to the current XML element?
Yes we have our own properties view for all properties in our CMS.
And in case the properties are the attributes of an AuthorNode in the Editor they are modified by the AuthorDocumentController API.
So your guess is right.
Radu wrote: Are you sure that the custom code you added for setting the attribute does not request focus in the document at some point?
Because of the fact that modifing conref attributes and all other attributes have the same implementation, it must be the conrefs fault that the focus is gained. When we modify other attributes the editor does not gain the focus.
Other reason is that when I turn off the preference for resolving conrefs everything works just fine.
So resolving conrefs and the focus problem must be somehow connected.

Here is the code, which I use to modify the attributes.

Code: Select all


 if (authorNode instanceof AuthorElement) {
AuthorElement authorElement = (AuthorElement) authorNode;
AuthorDocumentController documentController = getDocumentController();
if (documentController != null) {
AttrValue attrValue = new AttrValue(value.toString());
if (id instanceof CIAttribute) {
String attrName = ((CIAttribute) id).getName();
if ("".equals(value)) { //$NON-NLS-1$
documentController.removeAttribute(attrName,
authorElement);
} else {
documentController.setAttribute(attrName, attrValue,
authorElement);
}
}
if (id instanceof String) {
if ("".equals(value)) { //$NON-NLS-1$
documentController.removeAttribute(id.toString(),
authorElement);
} else {
AttrValue oldAttrValue = authorElement.getAttribute(id
.toString());
// check if the change is really new
if (!attrValue.equals(oldAttrValue)) {
documentController.setAttribute(id.toString(),
attrValue, authorElement);
}
}
}
}
}
Best regards

Simon

Re: Editor gains focus, while conref is edited

Posted: Fri Jul 12, 2013 12:36 pm
by Radu
Hi Simon,

Sorry, but I still cannot reproduce the problem on my side.
Here's what I did:

In our Elements view I added an extra text field which on every modification sets the @conref attribute on a certain element:

Code: Select all

    final Text tf = SWTUtils.createGridTextField(parent);
tf.addModifyListener(new ModifyListener() {

@Override
public void modifyText(ModifyEvent e) {
String value = tf.getText();
AuthorElement authorElement = currentElement;
String attrName = "conref";
if (authorElement != null) {
AuthorDocumentController documentController = viewport.getController();
if (documentController != null) {
AttrValue attrValue = new AttrValue(value.toString());
AttrValue oldAttrValue = authorElement.getAttribute(attrName);
// check if the change is really new
if (!attrValue.equals(oldAttrValue)) {
documentController.setAttribute(attrName, attrValue, authorElement);
}
}
}
}
});
I placed the caret in the Author mode on an element with an existing @conref and then I started typing in that text field. The focus remained in the text field as the content in the Author mode changed to show either the conref target or an error when the typed value was invalid. The focus never moved in the Author mode.

Could you also try to do a similar experiment on your side?
You could try to have a clean Eclipse workspace with an installed Oxygen plugin and have a custom plugin with a simple custom view which has a text field in which when typing the value gets sent to the controller.

If the focus does not move in the Author mode in such a simple example but it does in a more complex customization then something in your customization (maybe the styles filter or maybe some other listener) somehow triggers this focus to be lost.

Regards,
Radu