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.ednovo.gooru.client.uc.TextBoxWithPlaceholder.java

License:Open Source License

private void setupHandlers() {
    addFocusHandler(new FocusHandler() {
        public void onFocus(FocusEvent event) {
            hidePlaceholder();//from w  w  w  .  java 2 s. c  o  m
        }
    });

    addBlurHandler(new BlurHandler() {
        public void onBlur(BlurEvent event) {
            showPlaceholder();
        }
    });
}

From source file:org.eobjects.datacleaner.monitor.scheduling.widgets.CustomizeSchedulePanel.java

License:Open Source License

public CustomizeSchedulePanel(SchedulingServiceAsync service, TenantIdentifier tenant,
        ScheduleDefinition schedule) {/*from ww w .  j  a  va 2  s  .  c o m*/
    super();

    _service = service;
    _tenant = tenant;
    _schedule = schedule;
    _service.getServerDate(new DCAsyncCallback<String>() {

        @Override
        public void onSuccess(String result) {
            serverDateAsString = result;
            serverDate = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").parse(serverDateAsString);
        }
    });

    MultiWordSuggestOracle suggestions = new MultiWordSuggestOracle();
    suggestions.add("@yearly");
    suggestions.add("@monthly");
    suggestions.add("@weekly");
    suggestions.add("@daily");
    suggestions.add("@hourly");
    suggestions.add("@minutely");
    periodicTriggerExpressionTextBox = new SuggestBox(suggestions);
    periodicTriggerExpressionTextBox.getValueBox().addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            periodicTriggerRadio.setValue(true);
            Element elementById = DOM.getElementById("periodicErrorMessage");
            if (periodicTriggerExpressionTextBox.getText().equals("")) {
                elementById.setInnerHTML("Specify cron expression for periodic scheduling");
            } else {
                elementById.setInnerHTML("");
            }
        }
    });

    initWidget(uiBinder.createAndBindUi(this));

    dateBox.setFormat(new DateBox.DefaultFormat(DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss")));
    dateBox.getDatePicker().setWidth("200px");

    dateBox.getTextBox().addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            oneTimeTriggerRadio.setValue(true);
            Element elementByIdForDate = DOM.getElementById("serverDate");
            elementByIdForDate.setInnerHTML("Server Time : " + serverDateAsString);
        }
    });

    dateBox.getTextBox().addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            Element elementById = DOM.getElementById("errorMessage");
            if (dateBox.getValue() == null) {
                elementById.setInnerHTML("Select date for one time schedule");
            } else {
                Date scheduleDate = dateBox.getValue();
                elementById.setInnerHTML("");
                if (scheduleDate.before(serverDate)) {
                    elementById.setInnerHTML("Past date can not be selected for one time schedule");
                } else {
                    elementById.setInnerHTML("");
                }
            }
        }
    });

    oneTimeTriggerRadio.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Element elementById = DOM.getElementById("errorMessage");
            Element elementByIdForDate = DOM.getElementById("serverDate");
            elementByIdForDate.setInnerHTML("Server Time : " + serverDateAsString);
            if (dateBox.getValue() == null) {
                elementById.setInnerHTML("Select date for one time schedule");
            }
        }
    });

    dateBox.addValueChangeHandler(new ValueChangeHandler<Date>() {

        @Override
        public void onValueChange(ValueChangeEvent<Date> event) {
            Date scheduleDate = dateBox.getValue();
            Element elementById = DOM.getElementById("errorMessage");
            elementById.setInnerHTML("");
            if (scheduleDate.before(serverDate)) {
                elementById.setInnerHTML("Past date can not be selected for one time schedule");
            } else {
                elementById.setInnerHTML("");
            }
        }
    });

    final String expression = _schedule.getCronExpression();
    final JobIdentifier scheduleAfterJob = _schedule.getDependentJob();
    final String expressionForOneTime = _schedule.getDateForOneTimeSchedule();

    if (expression != null) {
        periodicTriggerRadio.setValue(true);
        periodicTriggerExpressionTextBox.setText(expression);
    } else if (expressionForOneTime != null) {
        oneTimeTriggerRadio.setValue(true);
        dateBox.getTextBox().setValue(expressionForOneTime);
    } else if (scheduleAfterJob != null) {
        dependentTriggerRadio.setValue(true);
        dependentTriggerJobListBox.addItem(scheduleAfterJob.getName());
        dependentTriggerJobListBox.setSelectedIndex(0);
    } else {
        manualTriggerRadio.setValue(true);
    }

    dependentTriggerJobListBox.addFocusHandler(new FocusHandler() {

        @Override
        public void onFocus(FocusEvent event) {
            dependentTriggerRadio.setValue(true);
        }
    });

    _service.getDependentJobCandidates(_tenant, _schedule, new DCAsyncCallback<List<JobIdentifier>>() {
        @Override
        public void onSuccess(List<JobIdentifier> result) {
            for (JobIdentifier jobIdentifier : result) {
                final String jobName = jobIdentifier.getName();
                if (scheduleAfterJob != null && jobName.equals(scheduleAfterJob.getName())) {
                    // already added
                } else {
                    dependentTriggerJobListBox.addItem(jobName);
                }
            }
        }
    });
}

