Search in sources :

Example 16 with Component

use of org.zkoss.zk.ui.Component in project adempiere by adempiere.

the class FindWindow method addSelectionColumn.

// setValues
/**
     *  Add Selection Column to first Tab
     *  @param mField field
    **/
public void addSelectionColumn(GridField mField) {
    log.config(mField.getHeader());
    int displayLength = mField.getDisplayLength();
    if (displayLength <= 0 || displayLength > FIELDLENGTH)
        mField.setDisplayLength(FIELDLENGTH);
    else
        displayLength = 0;
    //  Editor
    WEditor editor = null;
    Label label = null;
    if (mField.isRangeLookup()) {
        Hbox box = new Hbox();
        editor = WebEditorFactory.getEditor(mField, false);
        label = editor.getLabel();
        editor.setMandatory(false);
        editor.setReadWrite(true);
        editor.dynamicDisplay();
        Component fieldLabel = editor.getComponent();
        box.appendChild(editor.getComponent());
        rangeFirstEditor.add(mField.getColumnName());
        // The Editor
        WEditor toRangeEditor = WebEditorFactory.getEditor(mField, false);
        // New Field value to be updated to editor
        toRangeEditor.setMandatory(false);
        toRangeEditor.setReadWrite(true);
        toRangeEditor.dynamicDisplay();
        //
        m_sEditors2.add(toRangeEditor);
        Label separator = new Label(" - ");
        box.appendChild(separator);
        Component fieldLabel1 = toRangeEditor.getComponent();
        box.appendChild(toRangeEditor.getComponent());
        if (//  set it back
        displayLength > 0)
            mField.setDisplayLength(displayLength);
        //
        if (isTwoColumns) {
            if (!isPair)
                panel = new Row();
        } else
            panel = new Row();
        panel.appendChild(LayoutUtils.makeRightAlign(label));
        panel.appendChild(box);
        contentSimpleRows.appendChild(panel);
        fieldLabel.addEventListener(Events.ON_OK, this);
        fieldLabel1.addEventListener(Events.ON_OK, this);
    } else {
        editor = WebEditorFactory.getEditor(mField, false);
        label = editor.getLabel();
        editor.setMandatory(false);
        editor.setReadWrite(true);
        editor.dynamicDisplay();
        Component fieldLabel = editor.getComponent();
        if (//  set it back
        displayLength > 0)
            mField.setDisplayLength(displayLength);
        //
        if (isTwoColumns) {
            if (!isPair)
                panel = new Row();
        } else
            panel = new Row();
        panel.appendChild(LayoutUtils.makeRightAlign(label));
        panel.appendChild(fieldLabel);
        contentSimpleRows.appendChild(panel);
        fieldLabel.addEventListener(Events.ON_OK, this);
        m_sEditors2.add(null);
    }
    m_sEditors.add(editor);
}
Also used : Hbox(org.zkoss.zul.Hbox) Label(org.adempiere.webui.component.Label) WEditor(org.adempiere.webui.editor.WEditor) Row(org.adempiere.webui.component.Row) Component(org.zkoss.zk.ui.Component)

Example 17 with Component

use of org.zkoss.zk.ui.Component in project adempiere by adempiere.

the class FindWindow method onEvent.

