use of org.compiere.model.MForm in project adempiere by adempiere.
the class ASPGenerateLevel method addNodeToLevel.
// doIt
private void addNodeToLevel(MTreeNode nn) {
// Add Menu
MMenu menu = new MMenu(getCtx(), nn.getNode_ID(), get_TrxName());
if (menu.getAction().equals(MMenu.ACTION_Window)) {
MWindow window = new MWindow(getCtx(), menu.getAD_Window_ID(), get_TrxName());
int asp_window_id = DB.getSQLValueEx(get_TrxName(), "SELECT ASP_Window_ID FROM ASP_Window WHERE ASP_Level_ID = ? AND AD_Window_ID = ?", p_ASP_Level_ID, window.getAD_Window_ID());
X_ASP_Window aspWindow = null;
if (asp_window_id < 1) {
// Add Window, Tabs and Fields (if IsGenerateFields)
aspWindow = new X_ASP_Window(getCtx(), 0, get_TrxName());
aspWindow.setASP_Level_ID(p_ASP_Level_ID);
aspWindow.setAD_Window_ID(window.getAD_Window_ID());
aspWindow.setASP_Status(p_ASP_Status);
if (aspWindow.save()) {
noWindows++;
asp_window_id = aspWindow.getASP_Window_ID();
}
} else {
aspWindow = new X_ASP_Window(getCtx(), asp_window_id, get_TrxName());
}
// tabs
for (MTab tab : window.getTabs(true, get_TrxName())) {
int asp_tab_id = DB.getSQLValueEx(get_TrxName(), "SELECT ASP_Tab_ID FROM ASP_Tab WHERE ASP_Window_ID = ? AND AD_Tab_ID = ?", asp_window_id, tab.getAD_Tab_ID());
X_ASP_Tab aspTab = null;
if (asp_tab_id < 1) {
aspTab = new X_ASP_Tab(getCtx(), 0, get_TrxName());
aspTab.setASP_Window_ID(asp_window_id);
aspTab.setAD_Tab_ID(tab.getAD_Tab_ID());
aspTab.setASP_Status(p_ASP_Status);
aspTab.setAllFields(!p_IsGenerateFields);
if (aspTab.save()) {
noTabs++;
asp_tab_id = aspTab.getASP_Tab_ID();
}
} else {
aspTab = new X_ASP_Tab(getCtx(), asp_tab_id, get_TrxName());
}
// fields
for (MField field : tab.getFields(true, get_TrxName())) {
if (p_IsGenerateFields) {
if (DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM ASP_Field WHERE ASP_Tab_ID = ? AND AD_Field_ID = ?", aspTab.getASP_Tab_ID(), field.getAD_Field_ID()) < 1) {
X_ASP_Field aspField = new X_ASP_Field(getCtx(), 0, get_TrxName());
aspField.setASP_Tab_ID(aspTab.getASP_Tab_ID());
aspField.setAD_Field_ID(field.getAD_Field_ID());
aspField.setASP_Status(p_ASP_Status);
if (aspField.save())
noFields++;
}
}
// verify if a field is a button and assign permission to the corresponding process
MColumn column = MColumn.get(getCtx(), field.getAD_Column_ID());
if (column.getAD_Reference_ID() == DisplayType.Button) {
if (column.getAD_Process_ID() > 0) {
generateProcess(column.getAD_Process_ID());
}
}
}
}
} else if (menu.getAction().equals(MMenu.ACTION_Process) || menu.getAction().equals(MMenu.ACTION_Report)) {
generateProcess(menu.getAD_Process_ID());
} else if (menu.getAction().equals(MMenu.ACTION_Form)) {
// Add Form
MForm form = new MForm(getCtx(), menu.getAD_Form_ID(), get_TrxName());
if (DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM ASP_Form WHERE ASP_Level_ID = ? AND AD_Form_ID = ?", p_ASP_Level_ID, form.getAD_Form_ID()) < 1) {
X_ASP_Form aspForm = new X_ASP_Form(getCtx(), 0, get_TrxName());
aspForm.setASP_Level_ID(p_ASP_Level_ID);
aspForm.setAD_Form_ID(form.getAD_Form_ID());
aspForm.setASP_Status(p_ASP_Status);
if (aspForm.save())
noForms++;
}
} else if (menu.getAction().equals(MMenu.ACTION_SmartBrowse)) {
// Add Browse
MBrowse browse = new MBrowse(getCtx(), menu.getAD_Browse_ID(), get_TrxName());
if (DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM ASP_Browse WHERE ASP_Level_ID = ? AND AD_Browse_ID = ?", p_ASP_Level_ID, browse.getAD_Browse_ID()) < 1) {
X_ASP_Browse aspBrowse = new X_ASP_Browse(getCtx(), 0, get_TrxName());
aspBrowse.setASP_Level_ID(p_ASP_Level_ID);
aspBrowse.setAD_Browse_ID(browse.getAD_Browse_ID());
aspBrowse.setASP_Status(p_ASP_Status);
if (aspBrowse.save())
noBrowses++;
}
} else if (menu.getAction().equals(MMenu.ACTION_Task)) {
// Add Task
MTask task = new MTask(getCtx(), menu.getAD_Task_ID(), get_TrxName());
if (DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM ASP_Task WHERE ASP_Level_ID = ? AND AD_Task_ID = ?", p_ASP_Level_ID, task.getAD_Task_ID()) < 1) {
X_ASP_Task aspTask = new X_ASP_Task(getCtx(), 0, get_TrxName());
aspTask.setASP_Level_ID(p_ASP_Level_ID);
aspTask.setAD_Task_ID(task.getAD_Task_ID());
aspTask.setASP_Status(p_ASP_Status);
if (aspTask.save())
noTasks++;
}
} else if (menu.getAction().equals(MMenu.ACTION_WorkFlow)) {
generateWorkflow(menu.getAD_Workflow_ID());
}
}
use of org.compiere.model.MForm 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.compiere.model.MForm in project adempiere by adempiere.
the class FormElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("ADFormNameID"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("ADFormNameID");
int id = get_ID(ctx, "AD_Form", name);
MForm m_Form = new MForm(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_Form_ID") != null && Integer.parseInt(atts.getValue("AD_Form_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Form.setAD_Form_ID(Integer.parseInt(atts.getValue("AD_Form_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Form", m_Form);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Form.setClassname(atts.getValue("Classname"));
m_Form.setIsBetaFunctionality(Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue());
m_Form.setAccessLevel(atts.getValue("AccessLevel"));
m_Form.setDescription(getStringValue(atts, "Description"));
m_Form.setEntityType(atts.getValue("EntityType"));
m_Form.setHelp(getStringValue(atts, "Help"));
m_Form.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_Form.setName(atts.getValue("Name"));
if (m_Form.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Form.getName(), "Form", m_Form.get_ID(), AD_Backup_ID, Object_Status, "AD_Form", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Form"));
} else {
record_log(ctx, 0, m_Form.getName(), "Form", m_Form.get_ID(), AD_Backup_ID, Object_Status, "AD_Form", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Form"));
throw new POSaveFailedException("Failed to save form definition");
}
} else {
element.skip = true;
}
}
use of org.compiere.model.MForm in project adempiere by adempiere.
the class WMenu method printNode.
// createPage
/**
* Print Menu Item
* @param node node
* @param ctx context
* @return string with node
*/
private StringBuffer printNode(MTreeNode node, Properties ctx) {
StringBuffer sb = new StringBuffer();
// Leaf
if (!node.isSummary()) {
/**
* <li id="menuXXXXX"><a href="...." onMouseOver="status='Menu Description';return true;">Menu Entry</a></li>
*/
String cssClassName = "";
String servletName = "";
if (node.isWindow()) {
cssClassName = "menuWindow";
servletName = "WWindow";
} else if (node.isForm()) {
cssClassName = "menuWindow";
servletName = "WForm";
} else if (node.isBrowse()) {
cssClassName = "menuWindow";
servletName = "WBrowse";
} else if (node.isReport()) {
cssClassName = "menuReport";
servletName = "WProcess";
} else if (node.isProcess()) {
cssClassName = "menuProcess";
servletName = "WProcess";
} else if (node.isWorkFlow()) {
cssClassName = "menuWorkflow";
servletName = "WWorkflow";
} else if (node.isTask()) {
cssClassName = "menuProcess";
servletName = "WTask";
} else
servletName = "WError";
String name = node.getName().replace('\'', ' ').replace('"', ' ');
String description = node.getDescription().replace('\'', ' ').replace('"', ' ');
//
sb.append("<li class=\"" + cssClassName + "\" id=\"" + // debug
node.getNode_ID() + "\"><a href=\"");
// Get URL
boolean standardURL = true;
if (node.isForm()) {
MForm form = new MForm(ctx, node.getNode_ID(), null);
if (form.getJSPURL() != null && form.getJSPURL().length() > 0) {
sb.append(form.getJSPURL());
standardURL = false;
}
}
if (// url = /appl/servletName?AD_Menu_ID=x
standardURL) {
sb.append(WebEnv.getBaseDirectory(servletName)).append("?AD_Menu_ID=").append(node.getNode_ID());
}
// remaining a tag
sb.append("\" title=\"" + description + "\" onClick=\"showLoadingWindow('" + WebEnv.getBaseDirectory("") + "')\">").append(// language set in MTree.getNodeDetails based on ctx
name).append("</a></li>\n");
} else {
/**
* <li class="foldHeader" onClick="changeMenu(event)">MenuEntry
* <ul style="display:none">
* ....
* </ul></li>
*/
String name = node.getName().replace('\'', ' ').replace('"', ' ');
sb.append("\n<li class=\"menuSummary\"" + " id=\"" + // debug
node.getNode_ID() + // summary node
"\" onClick=\"changeMenu(event);\">").append(name).append("\n");
}
return sb;
}
Aggregations