PDA

View Full Version : Set Icon to StoreFilterField MenuItem



slynch
4 Feb 2010, 8:33 AM
Hi all,

I have added a StoreFilterField item to a menu:

Menu.add(StoreFilterField)

Similar to the MenuItem where you can apply an icon using the setIcon method, I would like to be able to apply an icon to my StoreFilterField menu item option.

Any possible solutions would be much appreciated.

Thanks,
Susan.

micgala
4 Feb 2010, 8:41 AM
Try to create a new class that extends StoreFilterField and implements IconSupport.

Not sure if that will work, thought.

You can give it a try.

Regards,
Michel.

slynch
4 Feb 2010, 9:17 AM
Hi,

I have put the following class together:

public class Filter extends StoreFilterField<Employee> implements IconSupport {

@Override
protected boolean doSelect(final Store<Employee> store, final Employee parent, final Employee record,
final String property, final String filter) {
final Employee emp = record;
final double salary = emp.getSalary();
if (salary < Integer.parseInt(filter)) {
return true;
}
return false;
}

@Override
public AbstractImagePrototype getIcon() {
return this.getIcon();
}

@Override
public void setIcon(final AbstractImagePrototype icon) {
this.setIcon(icon);
}

@Override
public void setIconStyle(final String icon) {
// TODO Auto-generated method stub

}

}

But get the following error:

17:09:41.252 [ERROR] [gwt20project] Uncaught exception escaped
java.lang.StackOverflowError: null
at com.corm.client.networktab.Filter.setIcon(Filter.java:47)

Arno.Nyhm
4 Feb 2010, 9:26 AM
you have the autogenerated methods not right implemented

and with "this.setIcon" you call the same method by yourself ... thats wrong.

best weay: you have to look how other classes in the sourcecode has implemented the IconSupport and make the same with your class.

micgala
5 Feb 2010, 5:03 AM
Exactly...

For example try to copy MenuItem implementations of it...

KeanuLee
2 Jun 2010, 10:41 PM
Hi,

I had implemented a class just like the above description,
and there is a icon next to my storefilterfield menu item.
However, it doesn't looks correct...
20759
Does someone get any idea?

Here is the class code


class ReportDataFilterField extends StoreFilterField<ReportData> implements IconSupport {

private String style;
protected AbstractImagePrototype icon;

public ReportDataFilterField() {
this.style = "x-menu-item";
}

@Override
protected boolean doSelect(Store<ReportData> store, ReportData parent,
ReportData record, String property, String filter) {
String data = record.get(String.valueOf(field));
if (data.contains(filter.toLowerCase())) {
return true;
}

return false;
}

@Override
public AbstractImagePrototype getIcon() {
return icon;
}

@Override
public void setIcon(AbstractImagePrototype icon) {
if (rendered)
{
El oldIcon = el().selectNode(style);
if (oldIcon != null) {
oldIcon.remove();
}
if (icon != null) {
Element e = icon.createElement().cast();
El.fly(e).addStyleName(style);
el().insertChild(e, 0);
}
}
this.icon = icon;
}

@Override
public void setIconStyle(String icon) {
setIcon(IconHelper.create(icon));
}

@Override
protected void afterRender() {
super.afterRender();
setIcon(icon);
}
}