Items does not sets disabled after first click on ListBox in Chrome - gwt

Here is my code:
listbox.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
serv.getSlotStatusesStrings(clientFactory.getWorkspaceId(), new AsyncCallback<SlotStatusGwtStruct>() {
#Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
#Override
public void onSuccess(SlotStatusGwtStruct result) {
List<String> statusList = Arrays.asList(result.styleName);
int emtyCounter = 0;
boolean passFlag = false;
boolean failFlag = false;
for(String status : statusList){
if(status.equals("empty")){
emtyCounter++;
}else if(status.equals("pass")){
passFlag = true;
}else if(status.equals("fail")){
failFlag = true;
}
}
if(emtyCounter == statusList.size()){
listbox.getElement().<SelectElement>cast().getOptions().getItem(0).setDisabled(true);
}
if(passFlag == false){
listbox.getElement().<SelectElement>cast().getOptions().getItem(1).setDisabled(true);
}
if(failFlag == false){
listbox.getElement().<SelectElement>cast().getOptions().getItem(2).setDisabled(true);
}
}
});
}
});
}
In Firefox it works ok, but in Chrome browser when I click on listbox at the first time all my items are enabled (by condition they should be disabled), and after I made one more click I have the expected result.
Could yo please give me some advice how to resolve this issue.

Related

Android Webview signout issue

