use of org.adempiere.webui.editor.WEditor in project adempiere by adempiere.
the class FindWindow method parseString.
/**
* Parse String
* @param field column
* @param in value
* @param to
* @param listItem
* @return data type corected value
*/
private Component parseString(GridField field, String in, ListItem listItem, boolean to) {
if (in == null)
return null;
int dt = field.getDisplayType();
try {
WEditor editor = null;
if (field.isKey())
editor = new WNumberEditor(field);
else
editor = WebEditorFactory.getEditor(field, true);
if (editor == null)
editor = new WStringEditor(field);
// Return Integer
if (dt == DisplayType.Integer || (DisplayType.isID(dt) && field.getColumnName().endsWith("_ID"))) {
int i = Integer.parseInt(in);
editor.setValue(new Integer(i));
} else // Return BigDecimal
if (DisplayType.isNumeric(dt)) {
editor.setValue(DisplayType.getNumberFormat(dt).parse(in));
} else // Return Timestamp
if (DisplayType.isDate(dt)) {
long time = 0;
try {
time = DisplayType.getDateFormat_JDBC().parse(in).getTime();
editor.setValue(new Timestamp(time));
} catch (Exception e) {
log.log(Level.SEVERE, in + "(" + in.getClass() + ")" + e);
time = DisplayType.getDateFormat(dt).parse(in).getTime();
}
editor.setValue(new Timestamp(time));
} else if (dt == DisplayType.YesNo)
editor.setValue(Boolean.valueOf(in));
else
editor.setValue(in);
editor.addValueChangeListener(this);
boolean between = false;
Listbox listOp = (Listbox) listItem.getFellow("listOperator" + listItem.getId());
String betweenValue = listOp.getSelectedItem().getValue().toString();
String opValue = MQuery.OPERATORS[MQuery.BETWEEN_INDEX].getValue();
if (to && betweenValue != null && betweenValue.equals(opValue))
between = true;
boolean enabled = !to || (to && between);
editor.setReadWrite(enabled);
editor.setVisible(enabled);
editor.dynamicDisplay();
return editor.getComponent();
} catch (Exception ex) {
log.log(Level.SEVERE, "Object=" + in, ex);
return null;
}
}
use of org.adempiere.webui.editor.WEditor in project adempiere by adempiere.
the class GridTabDataBinder method valueChange.
/**
* @param e
*/
public void valueChange(ValueChangeEvent e) {
if (// only active records
gridTab.isProcessed()) {
Object source = e.getSource();
if (source instanceof WEditor) {
// Elaine 2009/05/06
WEditor editor = (WEditor) source;
GridField gridField = editor.getGridField();
if (gridField != null) {
if (!gridField.isEditable(true)) {
logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
return;
}
} else if (!editor.isReadWrite()) {
logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
return;
}
} else {
logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
return;
}
}
// processed
logger.config("(" + gridTab.toString() + ") " + e.getPropertyName() + "=" + e.getNewValue() + " (" + e.getOldValue() + ") " + (e.getOldValue() == null ? "" : e.getOldValue().getClass().getName()));
// Get Row/Col Info
GridTable mTable = gridTab.getTableModel();
int row = gridTab.getCurrentRow();
int col = mTable.findColumn(e.getPropertyName());
//
if (e.getNewValue() == null && e.getOldValue() != null && // some editors return "" instead of null
e.getOldValue().toString().length() > 0)
// this is the original code from GridController, don't know what it does there but it breaks ignore button for web ui
// mTable.setChanged (true);
mTable.setValueAt(e.getNewValue(), row, col);
else {
Object newValue = e.getNewValue();
Integer[] newValues = null;
if (newValue instanceof Integer[]) {
newValues = ((Integer[]) newValue);
newValue = newValues[0];
if (newValues.length > 1) {
Integer[] valuesCopy = new Integer[newValues.length - 1];
System.arraycopy(newValues, 1, valuesCopy, 0, valuesCopy.length);
newValues = valuesCopy;
} else {
newValues = null;
}
} else if (newValue instanceof Object[]) {
logger.severe("Multiple values can only be processed for IDs (Integer)");
throw new IllegalArgumentException("Multiple Selection values not available for this field. " + e.getPropertyName());
}
mTable.setValueAt(newValue, row, col);
// Force Callout
if (e.getPropertyName().equals("S_ResourceAssignment_ID")) {
GridField mField = gridTab.getField(col);
if (mField != null && mField.getCallout().length() > 0) {
// Dependencies & Callout
gridTab.processFieldChange(mField);
}
}
if (newValues != null && newValues.length > 0) {
// Save data, since record need to be used for generating clones.
if (!gridTab.dataSave(false)) {
throw new AdempiereException("SaveError");
}
// Retrieve the current record ID
int recordId = gridTab.getKeyID(gridTab.getCurrentRow());
Trx trx = Trx.get(Trx.createTrxName(), true);
trx.start();
try {
saveMultipleRecords(Env.getCtx(), gridTab.getTableName(), e.getPropertyName(), recordId, newValues, trx.getTrxName());
trx.commit();
gridTab.dataRefreshAll();
} catch (Exception ex) {
trx.rollback();
logger.severe(ex.getMessage());
throw new AdempiereException("SaveError");
} finally {
trx.close();
}
}
}
}
use of org.adempiere.webui.editor.WEditor in project adempiere by adempiere.
the class FindWindow method onEvent.
// addSelectionColumn
public void onEvent(Event event) throws Exception {
if (Events.ON_SELECT.equals(event.getName())) {
if (event.getTarget() instanceof Listbox) {
ListItem row = (ListItem) (event.getTarget().getParent().getParent());
Listbox listbox = (Listbox) event.getTarget();
advancedPanel.setSelectedItem(row);
Listbox listColumn = (Listbox) row.getFellow("listColumn" + row.getId());
Listbox listOperator = (Listbox) row.getFellow("listOperator" + row.getId());
if (listbox.getId().equals(listColumn.getId()) || listbox.getId().equals(listOperator.getId())) {
if (listbox.getId().equals(listColumn.getId())) {
ListItem column = listColumn.getSelectedItem();
if (column != null) {
addOperators(column, listOperator);
}
}
Component componentFrom = getEditorCompQueryFrom(row);
Component componentTo = getEditorCompQueryTo(row);
addRowEditor(componentFrom, (ListCell) row.getFellow("cellQueryFrom" + row.getId()));
addRowEditor(componentTo, (ListCell) row.getFellow("cellQueryTo" + row.getId()));
}
} else if (event.getTarget() == fQueryName) {
int index = fQueryName.getSelectedIndex();
if (index < 0) {
if (fQueryName.getSelectedItem() == null || fQueryName.getSelectedItem().equals(m_sTipText)) {
return;
}
} else if (index == 0) {
// no query - wipe and start over.
List<?> rowList = advancedPanel.getChildren();
for (int rowIndex = rowList.size() - 1; rowIndex >= 1; rowIndex--) rowList.remove(rowIndex);
createFields();
fQueryName.setSelectedIndex(-1);
fQueryName.setText(m_sTipText);
} else
parseUserQuery(userQueries[index - 1]);
}
} else //
if (Events.ON_CLICK.equals(event.getName())) {
// Toolbar Buttons actions
if (event.getTarget() instanceof ToolBarButton) {
ToolBarButton button = (ToolBarButton) event.getTarget();
if ("btnNewAdv".equals(button.getAttribute("name").toString())) {
createFields();
} else if ("btnDeleteAdv".equals(button.getAttribute("name").toString())) {
int index = advancedPanel.getSelectedIndex();
if (index >= 0) {
cmd_delete();
}
} else if ("btnSaveAdv".equals(button.getAttribute("name").toString())) {
// Save the query but don't overwrite the Last query
cmd_save(false);
}
} else // Confirm panel actions
if (event.getTarget() instanceof Button) {
Button btn = (Button) event.getTarget();
if ("btnOkSimple".equals(btn.getName())) {
cmd_ok_Simple();
dispose();
} else if ("btnOkAdv".equals(btn.getName())) {
cmd_ok_Advanced();
dispose();
} else if ("btnCancel".equals(btn.getName())) {
m_isCancel = true;
dispose();
} else if ("btnNew".equals(btn.getName())) {
m_query = MQuery.getNoRecordQuery(m_tableName, true);
m_total = 0;
m_createNew = true;
dispose();
}
}
} else if (Events.ON_OK.equals(event.getName())) {
if (winLookupRecord.equals(event.getTarget())) {
cmd_ok_Simple();
dispose();
} else if (winAdvanced.equals(event.getTarget())) {
cmd_ok_Advanced();
dispose();
}
// Check simple panel fields
for (WEditor editor : m_sEditors) {
if (editor.getComponent() == event.getTarget()) {
cmd_ok_Simple();
dispose();
}
}
// Check simple panel fields
for (WEditor editor : m_sEditors2) {
if (editor != null && editor.getComponent() == event.getTarget()) {
cmd_ok_Simple();
dispose();
}
}
} else if (Events.ON_FOCUS.equals(event.getName())) {
if (event.getTarget() == fQueryName) {
// fQueryName received the focus - delete the tip text so the user can type without
// having to delete the tip.
int index = fQueryName.getSelectedIndex();
if (index < 0) {
if (fQueryName.getSelectedItem() == null || fQueryName.getSelectedItem().equals(m_sTipText)) {
fQueryName.setSelectedIndex(-1);
fQueryName.setText("");
}
}
}
} else if (Events.ON_BLUR.equals(event.getName())) {
if (event.getTarget() == fQueryName) {
// fQueryName lost the focus. If the field is blank, replace the tip text.
if (fQueryName.getSelectedItem() != null && fQueryName.getSelectedItem().equals("")) {
fQueryName.setText(m_sTipText);
}
}
}
}
use of org.adempiere.webui.editor.WEditor in project adempiere by adempiere.
the class ProcessPanel method formatEditor.
public void formatEditor(CEditor editor1, CEditor editor2) {
//
WEditor editor = (WEditor) editor1;
WEditor editorTo = (WEditor) editor2;
configColumns(editor, editorTo);
//
if (editor == null) {
return;
}
//streach component to fill grid cell
editor.fillHorizontal();
//setup editor context menu
WEditorPopupMenu popupMenu;
popupMenu = editor.getPopupMenu();
if (popupMenu != null) {
popupMenu.addMenuListener((ContextMenuListener) editor);
mainPanel.appendChild(popupMenu);
}
//
Div div = new Div();
div.setAlign("right");
Label label = editor.getLabel();
div.appendChild(label);
if (label.getDecorator() != null)
div.appendChild(label.getDecorator());
//
currentRow.appendChild(div);
// Add Child
cols += 2;
//
Hbox box;
if (editorTo != null) {
box = new Hbox();
box.appendChild(editor.getComponent());
} else {
currentRow.appendChild(editor.getComponent());
m_separators.add(null);
return;
}
// The 2nd range editor
editorTo.fillHorizontal();
//setup editor context menu
popupMenu = editorTo.getPopupMenu();
if (popupMenu != null) {
popupMenu.addMenuListener((ContextMenuListener) editorTo);
mainPanel.appendChild(popupMenu);
}
//
Label separator = new Label(" - ");
m_separators.add(separator);
box.appendChild(separator);
box.appendChild(editorTo.getComponent());
// Add
currentRow.appendChild(box);
}
use of org.adempiere.webui.editor.WEditor in project adempiere by adempiere.
the class ProcessPanel method setComponentVisibility.
@Override
public void setComponentVisibility(int index, Boolean visible, Boolean isRange) {
WEditor editor = (WEditor) getEditor(index);
WEditor editorTo = (WEditor) getEditorTo(index);
if (visible) {
if (!editor.isVisible()) {
// Also makes the label visible
editor.setVisible(true);
if (isRange && editorTo != null) {
m_separators.get(index).setVisible(true);
editorTo.setVisible(true);
}
}
} else if (editor.isVisible()) {
// Also hides the label
editor.setVisible(false);
if (isRange && editorTo != null) {
m_separators.get(index).setText("");
editorTo.setVisible(false);
}
}
}
Aggregations