Search in sources :

Example 1 with AuFocus

use of org.zkoss.zk.au.out.AuFocus in project adempiere by adempiere.

the class ADSortTab method migrateValueAcrossLists.

/**
	 * @param event
	 */
void migrateValueAcrossLists(Event event) {
    Object source = event.getTarget();
    if (source instanceof ListItem) {
        source = ((ListItem) source).getListbox();
    }
    Listbox listFrom = (source == bAdd || source == noList) ? noList : yesList;
    Listbox listTo = (source == bAdd || source == noList) ? yesList : noList;
    SimpleListModel lmFrom = (source == bAdd || source == noList) ? noModel : yesModel;
    SimpleListModel lmTo = (lmFrom == yesModel) ? noModel : yesModel;
    Set selectedItems = listFrom.getSelectedItems();
    List<ListElement> selObjects = new ArrayList<ListElement>();
    for (Object obj : selectedItems) {
        ListItem listItem = (ListItem) obj;
        int index = listFrom.getIndexOfItem(listItem);
        ListElement selObject = (ListElement) lmFrom.getElementAt(index);
        selObjects.add(selObject);
    }
    for (ListElement selObject : selObjects) {
        if (selObject == null || !selObject.isUpdateable())
            continue;
        lmFrom.removeElement(selObject);
        lmTo.addElement(selObject);
        //  Enable explicit Save
        setIsChanged(true);
    }
    for (ListElement selObject : selObjects) {
        int index = lmTo.indexOf(selObject);
        listTo.setSelectedIndex(index);
    }
    if (listTo.getSelectedItem() != null) {
        AuFocus focus = new AuFocus(listTo.getSelectedItem());
        Clients.response(focus);
    }
}
Also used : ResultSet(java.sql.ResultSet) Set(java.util.Set) SimpleListModel(org.adempiere.webui.component.SimpleListModel) ArrayList(java.util.ArrayList) ListItem(org.adempiere.webui.component.ListItem) Listbox(org.adempiere.webui.component.Listbox) AuFocus(org.zkoss.zk.au.out.AuFocus)

Example 2 with AuFocus

use of org.zkoss.zk.au.out.AuFocus in project adempiere by adempiere.

the class ADSortTab method migrateValueWithinYesList.

//	migrateValueAcrossLists
/**
	 * 	Move within Yes List
	 *	@param event event
	 */
void migrateValueWithinYesList(Event event) {
    Object[] selObjects = yesList.getSelectedItems().toArray();
    if (selObjects == null)
        return;
    int length = selObjects.length;
    if (length == 0)
        return;
    //
    int[] indices = yesList.getSelectedIndices();
    //
    boolean change = false;
    //
    Object source = event.getTarget();
    if (source == bUp) {
        for (int i = 0; i < length; i++) {
            int index = indices[i];
            if (index == 0)
                break;
            ListElement selObject = (ListElement) yesModel.getElementAt(index);
            ListElement newObject = (ListElement) yesModel.getElementAt(index - 1);
            if (!selObject.isUpdateable() || !newObject.isUpdateable())
                break;
            yesModel.setElementAt(newObject, index);
            yesModel.setElementAt(selObject, index - 1);
            indices[i] = index - 1;
            change = true;
        }
    } else if (source == bDown) {
        for (int i = length - 1; i >= 0; i--) {
            int index = indices[i];
            if (index >= yesModel.getSize() - 1)
                break;
            ListElement selObject = (ListElement) yesModel.getElementAt(index);
            ListElement newObject = (ListElement) yesModel.getElementAt(index + 1);
            if (!selObject.isUpdateable() || !newObject.isUpdateable())
                break;
            yesModel.setElementAt(newObject, index);
            yesModel.setElementAt(selObject, index + 1);
            yesList.setSelectedIndex(index + 1);
            indices[i] = index + 1;
            change = true;
        }
    }
    //
    if (change) {
        yesList.setSelectedIndices(indices);
        setIsChanged(true);
        if (yesList.getSelectedItem() != null) {
            AuFocus focus = new AuFocus(yesList.getSelectedItem());
            Clients.response(focus);
        }
    }
}
Also used : AuFocus(org.zkoss.zk.au.out.AuFocus)

Example 3 with AuFocus

use of org.zkoss.zk.au.out.AuFocus in project adempiere by adempiere.

the class ADSortTab method init.

