How to make gmail search box similar ui in gwt - gwt

We are making an application using GWT that require a search box widget like gmail has.
I dont know how and where to start to make such widget.
Basically what widget/component should i use to make a text box with a dropdown icon,where if i click the dropdown icon it opens a panel with advanced search using gwt.Please help

with UiBinder tool, you can design fastly what you wish :
`
<g:HTMLPanel>
<g:VerticalPanel>
<g:HorizontalPanel>
<g:TextBox/>
<g:PushButton text="V" ui:field="pushButton"/>
<g:PushButton text="Search"/>
</g:HorizontalPanel>
<g:VerticalPanel ui:field="optionsPanel">
<g:HorizontalPanel>
<g:Label text="Foo"/>
<g:TextBox/>
</g:HorizontalPanel>
<g:HorizontalPanel>
<g:Label text="Bar"/>
<g:TextBox/>
</g:HorizontalPanel>
</g:VerticalPanel>
</g:VerticalPanel>
</g:HTMLPanel>
`
and
`
package yde.dev.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.event.dom.client.ClickEvent;
public class SearchLikeGmail extends Composite {
private static SearchLikeGmailUiBinder uiBinder = GWT
.create(SearchLikeGmailUiBinder.class);
#UiField VerticalPanel optionsPanel;
#UiField PushButton moreOptionsBttn;
interface SearchLikeGmailUiBinder extends UiBinder<Widget, SearchLikeGmail> {
}
public SearchLikeGmail() {
initWidget(uiBinder.createAndBindUi(this));
optionsPanel.setVisible( false );
}
#UiHandler("moreOptionsBttn")
void onMoreOptionsBttnClick(ClickEvent event) {
optionsPanel.setVisible( true );
}
}
`

Related

Styleclass not being applied when the previous style class is added in FXML

I assign styleclass of ToggleButton in FXML file as follows:
<ToggleButton fx:id="Button" styleClass="defaultStyle">
Later, in my code I change the style classes as follows:
#FXML private ToggleButton Button;
Button.getStyleClass().remove("defaultStyle");
Button.getStyleClass().add("newStyle");
The CSS file is defined as:
.defaultStyle { -fx-background-color: black;}
.newStyle { -fx-background-color: red;}
EDITED:
The new style is applied when done in the Controller, but the new style is not being applied when done somewhere else. When I debug, I see the correct style-class being added & removed to the button.
Anyone got a workaround for this problem? I appreciate your help in advance.
Style class removing and adding are working as expected. I guess your problem is the ToggleButton has not been injected correctly, it should be:
#FXML private ToggleButton Button;
...
Button.getStyleClass().remove("defaultStyle");
Button.getStyleClass().add("newStyle");
in the controller class. Note the capital b of "Button" since you have defined fx:id="Button" in FXML file. Also note that you don't need to instantiate the ToggleButton Button (like new ToggleButton()) yourself.
EDIT:
Here is code example for changing the styleclass. As I said it is working as expected. Compare it with yours.
Sample.fxml:
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="somepackage.SampleController">
<stylesheets>
<String fx:value="somepackage/style.css" />
</stylesheets>
<children>
<ToggleButton layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="mybutton" styleClass="defaultStyle" />
</children>
</AnchorPane>
SampleController.java:
package somepackage;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ToggleButton;
public class SampleController implements Initializable {
#FXML
private ToggleButton mybutton;
#FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("before :" + mybutton.getStyleClass());
mybutton.getStyleClass().remove("defaultStyle");
mybutton.getStyleClass().add("newStyle");
System.out.println("after :" + mybutton.getStyleClass());
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
MainDemo.java:
package somepackage;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainDemo extends Application {
#Override
public void start(Stage stage) throws Exception {
System.out.println("version: " + com.sun.javafx.runtime.VersionInfo.getRuntimeVersion());
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The css file includes selectors of yours.
Since you said it is only done when the controller does it.
Use the FXMLLoader to load your controller. then you change the StyleClass to the newStyle.

GWT Bootstrap Modal buttons won't work with ClickHandler's onClick

I'm trying to create a dialog box using GWT-Bootstrap modal widget.
I can get it to display but have not been able to get the buttons to recognize events.
The cancel button onClick never fires.
Had some other code to try to get the addClass button to do do something but stripped it out. If I can get the cancel button to do something (anything!) I should be in good shape.
I've also tried the java using addDomHandler and that didn't work either.
Here's the XML:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:a="urn:import:cgs.common.client.gwt.bootstrap"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<b:Modal title="Add Class?" ui:field="addClassModal" backdrop="STATIC" keyboard="true" animation="true">
<a:BootstrapField label="Classname:">
<a:BootstrapTextInput
ui:field="classname"
placeholder="Classname" />
</a:BootstrapField>
<b:Button ui:field="addClass">Add Class</b:Button>
<b:Button ui:field="cancel">Cancel</b:Button>
</b:Modal>
</ui:UiBinder>
And here's the java:
package cgs.teacher.portal.client.view.impl.bootstrap;
import cgs.common.client.gwt.bootstrap.BootstrapTextInput;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Modal;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
public class AddClassDialogViewImpl
extends Composite
{
interface AddClassDialogViewImplUiBinder extends UiBinder<Widget, AddClassDialogViewImpl>
{
}
private static AddClassDialogViewImplUiBinder uiBinder = GWT
.create(AddClassDialogViewImplUiBinder.class);
#UiField
Modal addClassModal;
#UiField
BootstrapTextInput classname;
#UiField
Button addClass;
#UiField
Button cancel;
public AddClassDialogViewImpl()
{
initWidget(uiBinder.createAndBindUi(this));
cancel.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
addClassModal.hide();
}
});
addClassModal.toggle(); //PS. Show gave error. Had to use toggle to show!
}
}
Thanks!
Another workaround which I have found is adding the Modal component to the RootPanel :
public AddClassDialogViewImpl() {
initWidget(uiBinder.createAndBindUi(this));
cancel.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
//hide the widget
addClassModal.hide();
// unless you want to keep this modal as a singleton, you need to remove it from the DOM
RootPanel.get().remove(AddClassDialogViewImpl.this);
}
});
//add the widget to the DOM
RootPanel.get().add(this);
// show the widget
addClassModal.show();
}