In my webview app when I run the app for the first time and log out from a user session, close the app and then when I open the app again instead of asking user credentials I find myself already logged in. I tried clearing cookies but then it always require sign in on every restart. I only want it to ask for sign in when the user logs out from the app.
Please Help!!
Here is a snippet of the code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frameLayout = (FrameLayout) findViewById(R.id.framelayout);
bar = (ProgressBar) findViewById(R.id.progressBar2);
bar.setMax(100);
webview = (WebView) findViewById(R.id.mywebview);
webview.clearCache(true);
webview.clearHistory();
WebSettings mWebSettings = webview.getSettings();
mWebSettings.setSaveFormData(false);
swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
LoadWeb();
}
});
LoadWeb();
}
public void LoadWeb(){
webview = (WebView) findViewById(R.id.mywebview);
webview.setWebViewClient(new HelpClient());
webview.setWebChromeClient(new WebChromeClient(){
#Override
public void onProgressChanged(WebView view, int newProgress) {
frameLayout.setVisibility(View.VISIBLE);
bar.setProgress(newProgress);
setTitle("Loading....");
if (newProgress == 100){
frameLayout.setVisibility(View.GONE);
setTitle(view.getTitle());
}
super.onProgressChanged(view, newProgress);
}
});
webview.getSettings().setJavaScriptEnabled(true);
webview.setVerticalScrollBarEnabled(false);
webview.loadUrl(WebAddress);
webview.loadUrl("javascript:window.location.reload(true)");
swipe.setRefreshing(false);
bar.setProgress(0);
}
private class HelpClient extends WebViewClient{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
frameLayout.setVisibility(view.VISIBLE);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
swipe.setRefreshing(false);
}
#Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
try {
webview.stopLoading();
} catch (Exception e) {
}
if (webview.canGoBack()) {
webview.goBack();
}
webview.loadUrl("about:blank");
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Error");
alertDialog.setMessage("Check your internet connection and try again.");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Try Again", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
startActivity(getIntent());
}
});
alertDialog.show();
super.onReceivedError(view, request, error);
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK){
if (webview.canGoBack()){
webview.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
Run below code before loadUrl()
WebStorage webStorage = WebStorage.getInstance();
webStorage.deleteAllData();
CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
I test it using Gmail account
CookieSynManager is now deprecated. This works for me :
WebStorage.getInstance().deleteAllData()
CookieManager.getInstance().removeAllCookies(null)

Why does setText in the TextField doesn't work?

Why does this method doesn't save the new selected categories. is there something wrong with my codes?
catCon = new TextField();
rowEditing.addEditor(catConfig, catCon);
this is the code for setting the catCon:
TextButton save = new TextButton("Save");
save.addSelectHandler(new SelectEvent.SelectHandler() {
#Override
public void onSelect(SelectEvent event) {
selectedItems = new LinkedList<Short>();
for (int i = 0; i < toCat.size(); i++) {
selectedItems.add(toCat.get(i).getIDCategory());
}
Collections.sort(selectedItems);
newSelectedItems = selectedItems.toString().replace(",", "-").replace("[", "").replace("]", "").replace(" ", "");
msg = new MessageBox("SELECTED ITEMSSSSSSSSS: " + selectedItems.size() + " " + newSelectedItems);;
msg.show();
catCon.setText(newSelectedItems);
hide();
}
});
and this is where the saving of the commited changes:
rowEditing.getSaveButton().addSelectHandler(new SelectEvent.SelectHandler() {
#Override
public void onSelect(SelectEvent event) {
store.commitChanges();
service.saveUserRights(store.get(index), new AsyncCallback<Boolean>() {
#Override
public void onFailure(Throwable caught) {
msg = new MessageBox("Error", caught.getMessage());
msg.show();
}
#Override
public void onSuccess(Boolean result) {
if (result) {
msg = new MessageBox("Information", "Changes saved.");
msg.show();
service.getURListGrid(new AsyncCallback<List<UserRights>>() {
#Override
public void onFailure(Throwable caught) {
MessageBox msg = new MessageBox("Error", caught.getMessage());
msg.show();
}
#Override
public void onSuccess(List<UserRights> result) {
store = new ListStore<UserRights>(properties.idRight());
store.addAll(result);
grid.reconfigure(store, cm);
}
});
} else {
msg = new MessageBox("Error", "Failed to save changes.");
msg.show();
}
}
});
}
});
When I am going to set the catCon there will no be changes of the data but when I manually type the categories there will be a change. Can somebody help me?
In order for me to save the current categories is to get the index of the store and set the category to the newSelectedItem
store.get(index).setCategories(newSelectedItems);
I hope this will help to the people who has the same problem as mine.

DoubleClick on a row in JfaceTable to get the details of object on that row

In eclipse e4.
On double clicking on a row in jface table I want to see the data on that row as a dialog.
Existing Code
orgTable.addDoubleClickListener(new IDoubleClickListener() {
#Override
public void doubleClick(DoubleClickEvent event) {
System.out.println("Double CLikc works");
}
});
OrgTable.addDoubleClickListener(new IDoubleClickListener() {
#Override
public void doubleClick(DoubleClickEvent event) {
System.out.println("Double CLikc works");
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
OrgDetails org = (OrgDetails) sel.getFirstElement();
if(org != null){
System.out.println("Double-click on : "+ org.getOrgName()+ " " + org.getTin());
}
System.out.println(orgTable.getElementAt());
}
});

Refresh ListView when Device receives GCM IntentService Message

My app is able to receive messages from GCM and saves the messages to the SQLlite database on the phone. The messages are viewable in a activity that has a listview.
In the code below, the onPause() function refreshes the listView. This is not a good implementation because it only works if the activity is not displayed at the time of the update. If the activity is displayed at the time of an update, the list is static and does not update.
Questions:
How to I update the listview when the activity is being displayed? Or is there a way to use a background service to update the adapter, so that whenever the activity is displayed, it always shows the newest data.
is this kind of functionality currently not possible with android and I'll need to implement something else like 'pull-to-refresh'?
refreshing listview in OnResume() crashes the application, and shows a null pointer exception.
Activity:
public class NotesView extends Activity implements OnItemClickListener {
ListView listView;
NoteAdapter objAdapter;
NotificationsDatabase db = new NotificationsDatabase(this);
List<Notes> listAlerts;
String note;
String time;
TextView noteView;
TextView timeView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.note);
listView = (ListView) findViewById(R.id.notelist);
listView.setOnItemClickListener(this);
noteView = (TextView) findViewById(R.id.noteDisplay);
timeView = (TextView) findViewById(R.id.notetimeStampDisplay);
new MyTask().execute();
}
// My AsyncTask start...
class MyTask extends AsyncTask<Void, Void, List<Notes>> {
ProgressDialog pDialog;
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(NotesView.this);
pDialog.setMessage("Loading...");
pDialog.setCancelable(false);
pDialog.show();
if (isCancelled()) {
this.cancel(true);
}
}
#Override
protected List<Notes> doInBackground(Void... params) {
db.open();
listAlerts = db.getData();
if (isCancelled()) {
this.cancel(true);
}
return null;
}
protected void onPostExecute(List<Notes> alerts) {
if (null != pDialog && pDialog.isShowing()) {
pDialog.dismiss();
}
db.close();
setAdapterToListview();
}
}// end myTask
public void setAdapterToListview() {
objAdapter = new NoteAdapter(NotesView.this, R.layout.row_notes, listAlerts);
objAdapter.sortByNoteDesc();
objAdapter.notifyDataSetChanged();
listView.setAdapter(objAdapter);
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
Intent intent = new Intent(
NotesView.this.getApplicationContext(),
TabBarExample.class);
intent.putExtra("goToTab", "Alerts");
startActivity(intent);
return true;
}
return super.onKeyDown(keyCode, event);
}
public void onItemClick(AdapterView<?> parent, View viewDel, int position,
long id) {
for (int i = 0; i < 1; i++) {
Notes item = listAlerts.get(position);
int ids = item.getId();
note = item.getNote();
time = item.getTimeStamp();
}
System.out.println(note + " " + time);
//
}
#Override
protected void onResume() {
super.onResume();
}
#Override
protected void onPause() {
super.onPause();
setContentView(R.layout.note);
listView = (ListView) findViewById(R.id.notelist);
listView.setAdapter(null);
listView.setOnItemClickListener(this);
noteView = (TextView) findViewById(R.id.noteDisplay);
timeView = (TextView) findViewById(R.id.notetimeStampDisplay);
new MyTask().execute();
}
#Override
protected void onDestroy() {
}
}
Code snippets From GCMIntentService
#Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
//String message = getString(R.string.gcm_message);
System.out.println("onMessage: ");
Bundle extras = intent.getExtras();
String message = extras.getString("message");
String event_id_from_server = extras.getString("server_id");
// displayMessage(context, message);
generateNotification(context, message);
saveMsg(message);
System.out.println("server id is " + event_id_from_server);
if (event_id_from_server != null) {
updateLocalDatabase(event_id_from_server);
}
}
public void saveMsg(String msg) {
boolean worked = true;
try {
NotificationsDatabase entry = new NotificationsDatabase(GCMIntentService.this);
entry.open();
java.util.Date date = new java.util.Date();
Timestamp x = new Timestamp(date.getTime());
String timeStamp = x.toLocaleString();
entry.createEntry(msg, timeStamp);
entry.close();
//update adapter service
} catch (Exception e) {
worked = false;
String error = e.toString();
System.out.println(error);
} finally {
if (worked) {
}
}
}
I cleaned up your code a little bit. Basically all the view assignments should be done once in onCreate, while the loading of the data should be done in onResume(). See if this helps:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.note);
listView = (ListView) findViewById(R.id.notelist);
listView.setAdapter(null);
listView.setOnItemClickListener(this);
noteView = (TextView) findViewById(R.id.noteDisplay);
timeView = (TextView) findViewById(R.id.notetimeStampDisplay);
}
#Override
protected void onResume() {
super.onResume();
new MyTask().execute();
}
#Override
protected void onPause() {
super.onPause();
}

