Search in sources :

Example 6 with Component

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

the class WWFActivity method onEvent.

public void onEvent(Event event) throws Exception {
    Component comp = event.getTarget();
    String eventName = event.getName();
    if (eventName.equals(Events.ON_CLICK)) {
        if (comp == bZoom)
            cmd_zoom();
        else if (comp == bOK) {
            Clients.showBusy(Msg.getMsg(Env.getCtx(), "Processing"));
            Events.echoEvent("onOK", this, null);
        } else if (comp == fAnswerButton)
            cmd_button();
    } else if (Events.ON_SELECT.equals(eventName) && comp == listbox) {
        m_index = listbox.getSelectedIndex();
        if (m_index >= 0)
            display(m_index);
    }
}
Also used : Component(org.zkoss.zk.ui.Component)

Example 7 with Component

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

the class AdempiereWebUI method loginCompleted.

/* (non-Javadoc)
	 * @see org.adempiere.webui.IWebClient#loginCompleted()
	 */
public void loginCompleted() {
    Properties ctx = Env.getCtx();
    // to reload preferences when the user refresh the browser
    userPreference = loadUserPreference(Env.getAD_User_ID(ctx));
    // Set the theme according to the user preferences.  If the theme changes, the page will
    // be reloaded again - so do this first thing.
    int theme_id = userPreference.getPropertyAsInt(UserPreference.P_ZK_THEME_PREFERENCE);
    if (theme_id > 0) {
        // If theme_id == 0, don't bother setting a new MTheme. Just use the current theme.
        MTheme theme = MTheme.get(ctx, theme_id);
        if (ThemeUtils.makeCurrent(theme)) {
            // Make the theme active and reload the page.
            return;
        }
    }
    ThemeUtils.addBrowserIconAndTitle(this.getPage());
    if (loginDesktop != null) {
        loginDesktop.detach();
        loginDesktop = null;
    }
    String langLogin = Env.getContext(ctx, Env.LANGUAGE);
    if (langLogin == null || langLogin.length() <= 0) {
        langLogin = langSession;
        Env.setContext(ctx, Env.LANGUAGE, langSession);
    }
    // Validate language
    Language language = Language.getLanguage(langLogin);
    String locale = Env.getContext(ctx, AEnv.LOCALE);
    if (locale != null && locale.length() > 0 && !language.getLocale().toString().equals(locale)) {
        String adLanguage = language.getAD_Language();
        Language tmp = Language.getLanguage(locale);
        language = new Language(tmp.getName(), adLanguage, tmp.getLocale(), tmp.isDecimalPoint(), tmp.getDateFormat().toPattern(), tmp.getMediaSize());
    } else {
        Language tmp = language;
        language = new Language(tmp.getName(), tmp.getAD_Language(), tmp.getLocale(), tmp.isDecimalPoint(), tmp.getDateFormat().toPattern(), tmp.getMediaSize());
    }
    Env.verifyLanguage(ctx, language);
    //Bug
    Env.setContext(ctx, Env.LANGUAGE, language.getAD_Language());
    //	Create adempiere Session - user id in ctx
    Execution exec = Executions.getCurrent();
    Session currSess = exec.getDesktop().getSession();
    HttpSession httpSess = (HttpSession) currSess.getNativeSession();
    MSession mSession = MSession.get(ctx, exec.getRemoteAddr(), exec.getRemoteHost(), httpSess.getId());
    //enable full interface, relook into this when doing preference
    Env.setContext(ctx, "#ShowTrl", true);
    Env.setContext(ctx, "#ShowAcct", MRole.getDefault().isShowAcct());
    Env.setContext(ctx, "#ShowAdvanced", true);
    //auto commit user preference
    String autoCommit = userPreference.getProperty(UserPreference.P_AUTO_COMMIT);
    Env.setAutoCommit(ctx, "true".equalsIgnoreCase(autoCommit) || "y".equalsIgnoreCase(autoCommit));
    //auto new user preference
    String autoNew = userPreference.getProperty(UserPreference.P_AUTO_NEW);
    Env.setAutoNew(ctx, "true".equalsIgnoreCase(autoNew) || "y".equalsIgnoreCase(autoNew));
    IDesktop d = (IDesktop) currSess.getAttribute("application.desktop");
    if (d != null && d instanceof IDesktop) {
        ExecutionCarryOver eco = (ExecutionCarryOver) currSess.getAttribute(EXECUTION_CARRYOVER_SESSION_KEY);
        if (eco != null) {
            //try restore
            try {
                appDesktop = (IDesktop) d;
                ExecutionCarryOver current = new ExecutionCarryOver(this.getPage().getDesktop());
                ExecutionCtrl ctrl = ExecutionsCtrl.getCurrentCtrl();
                Visualizer vi = ctrl.getVisualizer();
                eco.carryOver();
                Collection<Component> rootComponents = new ArrayList<Component>();
                try {
                    ctrl = ExecutionsCtrl.getCurrentCtrl();
                    ((DesktopCtrl) Executions.getCurrent().getDesktop()).setVisualizer(vi);
                    //detach root component from old page
                    Page page = appDesktop.getComponent().getPage();
                    Collection<?> collection = page.getRoots();
                    Object[] objects = new Object[0];
                    objects = collection.toArray(objects);
                    for (Object obj : objects) {
                        if (obj instanceof Component) {
                            ((Component) obj).detach();
                            rootComponents.add((Component) obj);
                        }
                    }
                    appDesktop.getComponent().detach();
                    DesktopCache desktopCache = ((SessionCtrl) currSess).getDesktopCache();
                    if (desktopCache != null)
                        desktopCache.removeDesktop(Executions.getCurrent().getDesktop());
                } catch (Exception e) {
                    appDesktop = null;
                } finally {
                    eco.cleanup();
                    current.carryOver();
                }
                if (appDesktop != null) {
                    //re-attach root components
                    for (Component component : rootComponents) {
                        try {
                            component.setPage(this.getPage());
                        } catch (UiException e) {
                        // e.printStackTrace();
                        // an exception is thrown here when refreshing the page, it seems is harmless to catch and ignore it
                        // i.e.: org.zkoss.zk.ui.UiException: Not unique in the ID space of [Page z_kg_0]: zk_comp_2
                        }
                    }
                    appDesktop.setPage(this.getPage());
                    currSess.setAttribute(EXECUTION_CARRYOVER_SESSION_KEY, current);
                }
                currSess.setAttribute(ZK_DESKTOP_SESSION_KEY, this.getPage().getDesktop());
            } catch (Throwable t) {
                //restore fail
                appDesktop = null;
            }
        }
    }
    if (appDesktop == null) {
        //create new desktop
        createDesktop();
        appDesktop.setClientInfo(clientInfo);
        appDesktop.createPart(this.getPage());
        currSess.setAttribute("application.desktop", appDesktop);
        ExecutionCarryOver eco = new ExecutionCarryOver(this.getPage().getDesktop());
        currSess.setAttribute(EXECUTION_CARRYOVER_SESSION_KEY, eco);
        currSess.setAttribute(ZK_DESKTOP_SESSION_KEY, this.getPage().getDesktop());
    }
    if ("Y".equalsIgnoreCase(Env.getContext(ctx, BrowserToken.REMEMBER_ME)) && MSystem.isZKRememberUserAllowed()) {
        MUser user = MUser.get(ctx);
        BrowserToken.save(mSession, user);
    } else {
        BrowserToken.remove();
    }
}
Also used : ArrayList(java.util.ArrayList) MTheme(org.compiere.model.MTheme) MSession(org.compiere.model.MSession) Page(org.zkoss.zk.ui.Page) SessionCtrl(org.zkoss.zk.ui.sys.SessionCtrl) Properties(java.util.Properties) ExecutionCtrl(org.zkoss.zk.ui.sys.ExecutionCtrl) Execution(org.zkoss.zk.ui.Execution) Language(org.compiere.util.Language) DesktopCtrl(org.zkoss.zk.ui.sys.DesktopCtrl) Component(org.zkoss.zk.ui.Component) MUser(org.compiere.model.MUser) HttpSession(javax.servlet.http.HttpSession) UiException(org.zkoss.zk.ui.UiException) IDesktop(org.adempiere.webui.desktop.IDesktop) UiException(org.zkoss.zk.ui.UiException) ExecutionCarryOver(org.zkoss.zk.ui.impl.ExecutionCarryOver) Visualizer(org.zkoss.zk.ui.sys.Visualizer) DesktopCache(org.zkoss.zk.ui.sys.DesktopCache) MSession(org.compiere.model.MSession) HttpSession(javax.servlet.http.HttpSession) Session(org.zkoss.zk.ui.Session)

