Want to hit a rest service with clicking a button - smartgwt

I have a button on a ListGrid, for the button I have:
.addClickHandler(new ClickHandler()
{
#Override
public void onClick(final ClickEvent event)
{
SC.confirm("Are you sure?", new BooleanCallback()
{
#Override
public void execute(Boolean value)
{
if (value == null || Boolean.FALSE.equals(value))
{
event.cancel();
return;
}
// How do I call RS : //localhost:8080/service/task1
}
});
}
How do I send a request to that rest service URL? the base URL is the same, they are on the same grid. The type is a #GET

You can create RestDataSource in SmartGWT. Something like this
final RestDataSource dataSource = new RestDataSource() {
#Override
protected Object transformRequest(DSRequest request) {
request.setHttpMethod("GET"); // To set the HTTP method as "GET"
return super.transformRequest(request);
}
};
dataSource.setDataFormat(DSDataFormat.JSON); //set format
dataSource.setFields(); // set fields
dataSource.setDataURL("localhost:8080/service/task1");
On Click of the button call this:
dataSource.fetchData();

Related

What happens if user clicks on deep link in the app itself

If I have created a deep link using the branch.io that opens a specific screen in my app. If this link is also available in my app and a user clicks on it, will it open my screen? or it will do nothing as the link I am trying to open from the app is pointing to the same app?
When you click on a Branch link within a webView in your App, you will have to handle the routing to the specific Activity, after reading the Branch link parameters.
Here is a sample Activity which contains a webView and and shows a couple of Branch links. When you click on a link in the webView it reopens the webview and displays the link parameters in a Toast message if a Branch link is clicked
public class MainActivity extends AppCompatActivity {
private WebView webView_;
private Button button_;
private String TAG = "WebViewController";
private Context context_;
private static final String URL_TO_LOAD = "https://evangelosg.github.io/index.html";
private static final String BRANCH_LINK_TO_LOAD = "https://ere6.app.link/b6sS0gsCfG";
#Override
protected void onNewIntent(Intent intent) {
Log.d("WebView", "onNewIntent");
setIntent(intent);
}
#Override
protected void onResume() {
super.onResume();
Branch branch = Branch.getInstance();
branch.initSession(new Branch.BranchReferralInitListener() {
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
Log.d(TAG, referringParams.toString());
Toast.makeText(context_, referringParams.toString(), Toast.LENGTH_LONG).show();
if (referringParams.has(BundleExtraKeys.CLICKED_BRANCH_LINK)) {
try {
boolean clickedBranchLink = referringParams.getBoolean(BundleExtraKeys.CLICKED_BRANCH_LINK);
if (clickedBranchLink) {
//do stuff!
}
} catch (JSONException e) {
Log.d("BranchTrends", e.getMessage());
}
}
} else {
Log.i("MyApp", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
#Override
protected void onStart() {
super.onStart();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context_ = this;
setContentView(R.layout.activity_main);
webView_ = (WebView) findViewById(R.id.webView);
webView_.setWebViewClient(new BranchWebViewController("app.link", MainActivity.class));
webView_.loadUrl(URL_TO_LOAD);
button_ = (Button) findViewById(R.id.button);
button_.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.putExtra("branch", BRANCH_LINK_TO_LOAD);
customTabsIntent.intent.putExtra("branch_force_new_session", true);
finish();
customTabsIntent.launchUrl(MainActivity.this, Uri.parse(BRANCH_LINK_TO_LOAD));
}
});
}
public class BranchWebViewController extends WebViewClient {
private String myDomain_;
private Class activityToLaunch_;
BranchWebViewController(#NonNull String myDomain, Class activityToLaunch) {
myDomain_ = myDomain;
activityToLaunch_ = activityToLaunch;
}
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
String url = request.getUrl().toString();
if (url.contains(myDomain_)) {
Intent i = new Intent(view.getContext(), activityToLaunch_);
i.putExtra("branch", url);
i.putExtra("branch_force_new_session", true);
finish();
startActivity(i);
} else {
view.loadUrl(url);
}
return true;
}
}
}
Once you read the link parameters you can route to the appropriate Activity based on the link parameters.

OptionGroup addValueChangeListener CheckBox

Vaadin 7.6.5.
I am trying to figure out why a value change listener fails in the below case?
The CheckBox is observing for addValueChangeListener OptionGroup.
#Theme("vaadindemo")
public class VaadindemoUI extends UI {
#WebServlet(value = "/*", asyncSupported = true)
#VaadinServletConfiguration(productionMode = false, ui = VaadindemoUI.class)
public static class Servlet extends VaadinServlet {
}
#Override
protected void init(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
OptionGroup group = new OptionGroup();
group.addItem("01");
group.setItemCaption("01", "ONE");
group.addItem("02");
group.setItemCaption("02", "TWO");
group.addItem("03");
group.setItemCaption("03", "THREE");
group.addValueChangeListener(new ValueChangeListener() {
#Override
public void valueChange(ValueChangeEvent event) {
System.out.println("group getValue " + event.getProperty().getValue());
System.out.println("group getType " + event.getProperty().getType());
}
});
CheckBox box = new CheckBox();
box.setCaption("Check Me");
//Notify CheckBox of value change of radio button
//group.addValueChangeListener(box); -- // Code Fails
//box.addValueChangeListener(group); // Selected Radio Button is removed
TextField field = new TextField();
field.addValueChangeListener(new ValueChangeListener() {
#Override
public void valueChange(ValueChangeEvent event) {
System.out.println("field getValue " + event.getProperty().getValue());
System.out.println("field getType " + event.getProperty().getType());
System.out.println("field getType " + field.getValue());
}
});
group.addValueChangeListener(field);// The value is reflected. How do i get only the event without over writing the value
//group.addValueChangeListener(box);
layout.addComponent(group);
layout.addComponent(box);
layout.addComponent(field);
Button button = new Button("Click Me");
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
layout.addComponent(new Label("Thank you for clicking"));
}
});
layout.addComponent(button);
}
}
It logs:
com.vaadin.data.util.converter.Converter$ConversionException: Unable to convert value of type java.lang.String to presentation type class java.lang.Boolean. No converter is set and the types are not compatible.
at com.vaadin.data.util.converter.ConverterUtil.convertFromModel(ConverterUtil.java:116)
at com.vaadin.ui.AbstractField.convertFromModel(AbstractField.java:736)
at com.vaadin.ui.AbstractField.convertFromModel(AbstractField.java:721)
at ...
I think you want something like...
group.addValueChangeListener(new ValueChangeListener() {
#Override
public void valueChange(ValueChangeEvent event) {
//Do something with box here? e.g...
box.setValue(!box.getValue());
}
});
rather than...
group.addValueChangeListener(box);

