Hi, i have a custom FormItem that extends CanvasItem. It works fine, but i just (started in 13?) seeing a warning in the logs:
I tried overrideing the visiblewidth method to see if i could do something, but it seems it doesn't get called at all.
Is there some simple way for me to make this go away?
class below:
Code:
WARN:sizing:isc_TrafficLightFormItem_1[flag]:getVisibleWidth() unable to determine width - returning zero
Is there some simple way for me to make this go away?
class below:
Code:
package com.nuba.client.layout.form; import com.google.gwt.core.client.GWT; import com.nuba.client.data.FilterItem; import com.nuba.common.CSConstants; import com.smartgwt.client.data.Criteria; import com.smartgwt.client.data.DataSourceField; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.fields.CanvasItem; import com.smartgwt.client.widgets.form.fields.events.ShowValueEvent; import com.smartgwt.client.widgets.form.fields.events.ShowValueHandler; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.Layout; import java.util.ArrayList; import java.util.List; /** * This is a custom form item that shows a traffic light that can be green, yellow or red. * * @author Mathias af Jochnick */ public class TrafficLightFormItem extends CanvasItem implements ShowValueHandler, FilterItem { TrafficLightImg[] icons; Layout layout; int latestValue = 0; final boolean multiOK; final boolean showNoFlagChoice; public TrafficLightFormItem(DataSourceField field) { this(field.getName(), field.getTitle(), true, false, false); } public TrafficLightFormItem(String name, String title, boolean shouldSaveValue, boolean multiOK, boolean showNoFlagChoice) { super(name, title); this.multiOK = multiOK; this.showNoFlagChoice = showNoFlagChoice; this.setShouldSaveValue(shouldSaveValue); addShowValueHandler(this); setAlign(Alignment.LEFT); } public Canvas createCanvas(){ layout = new HLayout(); layout.setMembersMargin(2); layout.setAutoHeight(); layout.setAutoWidth(); final TrafficLightImg green = new TrafficLightImg("1", "trafficlights/green.png", "trafficlights/green_selected.png", 16, 16); final TrafficLightImg yellow = new TrafficLightImg("2", "trafficlights/yellow.png", "trafficlights/yellow_selected.png", 16, 16); final TrafficLightImg red = new TrafficLightImg("3", "trafficlights/red.png", "trafficlights/red_selected.png", 16, 16); icons = new TrafficLightImg[showNoFlagChoice ? 4 : 3]; icons[0] = green; icons[1] = yellow; icons[2] = red; ClickHandler clicker = clickEvent -> { TrafficLightImg src = (TrafficLightImg) clickEvent.getSource(); src.setOn(!src.isOn()); if (src.isOn() && !multiOK) { for (TrafficLightImg icon : icons) { if (icon != src) { icon.setOn(false); } } } if(src.isOn()){ storeValue(src.getVal()); }else{ storeValue("0"); } }; green.addClickHandler(clicker); yellow.addClickHandler(clicker); red.addClickHandler(clicker); layout.addMember(green); layout.addMember(yellow); layout.addMember(red); if(showNoFlagChoice){ final TrafficLightImg clear = new TrafficLightImg("0", "trafficlights/clear.png", "trafficlights/clear_selected.png", 16, 16); icons[3] = clear; clear.addClickHandler(clicker); clear.setShowHover(true); layout.addMember(clear); } return layout; } @Override public void onShowValue(ShowValueEvent showValueEvent) { Integer val = (Integer)getValue(); if(val == null){ val = 0; } if(val == latestValue){ return; } latestValue = val; for (int i = 0; i < icons.length; i++) { icons[i].setOn(val-1 == i); } } public List<Integer> getSelection(){ List<Integer> selection = null; for (TrafficLightImg icon : icons) { if (icon.isOn()){ if(selection == null){ selection = new ArrayList<>(); } selection.add(Integer.parseInt(icon.getVal())); } } //Check if all are selected, and we have four icons. This is the same as "every combination", so just return null, and clear any selection. if(selection != null && selection.size() == icons.length && icons.length == 4){ for (TrafficLightImg icon : icons) { icon.setOn(false); } return null; } return selection; } @Override public void addFilterToCriteria(Criteria criteria) { List<Integer> sel = getSelection(); if (sel != null) { Integer[] selection = new Integer[sel.size()]; sel.toArray(selection); criteria.addCriteria(CSConstants.FIELD_FLAG, selection); } } public void clear(){ for (TrafficLightImg icon : icons) { icon.setOn(false); } } //DOES NOT GET CALLED? @Override public int getVisibleWidth() { GWT.log("getvisiblewidth"); return layout.getVisibleWidth(); } }
Comment