Search in sources :

Example 1 with MMenu

use of org.compiere.model.MMenu 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());
    }
}
Also used : MColumn(org.compiere.model.MColumn) X_ASP_Field(org.compiere.model.X_ASP_Field) MTab(org.compiere.model.MTab) MMenu(org.compiere.model.MMenu) MWindow(org.compiere.model.MWindow) X_ASP_Tab(org.compiere.model.X_ASP_Tab) MBrowse(org.adempiere.model.MBrowse) MForm(org.compiere.model.MForm) MTask(org.compiere.model.MTask) X_ASP_Task(org.compiere.model.X_ASP_Task) X_ASP_Form(org.compiere.model.X_ASP_Form) X_ASP_Window(org.compiere.model.X_ASP_Window) MField(org.compiere.model.MField) X_ASP_Browse(org.eevolution.model.X_ASP_Browse)

Example 2 with MMenu

use of org.compiere.model.MMenu in project adempiere by adempiere.

the class NavBarDesktop method createHomeTab.

private void createHomeTab() {
    Tabpanel homeTab = new Tabpanel();
    windowContainer.addWindow(homeTab, Msg.getMsg(Env.getCtx(), "Home").replaceAll("&", ""), false);
    Anchorlayout anchorLayout = new Anchorlayout();
    homeTab.appendChild(anchorLayout);
    // Dashboard content
    Anchorchildren anchorchildren = null;
    int currentColumnNo = 0;
    String sql = "SELECT COUNT(DISTINCT COLUMNNO) " + "FROM PA_DASHBOARDCONTENT " + "WHERE (AD_CLIENT_ID=0 OR AD_CLIENT_ID=?) AND ISACTIVE='Y'";
    int noOfCols = DB.getSQLValue(null, sql, Env.getAD_Client_ID(Env.getCtx()));
    int width = noOfCols <= 0 ? 100 : 100 / noOfCols;
    sql = "SELECT x.*, m.AD_MENU_ID " + "FROM PA_DASHBOARDCONTENT x " + "LEFT OUTER JOIN AD_MENU m ON x.AD_WINDOW_ID=m.AD_WINDOW_ID " + "WHERE (x.AD_CLIENT_ID=0 OR x.AD_CLIENT_ID=?) AND x.ISACTIVE='Y' " + "AND x.zulfilepath not in (?, ?, ?) " + "ORDER BY x.COLUMNNO, x.AD_CLIENT_ID, x.LINE ";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
        pstmt.setString(2, ACTIVITIES_PATH);
        pstmt.setString(3, FAVOURITES_PATH);
        pstmt.setString(4, VIEWS_PATH);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            int columnNo = rs.getInt(X_PA_DashboardContent.COLUMNNAME_ColumnNo);
            if (anchorchildren == null || currentColumnNo != columnNo) {
                anchorchildren = new Anchorchildren();
                anchorLayout.appendChild(anchorchildren);
                anchorchildren.setWidth(width + "%");
                anchorchildren.setStyle("padding: 5px");
                currentColumnNo = columnNo;
            }
            Panel panel = new Panel();
            panel.setStyle("margin-bottom:10px");
            panel.setTitle(rs.getString(X_PA_DashboardContent.COLUMNNAME_Name));
            String description = rs.getString(X_PA_DashboardContent.COLUMNNAME_Description);
            if (description != null)
                panel.setTooltiptext(description);
            String collapsible = rs.getString(X_PA_DashboardContent.COLUMNNAME_IsCollapsible);
            panel.setCollapsible(collapsible.equals("Y"));
            panel.setBorder("normal");
            anchorchildren.appendChild(panel);
            Panelchildren content = new Panelchildren();
            panel.appendChild(content);
            boolean panelEmpty = true;
            // HTML content
            String htmlContent = rs.getString(X_PA_DashboardContent.COLUMNNAME_HTML);
            if (htmlContent != null) {
                StringBuffer result = new StringBuffer("<html><head>");
                URL url = getClass().getClassLoader().getResource("org/compiere/images/PAPanel.css");
                InputStreamReader ins;
                try {
                    ins = new InputStreamReader(url.openStream());
                    BufferedReader bufferedReader = new BufferedReader(ins);
                    String cssLine;
                    while ((cssLine = bufferedReader.readLine()) != null) result.append(cssLine + "\n");
                } catch (IOException e1) {
                    logger.log(Level.SEVERE, e1.getLocalizedMessage(), e1);
                }
                result.append("</head><body><div class=\"content\">\n");
                //	            	if(description != null)
                //	            		result.append("<h2>" + description + "</h2>\n");
                result.append(stripHtml(htmlContent, false) + "<br>\n");
                result.append("</div>\n</body>\n</html>\n</html>");
                Html html = new Html();
                html.setContent(result.toString());
                content.appendChild(html);
                panelEmpty = false;
            }
            // Window
            int AD_Window_ID = rs.getInt(X_PA_DashboardContent.COLUMNNAME_AD_Window_ID);
            if (AD_Window_ID > 0) {
                int AD_Menu_ID = rs.getInt(X_AD_Menu.COLUMNNAME_AD_Menu_ID);
                ToolBarButton btn = new ToolBarButton(String.valueOf(AD_Menu_ID));
                MMenu menu = new MMenu(Env.getCtx(), AD_Menu_ID, null);
                btn.setLabel(menu.getName());
                btn.addEventListener(Events.ON_CLICK, this);
                content.appendChild(btn);
                panelEmpty = false;
            }
            // Goal
            int PA_Goal_ID = rs.getInt(X_PA_DashboardContent.COLUMNNAME_PA_Goal_ID);
            if (PA_Goal_ID > 0) {
                String goalDisplay = rs.getString(X_PA_DashboardContent.COLUMNNAME_GoalDisplay);
                MGoal goal = new MGoal(Env.getCtx(), PA_Goal_ID, null);
                WGraph graph = new WGraph(goal, 55, false, true, !(X_PA_DashboardContent.GOALDISPLAY_Chart.equals(goalDisplay)), X_PA_DashboardContent.GOALDISPLAY_Chart.equals(goalDisplay));
                content.appendChild(graph);
                panelEmpty = false;
            }
            // ZUL file url
            String url = rs.getString(X_PA_DashboardContent.COLUMNNAME_ZulFilePath);
            if (url != null) {
                try {
                    Component component = Executions.createComponents(url, content, null);
                    if (component != null) {
                        if (component instanceof DashboardPanel) {
                            DashboardPanel dashboardPanel = (DashboardPanel) component;
                            if (!dashboardPanel.getChildren().isEmpty()) {
                                content.appendChild(dashboardPanel);
                                dashboardRunnable.add(dashboardPanel);
                                panelEmpty = false;
                            }
                        } else {
                            content.appendChild(component);
                            panelEmpty = false;
                        }
                    }
                } catch (Exception e) {
                    logger.log(Level.WARNING, "Failed to create components. zul=" + url, e);
                }
            }
            if (panelEmpty)
                panel.detach();
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, "Failed to create dashboard content", e);
    } finally {
        DB.close(rs, pstmt);
    }
    //
    //register as 0
    registerWindow(homeTab);
    if (!anchorLayout.getDesktop().isServerPushEnabled())
        anchorLayout.getDesktop().enableServerPush(true);
    dashboardRunnable.refreshDashboard();
    dashboardThread = new Thread(dashboardRunnable, "UpdateInfo");
    dashboardThread.setDaemon(true);
    dashboardThread.start();
}
Also used : Anchorchildren(org.zkoss.zul.Anchorchildren) ToolBarButton(org.adempiere.webui.component.ToolBarButton) InputStreamReader(java.io.InputStreamReader) WGraph(org.adempiere.webui.apps.graph.WGraph) Anchorlayout(org.zkoss.zul.Anchorlayout) Html(org.zkoss.zul.Html) PreparedStatement(java.sql.PreparedStatement) Panelchildren(org.zkoss.zul.Panelchildren) IOException(java.io.IOException) MMenu(org.compiere.model.MMenu) URL(java.net.URL) IOException(java.io.IOException) DashboardPanel(org.adempiere.webui.dashboard.DashboardPanel) SidePanel(org.adempiere.webui.panel.SidePanel) HeaderPanel(org.adempiere.webui.panel.HeaderPanel) DashboardPanel(org.adempiere.webui.dashboard.DashboardPanel) Panel(org.zkoss.zul.Panel) ResultSet(java.sql.ResultSet) BufferedReader(java.io.BufferedReader) Component(org.zkoss.zk.ui.Component) Tabpanel(org.adempiere.webui.component.Tabpanel) MGoal(org.compiere.model.MGoal)