Can I set custom onClick on my timeline using fabric sdk?

I am creating a Twitter client using Fabric but I can not create a custom onClick.
I created this custom adapter and tried to create a OnClickListener but not working. Always open in browser tweet.
public class TweetAdapter extends TweetTimelineListAdapter {
public ArrayList<Long> tweetIds=new ArrayList<Long>();
public TweetAdapter(Context context, Timeline<Tweet> timeline) {
super(context, timeline);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Object rowView = convertView;
final Tweet tweet = (Tweet)this.getItem(position);
if(convertView == null) {
rowView = new CompactTweetView(this.context, tweet);
} else {
((BaseTweetView)convertView).setTweet(tweet);
((View)rowView).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
tweetIds.add(tweet.getId());
}
});
}
return (View)rowView;
}
}
In BaseTweetView class it is the function type OnClickListener but in this case I can't think of any idea to overwrite.
private void setPermalinkLauncher() {
BaseTweetView.PermalinkClickListener listener = new BaseTweetView.PermalinkClickListener();
this.setOnClickListener(listener);
this.contentView.setOnClickListener(listener);
}
class PermalinkClickListener implements OnClickListener {
PermalinkClickListener() {
}
public void onClick(View v) {
if(BaseTweetView.this.getPermalinkUri() != null) {
BaseTweetView.this.scribePermalinkClick();
BaseTweetView.this.launchPermalink();
}
}
}
Any ideas? Thanks
Finally I made this works using a custom Adapter (very similar that the one you use in the question). This adapter obtains the resulting view from super implementation and adds an onClickListener to overrides the fabric defaults one:
class CustomTweetTimelineListAdapter extends TweetTimelineListAdapter {
public CustomTweetTimelineListAdapter(Context context, Timeline<Tweet> timeline) {
super(context, timeline);
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
//disable subviews to avoid links are clickable
if(view instanceof ViewGroup){
disableViewAndSubViews((ViewGroup) view);
}
//enable root view and attach custom listener
view.setEnabled(true);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String tweetId = "click tweetId:"+getItemId(position);
Toast.makeText(context, tweetId, Toast.LENGTH_SHORT).show();
}
});
return view;
}
//helper method to disable subviews
private void disableViewAndSubViews(ViewGroup layout) {
layout.setEnabled(false);
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof ViewGroup) {
disableViewAndSubViews((ViewGroup) child);
} else {
child.setEnabled(false);
child.setClickable(false);
child.setLongClickable(false);
}
}
}
}
Full code example here.
Hope it helps.

