Example usage for com.google.gwt.event.dom.client FocusHandler FocusHandler

List of usage examples for com.google.gwt.event.dom.client FocusHandler FocusHandler

Introduction

In this page you can find the example usage for com.google.gwt.event.dom.client FocusHandler FocusHandler.

Prototype

FocusHandler

Source Link

Usage

From source file:org.opencms.gwt.client.ui.input.CmsComboBox.java

License:Open Source License

/**
 * @see org.opencms.gwt.client.ui.input.A_CmsSelectBox#initOpener()
 *///from ww w  .  j  a  va  2 s . c o  m
@Override
protected void initOpener() {

    m_mainPanel = new SimplePanel();
    m_fadePanel = new SimplePanel();
    m_openerWidget = new CmsSimpleTextBox();
    m_panel.add(m_fadePanel);

    m_openerWidget.addBlurHandler(new BlurHandler() {

        public void onBlur(BlurEvent event) {

            m_panel.add(m_fadePanel);
            m_openerWidget.getElement().setTitle(m_openerWidget.getText());
        }
    });
    m_openerWidget.addFocusHandler(new FocusHandler() {

        public void onFocus(FocusEvent event) {

            // on focus remove the fader.
            m_panel.remove(m_fadePanel);
            m_openerWidget.getElement().setTitle("");

        }
    });

    m_mainPanel.setStyleName(CSS.comboBoxOpener());
    m_fadePanel.addDomHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {

            m_openerWidget.setFocus(true);
            m_openerWidget.setCursorPos(m_openerWidget.getText().length());

            if (m_popup.isShowing()) {
                close();
            } else {
                open();
            }

        }
    }, ClickEvent.getType());
    m_fadePanel.setStyleName(CSS.fader());
    m_mainPanel.add(m_openerWidget);
    m_opener.add(m_mainPanel);

}

From source file:org.openelis.gwt.widget.richtext.RichTextWidget.java

License:Open Source License

public void init(boolean tools) {
    this.tools = tools;
    initWidget(vp);//from  w ww . j a  v a 2s  .c  om
    DOM.setStyleAttribute(vp.getElement(), "background", "white");
    vp.setSpacing(0);

    if (tools) {
        vp.add(toolbar);
        vp.add(area);
        vp.setCellWidth(toolbar, "100%");
    } else {
        vp.add(area);
    }
    area.setSize("100%", "100%");
    area.addFocusHandler(this);
    //Font and Font size can not be set until the area recieves focus.  We set up this handler to 
    //set the font and size that we want to default then remove the handler so we don't repeat it.
    focReg = area.addFocusHandler(new FocusHandler() {
        public void onFocus(FocusEvent event) {
            area.getFormatter().setFontName("Verdana");
            area.getFormatter().setFontSize(RichTextArea.FontSize.X_SMALL);
            focReg.removeHandler();
        }
    });
}

From source file:org.openelis.modules.report.client.ReportScreen.java

License:Open Source License

protected TextBox createTextBox(Field f, Prompt p) {
    final TextBox t;

    t = new TextBox();
    t.setStyleName("ScreenTextBox");
    t.addFocusHandler(new FocusHandler() {
        @Override//  ww w  . j  a va 2s.  c o m
        public void onFocus(FocusEvent event) {
            t.addStyleName("Focus");
        }
    });
    t.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            t.removeStyleName("Focus");
        }
    });
    f.required = p.isRequired();
    t.setField(f);

    if (p.getMask() != null)
        t.setMask(p.getMask());
    if (p.getLength() != null)
        t.setMaxLength(p.getLength());
    if (p.getCase() == Prompt.Case.LOWER)
        t.setCase(Case.LOWER);
    else if (p.getCase() == Prompt.Case.UPPER)
        t.setCase(Case.UPPER);
    if (p.getWidth() != null && p.getWidth() > 0)
        t.setWidth(p.getWidth() + "px");
    else
        t.setWidth("100px");
    t.setValue(p.getDefaultValue());

    return t;
}

From source file:org.openelis.modules.secondDataEntry.client.field.AuxData.java

License:Open Source License

/**
 * Makes the row in which the widgets are shown, visible and sets its style;
 * adds handlers to the widgets in the row
 *//*from w w  w  . j  a  va 2s. co  m*/