/**
	 * 	Static Layout
	 * 	@throws Exception
	 */
private void init() throws Exception {
    this.setStyle("height: 100%; width: 100%;");
    //
    noLabel.setValue("No");
    yesLabel.setValue("Yes");
    //yesList.setHeight("100%");
    //noList.setHeight("100%");
    yesList.setVflex(true);
    noList.setVflex(true);
    EventListener mouseListener = new EventListener() {

        public void onEvent(Event event) throws Exception {
            if (Events.ON_DOUBLE_CLICK.equals(event.getName())) {
                migrateValueAcrossLists(event);
            }
        }
    };
    yesList.addDoubleClickListener(mouseListener);
    noList.addDoubleClickListener(mouseListener);
    //
    EventListener actionListener = new EventListener() {

        public void onEvent(Event event) throws Exception {
            migrateValueAcrossLists(event);
        }
    };
    yesList.setSeltype("multiple");
    noList.setSeltype("multiple");
    bAdd.setImage(ServletFns.resolveThemeURL("~./images/Detail24.png"));
    bAdd.addEventListener(Events.ON_CLICK, actionListener);
    bRemove.setImage(ServletFns.resolveThemeURL("~./images/Parent24.png"));
    bRemove.addEventListener(Events.ON_CLICK, actionListener);
    EventListener crossListMouseListener = new DragListener();
    yesList.addOnDropListener(crossListMouseListener);
    noList.addOnDropListener(crossListMouseListener);
    yesList.setItemDraggable(true);
    noList.setItemDraggable(true);
    actionListener = new EventListener() {

        public void onEvent(Event event) throws Exception {
            migrateValueWithinYesList(event);
        }
    };
    bUp.setImage(ServletFns.resolveThemeURL("~./images/Previous24.png"));
    bUp.addEventListener(Events.ON_CLICK, actionListener);
    bDown.setImage(ServletFns.resolveThemeURL("~./images/Next24.png"));
    bDown.addEventListener(Events.ON_CLICK, actionListener);
    EventListener yesListMouseMotionListener = new EventListener() {

        public void onEvent(Event event) throws Exception {
            if (event instanceof DropEvent) {
                DropEvent me = (DropEvent) event;
                ListItem startItem = (ListItem) me.getDragged();
                ListItem endItem = (ListItem) me.getTarget();
                if (startItem.getListbox() == endItem.getListbox() && startItem.getListbox() == yesList) {
                    int startIndex = yesList.getIndexOfItem(startItem);
                    int endIndex = yesList.getIndexOfItem(endItem);
                    Object endElement = yesModel.getElementAt(endIndex);
                    Object element = yesModel.getElementAt(startIndex);
                    yesModel.removeElement(element);
                    endIndex = yesModel.indexOf(endElement);
                    yesModel.add(endIndex, element);
                    yesList.setSelectedIndex(endIndex);
                    if (yesList.getSelectedItem() != null) {
                        AuFocus focus = new AuFocus(yesList.getSelectedItem());
                        Clients.response(focus);
                    }
                    setIsChanged(true);
                }
            }
        }
    };
    yesList.addOnDropListener(yesListMouseMotionListener);
    ListHead listHead = new ListHead();
    listHead.setParent(yesList);
    ListHeader listHeader = new ListHeader();
    listHeader.appendChild(yesLabel);
    listHeader.setParent(listHead);
    listHead = new ListHead();
    listHead.setParent(noList);
    listHeader = new ListHeader();
    listHeader.appendChild(noLabel);
    listHeader.setParent(listHead);
    Span span = new Span();
    span.setParent(this);
    span.setStyle("height: 99%; display: inline-block; width: 40%;");
    span.appendChild(noList);
    Vbox vbox = new Vbox();
    vbox.appendChild(bAdd);
    vbox.appendChild(bRemove);
    span = new Span();
    span.setParent(this);
    span.setStyle("height: 99%; display: inline-block; width: 46px");
    span.appendChild(vbox);
    span = new Span();
    span.setParent(this);
    span.setStyle("height: 99%; display: inline-block; width: 40%");
    span.appendChild(yesList);
    vbox = new Vbox();
    vbox.appendChild(bUp);
    vbox.appendChild(bDown);
    span = new Span();
    span.setParent(this);
    span.setStyle("height: 99%; display: inline-block; width: 46px");
    span.appendChild(vbox);
}
Also used : DropEvent(org.zkoss.zk.ui.event.DropEvent) Span(org.zkoss.zhtml.Span) SQLException(java.sql.SQLException) AuFocus(org.zkoss.zk.au.out.AuFocus) ListHead(org.adempiere.webui.component.ListHead) ListDataEvent(org.zkoss.zul.event.ListDataEvent) Event(org.zkoss.zk.ui.event.Event) DropEvent(org.zkoss.zk.ui.event.DropEvent) ListHeader(org.adempiere.webui.component.ListHeader) EventListener(org.zkoss.zk.ui.event.EventListener) ListItem(org.adempiere.webui.component.ListItem) Vbox(org.zkoss.zul.Vbox)

