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.unitime.timetable.gwt.client.widgets.FilterBox.java

License:Apache License

public FilterBox() {
    setStyleName("unitime-FilterBox");

    final Timer blur = new Timer() {
        @Override/* w w w .j  a va  2  s  .c o  m*/
        public void run() {
            if (!iFocus) {
                removeStyleName("unitime-FilterBoxFocus");
                if (isFilterPopupShowing())
                    hideFilterPopup();
            }
        }
    };

    iFocusHandler = new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            if (event.getSource() != null && event.getSource() instanceof Focusable)
                iLastFocusedWidget = (Focusable) event.getSource();
            iFocus = true;
            addStyleName("unitime-FilterBoxFocus");
            if (iShowSuggestionsOnFocus)
                refreshSuggestions();
        }
    };

    iBlurHandler = new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            iFocus = false;
            iLastFocusedWidget = null;
            blur.schedule(100);
        }
    };

    iFilter = new AriaTextBox();
    iFilter.setStyleName("filter");

    iFilter.addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (isFilterPopupShowing()) {
                hideFilterPopup();
            }
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_BACKSPACE && iFilter.getText().isEmpty()) {
                if (getWidgetCount() > 4) {
                    remove(getWidgetCount() - 5);
                    resizeFilterIfNeeded();
                    setAriaLabel(toAriaString());
                    ValueChangeEvent.fire(FilterBox.this, getValue());
                    setStatus(getAriaLabel());
                }
            }
            if (isSuggestionsShowing()) {
                switch (event.getNativeEvent().getKeyCode()) {
                case KeyCodes.KEY_DOWN:
                    iSuggestionMenu.selectItem(iSuggestionMenu.getSelectedItemIndex() + 1);
                    setStatus(ARIA.onSuggestion(iSuggestionMenu.getSelectedItemIndex() + 1,
                            iSuggestionMenu.getNumItems(),
                            iSuggestionMenu.getSelectedSuggestion().toAriaString(FilterBox.this)));
                    break;
                case KeyCodes.KEY_UP:
                    if (iSuggestionMenu.getSelectedItemIndex() == -1) {
                        iSuggestionMenu.selectItem(iSuggestionMenu.getNumItems() - 1);
                    } else {
                        iSuggestionMenu.selectItem(iSuggestionMenu.getSelectedItemIndex() - 1);
                    }
                    setStatus(ARIA.onSuggestion(iSuggestionMenu.getSelectedItemIndex() + 1,
                            iSuggestionMenu.getNumItems(),
                            iSuggestionMenu.getSelectedSuggestion().toAriaString(FilterBox.this)));
                    break;
                case KeyCodes.KEY_ENTER:
                    iSuggestionMenu.executeSelected();
                    hideSuggestions();
                    break;
                case KeyCodes.KEY_TAB:
                    hideSuggestions();
                    break;
                case KeyCodes.KEY_ESCAPE:
                    hideSuggestions();
                    break;
                }
                switch (event.getNativeEvent().getKeyCode()) {
                case KeyCodes.KEY_DOWN:
                case KeyCodes.KEY_UP:
                case KeyCodes.KEY_ENTER:
                case KeyCodes.KEY_ESCAPE:
                    event.preventDefault();
                    event.stopPropagation();
                }
            } else {
                if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_DOWN
                        && (event.getNativeEvent().getAltKey()
                                || iFilter.getCursorPos() == iFilter.getText().length())) {
                    showSuggestions();
                    event.preventDefault();
                    event.stopPropagation();
                }
            }
        }
    });
    iFilter.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            refreshSuggestions();
        }
    });
    iFilter.addFocusHandler(iFocusHandler);
    iFilter.addBlurHandler(iBlurHandler);
    add(iFilter);
    iFilter.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            setAriaLabel(toAriaString());
            ValueChangeEvent.fire(FilterBox.this, getValue());
        }
    });

    iFilterClear = new Image(RESOURCES.filter_clear());
    iFilterClear.setAltText(MESSAGES.altClearFilter());
    iFilterClear.setTitle(MESSAGES.altClearFilter());
    iFilterClear.setStyleName("button-image");
    add(iFilterClear);
    iFilterClear.setVisible(false);
    Roles.getDocumentRole().setAriaHiddenState(iFilterClear.getElement(), true);
    iFilter.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            if (iFilterClear.isVisible() && getValue().isEmpty()) {
                resizeFilterIfNeeded();
            } else if (!iFilterClear.isVisible() && !getValue().isEmpty()) {
                resizeFilterIfNeeded();
            }
        }
    });

    iFilterOpen = new Image(RESOURCES.filter_open());
    iFilterOpen.setAltText(MESSAGES.altOpenFilter());
    iFilterOpen.setTitle(MESSAGES.altOpenFilter());
    iFilterOpen.addStyleName("button-image");
    add(iFilterOpen);
    Roles.getDocumentRole().setAriaHiddenState(iFilterOpen.getElement(), true);

    iFilterClose = new Image(RESOURCES.filter_close());
    iFilterClose.setAltText(MESSAGES.altCloseFilter());
    iFilterClose.setTitle(MESSAGES.altCloseFilter());
    iFilterClose.addStyleName("button-image");
    add(iFilterClose);
    iFilterClose.setVisible(false);
    Roles.getDocumentRole().setAriaHiddenState(iFilterClose.getElement(), true);

    iFilterPopup = new PopupPanelKeepFocus();
    iFilterPopup.setStyleName("unitime-FilterBoxPopup");
    iFilterPopup.setAutoHideEnabled(false);
    iSuggestionMenu = new SuggestionMenu();
    iSuggestionsPopup = new PopupPanelKeepFocus();
    iSuggestionsPopup.setWidget(iSuggestionMenu);
    iSuggestionsPopup.setStyleName("unitime-FilterBoxPopup");

    sinkEvents(Event.ONMOUSEDOWN);

    iSuggestionsPopup.getElement().setAttribute("id", DOM.createUniqueId());
    Roles.getTextboxRole().setAriaOwnsProperty(iFilter.getElement(), Id.of(iSuggestionsPopup.getElement()));

    Roles.getTextboxRole().setAriaAutocompleteProperty(iFilter.getElement(), AutocompleteValue.NONE);
}