protected void init() {
    ScheduledCommand cmd;

    setRowVisible();

    /*
     * this is done so that the table gets resized to show the headers and
     * rows after it's made visible; it won't get resized otherwise because
     * it's in a LayoutPanel, and that panel is inside a <td> and not
     * another panel; so the browser's chain for resizing panels gets broken
     * and doesn't reach the table
     */
    cmd = new ScheduledCommand() {
        @Override
        public void execute() {
            editableWidget.onResize();
        }
    };
    Scheduler.get().scheduleDeferred(cmd);

    parentScreen.addScreenHandler(editableWidget, "auxDataTable", new ScreenHandler<ArrayList<Row>>() {
        public void onDataChange(DataChangeEvent<ArrayList<Row>> event) {
            clear();
        }

        public void onStateChange(StateChangeEvent event) {
            editableWidget.setEnabled(true);
        }

        public Widget onTab(boolean forward) {
            return forward ? nextTabWidget : prevTabWidget;
        }
    });
    /*
     * overridden because the table by default doesn't show any special
     * style on getting the focus
     */
    editableWidget.addDomHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            if (editableWidget.getRowCount() > 0 && editableWidget.getSelectedRow() == -1)
                editableWidget.selectRowAt(0);
        }
    }, FocusEvent.getType());

    editableWidget.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        @Override
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            AuxDataViewDO data;

            if (!parentScreen.isState(UPDATE) || event.getCol() != 1) {
                event.cancel();
                return;
            }

            /*
             * set the editor, e.g. dropdown or text box, in the editable
             * cell and in the cell for showing the value in the manager for
             * this row's analyte
             */
            data = parentScreen.getManager().auxData.get(event.getRow());
            try {
                setCellEditor(1, data.getAuxFieldGroupId(), data.getAuxFieldId());
                setCellEditor(4, data.getAuxFieldGroupId(), data.getAuxFieldId());
            } catch (Exception e) {
                Window.alert(e.getMessage());
                logger.log(Level.SEVERE, e.getMessage(), e);
                event.cancel();
            }
        }
    });

    editableWidget.addCellEditedHandler(new CellEditedHandler() {
        @Override
        public void onCellUpdated(CellEditedEvent event) {
            switch (event.getCol()) {
            case 1:
                valueChanged(event.getRow(), false);
                break;
            }
        }
    });
}

From source file:org.openelis.modules.secondDataEntry.client.field.SampleQAEvent.java

License:Open Source License

/**
 * Makes the row in which the widgets are shown, visible and sets its style;
 * adds handlers to the widgets in the row
 *///from   www .  jav a2 s .  c o  m
protected void init() {
    ScheduledCommand cmd;
    Item<Integer> row;
    ArrayList<Item<Integer>> model;

    setRowVisible();

    /*
     * this is done so that the table gets resized to show the headers and
     * rows after it's made visible; it won't get resized otherwise because
     * it's in a LayoutPanel, and that panel is inside a <td> and not
     * another panel; so the browser's chain for resizing panels gets broken
     * and doesn't reach the table
     */
    cmd = new ScheduledCommand() {
        @Override
        public void execute() {
            editableWidget.onResize();
        }
    };
    Scheduler.get().scheduleDeferred(cmd);

    parentScreen.addScreenHandler(editableWidget, "sampleQATable", new ScreenHandler<ArrayList<Row>>() {
        public void onDataChange(DataChangeEvent<ArrayList<Row>> event) {
            clear();
        }

        public void onStateChange(StateChangeEvent event) {
            editableWidget.setEnabled(true);
        }

        public Widget onTab(boolean forward) {
            return forward ? nextTabWidget : prevTabWidget;
        }
    });
    /*
     * overridden because the table by default doesn't show any special
     * style on getting the focus
     */
    editableWidget.addDomHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            if (editableWidget.getRowCount() > 0 && editableWidget.getSelectedRow() == -1)
                editableWidget.selectRowAt(0);
        }
    }, FocusEvent.getType());

    editableWidget.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        @Override
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            if (!parentScreen.isState(UPDATE) || event.getCol() > 0)
                event.cancel();
        }
    });

    editableWidget.addCellEditedHandler(new CellEditedHandler() {
        @Override
        public void onCellUpdated(CellEditedEvent event) {
            switch (event.getCol()) {
            case 0:
                verify(event.getRow());
                break;
            }
        }
    });

    /*
     * set model for qa event type
     */
    model = new ArrayList<Item<Integer>>();
    for (DictionaryDO d : CategoryCache.getBySystemName("qaevent_type")) {
        row = new Item<Integer>(d.getId(), d.getEntry());
        row.setEnabled("Y".equals(d.getIsActive()));
        model.add(row);
    }
    ((Dropdown<Integer>) editableWidget.getColumnWidget(2)).setModel(model);
}

From source file:org.openelis.ui.widget.AutoComplete.java

License:Open Source License

/**
 * Default no-arg constructor//from w w w. j  a  va  2 s. c o m
 */