From source file:org.eobjects.datacleaner.monitor.shared.widgets.StringParameterizedMetricTextBox.java

License:Open Source License

public StringParameterizedMetricTextBox(String text, final CheckBox checkBoxToActivate,
        SuggestOracle suggestOracle) {/* w ww  . java2s  .  c  o  m*/
    super(suggestOracle);
    addStyleName("StringParameterizedMetricTextBox");
    setText(text);

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

    if (checkBoxToActivate != null) {
        getValueBox().addKeyUpHandler(new KeyUpHandler() {
            @Override
            public void onKeyUp(KeyUpEvent event) {
                final String text = getText();
                if (text != null && !"".equals(text)) {
                    // activate checkbox whenever something is written.
                    checkBoxToActivate.setValue(true);
                }
            }
        });
    }
}

From source file:org.eurekastreams.web.client.ui.common.autocomplete.AutoCompleteDropDownPanel.java

License:Apache License

/**
 * Sets the default text.//  ww w .j  a v a  2 s.c o m
 *
 * @param text
 *            the text.
 */
public void setDefaultText(final String text) {
    textWidget.setText(text);
    textWidget.addStyleName(StaticResourceBundle.INSTANCE.coreCss().defaultClass());
    textWidget.addFocusHandler(new FocusHandler() {
        public void onFocus(final FocusEvent inEvent) {
            textWidget.setText("");
            textWidget.removeStyleName(StaticResourceBundle.INSTANCE.coreCss().defaultClass());
        }
    });
}

From source file:org.eurekastreams.web.client.ui.common.stream.PostToStreamComposite.java

License:Apache License

/**
 * Wires up events./*from ww w. j  a v  a2  s. c  om*/
 */
private void setupEvents() {
    // user clicked in message text box
    message.addFocusHandler(new FocusHandler() {
        public void onFocus(final FocusEvent inEvent) {
            if ((" " + getStyleName() + " ").contains(StaticResourceBundle.INSTANCE.coreCss().small())) {
                removeStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
                onExpand();
            }
        }
    });

    message.addValueChangedHandler(new ValueChangeHandler<String>() {
        public void onValueChange(final ValueChangeEvent<String> newValue) {
            checkMessageTextChanged();
        }
    });

    // user typed in message text box
    message.addKeystrokeHandler(new KeyUpHandler() {
        public void onKeyUp(final KeyUpEvent ev) {
            if (ev.getNativeKeyCode() == KeyCodes.KEY_ENTER && ev.isControlKeyDown()
                    && message.getText().length() > 0) {
                checkMessageTextChanged();
                handlePostMessage();
            } else {
                checkMessageTextChanged();
            }
        }
    });

    // user clicked on post button
    postButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent ev) {
            checkMessageTextChanged();
            handlePostMessage();
        }
    });

    final EventBus eventBus = Session.getInstance().getEventBus();
    eventBus.addObserver(MessageStreamAppendEvent.class, new Observer<MessageStreamAppendEvent>() {
        public void update(final MessageStreamAppendEvent event) {
            errorMsg.setVisible(false);
            addStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
            messageText = "";
            message.setText(postBoxDefaultText);
            onRemainingCharactersChanged();
            links.close();
        }
    });

    eventBus.addObserver(GotSystemSettingsResponseEvent.class, new Observer<GotSystemSettingsResponseEvent>() {
        public void update(final GotSystemSettingsResponseEvent event) {
            String warning = event.getResponse().getContentWarningText();
            if (warning != null && !warning.isEmpty()) {
                contentWarning.setText(warning);
            } else {
                contentWarning.setVisible(false);
            }
            message.setVisible(true);
        }
    });

    eventBus.addObserver(MessageTextAreaChangedEvent.getEvent(), new Observer<MessageTextAreaChangedEvent>() {
        public void update(final MessageTextAreaChangedEvent arg1) {
            // the value changed - make sure we're not stuck in the disabled, non-editable mode
            if ((" " + getStyleName() + " ").contains(StaticResourceBundle.INSTANCE.coreCss().small())) {
                removeStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
            }
            onRemainingCharactersChanged();
        }
    });

    eventBus.addObserver(MessageAttachmentChangedEvent.class, new Observer<MessageAttachmentChangedEvent>() {
        public void update(final MessageAttachmentChangedEvent evt) {
            errorMsg.setVisible(false);
            attachment = evt.getAttachment();
            if (attachment == null && messageText.isEmpty()) {
                hidePostButton();
            } else {
                showPostButton();
            }
        }
    });

    eventBus.addObserver(new ErrorPostingMessageToNullScopeEvent(),
            new Observer<ErrorPostingMessageToNullScopeEvent>() {
                public void update(final ErrorPostingMessageToNullScopeEvent event) {
                    errorMsg.setText(event.getErrorMsg());
                    errorMsg.setVisible(true);
                    showPostButton();
                }
            });
}