// addSelectionColumn
public void onEvent(Event event) throws Exception {
    if (Events.ON_SELECT.equals(event.getName())) {
        if (event.getTarget() instanceof Listbox) {
            ListItem row = (ListItem) (event.getTarget().getParent().getParent());
            Listbox listbox = (Listbox) event.getTarget();
            advancedPanel.setSelectedItem(row);
            Listbox listColumn = (Listbox) row.getFellow("listColumn" + row.getId());
            Listbox listOperator = (Listbox) row.getFellow("listOperator" + row.getId());
            if (listbox.getId().equals(listColumn.getId()) || listbox.getId().equals(listOperator.getId())) {
                if (listbox.getId().equals(listColumn.getId())) {
                    ListItem column = listColumn.getSelectedItem();
                    if (column != null) {
                        addOperators(column, listOperator);
                    }
                }
                Component componentFrom = getEditorCompQueryFrom(row);
                Component componentTo = getEditorCompQueryTo(row);
                addRowEditor(componentFrom, (ListCell) row.getFellow("cellQueryFrom" + row.getId()));
                addRowEditor(componentTo, (ListCell) row.getFellow("cellQueryTo" + row.getId()));
            }
        } else if (event.getTarget() == fQueryName) {
            int index = fQueryName.getSelectedIndex();
            if (index < 0) {
                if (fQueryName.getSelectedItem() == null || fQueryName.getSelectedItem().equals(m_sTipText)) {
                    return;
                }
            } else if (index == 0) {
                // no query - wipe and start over.
                List<?> rowList = advancedPanel.getChildren();
                for (int rowIndex = rowList.size() - 1; rowIndex >= 1; rowIndex--) rowList.remove(rowIndex);
                createFields();
                fQueryName.setSelectedIndex(-1);
                fQueryName.setText(m_sTipText);
            } else
                parseUserQuery(userQueries[index - 1]);
        }
    } else //
    if (Events.ON_CLICK.equals(event.getName())) {
        //  Toolbar Buttons actions
        if (event.getTarget() instanceof ToolBarButton) {
            ToolBarButton button = (ToolBarButton) event.getTarget();
            if ("btnNewAdv".equals(button.getAttribute("name").toString())) {
                createFields();
            } else if ("btnDeleteAdv".equals(button.getAttribute("name").toString())) {
                int index = advancedPanel.getSelectedIndex();
                if (index >= 0) {
                    cmd_delete();
                }
            } else if ("btnSaveAdv".equals(button.getAttribute("name").toString())) {
                // Save the query but don't overwrite the Last query
                cmd_save(false);
            }
        } else //  Confirm panel actions
        if (event.getTarget() instanceof Button) {
            Button btn = (Button) event.getTarget();
            if ("btnOkSimple".equals(btn.getName())) {
                cmd_ok_Simple();
                dispose();
            } else if ("btnOkAdv".equals(btn.getName())) {
                cmd_ok_Advanced();
                dispose();
            } else if ("btnCancel".equals(btn.getName())) {
                m_isCancel = true;
                dispose();
            } else if ("btnNew".equals(btn.getName())) {
                m_query = MQuery.getNoRecordQuery(m_tableName, true);
                m_total = 0;
                m_createNew = true;
                dispose();
            }
        }
    } else if (Events.ON_OK.equals(event.getName())) {
        if (winLookupRecord.equals(event.getTarget())) {
            cmd_ok_Simple();
            dispose();
        } else if (winAdvanced.equals(event.getTarget())) {
            cmd_ok_Advanced();
            dispose();
        }
        // Check simple panel fields
        for (WEditor editor : m_sEditors) {
            if (editor.getComponent() == event.getTarget()) {
                cmd_ok_Simple();
                dispose();
            }
        }
        // Check simple panel fields
        for (WEditor editor : m_sEditors2) {
            if (editor != null && editor.getComponent() == event.getTarget()) {
                cmd_ok_Simple();
                dispose();
            }
        }
    } else if (Events.ON_FOCUS.equals(event.getName())) {
        if (event.getTarget() == fQueryName) {
            // fQueryName received the focus - delete the tip text so the user can type without 
            // having to delete the tip.
            int index = fQueryName.getSelectedIndex();
            if (index < 0) {
                if (fQueryName.getSelectedItem() == null || fQueryName.getSelectedItem().equals(m_sTipText)) {
                    fQueryName.setSelectedIndex(-1);
                    fQueryName.setText("");
                }
            }
        }
    } else if (Events.ON_BLUR.equals(event.getName())) {
        if (event.getTarget() == fQueryName) {
            // fQueryName lost the focus. If the field is blank, replace the tip text.
            if (fQueryName.getSelectedItem() != null && fQueryName.getSelectedItem().equals("")) {
                fQueryName.setText(m_sTipText);
            }
        }
    }
}
Also used : ToolBarButton(org.adempiere.webui.component.ToolBarButton) Button(org.adempiere.webui.component.Button) ToolBarButton(org.adempiere.webui.component.ToolBarButton) ListItem(org.adempiere.webui.component.ListItem) WEditor(org.adempiere.webui.editor.WEditor) Listbox(org.adempiere.webui.component.Listbox) Component(org.zkoss.zk.ui.Component)

Example 18 with Component

use of org.zkoss.zk.ui.Component in project adempiere by adempiere.

the class DynamicDashBoard method updateUI.

@SuppressWarnings("unchecked")
public void updateUI() {
    Component c = (Component) this.getParent();
    updateView();
    if (this.getPreviousSibling() != null)
        this.getPreviousSibling().setParent(null);
}
Also used : Component(org.zkoss.zk.ui.Component)

Example 19 with Component

use of org.zkoss.zk.ui.Component in project adempiere by adempiere.

the class DefaultDesktop method onEvent.

public void onEvent(Event event) {
    Component comp = event.getTarget();
    String eventName = event.getName();
    if (eventName.equals(Events.ON_CLICK)) {
        if (comp instanceof ToolBarButton) {
            ToolBarButton btn = (ToolBarButton) comp;
            int menuId = 0;
            try {
                menuId = Integer.valueOf(btn.getName());
            } catch (Exception e) {
            }
            if (menuId > 0)
                onMenuSelected(menuId);
        }
    }
}
Also used : ToolBarButton(org.adempiere.webui.component.ToolBarButton) Component(org.zkoss.zk.ui.Component) IOException(java.io.IOException)

Example 20 with Component

use of org.zkoss.zk.ui.Component 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)

Aggregations

Component (org.zkoss.zk.ui.Component)70 IOException (java.io.IOException)8 HtmlBasedComponent (org.zkoss.zk.ui.HtmlBasedComponent)8 Checkbox (org.adempiere.webui.component.Checkbox)7 ToolBarButton (org.adempiere.webui.component.ToolBarButton)7 Div (org.zkoss.zul.Div)7 Listitem (org.zkoss.zul.Listitem)7 MapLayer (au.org.emii.portal.menu.MapLayer)6 Button (org.adempiere.webui.component.Button)6 Tabpanel (org.adempiere.webui.component.Tabpanel)6 WEditor (org.adempiere.webui.editor.WEditor)6 ParseException (org.json.simple.parser.ParseException)6 Event (org.zkoss.zk.ui.event.Event)6 MapComposer (au.org.emii.portal.composer.MapComposer)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 DashboardPanel (org.adempiere.webui.dashboard.DashboardPanel)5 HeaderPanel (org.adempiere.webui.panel.HeaderPanel)5 SidePanel (org.adempiere.webui.panel.SidePanel)5 UiException (org.zkoss.zk.ui.UiException)5