public AutoComplete() {
    source = this;
    /*
     * Final instance of the private class KeyboardHandler
     */
    final KeyboardHandler keyHandler = new KeyboardHandler();

    initWidget(uiBinder.createAndBindUi(this));

    /*
     * Set the focus style when the Focus event is fired Externally
     */
    addFocusHandler(new FocusHandler() {
        public void onFocus(FocusEvent event) {
            if (isEnabled()) {
                display.addStyleName(css.Focus());
                selectAll();
            }
        }
    });

    /*
     * Removes the focus style when the Blur event is fires externally
     */
    addBlurHandler(new BlurHandler() {
        public void onBlur(BlurEvent event) {
            display.removeStyleName(css.Focus());
            textbox.setSelectionRange(0, 0);
            finishEditing();
        }
    });

    /*
     * Registers the keyboard handling this widget
     */
    addHandler(keyHandler, KeyDownEvent.getType());
    addHandler(keyHandler, KeyPressEvent.getType());

    /*
     * Timer is defined here once and scheduled to run when needed.  The timer is used to try and not 
     * make the query request for suggestions until the user has stopped typing to avoid firing multiple
     * request that will not be used
     */
    timer = new Timer() {
        public void run() {
            BeforeGetMatchesEvent bgme;
            String text;

            text = textbox.getText();

            bgme = BeforeGetMatchesEvent.fire(source, textbox.getText());
            if (bgme != null && bgme.isCancelled())
                return;

            GetMatchesEvent.fire(source, text);
        }
    };

    exceptions = new Exceptions();

    setCSS(UIResources.INSTANCE.dropdown());

    setPopupContext(new Table.Builder(10).column(new Column.Builder(10).build()).build());

    setWidth("150px");

}

From source file:org.openelis.ui.widget.Browser.java

License:Open Source License

/**
 * Adds a Window directly to the browser indexing it by the passed key
 * @param window//from   www .  j  a  v a 2 s . co  m
 * @param key
 */
public void addWindow(WindowInt window, String key, int left, int top) {
    WindowValues wv;

    index++;
    browser.add(window.asWidget(), left, top);
    wv = new WindowValues();
    wv.key = key + index;
    wv.zIndex = index;
    windows.put(window, wv);
    windowsByKey.put(key + index, window);
    window.addCloseHandler(new CloseHandler<WindowInt>() {
        public void onClose(CloseEvent<WindowInt> event) {
            if (windows.containsKey(event.getSource()))
                windowsByKey.remove(windows.remove(event.getSource()).key);

            setFocusedWindow();
        }
    });

    window.addFocusHandler(new FocusHandler() {
        public void onFocus(FocusEvent event) {
            selectScreen(windows.get(event.getSource()).key);

        }
    });

    window.makeDragable(dragController);
    setFocusedWindow();
    focusedWindow = window;
    window.setFocus(true);
}

From source file:org.openelis.ui.widget.Button.java

License:Open Source License

private void setFocusHandler() {
    addFocusHandler(new FocusHandler() {
        @Override//  w  w w.j  a va 2s .co  m
        public void onFocus(FocusEvent event) {
            if (isEnabled())
                outer.addClassName(css.Focus());
        }
    });
}

From source file:org.openelis.ui.widget.calendar.Calendar.java

License:Open Source License

/**
 * Default no-arg constructor//from  w  ww  .j  a  v  a  2 s  .c  o  m
 */
public Calendar() {
    source = this;

    final KeyboardHandler keyHandler = new KeyboardHandler();

    initWidget(uiBinder.createAndBindUi(this));

    /*
     * Set the focus style when the Focus event is fired Externally
     */
    addFocusHandler(new FocusHandler() {
        public void onFocus(FocusEvent event) {
            if (isEnabled()) {
                display.addStyleName(css.Focus());
                textbox.selectAll();
            }
        }
    });

    /*
     * Removes the focus style when the Blue event is fires externally
     */
    addBlurHandler(new BlurHandler() {
        public void onBlur(BlurEvent event) {
            display.removeStyleName(css.Focus());
            finishEditing(true);
        }
    });

    exceptions = new Exceptions();

    addHandler(keyHandler, KeyDownEvent.getType());

    setCSS(UIResources.INSTANCE.calendar());

    setWidth("90px");

}

From source file:org.openelis.ui.widget.CheckBox.java

License:Open Source License

protected void init() {
    check = new Check();

    check.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            if (!queryMode) {
                setValue(event.getValue() != null ? (event.getValue() ? "Y" : "N") : null, true);
                //fireValueChange(event.getValue() != null ? (event.getValue() ? "Y" : "N") : null);
            }/*  w  ww .j ava  2 s  .  co m*/
        }
    });

    super.addFocusHandler(new FocusHandler() {

        @Override
        public void onFocus(FocusEvent event) {
            check.setFocus(true);
        }
    });

    super.addBlurHandler(new BlurHandler() {

        @Override
        public void onBlur(BlurEvent event) {
            check.setFocus(false);
        }
    });

    check.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            FocusEvent.fireNativeEvent(event.getNativeEvent(), source);
        }
    });

    setWidget(check);

    exceptions = new Exceptions();

    setWidth("13px");
}