ComboBoxViewerCellEditor显示对象列表中的字符串

时间:2014-11-08 04:16:28

标签: java swt jface

问题陈述:获取在另一个类中声明为集合的类的getter和setter

的DataModel

Public Class Person{
 String firstName;
 String lastName;
 Collection<Address> allAddresses = new ArrayList<Address>();
 getFirstName(){..}
 getLastName{..}
 getContacts{....}
}

Public Class Address{
 String Street;
 String City;
 getCity(){..};
 getStreet(){..};
}

TableViewer内容

personTableViewer.setInput(//lsit of Persons from Database)
columViewer.setLabelProvider{...
...
}
DropDownInTable dot = new DropDownInTable(valcol.getViewer());
columnViewe.setEditingSupport(dot)

DropDownClass

private ComboBoxViewerCellEditor cellEditor=null;
potected CellEditor getCellEditor(Object element) {
  //element here is person Object.I need setINput as getAddress().getCity()
  //if there was way to make element as address Object It would be great
    cellEditor.setInput(element.getAddress)
    return cellEditor;
}

如果有办法强制元素成为地址对象或检索地址,那么任何建议都值得赞赏

1 个答案:

答案 0 :(得分:0)

使用setLabelProvider调用设置标签提供程序,该提供程序获取集合中每个对象的字符串。标签提供者将类似于:

class CollectionLabelProvider extends LabelProvider
{
  @Override
  public String getText(Object element)
  {
    // 'element' is an object from the collection

    CollectionEntry entry = (CollectionEntry)element;

    return entry.getString();
  }
}

将'CollectionEntry'替换为集合中的类。