class GrainSizeInBedEditorDialog(DatasetInBedEditorDialog):
    def __init__(self, parent, data):
        DatasetInBedEditorDialog.__init__(self, parent, data)
        self.addContentPanel(self.tr("Grain Size In Bed"))
        self.addIdDisplay()
        self.addNameEdit()
        self.addBedSelector()
        self.addGrainSizeEditor()
        self.addPercentEditor()
        self.addDescriptionEdit()
        self.addButtons()
        self.nameW.setEnabled(False)

        self.idW.setValue(self.data.id)
        self.nameW.setValue(self.data.name)
        self.grainSizeW.selectDataset(data.grainSize)
        self.bedW.selectDataset(data.bed)
        self.percentW.setValues(data.begin, data.end)
        self.descriptionW.setValue(unicode(self.data.description))

        self.nameW.nameChanged.connect(self.onNameChange)
        self.descriptionW.descriptionChanged.connect(self.onDescriptionChange)
        self.percentW.beginValueChanged.connect(self.onBeginValueChange)
        self.percentW.endValueChanged.connect(self.onEndValueChange)
        self.grainSizeW.currentDatasetChanged.connect(self.onGrainSizeChange)

    def onNameChange(self, txt):
        self.data.name = unicode(txt)
    def onDescriptionChange(self, txt):
        self.data.description = unicode(txt)
    def addGrainSizeEditor(self):
        self.grainSizeL = self.createMultiLineLabel(self.tr("&Grain Size"))
        self.grainSizeW = GrainSizeItemView(self.contentW)
        self.grainSizeL.setBuddy(self.grainSizeW)
        self.addLabelWidgetPair(self.grainSizeL, self.grainSizeW)
        self.grainSizeW.reload()
    def onGrainSizeChange(self, l):
        self.data.grainSize = l
        self.updateName()
    def updateName(self):
        if self.data.grainSize is None:
            self.nameW.setText(self.tr("<Grain Size not Set>"))
        else:
            self.data.name = unicode(self.tr("%1 - %2: %3").arg(self.data.begin).arg(self.data.end).arg(self.data.grainSize.name))
            self.nameW.setText(self.data.name)
    def onBeginValueChange(self, v):
        self.data.begin = v
        self.updateName()
    def onEndValueChange(self, v):
        self.data.end = v
        self.updateName()
 def addGrainSizeEditor(self):
     self.grainSizeL = self.createMultiLineLabel(self.tr("&Grain Size"))
     self.grainSizeW = GrainSizeItemView(self.contentW)
     self.grainSizeL.setBuddy(self.grainSizeW)
     self.addLabelWidgetPair(self.grainSizeL, self.grainSizeW)
     self.grainSizeW.reload()