Change span element style for GWT Cell using UiRenderer

How do I change the style for a Span HTML element when using UiRenderer with GWT 2.5?
I have setup a simple cell to be used in a CellTable. The ui.xml looks like this :
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder">
<ui:with field='stkval' type='java.lang.String'/>
<ui:with field='stkchg' type='java.lang.String'/>
<ui:with field='res' type='com.mycompanyclient.client.Enres'/>
<div id="parent">
<span><ui:text from='{stkval}'/></span>.
[<span class="{res.newstyle.positive}" ui:field="signSpan">
<ui:text from='{stkchg}'/>
</span>]
</div>
</ui:UiBinder>
Now when this cell is instantiated by the CellTable, I expect to change the class name of the signSpan to be changed based on the value passed into the render function. My java code looks something like this:
public class IndCell extends AbstractCell<QuoteProxy> {
#UiField
SpanElement signSpan;
#UiField(provided=true)
Enres res = Enres.INSTANCE;
interface MyUiRenderer extends UiRenderer {
SpanElement getSignSpan(Element parent);
void render(SafeHtmlBuilder sb, String stkval,String stkchg);
}
private static MyUiRenderer renderer = GWT.create(MyUiRenderer.class);
public IndCell() {
res.newstyle().ensureInjected();
}
#Override
public void render(com.google.gwt.cell.client.Cell.Context context,
QuoteProxy value, SafeHtmlBuilder sb) {
if (value.getChangeSign().contentequals('d')) {
renderer.getSignSpan(/* ?? */).removeClassName(res.newstyle().negative());
renderer.getSignSpan(/* ?? */).addClassName(res.newstyle().positive());
}
renderer.render(sb, value.getAmount(),value.getChange());
}
If I try to use the UiField directly it is set to Null. That makes sense because I am not calling the createandbindui function like I would for UiBinder. The renderer.getSignSpan looks promising but I dont know what to pass for parent.
All the example I could find use a event to identify the parent. But I dont want to click the cell generated.
Is there a way of changing style in the render method?
Because the class of the element is not a constant, you'll want to pass it as an argument to the render method so the cell's render reads:
public void render(Cell.Context context, QuoteProxy value, SafeHtmlBuilder sb) {
renderer.render(sb, value.getAmount(), value.getChange(),
value.getChangeSign().contentequals('d') ? res.newstyle.positive() : res.newstyle.negative());
}
I just thought that I would provide an example solution for those that are still struggling with this. In the case where you want to set the style prior to rendering, like in the case of rendering a positive value as "green" and a negative value as "red", you would do the following:
This would be your cell class:
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.uibinder.client.UiRenderer;
public class ExpenseInfoCell extends AbstractCell<YourClassProxy> {
interface ExpenseInfoCellUiRenderer extends UiRenderer {
void render(SafeHtmlBuilder sb, String cost, String newStyle);
ValueStyle getCostStyle();
}
private static ExpenseInfoCellUiRenderer renderer = GWT
.create(ExpenseInfoCellUiRenderer.class);
#Override
public void render(Context context, YourClassProxy value, SafeHtmlBuilder sb) {
String coloredStyle = (value.getCost() < 0) ? renderer.getCostStyle()
.red() : renderer.getCostStyle().green();
renderer.render(sb, value.getCost()),
coloredStyle);
}
}
And this would be the accompanying UiBinder xml file
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder">
<ui:style field="costStyle" type="com.myproject.client.tables.MyValueStyle">
.red {
color: red;
}
.green {
color: green;
}
</ui:style>
<ui:with type="java.lang.String" field="cost" />
<ui:with type="java.lang.String" field="newStyle" />
<div>
<span class='{newStyle}'>
<ui:text from='{cost}' />
</span>
</div>
</ui:UiBinder>
Also, note that the field="costStyle" matches the getter in the class "getCostStyle". You must follow this naming convention otherwise the renderer will throw an error.

