我使用smartGWT listGrid与自定义和非自定义单元格, 在每个自定义单元格上我添加了一个图像,我希望字段也可以编辑,当我点击其中一个自定义字段时,该字段没有打开进行编辑,我可以访问它的唯一方法是单击非自定义字段并使用Tab键移动到自定义按钮。 问题只在于fierFox和chrome,但在IE上,每件事情都很完美。
private ListGrid initializeAndGetSubstratesIndividualListgrid(){
substratesIndividualListgrid = new ListGrid(true){
@Override
protected boolean canEditCell(int rowNum, int colNum) {
if(this.getFieldNum(myConstants.SUBSTRATES_CONVENTIONAL_INDIVIDUAL) == colNum ||
this.getFieldNum(myConstants.SUBSTRATE_NAME) == colNum ||
this.getFieldNum(myConstants.SUBSTRATES_SUITABLE_FOR_IN_LINE_PRIMING_INDIVIDUAL) == colNum ||
((this.getFieldNum(myConstants.SUBSTRATES_HP_FOR_ALL_DISCREAT_INDIVIDUAL) == colNum)
&& LabelsSubstratesViewImpl.this.isCanOpenIndividual(getRecord(rowNum)) ))
return true;
return false;
}
@Override
protected Canvas createRecordComponent(final ListGridRecord record, final Integer colNum) {
String fieldName = this.getFieldName(colNum);
if (fieldName.equals(myConstants.SUBSTRATES_HP_FIXED_COST_INDIVIDUAL)) {
HLayout hpfixedcostHlayout = new HLayout();
fixedCostImg = new LabelSubstratesIndividualListGridRadioButton();
if(record.getAttributeAsInt(myConstants.SUBSTRATE_ID) >=0){
fixedCostHashMap.put(record.getAttributeAsInt(myConstants.SUBSTRATE_ID), fixedCostImg);
}else{
fixedCostHashMap.put(record.getAttributeAsInt(myConstants.SUBSTRATES_GROUPING_INDEX_INDIVIDUAL), fixedCostImg);
}
fixedCostImg.setTop(4);
fixedCostImg.setLeft(4);
myLabel fixedCostLabel= new myLabel();
fixedCostLabel.setWidth(90);
fixedCostLabel.setHeight(22);
fixedCostLabel.setTop(1);
fixedCostLabel.setLeft(21);
hpfixedcostHlayout.addChild(fixedCostImg);
hpfixedcostHlayout.addChild(fixedCostLabel);
hpfixedcostHlayout.setSize("60px", "24px");
fixedCostImg.getImg().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ClientFactoryImpl.setDirty(true);
if(record.getAttributeAsInt(myConstants.SUBSTRATE_ID) >=0){
primingFactorHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATE_ID)).unSelectRadio();
discreatHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATE_ID)).unSelectRadio();
}else{
primingFactorHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATES_GROUPING_INDEX_INDIVIDUAL)).unSelectRadio();
discreatHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATES_GROUPING_INDEX_INDIVIDUAL)).unSelectRadio();
}
calculatehpCostIndividual(record);
record.setAttribute(myConstants.SUBSTRATES_SELECTEDRADIO, 3);
}
});
for(int i=0; i<this.getRecords().length; i++){
if(fillFixedCostHashMap.get(i)== record.getAttributeAsInt(myConstants.SUBSTRATE_ID)){
fixedCostHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATE_ID)).selectRadio();
}
}
return hpfixedcostHlayout;
} else if (fieldName.equals(myConstants.SUBSTRATES_HP_PRIMING_FACTOR_INDIVIDUAL)) {
HLayout primingFactorHlayout = new HLayout();
primingFactorImg = new LabelSubstratesIndividualListGridRadioButton();
if(record.getAttributeAsInt(myConstants.SUBSTRATE_ID) >=0){
primingFactorHashMap.put(record.getAttributeAsInt(myConstants.SUBSTRATE_ID), primingFactorImg);
}else{
primingFactorHashMap.put(record.getAttributeAsInt(myConstants.SUBSTRATES_GROUPING_INDEX_INDIVIDUAL), primingFactorImg);// -1 if the record index is the same as exested record id
}
primingFactorImg.setTop(4);
primingFactorImg.setLeft(4);
myLabel primingFactorLabel = new myLabel();
primingFactorLabel.setWidth(90);
primingFactorLabel.setHeight(22);
primingFactorLabel.setTop(1);
primingFactorLabel.setLeft(21);
primingFactorHlayout.addChild(primingFactorImg);
primingFactorHlayout.addChild(primingFactorLabel);
primingFactorHlayout.setSize("60px", "24px");
primingFactorImg.getImg().addClickHandler( new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ClientFactoryImpl.setDirty(true);
if(record.getAttributeAsInt(myConstants.SUBSTRATE_ID) >=0){
discreatHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATE_ID)).unSelectRadio();
fixedCostHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATE_ID)).unSelectRadio();
}else{
discreatHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATES_GROUPING_INDEX_INDIVIDUAL)).unSelectRadio();
fixedCostHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATES_GROUPING_INDEX_INDIVIDUAL)).unSelectRadio();
}
calculatehpCostFromPrimingFactorIndividual(record);
record.setAttribute(myConstants.SUBSTRATES_SELECTEDRADIO, 1);
}
});
for(int i=0; i<this.getRecords().length; i++){
if(fillFactorHashMap.get(i) == record.getAttributeAsInt(myConstants.SUBSTRATE_ID)){
primingFactorHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATE_ID)).selectRadio();
}
}
return primingFactorHlayout;
}else if (fieldName.equals(myConstants.SUBSTRATES_HP_FOR_ALL_DISCREAT_INDIVIDUAL)) {
HLayout discreatHlayout = new HLayout();
discreatImg = new LabelSubstratesIndividualListGridRadioButton();
discreatImg.setTop(4);
if(Utils.isIE())
discreatImg.setLeft(-20);
else{
discreatImg.setZIndex(100000000);
discreatImg.setLeft(-1);
}
if(record.getAttributeAsInt(myConstants.SUBSTRATE_ID) >=0){
discreatHashMap.put(record.getAttributeAsInt(myConstants.SUBSTRATE_ID), discreatImg);
}else{
discreatHashMap.put(record.getAttributeAsInt(myConstants.SUBSTRATES_GROUPING_INDEX_INDIVIDUAL), discreatImg);// -1 if the record index is the same as exested record id
}
discreatImg.getImg().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ClientFactoryImpl.setDirty(true);
if(record.getAttributeAsInt(myConstants.SUBSTRATE_ID) >=0){
primingFactorHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATE_ID)).unSelectRadio();
fixedCostHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATE_ID)).unSelectRadio();
}else{
primingFactorHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATES_GROUPING_INDEX_INDIVIDUAL)).unSelectRadio();
fixedCostHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATES_GROUPING_INDEX_INDIVIDUAL)).unSelectRadio();
}
substratesIndividualListgrid.startEditing(substratesIndividualListgrid.getRecordIndex(record));
record.setAttribute(myConstants.SUBSTRATES_HP_FOR_ALL_DISCREAT_INDIVIDUAL, substratesGroupsListgrid.getRecord(substratesIndividualListgrid.getRecordIndex(record)).getAttribute(myConstants.SUBSTRATES_HP_FOR_ALL_DISCREAT) );
if(Utils.isIE()){
substratesIndividualListgrid.discardEdits(substratesIndividualListgrid.getRecordIndex(record),1);
substratesIndividualListgrid.discardEdits(substratesIndividualListgrid.getRecordIndex(record),2);
}
substratesGroupsListgrid.getRecord(substratesIndividualListgrid.getRecordIndex(record)).setAttribute(myConstants.SUBSTRATE_NAME, substratesIndividualListgrid.getRecord(substratesIndividualListgrid.getRecordIndex(record)).getAttribute(myConstants.SUBSTRATE_NAME) );
record.setAttribute(myConstants.SUBSTRATES_SELECTEDRADIO, 2);
substratesIndividualListgrid.refreshFields();
}
});
/* myLabel discreatLabel= new myLabel();
discreatLabel.setWidth(90);
discreatLabel.setHeight(22);
discreatLabel.setTop(1);
discreatLabel.setLeft(21);*/
discreatHlayout.addChild(discreatImg);
discreatHlayout.setSize("100px", "24px");
for(int i=0; i<this.getRecords().length; i++){
if(filldiscreatHashMap.get(i) == record.getAttributeAsInt(myConstants.SUBSTRATE_ID)){
discreatHashMap.get(record.getAttributeAsInt(myConstants.SUBSTRATE_ID)).selectRadio();
}
}
return discreatHlayout;
}
else{
return null;
}
}
};
substratesIndividualListgrid.setSelectionType(SelectionStyle.SIMPLE);
substratesIndividualListgrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
substratesIndividualListgrid.setCanEdit(true);
substratesIndividualListgrid.setShowRecordComponents(true);
substratesIndividualListgrid.setShowRecordComponentsByCell(true);
ListGridField id = new myListGridField(myConstants.SUBSTRATE_ID);
substratesIndividualListgrid.addSelectionChangedHandler(new SelectionChangedHandler() {
@Override
public void onSelectionChanged(SelectionEvent event) {
if(substratesIndividualListgrid.getSelectedRecords().length>0){
substratesIndividualsToolStripedGrid.getDeleteDisabledIcon().hide();
substratesIndividualsToolStripedGrid.getDeleteEnabledIcon().show();
}else{
substratesIndividualsToolStripedGrid.getDeleteDisabledIcon().show();
substratesIndividualsToolStripedGrid.getDeleteEnabledIcon().hide();
}
}
});
id.setType(ListGridFieldType.INTEGER);
id.setHidden(true);
NonEmptyValidator nonEmptyValidator = new NonEmptyValidator();
nonEmptyValidator.setErrorMessage("cant be empty");
//conv.colors ListGridField
substrateIndividualName = new myListGridField(myConstants.SUBSTRATE_NAME, substratesViewVocabularies.substrateName());
substrateIndividualName.setType(ListGridFieldType.TEXT);
substrateIndividualName.setAlign(Alignment.CENTER);
substrateIndividualName.setValidators(nonEmptyValidator);
substrateIndividualName.setWidth(167);
substrateIndividualName.addEditorExitHandler(this);
convintionalFieldIndividual = new myListGridField(myConstants.SUBSTRATES_CONVENTIONAL_INDIVIDUAL, substratesViewVocabularies.conventional());
convintionalFieldIndividual.setType(ListGridFieldType.FLOAT);
convintionalFieldIndividual.setAlign(Alignment.CENTER);
convintionalFieldIndividual.setValidators(nonEmptyValidator);
convintionalFieldIndividual.setWidth(143);
convintionalFieldIndividual.addChangedHandler( this);
convintionalFieldIndividual.addEditorExitHandler(this);
convintionalFieldIndividual.setCellFormatter(twoDigitesFormatter);
hpFixedCostFieldIndividual = new myListGridField(myConstants.SUBSTRATES_HP_FIXED_COST_INDIVIDUAL, substratesViewVocabularies.hpFixedCost());
hpFixedCostFieldIndividual.setAlign(Alignment.CENTER);
hpFixedCostFieldIndividual.setWidth(144);
hpFixedCostFieldIndividual.setCellFormatter(twoDigitesFormatter);
hpPrimingFactorFieldIndividual = new myListGridField(myConstants.SUBSTRATES_HP_PRIMING_FACTOR_INDIVIDUAL, substratesViewVocabularies.hpPrimingFactor());
hpPrimingFactorFieldIndividual.setAlign(Alignment.CENTER);
hpPrimingFactorFieldIndividual.setWidth(144);
hpPrimingFactorFieldIndividual.setCellFormatter(twoDigitesFormatter);
hpFieldForAllDiscreteIndividual = new myListGridField(myConstants.SUBSTRATES_HP_FOR_ALL_DISCREAT_INDIVIDUAL, substratesViewVocabularies.hp());
hpFieldForAllDiscreteIndividual.setAlign(Alignment.CENTER);
hpFieldForAllDiscreteIndividual.setWidth(144);
hpFieldForAllDiscreteIndividual.addEditorExitHandler(this);
hpFieldForAllDiscreteIndividual.setCellFormatter(twoDigitesFormatter);
hpFieldForAllDiscreteIndividual.setCanEdit(true);
ListGridField suitableForInLine = new myListGridField(myConstants.SUBSTRATES_SUITABLE_FOR_IN_LINE_PRIMING_INDIVIDUAL, substratesViewVocabularies.suitableForInLinePriming());
suitableForInLine.setType(ListGridFieldType.BOOLEAN);
suitableForInLine.setAlign(Alignment.CENTER);
suitableForInLine.setWidth(130);
substratesIndividualListgrid.setShowHeader(false);
substratesIndividualListgrid.setFields(id, substrateIndividualName,convintionalFieldIndividual,hpFixedCostFieldIndividual,hpPrimingFactorFieldIndividual, hpFieldForAllDiscreteIndividual ,suitableForInLine);
substratesIndividualListgrid.selectRecord(0);
return substratesIndividualListgrid;
}
或至少我想把文本标记放在自定义字段
中