From source file:org.unitime.timetable.gwt.client.widgets.IntervalSelector.java

License:Apache License

public IntervalSelector(boolean allowMultiSelection) {
    iAllowMultiSelection = allowMultiSelection;

    iPanel = new P("unitime-IntervalSelector");

    P row = new P("row");
    iPanel.add(row);//from   w  ww .j  a va 2 s  .  c  o  m

    iPrev = new Button("«");
    iPrev.setEnabled(false);
    iPrev.addMouseDownHandler(new MouseDownHandler() {
        @Override
        public void onMouseDown(MouseDownEvent event) {
            Interval prev = (getValue() == null ? null : previous(getValue()));
            if (prev != null)
                setValue(prev, true);
        }
    });

    iNext = new Button("»");
    iNext.setEnabled(false);
    iNext.addMouseDownHandler(new MouseDownHandler() {
        @Override
        public void onMouseDown(MouseDownEvent event) {
            Interval next = (getValue() == null ? null : next(getValue()));
            if (next != null)
                setValue(next, true);
        }
    });

    iFilter = new AriaTextBox();
    iFilter.addStyleName("selection");

    iFilter.addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (isSuggestionsShowing()) {
                switch (event.getNativeEvent().getKeyCode()) {
                case KeyCodes.KEY_DOWN:
                    iPopupMenu.selectItem(iPopupMenu.getSelectedItemIndex() + 1);
                    setStatus(ARIA.onSuggestion(iPopupMenu.getSelectedItemIndex() + 1, iPopupMenu.getNumItems(),
                            iPopupMenu.getSelectedInterval().toAriaString()));
                    break;
                case KeyCodes.KEY_UP:
                    if (iPopupMenu.getSelectedItemIndex() == -1) {
                        iPopupMenu.selectItem(iPopupMenu.getNumItems() - 1);
                    } else {
                        iPopupMenu.selectItem(iPopupMenu.getSelectedItemIndex() - 1);
                    }
                    setStatus(ARIA.onSuggestion(iPopupMenu.getSelectedItemIndex() + 1, iPopupMenu.getNumItems(),
                            iPopupMenu.getSelectedInterval().toAriaString()));
                    break;
                case KeyCodes.KEY_TAB:
                case KeyCodes.KEY_ENTER:
                    iPopupMenu.executeSelected();
                    hideSuggestions();
                    break;
                case KeyCodes.KEY_ESCAPE:
                    hideSuggestions();
                    break;
                }
                switch (event.getNativeEvent().getKeyCode()) {
                case KeyCodes.KEY_DOWN:
                case KeyCodes.KEY_UP:
                case KeyCodes.KEY_ENTER:
                case KeyCodes.KEY_ESCAPE:
                    event.preventDefault();
                    event.stopPropagation();
                }
            } else {
                if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_DOWN
                        && (event.getNativeEvent().getAltKey()
                                || iFilter.getCursorPos() == iFilter.getText().length())) {
                    showSuggestions();
                    event.preventDefault();
                    event.stopPropagation();
                }
            }
        }
    });

    iFilter.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (selectASuggestion()) {
                if (!isSuggestionsShowing())
                    showSuggestions();
                else
                    setStatus(ARIA.onSuggestion(iPopupMenu.getSelectedItemIndex() + 1, iPopupMenu.getNumItems(),
                            iPopupMenu.getSelectedInterval().toAriaString()));
            }
        }
    });

    iFilter.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            if (iValues != null) {
                if (isAllowMultiSelection() && event.getValue().equals(getReplaceString(new Interval()))) {
                    setValue(new Interval());
                } else {
                    Interval value = null;
                    iterator: for (int i = 0; i < iValues.size(); i++) {
                        if (event.getValue().equals(getReplaceString(new Interval(iValues.get(i))))) {
                            value = new Interval(iValues.get(i));
                            break iterator;
                        }
                        if (isAllowMultiSelection()) {
                            for (int j = i + 1; j < iValues.size(); j++) {
                                if (event.getValue().equals(
                                        getReplaceString(new Interval(iValues.get(i), iValues.get(j))))) {
                                    value = new Interval(iValues.get(i), iValues.get(j));
                                    break iterator;
                                }
                            }
                        }
                    }
                    setValue(value);
                }
            }
        }
    });

    iFilter.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            showSuggestions();
        }
    });

    iPopupMenu = new Menu();

    iPopupScroll = new ScrollPanel(iPopupMenu);
    iPopupScroll.addStyleName("scroll");

    iPopup = new PopupPanel(true, false);
    iPopup.setPreviewingAllNativeEvents(true);
    iPopup.setStyleName("unitime-IntervalSelectorPopup");
    iPopup.setWidget(iPopupScroll);

    row.add(iPrev);
    row.add(iFilter);
    row.add(iNext);

    iWidget = new UniTimeWidget<AbsolutePanel>(iPanel);

    initWidget(iWidget);

    Roles.getTextboxRole().setAriaAutocompleteProperty(iFilter.getElement(), AutocompleteValue.NONE);

    iPopup.getElement().setAttribute("id", DOM.createUniqueId());
    Roles.getTextboxRole().setAriaOwnsProperty(iFilter.getElement(), Id.of(iPopup.getElement()));
}