How to create a drop down list on right click in GWT

I am creating a Dropdown list which should have CREATE, DELETE, SUBMIT for a particular row in a table. Can someone help me how to create one in GWT.
table.addCellPreviewHandler(new Handler<RequestDto>()
{
#Override
public void onCellPreview(CellPreviewEvent<RequestDto> event)
{
if (event.getNativeEvent().getButton() == NativeEvent.BUTTON_RIGHT)
{
MenuBar options = new MenuBar();
MenuBar gwtPop = new MenuBar();
options.addItem("Create", gwtPop);
options.addItem("Submit", gwtPop);
MenuItem Import = new MenuItem(new SafeHtmlBuilder().appendEscaped("Import").toSafeHtml());
Import.setScheduledCommand(new ScheduledCommand()
{
#Override
public void execute()
{
Window.alert("hello");
}
});
final DialogBox menuWrapper = new DialogBox(true);
menuWrapper.add(options);
gwtPop.addItem(Import);
First of all, do not construct your menu inside onCellPreview method. There is no need to build the same widget over and over again on each click.
You can do something like this:
int clickedRow = -1;
...
// build your menu here
// use clickedRow where necessary, for example:
deleteMenuItem.setScheduledCommand(new ScheduledCommand() {
#Override
public void execute() {
Window.alert("hello, I am about to delete row " + clickedRow);
}
});
...
myTable.addCellPreviewHandler(new Handler<MyObject>() {
#Override
public void onCellPreview(CellPreviewEvent<MyObject> event) {
if (event.getNativeEvent().getButton() == NativeEvent.BUTTON_RIGHT) {
event.getNativeEvent().stopPropagation();
clickedRow = event.getIndex();
// show your menu - no need to construct it again
}
}

How to create an URL in Blackberry program

Can anyone tell me how to create an URL link in Blackberry, which opens a web page after it's been clicked?
// This can eb a nested class in your screen class.
class URLButtonField extends ButtonField {
String url;
public URLButtonField(String label, String url) {
super(label);
this.url = url;
}
public String getURL() {
return url;
}
public void setURL(String url) {
this.url = url;
}
}
// member variable of your screen class- this will let you access it later
// to change the URL
URLButtonField bf;
// In your screen's constructor:
bf = new ButtonField("Example", "http://www.example.com");
bf.setFieldChangeListener( new FieldChangeListener() {
void fieldChanged(Field field, int context) {
if (field == this) {
BrowserSession session =- Browser.getDefaultSession();
session.displayPage(getURL());
}
}
} );
add(bf);
You can then change the text or destination URL of "bf" at any time, and whatever you change it to will be the URL that is launched when it is clicked:
// In response to some activity:
bf.setText("Example Two");
bf.setURL("http://www.example.com/two");

Resources