package com.nexirius.jnex.example.datamodel;
import com.nexirius.framework.application.DialogManager;
import com.nexirius.framework.datamodel.*;
import com.nexirius.framework.dataviewer.RadioBoxViewerCreator;
public class MainModel extends StructModel {
public static final String FIELD_NAME = "Main";
public static final String ADD_MEDIUM_COMMAND = "addMediumCommand";
public static final String EDIT_MEDIUM_COMMAND = "editMediumCommand";
public static final String DELETE_MEDIUM_COMMAND = "deleteMediumCommand";
MediaArrayModel mediaArray;
public MainModel() {
super(FIELD_NAME);
init();
}
private void init() {
append(mediaArray = new MediaArrayModel());
appendMethod(new DefaultDataModelCommand(ADD_MEDIUM_COMMAND));
appendMethod(new DefaultDataModelCommand(EDIT_MEDIUM_COMMAND));
appendMethod(new DefaultDataModelCommand(DELETE_MEDIUM_COMMAND));
}
public MediaArrayModel getMediaArray() {
return mediaArray;
}
public void addMediumCommand() {
MediaModel medium = null;
ComboBoxModel select = new ComboBoxModel(0, new SimpleArrayModel(MediaModel.MEDIUM_ARRAY), "select");
if (DialogManager.getPopupEditorAdaptor().popupEdit(select, new RadioBoxViewerCreator())) {
System.out.println("select " + select.getInt());
switch (select.getInt()) {
case MediaModel.CD:
medium = new CDModel();
break;
case MediaModel.DVD:
medium = new DVDModel();
break;
case MediaModel.MD:
medium = new MDModel();
break;
case MediaModel.VIDEO:
medium = new VIDEOModel();
break;
}
} else {
return;
}
if (DialogManager.getPopupEditorAdaptor().popupEdit(medium)) {
mediaArray.append(medium);
}
}
public void editMediumCommand() {
DataModel act = mediaArray.getHighlightedItem();
if (act == null) {
DialogManager.warning("NothingHighlighted");
} else {
DialogManager.getPopupEditorAdaptor().popupEdit(act);
}
}
public void deleteMediumCommand() {
DataModel act = mediaArray.getHighlightedItem();
if (act == null) {
DialogManager.warning("NothingHighlighted");
} else {
if (DialogManager.ask("ReallyDelete", "Delete", "Cancel", false)) {
mediaArray.removeItem(act);
}
}
}
}