From source file:org.unitime.timetable.gwt.client.widgets.TimeSelector.java

License:Apache License

public TimeSelector(TimeSelector start) {
    iStart = start;/*from w ww  . j a  va2  s.  com*/
    iText = new AriaTextBox();
    iText.setStyleName("gwt-SuggestBox");
    iText.addStyleName("unitime-TimeSelector");
    iText.setAriaLabel(start == null ? ARIA.startTime() : ARIA.endTime());

    iTimes = new TimeMenu();

    iTimeScroll = new ScrollPanel(iTimes);
    iTimeScroll.addStyleName("scroll");

    iPopup = new PopupPanel(true, false);
    iPopup.setPreviewingAllNativeEvents(true);
    iPopup.setStyleName("unitime-TimeSelectorPopup");
    iPopup.setWidget(iTimeScroll);

    initWidget(iText);

    createSuggestions();

    iText.addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (isSuggestionsShowing()) {
                switch (event.getNativeEvent().getKeyCode()) {
                case KeyCodes.KEY_DOWN:
                    iTimes.selectItem(iTimes.getSelectedItemIndex() + 1);
                    updateSuggestionStatus();
                    break;
                case KeyCodes.KEY_UP:
                    if (iTimes.getSelectedItemIndex() == -1) {
                        iTimes.selectItem(iTimes.getNumItems() - 1);
                    } else {
                        iTimes.selectItem(iTimes.getSelectedItemIndex() - 1);
                    }
                    updateSuggestionStatus();
                    break;
                case KeyCodes.KEY_ENTER:
                    iTimes.executeSelected();
                    hideSuggestions();
                    break;
                case KeyCodes.KEY_TAB:
                    hideSuggestions();
                    break;
                case KeyCodes.KEY_ESCAPE:
                    hideSuggestions();
                    break;
                }
                switch (event.getNativeEvent().getKeyCode()) {
                case KeyCodes.KEY_DOWN:
                case KeyCodes.KEY_UP:
                case KeyCodes.KEY_ENTER:
                case KeyCodes.KEY_ESCAPE:
                    event.preventDefault();
                    event.stopPropagation();
                }
            } else {
                if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_DOWN
                        && (event.getNativeEvent().getAltKey()
                                || iText.getCursorPos() == iText.getText().length())) {
                    showSuggestions();
                    updateSuggestionStatus();
                    event.preventDefault();
                    event.stopPropagation();
                }
            }
        }
    });

    iText.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (selectASuggestion()) {
                if (!isSuggestionsShowing())
                    showSuggestions();
                updateSuggestionStatus();
            }
        }
    });

    iText.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            setValue(parseTime(event.getValue()), true);
        }
    });

    if (iStart != null)
        iStart.addValueChangeHandler(new ValueChangeHandler<Integer>() {
            @Override
            public void onValueChange(ValueChangeEvent<Integer> event) {
                createSuggestions();
                if (iDiff != null && event.getValue() != null)
                    setValue(Math.min(event.getValue() + iDiff, 288));
            }
        });

    iText.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            showSuggestions();
        }
    });
}

