use of org.adempiere.webui.exception.ApplicationException in project adempiere by adempiere.
the class ADForm method openForm.
/**
* Create a new form corresponding to the specified identifier
*
* @param adFormID The unique identifier for the form type
* @return The created form
*/
public static ADForm openForm(int adFormID) {
Object obj;
ADForm form;
String webClassName = "";
MForm mform = new MForm(Env.getCtx(), adFormID, null);
String richClassName = mform.getClassname();
String name = mform.get_Translation(MForm.COLUMNNAME_Name);
if (mform.get_ID() == 0 || richClassName == null) {
throw new ApplicationException("There is no form associated with the specified selection");
} else {
logger.info("AD_Form_ID=" + adFormID + " - Class=" + richClassName);
//static lookup
webClassName = ADClassNameMap.get(richClassName);
//fallback to dynamic translation
if (webClassName == null || webClassName.trim().length() == 0) {
webClassName = translateFormClassName(richClassName);
}
if (webClassName == null) {
throw new ApplicationException("Web UI form not implemented for the swing form " + richClassName);
}
try {
// Create instance w/o parameters
obj = ADForm.class.getClassLoader().loadClass(webClassName).newInstance();
} catch (Exception e) {
throw new ApplicationException("The selected web user interface custom form '" + webClassName + "' is not accessible.", e);
}
try {
if (obj instanceof ADForm) {
form = (ADForm) obj;
form.init(adFormID, name);
return form;
} else if (obj instanceof IFormController) {
IFormController customForm = (IFormController) obj;
Object o = customForm.getForm();
if (o instanceof ADForm) {
form = (ADForm) o;
form.setICustomForm(customForm);
form.init(adFormID, name);
return form;
} else
throw new ApplicationException("The web user interface custom form '" + webClassName + "' cannot be displayed in the web user interface.");
} else {
throw new ApplicationException("The web user interface custom form '" + webClassName + "' cannot be displayed in the web user interface.");
}
} catch (Exception ex) {
logger.log(Level.SEVERE, "Class=" + webClassName + ", AD_Form_ID=" + adFormID, ex);
throw new ApplicationException("The web user interface custom form '" + webClassName + "' failed to initialise:" + ex);
}
}
}
use of org.adempiere.webui.exception.ApplicationException in project adempiere by adempiere.
the class WListbox method loadTable.
// setColorColumn
/**
* Load Table from ResultSet - The ResultSet is not closed.
*
* @param rs ResultSet containing data t enter int the table.
* The contents must conform to the column layout defined in
* {@link #prepareTable(ColumnInfo[], String, String, boolean, String)}
*/
public void loadTable(ResultSet rs) {
int no = 0;
// model row
int row = 0;
// model column
int col = 0;
Object data = null;
// index into result set
int rsColIndex = 0;
// result set columns start with 1
int rsColOffset = 1;
// class of the column
Class columnClass;
if (getLayout() == null) {
throw new UnsupportedOperationException("Layout not defined");
}
clearTable();
try {
while (rs.next()) {
row = getItemCount();
setRowCount(row + 1);
rsColOffset = 1;
no++;
for (col = 0; col < m_layout.length; col++) {
//reset the data value
data = null;
columnClass = m_layout[col].getColClass();
rsColIndex = col + rsColOffset;
if (isColumnClassMismatch(col, columnClass)) {
throw new ApplicationException("Cannot enter a " + columnClass.getName() + " in column " + col + ". " + "An object of type " + m_modelHeaderClass.get(col).getSimpleName() + " was expected.");
}
if (columnClass == IDColumn.class && !m_layout[col].getColSQL().equals("'Row' AS \"Row\"")) {
data = new IDColumn(rs.getInt(rsColIndex));
} else if (columnClass == IDColumn.class && m_layout[col].getColSQL().equals("'Row' AS \"Row\"")) {
data = new IDColumn(no);
} else if (columnClass == Boolean.class) {
data = rs.getString(rsColIndex) == null ? new Boolean(false) : new Boolean(rs.getString(rsColIndex).equals("Y"));
} else if (columnClass == Timestamp.class) {
data = rs.getTimestamp(rsColIndex);
} else if (columnClass == BigDecimal.class) {
data = rs.getBigDecimal(rsColIndex);
} else if (columnClass == Double.class) {
data = new Double(rs.getDouble(rsColIndex));
} else if (columnClass == Integer.class) {
data = new Integer(rs.getInt(rsColIndex));
} else if (columnClass == KeyNamePair.class) {
// TODO factor out this generation
String display = rs.getString(rsColIndex);
int key = rs.getInt(rsColIndex + 1);
data = new KeyNamePair(key, display);
rsColOffset++;
} else {
// TODO factor out this cleanup
String s = rs.getString(rsColIndex);
if (s != null) {
// problems with NCHAR
data = s.trim();
} else {
data = null;
}
}
// store in underlying model
getModel().setDataAt(data, row, col);
}
}
} catch (SQLException exception) {
logger.log(Level.SEVERE, "", exception);
}
autoSize();
if (getShowTotals())
addTotals(m_layout);
// repaint the table
this.repaint();
logger.config("Row(rs)=" + getRowCount());
return;
}
use of org.adempiere.webui.exception.ApplicationException in project adempiere by adempiere.
the class WListbox method loadTable.
/**
* Load Table from Object Array.
* @param pos array of Persistent Objects
*/
public void loadTable(PO[] pos) {
int row = 0;
int col = 0;
// index into the PO array
int poIndex = 0;
String columnName;
Object data;
Class columnClass;
if (m_layout == null) {
throw new UnsupportedOperationException("Layout not defined");
}
// Clear Table
clearTable();
for (poIndex = 0; poIndex < pos.length; poIndex++) {
PO myPO = pos[poIndex];
row = getRowCount();
setRowCount(row + 1);
for (col = 0; col < m_layout.length; col++) {
columnName = m_layout[col].getColSQL();
data = myPO.get_Value(columnName);
if (data != null) {
columnClass = m_layout[col].getColClass();
if (isColumnClassMismatch(col, columnClass)) {
throw new ApplicationException("Cannot enter a " + columnClass.getName() + " in column " + col + ". " + "An object of type " + m_modelHeaderClass.get(col).getSimpleName() + " was expected.");
}
if (columnClass == IDColumn.class) {
data = new IDColumn(((Integer) data).intValue());
} else if (columnClass == Double.class) {
data = new Double(((BigDecimal) data).doubleValue());
}
}
// store
getModel().setDataAt(data, row, col);
}
}
autoSize();
if (getShowTotals())
addTotals(m_layout);
// repaint the table
this.repaint();
logger.config("Row(array)=" + getRowCount());
return;
}
use of org.adempiere.webui.exception.ApplicationException in project adempiere by adempiere.
the class LoginPanel method validateLogin.
/**
* validates user name and password when logging in
*
**/
public void validateLogin() {
Login login = new Login(ctx);
String userId = txtUserId.getValue();
String userPassword = txtPassword.getValue();
//check is token
String token = (String) txtPassword.getAttribute("user.token.hash");
if (token != null && token.equals(userPassword)) {
userPassword = "";
int AD_Session_ID = (Integer) txtPassword.getAttribute("user.token.sid");
MSession session = new MSession(Env.getCtx(), AD_Session_ID, null);
if (session.get_ID() == AD_Session_ID) {
MUser user = MUser.get(Env.getCtx(), session.getCreatedBy());
if (BrowserToken.validateToken(session, user, token)) {
userPassword = user.getPassword();
}
}
}
KeyNamePair[] rolesKNPairs = login.getRoles(userId, userPassword);
if (rolesKNPairs == null || rolesKNPairs.length == 0)
throw new WrongValueException("User Id or Password invalid!!!");
else {
String langName = null;
if (lstLanguage.getSelectedItem() != null)
langName = (String) lstLanguage.getSelectedItem().getLabel();
else
langName = Language.getBaseLanguage().getName();
Language language = findLanguage(langName);
wndLogin.loginOk(userId, userPassword);
// Elaine 2009/02/06
Env.setContext(ctx, UserPreference.LANGUAGE_NAME, language.getName());
Locales.setThreadLocal(language.getLocale());
String timeoutText = getUpdateTimeoutTextScript();
if (!Strings.isEmpty(timeoutText))
Clients.response("zkLocaleJavaScript2", new AuScript(null, timeoutText));
}
// This temporary validation code is added to check the reported bug
// [ adempiere-ZK Web Client-2832968 ] User context lost?
// https://sourceforge.net/tracker/?func=detail&atid=955896&aid=2832968&group_id=176962
// it's harmless, if there is no bug then this must never fail
Session currSess = Executions.getCurrent().getDesktop().getSession();
currSess.setAttribute("Check_AD_User_ID", Env.getAD_User_ID(ctx));
// End of temporary code for [ adempiere-ZK Web Client-2832968 ] User context lost?
Env.setContext(ctx, BrowserToken.REMEMBER_ME, chkRememberMe.isChecked());
/* Check DB version */
String version = DB.getSQLValueString(null, "SELECT Version FROM AD_System");
// Identical DB version
if (!Adempiere.DB_VERSION.equals(version)) {
String AD_Message = "DatabaseVersionError";
// Code assumes Database version {0}, but Database has Version {1}.
// complete message
String msg = Msg.getMsg(ctx, AD_Message);
msg = MessageFormat.format(msg, new Object[] { Adempiere.DB_VERSION, version });
throw new ApplicationException(msg);
}
}
use of org.adempiere.webui.exception.ApplicationException in project adempiere by adempiere.
the class WPOSTable method loadTable.
// loadTable
/**
* Load Table from Object Array.
* @param pos array of Persistent Objects
*/
public void loadTable(PO[] pos) {
int row = 0;
int col = 0;
// index into the PO array
int poIndex = 0;
String columnName;
Object data;
Class columnClass;
if (m_layout == null) {
throw new UnsupportedOperationException("Layout not defined");
}
// Clear Table
clearTable();
for (poIndex = 0; poIndex < pos.length; poIndex++) {
PO myPO = pos[poIndex];
row = getRowCount();
setRowCount(row + 1);
for (col = 0; col < m_layout.length; col++) {
columnName = m_layout[col].getColSQL();
data = myPO.get_Value(columnName);
if (data != null) {
columnClass = m_layout[col].getColClass();
if (isColumnClassMismatch(col, columnClass)) {
throw new ApplicationException("Cannot enter a " + columnClass.getName() + " in column " + col + ". " + "An object of type " + m_modelHeaderClass.get(col).getSimpleName() + " was expected.");
}
if (columnClass == IDColumn.class) {
data = new IDColumn(((Integer) data).intValue());
} else if (columnClass == Double.class) {
data = new Double(((BigDecimal) data).doubleValue());
}
}
// store
getModel().setDataAt(data, row, col);
}
}
autoSize();
if (getShowTotals())
addTotals(m_layout);
// repaint the table
this.repaint();
logger.config("Row(array)=" + getRowCount());
return;
}
Aggregations