package com.nexirius.jnex.example.dataviewer;
import com.nexirius.framework.datamodel.DataModel;
import com.nexirius.framework.datamodel.Viewable;
import com.nexirius.framework.dataviewer.ViewerFactory;
import com.nexirius.framework.swing.SwingViewer;
import com.nexirius.jnex.example.datamodel.MainModel;
import com.nexirius.jnex.example.datamodel.MediaArrayModel;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import java.awt.*;
public class MainViewer implements SwingViewer {
MainModel mainModel;
public JComponent createJComponent(ViewerFactory factory) {
JPanel panel = new JPanel(new BorderLayout());
try {
DataModel array = mainModel.getChild(MediaArrayModel.FIELD_NAME);
JComponent table = factory.createDefaultEditor(array).getJComponent();
table.setBorder(new BevelBorder(BevelBorder.LOWERED));
panel.add(table, BorderLayout.CENTER);
Viewable add = mainModel.getViewableChild(MainModel.ADD_MEDIUM_COMMAND);
Viewable edit = mainModel.getViewableChild(MainModel.EDIT_MEDIUM_COMMAND);
Viewable delete = mainModel.getViewableChild(MainModel.DELETE_MEDIUM_COMMAND);
JPanel bPanel = new JPanel();
new BoxLayout(bPanel, BoxLayout.LINE_AXIS);
bPanel.add(Box.createHorizontalGlue());
bPanel.add(factory.createDefaultEditor(add).getJComponent());
bPanel.add(Box.createHorizontalGlue());
bPanel.add(factory.createDefaultEditor(edit).getJComponent());
bPanel.add(Box.createHorizontalGlue());
bPanel.add(factory.createDefaultEditor(delete).getJComponent());
bPanel.add(Box.createHorizontalGlue());
bPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
bPanel.setBackground(factory.getClientResource().getColor("buttonPanelBackground"));
panel.add(bPanel, BorderLayout.SOUTH);
} catch (Exception e) {
e.printStackTrace(); //TODO
}
return panel;
}
public boolean isEditor() {
return true;
}
public void setDataModel(DataModel model) {
mainModel = (MainModel) model;
}
public DataModel getDataModel() {
return mainModel;
}
}