package com.nexirius.ulc.example1.dataviewer;
import com.nexirius.framework.datamodel.*;
import com.nexirius.ulc.ulcviewer.ULCViewer;
import com.nexirius.ulc.ulcviewer.ULCViewerFactory;
import com.nexirius.ulc.example1.datamodel.ItemModel;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCComponent;
import com.ulcjava.base.application.ULCLabel;
import com.ulcjava.base.application.util.Color;
public class ItemULCEditor implements ULCViewer {
ULCBoxPane component;
ItemModel itemModel;
public ULCComponent getULCComponent(ULCViewerFactory factory) {
if (component != null) {
return component;
}
component = new ULCBoxPane(2, 0);
BooleanModel booleanField = itemModel.getBooleanField();
DateModel dateField = itemModel.getDateField();
IntModel intField = itemModel.getIntField();
DoubleModel doubleField = itemModel.getDoubleField();
StringModel stringField = itemModel.getStringField();
try {
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, createLabel(factory, booleanField));
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, factory.createDefaultUlcEditor(booleanField).getULCComponent(factory));
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, createLabel(factory, dateField));
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, factory.createDefaultUlcEditor(dateField).getULCComponent(factory));
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, createLabel(factory, intField));
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, factory.createDefaultUlcEditor(intField).getULCComponent(factory));
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, createLabel(factory, doubleField));
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, factory.createDefaultUlcEditor(doubleField).getULCComponent(factory));
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, createLabel(factory, stringField));
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, factory.createDefaultUlcEditor(stringField).getULCComponent(factory));
DataModel child = itemModel.getChild("comboBoxField");
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, createLabel(factory, child));
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, factory.createDefaultUlcEditor(child).getULCComponent(factory));
child = itemModel.getChild("timeField");
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, createLabel(factory, child));
component.add(ULCBoxPane.BOX_EXPAND_EXPAND, factory.createDefaultUlcEditor(child).getULCComponent(factory));
} catch (Exception e) {
e.printStackTrace(); //TODO
}
return component;
}
private ULCLabel createLabel(ULCViewerFactory factory, DataModel model) {
ULCLabel ulcLabel = new ULCLabel(factory.getClientResource().getLabel(model.getFieldName()));
ulcLabel.setBackground(new Color(220, 240, 190));
return ulcLabel;
}
public boolean isEditor() {
return true;
}
public void setDataModel(Viewable model) {
this.itemModel = (ItemModel) model;
}
public Viewable getDataModel() {
return itemModel;
}
public void updateModel() {
}
}