AMSamplePlatePre2013Selector::AMSamplePlatePre2013Selector(AMSamplePlatePre2013* sourcePlate, QWidget *parent)
	: QWidget(parent) {

	samplePlateTableName_ = AMDbObjectSupport::s()->tableNameForClass<AMSamplePlatePre2013>();
	// Either use an external plate (if specified in sourcePlate), or make an internal one.
	plate_ = sourcePlate ? sourcePlate : new AMSamplePlatePre2013(this);

	setupUi();
	notesEditor->setObjectName("notesEditor");
	notesEditor->setStyleSheet("#notesEditor { background-image: url(:/notepadBackground.png); font: bold 15px \"Marker Felt\";}");

	AMDetailedItemDelegate* del = new AMDetailedItemDelegate(this);
	// Setting a new view fixes a grayed-menu-background drawing bug on mac
	QListView* lview = new QListView(this);
	lview->setItemDelegate(del);
	lview->setAlternatingRowColors(true);
	plateComboBox->setView(lview);

	notesEditor->setMaximumHeight(80);
	this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);

	connect(&plateRefreshScheduler_, SIGNAL(executed()), this, SLOT(populateSamplePlates()));
	plateRefreshScheduler_.schedule();

	onSamplePlateChanged(/*plate_->valid()*/);

	connect(AMDatabase::database("user"), SIGNAL(updated(QString,int)), this, SLOT(onDatabaseUpdated(QString,int)), Qt::QueuedConnection);
	connect(AMDatabase::database("user"), SIGNAL(created(QString,int)), this, SLOT(onDatabaseCreated(QString,int)), Qt::QueuedConnection);
	connect(AMDatabase::database("user"), SIGNAL(removed(QString,int)), this, SLOT(onDatabaseRemoved(QString,int)), Qt::QueuedConnection);

	// GUI event connections
	connect(plateComboBox, SIGNAL(activated(int)), this, SLOT(onComboBoxActivated(int)));
	connect(nameEdit, SIGNAL(textEdited(QString)), this, SLOT(onNameEdited(QString)));
	connect(nameEdit, SIGNAL(editingFinished()), this, SLOT(onPlateEditingFinished()));
	connect(notesEditor, SIGNAL(textChanged()), this, SLOT(onNotesEdited()));
	connect(notesEditor, SIGNAL(editingFinished(int)), this, SLOT(onPlateEditingFinished()));

	notesHeaderButton->setChecked(false);
	notesEditor->setVisible(false);
	connect(notesHeaderButton, SIGNAL(clicked(bool)), notesEditor, SLOT(setVisible(bool)));

	// when our current sample plate is re-loaded out of the database, respond to update the GUI values
	connect(plate_, SIGNAL(loadedFromDb()), this, SLOT(onSamplePlateChanged()), Qt::QueuedConnection);
}
AMSamplePlateMoveActionEditor::AMSamplePlateMoveActionEditor(AMSamplePlateMoveActionInfo *info, QWidget *parent) :
	QFrame(parent)
{
	info_ = info;

	QHBoxLayout *hl = new QHBoxLayout(this);
	samplePositionSelectorBox_ = new QComboBox();
	hl->addWidget(new QLabel("Sample: "));
	hl->addWidget(samplePositionSelectorBox_);
	changeSamplePlateCheckBox_ = new QCheckBox("Change sample plate");
	hl->addWidget(changeSamplePlateCheckBox_);
	samplePlateSelectorBox_ = new QComboBox();
	samplePlateSelectorBox_->setEnabled(false);
	hl->addWidget(new QLabel("Sample Plate: "));
	hl->addWidget(samplePlateSelectorBox_);
	hl->addStretch(0);

	populateSamplePlates();
	populateSamplePositions();

	connect(samplePositionSelectorBox_, SIGNAL(currentIndexChanged(int)), this, SLOT(onSamplePositionSelectorBoxCurrentIndexChanged(int)));
	connect(samplePlateSelectorBox_, SIGNAL(currentIndexChanged(int)), this, SLOT(onSamplePlateSeletectorBoxCurrentIndexChanged(int)));
	connect(changeSamplePlateCheckBox_, SIGNAL(toggled(bool)), this, SLOT(onChangeSamplePlateCheckBoxToggled(bool)));
}