From source file:org.unitime.timetable.gwt.client.widgets.WeekSelector.java

License:Apache License

public WeekSelector(AcademicSessionProvider session) {
    super(true);/*w  w w .  j  a va  2 s  .  c o  m*/
    iAcademicSession = session;

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            init(iAcademicSession.getAcademicSessionId());
        }
    });

    session.addAcademicSessionChangeHandler(new AcademicSessionChangeHandler() {
        @Override
        public void onAcademicSessionChange(AcademicSessionChangeEvent event) {
            init(event.getNewAcademicSessionId());
        }
    });

    addValueChangeHandler(new ValueChangeHandler<Interval>() {
        @Override
        public void onValueChange(ValueChangeEvent<Interval> event) {
            setAriaLabel(ARIA.weekSelection(toAriaString()));
        }
    });

    addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            setAriaLabel(ARIA.weekSelection(toAriaString()));
        }
    });
}

From source file:org.utgenome.gwt.utgb.client.ui.EditableLabel.java

License:Apache License

public EditableLabel(CellReference cellReference, String text) {
    _cellReference = cellReference;//  w  ww.jav  a  2s.  co  m
    setText(text);

    Style.set(this, Style.CSS_BORDER, "0");
    Style.backgroundColor(this, "#9999FF");
    setSize("100%", "100%");

    addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent arg0) {
            setSelectionRange(0, getText().length());
        }
    });
    addFocusHandler(new FocusHandler() {

        public void onFocus(FocusEvent arg0) {
            //Style.backgroundColor(_textBox, "#9999FF");            
        }
    });

}

From source file:org.vaadin.addons.tuningdatefield.widgetset.client.ui.TuningDateFieldWidget.java

License:Apache License

