Line 55... |
Line 55... |
55 |
import org.openconcerto.sql.request.ComboSQLRequest;
|
55 |
import org.openconcerto.sql.request.ComboSQLRequest;
|
56 |
import org.openconcerto.sql.request.ListSQLRequest;
|
56 |
import org.openconcerto.sql.request.ListSQLRequest;
|
57 |
import org.openconcerto.sql.request.SQLCache;
|
57 |
import org.openconcerto.sql.request.SQLCache;
|
58 |
import org.openconcerto.sql.request.SQLFieldTranslator;
|
58 |
import org.openconcerto.sql.request.SQLFieldTranslator;
|
59 |
import org.openconcerto.sql.sqlobject.SQLTextCombo;
|
59 |
import org.openconcerto.sql.sqlobject.SQLTextCombo;
|
- |
|
60 |
import org.openconcerto.sql.ui.light.CustomRowEditor;
|
60 |
import org.openconcerto.sql.ui.light.GroupToLightUIConvertor;
|
61 |
import org.openconcerto.sql.ui.light.GroupToLightUIConvertor;
|
61 |
import org.openconcerto.sql.ui.light.LightEditFrame;
|
62 |
import org.openconcerto.sql.ui.light.LightEditFrame;
|
62 |
import org.openconcerto.sql.ui.light.LightUIPanelFiller;
|
63 |
import org.openconcerto.sql.ui.light.LightUIPanelFiller;
|
63 |
import org.openconcerto.sql.ui.light.SavableCustomEditorProvider;
|
- |
|
64 |
import org.openconcerto.sql.users.rights.UserRightsManager;
|
64 |
import org.openconcerto.sql.users.rights.UserRightsManager;
|
65 |
import org.openconcerto.sql.utils.SQLUtils;
|
65 |
import org.openconcerto.sql.utils.SQLUtils;
|
66 |
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
|
66 |
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
|
67 |
import org.openconcerto.sql.view.EditFrame;
|
67 |
import org.openconcerto.sql.view.EditFrame;
|
68 |
import org.openconcerto.sql.view.EditPanel.EditMode;
|
68 |
import org.openconcerto.sql.view.EditPanel.EditMode;
|
Line 72... |
Line 72... |
72 |
import org.openconcerto.sql.view.list.SQLTableModelSource;
|
72 |
import org.openconcerto.sql.view.list.SQLTableModelSource;
|
73 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOffline;
|
73 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOffline;
|
74 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
|
74 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
|
75 |
import org.openconcerto.ui.group.Group;
|
75 |
import org.openconcerto.ui.group.Group;
|
76 |
import org.openconcerto.ui.light.ComboValueConvertor;
|
76 |
import org.openconcerto.ui.light.ComboValueConvertor;
|
77 |
import org.openconcerto.ui.light.CustomEditorProvider;
|
- |
|
78 |
import org.openconcerto.ui.light.IntValueConvertor;
|
77 |
import org.openconcerto.ui.light.IntValueConvertor;
|
79 |
import org.openconcerto.ui.light.LightUIComboBox;
|
78 |
import org.openconcerto.ui.light.LightUIComboBox;
|
80 |
import org.openconcerto.ui.light.LightUIElement;
|
79 |
import org.openconcerto.ui.light.LightUIElement;
|
81 |
import org.openconcerto.ui.light.LightUIFrame;
|
80 |
import org.openconcerto.ui.light.LightUIFrame;
|
82 |
import org.openconcerto.ui.light.LightUIPanel;
|
81 |
import org.openconcerto.ui.light.LightUIPanel;
|
Line 335... |
Line 334... |
335 |
|
334 |
|
336 |
if (editMode.equals(EditMode.CREATION)) {
|
335 |
if (editMode.equals(EditMode.CREATION)) {
|
337 |
editFrame.createTitlePanel(this.getCreationFrameTitle());
|
336 |
editFrame.createTitlePanel(this.getCreationFrameTitle());
|
338 |
} else if (editMode.equals(EditMode.MODIFICATION)) {
|
337 |
} else if (editMode.equals(EditMode.MODIFICATION)) {
|
339 |
editFrame.createTitlePanel(this.getModificationFrameTitle(sqlRow));
|
338 |
editFrame.createTitlePanel(this.getModificationFrameTitle(sqlRow));
|
340 |
new LightUIPanelFiller(editFrame.getContentPanel()).fillFromRow(configuration, sqlRow);
|
339 |
new LightUIPanelFiller(editFrame.getContentPanel()).fillFromRow(configuration, this, sqlRow, sessionSecurityToken);
|
341 |
} else if (editMode.equals(EditMode.READONLY)) {
|
340 |
} else if (editMode.equals(EditMode.READONLY)) {
|
342 |
editFrame.createTitlePanel(this.getReadOnlyFrameTitle(sqlRow));
|
341 |
editFrame.createTitlePanel(this.getReadOnlyFrameTitle(sqlRow));
|
343 |
new LightUIPanelFiller(editFrame.getContentPanel()).fillFromRow(configuration, sqlRow);
|
342 |
new LightUIPanelFiller(editFrame.getContentPanel()).fillFromRow(configuration, this, sqlRow, sessionSecurityToken);
|
344 |
}
|
343 |
}
|
345 |
|
344 |
|
346 |
this.setEditFrameModifiers(editFrame, sessionSecurityToken);
|
345 |
this.setEditFrameModifiers(editFrame, sessionSecurityToken);
|
347 |
|
346 |
|
348 |
return editFrame;
|
347 |
return editFrame;
|
Line 387... |
Line 386... |
387 |
*
|
386 |
*
|
388 |
* @return An initialized GroupToLightUIConvertor
|
387 |
* @return An initialized GroupToLightUIConvertor
|
389 |
*/
|
388 |
*/
|
390 |
public GroupToLightUIConvertor getGroupToLightUIConvertor(final PropsConfiguration configuration, final EditMode editMode, final SQLRowAccessor sqlRow, final String token) {
|
389 |
public GroupToLightUIConvertor getGroupToLightUIConvertor(final PropsConfiguration configuration, final EditMode editMode, final SQLRowAccessor sqlRow, final String token) {
|
391 |
final GroupToLightUIConvertor convertor = new GroupToLightUIConvertor(configuration);
|
390 |
final GroupToLightUIConvertor convertor = new GroupToLightUIConvertor(configuration);
|
392 |
if (editMode.equals(EditMode.CREATION)) {
|
391 |
// if (editMode.equals(EditMode.CREATION)) {
|
393 |
convertor.putAllCustomEditorProvider(this.getCustomEditorProviderForCreation(configuration, token));
|
392 |
convertor.putAllCustomEditorProvider(this.getCustomRowEditors(configuration, token));
|
394 |
} else {
|
393 |
// } else {
|
395 |
convertor.putAllCustomEditorProvider(this.getCustomEditorProviderForModification(configuration, sqlRow, token));
|
394 |
// convertor.putAllCustomEditorProvider(this.getCustomRowEditors(configuration, sqlRow,
|
- |
|
395 |
// token));
|
396 |
}
|
396 |
// }
|
397 |
return convertor;
|
397 |
return convertor;
|
398 |
}
|
398 |
}
|
399 |
|
399 |
|
400 |
/**
|
400 |
/**
|
401 |
* Override this function in an element and put new value in map for use ComboValueConvertor.
|
401 |
* Override this function in an element and put new value in map for use ComboValueConvertor.
|
Line 416... |
Line 416... |
416 |
*/
|
416 |
*/
|
417 |
// TODO: implement with IClosure
|
417 |
// TODO: implement with IClosure
|
418 |
public void setEditFrameModifiers(final LightEditFrame frame, final String sessionToken) {
|
418 |
public void setEditFrameModifiers(final LightEditFrame frame, final String sessionToken) {
|
419 |
}
|
419 |
}
|
420 |
|
420 |
|
421 |
public final Map<String, CustomEditorProvider> getCustomEditorProviderForCreation(final Configuration configuration, final String sessionToken) {
|
421 |
public List<CustomRowEditor> getCustomRowEditors(final Configuration configuration, final String sessionToken) {
|
422 |
final Map<String, CustomEditorProvider> map = this.getDefaultCustomEditorProvider(configuration, null, sessionToken);
|
- |
|
423 |
map.putAll(this._getCustomEditorProviderForCreation(configuration, sessionToken));
|
- |
|
424 |
return map;
|
- |
|
425 |
}
|
- |
|
426 |
|
- |
|
427 |
public final Map<String, CustomEditorProvider> getCustomEditorProviderForModification(final Configuration configuration, final SQLRowAccessor sqlRow, final String sessionToken) {
|
- |
|
428 |
final Map<String, CustomEditorProvider> map = this.getDefaultCustomEditorProvider(configuration, sqlRow, sessionToken);
|
- |
|
429 |
map.putAll(this._getCustomEditorProviderForModification(configuration, sqlRow, sessionToken));
|
- |
|
430 |
return map;
|
- |
|
431 |
}
|
- |
|
432 |
|
- |
|
433 |
protected Map<String, CustomEditorProvider> _getCustomEditorProviderForCreation(final Configuration configuration, final String sessionToken) {
|
- |
|
434 |
return new HashMap<String, CustomEditorProvider>();
|
- |
|
435 |
}
|
- |
|
436 |
|
- |
|
437 |
protected Map<String, CustomEditorProvider> _getCustomEditorProviderForModification(final Configuration configuration, final SQLRowAccessor sqlRow, final String sessionToken) {
|
- |
|
438 |
return new HashMap<String, CustomEditorProvider>();
|
- |
|
439 |
}
|
- |
|
440 |
|
- |
|
441 |
protected Map<String, CustomEditorProvider> _getDefaultCustomEditorProvider(final Configuration configuration, final SQLRowAccessor sqlRow, final String sessionToken) {
|
- |
|
442 |
return new HashMap<String, CustomEditorProvider>();
|
- |
|
443 |
}
|
- |
|
444 |
|
- |
|
445 |
private final Map<String, CustomEditorProvider> getDefaultCustomEditorProvider(final Configuration configuration, final SQLRowAccessor sqlRow, final String sessionToken) {
|
- |
|
446 |
final Map<String, ComboValueConvertor<?>> comboConvertors = this.getComboConvertors();
|
422 |
final Map<String, ComboValueConvertor<?>> comboConvertors = this.getComboConvertors();
|
447 |
final Map<String, CustomEditorProvider> result = new HashMap<String, CustomEditorProvider>();
|
423 |
final List<CustomRowEditor> result = new ArrayList<>();
|
448 |
for (final Entry<String, ComboValueConvertor<?>> entry : comboConvertors.entrySet()) {
|
424 |
for (final Entry<String, ComboValueConvertor<?>> entry : comboConvertors.entrySet()) {
|
- |
|
425 |
|
- |
|
426 |
final String itemId = entry.getKey();
|
449 |
result.put(entry.getKey(), new SavableCustomEditorProvider() {
|
427 |
result.add(new CustomRowEditor(itemId) {
|
450 |
final ComboValueConvertor<?> convertor = entry.getValue();
|
428 |
final ComboValueConvertor<?> convertor = entry.getValue();
|
451 |
|
429 |
|
452 |
@Override
|
430 |
@Override
|
453 |
public LightUIElement createUIElement(final String elementId) {
|
431 |
public LightUIElement createUIElement() {
|
454 |
final LightUIComboBox uiCombo = new LightUIComboBox(elementId);
|
432 |
final LightUIComboBox uiCombo = new LightUIComboBox(getItemId());
|
455 |
|
- |
|
456 |
if (sqlRow == null) {
|
- |
|
457 |
this.convertor.fillCombo(uiCombo, null);
|
433 |
this.convertor.fillCombo(uiCombo, null);
|
- |
|
434 |
return uiCombo;
|
- |
|
435 |
}
|
- |
|
436 |
|
458 |
} else {
|
437 |
@Override
|
- |
|
438 |
public void fillFrom(LightUIElement uiElement, SQLRowAccessor sqlRow) {
|
- |
|
439 |
final LightUIComboBox uiCombo = (LightUIComboBox) uiElement;
|
459 |
final SQLField field = configuration.getFieldMapper().getSQLFieldForItem(elementId);
|
440 |
final SQLField field = configuration.getFieldMapper().getSQLFieldForItem(getItemId());
|
460 |
if (this.convertor instanceof StringValueConvertor) {
|
441 |
if (this.convertor instanceof StringValueConvertor) {
|
461 |
((StringValueConvertor) this.convertor).fillCombo(uiCombo, sqlRow.getString(field.getFieldName()));
|
442 |
((StringValueConvertor) this.convertor).fillCombo(uiCombo, sqlRow.getString(field.getFieldName()));
|
462 |
} else if (this.convertor instanceof IntValueConvertor) {
|
443 |
} else if (this.convertor instanceof IntValueConvertor) {
|
463 |
if (sqlRow.getObject(field.getFieldName()) == null) {
|
444 |
if (sqlRow.getObject(field.getFieldName()) != null) {
|
464 |
this.convertor.fillCombo(uiCombo, null);
|
- |
|
465 |
} else {
|
- |
|
466 |
((IntValueConvertor) this.convertor).fillCombo(uiCombo, sqlRow.getInt(field.getFieldName()));
|
445 |
((IntValueConvertor) this.convertor).fillCombo(uiCombo, sqlRow.getInt(field.getFieldName()));
|
467 |
}
|
446 |
}
|
468 |
}
|
447 |
}
|
469 |
}
|
- |
|
470 |
return uiCombo;
|
- |
|
- |
|
448 |
|
471 |
}
|
449 |
}
|
472 |
|
450 |
|
473 |
@Override
|
451 |
@Override
|
474 |
protected void _save(final SQLRowValues sqlRow, final SQLField sqlField, final LightUIElement uiElement) {
|
452 |
public void store(LightUIElement uiElement, SQLRowValues sqlRow) {
|
475 |
final LightUIComboBox combo = (LightUIComboBox) uiElement;
|
453 |
final LightUIComboBox combobox = (LightUIComboBox) uiElement;
|
- |
|
454 |
final String fieldName = configuration.getFieldMapper().getSQLFieldForItem(getItemId()).getName();
|
476 |
if (combo.hasSelectedValue()) {
|
455 |
if (combobox.hasSelectedValue()) {
|
477 |
if (this.convertor instanceof StringValueConvertor) {
|
456 |
if (this.convertor instanceof StringValueConvertor) {
|
478 |
sqlRow.put(sqlField.getName(), ((StringValueConvertor) this.convertor).getIdFromIndex(combo.getSelectedValue().getId()));
|
457 |
sqlRow.put(fieldName, ((StringValueConvertor) this.convertor).getIdFromIndex(combobox.getSelectedValue().getId()));
|
479 |
} else if (this.convertor instanceof IntValueConvertor) {
|
458 |
} else if (this.convertor instanceof IntValueConvertor) {
|
480 |
sqlRow.put(sqlField.getName(), combo.getSelectedValue().getId());
|
459 |
sqlRow.put(fieldName, combobox.getSelectedValue().getId());
|
481 |
} else {
|
460 |
} else {
|
482 |
throw new IllegalArgumentException("the save is not implemented for the class: " + this.convertor.getClass().getName() + " - ui element id: " + uiElement.getId());
|
461 |
throw new IllegalArgumentException("the save is not implemented for the class: " + this.convertor.getClass().getName() + " - ui id: " + getItemId());
|
483 |
}
|
462 |
}
|
484 |
} else {
|
463 |
} else {
|
485 |
sqlRow.put(sqlField.getName(), null);
|
464 |
sqlRow.put(fieldName, null);
|
486 |
}
|
465 |
}
|
- |
|
466 |
|
487 |
}
|
467 |
}
|
488 |
});
|
468 |
});
|
489 |
}
|
469 |
}
|
490 |
result.putAll(this._getDefaultCustomEditorProvider(configuration, sqlRow, sessionToken));
|
- |
|
491 |
return result;
|
470 |
return result;
|
492 |
}
|
471 |
}
|
493 |
|
472 |
|
494 |
/**
|
473 |
/**
|
495 |
* Override this function in an element to execute some code just after inserted new row in
|
474 |
* Override this function in an element to execute some code just after inserted new row in
|