Example 8 with Component

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

the class WBrowserListItemRenderer method onEvent.

@Override
public void onEvent(Event event) throws Exception {
    int col = -1;
    int row = -1;
    Object value = null;
    TableValueChangeEvent vcEvent = null;
    WTableColumn tableColumn;
    Component source = event.getTarget();
    if (isWithinListCell(source)) {
        row = getRowPosition(source);
        col = getColumnPosition(source);
        tableColumn = m_tableColumns.get(col);
        if (source instanceof Checkbox) {
            value = Boolean.valueOf(((Checkbox) source).isChecked());
        } else if (source instanceof Decimalbox) {
            value = ((Decimalbox) source).getValue();
        } else if (source instanceof Datebox) {
            value = ((Datebox) source).getValue();
        } else if (source instanceof Textbox) {
            value = ((Textbox) source).getValue();
        }
        if (value != null) {
            vcEvent = new TableValueChangeEvent(source, tableColumn.getHeaderValue().toString(), row, col, value, value);
            fireTableValueChange(vcEvent);
        }
    } else if (event.getTarget() instanceof WBrowserTable && Events.ON_SELECT.equals(event.getName())) {
        WBrowserTable table = (WBrowserTable) event.getTarget();
        if (table.isCheckmark()) {
            int cnt = table.getRowCount();
            if (cnt == 0 || !(table.getValueAt(0, 0) instanceof IDColumn))
                return;
            //update IDColumn
            tableColumn = m_tableColumns.get(0);
            for (int i = 0; i < cnt; i++) {
                IDColumn idcolumn = (IDColumn) table.getValueAt(i, 0);
                if (idcolumn != null) {
                    Listitem item = table.getItemAtIndex(i);
                    value = item.isSelected();
                    Boolean old = idcolumn.isSelected();
                    if (!old.equals(value)) {
                        vcEvent = new TableValueChangeEvent(source, tableColumn.getHeaderValue().toString(), i, 0, old, value);
                        fireTableValueChange(vcEvent);
                    }
                }
            }
        }
    }
    return;
}
Also used : Datebox(org.adempiere.webui.component.Datebox) WTableColumn(org.adempiere.webui.component.WTableColumn) Textbox(org.adempiere.webui.component.Textbox) Listitem(org.zkoss.zul.Listitem) IDColumn(org.compiere.minigrid.IDColumn) Decimalbox(org.zkoss.zul.Decimalbox) Checkbox(org.adempiere.webui.component.Checkbox) Component(org.zkoss.zk.ui.Component) TableValueChangeEvent(org.adempiere.webui.event.TableValueChangeEvent)