public TuningDateFieldWidget() {
    setStyleName(CLASSNAME);//w w w . ja va 2  s  . co  m
    addStyleName("tuning-datefield");

    dateTextBox = new TextBox();
    dateTextBox.addStyleName("v-textfield");
    dateTextBox.addStyleName(CLASSNAME + "-textfield");
    dateTextBox.addChangeHandler(this);
    dateTextBox.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            dateTextBox.addStyleName(VTextField.CLASSNAME + "-" + VTextField.CLASSNAME_FOCUS);
            // Show calendar
            if (isEnabled() && openCalendarOnFocusEnabled) {
                openCalendar();
            }
        }
    });
    dateTextBox.addBlurHandler(new BlurHandler() {

        @Override
        public void onBlur(BlurEvent event) {
            dateTextBox.removeStyleName(VTextField.CLASSNAME + "-" + VTextField.CLASSNAME_FOCUS);

        }
    });
    add(dateTextBox);

    calendarToggle.addStyleName("v-datefield-button");
    calendarToggle.setText("");
    calendarToggle.addClickHandler(this);
    calendarToggle.getElement().setTabIndex(-2);

    Roles.getButtonRole().set(calendarToggle.getElement());
    Roles.getButtonRole().setAriaHiddenState(calendarToggle.getElement(), true);
    add(calendarToggle);

    calendar = GWT.create(TuningDateFieldCalendarWidget.class);
    calendar.setFocusOutListener(new FocusOutListener() {
        @Override
        public boolean onFocusOut(DomEvent<?> event) {
            event.preventDefault();
            closeCalendar();
            return true;
        }
    });

    Roles.getTextboxRole().setAriaControlsProperty(dateTextBox.getElement(), Id.of(calendar.getElement()));
    Roles.getButtonRole().setAriaControlsProperty(calendarToggle.getElement(), Id.of(calendar.getElement()));

    popup = new VOverlay(true, false, true);
    popup.setOwner(this);

    popup.setWidget(calendar);
    // When the calendar widget is set we need to update
    // popup position
    calendar.addCalendarAttachedHandler(new CalendarAttachedHandler() {
        @Override
        public void onCalendarAttached(CalendarAttachedEvent event) {
            updatePopupPosition();
        }
    });

    popup.addCloseHandler(this);

    sinkEvents(Event.ONKEYDOWN);

    updateStyleNames();
}

From source file:org.workcraft.gwt.imagemap.client.ImageMap.java

public ImageMap(final ImageMapDefinition definition, final ResultHandler handler) {
    this.definition = definition;

    imageDiv = new FlowPanel();
    imageDiv.addStyleName("imagemap-container");

    imageDiv.getElement().setTabIndex(1);

    final Image baseImage = new Image(definition.baseImageUrl);
    baseImage.addStyleName("imagemap-base-image");

    imageDiv.add(baseImage);//w w  w .  j  a v  a  2  s . co  m

    mouseMoveHandler = new MouseMoveHandler() {
        @Override
        public void onMouseMove(MouseMoveEvent event) {

            double mouseX = (double) event.getRelativeX(baseImage.getElement()) / baseImage.getOffsetWidth();
            double mouseY = (double) event.getRelativeY(baseImage.getElement()) / baseImage.getOffsetWidth();

            int mouseOverArea = -1;

            for (int i = 0; i < definition.areas.length; i++) {
                if (definition.areas[i].shape.isInside(new Point(mouseX, mouseY))) {
                    mouseOverArea = i;
                    break;
                }
            }

            if (mouseOverArea != activeArea) {
                if (hasFocus && mouseOverArea == -1) {
                    setActiveArea(lastActiveArea);
                } else
                    setActiveArea(mouseOverArea);
            }
        }
    };

    clickHandler = new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            handler.handleResult(definition.areas[activeArea].id);
        }
    };

    baseImage.addMouseMoveHandler(mouseMoveHandler);

    addDomHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            // System.out.println (event.getCharCode());

            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                handler.handleResult(activeArea);
            }

            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_LEFT) {
                prev();
                event.preventDefault();
            }
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_RIGHT) {
                next();
                event.preventDefault();
            }
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_UP) {
                next();
                event.preventDefault();
            }
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_DOWN) {
                prev();
                event.preventDefault();
            }
        }
    }, KeyDownEvent.getType());

    addDomHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            hasFocus = true;
            if (activeArea == -1)
                setActiveArea(0);
        }
    }, FocusEvent.getType());

    addDomHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            hasFocus = false;
            setActiveArea(-1);
        }
    }, BlurEvent.getType());

    initWidget(imageDiv);

    prefetchImages();
}

From source file:org.zanata.webtrans.client.editor.table.InlineTargetCellEditor.java

License:Open Source License

/**
 * Construct a new {@link InlineTargetCellEditor} with the specified images.
 * //from ww w.ja v  a2  s . c om
 * @param content the {@link Widget} used to edit
 * @param images the images to use for the accept/cancel buttons
 */
