package com.nexirius.ulc.example1.dataviewer;
import com.nexirius.framework.datamodel.Viewable;
import com.nexirius.ulc.example1.datamodel.ItemListModel;
import com.nexirius.ulc.ulcviewer.ULCViewer;
import com.nexirius.ulc.ulcviewer.ULCViewerFactory;
import com.ulcjava.base.application.ULCComponent;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.GridBagConstraints;
import com.ulcjava.base.application.util.Insets;
public class ItemListULCViewer implements ULCViewer {
private ItemListModel mainModel;
public ULCComponent getULCComponent(ULCViewerFactory factory) {
ULCBoxPane panel = new ULCBoxPane(1, 0);
Insets insets = new Insets(2, 2, 2, 2);
GridBagConstraints c1 = new GridBagConstraints(0, 0, 3, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, insets, 0, 0);
GridBagConstraints bc1 = new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, insets, 0, 0);
GridBagConstraints bc2 = new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, insets, 0, 0);
GridBagConstraints bc3 = new GridBagConstraints(2, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, insets, 0, 0);
try {
ULCComponent table = factory.createUlcViewer(mainModel.getArray(), false).getULCComponent(factory);
panel.add(table, c1);
ULCComponent editButton = factory.createUlcViewer(mainModel.getViewableChild(ItemListModel.EDIT_ITEM_COMMAND), true).getULCComponent(factory);
ULCComponent newButton = factory.createUlcViewer(mainModel.getViewableChild(ItemListModel.NEW_ITEM_COMMAND), true).getULCComponent(factory);
ULCComponent deleteButton = factory.createUlcViewer(mainModel.getViewableChild(ItemListModel.DELETE_ITEM_COMMAND), true).getULCComponent(factory);
panel.add(editButton, bc1);
panel.add(newButton, bc2);
panel.add(deleteButton, bc3);
} catch (Exception e) {
e.printStackTrace(); //TODO
}
return panel;
}
public boolean isEditor() {
return true;
}
public void updateModel() throws Exception {
}
public void setDataModel(Viewable model) {
mainModel = (ItemListModel) model;
}
public Viewable getDataModel() {
return mainModel;
}
}