Example 9 with Component

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

the class WBrowserListItemRenderer method renderListHead.

/**
	 * Render the ListHead for the table with headers for the table columns.
	 *
	 * @param head	The ListHead component to render.
	 * @see #addColumn(String)
	 */
public void renderListHead(ListHead head) {
    Component header;
    WTableColumn column;
    for (int columnIndex = 0; columnIndex < m_tableColumns.size(); columnIndex++) {
        column = m_tableColumns.get(columnIndex);
        header = getListHeaderComponent(column.getHeaderValue(), columnIndex, column.getColumnClass());
        head.appendChild(header);
    }
    head.setSizable(true);
    return;
}
Also used : WTableColumn(org.adempiere.webui.component.WTableColumn) Component(org.zkoss.zk.ui.Component)

Example 10 with Component

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

the class GridTabRowRenderer method render.

/**
	 * @param row
	 * @param data
	 * @see RowRenderer#render(Row, Object)
	 */
public void render(Row row, Object[] data, int index) throws Exception {
    //don't render if not visible
    if (gridPanel != null && !gridPanel.isVisible()) {
        return;
    }
    if (grid == null)
        grid = (Grid) row.getParent().getParent();
    if (rowListener == null)
        rowListener = new RowListener((Grid) row.getParent().getParent());
    currentValues = data;
    int columnCount = gridTab.getTableModel().getColumnCount();
    GridField[] gridField = gridTab.getFields();
    Grid grid = (Grid) row.getParent().getParent();
    org.zkoss.zul.Columns columns = grid.getColumns();
    int rowIndex = row.getParent().getChildren().indexOf(row);
    if (paging != null && paging.getPageSize() > 0) {
        rowIndex = (paging.getActivePage() * paging.getPageSize()) + rowIndex;
    }
    int colIndex = -1;
    for (int i = 0; i < columnCount; i++) {
        if (!(gridField[i].isDisplayed())) {
            continue;
        }
        colIndex++;
        Div div = new Div();
        ThemeUtils.addSclass("ad-gridtabrowrenderer", div);
        org.zkoss.zul.Column column = (org.zkoss.zul.Column) columns.getChildren().get(colIndex);
        if (column.isVisible()) {
            Component component = getDisplayComponent(currentValues[i], gridField[i]);
            div.appendChild(component);
            //				if (compCount == 1) {
            //add hidden input component to help focusing to row
            div.appendChild(createAnchorInput());
            if (DisplayType.YesNo == gridField[i].getDisplayType() || DisplayType.Image == gridField[i].getDisplayType()) {
                ThemeUtils.addSclass("yes-no", div);
            //divStyle += "text-align:center; ";
            } else if (DisplayType.isNumeric(gridField[i].getDisplayType())) {
                ThemeUtils.addSclass("numeric", div);
            //divStyle += "text-align:right; ";
            }
        }
        div.setAttribute("columnName", gridField[i].getColumnName());
        div.addEventListener(Events.ON_CLICK, rowListener);
        div.addEventListener(Events.ON_DOUBLE_CLICK, rowListener);
        row.appendChild(div);
    }
    if (rowIndex == gridTab.getCurrentRow()) {
        setCurrentRow(row);
    }
    row.addEventListener(Events.ON_OK, rowListener);
}
Also used : Grid(org.zkoss.zul.Grid) GridField(org.compiere.model.GridField) Div(org.zkoss.zul.Div) Component(org.zkoss.zk.ui.Component) HtmlBasedComponent(org.zkoss.zk.ui.HtmlBasedComponent)

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