public InlineTargetCellEditor(final NavigationMessages messages, TargetCellEditorImages images,
        CancelCallback<TransUnit> callback, EditRowCallback rowCallback,
        UndoCallback<TransUnit> undoTransCallback) {
    // Wrap contents in a table
    layoutTable = new FlowPanel();

    cancelCallback = callback;
    editRowCallback = rowCallback;
    undoCallback = undoTransCallback;
    textArea = new TextArea();
    textArea.setStyleName("TableEditorContent-Edit");
    textArea.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            isFocused = false;
        }

    });
    textArea.addFocusHandler(new FocusHandler() {

        @Override
        public void onFocus(FocusEvent event) {
            isFocused = true;
        }

    });
    textArea.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            // NB: if you change these, please change NavigationConsts too!
            if (event.isControlKeyDown() && event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                acceptEdit();
                gotoNextRow(curRow);
            } else if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
                cancelEdit();
            }
            // else if (event.isControlKeyDown() && event.isShiftKeyDown() &&
            // event.getNativeKeyCode() == KeyCodes.KEY_PAGEDOWN)
            // { // was alt-e
            // handleNextState(ContentState.NeedReview);
            // }
            // else if (event.isControlKeyDown() && event.isShiftKeyDown() &&
            // event.getNativeKeyCode() == KeyCodes.KEY_PAGEUP)
            // { // was alt-m
            // handlePrevState(ContentState.NeedReview);
            // // } else if(event.isControlKeyDown() && event.getNativeKeyCode()
            // // == KeyCodes.KEY_PAGEDOWN) { // bad in Firefox
            // }
            else if (event.isAltKeyDown() && event.isDownArrow()) {
                handleNext();
                // } else if(event.isControlKeyDown() && event.getNativeKeyCode()
                // == KeyCodes.KEY_PAGEUP) { // bad in Firefox
            } else if (event.isAltKeyDown() && event.isUpArrow()) {
                handlePrev();
            } else if (event.isAltKeyDown() && event.getNativeKeyCode() == KeyCodes.KEY_PAGEDOWN) { // alt-pagedown
                handleNextState();
            } else if (event.isAltKeyDown() && event.getNativeKeyCode() == KeyCodes.KEY_PAGEUP) { // alt-pageup
                handlePrevState();
            }
            // these shortcuts disabled because they conflict with basic text editing:
            //            else if (event.isControlKeyDown() && event.getNativeKeyCode() == KeyCodes.KEY_HOME)
            //            { // ctrl-home
            //               cloneHandler.onClick(null);
            //            }
            //            else if (event.isControlKeyDown() && event.getNativeKeyCode() == KeyCodes.KEY_END)
            //            { // ctrl-end
            //               cloneAndSaveHandler.onClick(null);
            //            }
        }

    });
    layoutTable.add(textArea);

    HorizontalPanel operationsPanel = new HorizontalPanel();
    operationsPanel.addStyleName("float-right-div");
    operationsPanel.setSpacing(4);
    layoutTable.add(operationsPanel);

    // icon as the current state of the unit
    // stateImage = new Image(resources.newUnit());
    // operationsPanel.add(stateImage);

    // Add content widget
    toggleFuzzy = new CheckBox(messages.fuzzy());
    operationsPanel.add(toggleFuzzy);

    PushButton cloneButton = new PushButton(new Image(), cloneHandler);
    cloneButton.setText(messages.editClone());
    cloneButton.setTitle(messages.editCloneShortcut());
    operationsPanel.add(cloneButton);

    PushButton cloneAndSaveButton = new PushButton(new Image(), cloneAndSaveHandler);
    cloneAndSaveButton.setText(messages.editCloneAndSave());
    cloneAndSaveButton.setTitle(messages.editCloneAndSaveShortcut());
    operationsPanel.add(cloneAndSaveButton);

    PushButton cancelButton = new PushButton(images.cellEditorCancel().createImage(), cancelHandler);
    cancelButton.setText(messages.editCancel());
    cancelButton.setTitle(messages.editCancelShortcut());
    operationsPanel.add(cancelButton);

    PushButton acceptButton = new PushButton(images.cellEditorAccept().createImage(), acceptHandler);
    acceptButton.setText(messages.editSave());
    acceptButton.setTitle(messages.editSaveShortcut());
    operationsPanel.add(acceptButton);
}

From source file:sf.wicklet.gwt.client.ui.dialog.LoginDialog.java

License:Apache License

