private void init() { getComponent().setWidth("200px"); getComponent().setAutocomplete(true); getComponent().setAutodrop(true); getComponent().addEventListener(Events.ON_BLUR, this); boolean zoom = false; if (lookup != null) { lookup.addListDataListener(this); // always need the empty item for zk to work correctly lookup.setMandatory(false); if ((lookup.getDisplayType() == DisplayType.List && Env.getContextAsInt(Env.getCtx(), "#AD_Role_ID") == 0) || lookup.getDisplayType() != DisplayType.List) { zoom = true; } // no need to refresh readonly lookup if (isReadWrite()) lookup.refresh(); refreshList(); actionRefresh(); } if (mField != null) { popupMenu = new WEditorPopupMenu(zoom, true, true); if (mField != null && mField.getGridTab() != null) { WFieldRecordInfo.addMenu(popupMenu); } getComponent().setContext(popupMenu.getId()); } }
private void refreshList() { if (getComponent().getItemCount() > 0) getComponent().removeAllItems(); if (isReadWrite()) { if (lookup != null) { int size = lookup.getSize(); boolean found = false; for (int i = 0; i < size; i++) { Object obj = lookup.getElementAt(i); if (obj instanceof KeyNamePair) { KeyNamePair lookupKNPair = (KeyNamePair) obj; getComponent().appendItem(lookupKNPair.getName(), lookupKNPair.getKey()); if (!found && oldValue != null && oldValue instanceof Integer && lookupKNPair.getKey() == (Integer) oldValue) { found = true; } } else if (obj instanceof ValueNamePair) { ValueNamePair lookupKNPair = (ValueNamePair) obj; getComponent().appendItem(lookupKNPair.getName(), lookupKNPair.getValue()); if (!found && oldValue != null && lookupKNPair.getValue().equals(oldValue.toString())) { found = true; } } } if (!found && oldValue != null) { NamePair pair = lookup.getDirect(oldValue, false, false); if (pair != null) { if (pair instanceof KeyNamePair) { int key = ((KeyNamePair) pair).getKey(); getComponent().appendItem(pair.getName(), key); } else if (pair instanceof ValueNamePair) { ValueNamePair valueNamePair = (ValueNamePair) pair; getComponent().appendItem(valueNamePair.getName(), valueNamePair.getValue()); } } } } } else { if (lookup != null) { NamePair pair = lookup.getDirect(oldValue, false, false); if (pair != null) { if (pair instanceof KeyNamePair) { int key = ((KeyNamePair) pair).getKey(); getComponent().appendItem(pair.getName(), key); } else if (pair instanceof ValueNamePair) { ValueNamePair valueNamePair = (ValueNamePair) pair; getComponent().appendItem(valueNamePair.getName(), valueNamePair.getValue()); } } } } getComponent().setValue(oldValue); }
public void actionRefresh() { if (lookup != null) { Object curValue = getValue(); if (isReadWrite()) { lookup.refresh(); lookup.fillComboBox(isMandatory(), true, true, false, false); } refreshList(); // if (curValue != null) // { setValue(curValue); // } } }
public void setValue(Object value) { if (value != null && (value instanceof Integer || value instanceof String)) { getComponent().setValue(value); if (!getComponent().isSelected(value)) { if (isReadWrite() && lookup != null) lookup.refresh(); Object curValue = oldValue; oldValue = value; refreshList(); // still not in list, reset to zero if (!getComponent().isSelected(value)) { if (value instanceof Integer && (Integer) value == 0) { getComponent().setValue(null); if (curValue == null) curValue = value; ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), curValue, null); super.fireValueChange(changeEvent); oldValue = null; } } } else { oldValue = value; } } else { getComponent().setValue(null); oldValue = value; } }
/** * Constructor for use if a grid field is unavailable * * @param lookup Store of selectable data * @param label column name (not displayed) * @param description description of component * @param mandatory whether a selection must be made * @param readonly whether or not the editor is read only * @param updateable whether the editor contents can be changed */ public WTableDirEditor( Lookup lookup, String label, String description, boolean mandatory, boolean readonly, boolean updateable) { super(new Combobox(), label, description, mandatory, readonly, updateable); if (lookup == null) { throw new IllegalArgumentException("Lookup cannot be null"); } this.lookup = lookup; super.setColumnName(lookup.getColumnName()); init(); }
@Override public void dynamicDisplay() { if ((lookup != null) && (!lookup.isValidated() || !lookup.isLoaded())) this.actionRefresh(); }