@Override public void valueChanged(String key, Object oldValue, Object newValue) { super.valueChanged(key, oldValue, newValue); // if(isComputeField){//如果是表达式字段,需要重新计算 presentValue(); // } }
@Override protected void createControl(Composite parent) { isComputeField = field.isComputeField(); String fieldType = field.getType(); // 类型检查 并且根据数据类型设置文本的对齐方式 int style; if (isComputeField) { style = SWT.NONE; } else { style = SWT.BORDER; } if (field.isPassword()) { style = style | SWT.PASSWORD; } if ((IFieldTypeConstants.FIELD_INTEGER.equals(fieldType)) || (IFieldTypeConstants.FIELD_DOUBLE.equals(fieldType))) { style = style | SWT.RIGHT; } else if (IFieldTypeConstants.FIELD_STRING.equals(fieldType)) { } else { Assert.isLegal(false, TYPE_MISMATCH + field.getId()); } control = new Text(parent, style); GridData td = getControlLayoutData(); control.setLayoutData(td); if (!isComputeField) { // 设置字数限制 int textLimit = field.getTextLimit(); if (textLimit != 0) { control.setTextLimit(textLimit); } // 设置如何设置值 control.addFocusListener( new FocusListener() { @Override public void focusLost(FocusEvent event) { // 如果只读,不做任何变化 if (isEditable) { updateDataValueAndPresent(); } } @Override public void focusGained(FocusEvent event) { if (isEditable && isValuePresented()) { String editableValue = getValue() == null ? "" : getValue().toString(); control.setText(editableValue); } } }); // 设置字数控制提示 if ((textLimit != 0) && (field.isEditable()) && (!isValuePresented()) && (field.getType().equals(IFieldTypeConstants.FIELD_STRING))) { new TextLimitToolTipsControl(this); } // 设置编辑提示 String textMessage = field.getTextMessage(); if (!Util.isNullOrEmptyString(textMessage)) { control.setMessage(textMessage); } } super.createControl(parent); }