private void populateContent(final IGwtPanel panel) {
    new GwtBuilder() {
        @SuppressWarnings("synthetic-access")
        void build() {
            panel.c(label("").id(msgId).istyle("color: red; margin: 4px"), grid(2, 2).spacing(8).c(
                    label("User name").istyle("text-align: right"),
                    textbox("").id(userId).istyle("padding: 2px 0px 2px 4px").onfocus(new FocusHandler() {
                        @Override
                        public void onFocus(final FocusEvent event) {
                            setMessage("");
                        }/*from  w w w. j a  va2s. c om*/
                    }), label("Password").istyle("text-align: right"),
                    password("").id(passId).istyle("padding: 2px 0px 2px 4px").onfocus(new FocusHandler() {
                        @Override
                        public void onFocus(final FocusEvent event) {
                            setMessage("");
                        }
                    })), populateButtons(button("Cancel").id(cancelId).onclick(new ClickHandler() {
                        @Override
                        public void onClick(final ClickEvent event) {
                            event.preventDefault();
                            onCancel();
                        }
                    }), button("OK").id(okId).onclick(new ClickHandler() {
                        @Override
                        public void onClick(final ClickEvent event) {
                            event.preventDefault();
                            onOK();
                        }
                    })));
        }
    }.build();
}

From source file:sf.wicklet.gwt.site.home.client.WickletGwtSiteHome.java

License:Apache License

void wikiCommentPanel(final String href, final String html) {
    new GwtBuilder() {
        void build() {
            final IGwtComplexPanel top = templatepanel(html);
            final ComplexPanel rightpanel = rightPanel.asPanel();
            rightpanel.add(top);/*from   w w w .  ja v  a 2 s  .  c  o m*/
            final DomCache cache = new DomCache(top.asPanel().getElement(), "id", "name");
            final Element form = cache.byId(WID.commentForm);
            final UrlParts formaction = UrlParts.parse(form.getAttribute("action"));
            final IGwtTextBox subject = textbox(cache.by("name", WID.commentSubject).get(0));
            final IGwtTextArea comment = textarea(cache.by("name", WID.commentText).get(0));
            final IGwtTextBox captcha = textbox(cache.by("name", WID.commentCaptchaText).get(0));
            final FocusHandler clearmsg = new FocusHandler() {
                @Override
                public void onFocus(final FocusEvent event) {
                    GwtDomUtil.clear(DOM.getElementById(WID.commentFeedback.toString()));
                }
            };
            top.istyle("margin: 10px").c(form(form).onsubmit(new SubmitHandler() {
                @Override
                public void onSubmit(final SubmitEvent event) {
                    event.cancel();
                    WickletAjax.ajax(WickletGwtSiteUtil.getContextUrl("/wicket/page?" + formaction.getQuery()),
                            encode(subject.getText(), comment.getText(), captcha.getText()),
                            new XmlWickletAjaxCallback() {
                                @Override
                                public void onResponseReceived(final Request request, final Response response) {
                                    if (!GwtHttp.Status.isOK(response.getStatusCode())) {
                                        showError("ERROR: Invalid response: " + response.getText());
                                        return;
                                    }
                                    final String res = response.getText();
                                    final Document doc = XMLParser.parse(res);
                                    final com.google.gwt.xml.client.Element e = doc.getDocumentElement();
                                    final String tag = e.getNodeName();
                                    if ("success".equals(tag)) {
                                        rightpanel.remove(top);
                                        rightpanel.asWidget().getElement()
                                                .setInnerHTML(GwtXmlUtil.unescXml(GwtXmlUtil.getTextUnder(e)));
                                    } else if ("feedback".equals(tag)) {
                                        final Element o = DOM.getElementById(WID.commentFeedback.toString());
                                        final String text = GwtXmlUtil.unescTextUnder(e);
                                        o.setInnerHTML(text);
                                    } else {
                                        showError("ERROR: Invalid response: " + tag);
                                    }
                                }

                                @Override
                                public void onError(final Request request, final Throwable e) {
                                    CConf.debug("ERROR: Wiki comment failed: " + request, e);
                                    showError("ERROR: Wiki comment failed");
                                }
                            });
                }
            }), subject.onfocus(clearmsg), comment.onfocus(clearmsg),
                    image(cache.byId(WID.commentCaptchaImage)), captcha.onfocus(clearmsg),
                    button(cache.byId(WID.commentSubmit)));
        }

        String encode(final String subject, final String comment, final String captcha) {
            return "" + (WID.commentSubject + "=" + URL.encodeQueryString(subject))
                    + ("&" + WID.commentText + "=" + URL.encodeQueryString(comment))
                    + ("&" + WID.commentCaptchaText + "=" + URL.encodeQueryString(captcha));
        }
    }.build();
}