From source file:org.eurekastreams.web.client.ui.common.widgets.activity.PostBoxComposite.java

License:Apache License

/**
 * Build page.//  w w  w.j  av a2 s. co  m
 */
private void buildPage() {
    posterAvatar.add(avatarRenderer.render(Session.getInstance().getCurrentPerson().getEntityId(),
            Session.getInstance().getCurrentPerson().getAvatarId(), EntityType.PERSON, Size.Small));
    postCharCount.setInnerText(POST_MAX.toString());
    checkPostBox();
    postBox.setLabel("Post to your stream...");
    postBox.reset();

    addEvents();

    postBox.addKeyUpHandler(new KeyUpHandler() {
        public void onKeyUp(final KeyUpEvent event) {
            checkPostBox();
        }
    });

    postBox.addFocusHandler(new FocusHandler() {
        public void onFocus(final FocusEvent event) {
            postOptions.addClassName(style.visiblePostBox());
        }
    });

    postBox.addBlurHandler(new BlurHandler() {
        public void onBlur(final BlurEvent event) {

            timerFactory.runTimer(BLUR_DELAY, new TimerHandler() {
                public void run() {
                    if (postBox.getText().trim().length() == 0 && !addLinkComposite.inAddMode()
                            && attachment == null) {
                        postOptions.removeClassName(style.visiblePostBox());
                        postBox.getElement().getStyle().clearHeight();
                        postBox.reset();
                    }
                }
            });
        }
    });

    setupPostButtonClickHandler();

    postBox.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(final KeyDownEvent event) {
            if ((event.getNativeKeyCode() == KeyCodes.KEY_TAB || event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
                    && !event.isAnyModifierKeyDown() && activeItemIndex != null) {
                hashTags.getWidget(activeItemIndex).getElement().dispatchEvent(
                        Document.get().createClickEvent(1, 0, 0, 0, 0, false, false, false, false));
                event.preventDefault();
                event.stopPropagation();
                // clearSearch();

            } else if (event.getNativeKeyCode() == KeyCodes.KEY_DOWN && activeItemIndex != null) {
                if (activeItemIndex + 1 < hashTags.getWidgetCount()) {
                    selectItem((Label) hashTags.getWidget(activeItemIndex + 1));
                }
                event.preventDefault();
                event.stopPropagation();
            } else if (event.getNativeKeyCode() == KeyCodes.KEY_UP && activeItemIndex != null) {
                if (activeItemIndex - 1 >= 0) {
                    selectItem((Label) hashTags.getWidget(activeItemIndex - 1));
                }
                event.preventDefault();
                event.stopPropagation();
            } else if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER && event.isControlKeyDown()) {
                postButton.getElement().dispatchEvent(
                        Document.get().createClickEvent(1, 0, 0, 0, 0, false, false, false, false));
                event.preventDefault();
                event.stopPropagation();
            }

        }
    });

    postBox.addKeyUpHandler(new KeyUpHandler() {
        public void onKeyUp(final KeyUpEvent event) {
            int tagsAdded = 0;

            String postText = postBox.getText();
            if (!postText.endsWith(" ")) {
                String[] words = postText.split("\\s");
                if (words.length >= 1) {
                    final String lastWord = words[words.length - 1];
                    if (lastWord.startsWith("#")) {
                        boolean activeItemSet = false;
                        Label firstItem = null;

                        for (String hashTag : allHashTags) {
                            if (hashTag.startsWith(lastWord)) {
                                // get list ready on first tag added
                                if (tagsAdded == 0) {
                                    hashTags.clear();

                                    String boxHeight = postBox.getElement().getStyle().getHeight().replace("px",
                                            "");
                                    if (boxHeight.isEmpty()) {
                                        boxHeight = "44";
                                    }
                                    hashTags.getElement().getStyle().setTop(
                                            Integer.parseInt(boxHeight) + HASH_TAG_DROP_DOWN_PADDING, Unit.PX);
                                    hashTags.setVisible(true);
                                }

                                final String hashTagFinal = hashTag;
                                final Label tagLbl = new Label(hashTagFinal);
                                tagLbl.addClickHandler(new ClickHandler() {
                                    public void onClick(final ClickEvent event) {
                                        String postText = postBox.getText();
                                        postText = postText.substring(0, postText.length() - lastWord.length())
                                                + hashTagFinal + " ";
                                        postBox.setText(postText);
                                        hashTags.setVisible(false);
                                        hashTags.clear();
                                        activeItemIndex = null;
                                    }
                                });
                                tagLbl.addMouseOverHandler(new MouseOverHandler() {
                                    public void onMouseOver(final MouseOverEvent arg0) {
                                        selectItem(tagLbl);
                                    }
                                });
                                hashTags.add(tagLbl);

                                if (firstItem == null) {
                                    firstItem = tagLbl;
                                }

                                if (activeItemIndex != null
                                        && activeItemIndex.equals(hashTags.getWidgetCount() - 1)) {
                                    activeItemIndex = null;
                                    activeItemSet = true;
                                    selectItem(tagLbl);
                                }

                                tagsAdded++;
                                if (tagsAdded >= MAX_HASH_TAG_AUTOCOMPLETE_ENTRIES) {
                                    break;
                                }
                            }
                        }

                        if (!activeItemSet && firstItem != null) {
                            activeItemIndex = null;
                            selectItem(firstItem);
                        }
                    }
                }
            }

            if (tagsAdded == 0) {
                hashTags.setVisible(false);
                activeItemIndex = null;
            }
        }
    });

    AllPopularHashTagsModel.getInstance().fetch(null, true);
    SystemSettingsModel.getInstance().fetch(null, true);

    hashTags.setVisible(false);
}

