`

单选圆形框的应用;日期文本框的应用;弹出确认文本框

 
阅读更多



 class1:定义单选按钮的内容

public enum  TradeOperationEnum {
  BUY("买入"),
  SALE("卖出");
  String displayName;
  TradeOperationEnum(String displayName) {
    this.displayName = displayName;
  }
  public String getDisplayName() {
    return this.displayName;
  }
}

 

class2:定义单选按钮

import com.my.stock.view.trade.vo.TradeOperationEnum;
import org.vaadin.viritin.fields.EnumSelect;

public class TradeInformationForm extends AbstractForm<TradeInformationVO> {
	private static final long serialVersionUID = -5238090169742945624L;
	MTextField name = new MTextField("产品名称");
	MDateField tradeDate = new MDateField("交易日期");
	MTextField holding = new MTextField("持有量(张)");
	MTextField price = new MTextField("现价(元)");
	MTextField amount = new MTextField("数量(张)");
        EnumSelect<TradeOperationEnum> operation = new EnumSelect<TradeOperationEnum>("操作").withSelectType(OptionGroup.class);

	@PostConstruct
	void init() {
	}

	public void configure() {
		name.setReadOnly(false);
		tradeDate.setValue(new Date());
		tradeDate.setRangeEnd(DateTime.now().toDate());
	}

	public void setAmount(String amount) {
		amount.setReadOnly(false);
		amount.setValue(amount);
		amount.setReadOnly(true);
        }
	@Override
	protected Component createContent() {
		operation.setCaptionGenerator(o -> o.getDisplayName());
		tradeDate.setValue(new Date());
		getSaveButton().setCaption("添加交易记录");
		getResetButton().setCaption("重填");
		configure();
		FormLayout formLayout = new MFormLayout(bondCode, bondName,
				productName, holding, tradeDate, price, operation, amount,
				getToolbar());
		return formLayout;
	}

	public MTextField getBondCode() {
		return bondCode;
	}

	public MTextField getBondName() {
		return bondName;
	}
} 

 

class3:

public class TradeView extends TradeLayout implements View {
    TradeInformationForm tradeInformationForm = new TradeInformationForm();
	@PostConstruct
	void init() {
		configTradeForm();
	}
	void configTradeForm() {
		TradeInformationVO tradeInformationVO = new TradeInformationVO();
		tradeInformationForm.setEntity(tradeInformationVO);
		tradeInformationForm.configure();
		tradeInformationForm.operation.setOptions(TradeOperationEnum.BUY,TradeOperationEnum.SALE);
		tradeInformationForm.getSaveButton().setEnabled(false);
		tradeInformationForm.setVisible(true);//false
		tradeInformationForm.setSavedHandler(this::saveTradeRecord);
		editPanel.setContent(tradeInformationForm);
	}
	void saveTradeRecord(TradeInformationVO tradeInformationVO) {
		if (tradeInformationVO.getName() ==null) {
			Notification.show("正确设置买卖信息!", Type.ERROR_MESSAGE);
			return;
		}
		if (tradeInformationVO.getAmount() < 1) {
			Notification.show("设置交易数量 !", Type.ERROR_MESSAGE);
			return;
		}
		if (tradeInformationVO.getOperation() == TradeOperationEnum.SALE)
			if (tradeInformationVO.getAmount() > tradeInformationVO
					.getHolding()) {
				Notification.show("卖出数额超限 !", Type.ERROR_MESSAGE);
				return;
		String mess = getConfirmMess(tradeInformationVO);

		ConfirmDialog.show(this.getUI(), "添加交易确认: ", mess, "确认", "取消",
				new ConfirmDialog.Listener() {
					private static final long serialVersionUID = 593093678633114533L;

					public void onClose(ConfirmDialog dialog) {
						if (dialog.isConfirmed()) {
							addTradeRecord(tradeInformationVO);
							logTrade(tradeInformationVO);
						} else {
							// tradeInformationForm.getSaveButton().setEnabled(true);
						}
					}
				});
	}
	private void addTradeRecord(TradeInformationVO tradeInformationVO) {			               if (tradeInformationVO.getOperation() == TradeOperationEnum.BUY) {
				amount = amount + tradeInformationVO.getAmount();
			} else
				amount = amount - tradeInformationVO.getAmount();
        }
}

 class4:

import com.vaadin.annotations.DesignRoot;

@DesignRoot
public class TradeLayout extends VerticalLayout {
	private static final long serialVersionUID = -2659591538746780121L;
	Panel editPanel;
	public TradeLayout() {
		Design.read(this);
		splitPanel.setSplitPosition(60, Unit.PERCENTAGE);
	}
}

 class5:

import lombok.Data;

/**
 * Created by shawz on 12/26/2015.
 */
@Data
public class TradeInformationVO {
  private String name;
  private long holding;
  private double price;
  @NotNull
  private long amount;
  @NotNull(message = "请选择交易日期")
  private Date tradeDate;
  private TradeOperationEnum operation;
}

 

  • 大小: 2.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics