Intellihints Override to make arbitraty object possible

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

Intellihints Override to make arbitraty object possible

Postby fotakis » Sun Aug 16, 2009 3:13 am

Hello,

By overriding the updateHints to the following I was able to use my arbitrary object which was correctly passed
to the acceptHint method. Currently it seems that only Strings can be used

Code: Select all
@Override
          public boolean updateHints(Object context) {
              if (context == null) {
                  return false;
              }
              String s = context.toString();
              int substringLen = s.length();
              List<Object> possibleStrings = new ArrayList<Object>();
              for (Object o : getCompletionList()) {
                  String listEntry = (String) o.toString();
                  if (substringLen > listEntry.length())
                      continue;

                  if (!isCaseSensitive()) {
                      if (s.equalsIgnoreCase(listEntry.substring(0, substringLen)))
                          possibleStrings.add(o);
                  }
                  else if (listEntry.startsWith(s))
                      possibleStrings.add(o);
              }

              Object[] objects = possibleStrings.toArray();
              setListData(objects);
              return objects.length > 0;
          }


Best Regards,
Fotis
fotakis
 
Posts: 7
Joined: Wed Oct 10, 2007 4:35 am

Re: Intellihints Override to make arbitraty object possible

Postby JIDE Support » Sun Aug 16, 2009 5:23 pm

Thanks for the code. Should this code go to ListIntelliHint.java? Any reason you don't use the protected boolean compare(Object context, T o) method? This method has to be called since people might override it to do their own comparision.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Intellihints Override to make arbitraty object possible

Postby fotakis » Sun Aug 16, 2009 11:37 pm

JIDE Support wrote:Thanks for the code. Should this code go to ListIntelliHint.java?

Yes I am overriding the ListIntelliHint class.

Any reason you don't use the protected boolean compare(Object context, T o) method? This method has to be called since people might override it to do their own comparision.

Thanks,

Well I was actually looking to add a listener to do something when the user accepts a hint, other than setting the text on the text field. I couldn't find anything, so I noticed I could override acceptHint(Object o). The problem was that the original code in updateHints() only catered for Strings.class. So the object in acceptHint() was a String from the toString() method of my object. I needed the actual bean that I was using in the data to create the hints.

I hope this makes sense, please let me know if an alternative was possible.

Best Regards,
Fotis
fotakis
 
Posts: 7
Joined: Wed Oct 10, 2007 4:35 am

Re: Intellihints Override to make arbitraty object possible

Postby JIDE Support » Mon Aug 17, 2009 1:30 pm

I'm assuming that you are using JIDE ListDataIntelliHints class when you mentioned updateHints(). Please try override compare() to compare your object and the input string and you should be able to get correct result. In that method, I don't see any String class restriction there. You can also check the source code at the open source project: https://jide-oss.dev.java.net/

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Intellihints Override to make arbitraty object possible

Postby fotakis » Tue Aug 18, 2009 12:00 am

Hello again,

I seem to have confused you. Currently I don't have a specific problem since I have solved it by overriding updateHints. I mentioned it on this
forum so that if others have an issue they can use my workaround.

Furthermore why would I want to override compare? It has nothing to do with the issue that I have mentioned.

My problem began with the fact that the method acceptHint(Object o) was the only way to plug into the user selection. I noticed that if I passed
list List<CustomBean> to setCompletionList, the class of the Object in acceptHint was of String.class instead of CustomBean.class. Bellow I am
posting the original updateHints to point out the problems.

Code: Select all
    public boolean updateHints(Object context) {
        if (context == null) {
            return false;
        }
        String s = context.toString();
        int substringLen = s.length();
        List<String> possibleStrings = new ArrayList<String>(); //<-- Here is the firs issue, the possible strings should be Object not String
        for (Object o : getCompletionList()) {
            String listEntry = (String) o; //<-- Here is the second problem, instead of using toString() you assume that the completion list has String.class objects
            if (substringLen > listEntry.length())
                continue;

            if (!isCaseSensitive()) {
                if (s.equalsIgnoreCase(listEntry.substring(0, substringLen)))
                    possibleStrings.add(listEntry); //<-- Here you add a String.class to the internal model, not the actual object, so acceptHint(Object o) will receive a String
            }
            else if (listEntry.startsWith(s))
                possibleStrings.add(listEntry); //<-- Here you add a String.class to the internal model, not the actual object, so acceptHint(Object o) will receive a String
        }

        Object[] objects = possibleStrings.toArray(); //<-- Given the code above there is not reason why this shouldn't be a String[] array
        setListData(objects);
        return objects.length > 0;
    }


I hope I have made the issue clearer.

In my workaround I am also assuming that the bean has a toString() method, what would be correct, is to force a specific interface or something.

Best Regards,
Fotis
fotakis
 
Posts: 7
Joined: Wed Oct 10, 2007 4:35 am

Re: Intellihints Override to make arbitraty object possible

Postby JIDE Support » Tue Aug 18, 2009 3:18 pm

Thanks for detail explanation. We will review this part of code and try detach the String class requirement.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to Product Suggestions

Who is online

Users browsing this forum: Google [Bot] and 11 guests

cron