Example 3 with MMenu

use of org.compiere.model.MMenu in project adempiere by adempiere.

the class NavBar2Desktop method createHomeTab.

private void createHomeTab() {
    Tabpanel homeTab = new Tabpanel();
    windowContainer.addWindow(homeTab, Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Home")), false);
    Anchorlayout anchorLayout = new Anchorlayout();
    anchorLayout.setVflex("1");
    anchorLayout.setHflex("1");
    homeTab.appendChild(anchorLayout);
    // Dashboard content
    Anchorchildren anchorChildren = null;
    int currentColumnNo = 0;
    String sql = "SELECT COUNT(DISTINCT COLUMNNO) " + "FROM PA_DASHBOARDCONTENT " + "WHERE (AD_CLIENT_ID=0 OR AD_CLIENT_ID=?) AND ISACTIVE='Y'";
    int noOfCols = DB.getSQLValue(null, sql, Env.getAD_Client_ID(Env.getCtx()));
    int width = noOfCols <= 0 ? 100 : 100 / noOfCols;
    sql = "SELECT x.*, m.AD_MENU_ID " + "FROM PA_DASHBOARDCONTENT x " + "LEFT OUTER JOIN AD_MENU m ON x.AD_WINDOW_ID=m.AD_WINDOW_ID " + "WHERE (x.AD_CLIENT_ID=0 OR x.AD_CLIENT_ID=?) AND x.ISACTIVE='Y' " + "AND x.zulfilepath not in (?, ?) " + "ORDER BY x.COLUMNNO, x.AD_CLIENT_ID, x.LINE ";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
        pstmt.setString(2, ACTIVITIES_PATH);
        pstmt.setString(3, FAVOURITES_PATH);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            int columnNo = rs.getInt(X_PA_DashboardContent.COLUMNNAME_ColumnNo);
            if (anchorChildren == null || currentColumnNo != columnNo) {
                anchorChildren = new Anchorchildren();
                anchorLayout.appendChild(anchorChildren);
                anchorChildren.setWidth(width + "%");
                currentColumnNo = columnNo;
            }
            Panel panel = new Panel();
            panel.setStyle("margin-bottom:10px");
            panel.setTitle(rs.getString(X_PA_DashboardContent.COLUMNNAME_Name));
            String description = rs.getString(X_PA_DashboardContent.COLUMNNAME_Description);
            if (description != null)
                panel.setTooltiptext(description);
            String collapsible = rs.getString(X_PA_DashboardContent.COLUMNNAME_IsCollapsible);
            panel.setCollapsible(collapsible.equals("Y"));
            panel.setBorder("normal");
            anchorChildren.appendChild(panel);
            Panelchildren content = new Panelchildren();
            panel.appendChild(content);
            boolean panelEmpty = true;
            // HTML content
            String htmlContent = rs.getString(X_PA_DashboardContent.COLUMNNAME_HTML);
            if (htmlContent != null) {
                StringBuffer result = new StringBuffer("<html><head>");
                URL url = getClass().getClassLoader().getResource("org/compiere/images/PAPanel.css");
                InputStreamReader ins;
                try {
                    ins = new InputStreamReader(url.openStream());
                    BufferedReader bufferedReader = new BufferedReader(ins);
                    String cssLine;
                    while ((cssLine = bufferedReader.readLine()) != null) result.append(cssLine + "\n");
                } catch (IOException e1) {
                    logger.log(Level.SEVERE, e1.getLocalizedMessage(), e1);
                }
                result.append("</head><body><div class=\"content\">\n");
                //	            	if(description != null)
                //	            		result.append("<h2>" + description + "</h2>\n");
                result.append(stripHtml(htmlContent, false) + "<br>\n");
                result.append("</div>\n</body>\n</html>\n</html>");
                Html html = new Html();
                html.setContent(result.toString());
                content.appendChild(html);
                panelEmpty = false;
            }
            // Window
            int AD_Window_ID = rs.getInt(X_PA_DashboardContent.COLUMNNAME_AD_Window_ID);
            if (AD_Window_ID > 0) {
                int AD_Menu_ID = rs.getInt(X_AD_Menu.COLUMNNAME_AD_Menu_ID);
                ToolBarButton btn = new ToolBarButton(String.valueOf(AD_Menu_ID));
                MMenu menu = new MMenu(Env.getCtx(), AD_Menu_ID, null);
                btn.setLabel(menu.getName());
                btn.addEventListener(Events.ON_CLICK, this);
                content.appendChild(btn);
                panelEmpty = false;
            }
            // Goal
            int PA_Goal_ID = rs.getInt(X_PA_DashboardContent.COLUMNNAME_PA_Goal_ID);
            if (PA_Goal_ID > 0) {
                String goalDisplay = rs.getString(X_PA_DashboardContent.COLUMNNAME_GoalDisplay);
                MGoal goal = new MGoal(Env.getCtx(), PA_Goal_ID, null);
                WGraph graph = new WGraph(goal, 55, false, true, !(X_PA_DashboardContent.GOALDISPLAY_Chart.equals(goalDisplay)), X_PA_DashboardContent.GOALDISPLAY_Chart.equals(goalDisplay));
                content.appendChild(graph);
                panelEmpty = false;
            }
            // ZUL file url
            String url = rs.getString(X_PA_DashboardContent.COLUMNNAME_ZulFilePath);
            if (url != null) {
                try {
                    Component component = Executions.createComponents(url, content, null);
                    if (component != null) {
                        if (component instanceof DashboardPanel) {
                            DashboardPanel dashboardPanel = (DashboardPanel) component;
                            if (!dashboardPanel.getChildren().isEmpty()) {
                                content.appendChild(dashboardPanel);
                                dashboardRunnable.add(dashboardPanel);
                                panelEmpty = false;
                            }
                        } else {
                            content.appendChild(component);
                            panelEmpty = false;
                        }
                    }
                } catch (Exception e) {
                    logger.log(Level.WARNING, "Failed to create components. zul=" + url, e);
                }
            }
            if (panelEmpty)
                panel.detach();
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, "Failed to create dashboard content", e);
    } finally {
        DB.close(rs, pstmt);
    }
    //
    //register as 0
    registerWindow(homeTab);
    if (!anchorLayout.getDesktop().isServerPushEnabled())
        anchorLayout.getDesktop().enableServerPush(true);
    dashboardRunnable.refreshDashboard();
    dashboardThread = new Thread(dashboardRunnable, "UpdateInfo");
    dashboardThread.setDaemon(true);
    dashboardThread.start();
}
Also used : Anchorchildren(org.zkoss.zul.Anchorchildren) ToolBarButton(org.adempiere.webui.component.ToolBarButton) InputStreamReader(java.io.InputStreamReader) WGraph(org.adempiere.webui.apps.graph.WGraph) Anchorlayout(org.zkoss.zul.Anchorlayout) Html(org.zkoss.zul.Html) PreparedStatement(java.sql.PreparedStatement) Panelchildren(org.zkoss.zul.Panelchildren) IOException(java.io.IOException) MMenu(org.compiere.model.MMenu) URL(java.net.URL) IOException(java.io.IOException) DashboardPanel(org.adempiere.webui.dashboard.DashboardPanel) SidePanel(org.adempiere.webui.panel.SidePanel) HeaderPanel(org.adempiere.webui.panel.HeaderPanel) DashboardPanel(org.adempiere.webui.dashboard.DashboardPanel) Panel(org.zkoss.zul.Panel) ResultSet(java.sql.ResultSet) BufferedReader(java.io.BufferedReader) Component(org.zkoss.zk.ui.Component) Tabpanel(org.adempiere.webui.component.Tabpanel) MGoal(org.compiere.model.MGoal)

Aggregations

MMenu (org.compiere.model.MMenu)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 WGraph (org.adempiere.webui.apps.graph.WGraph)2 Tabpanel (org.adempiere.webui.component.Tabpanel)2 ToolBarButton (org.adempiere.webui.component.ToolBarButton)2 DashboardPanel (org.adempiere.webui.dashboard.DashboardPanel)2 HeaderPanel (org.adempiere.webui.panel.HeaderPanel)2 SidePanel (org.adempiere.webui.panel.SidePanel)2 MGoal (org.compiere.model.MGoal)2 Component (org.zkoss.zk.ui.Component)2 Anchorchildren (org.zkoss.zul.Anchorchildren)2 Anchorlayout (org.zkoss.zul.Anchorlayout)2 Html (org.zkoss.zul.Html)2 Panel (org.zkoss.zul.Panel)2 Panelchildren (org.zkoss.zul.Panelchildren)2