private void addReportEntityBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addReportEntityBtnActionPerformed
TreePath path = mainTree.getSelectionPath();
TreePath newpath = null;
ReportEntityModel model = (ReportEntityModel) mainTree.getModel();
QEntity children[] = null;
if(path == null) {
if(core.getRoot() != null) {
Message.warning(this, "Выберите элемент для связи");
return;
}
children = entitySet.getAvailableEntities(core.getContextGroup());
} else {
QEntity ren = (QEntity) path.getLastPathComponent();
children = ren.getAvialiableEntities();
}
if(children == null) {
Message.warning(this, "У данного объекта нет связанных сущностей");
return;
}
ArrayList<QEntity> childrenList = new ArrayList<QEntity>();
ArrayList<QEntity> originalList = new ArrayList<QEntity>();
for(QEntity child: children) {
childrenList.add(child);
originalList.add(child);
}
Collections.sort(childrenList, new Comparator<QEntity>() {
@Override
public int compare(QEntity o1, QEntity o2) {
return o1.toString().compareTo(o2.toString());
}
});
NewReportEntityDlg dlg = new NewReportEntityDlg(parent, childrenList);
dlg.setVisible(true);
if(dlg.isOK()) {
int index = dlg.getSelectedIndex();
QEntity selectedEntity = childrenList.get(index);
if(path == null) {
core.setRoot(selectedEntity);
mainTree.setModel(new ReportEntityModel(selectedEntity));
newpath = new TreePath(selectedEntity);
} else {
QEntity parentEntity = (QEntity) path.getLastPathComponent();
index = originalList.indexOf(selectedEntity);
parentEntity.addSelectedEntity(index);
ArrayList<Object> newTreePath = new ArrayList<Object>();
for(Object obj: path.getPath()) {
newTreePath.add(obj);
}