From source file:org.eurekastreams.web.client.ui.connect.support.PostToStreamComposite.java

License:Apache License

/**
 * Wires up events./*from w ww.  jav  a 2s.com*/
 */
private void setupEvents() {
    // user clicked in message text box
    message.addFocusHandler(new FocusHandler() {
        public void onFocus(final FocusEvent inEvent) {
            if ((" " + getStyleName() + " ").contains(StaticResourceBundle.INSTANCE.coreCss().small())) {
                removeStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
                onExpand();
            }
        }
    });

    message.addValueChangedHandler(new ValueChangeHandler<String>() {
        public void onValueChange(final ValueChangeEvent<String> newValue) {
            checkMessageTextChanged();
        }
    });

    // user typed in message text box
    message.addKeystrokeHandler(new KeyUpHandler() {
        public void onKeyUp(final KeyUpEvent ev) {
            if (ev.getNativeKeyCode() == KeyCodes.KEY_ENTER && ev.isControlKeyDown()
                    && message.getText().length() > 0) {
                checkMessageTextChanged();
                handlePostMessage();
            } else {
                checkMessageTextChanged();
            }
        }
    });

    // user clicked on post button
    postButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent ev) {
            checkMessageTextChanged();
            handlePostMessage();
        }
    });

    final EventBus eventBus = Session.getInstance().getEventBus();
    eventBus.addObserver(MessageStreamAppendEvent.class, new Observer<MessageStreamAppendEvent>() {
        public void update(final MessageStreamAppendEvent event) {
            errorMsg.setVisible(false);
            addStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
            messageText = "";
            message.setText(postBoxDefaultText);
            onRemainingCharactersChanged();
            links.close();
        }
    });

    eventBus.addObserver(GotSystemSettingsResponseEvent.class, new Observer<GotSystemSettingsResponseEvent>() {
        public void update(final GotSystemSettingsResponseEvent event) {
            String warning = event.getResponse().getContentWarningText();
            if (warning != null && !warning.isEmpty()) {
                contentWarning.getElement().setInnerHTML(warning);
            } else {
                contentWarning.setVisible(false);
            }
            message.setVisible(true);
        }
    });

    eventBus.addObserver(MessageTextAreaChangedEvent.getEvent(), new Observer<MessageTextAreaChangedEvent>() {
        public void update(final MessageTextAreaChangedEvent arg1) {
            // the value changed - make sure we're not stuck in the disabled, non-editable mode
            if ((" " + getStyleName() + " ").contains(StaticResourceBundle.INSTANCE.coreCss().small())) {
                removeStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
            }
            onRemainingCharactersChanged();
        }
    });

    eventBus.addObserver(MessageAttachmentChangedEvent.class, new Observer<MessageAttachmentChangedEvent>() {
        public void update(final MessageAttachmentChangedEvent evt) {
            errorMsg.setVisible(false);
            attachment = evt.getAttachment();
            if (attachment == null && messageText.isEmpty()) {
                hidePostButton();
            } else {
                showPostButton();
            }
        }
    });

    eventBus.addObserver(new ErrorPostingMessageToNullScopeEvent(),
            new Observer<ErrorPostingMessageToNullScopeEvent>() {
                public void update(final ErrorPostingMessageToNullScopeEvent event) {
                    errorMsg.setText(event.getErrorMsg());
                    errorMsg.setVisible(true);
                    showPostButton();
                }
            });
}

