I also get the impression that our environments are very different. I don’t know what environments you guys run on, but for development we are using IntelliJ with Jetty, and we deploy to Tomcat. Also, we develop in Windows but deploy to Solaris. Our database is Sybase 16, but I don’t think this has much to do with anything. What environment are you guys working in?
As for the code, our Grid setup is a bit different. Instead of a IndexedContainer we use a BeanItemContainer, but otherwise it is pretty close. Here is a rundown of our Grid Setup in our Panel. Oh, and by the constructor I mean the Panel’s actual constructor. Here’s a trimmed version (there’s a lot going on in there):
As you can see, we are binding the EditorField in the selection listener. However, if I bind it outside that listener, the application more or less stops working. Its hard to explain what that means because of the nature of the application, but one way to describe it is that there are three things that need to happen before the Grid can be populated, but if bind the EditorField in the way you describe, the first thing that needs to happen doesn’t work at all and nothing can happen after which will eventually populate the grid. I haven’t tried debugging this because I wasn’t sure how it was supposed to work in the first place. Now that I know, I will look into this from a different angle.
Oh, and regardign that TextFieldRenderer you suggested earlier, it never worked. I tried it in a sandbox environment on a different machine and it didn’t work there either … what environment do you guys work in?
@Inject
public ComplexGridModule(final WeeklyDAO dao) {
...
...
complexes = new ArrayList<>();
complexGrid.setContainerDataSource(new BeanItemContainer<>(ComplexModuleData.class));
complexGrid.setColumnOrder("ct", "fundid", "ticker", "fundname", "tna", "tnac", "nav", "navc", "shares", "sharesc", "nncf");
complexGrid.getColumn("ct").setHeaderCaption("#");
complexGrid.getColumn("ct").setRenderer(new NumberRenderer(new DecimalFormat("#")));
complexGrid.getColumn("fundid").setHeaderCaption("Fund ID");
complexGrid.getColumn("fundid").setRenderer(new NumberRenderer(new DecimalFormat("#")));
complexGrid.getColumn("ticker").setHeaderCaption("Ticker");
complexGrid.getColumn("fundname").setHeaderCaption("Fund Name");
complexGrid.getColumn("tna").setHeaderCaption("TNA");
complexGrid.getColumn("tnac").setHeaderCaption("TC");
complexGrid.getColumn("nav").setHeaderCaption("NAV");
complexGrid.getColumn("navc").setHeaderCaption("NC");
complexGrid.getColumn("shares").setHeaderCaption("Shares");
complexGrid.getColumn("sharesc").setHeaderCaption("SC");
complexGrid.getColumn("nncf").setHeaderCaption("NNCF");
complexGrid.getColumn("ct").setEditable(false);
complexGrid.getColumn("fundid").setEditable(false);
complexGrid.getColumn("ticker").setEditable(false);
complexGrid.getColumn("fundname").setEditable(false);
complexGrid.getColumn("tna").setEditable(true);
complexGrid.getColumn("nav").setEditable(true);
complexGrid.getColumn("shares").setEditable(false);
complexGrid.getColumn("tnac").setEditable(false);
complexGrid.getColumn("navc").setEditable(false);
complexGrid.getColumn("sharesc").setEditable(false);
complexGrid.getColumn("ct").setWidth(60);
complexGrid.getColumn("fundid").setWidth(75);
complexGrid.getColumn("ticker").setWidth(100);
complexGrid.getColumn("fundname").setWidth(385);
complexGrid.getColumn("tna").setWidth(140);
complexGrid.getColumn("tnac").setWidth(40);
complexGrid.getColumn("nav").setWidth(140);
complexGrid.getColumn("navc").setWidth(40);
complexGrid.getColumn("shares").setWidth(140);
complexGrid.getColumn("sharesc").setWidth(40);
complexGrid.getColumn("nncf").setWidth(140);
complexGrid.removeColumn("tnaold");
complexGrid.removeColumn("navold");
complexGrid.removeColumn("sharesold");
complexGrid.removeColumn("tnaOrig");
complexGrid.removeColumn("navOrig");
complexGrid.removeColumn("sharesOrig");
complexGrid.removeColumn("tnaDescription");
complexGrid.removeColumn("navDescription");
complexGrid.removeColumn("sharesDescription");
complexGrid.removeColumn("classtype");
complexGrid.removeColumn("iob");
complexGrid.removeColumn("fof");
complexGrid.removeColumn("tna_source");
complexGrid.removeColumn("tna_entry_user");
complexGrid.removeColumn("tna_entry_date");
complexGrid.removeColumn("tna_update_user");
complexGrid.removeColumn("tna_update_date");
complexGrid.removeColumn("nav_source");
complexGrid.removeColumn("nav_entry_user");
complexGrid.removeColumn("nav_entry_date");
complexGrid.removeColumn("nav_update_user");
complexGrid.removeColumn("nav_update_date");
complexGrid.removeColumn("shares_source");
complexGrid.removeColumn("shares_entry_user");
complexGrid.removeColumn("shares_entry_date");
complexGrid.removeColumn("shares_update_user");
complexGrid.removeColumn("shares_update_date");
complexGrid.setSelectionMode(Grid.SelectionMode.SINGLE);
complexGrid.setImmediate(true);
complexGrid.setEditorEnabled(true);
complexGrid.setEditorBuffered(false);
complexGrid.setWidth("1180px");
complexGrid.setHeightByRows(11);
/* ---------------- GRID COLUMN TNA ------------------------ */
TextField tnaEditField = new TextField();
tnaEditField.setNullRepresentation("");
tnaEditField.addFocusListener(new FieldEvents.FocusListener() {
@Override
public void focus(FieldEvents.FocusEvent event) {
tnaEditField.selectAll();
}
});
tnaEditField.addShortcutListener(
new AbstractField.FocusShortcut(tnaEditField, ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
if (target == null) {
return;
}
Object targetParent = ((AbstractComponent) target).getParent();
if (complexGrid.isEditorActive() && !(targetParent instanceof VerticalLayout)) {
try {
complexGrid.saveEditor();
complexGrid.cancelEditor();
complexGrid.focus();
} catch (FieldGroup.CommitException e) {
e.printStackTrace();
}
}
}
});
/* ---------------- GRID COLUMN NAV ------------------------ */
TextField navEditField = new TextField();
navEditField.setNullRepresentation("");
navEditField.addFocusListener(new FieldEvents.FocusListener() {
@Override
public void focus(FieldEvents.FocusEvent event) {
navEditField.selectAll();
}
});
navEditField.addShortcutListener(
new AbstractField.FocusShortcut(navEditField, ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
Object targetParent = ((AbstractComponent) target).getParent();
if (complexGrid.isEditorActive() && !(targetParent instanceof VerticalLayout)) {
try {
complexGrid.saveEditor();
complexGrid.cancelEditor();
complexGrid.focus();
} catch (FieldGroup.CommitException e) {
e.printStackTrace();
}
}
}
});
/* ---------------- GRID COLUMN SHARES ------------------------ */
TextField sharesEditField = new TextField();
sharesEditField.setNullRepresentation("");
sharesEditField.addFocusListener(new FieldEvents.FocusListener() {
@Override
public void focus(FieldEvents.FocusEvent event) {
sharesEditField.selectAll();
}
});
sharesEditField.addShortcutListener(
new AbstractField.FocusShortcut(sharesEditField, ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
Object targetParent = ((AbstractComponent) target).getParent();
if (complexGrid.isEditorActive() && !(targetParent instanceof VerticalLayout)) {
try {
complexGrid.saveEditor();
complexGrid.cancelEditor();
complexGrid.focus();
} catch (FieldGroup.CommitException e) {
e.printStackTrace();
}
}
}
});
complexGrid.setCellStyleGenerator(cellRef -> {// Java 8
int tna;
float nav;
ComplexModuleData d = (ComplexModuleData) cellRef.getItemId();
boolean etf = d.getClasstype() == 5;
String style = "custom-style";
if ("tna".equals(cellRef.getPropertyId())) {
try {
tna = cellRef.getValue() == null ? 0 : Util.removeCommas(cellRef.getValue().toString()).intValue();
TnaValidatorGrid tnaVal = new TnaValidatorGrid(d.getTnaold() == null ? 0 : d.getTnaold().intValue());
if (!tnaVal.isValid(tna))
style = "custom-style supercell";
else
style = "custom-style";
} catch (Exception e) {
e.printStackTrace();
}
} else if ("nav".equals(cellRef.getPropertyId())) {
try {
nav = cellRef.getValue() == null ? 0 : Float.parseFloat(cellRef.getValue().toString());
NavValidatorGrid navVal = new NavValidatorGrid(d.getNavold() == null ? 0 : d.getNavold().floatValue(), etf);
if (!navVal.isValid(nav))
style = "custom-style supercell";
else
style = "custom-style";
} catch (Exception e) {
e.printStackTrace();
}
} else
style = null;
return style;
});
complexGrid.addSelectionListener(new SelectionEvent.SelectionListener() {
@Override
public void select(SelectionEvent selectionEvent) {
complexGrid.getColumn("tna").setEditorField(tnaEditField);
complexGrid.getColumn("nav").setEditorField(navEditField);
complexGrid.getColumn("shares").setEditorField(sharesEditField);
Object obj = complexGrid.getSelectedRow();
if (obj != null && obj instanceof ComplexModuleData) {
lastSelectedRow = (ComplexModuleData) obj;
rowFundClicked(lastSelectedRow);
} else {
rowFundClicked(null);
}
}
});
complexGrid.addShortcutListener(new ShortcutListener("DOWN",
ShortcutAction.KeyCode.ARROW_DOWN, null) {
@Override
public void handleAction(Object sender, Object target) {
if (target == null) {
return;
}
Object targetParent = ((AbstractComponent) target).getParent();
if ((targetParent != null) && (targetParent instanceof Grid)) {
Grid targetGrid = (Grid) targetParent;
if (targetGrid.isEditorActive()) {
try {
targetGrid.saveEditor();
targetGrid.cancelEditor();
targetGrid.focus();
} catch (FieldGroup.CommitException e) {
Notification.show("Validation failed");
}
}
}
}
});
complexGrid.addShortcutListener(new ShortcutListener("UP",
ShortcutAction.KeyCode.ARROW_UP, null) {
@Override
public void handleAction(Object sender, Object target) {
if (target == null) {
return;
}
// logger.info("----> UP KEY <----");
Object targetParent = ((AbstractComponent) target).getParent();
if ((targetParent != null) && (targetParent instanceof Grid)) {
Grid targetGrid = (Grid) targetParent;
if (targetGrid.isEditorActive()) {
try {
targetGrid.saveEditor();
targetGrid.cancelEditor();
targetGrid.focus();
} catch (FieldGroup.CommitException e) {
Notification.show("Validation failed");
}
}
}
}
});
complexGrid.addBlurListener(new InnerComplexGridBlurListener());
/* ------------------- BUTTON SECTION FOR TNA NAV AND SHARES -------------- */
complexGrid.getColumn("tnac")
.setRenderer(new ButtonRenderer(e -> { // Java 8
if (!hasConfirmationPermission())
return;
ComplexModuleData d = (ComplexModuleData) e.getItemId();
complexGrid.select(manageItemId(e.getItemId()));
if (complexGrid.isEnabled()) {
final ConfirmationWindow results = new ConfirmationWindow(dao, ConfirmationWindow.TNA_TYPE, d.getFundid(), selectedDate, d.getIob(), d.getClasstype());
UI.getCurrent().addWindow(results);
results.addFocusListener(new FieldEvents.FocusListener() {
@Override
public void focus(FieldEvents.FocusEvent focusEvent) {
results.grabFocus();
}
});
}
}));
complexGrid.getColumn("navc")
.setRenderer(new ButtonRenderer(e -> {// Java 8
if (!hasConfirmationPermission())
return;
ComplexModuleData d = (ComplexModuleData) e.getItemId();
complexGrid.select(manageItemId(e.getItemId()));
if (complexGrid.isEnabled()) {
final ConfirmationWindow results = new ConfirmationWindow(dao, ConfirmationWindow.NAV_TYPE, d.getFundid(), selectedDate, d.getIob(), d.getClasstype());
UI.getCurrent().addWindow(results);
results.addFocusListener(new FieldEvents.FocusListener() {
@Override
public void focus(FieldEvents.FocusEvent focusEvent) {
results.grabFocus();
}
});
}
}));
complexGrid.getColumn("sharesc")
.setRenderer(new ButtonRenderer(e -> {// Java 8
if (!hasConfirmationPermission())
return;
ComplexModuleData d = (ComplexModuleData) e.getItemId();
complexGrid.select(manageItemId(e.getItemId()));
if (complexGrid.isEnabled()) {
final ConfirmationWindow results = new ConfirmationWindow(dao, ConfirmationWindow.SHARES_TYPE, d.getFundid(), selectedDate, d.getIob(), d.getClasstype());
UI.getCurrent().addWindow(results);
results.addFocusListener(new FieldEvents.FocusListener() {
@Override
public void focus(FieldEvents.FocusEvent focusEvent) {
results.grabFocus();
}
});
}
}));
GridExtension.apply(complexGrid);
...
...
}