package com.nexirius.multimail.dataviewer;
import com.nexirius.framework.swing.SwingViewer;
import com.nexirius.framework.swing.CFJLabel;
import com.nexirius.framework.dataviewer.ViewerFactory;
import com.nexirius.framework.datamodel.DataModel;
import com.nexirius.multimail.datamodel.MailModel;
import javax.swing.*;
import java.awt.*;
/**
* Created by IntelliJ IDEA.
* User: nexirius
* Date: 20.12.2007
* Time: 17:15:01
* To change this template use File | Settings | File Templates.
*/
public class MailArrayEditor implements SwingViewer {
String[] children = new String[] {
MailModel.FIELD_email
, MailModel.FIELD_firstName
, MailModel.FIELD_name
, MailModel.FIELD_text1
, MailModel.FIELD_text2
, MailModel.FIELD_text3
, MailModel.FIELD_text4
};
private MailModel mailModel;
public JComponent createJComponent(ViewerFactory factory) {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
for (int i = 0; i < children.length; i++) {
String child = children[i];
JPanel cellPanel = new JPanel(new BorderLayout());
CFJLabel label = new CFJLabel(factory.getClientResource(), child);
label.setFont(new Font("Tahoma", Font.BOLD, 7));
cellPanel.add(label, BorderLayout.NORTH);
try {
cellPanel.add(factory.createDefaultEditor(getDataModel().getChild(child)).getJComponent(), BorderLayout.CENTER);
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
cellPanel.setPreferredSize(new Dimension(100, 32));
panel.add(cellPanel);
}
return panel;
}
public boolean isEditor() {
return true;
}
public void setDataModel(DataModel model) {
mailModel = (MailModel)model;
}
public DataModel getDataModel() {
return mailModel;
}
}