use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class VHRPayPrint method loadPaymentRuleInfo.
// loadPaymentRule
/**
* PaymentRule changed - load DocumentNo, NoPayments,
* enable/disable EFT, Print
*/
private void loadPaymentRuleInfo() {
ValueNamePair pp = (ValueNamePair) fPaymentRule.getSelectedItem();
if (pp == null)
return;
String PaymentRule = pp.getValue();
log.info("PaymentRule=" + PaymentRule);
fNoPayments.setText(" ");
int C_PaySelection_ID = ((KeyNamePair) fPaySelect.getSelectedItem()).getKey();
String msg = loadPaymentRuleInfo(C_PaySelection_ID, PaymentRule);
if (noPayments != null)
fNoPayments.setText(noPayments);
bProcess.setEnabled(PaymentRule.equals("T"));
if (documentNo != null)
fDocumentNo.setValue(documentNo);
if (msg != null && msg.length() > 0)
ADialog.error(m_WindowNo, panel, msg);
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class MRefList method getList.
// getListDescription
/**
* Get Reference List (translated)
* @param ctx context
* @param AD_Reference_ID reference
* @param optional if true add "",""
* @return List or null
*/
public static ValueNamePair[] getList(Properties ctx, int AD_Reference_ID, boolean optional) {
String ad_language = Env.getAD_Language(ctx);
boolean isBaseLanguage = Env.isBaseLanguage(ad_language, "AD_Ref_List");
String sql = isBaseLanguage ? "SELECT Value, Name FROM AD_Ref_List WHERE AD_Reference_ID=? AND IsActive='Y' ORDER BY Name" : "SELECT r.Value, t.Name FROM AD_Ref_List_Trl t" + " INNER JOIN AD_Ref_List r ON (r.AD_Ref_List_ID=t.AD_Ref_List_ID)" + " WHERE r.AD_Reference_ID=? AND t.AD_Language=? AND r.IsActive='Y'" + " ORDER BY t.Name";
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList<ValueNamePair> list = new ArrayList<ValueNamePair>();
if (optional)
list.add(new ValueNamePair("", ""));
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Reference_ID);
if (!isBaseLanguage)
pstmt.setString(2, ad_language);
rs = pstmt.executeQuery();
while (rs.next()) list.add(new ValueNamePair(rs.getString(1), rs.getString(2)));
rs.close();
pstmt.close();
pstmt = null;
} catch (SQLException e) {
s_log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
ValueNamePair[] retValue = new ValueNamePair[list.size()];
list.toArray(retValue);
return retValue;
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class Find method parseUserQuery.
/**
* Parse delimited string into user query
* Old field sequence: column, operator, value, value to
* New field sequence: column, operator, value, value to, and/or, left brackets, right brackets
* @param userQuery
*/
private void parseUserQuery(MUserQuery userQuery) {
String code = userQuery.getCode();
log.fine("Parse user query: " + code);
String[] segments = code.split(Pattern.quote(SEGMENT_SEPARATOR), -1);
advancedTable.stopEditor(true);
DefaultTableModel model = (DefaultTableModel) advancedTable.getModel();
int cnt = model.getRowCount();
for (int i = cnt - 1; i >= 0; i--) model.removeRow(i);
for (int i = 0; i < segments.length; i++) {
String[] fields = segments[i].split(Pattern.quote(FIELD_SEPARATOR));
model.addRow(new Object[] { "", "", null, MQuery.OPERATORS[MQuery.EQUAL_INDEX], null, null, "" });
String columnName = null;
for (int j = 0; j < fields.length; j++) {
// column
if (j == 0) {
for (ValueNamePair vnp : columnValueNamePairs) {
if (vnp.getValue().equals(fields[j])) {
model.setValueAt(vnp, i, INDEX_COLUMNNAME);
columnName = fields[j];
break;
}
}
} else // operator
if (j == 1) {
for (ValueNamePair vnp : MQuery.OPERATORS) {
if (vnp.getValue().equals(fields[j])) {
model.setValueAt(vnp, i, INDEX_OPERATOR);
break;
}
}
} else // value
if (j == 2 && fields[j].length() > 0) {
GridField field = getTargetMField(columnName);
Object value = parseString(field, fields[j]);
model.setValueAt(value, i, INDEX_VALUE);
} else // value 2
if (j == 3 && fields[j].length() > 0) {
GridField field = getTargetMField(columnName);
Object value = parseString(field, fields[j]);
model.setValueAt(value, i, INDEX_VALUE2);
} else // and/or
if (j == 4 && fields[j].length() > 0) {
if (i != 0)
model.setValueAt(fields[j], i, INDEX_ANDOR);
} else if (j == 5 && fields[j].length() > 0) {
model.setValueAt(fields[j], i, INDEX_LEFTBRACKET);
} else if (j == 6 && fields[j].length() > 0) {
model.setValueAt(fields[j], i, INDEX_RIGHTBRACKET);
}
}
}
advancedTable.invalidate();
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class WLogin method doPost.
// doGet
/**
* Process the HTTP Post request.
* <pre>
* - Optionally create Session
* - Check database connection
* - LoginInfo from request?
* - Yes: DoLogin success ?
* - Yes: return (second) preferences page
* - No: return (first) user/password page
* - No: User Principal ?
* - Yes: DoLogin success ?
* - Yes: return (second) preferences page
* - No: return (first) user/password page
* - No: return (first) user/password page
* </pre>
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("");
// Create New Session
HttpSession sess = request.getSession(true);
sess.setMaxInactiveInterval(MobileEnv.TIMEOUT);
// Get Cookie Properties
Properties cProp = MobileUtil.getCookieProprties(request);
// Create Context
MobileSessionCtx wsc = MobileSessionCtx.get(request);
// Page
MobileDoc doc = null;
// Check DB connection
if (!DB.isConnected()) {
String msg = Msg.getMsg(wsc.ctx, "WLoginNoDB");
if (msg.equals("WLoginNoDB"))
msg = "No Database Connection";
doc = MobileDoc.createWindow(msg);
}
// Get Parameters: Role, Client, Org, Warehouse, Date
String role = MobileUtil.getParameter(request, WLogin.P_ROLE);
String client = MobileUtil.getParameter(request, WLogin.P_CLIENT);
String org = MobileUtil.getParameter(request, WLogin.P_ORG);
String language = MobileUtil.getParameter(request, Env.LANGUAGE);
if (role != null && client != null && org != null) {
// Get Info from Context - User, Role, Client
int AD_User_ID = Env.getAD_User_ID(wsc.ctx);
int AD_Role_ID = Env.getAD_Role_ID(wsc.ctx);
int AD_Client_ID = Env.getAD_Client_ID(wsc.ctx);
// Not available in context yet - Org, Warehouse
int AD_Org_ID = -1;
int M_Warehouse_ID = -1;
// Get latest info from context
try {
int req_role = Integer.parseInt(role);
if (req_role != AD_Role_ID) {
log.fine("AD_Role_ID - changed from " + AD_Role_ID);
AD_Role_ID = req_role;
Env.setContext(wsc.ctx, "#AD_Role_ID", AD_Role_ID);
}
log.fine("AD_Role_ID = " + AD_Role_ID);
//
int req_client = Integer.parseInt(client);
if (req_client != AD_Client_ID) {
log.fine("AD_Client_ID - changed from " + AD_Client_ID);
AD_Client_ID = req_client;
Env.setContext(wsc.ctx, "#AD_Client_ID", AD_Client_ID);
}
log.fine("AD_Client_ID = " + AD_Client_ID);
//
AD_Org_ID = Integer.parseInt(org);
log.fine("AD_Org_ID = " + AD_Org_ID);
//
} catch (Exception e) {
log.log(Level.SEVERE, "Parameter", e);
MobileUtil.createTimeoutPage(request, response, this, Msg.getMsg(wsc.ctx, "ParameterMissing"));
return;
}
// Check Login info and set environment
wsc.loginInfo = checkLogin(wsc.ctx, AD_User_ID, AD_Role_ID, AD_Client_ID, AD_Org_ID, M_Warehouse_ID);
if (wsc.loginInfo == null) {
MobileUtil.createErrorPage(request, response, this, Msg.getMsg(wsc.ctx, "RoleInconsistent"));
return;
}
// Set Date
Timestamp ts = MobileUtil.getParameterAsDate(request, WLogin.P_DATE);
if (ts == null)
ts = new Timestamp(System.currentTimeMillis());
// JDBC format
Env.setContext(wsc.ctx, "#Date", ts);
cProp.setProperty(P_ROLE, Integer.toString(AD_Role_ID));
cProp.setProperty(P_ORG, Integer.toString(AD_Org_ID));
// Update Cookie - overwrite
if (cProp != null) {
Cookie cookie = new Cookie(MobileEnv.COOKIE_INFO, MobileUtil.propertiesEncode(cProp));
cookie.setComment("(c) adempiere, Inc - Jorg Janke");
cookie.setSecure(false);
cookie.setPath("/");
if (cProp.size() == 0)
// delete cookie
cookie.setMaxAge(0);
else
// 30 days in seconds 60*60*24*30
cookie.setMaxAge(2592000);
response.addCookie(cookie);
}
response.sendRedirect(MobileEnv.getBaseDirectory("/WMenu"));
return;
} else // Login Info from request?
{
// Get Parameters: UserName/Password
String usr = MobileUtil.getParameter(request, P_USERNAME);
String pwd = MobileUtil.getParameter(request, P_PASSWORD);
// Get Principle
Principal userPrincipal = request.getUserPrincipal();
log.info("Principal=" + userPrincipal + "; User=" + usr);
// Login info not from request and not pre-authorized
if (userPrincipal == null && (usr == null || pwd == null))
doc = createFirstPage(cProp, request, "");
else // Login info from request or authorized
{
KeyNamePair[] roles = null;
Login login = new Login(wsc.ctx);
// Pre-authorized
if (userPrincipal != null) {
roles = login.getRoles(userPrincipal);
usr = userPrincipal.getName();
} else
roles = login.getRoles(usr, pwd);
//
if (roles == null)
doc = createFirstPage(cProp, request, Msg.getMsg(wsc.ctx, "UserPwdError"));
else {
String sql = "SELECT AD_Role_ID, Name FROM AD_Role WHERE IsMobileAccessible='Y'";
ArrayList<KeyNamePair> validRoles = new ArrayList();
try {
ValueNamePair[] mobileRoles = DB.getValueNamePairs(sql, false, null);
for (KeyNamePair role1 : roles) {
for (ValueNamePair mobileRole : mobileRoles) {
if (role1.getKey() == Integer.parseInt(mobileRole.getValue())) {
validRoles.add(role1);
break;
}
}
}
roles = new KeyNamePair[validRoles.size()];
roles = validRoles.toArray(roles);
} catch (Exception e) {
// IsMobileAccessible not supported, allow any role
}
cProp.setProperty(P_USERNAME, usr);
cProp.setProperty(Env.LANGUAGE, language);
if (roles.length == 0)
doc = createFirstPage(cProp, request, Msg.getMsg(wsc.ctx, "UserPwdError"));
else {
String roleData = (cProp.getProperty(P_ROLE, null));
doc = createSecondPage(cProp, request, MobileUtil.convertToOption(roles, roleData), "");
// Create adempiere Session - user id in ctx
MSession.get(wsc.ctx, request.getRemoteAddr(), request.getRemoteHost(), sess.getId());
MobileUtil.createResponseFragment(request, response, this, cProp, doc);
return;
}
}
}
}
MobileUtil.createResponse(request, response, this, cProp, doc, false);
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class Preference method cmd_save.
// load
/**
* Save Settings
*/
private void cmd_save() {
log.config("");
// UI
// AutoCommit
Ini.setProperty(Ini.P_A_COMMIT, (autoCommit.isSelected()));
Env.setAutoCommit(Env.getCtx(), autoCommit.isSelected());
Ini.setProperty(Ini.P_A_NEW, (autoNew.isSelected()));
Env.setAutoNew(Env.getCtx(), autoNew.isSelected());
// AdempiereSys
Ini.setProperty(Ini.P_ADEMPIERESYS, adempiereSys.isSelected());
// LogMigrationScript
Ini.setProperty(Ini.P_LOGMIGRATIONSCRIPT, logMigrationScript.isSelected());
if (MSystem.isSwingRememberPasswordAllowed()) {
// AutoLogin
Ini.setProperty(Ini.P_A_LOGIN, (autoLogin.isSelected()));
// Save Password
Ini.setProperty(Ini.P_STORE_PWD, (storePassword.isSelected()));
} else {
Ini.setProperty(Ini.P_A_LOGIN, false);
Ini.setProperty(Ini.P_STORE_PWD, false);
}
// Show Acct Tab
Ini.setProperty(Ini.P_SHOW_ACCT, (showAcct.isSelected()));
Env.setContext(Env.getCtx(), "#ShowAcct", (showAcct.isSelected()));
// Show Trl Tab
Ini.setProperty(Ini.P_SHOW_TRL, (showTrl.isSelected()));
Env.setContext(Env.getCtx(), "#ShowTrl", (showTrl.isSelected()));
// Show Advanced Tab
Ini.setProperty(Ini.P_SHOW_ADVANCED, (showAdvanced.isSelected()));
Env.setContext(Env.getCtx(), "#ShowAdvanced", (showAdvanced.isSelected()));
// ConnectionProfile
ValueNamePair ppNew = (ValueNamePair) connectionProfile.getSelectedItem();
String cpNew = ppNew.getValue();
String cpOld = CConnection.get().getConnectionProfile();
CConnection.get().setConnectionProfile(cpNew);
if (!cpNew.equals(cpOld) && (cpNew.equals(CConnection.PROFILE_WAN) || cpOld.equals(CConnection.PROFILE_WAN)))
ADialog.info(0, this, "ConnectionProfileChange");
Ini.setProperty(Ini.P_CACHE_WINDOW, cacheWindow.isSelected());
// Print Preview
Ini.setProperty(Ini.P_PRINTPREVIEW, (printPreview.isSelected()));
// Validate Connection on Startup
Ini.setProperty(Ini.P_VALIDATE_CONNECTION_ON_STARTUP, (validateConnectionOnStartup.isSelected()));
// Single Instance per Window
Ini.setProperty(Ini.P_SINGLE_INSTANCE_PER_WINDOW, (singleInstancePerWindow.isSelected()));
// Open Window Maximized
Ini.setProperty(Ini.P_OPEN_WINDOW_MAXIMIZED, (openWindowMaximized.isSelected()));
// TraceLevel/File
Level level = (Level) traceLevel.getSelectedItem();
CLogMgt.setLevel(level);
Ini.setProperty(Ini.P_TRACELEVEL, level.getName());
Ini.setProperty(Ini.P_TRACEFILE, traceFile.isSelected());
// Printer
String printer = (String) fPrinter.getSelectedItem();
Env.setContext(Env.getCtx(), "#Printer", printer);
Ini.setProperty(Ini.P_PRINTER, printer);
// Date (remove seconds)
java.sql.Timestamp ts = (java.sql.Timestamp) fDate.getValue();
if (ts != null)
Env.setContext(Env.getCtx(), "#Date", ts);
// Charset
Charset charset = (Charset) fCharset.getSelectedItem();
Ini.setProperty(Ini.P_CHARSET, charset.name());
//UI
ValueNamePair laf = plafEditor.getSelectedLook();
ValueNamePair theme = plafEditor.getSelectedTheme();
if (laf != null) {
String clazz = laf.getValue();
String currentLaf = UIManager.getLookAndFeel().getClass().getName();
if (clazz != null && clazz.length() > 0 && !currentLaf.equals(clazz)) {
//laf changed
AdempierePLAF.setPLAF(laf, theme, true);
AEnv.updateUI();
} else {
if (UIManager.getLookAndFeel() instanceof MetalLookAndFeel) {
MetalTheme currentTheme = MetalLookAndFeel.getCurrentTheme();
String themeClass = currentTheme.getClass().getName();
String sTheme = theme.getValue();
if (sTheme != null && sTheme.length() > 0 && !sTheme.equals(themeClass)) {
ValueNamePair plaf = new ValueNamePair(UIManager.getLookAndFeel().getClass().getName(), UIManager.getLookAndFeel().getName());
AdempierePLAF.setPLAF(plaf, theme, true);
AEnv.updateUI();
}
}
}
}
Ini.saveProperties(Ini.isClient());
dispose();
}
Aggregations