From source file:org.eurekastreams.web.client.ui.connect.widget.ShareWidget.java

License:Apache License

/**
 * Constructor.//from w  w w .  j  a  v a 2 s.  c o  m
 * 
 * @param resourceUrl
 *            resource url.
 * @param inTitle
 *            the title.
 * @param desc
 *            the description.
 * @param thumbs
 *            the thumbnails.
 */
public ShareWidget(final String resourceUrl, final String inTitle, final String desc, final String[] thumbs) {
    final FlowPanel widget = new FlowPanel();
    widget.addStyleName(StaticResourceBundle.INSTANCE.coreCss().eurekaConnectShareWidgetContainer());
    initWidget(widget);

    PersonModelView person = Session.getInstance().getCurrentPerson();

    StreamScope defaultStreamScope = new StreamScope(person.getDisplayName(), ScopeType.PERSON,
            person.getAccountId(), person.getStreamId());

    final PostToPanel postToPanel = new PostToPanel(defaultStreamScope);
    widget.add(postToPanel);

    // -- Setup the link display panel (thumbnail selector, field to update title) --

    title.addStyleName(StaticResourceBundle.INSTANCE.coreCss().attachLinkTitleEntry());
    linkUrlDisplay.addStyleName(StaticResourceBundle.INSTANCE.coreCss().url());
    linkDesc.addStyleName(StaticResourceBundle.INSTANCE.coreCss().metaDescription());

    FlowPanel linkInfoPanel = new FlowPanel();
    linkInfoPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().messageLink());
    linkInfoPanel.add(title);
    linkInfoPanel.add(linkUrlDisplay);
    linkInfoPanel.add(linkDesc);

    displayPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().linkPanel());
    displayPanel.add(selector);
    displayPanel.add(linkInfoPanel);
    displayPanel.add(selector.getPagingControls());

    widget.add(displayPanel);

    final LinkInformation link = new LinkInformation();
    link.setDescription(desc);
    link.setTitle(inTitle);
    link.setUrl(resourceUrl);
    try {
        link.setSource(resourceUrl.substring(0, resourceUrl.indexOf('/', 7)));
    } catch (Exception e) {
        link.setSource(resourceUrl);
    }

    if (thumbs != null) {
        HashSet<String> thumbsSet = new HashSet<String>();

        for (String thumb : thumbs) {
            thumbsSet.add(thumb);
        }

        link.setImageUrls(thumbsSet);

        link.setLargestImageUrl(thumbs[0]);
    }

    onLinkAdded(link);

    final FlowPanel postContainer = new FlowPanel();
    postContainer.getElement().setAttribute("id", "post-to-stream");
    postContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postToStream());
    postContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
    postContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postToStreamContainer());

    FlowPanel postInfoContainer = new FlowPanel();
    postInfoContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postInfoContainer());

    postButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postButton());
    postInfoContainer.add(postButton);

    countDown.setText(Integer.toString(MAXLENGTH));
    countDown.addStyleName(StaticResourceBundle.INSTANCE.coreCss().charactersRemaining());
    postInfoContainer.add(countDown);

    message.setText(defaultText);

    // user clicked in message text box
    message.addFocusHandler(new FocusHandler() {
        public void onFocus(final FocusEvent inEvent) {
            if ((" " + postContainer.getStyleName() + " ")
                    .contains(StaticResourceBundle.INSTANCE.coreCss().small())) {
                postContainer.removeStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
                message.setText("");
            }
        }
    });

    // changes to the message for character countdown
    message.addKeystrokeHandler(new KeyUpHandler() {
        public void onKeyUp(final KeyUpEvent inEvent) {
            onCommentChanges();

        }
    });
    message.addValueChangedHandler(new ValueChangeHandler<String>() {
        public void onValueChange(final ValueChangeEvent<String> inEvent) {
            onCommentChanges();
        }
    });

    AvatarWidget avatar = new AvatarWidget(person, EntityType.PERSON, Size.VerySmall);
    avatar.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postEntryAvatar());

    Panel entryPanel = new FlowPanel();
    entryPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postEntryPanel());
    entryPanel.add(avatar);
    entryPanel.add(postInfoContainer);
    entryPanel.add(message);

    postContainer.add(entryPanel);

    FlowPanel contentWarningContainer = new FlowPanel();
    contentWarningContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().contentWarning());
    contentWarningContainer.add(new SimplePanel());
    final FlowPanel contentWarning = new FlowPanel();
    contentWarningContainer.add(contentWarning);
    postContainer.add(contentWarningContainer);
    Session.getInstance().getEventBus().addObserver(GotSystemSettingsResponseEvent.class,
            new Observer<GotSystemSettingsResponseEvent>() {
                public void update(final GotSystemSettingsResponseEvent event) {
                    contentWarning.getElement().setInnerHTML(event.getResponse().getContentWarningText());
                }
            });
    SystemSettingsModel.getInstance().fetch(null, true);

    widget.add(postContainer);

    EventBus.getInstance().addObserver(MessageStreamAppendEvent.class,
            new Observer<MessageStreamAppendEvent>() {
                public void update(final MessageStreamAppendEvent arg1) {
                    closeWindow();
                }
            });

    postButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent event) {
            StreamScope scope = postToPanel.getPostScope();
            if (scope == null) {
                ErrorPostingMessageToNullScopeEvent error = new ErrorPostingMessageToNullScopeEvent();
                error.setErrorMsg("The stream name you entered could not be found");
                Session.getInstance().getEventBus().notifyObservers(error);
                return;
            }

            EntityType recipientType = DomainConversionUtility.convertToEntityType(scope.getScopeType());
            if (EntityType.NOTSET.equals(recipientType)) {
                recipientType = EntityType.GROUP;
            }

            String messageText = message.getText();

            if (messageText.equals(defaultText)) {
                messageText = "";
            }

            BookmarkPopulator objectStrat = new BookmarkPopulator();
            objectStrat.setLinkInformation(link);
            ActivityDTO activity = activityPopulator.getActivityDTO(messageText, recipientType,
                    scope.getUniqueKey(), new PostPopulator(), objectStrat);
            PostActivityRequest postRequest = new PostActivityRequest(activity);

            ActivityModel.getInstance().insert(postRequest);
        }
    });

    EventBus.getInstance().notifyObservers(new PostReadyEvent("Something"));
}

