use of org.compiere.model.MUserQuery in project adempiere by adempiere.
the class Find method cmd_delete.
// parseValue
/**
* Delete
*/
private void cmd_delete() {
advancedTable.stopEditor(false);
DefaultTableModel model = (DefaultTableModel) advancedTable.getModel();
int row = advancedTable.getSelectedRow();
if (row >= 0) {
model.removeRow(row);
} else {
//delete the whole thing
MUserQuery uq = null;
Object o = fQueryName.getSelectedItem();
if (userQueries != null && o != null) {
String selected = o.toString();
for (int i = 0; i < userQueries.length; i++) {
if (userQueries[i].getName().equals(selected)) {
uq = userQueries[i];
break;
}
}
}
if (uq != null) {
uq.delete(true);
userQueries = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID);
String[] queries = new String[userQueries.length];
for (int i = 0; i < userQueries.length; i++) queries[i] = userQueries[i].getName();
fQueryName.setModel(new DefaultComboBoxModel(queries));
fQueryName.setValue("");
int cnt = model.getRowCount();
for (int i = cnt - 1; i >= 0; i--) model.removeRow(i);
advancedTable.invalidate();
}
}
cmd_refresh();
advancedTable.requestFocusInWindow();
}
use of org.compiere.model.MUserQuery in project adempiere by adempiere.
the class Find method cmd_save.
// cmd_new
/**
* Save the advanced query in the database using the query name. If the query name is set,
* the query will be updated or a new query saved.
* @param saveQuery Save the query as the Last Query. Set to true when running the query.
* Set to false to only save using the query name.
*/
private void cmd_save(boolean saveQuery) {
// Update or save the query if there is a valid name.
Object selected = fQueryName.getSelectedItem();
if (selected == null) {
return;
}
// Generate the query code
StringBuffer code = codeUserQuery();
String name = selected.toString();
if (name.equals(m_sNew) || name.equals(m_sLast) || name.equals(m_sTipText) || Util.isEmpty(name, true)) {
// No name to save to. Just run the query.
} else {
MUserQuery uq = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID, name);
if (code.length() > 0) {
// New or updated
if (// Create a new record
uq == null) {
uq = new MUserQuery(Env.getCtx(), 0, null);
uq.setName(name);
uq.setAD_Table_ID(m_AD_Table_ID);
//red1 UserQuery [ 1798539 ] taking in new field from Compiere
uq.setAD_Tab_ID(m_AD_Tab_ID);
//red1 - [ 1798539 ] missing in Compiere delayed source :-)
uq.setAD_User_ID(Env.getAD_User_ID(Env.getCtx()));
}
// Update the query code
uq.setCode(code.toString());
} else if (// Delete the query
code.length() <= 0) {
if (uq.delete(true)) {
ADialog.info(m_targetWindowNo, this, "Deleted", name);
refreshUserQueries();
} else
ADialog.warn(m_targetWindowNo, this, "DeleteError", name);
return;
}
//
if (uq.save()) {
//ADialog.info (m_targetWindowNo, this, "Saved", name);
refreshUserQueries();
} else
ADialog.warn(m_targetWindowNo, this, "SaveError", name);
}
// Save the query as the Last query run.
if (saveQuery) {
MUserQuery last = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID, m_sLast);
if (code.length() > 0) {
// New or update
if (// Create a new record
last == null) {
last = new MUserQuery(Env.getCtx(), 0, null);
last.setName(m_sLast);
last.setAD_Table_ID(m_AD_Table_ID);
last.setAD_Tab_ID(m_AD_Tab_ID);
last.setAD_User_ID(Env.getAD_User_ID(Env.getCtx()));
}
// Update the query code
last.setCode(code.toString());
} else if (code.length() <= 0) {
// Delete the query
if (!last.delete(true))
ADialog.warn(m_targetWindowNo, this, "DeleteError", name);
return;
}
if (!last.save())
ADialog.warn(m_targetWindowNo, this, "SaveError", name);
}
}
Aggregations