GWT: Export a CellTable to an image or pdf file

I have a CellTable showing data that is plotted in a GFlot SimplePlot.
An export of the plot is possible with GFlots integrated function:
exportImage = plot.getImage();
Now I would like to export the CellTable too, to show the corresponding data to the plot.
Is this possible in some way with GWT on the client-side? It needn't to be the CellTable itself, just the data it shows would suffice.
I think You can use flash4j library:
package com.emitrom.flash4j.demo.client;
import com.emitrom.flash4j.clientio.client.ClientIO;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
public class ClientIOExample implements EntryPoint {
#Override
public void onModuleLoad() {
// initialize the ClientIO module
ClientIO.init();
Button b = new Button("Click Me");
b.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
// create a PDF File
PDF pdf = new PDF();
pdf.addPage();
pdf.setTextStyle(new RGBColor(0x000000));
pdf.setFont(new CoreFont(), 10);
pdf.addText("");
ClientIO.saveFile(pdf.save(), "file.pdf");
}
});
RootPanel.get().add(b);
}
}
You can see more detailed information a link

GWT/JAVA - Getting an AJAX call into a dialog box

I'm new to GWT, and having an issue getting the result of an AJAX call to show up in my Dialog box.
I set up my dialog box, Vpanel, and response label here:
VerticalPanel eventDetailWindow = new VerticalPanel();
final DialogBox dialogBox2 = new DialogBox();
dialogBox2.setText("Event Detail");
dialogBox2.setAnimationEnabled(true);
final HTML serverResponse3 = new HTML("<b> ok, this is working</b>");
serverResponse3.addStyleName("detailView");
eventDetailWindow.add(serverResponse3);
eventDetailWindow.addStyleName("detailWindow");
dialogBox2.setWidget(eventDetailWindow);
RootPanel.get("detailWindow").add(eventDetailWindow);
Then, in the onSuccess method I have this:
dialogBox2.setText("Remote Procedure Call");
serverResponse3.setHTML(result);
dialogBox2.center();
closeButton.setFocus(true);
However, when it fires, the response shows up on the page, not in the dialog box and the dialog box is empty. It looks like it's set up the same as the starter project - which works fine..
Can someone help me out...?
Dont use that RootPanel.get("detailWindow").add(eventDetailWindow);
if you want to only add into dialogBox2
use like that:
dialogBox2.setWidget(eventDetailWindow);
and You dont have to add dialogBox2.show(); because dialogBox2.center(); that code will show the dialogBox2 initially.
package com.ex.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class Example implements EntryPoint {
public void onModuleLoad() {
VerticalPanel eventDetailWindow = new VerticalPanel();
final DialogBox dialogBox2 = new DialogBox();
dialogBox2.setText("Event Detail");
dialogBox2.setAnimationEnabled(true);
final HTML serverResponse3 = new HTML("<b> ok, this is working</b>");
serverResponse3.addStyleName("detailView");
eventDetailWindow.add(serverResponse3);
eventDetailWindow.addStyleName("detailWindow");
dialogBox2.setWidget(eventDetailWindow);
Button b= new Button("click");
b.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
dialogBox2.setText("Remote Procedure Call");
serverResponse3.setHTML("result");
dialogBox2.center();
}
});
RootPanel.get().add(b);
}
}
You are adding the eventDetailWindow to something on the page and I don't see a call to .show() on the DialogBox. Can you post your full code?