From source file:org.eurekastreams.web.client.ui.pages.widget.ShareWidget.java

License:Apache License

/**
 * Constructor./*from   w  w w.java2  s. c  o m*/
 *
 * @param resourceUrl
 *            resource url.
 * @param inTitle
 *            the title.
 * @param desc
 *            the description.
 * @param thumbs
 *            the thumbnails.
 */
public ShareWidget(final String resourceUrl, final String inTitle, final String desc, final String[] thumbs) {
    final FlowPanel widget = new FlowPanel();
    widget.addStyleName(StaticResourceBundle.INSTANCE.coreCss().eurekaConnectShareWidgetContainer());
    initWidget(widget);

    PersonModelView person = Session.getInstance().getCurrentPerson();

    StreamScope defaultStreamScope = new StreamScope(person.getDisplayName(), ScopeType.PERSON,
            person.getAccountId(), person.getStreamId());

    final PostToPanel postToPanel = new PostToPanel(defaultStreamScope);
    widget.add(postToPanel);

    // -- Setup the link display panel (thumbnail selector, field to update title) --

    title.addStyleName(StaticResourceBundle.INSTANCE.coreCss().attachLinkTitleEntry());
    linkUrlDisplay.addStyleName(StaticResourceBundle.INSTANCE.coreCss().url());
    linkDesc.addStyleName(StaticResourceBundle.INSTANCE.coreCss().metaDescription());

    FlowPanel linkInfoPanel = new FlowPanel();
    linkInfoPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().messageLink());
    linkInfoPanel.add(title);
    linkInfoPanel.add(linkUrlDisplay);
    linkInfoPanel.add(linkDesc);

    displayPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().linkPanel());
    displayPanel.add(selector);
    displayPanel.add(linkInfoPanel);
    displayPanel.add(selector.getPagingControls());

    widget.add(displayPanel);

    final LinkInformation link = new LinkInformation();
    link.setDescription(desc);
    link.setTitle(inTitle);
    link.setUrl(resourceUrl);
    try {
        link.setSource(resourceUrl.substring(0, resourceUrl.indexOf('/', 7)));
    } catch (Exception e) {
        link.setSource(resourceUrl);
    }

    if (thumbs != null) {
        HashSet<String> thumbsSet = new HashSet<String>();

        for (String thumb : thumbs) {
            thumbsSet.add(thumb);
        }

        link.setImageUrls(thumbsSet);

        link.setLargestImageUrl(thumbs[0]);
    }

    onLinkAdded(link);

    final FlowPanel postContainer = new FlowPanel();
    postContainer.getElement().setAttribute("id", "post-to-stream");
    postContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postToStream());
    postContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
    postContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postToStreamContainer());

    FlowPanel postInfoContainer = new FlowPanel();
    postInfoContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postInfoContainer());

    postButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postButton());
    postInfoContainer.add(postButton);

    countDown.setText(Integer.toString(MAXLENGTH));
    countDown.addStyleName(StaticResourceBundle.INSTANCE.coreCss().charactersRemaining());
    postInfoContainer.add(countDown);

    message.setText(defaultText);

    // user clicked in message text box
    message.addFocusHandler(new FocusHandler() {
        public void onFocus(final FocusEvent inEvent) {
            if ((" " + postContainer.getStyleName() + " ")
                    .contains(StaticResourceBundle.INSTANCE.coreCss().small())) {
                postContainer.removeStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
                message.setText("");
            }
        }
    });

    // changes to the message for character countdown
    message.addKeystrokeHandler(new KeyUpHandler() {
        public void onKeyUp(final KeyUpEvent inEvent) {
            onCommentChanges();

        }
    });
    message.addValueChangedHandler(new ValueChangeHandler<String>() {
        public void onValueChange(final ValueChangeEvent<String> inEvent) {
            onCommentChanges();
        }
    });

    AvatarWidget avatar = new AvatarWidget(person, EntityType.PERSON, Size.VerySmall);
    avatar.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postEntryAvatar());

    Panel entryPanel = new FlowPanel();
    entryPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postEntryPanel());
    entryPanel.add(avatar);
    entryPanel.add(postInfoContainer);
    entryPanel.add(message);

    postContainer.add(entryPanel);

    FlowPanel contentWarningContainer = new FlowPanel();
    contentWarningContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().contentWarning());
    contentWarningContainer.add(new SimplePanel());
    final InlineLabel contentWarning = new InlineLabel();
    contentWarningContainer.add(contentWarning);
    postContainer.add(contentWarningContainer);
    Session.getInstance().getEventBus().addObserver(GotSystemSettingsResponseEvent.class,
            new Observer<GotSystemSettingsResponseEvent>() {
                public void update(final GotSystemSettingsResponseEvent event) {
                    contentWarning.setText(event.getResponse().getContentWarningText());
                }
            });
    SystemSettingsModel.getInstance().fetch(null, true);

    widget.add(postContainer);

    EventBus.getInstance().addObserver(MessageStreamAppendEvent.class,
            new Observer<MessageStreamAppendEvent>() {
                public void update(final MessageStreamAppendEvent arg1) {
                    closeWindow();
                }
            });

    postButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent event) {
            StreamScope scope = postToPanel.getPostScope();
            if (scope == null) {
                ErrorPostingMessageToNullScopeEvent error = new ErrorPostingMessageToNullScopeEvent();
                error.setErrorMsg("The stream name you entered could not be found");
                Session.getInstance().getEventBus().notifyObservers(error);
                return;
            }

            EntityType recipientType = DomainConversionUtility.convertToEntityType(scope.getScopeType());
            if (EntityType.NOTSET.equals(recipientType)) {
                recipientType = EntityType.GROUP;
            }

            String messageText = message.getText();

            if (messageText.equals(defaultText)) {
                messageText = "";
            }

            BookmarkPopulator objectStrat = new BookmarkPopulator();
            objectStrat.setLinkInformation(link);
            ActivityDTO activity = activityPopulator.getActivityDTO(messageText, recipientType,
                    scope.getUniqueKey(), new PostPopulator(), objectStrat);
            PostActivityRequest postRequest = new PostActivityRequest(activity);

            ActivityModel.getInstance().insert(postRequest);
        }
    });

    EventBus.getInstance().notifyObservers(new PostReadyEvent("Something"));
}

