private void showAddNewComment() { newCommentLayout.clear(); final TextArea comment = new TextArea(); comment.setWidth("100%"); newCommentLayout.add(comment); Button ok = new Button(constants.OK()); Button cancel = new Button(constants.Cancel()); ok.addClickHandler( new ClickHandler() { public void onClick(ClickEvent sender) { sendNewComment(comment.getText()); } }); cancel.addClickHandler( new ClickHandler() { public void onClick(ClickEvent sender) { showNewCommentButton(); } }); HorizontalPanel hp = new HorizontalPanel(); hp.add(ok); hp.add(cancel); newCommentLayout.add(hp); comment.setFocus(true); }
private TextArea createClipboardTextArea() { final TextArea pasteArea = new TextArea(); pasteArea.setPixelSize(0, 0); Style style = pasteArea.getElement().getStyle(); style.setPosition(Style.Position.FIXED); RootPanel.get().add(pasteArea); pasteArea.setFocus(true); return pasteArea; }
private boolean validateFormInput() { if (inputNoteTitle.getText().trim().length() == 0) { Window.alert("Please enter a title for the new note!"); inputNoteTitle.setFocus(true); return false; } if (inputNoteText.getText().trim().length() == 0) { Window.alert("Please enter a text for the new note!"); inputNoteText.setFocus(true); return false; } return true; }
public void insertText(final String text, final boolean isSpecialPaste) { String textToInsert = text; final int i = textArea.getCursorPos(); final String left = textArea.getText().substring(0, i); final String right = textArea.getText().substring(i, textArea.getText().length()); int cursorPosition = left.toCharArray().length; if (isSpecialPaste) { int p = text.indexOf("|"); if (p > -1) { cursorPosition += p; textToInsert = textToInsert.replaceAll("\\|", ""); } } textArea.setFocus(true); textArea.setText(left + textToInsert + right); textArea.setCursorPos(cursorPosition); }
void insertText(String ins, boolean isSpecialPaste) { text.setFocus(true); int i = text.getCursorPos(); String left = text.getText().substring(0, i); String right = text.getText().substring(i, text.getText().length()); int cursorPosition = left.toCharArray().length; if (isSpecialPaste) { int p = ins.indexOf("|"); if (p > -1) { cursorPosition += p; ins = ins.replaceAll("\\|", ""); } } text.setText(left + ins + right); this.data.content = text.getText(); text.setCursorPos(cursorPosition); }
/** Activate the control. */ public void activate() { this.clear(); this.setVisible(true); Widget avatar = new AvatarWidget( Session.getInstance().getCurrentPerson().getId(), Session.getInstance().getCurrentPerson().getAvatarId(), EntityType.PERSON, Size.VerySmall, Background.White); avatar.addStyleName("avatar"); this.add(avatar); FlowPanel body = new FlowPanel(); body.addStyleName("body"); commentBox = new TextArea(); body.add(commentBox); commentBox.setFocus(true); countDown = new Label(Integer.toString(MAXLENGTH)); countDown.addStyleName("characters-remaining"); body.add(countDown); post = new Hyperlink("post", History.getToken()); post.addStyleName("post-button"); post.addStyleName("inactive"); final Label warning = new Label(); warning.addStyleName("warning hidden"); body.add(warning); Session.getInstance() .getEventBus() .addObserver( GotSystemSettingsResponseEvent.class, new Observer<GotSystemSettingsResponseEvent>() { public void update(final GotSystemSettingsResponseEvent event) { String text = event.getResponse().getContentWarningText(); if (text != null && !text.isEmpty()) { warning.removeStyleName("hidden"); warning.setText(text); } } }); SystemSettingsModel.getInstance().fetch(null, true); post.addClickHandler( new ClickHandler() { public void onClick(final ClickEvent event) { fullCollapse = false; if (!inactive) { unActivate(); CommentDTO comment = new CommentDTO(); comment.setBody(commentBox.getText()); comment.setActivityId(messageId); Session.getInstance() .getActionProcessor() .makeRequest( new ActionRequestImpl<CommentDTO>("postActivityCommentAction", comment), new AsyncCallback<CommentDTO>() { /* implement the async call back methods */ public void onFailure(final Throwable caught) {} public void onSuccess(final CommentDTO result) { Session.getInstance() .getEventBus() .notifyObservers(new CommentAddedEvent(result, messageId)); } }); } } }); body.add(post); this.add(body); commentBox.setFocus(true); nativeSetFocus(commentBox.getElement()); commentBox.addBlurHandler( new BlurHandler() { public void onBlur(final BlurEvent arg0) { TimerFactory timerFactory = new TimerFactory(); timerFactory.runTimer( BLUR_DELAY, new TimerHandler() { public void run() { if (commentBox.getText().length() == 0) { unActivate(); } } }); } }); commentBox.addKeyPressHandler( new KeyPressHandler() { public void onKeyPress(final KeyPressEvent event) { if (event.getCharCode() == KeyCodes.KEY_ESCAPE) { unActivate(); } } }); commentBox.addKeyUpHandler( new KeyUpHandler() { public void onKeyUp(final KeyUpEvent event) { onCommentChanges(); } }); commentBox.addChangeHandler( new ChangeHandler() { public void onChange(final ChangeEvent event) { onCommentChanges(); } }); }
/** Activate the control. */ public void activate() { clear(); this.setVisible(true); Widget avatar = new AvatarWidget( Session.getInstance().getCurrentPerson().getAvatarId(), EntityType.PERSON, Size.VerySmall); avatar.addStyleName(StaticResourceBundle.INSTANCE.coreCss().avatar()); this.add(avatar); FlowPanel body = new FlowPanel(); body.addStyleName(StaticResourceBundle.INSTANCE.coreCss().body()); SimplePanel boxWrapper = new SimplePanel(); boxWrapper.addStyleName(StaticResourceBundle.INSTANCE.coreCss().boxWrapper()); commentBox = new ExtendedTextArea(true); boxWrapper.add(commentBox); body.add(boxWrapper); commentBox.setFocus(true); countDown = new Label(Integer.toString(MAXLENGTH)); countDown.addStyleName(StaticResourceBundle.INSTANCE.coreCss().charactersRemaining()); body.add(countDown); post = new PushButton("post"); post.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postButton()); post.addStyleName(StaticResourceBundle.INSTANCE.coreCss().inactive()); body.add(post); final Label warning = new Label(); warning.addStyleName(StaticResourceBundle.INSTANCE.coreCss().warning()); warning.addStyleName(StaticResourceBundle.INSTANCE.coreCss().hidden()); body.add(warning); Session.getInstance() .getEventBus() .addObserver( GotSystemSettingsResponseEvent.class, new Observer<GotSystemSettingsResponseEvent>() { public void update(final GotSystemSettingsResponseEvent event) { String text = event.getResponse().getContentWarningText(); if (text != null && !text.isEmpty()) { warning.removeStyleName(StaticResourceBundle.INSTANCE.coreCss().hidden()); warning.setText(text); } } }); SystemSettingsModel.getInstance().fetch(null, true); post.addClickHandler( new ClickHandler() { public void onClick(final ClickEvent event) { fullCollapse = false; if (!inactive) { unActivate(); CommentDTO comment = new CommentDTO(); comment.setBody(commentBox.getText()); comment.setActivityId(messageId); Session.getInstance() .getActionProcessor() .makeRequest( "postActivityCommentAction", comment, new AsyncCallback<CommentDTO>() { /* implement the async call back methods */ public void onFailure(final Throwable caught) {} public void onSuccess(final CommentDTO result) { ActivityModel.getInstance().clearCache(); Session.getInstance() .getEventBus() .notifyObservers(new CommentAddedEvent(result, messageId)); } }); } } }); this.add(body); commentBox.setFocus(true); nativeSetFocus(commentBox.getElement()); commentBox.addBlurHandler( new BlurHandler() { public void onBlur(final BlurEvent arg0) { TimerFactory timerFactory = new TimerFactory(); timerFactory.runTimer( BLUR_DELAY, new TimerHandler() { public void run() { if (commentBox.getText().length() == 0) { unActivate(); } } }); } }); commentBox.addKeyDownHandler( new KeyDownHandler() { public void onKeyDown(final KeyDownEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) { unActivate(); } else if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER && event.isControlKeyDown()) { post.getElement() .dispatchEvent( Document.get().createClickEvent(1, 0, 0, 0, 0, false, false, false, false)); event.preventDefault(); event.stopPropagation(); } } }); commentBox.addKeyUpHandler( new KeyUpHandler() { public void onKeyUp(final KeyUpEvent event) { onCommentChanges(); } }); commentBox.addValueChangeHandler( new ValueChangeHandler<String>() { public void onValueChange(final ValueChangeEvent<String> inArg0) { onCommentChanges(); } }); commentBox.addChangeHandler( new ChangeHandler() { public void onChange(final ChangeEvent event) { onCommentChanges(); } }); }