GWT Multi-threaded effect

I know GWT is single threaded by nature, however I am trying to user deferred command to emulate a multi-threaded effect. I am trying to implement a text animation which is controlled by the isBusy boolean variable, which the text manipulation (animation effect) runs unti isBusy gets false value, when the server responded already. However this code seems to get stuck with the while-loop?
Here is the code:
loginButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
isBusy = true; // boolean
// Show animating effect...
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
#Override
public void execute() {
while(isBusy == true) {
for (int i=0;i<3;i++) {
if (i==0) { loginButton.setText("."); }
if (i==1) { loginButton.setText(".."); }
if (i==2) { loginButton.setText("..."); }
}
}
}
});
loginService.getUser(usernameBox.getText(), passwordBox.getText(), new AsyncCallback<User>() {
#Override
public void onSuccess(User result) {
isBusy = false;
}
#Override
public void onFailure(Throwable caught) {
isBusy = false;
}
});
}
});
Scheduler was the right tool, but you are using the wrong command. You have to use scheduleFixedPeriod insdead of scheduleDeferred. Here is a small example which showes hopefully helps you.
#Override
public void onModuleLoad() {
final Label l = new Label("");
RootPanel.get().add(l);
Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() {
#Override
public boolean execute() {
int i = l.getText().length();
if (i == 0) {
l.setText(".");
}
else if (i == 1) {
l.setText("..");
}
else if (i == 2) {
l.setText("...");
}
else if (i == 3) {
l.setText("");
}
return true; //as long as it returns true the execute is repealed after XX milliseconds
}
}, 200);
}