Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » getDataByText() for SmartFields with CodeTypes
getDataByText() for SmartFields with CodeTypes [message #1440399] Wed, 08 October 2014 10:07 Go to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
We are using a number of LookupServices for DB based data. In all of those, we have implemented the getDataByText() methods in a way that match the typed search text using contains() instead of startsWith(). This is what our users wanted and are used to.

However, we also have a number of Smartfields that use CodeTypes. On those, the search only considers text that matches the start of the code type's text. Our users would like to have the same behaviour as with our LookupService based smartfields.

I have looked at the implementation for Smartfields that use code types instead of LookupServices. As far as I can see AbstractSmartField.setCodeTypeClass() uses CodeLookupCall.newInstanceByService() which in turn uses DefaultCodeLookupCallFactoryService.newInstance() to create a new lookup call based on CodeLookupCall. The "only match the start of the string" behaviour seems to come from which CodeLookupCall.getSearchPattern().

Am I right in assuming that the way to change this behaviour I could extend CodeLookupCall to MyCodeLookupCall which overwrites getSearchPattern and then I would need to register my own MyCodeLookupCallFactoryService with a higher priority than DefaultCodeLookupCallFactoryService in order for this to work?

Or is there an easier way?
Re: getDataByText() for SmartFields with CodeTypes [message #1440423 is a reply to message #1440399] Wed, 08 October 2014 10:47 Go to previous messageGo to next message
Judith Gull is currently offline Judith GullFriend
Messages: 75
Registered: February 2010
Member
Yes, you can do that.
You can also set IDesktop.setAutoPrefixWildcardForTextSearch(boolean), if this behaviour is for all searches.
Re: getDataByText() for SmartFields with CodeTypes [message #1440451 is a reply to message #1440423] Wed, 08 October 2014 11:32 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Thanks Judith. I'll have a look at the setAutoPrefixWildcard, but in the meantime I've alrady had a go at the approach outlined above.

There is one stumbling block: getSearchPattern() is static, so it can't be overwritten in a derived class. Is there a reason for it being static?

As a workaround I've overwritten getText() instead and am pre-pending a "*" to the text before returning it. I guess this could potentially have side effects, but at a quick glance I haven't found any. Here are the two classes I wrote:

public class ContainsCodeLookupCall extends CodeLookupCall {
  private static final long serialVersionUID = 1L;

  @SuppressWarnings("rawtypes")
  public ContainsCodeLookupCall(Class<? extends ICodeType> codeTypeClass) {
    super(codeTypeClass);
  }

  // sadly, this doesn't overwrite CodeLookupCall.getSearchPattern() so that its methods would call our version
//  public static Pattern getSearchPattern(String s) {
//    if (s == null) {
//      s = "";
//    }
//    s = s.toLowerCase();
//    if (!s.endsWith("*")) {
//      s = s + "*";
//    }
//    if (!s.startsWith("*")) {
//      s = "*" + s;
//    }
//    return Pattern.compile(StringUtility.toRegExPattern(s), Pattern.DOTALL);
//  }

  @Override
  public String getText() {
    String t = super.getText();
    if (t != null) {
      if (!t.startsWith("*")) {
        t = "*" + t;
      }
    }
    return t;
  }
}


public class ContainsCodeLookupCallFactoryService extends DefaultCodeLookupCallFactoryService {
  @SuppressWarnings("rawtypes")
  @Override
  public CodeLookupCall newInstance(Class<? extends ICodeType> codeTypeClass) {
    return new ContainsCodeLookupCall(codeTypeClass);
  }
}


Then, in the server and client plugins I have registered the above factory:
        <service
            factory="org.eclipse.scout.rt.server.services.ServerServiceFactory"
            class="ch.sbb.cisi.core.scout.shared.services.lookup.ContainsCodeLookupCallFactoryService"
            session="ch.sbb.cisi.core.scout.server.CoreServerSession">
        </service>

and
        <service
            factory="org.eclipse.scout.rt.client.services.ClientServiceFactory"
            class="ch.sbb.cisi.core.scout.shared.services.lookup.ContainsCodeLookupCallFactoryService"
            session="ch.sbb.cisi.core.scout.client.CoreClientSession">
        </service>


I haven't found out how to set priorities in order to make sure my implementation wins over the default one, but it seems to do so even without that.
Re: getDataByText() for SmartFields with CodeTypes [message #1440489 is a reply to message #1440423] Wed, 08 October 2014 12:37 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Hi Urs,

Judith Gull wrote on Wed, 08 October 2014 12:47
You can also set IDesktop.setAutoPrefixWildcardForTextSearch(boolean), if this behaviour is for all searches.


As Judith said, if for all your lookupcall, you want to match the entered text like a "contains" operation, and not a "start with" you can just add this line at the beginning of Desktop#execOpened():

@Override
protected void execOpened() throws ProcessingException {
  setAutoPrefixWildcardForTextSearch(true);

  //... rest of the method

If you debug, you will see that the client adds 2 wildcard char "*" before and after the String entered by the user. This will be true for all the SmartFields in your application (SmartFields working with CodeTypes or with LookupCalls).


Urs Beeli wrote on Wed, 08 October 2014 13:32
There is one stumbling block: getSearchPattern() is static, so it can't be overwritten in a derived class. Is there a reason for it being static?


In my opinion, no reason at all. You can open a bug to fix this.

The fix is trivial:
- Mark "public static Pattern getSearchPattern(String s)" as deprecated [will be removed with N-Release].
- Create a replacement method "protected Pattern createSearchPattern(String s)" as replacement (copy paste from the old one with another signature).
- Change the code to use your new method.

This is a small but useful step into making scout better. We need those small contributions in order to improve our code base.


Re: getDataByText() for SmartFields with CodeTypes [message #1441005 is a reply to message #1440489] Thu, 09 October 2014 05:57 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Jérémie, thanks for confirming there is no need for this method to be static.

I created a bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=446394

[Updated on: Thu, 09 October 2014 05:57]

Report message to a moderator

Re: getDataByText() for SmartFields with CodeTypes [message #1441046 is a reply to message #1441005] Thu, 09 October 2014 07:28 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Thanks for opening the bug.

I think this is a really good case, where you can contribute a gerrit change.

If you want to try, I can assist you with the setup (feel free to ask if something is not working).
Previous Topic:FileChooser in RAP
Next Topic:Calling Scout from Mobile Device
Goto Forum:
  


Current Time: Tue Apr 23 11:52:19 GMT 2024

Powered by FUDForum. Page generated in 0.03993 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top