From source file:org.freemedsoftware.gwt.client.widget.EmrPrintDialog.java

License:Open Source License

public EmrPrintDialog() {
    final VerticalPanel verticalPanel = new VerticalPanel();
    setStylePrimaryName("freemed-EmrPrintDialog");
    setWidget(verticalPanel);//from   w w  w  . java  2  s  .c o  m

    final FlexTable flexTable = new FlexTable();
    verticalPanel.add(flexTable);
    flexTable.setWidth("100%");

    browserMethod = new RadioButton("printingMethod");
    flexTable.setWidget(0, 0, browserMethod);
    browserMethod.setValue(true);
    browserMethod.setName("printingMethod");
    browserMethod.setText(_("Browser"));

    printerMethod = new RadioButton("printingMethod");
    flexTable.setWidget(1, 0, printerMethod);
    printerMethod.setName("printingMethod");
    printerMethod.setText(_("Printer"));

    printerWidget = new SupportModuleWidget();
    printerWidget.setModuleName(_("Printers"));
    flexTable.setWidget(1, 1, printerWidget);

    faxMethod = new RadioButton("printingMethod");
    flexTable.setWidget(2, 0, faxMethod);
    faxMethod.setName("printingMethod");
    faxMethod.setText(_("Fax"));

    faxNumber = new TextBox();
    faxNumber.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            faxMethod.setValue(true);
        }
    });
    flexTable.setWidget(2, 1, faxNumber);
    faxNumber.setWidth("100%");

    final HorizontalPanel horizontalPanel = new HorizontalPanel();
    verticalPanel.add(horizontalPanel);
    horizontalPanel.setWidth("100%");
    horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    printfaxButton = new CustomButton(_("Print/Fax"), AppConstants.ICON_PRINT);
    horizontalPanel.add(printfaxButton);

    printfaxButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent evt) {
            printfaxButton.setEnabled(false);
            if (faxMethod.getValue()) {
                // Fax
                printToFax();
            } else if (browserMethod.getValue()) {
                // Browser
                printToBrowser();
            } else {
                // Printer
                printToPrinter();
            }
        }
    });

    final CustomButton cancelButton = new CustomButton(_("Cancel"), AppConstants.ICON_CANCEL);
    horizontalPanel.add(cancelButton);
    cancelButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent evt) {
            closeDialog();
        }
    });

    messageLabel = new Label("");
    verticalPanel.add(messageLabel);
    messageLabel.setWidth("100%");
}