public RichTextArea create(Element e) { String v = null; RichTextArea richArea = null; TextAreaElement textElement = null; if ($(e).widget(0) != null && $(e).widget(0) instanceof RichTextArea) { richArea = $(e).widget(0); v = richArea.getHTML(); } else if ("textarea".equalsIgnoreCase(e.getTagName())) { v = $(e).val(); textElement = TextAreaElement.as(e); } else if (WidgetsUtils.matchesTags(e, "div", "span")) { v = $(e).html(); } if (v != null) { final RichTextWithToolbar richWidget = new RichTextWithToolbar(richArea, textElement); richArea = richWidget.area; richArea.setHTML(v); if (textElement != null) { WidgetsUtils.hideAndAfter(textElement, richWidget); } else { WidgetsUtils.replaceOrAppend(e, richWidget); } return richArea; } return null; }
public void show(final Pair<Product, String> productPair) { this.product = productPair.getEntity1(); if (null != product.getDescription()) description.setHTML(product.getDescription()); else description.setText(""); tags.setValues(product.getTags()); name.setValue(product.getName()); versionNumber.setValue(product.getVersionNumber()); organization.setValue(product.getOrganizationName()); webpageUrl.setValue(product.getWebsiteUrl()); wikiUrl.setValue(product.getWikiUrl()); downloadUrl.setValue(product.getDownloadUrl()); showcaseUrl.setValue(product.getDemoUrl()); forumUrl.setValue(product.getForumUrl()); issueTrackerUrl.setValue(product.getIssueTrackerUrl()); newsfeedUrl.setValue(product.getNewsUrl()); WidgetUtil.selectValue(license.getComponent(), product.getLicense()); WidgetUtil.selectValue(status.getComponent(), product.getStatus()); WidgetUtil.selectValue(category.getComponent(), product.getCategoryId()); new GetProductCategoriesCommand() { @Override public void onSuccess(ArrayList<Category> result) { WidgetUtil.selectValue(category.getComponent(), product.getCategoryId()); } }.execute(); resetIcon(); uploaderContainer.clear(); if (null != product && null != product.getId()) { uploaderContainer.add(new ProductImageUploadPanel(product, this)); } }
public RichTextWithToolbar(RichTextArea a, final TextAreaElement e) { area = a != null ? a : new RichTextArea(); area.ensureDebugId("editorArea"); area.setSize("100%", "100%"); Toolbar toolbar = new Toolbar(area); toolbar.ensureDebugId("editorToolbar"); setStyleName("gq-richtext"); add(toolbar); add(area); setWidth("100%"); // Inject styles from parent document area.addInitializeHandler( new InitializeHandler() { public void onInitialize(InitializeEvent event) { $(area).contents().find("head").append($("style, link[rel='stylesheet']").clone()); $(area).contents().find("body").css("fontFamily", "arial").css("fontSize", "80%"); } }); if (e != null) { area.addBlurHandler( new BlurHandler() { public void onBlur(BlurEvent event) { e.setValue(area.getHTML().trim()); } }); } }
public EditProblemInterview(JSONObject interview) { this.setSpacing(20); this.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); String companyUniqueID = ConvertJson.convertToString(interview.get("company")); if (companyUniqueID == null) { companyUniqueID = ConvertJson.convertToString(UniqueIDGlobalVariables.companyUniqueID.get("ID")); ConvertJson.setStringValue(interview, companyUniqueID, "company"); } String interviewerUniqueID = ConvertJson.convertToString(interview.get("interviewer")); if (interviewerUniqueID == null && UniqueIDGlobalVariables.uniqueID != null) { interviewerUniqueID = ConvertJson.convertToString(UniqueIDGlobalVariables.uniqueID.get("ID")); ConvertJson.setStringValue(interview, interviewerUniqueID, "interviewer"); } this.add(FormField.getStringField("Interviewer", interviewerUniqueID)); String date = ConvertJson.convertToString(interview.get("datetime")); if (date == null) { dateTime.setValue(new Date()); } else { dateTime.setValue(new Date(new Long(date))); } this.add(FormField.getFormField("<font color=red>*</font> Date", dateTime)); String problem = ConvertJson.convertToString(interview.get("problem")); problemField = new ProblemsListbox(problem); this.add(FormField.getFormField("<font color=red>*</font> Problem", problemField)); String customerName = ConvertJson.convertToString(interview.get("customerName")); customerNameField.setValue(customerName); this.add(FormField.getFormField("<font color=red>*</font> Customer Name", customerNameField)); String customerUniqueID = ConvertJson.convertToString(interview.get("customerUniqueID")); customerUniqueIDField.setValue(customerUniqueID); this.add(FormField.getFormField("Customer UniqueID", customerUniqueIDField)); String videoURLValue = ConvertJson.convertToString(interview.get("videoURL")); videoURLField.setValue(videoURLValue); this.add(FormField.getFormField("Video URL", videoURLField)); videoURLField.setWidth("300px"); String notesValue = ConvertJson.convertToString(interview.get("notes")); notes.setHTML(notesValue); this.add(FormField.getFormField("Notes", notes)); notes.setSize("300px", "100px"); }
protected void processHQMF( RichTextArea textArea, SplitLayoutPanel splitLayoutPanel, VerticalPanel summaryVerticalPanel) { String text = textArea.getText(); final ScrollPanel xmlPanel = getPanelForXML(text); if (xmlPanel != null) { splitLayoutPanel.remove(textArea); splitLayoutPanel.add(xmlPanel); } for (final Map.Entry<String, TextArea> entry : bookmarkMap.entrySet()) { String key = entry.getKey(); Label label = new Label(key); label.setStyleName("bookMarkLabel"); label.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { TextArea textArea = entry.getValue(); xmlPanel.setVerticalScrollPosition(textArea.getElement().getOffsetTop()); } }); summaryVerticalPanel.add(label); } }
public void onSave() { ArrayList<Message> messages = new ArrayList<Message>(); WidgetUtil.checkNull( new LabeledContainer[] {name, category, status, license, webpageUrl}, messages); if (isNull(description.getText())) { messages.add(Message.error("Please enter the description", description)); } if (messages.size() > 0) { Messages.get().setMessages(null, messages); return; } product.setDescription(description.getHTML()); if (null == product.getId()) product.setName(name.getComponent().getValue()); List<String> _tags = tags.getValues(); if (null != _tags && _tags.size() > 0) { product.setTags(_tags.toArray(new String[_tags.size()])); } else { product.setTags(null); } product.setOrganizationName(organization.getValue()); product.setVersionNumber(versionNumber.getComponent().getValue()); product.setStatus(status.getValue(status.getSelectedIndex())); product.setLicense(license.getValue(license.getSelectedIndex())); product.setCategoryId(WidgetUtil.getSelectedValue(category.getComponent())); product.setWebsiteUrl(webpageUrl.getValue()); product.setDownloadUrl(downloadUrl.getValue()); product.setWikiUrl(wikiUrl.getValue()); product.setDemoUrl(showcaseUrl.getValue()); product.setIssueTrackerUrl(issueTrackerUrl.getValue()); product.setForumUrl(forumUrl.getValue()); product.setNewsUrl(newsfeedUrl.getValue()); new SaveProductCommand(product) { @Override public void onSuccess(Product result) { pages .goTo( result.getAlias(), new PageRequestSessionWithMessage("The product details were saved.")) .execute(); } }.execute(); }
@Inject public EditDocumentModelPlaceView(EventBus eventBus) { super(eventBus); initWidget(uiBinder.createAndBindUi(this)); this.setPlaceTitle("Éditeur de modèle"); this.setHelpFromFlowPanel(helpContainer); toolbar = new RichTextToolbar(new RichTextToolbarView()); toolbar.setTextArea(richTextArea); richTextArea.setHeight("100%"); toolbar.bind(); toolbarContainer.add(toolbar.getView().asWidget()); name.addStyleName(style.nameDefaultText()); name.addFocusHandler(this); name.addBlurHandler(this); resizer = new ToBottomResizer(textContainer, eventBus); }
public DescriptionCellEditor() { super(); ensureResources(); setStyleName(""); addCloseHandler( new CloseHandler<PopupPanel>() { @Override public void onClose(CloseEvent<PopupPanel> event) { if (event.isAutoClosed()) { commit(); hide(); } } }); VerticalPanel verticalPanel = new VerticalPanel(); textArea = new RichTextArea(); textArea.setTabIndex(0); textArea.addStyleName(resources.style().bDescriptionCellEditor__editor()); textArea.addKeyDownHandler( new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { int keyCode = event.getNativeKeyCode(); if (keyCode == KeyCodes.KEY_ESCAPE) { cancelButton.setFocus(true); // or grid did not get back focus hide(); } else if (keyCode == KeyCodes.KEY_ENTER && event.isControlKeyDown()) { okButton.setFocus(true); // or grid did not get back focus okButton.click(); } } }); VerticalPanel textAreaPanel = new VerticalPanel(); textAreaPanel.add(textArea); HorizontalPanel buttonPanel = new HorizontalPanel(); okButton = new Button(strings.ok()); okButton.addStyleName(resources.style().bDescriptionCellEditor__ok()); okButton.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { commit(); hide(); } }); buttonPanel.add(okButton); cancelButton = new Button(strings.cancel()); cancelButton.addStyleName(resources.style().bDescriptionCellEditor__cancel()); cancelButton.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { hide(); } }); buttonPanel.add(cancelButton); textAreaPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); textAreaPanel.add(buttonPanel); RichTextToolbar textToolbar = new RichTextToolbar(textArea); SimplePanel toolBarPanel = new SimplePanel(textToolbar); toolBarPanel.addStyleName(resources.style().bDescriptionCellEditor__toolbar()); verticalPanel.add(toolBarPanel); verticalPanel.add(textAreaPanel); add(verticalPanel); }
/** * Sets the content of the textbox to the specified value. * * @param newText the new content of the textbox */ public void setHTML(String newText) { bodyWidget.setHTML(newText); }
/** Focus on the text area editor */ public void focus() { textArea.setFocus(true); }
@Override public void proceedSettingReadonly() { textArea.setEnabled(!isReadonly()); }
public int getTextAreaOffsetTop() { return textArea.getAbsoluteTop() - getAbsoluteTop(); }
public void setTextAreaWidth(int width) { textArea.setWidth(width + "px"); }
private void commit() { this.fireEvent(new ValueChangedEvent<String>(textArea.getHTML())); }
public int getTextAreaOffsetLeft() { return textArea.getAbsoluteLeft() - getAbsoluteLeft(); }
/** * Creates a new widget. This class needs access to certain fields and methods on the application * enclosing it. * * @param parent the host application */ public RichTextWidget(final GWTNote parent) { super(); VerticalPanel top = new VerticalPanel(); top.setWidth("100%"); HorizontalPanel header = new HorizontalPanel(); top.add(header); header.setWidth("100%"); header.add(new Label("GWT GearsNote")); header.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); status = new Label("Ready"); header.add(status); this.bodyWidget = new RichTextArea(); bodyWidget.addKeyboardListener( new KeyboardListenerAdapter() { @Override public void onKeyPress(Widget sender, char keyCode, int modifiers) { String newText = bodyWidget.getText(); if (((newText == null) && (curText != null)) || ((newText != null) && !newText.equals(curText))) { curText = newText; } } }); HorizontalPanel controls = new HorizontalPanel(); RichTextToolbar tb = new RichTextToolbar(this.bodyWidget); name = new TextBox(); name.setText("default"); name.setEnabled(false); nameEdit = new PushButton("Edit"); nameEdit.addClickListener( new ClickListener() { public void onClick(Widget sender) { String curName = name.getText(); boolean doNotify = !oldName.equals(curName); if (!nameEditable) { // if becoming editable, store off current value oldName = curName; } if (nameEditable && (curName == null || "".equals(curName))) { // if becoming un-editable, check to make sure it's valid Window.alert("The note name cannot be blank. Please try again."); nameEdit.setText(oldName); return; } // if all else is good, just flip the state nameEditable = !nameEditable; name.setEnabled(nameEditable); nameEdit.getUpFace().setText((nameEditable ? "Confirm" : "Edit")); if (doNotify) { notifyNameListeners(); } } }); nameEdit.addStyleName("edit-button"); options = new ListBox(); controls.add(tb); options.addItem("default"); options.setSelectedIndex(0); options.addChangeListener( new ChangeListener() { public void onChange(Widget sender) { String newName = options.getItemText(options.getSelectedIndex()); name.setText(newName); notifyNameListeners(); } }); HorizontalPanel tmp = new HorizontalPanel(); tmp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); tmp.add(new Label("Note name:")); tmp.add(name); tmp.add(nameEdit); tmp.add(options); controls.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); controls.setWidth("100%"); controls.add(tmp); top.add(controls); top.add(bodyWidget); this.bodyWidget.setWidth("100%"); top.setCellHeight(bodyWidget, ((int) (Window.getClientHeight() * .75)) + "px"); this.bodyWidget.setHeight("100%"); initWidget(top); }
public RichTextArea getSmartTextArea() { final RichTextArea testtextArea = new RichTextArea(); testtextArea.setTitle("test test test."); testtextArea.setText("test test test."); testtextArea.addStyleName("boxsizingBorder"); testtextArea.setWidth("100%"); testtextArea.setHeight("100%"); // testtextArea.addKeyPressHandler(new KeyPressHandler() { // @Override // public void onKeyPress(KeyPressEvent event) { // System.out.println( "KeyPressEvent:" + // event.getCharCode() + ":" + // event.isAnyModifierKeyDown() + ":" + // event.isControlKeyDown()); // } // // // }); testtextArea.addKeyUpHandler( new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { // if(event.getNativeKeyCode() == 32 && event.isControlKeyDown()){ if (event.getNativeKeyCode() == 32) { System.out.println( "Show popup with context sensitive alternatives. Give focus to popup."); event.preventDefault(); event.stopPropagation(); // int xCoOrdinate = event.getNativeEvent().getScreenX(); // int yCoOrdinate = event.getNativeEvent().getScreenY(); RichTextArea richTextArea = (RichTextArea) event.getSource(); String htmlText = richTextArea.getHTML(); boolean isEndParagraphTagRemoved = false; System.out.println("before htmlText:" + htmlText); if (htmlText.endsWith("</p>")) { htmlText = htmlText.substring(0, htmlText.length() - 4); isEndParagraphTagRemoved = true; } System.out.println("after htmlText:" + htmlText); for (int i = htmlText.length() - 2; i >= 0; i--) { char c = htmlText.charAt(i); if (c == ' ') { String newText = htmlText.substring(i).trim(); if (newText.length() > 0) { htmlText = htmlText.substring(0, i); String setHTMLString = htmlText + " <span style='color:blue'>" + newText + " </span>" + (isEndParagraphTagRemoved ? "</p>" : ""); System.out.println(setHTMLString); richTextArea.setHTML(setHTMLString); } else { String setHTMLString = htmlText + (isEndParagraphTagRemoved ? "</p>" : ""); System.out.println(setHTMLString); richTextArea.setHTML(setHTMLString); } break; } } System.out.println("New html:" + richTextArea.getHTML()); // System.out.println("x:"+xCoOrdinate); // System.out.println("y:"+yCoOrdinate); // // ListBox listBox = new ListBox(); // listBox.addItem("define", "define"); // listBox.addItem("function", "function"); // listBox.addItem("library", "library"); // listBox.addItem("using", "using"); // listBox.addItem("include", "include"); // listBox.addItem("public", "public"); // listBox.addItem("private", "private"); // listBox.addItem("valueset", "valueset"); // listBox.addItem("List", "List"); // listBox.addItem("Tuple", "Tuple"); // listBox.addItem("Interval", "Interval"); // // listBox.setVisibleItemCount(listBox.getItemCount()+1); // PopupPanel popupPanel = new PopupPanel(true); // popupPanel.add(listBox); // popupPanel.setPopupPosition(xCoOrdinate, yCoOrdinate); // popupPanel.show(); } } }); return testtextArea; }
/** * Retrieves the current text stored in the UI widget. * * @return the current text in the UI */ public String getHTML() { return bodyWidget.getHTML(); }
protected void initItem(int width, int height) { String legacyHtml = ""; if (toolBar != null) { toolBar.removeFromParent(); } if (textArea != null) { legacyHtml = textArea.getHTML(); textArea.removeFromParent(); } if (mainLayout != null) { removeItem(mainLayout); mainLayout.destroy(); } textArea = new RichTextArea(); toolBar = new RichTextToolbar(textArea, DisplayType.DETAILED); saveButton = new IButton(BLCMain.getMessageManager().getString("ok")); IButton cancelButton = new IButton(BLCMain.getMessageManager().getString("cancel")); cancelButton.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { hide(); } }); final HtmlEditingPresenter pp = HtmlEditingPresenter.getInstance(); final HLayout buttonsLayout = new HLayout(10); buttonsLayout.setAlign(Alignment.CENTER); buttonsLayout.addMember(saveButton); buttonsLayout.addMember(cancelButton); buttonsLayout.setLayoutTopMargin(2); buttonsLayout.setLayoutBottomMargin(2); buttonsLayout.setWidth100(); buttonsLayout.setHeight(25); mainLayout = new VLayout(); mainLayout.setWidth100(); mainLayout.setHeight100(); toolBar.setHeight("60px"); final VLayout toolbarLayout = new VLayout(); toolbarLayout.setWidth100(); toolbarLayout.setHeight(60); toolbarLayout.addMember(toolBar); int textHeight = height - 130; textArea.setHeight(textHeight + "px"); textArea.setWidth(width + "px"); final VLayout textAreaLayout = new VLayout(); textAreaLayout.setWidth100(); textAreaLayout.setHeight(textHeight); textAreaLayout.addMember(textArea); mainLayout.addMember(toolbarLayout); mainLayout.addMember(textAreaLayout); mainLayout.addMember(buttonsLayout); addItem(mainLayout); toolBar.addAssetHandler( new Command() { @Override public void execute() { pp.displayAssetSearchDialog(toolBar); } }); textArea.setHTML(legacyHtml); saveButton.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { if (richTextItem != null) { richTextItem.setValue(toolBar.getHTML()); richTextItem.getForm().fireEvent(new ItemChangedEvent(richTextItem.getJsObj())); } hide(); } }); }
public void onModuleLoad() { TabLayoutPanel tabLayoutPanel = new TabLayoutPanel(2.5, Unit.EM); final SplitLayoutPanel splitLayoutPanel = new SplitLayoutPanel(); final HorizontalPanel hPanel = new HorizontalPanel(); hPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); hPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); hPanel.setSpacing(10); hPanel.add(new HTML("HQMF Viewer.")); Button processHQMFButton = new Button("Process HQMF."); processHQMFButton.addStyleName("sendButton"); hPanel.add(processHQMFButton); hPanel.add(new HTML("\t(For some reason, works only in IE right now.)")); final VerticalPanel summaryVerticalPanel = new VerticalPanel(); summaryVerticalPanel.setSpacing(3); processHQMFButton.setStyleName("summaryVPanel"); summaryVerticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); summaryVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); splitLayoutPanel.addNorth(hPanel, 50); splitLayoutPanel.addWest(summaryVerticalPanel, 0); final RichTextArea textArea = new RichTextArea(); textArea.setTitle("Paste your HQMF XML here."); textArea.setText("Paste your HQMF XML here."); textArea.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { if (textArea.getText().length() < 30 && textArea.getText().equals("Paste your HQMF XML here.")) { textArea.setText(""); } } }); textArea.addStyleName("boxsizingBorder"); textArea.setWidth("100%"); textArea.setHeight("100%"); processHQMFButton.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { processHQMF(textArea, splitLayoutPanel, summaryVerticalPanel); splitLayoutPanel.remove(hPanel); splitLayoutPanel.setWidgetSize(summaryVerticalPanel, 200); splitLayoutPanel.setWidgetToggleDisplayAllowed(summaryVerticalPanel, true); } }); splitLayoutPanel.add(textArea); MySplitLayoutPanel mySplitPanel = new MySplitLayoutPanel(); final VerticalPanel testVerticalPanel = new VerticalPanel(); testVerticalPanel.setSpacing(3); testVerticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); testVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); // final RichTextArea testtextArea = getSmartTextArea(); // final AceEditor testtextArea = getAceEditor(); AceEditor aceTxtArea = new AceEditor(); aceTxtArea.setWidth("100%"); aceTxtArea.setHeight("100%"); mySplitPanel.addEast(testVerticalPanel, 0); mySplitPanel.add(aceTxtArea); // mySplitPanel.add(testtextArea); aceTxtArea.startEditor(); setAceEditorProperties(aceTxtArea); mySplitPanel.setWidgetToggleDisplayAllowed(testVerticalPanel, true); tabLayoutPanel.add(mySplitPanel, "test CQL Editor."); tabLayoutPanel.add(splitLayoutPanel, "HQMF Viewer"); RootLayoutPanel.get().add(tabLayoutPanel); }