Example 4 with AuFocus

use of org.zkoss.zk.au.out.AuFocus in project adempiere by adempiere.

the class ADTabPanel method setFocusToField.

/**
	 * set focus to first active editor
	 */
private void setFocusToField() {
    WEditor toFocus = null;
    for (WEditor editor : editors) {
        if (editor.isHasFocus() && editor.isVisible() && editor.getComponent().getParent() != null) {
            toFocus = editor;
            break;
        }
        if (toFocus == null) {
            if (editor.isVisible() && editor.isReadWrite() && editor.getComponent().getParent() != null) {
                toFocus = editor;
            }
        }
    }
    if (toFocus != null) {
        Component c = toFocus.getComponent();
        if (c instanceof EditorBox) {
            c = ((EditorBox) c).getTextbox();
        }
        Clients.response(new AuFocus(c));
    }
}
Also used : Component(org.zkoss.zk.ui.Component) HtmlBasedComponent(org.zkoss.zk.ui.HtmlBasedComponent) AuFocus(org.zkoss.zk.au.out.AuFocus)

Example 5 with AuFocus

use of org.zkoss.zk.au.out.AuFocus in project adempiere by adempiere.

the class GridTabRowRenderer method setFocusToEditor.

/**
	 * set focus to first active editor
	 */
public void setFocusToEditor() {
    if (currentRow != null && currentRow.getParent() != null) {
        WEditor toFocus = null;
        WEditor firstEditor = null;
        for (WEditor editor : getEditors()) {
            if (editor.isHasFocus() && editor.isVisible() && editor.getComponent().getParent() != null) {
                toFocus = editor;
                break;
            }
            if (editor.isVisible() && editor.getComponent().getParent() != null) {
                if (toFocus == null && editor.isReadWrite()) {
                    toFocus = editor;
                }
                if (firstEditor == null)
                    firstEditor = editor;
            }
        }
        if (toFocus != null) {
            Component c = toFocus.getComponent();
            if (c instanceof EditorBox) {
                c = ((EditorBox) c).getTextbox();
            }
            Clients.response(new AuFocus(c));
        } else if (firstEditor != null) {
            Component c = firstEditor.getComponent();
            if (c instanceof EditorBox) {
                c = ((EditorBox) c).getTextbox();
            }
            Clients.response(new AuFocus(c));
        }
    }
}
Also used : WEditor(org.adempiere.webui.editor.WEditor) Component(org.zkoss.zk.ui.Component) HtmlBasedComponent(org.zkoss.zk.ui.HtmlBasedComponent) AuFocus(org.zkoss.zk.au.out.AuFocus)

Aggregations

AuFocus (org.zkoss.zk.au.out.AuFocus)5 ListItem (org.adempiere.webui.component.ListItem)2 Component (org.zkoss.zk.ui.Component)2 HtmlBasedComponent (org.zkoss.zk.ui.HtmlBasedComponent)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 ListHead (org.adempiere.webui.component.ListHead)1 ListHeader (org.adempiere.webui.component.ListHeader)1 Listbox (org.adempiere.webui.component.Listbox)1 SimpleListModel (org.adempiere.webui.component.SimpleListModel)1 WEditor (org.adempiere.webui.editor.WEditor)1 Span (org.zkoss.zhtml.Span)1 DropEvent (org.zkoss.zk.ui.event.DropEvent)1 Event (org.zkoss.zk.ui.event.Event)1 EventListener (org.zkoss.zk.ui.event.EventListener)1 Vbox (org.zkoss.zul.Vbox)1 ListDataEvent (org.zkoss.zul.event.ListDataEvent)1