Handling click event on SmartGWT RibbonBar - smartgwt

I have a ribbonBar with 4 Button on it. Now on each of the button clicked I want to perform some action. But the problem I have is how do I get to know which button is clicked. Can somebody guide me.Below is my code and screenshot. By the way I am using Button instead of the IconButton as shown in the showcase.is it OK if i use this button??.
public class DBilling implements EntryPoint
{
#Override
public void onModuleLoad()
{
VLayout vLayout = new VLayout();
vLayout.setWidth100();
RibbonBar ribbonBar = new RibbonBar();
ribbonBar.setLeft(0);
ribbonBar.setTop(0);
ribbonBar.setWidth100();
ribbonBar.setMembersMargin(2);
ribbonBar.setLayoutMargin(2);
RibbonGroup orderGroup = new RibbonGroup();
orderGroup.setTitle("New Order");
orderGroup.setRowHeight(60);
orderGroup.addControl(getButton("Order", "order", false));
RibbonGroup reportGroup = new RibbonGroup();
reportGroup.setTitle("Report");
reportGroup.setRowHeight(60);
reportGroup.addControl(getButton("Report", "report", false));
RibbonGroup productGroup = new RibbonGroup();
productGroup.setTitle("New Product");
productGroup.setRowHeight(60);
productGroup.addControl(getButton("Product", "cookies", false));
RibbonGroup systemGroup = new RibbonGroup();
systemGroup.setTitle("System");
systemGroup.setRowHeight(60);
systemGroup.addControl(getButton("System", "system", false));
ribbonBar.addMember(orderGroup);
ribbonBar.addMember(reportGroup);
ribbonBar.addMember(productGroup);
ribbonBar.addMember(systemGroup);
vLayout.addChild(ribbonBar);
vLayout.draw();
}
private Button getButton(String title, String iconName, boolean vertical)
{
final Button cssButton = new Button(title);
cssButton.setShowRollOver(true);
cssButton.setShowDisabled(true);
cssButton.setShowDown(true);
cssButton.setIcon(iconName + ".png");
cssButton.setIconSize(32);
cssButton.setWidth(120);
cssButton.addClickHandler(new ClickHandler()
{
#Override
public void onClick(ClickEvent event)
{
SC.say(event.getSource().toString());
}
});
return cssButton;
}

Untested, but I think something like this is what you want:
public class DBilling implements EntryPoint
{
private RibbonBar ribbonBar;
#Override
public void onModuleLoad()
{
VLayout vLayout = new VLayout();
vLayout.setWidth100();
this.ribbonBar = new RibbonBar();
this.ribbonBar.setLeft(0);
this.ribbonBar.setTop(0);
this.ribbonBar.setWidth100();
this.ribbonBar.setMembersMargin(2);
this.ribbonBar.setLayoutMargin(2);
RibbonGroup orderGroup = new RibbonGroup();
orderGroup.setTitle("New Order");
orderGroup.setRowHeight(60);
orderGroup.addControl(getButton("Order", "order", false));
RibbonGroup reportGroup = new RibbonGroup();
reportGroup.setTitle("Report");
reportGroup.setRowHeight(60);
reportGroup.addControl(getButton("Report", "report", false));
RibbonGroup productGroup = new RibbonGroup();
productGroup.setTitle("New Product");
productGroup.setRowHeight(60);
productGroup.addControl(getButton("Product", "cookies", false));
RibbonGroup systemGroup = new RibbonGroup();
systemGroup.setTitle("System");
systemGroup.setRowHeight(60);
systemGroup.addControl(getButton("System", "system", false));
this.ribbonBar.addMember(orderGroup);
this.ribbonBar.addMember(reportGroup);
this.ribbonBar.addMember(productGroup);
this.ribbonBar.addMember(systemGroup);
vLayout.addChild(this.ribbonBar);
vLayout.draw();
}
private Button getButton(String title, String iconName, boolean vertical)
{
final Button cssButton = new Button(title);
cssButton.setShowRollOver(true);
cssButton.setShowDisabled(true);
cssButton.setShowDown(true);
cssButton.setIcon(iconName + ".png");
cssButton.setIconSize(32);
cssButton.setWidth(120);
cssButton.addClickHandler(new ClickHandler()
{
#Override
public void onClick(ClickEvent event)
{
RibbonBar a;
for(Canvas b : a.getMembers()){
RibbonGroup c=(RibbonGroup)b;
for(Canvas d : c.getControls()){
Button e = (Button)d;
if(e.equals(event.getSource()))
SC.say(e.getTitle());
}
}
SC.say(event.getSource().toString());
}
});
return cssButton;
}
}
or really if you always know it will be a Button just cast event.getSource() to a Button, then you can get the button title like ((Button)event.getSource()).getTitle()

Related

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);

SMARTGWT, menu item width not changing

I am using a MenuItem in my application but its showing all over the page , please have a look at the attachment , i am trying for hours and searched for but this width is not reducing ,
I am using the demo application of SmartGWT , using its code but i cant figure out whats the issue
any idea
thanks
code snippet:
itemListMenu = new Menu();
itemListMenu.setCellHeight(22);
MenuItem detailsMenuItem = new MenuItem("Show Details");
detailsMenuItem.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
searchItemDetails.selectTab(0);
searchItemDetails.updateDetails();
}
});
MenuItem editMenuItem = new MenuItem("Edit Item");
editMenuItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
public void onClick(MenuItemClickEvent event) {
searchItemDetails.selectTab(1);
searchItemDetails.updateDetails();
}
});
MenuItem deleteMenuItem = new MenuItem("Delete Item");
deleteMenuItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
public void onClick(MenuItemClickEvent event) {
userGrid.removeSelectedData();
searchItemDetails.clearDetails(null);
}
});
itemListMenu.setData(detailsMenuItem, editMenuItem, deleteMenuItem);
Can we have a look at the code of the menu itself, did you set its width?
I tried your code
static void testMenu(){
Menu itemListMenu = new Menu();
itemListMenu.setCellHeight(22);
MenuItem detailsMenuItem = new MenuItem("Show Details");
detailsMenuItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
public void onClick(MenuItemClickEvent event) {
}
});
MenuItem editMenuItem = new MenuItem("Edit Item");
editMenuItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
public void onClick(MenuItemClickEvent event) {
}
});
MenuItem deleteMenuItem = new MenuItem("Delete Item");
deleteMenuItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
public void onClick(MenuItemClickEvent event) {
}
});
itemListMenu.setData(detailsMenuItem, editMenuItem, deleteMenuItem);
RootLayoutPanel.get().add(itemListMenu);
}
Everyrything is fine, the width without doing anything correspond to the length of the longest item. So to which container did you add your menu?.

how to give my page slide animation in blackberry?

I'm creating a BlackBerry application, and now I want to present an animation when I click on an image button. In my application, I use a splash screen, and after that a login page is shown. When I click on my login page's submit button, a home screen is displayed, and there I want to show a slide animation.
This is my code:
public class LoginPage extends MainScreen implements FieldChangeListener {
public TextField tf_username;
public TextField tf_password;
private Bitmap[] img1;
public LabelField labeluser;
public LabelField labelpass;
public static String strUsername = "";
public static String strPassword = "";
public CheckboxField objRemembercheckbox;
private ImageButton btn_login;
private ImageButton btn_clear;
public BitmapField loading = new BitmapField(Bitmap.getBitmapResource("login-bar.png"));
public H_FieldManager hfm_btn;
public VerticalFieldManager vfm_user, vfm_pass;
public PleaseWaitPopupScreen waitPopupScreen = null;
public VerticalFieldManager vfmMainManager;
public static boolean loginFlag = false;
public static boolean flagOutletButton;
public RecordStore objLoginRecordStore;
private String login_record_Store_Name = "LoginRMS";
public LoginPage() { // TODO Auto-generated constructor stub super(USE_ALL_WIDTH | USE_ALL_HEIGHT); setTitle(loading);
try {
Background bg = BackgroundFactory.createSolidTransparentBackground(
Color.BLUE, 100); getMainManager().setBackground(bg);
} catch (Exception e) { // TODO: handle exception }
labeluser = new LabelField("Enter Username : ", Field.FIELD_LEFT); labeluser.setMargin(10, 0, 0, 10); labeluser.setColor(Color.BLACK);
tf_username = new TextField(TextField.TYPE_PLAIN, Field.FIELD_HCENTER);
labelpass = new LabelField("Enter Password : ", Field.FIELD_LEFT); labelpass.setMargin(10, 0, 0, 10); labelpass.setColor(Color.BLACK);
tf_password = new TextField(TextField.TYPE_PASSWORD,
Field.FIELD_HCENTER);
objRemembercheckbox = new CheckboxField("Remember Me", false); objRemembercheckbox.setMargin(10, 0, 0, 10);
img1 = new Bitmap[3]; img1[0] = Bitmap.getBitmapResource("btn-hover.png"); img1[1] = Bitmap.getBitmapResource("btn.png"); img1[2] = Bitmap.getBitmapResource("btn.png");
btn_login = new ImageButton(img1, "Login", Field.FIELD_LEFT); btn_login.setColor(Color.WHITE); btn_clear = new ImageButton(img1, "Clear", Field.FIELD_RIGHT); btn_clear.setColor(Color.WHITE);
hfm_btn = new H_FieldManager(btn_login, btn_clear, true,
Field.FIELD_HCENTER); vfm_user = new VerticalFieldManager(); vfm_user.add(labeluser); vfm_user.add(tf_username);
vfm_pass = new VerticalFieldManager(); vfm_pass.add(labelpass); vfm_pass.add(tf_password); add(vfm_user); add(vfm_pass); add(objRemembercheckbox); add(hfm_btn);
btn_login.setChangeListener(this); btn_clear.setChangeListener(this);
}
public void fieldChanged(Field field, int context) { // TODO Auto-generated method stub if (field == btn_clear) { tf_username.setText(" "); tf_password.setText(" ");
} else if (field == btn_login) { login(); }
}
public void login() {
try {
LoginPage.strUsername = tf_username.getText().toString(); System.out.println("strUsername==" + strUsername); LoginPage.strPassword = tf_password.getText().toString(); System.out.println("strPassword==" + strPassword);
if (strUsername.length() == 0 || strPassword.length() == 0
|| strUsername == null || strPassword == null) {
Dialog.alert("You must enter credentials");
invalidate(); } else {
// strUsername=username.getText();
// strPassword=password.getText();
try {
waitPopupScreen = new PleaseWaitPopupScreen("Please wait..");
UiApplication.getUiApplication()
.pushScreen(waitPopupScreen);
new Thread() {
public void run() {
ConnectToServer objConnectToServer = new ConnectToServer();
loginFlag = objConnectToServer.loginCheck(
strUsername, strPassword);
UiApplication.getUiApplication().invokeLater(
new Runnable() {
public void run() {
UiApplication.getUiApplication()
.popScreen(waitPopupScreen);
if (loginFlag == true) {
LoginPage.flagOutletButton = false;
System.out
.println("Calling getOutletInfo");
HomeScreen objHome= new HomeScreen ();
UiApplication
.getUiApplication()
.pushScreen(objHome);
}
else {
Dialog.alert("Username Or Password Is Incorrect");
}
}
});
};
}.start();
// ConnectToServer objConnectToServer=new ConnectToServer();
//
// loginFlag=objConnectToServer.loginCheck(strUsername,
// strPassword);
System.out.println("loginFlag==" + loginFlag);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
} catch (Exception e) { // TODO: handle exception e.printStackTrace(); }
}
}
Please suggest how to implement the slide animation.
Thank you.
Try following links:
TransitionContext - The TransitionContext class contains all the necessary data to
uniquely describe a transition animation between two screens.
BlackBerry Screen Transition Sample Code
BlackBerry Java Application Screen Transitions - Sample Application Overview
Creating a screen transition Code sample

Open a new mainscreen within a mainscreen in blackberry

I'm making an application in which there are few tabs on each tab click a url is called and an online xml is parsed. The data from this xml is displayed. The problem is that when the data is dispalyed the tabs disappear and only appear when i press the back button of the simulator. Whereas the data should appear below the tabs.
Please help
My UI
public class TabControl extends UiApplication {
public TabControl() {
TabControlScreen screen = new TabControlScreen();
pushScreen(screen);
}
public static void main(String[] args) {
TabControl app = new TabControl();
app.enterEventDispatcher();
}
private class TabControlScreen extends MainScreen implements FocusChangeListener {
private Bitmap backgroundBitmap = Bitmap.getBitmapResource("rednavnar.png");
private LabelField tab1;
private LabelField tab2;
private LabelField tab3;
private VerticalFieldManager tabArea;
private VerticalFieldManager tab1Manager;
private VerticalFieldManager tab2Manager;
private VerticalFieldManager tab3Manager;
public TabControlScreen() {
LabelField appTitle = new LabelField("Energy", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.FIELD_HCENTER);
this.setTitle(appTitle);
HorizontalFieldManager hManager = new HorizontalFieldManager( Manager.HORIZONTAL_SCROLL | Manager.HORIZONTAL_SCROLLBAR | Manager.USE_ALL_WIDTH | Manager.TOPMOST) {
// Override the paint method to draw the background image.
public void paint(Graphics graphics) {
// Draw the background image and then call paint.
graphics.drawBitmap(0, 0, 700, 100, backgroundBitmap, 0, 0);
super.paint(graphics);
}
};
tab1 = new LabelField("Top News", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
tabArea = displayTab1();
return true;
}
};
LabelField separator = new LabelField("|", LabelField.NON_FOCUSABLE);
tab2 = new LabelField("Power", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
tabArea = displayTab2();
return true;
}
};
LabelField separator1 = new LabelField("|", LabelField.NON_FOCUSABLE);
tab3 = new LabelField("Renewable Energy", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
tabArea = displayTab3();
return true;
}
};
tab1.setFocusListener(this);
tab2.setFocusListener(this);
tab3.setFocusListener(this);
hManager.add(tab1);
hManager.add(separator);
hManager.add(tab2);
hManager.add(separator1);
hManager.add(tab3);
add(hManager);
add(new SeparatorField());
tab1Manager = new VerticalFieldManager();
tab2Manager = new VerticalFieldManager();
tab3Manager = new VerticalFieldManager();
tabArea = displayTab1();
add(tabArea);
}
public void focusChanged(Field field, int eventType) {
if (tabArea != null) {
if (eventType == FOCUS_GAINED) {
if (field == tab1) {
delete(tabArea);
tabArea = displayTab1();
add(tabArea);
} else if (field == tab2) {
delete(tabArea);
tabArea = displayTab2();
add(tabArea);
} else if (field == tab3) {
delete(tabArea);
tabArea = displayTab3();
add(tabArea);
}
}
}
}
public VerticalFieldManager displayTab1() {
UiApplication.getUiApplication().pushScreen(new News());
return tab1Manager;
}
public VerticalFieldManager displayTab2() {
UiApplication.getUiApplication().pushScreen(new Power());
return tab2Manager;
}
public VerticalFieldManager displayTab3() {
UiApplication.getUiApplication().pushScreen(new Energy());
return tab3Manager;
}
}
}
My News Main Screen
public class News extends MainScreen {
public News() {
String xmlUrl = "http://182.71.5.53:9090/solr/core4/select/?q=*";
String[][] urlData = XmlFunctions.getURLFromXml(xmlUrl);
for (int i = 0; i < urlData.length; i++) {
final String title = urlData[0][i];
final String id = urlData[1][i];
//add(new LinkLabel(title, i));
add(new RichTextField(title){
protected boolean navigationClick(int status,int time){
String cId = id;
String bodyUrl = "http://192.168.1.44:9090/solr/core0/select/?q="+cId+";
String[][] bodyData = XmlFunctions.getBodyFromXml(bodyUrl);
for(int j=0;j<bodyData.length;j++){
String body = bodyData[0][j];
add(new RichTextField(body));
}
return true;
}
});
add(new SeparatorField());
}
}
}
Now i want to open this news screen below the tabs
Please help
For your TabControl Class
public class TabControl extends UiApplication {
public TabControl() {
TabControlScreen screen = new TabControlScreen();
pushScreen(screen);
}
public static void main(String[] args) {
TabControl app = new TabControl();
app.enterEventDispatcher();
}
private class TabControlScreen extends MainScreen {
private Bitmap backgroundBitmap = Bitmap.getBitmapResource("rednavnar.png");
private LabelField tab1;
private LabelField tab2;
private LabelField tab3;
private VerticalFieldManager tabArea;
public TabControlScreen() {
LabelField appTitle = new LabelField("Energy", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.FIELD_HCENTER);
this.setTitle(appTitle);
HorizontalFieldManager hManager = new HorizontalFieldManager( Manager.HORIZONTAL_SCROLL | Manager.HORIZONTAL_SCROLLBAR | Manager.USE_ALL_WIDTH | Manager.TOPMOST) {
// Override the paint method to draw the background image.
public void paint(Graphics graphics) {
// Draw the background image and then call paint.
graphics.drawBitmap(0, 0, 700, 100, backgroundBitmap, 0, 0);
super.paint(graphics);
}
};
tab1 = new LabelField("Top News", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
delete(tabArea);
tabArea = displayTab1();
add(tabArea);
return true;
}
};
LabelField separator = new LabelField("|", LabelField.NON_FOCUSABLE);
tab2 = new LabelField("Power", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
delete(tabArea);
tabArea = displayTab2();
add(tabArea);
return true;
}
};
LabelField separator1 = new LabelField("|", LabelField.NON_FOCUSABLE);
tab3 = new LabelField("Renewable Energy", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
delete(tabArea);
tabArea = displayTab3();
add(tabArea);
return true;
}
};
hManager.add(tab1);
hManager.add(separator);
hManager.add(tab2);
hManager.add(separator1);
hManager.add(tab3);
add(hManager);
add(new SeparatorField());
// USELESS CODE HAS BEEN REMOVED
tabArea = displayTab1();
add(tabArea);
}
public VerticalFieldManager displayTab1() {
return new News(); // RETURN THE MANAGER DIRECTLY
}
public VerticalFieldManager displayTab2() {
return new Power(); // RETURN THE MANAGER DIRECTLY
}
public VerticalFieldManager displayTab3() {
return new Energy(); // RETURN THE MANAGER DIRECTLY
}
}
}
For your News class
public class News extends VerticalFieldManager { // CHANGING THE EXTENSION SUPER CLASS
public News() {
super(VerticalFieldManager.VERTICAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLLBAR);
String xmlUrl = "http://182.71.5.53:9090/solr/core4/select/?q=*";
String[][] urlData = XmlFunctions.getURLFromXml(xmlUrl);
for (int i = 0; i < urlData.length; i++) {
final String title = urlData[0][i];
final String id = urlData[1][i];
//add(new LinkLabel(title, i));
add(new RichTextField(title){
protected boolean navigationClick(int status,int time){
String cId = id;
String bodyUrl = "http://192.168.1.44:9090/solr/core0/select/?q="+cId+";
String[][] bodyData = XmlFunctions.getBodyFromXml(bodyUrl);
for(int j=0;j<bodyData.length;j++){
String body = bodyData[0][j];
add(new RichTextField(body));
}
return true;
}
});
add(new SeparatorField());
}
}
}
Yes, create a seprate mainscreen or screen objects and from your parent screen you can execute the below code to open new screen using the below code:
UIApplication.getUiApplication().pushScreen(your custom screen object);
Thanks
You don't need to create 2 mainscreens in the scenario which you described.
Just create a VerticalFieldManager, add it to the mainscreen, then add content to it.
Here's a sample of code that can help you, apply it in your mainscreen constructor.
VerticalFieldManager VFM_Content = new VerticalFieldManager();
add(VFM_Content);
VFM_Content.add(/*put content here embedded in any field type you prefer*/);

BlackBerry Alarm Integeration

Below is my application code. i want alarm to ring on my blackberry on every 6 of this month whether this apllication is running or not. please guide me in details i am a beginner.
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;
import java.util.*;
import java.lang.String.*;
public class ListChk extends UiApplication
{
String getFirstName;
String getLastName;
String getEmail;
String getGender;
String getStatus;
String getCompany;
/*declaring text fields for user input*/
private AutoTextEditField firstName;
private AutoTextEditField lastName;
private AutoTextEditField company;
private EmailAddressEditField email;
/*declaring choice field for user input*/
private ObjectChoiceField gender;
/*declaring check box field for user input*/
private CheckboxField status;
//Declaring button fields
private ButtonField save;
private ButtonField close;
private ButtonField List;
private ButtonField search;
/*declaring vector*/
private static Vector _data;
/*declaring persistent object*/
private static PersistentObject store;
/*creating an entry point*/
public static void main(String[] args)
{
ListChk objListChk = new ListChk();
objListChk.enterEventDispatcher();
}//end of main of ListChk
public ListChk()
{
/*Creating an object of the main screen class to use its functionalities*/
MainScreen mainScreen = new MainScreen();
//setting title of the main screen
mainScreen.setTitle(new LabelField("Enter Your Data"));
//creating text fields for user input
firstName = new AutoTextEditField("First Name: ", "");
lastName= new AutoTextEditField("Last Name: ", "");
email= new EmailAddressEditField("Email:: ", "");
company = new AutoTextEditField("Company: ", "");
//creating choice field for user input
String [] items = {"Male","Female"};
gender= new ObjectChoiceField("Gender",items);
//creating Check box field
status = new CheckboxField("Active",true);
//creating Button fields and adding functionality using listeners
// A button that saves the the user data persistently when it is clicked
save = new ButtonField("Save",ButtonField.CONSUME_CLICK);
save.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
save();
}
});
// a button which closes the entire application when clicked
close = new ButtonField("Close",ButtonField.CONSUME_CLICK);
close.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
onClose();
}
});
// A button that shows the List of all Data being stored persistently
List = new ButtonField("List",ButtonField.CONSUME_CLICK);
List.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context){
// pushing the next screen
pushScreen(new ListScreen());
}
});
search = new ButtonField("Search",ButtonField.CONSUME_CLICK);
search.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
pushScreen(new SearchScreen());
}
});
//adding the input fields to the main screen
mainScreen.add(firstName);
mainScreen.add(lastName);
mainScreen.add(email);
mainScreen.add(company);
mainScreen.add(gender);
mainScreen.add(status);
// Addning horizontal field manager
HorizontalFieldManager horizontal = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
//adding buttons to the main screen in Horizontal field manager
horizontal.add(close);
horizontal.add(save);
horizontal.add(List);
horizontal.add(search);
//Adding the horizontal field manger to the screen
mainScreen.add(horizontal);
//adding menu items
mainScreen.addMenuItem(saveItem);
mainScreen.addMenuItem(getItem);
mainScreen.addMenuItem(Deleteall);
//pushing the main screen
pushScreen(mainScreen);
}
private MenuItem Deleteall = new MenuItem("Delete all",110,10)
{
public void run()
{
int response = Dialog.ask(Dialog.D_YES_NO,"Are u sure u want to delete entire Database");
if(Dialog.YES == response){
PersistentStore.destroyPersistentObject(0xdec6a67096f833cL);
Dialog.alert("Closing Application");
onClose();
}
else
Dialog.inform("Thank God");
}
};
//adding functionality to menu item "saveItem"
private MenuItem saveItem = new MenuItem("Save", 110, 10)
{
public void run()
{
//Calling save method
save();
}
};
//adding functionality to menu item "saveItem"
private MenuItem getItem = new MenuItem("Get", 110, 11)
{
//running thread for this menu item
public void run()
{
//synchronizing thread
synchronized (store)
{
//getting contents of the persistent object
_data = (Vector) store.getContents();
try{
for (int i = _data.size()-1; i >-1; i--)
{
StoreInfo info = (StoreInfo)_data.elementAt(i);
//checking for empty object
if (!_data.isEmpty())
{
//if not empty
//create a new object of Store Info class
//storing information retrieved in strings
getFirstName = (info.getElement(StoreInfo.NAME));
getLastName = (info.getElement(StoreInfo.LastNAME));
getEmail = (info.getElement(StoreInfo.EMail));
getGender = (info.getElement(StoreInfo.GenDer));
getStatus = (info.getElement(StoreInfo.setStatus));
getCompany = (info.getElement(StoreInfo.setCompany));
//calling the show method
show();
}
}
}
catch(Exception e){}
}
}
};
public void save()
{
//creating an object of inner class StoreInfo
StoreInfo info = new StoreInfo();
//getting the test entered in the input fields
info.setElement(StoreInfo.NAME, firstName.getText());
info.setElement(StoreInfo.LastNAME,lastName.getText());
info.setElement(StoreInfo.EMail, email.getText());
info.setElement(StoreInfo.setCompany, company.getText());
info.setElement(StoreInfo.GenDer,gender.toString());
if(status.getChecked())
info.setElement(StoreInfo.setStatus, "Active");
else
info.setElement(StoreInfo.setStatus, "In Active");
//adding the object to the end of the vector
_data.addElement(info);
//synchronizing the thread
synchronized (store)
{
store.setContents(_data);
store.commit();
}
//resetting the input fields
Dialog.inform("Success!");
firstName.setText(null);
lastName.setText(null);
email.setText("");
company.setText(null);
gender.setSelectedIndex("Male");
status.setChecked(true);
}
//coding for persistent store
static {
store =
PersistentStore.getPersistentObject(0xdec6a67096f833cL);
synchronized (store) {
if (store.getContents() == null) {
store.setContents(new Vector());
store.commit();
}
}
_data = new Vector();
_data = (Vector) store.getContents();
}
//new class store info implementing persistable
private static final class StoreInfo implements Persistable
{
//declaring variables
private Vector _elements;
public static final int NAME = 0;
public static final int LastNAME = 1;
public static final int EMail= 2;
public static final int GenDer = 3;
public static final int setStatus = 4;
public static final int setCompany = 5;
public StoreInfo()
{
_elements = new Vector(6);
for (int i = 0; i < _elements.capacity(); ++i)
{
_elements.addElement(new String(""));
}
}
public String getElement(int id)
{
return (String) _elements.elementAt(id);
}
public void setElement(int id, String value)
{
_elements.setElementAt(value, id);
}
}
//details for show method
public void show()
{
Dialog.alert("Name is "+getFirstName+" "+getLastName+"\nGender is "+getGender+"\nE-mail: "+getEmail+"\nStatus is "+getStatus);
}
public void list()
{
Dialog.alert("haha");
}
//creating save method
//overriding onClose method
public boolean onClose()
{
System.exit(0);
return true;
}
class ListScreen extends MainScreen
{
String getUserFirstName;
String getUserLastName;
String getUserEmail;
String getUserGender;
String getUserStatus;
String getUserCompany;
String[] setData ;
String getData = new String();
String collectData = "";
ObjectListField fldList;
int counter = 0;
private ButtonField btnBack;
public ListScreen()
{
setTitle(new LabelField("Showing Data",LabelField.NON_FOCUSABLE));
//getData = myList();
//Dialog.alert(getData);
// setData = split(getData,"$");
// for(int i = 0;i<setData.length;i++)
// {
// add(new RichTextField(setData[i]+"#####"));
// }
showList();
btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK|ButtonField.FIELD_HCENTER);
btnBack.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field,int context)
{
UiApplication.getUiApplication().popScreen(getScreen());
}
});
add(btnBack);
}
public void showList()
{
HorizontalFieldManager hfManager = new HorizontalFieldManager(HorizontalFieldManager.HORIZONTAL_SCROLLBAR|HorizontalFieldManager.HORIZONTAL_SCROLL);
//SeparatorField spManager = new SeparatorField();
LabelField lblcheck = new LabelField("check",LabelField.NON_FOCUSABLE);
getData = myList();
setData = split(getData,"$");
fldList = new ObjectListField(ObjectListField.MULTI_SELECT);
fldList.set(setData);
//fldList.setEmptyString("heloo", 12);
//hfManager.add(lblcheck);
hfManager.add(fldList);
//hfManager.add(spManager);
add(hfManager);
addMenuItem(new MenuItem("Select", 100, 1) {
public void run() {
int selectedIndex = fldList.getSelectedIndex();
String item = (String)fldList.get(fldList, selectedIndex);
pushScreen(new ShowDataScreen(item));
}
});
}
public String[] split(String inString, String delimeter) {
String[] retAr;
try {
Vector vec = new Vector();
int indexA = 0;
int indexB = inString.indexOf(delimeter);
while (indexB != -1) {
vec.addElement(new String(inString.substring(indexA, indexB)));
indexA = indexB + delimeter.length();
indexB = inString.indexOf(delimeter, indexA);
}
vec.addElement(new String(inString.substring(indexA, inString
.length())));
retAr = new String[vec.size()];
for (int i = 0; i < vec.size(); i++) {
retAr[i] = vec.elementAt(i).toString();
}
} catch (Exception e) {
String[] ar = { e.toString() };
return ar;
}
return retAr;
}//end of Split Method
public String myList()
{
_data = (Vector) store.getContents();
try
{
for (int i = _data.size()-1; i >-1; i--,counter++)
{
StoreInfo info = (StoreInfo)_data.elementAt(i);
//checking for empty object
if (!_data.isEmpty())
{
//if not empty
//create a new object of Store Info class
//storing information retrieved in strings
//StoreInfo info = (StoreInfo)_data.lastElement();
getUserFirstName = (info.getElement(StoreInfo.NAME));
getUserLastName = (info.getElement(StoreInfo.LastNAME));
//getUserEmail = (info.getElement(StoreInfo.EMail));
//getUserGender = (info.getElement(StoreInfo.GenDer));
//getUserStatus = (info.getElement(StoreInfo.setStatus));
getUserCompany = (info.getElement(StoreInfo.setCompany));
collectData = collectData + getUserFirstName+" "+getUserLastName+" "+getUserCompany+ "$";
}
}
}
catch(Exception e){}
return collectData;
}//end of myList method
public boolean onClose()
{
System.exit(0);
return true;
}
}//end of class ListScreen
class ShowDataScreen extends MainScreen
{
String getFirstName;
String getLastName;
String getCompany;
String getEmail;
String getGender;
String getStatus;
String[] getData;
public ShowDataScreen(String data)
{
getData = split(data," ");
getFirstName = getData[0];
getLastName = getData[1];
getCompany = getData[2];
_data = (Vector) store.getContents();
try
{
for (int i = _data.size()-1; i >-1; i--)
{
StoreInfo info = (StoreInfo)_data.elementAt(i);
if (!_data.isEmpty())
{
if((getFirstName.equalsIgnoreCase(info.getElement(StoreInfo.NAME))) && (getLastName.equalsIgnoreCase(info.getElement(StoreInfo.LastNAME))) && (getCompany.equalsIgnoreCase(info.getElement(StoreInfo.setCompany))))
{
getEmail = info.getElement(StoreInfo.EMail);
getGender = info.getElement(StoreInfo.GenDer);
getStatus = info.getElement(StoreInfo.setStatus);
HorizontalFieldManager hfManager = new HorizontalFieldManager(HorizontalFieldManager.NON_FOCUSABLE);
AutoTextEditField name = new AutoTextEditField("Name: ",getFirstName+" "+getLastName);
AutoTextEditField email = new AutoTextEditField("Email: ",getEmail);
AutoTextEditField company = new AutoTextEditField("Company: ",getCompany);
AutoTextEditField Gender = new AutoTextEditField("Gender: ",getGender);
AutoTextEditField status = new AutoTextEditField("Status: ",getStatus);
add(name);
add(email);
add(company);
add(Gender);
add(status);
}
}
}//end of for loop
}//end of try
catch(Exception e){}
//Dialog.alert("fname is "+getFirstName+"\nlastname = "+getLastName+" company is "+getCompany);
}
public String[] split(String inString, String delimeter) {
String[] retAr;
try {
Vector vec = new Vector();
int indexA = 0;
int indexB = inString.indexOf(delimeter);
while (indexB != -1) {
vec.addElement(new String(inString.substring(indexA, indexB)));
indexA = indexB + delimeter.length();
indexB = inString.indexOf(delimeter, indexA);
}
vec.addElement(new String(inString.substring(indexA, inString
.length())));
retAr = new String[vec.size()];
for (int i = 0; i < vec.size(); i++) {
retAr[i] = vec.elementAt(i).toString();
}
} catch (Exception e) {
String[] ar = { e.toString() };
return ar;
}
return retAr;
}//end of Split Method
}
class SearchScreen extends MainScreen
{
private ButtonField btnFirstName;
private ButtonField btnLastName;
private ButtonField btnSearch;
private ButtonField btnEmail;
private SeparatorField sp;
String userName;
HorizontalFieldManager hr = new HorizontalFieldManager();
public AutoTextEditField searchField;
public SearchScreen()
{
sp = new SeparatorField();
setTitle(new LabelField("your Search Options"));
add(new RichTextField("Search by : "));
btnFirstName = new ButtonField("First Name",ButtonField.CONSUME_CLICK);
hr.add(btnFirstName);
btnFirstName.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
//HorizontalFieldManager hrs = new HorizontalFieldManager();
searchField = new AutoTextEditField("First Name: ","ali");
add(searchField);
btnSearch = new ButtonField("Search",ButtonField.CONSUME_CLICK);
btnSearch.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
//Dialog.alert(searchField.getText());
pushScreen(new FirstnameScreen(searchField.getText()));
//FirstnameScreen obj = new FirstnameScreen();
//obj.name= searchField.getText();
}
});
add(btnSearch);
//hrs.add(sp);
}
});
btnLastName = new ButtonField("Last Name",ButtonField.CONSUME_CLICK);
hr.add(btnLastName);
btnLastName.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int Context)
{
searchField = new AutoTextEditField("Last Name: ","");
add(searchField);
btnSearch = new ButtonField("Search",ButtonField.CONSUME_CLICK);
btnSearch.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
//Dialog.alert(searchField.getText());
pushScreen(new LastnameScreen(searchField.getText()));
//FirstnameScreen obj = new FirstnameScreen();
//obj.name= searchField.getText();
}
});
add(btnSearch);
}
});
btnEmail = new ButtonField("Email",ButtonField.CONSUME_CLICK);
hr.add(btnEmail);
btnEmail.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int Context)
{
searchField = new AutoTextEditField("Email: ","");
add(searchField);
btnSearch = new ButtonField("Search",ButtonField.CONSUME_CLICK);
btnSearch.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
//Dialog.alert(searchField.getText());
pushScreen(new EmailScreen(searchField.getText()));
//FirstnameScreen obj = new FirstnameScreen();
//obj.name= searchField.getText();
}
});
add(btnSearch);
}
});
add(hr);
}
void myShow()
{
Dialog.alert(searchField.getText());
}
}
class FirstnameScreen extends MainScreen
{
String userName;
private Manager mGrid;
String firstUserName;
String lastUserName;
String userEmail;
String userGender;
String userStatus;
ButtonField btnBack;
Font font;
public FirstnameScreen(String name)
{
setTitle(new LabelField("your Search Results"));
add(new RichTextField("Search results for"+name));
userName = name;
searchFirstName();
btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK);
btnBack.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
UiApplication.getUiApplication().popScreen(getScreen());
}
});
add(btnBack);
}
public void searchFirstName()
{
ButtonField btnDelete;
if (null != mGrid && null != mGrid.getManager())
mGrid.getManager().delete(mGrid);
int colWidth = net.rim.device.api.system.Display.getWidth() / 4;
mGrid = new GridFieldManager(new int[] { 0, colWidth, colWidth,
colWidth, colWidth }, VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
mGrid.add(new NullField(FOCUSABLE));
mGrid.add(new LabelField("Name"));
mGrid.add(new LabelField("E-Mail"));
mGrid.add(new LabelField("Gender"));
mGrid.add(new LabelField("Active"));
//mGrid.add(new ButtonField("Delete"));
//SeparatorField sps = new SeparatorField();
//mGrid.add(sps);
add(mGrid);
_data = (Vector) store.getContents();
try {
for (int i = _data.size() - 1; i > -1; i--) {
StoreInfo info = (StoreInfo) _data.elementAt(i);
// checking for empty object
if (!_data.isEmpty()) {
firstUserName = (info.getElement(StoreInfo.NAME));
if(firstUserName.equalsIgnoreCase(userName))
{
// if not empty
// create a new object of Store Info class
// stored information retrieved in strings
lastUserName = (info.getElement(StoreInfo.LastNAME));
userEmail = (info.getElement(StoreInfo.EMail));
userGender = (info.getElement(StoreInfo.GenDer));
userStatus = (info.getElement(StoreInfo.setStatus));
final int sn = i;
// calling the listAll method
mGrid.add(new NullField(FOCUSABLE));
mGrid.add(new LabelField(firstUserName + " "
+ lastUserName));
mGrid.add(new LabelField(userEmail));
mGrid.add(new LabelField(userGender));
mGrid.add(new LabelField(userStatus));
btnDelete = new ButtonField("Delete",ButtonField.CONSUME_CLICK);
btnDelete.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
_data.removeElementAt(sn);
}
});
add(btnDelete);
// SeparatorField sps1 = new SeparatorField();
//mGrid.add(sps1);
}
}
}
} catch (Exception e) {
}
}
}
class LastnameScreen extends MainScreen
{
String userName;
private Manager mGrid;
String firstUserName;
String lastUserName;
String userEmail;
String userGender;
String userStatus;
ButtonField btnBack;
Font font;
public LastnameScreen(String name)
{
setTitle(new LabelField("your Search Results"));
add(new RichTextField("Search results for"+name));
userName = name;
searchLastName();
btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK);
btnBack.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
UiApplication.getUiApplication().popScreen(getScreen());
}
});
add(btnBack);
}
public void searchLastName()
{
ButtonField btnDelete;
if (null != mGrid && null != mGrid.getManager())
mGrid.getManager().delete(mGrid);
int colWidth = net.rim.device.api.system.Display.getWidth() / 4;
mGrid = new GridFieldManager(new int[] { 0, colWidth, colWidth,
colWidth, colWidth }, VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
mGrid.add(new NullField(FOCUSABLE));
mGrid.add(new LabelField("Name"));
mGrid.add(new LabelField("E-Mail"));
mGrid.add(new LabelField("Gender"));
mGrid.add(new LabelField("Active"));
//mGrid.add(new ButtonField("Delete"));
//SeparatorField sps = new SeparatorField();
//mGrid.add(sps);
add(mGrid);
_data = (Vector) store.getContents();
try {
for (int i = _data.size() - 1; i > -1; i--) {
StoreInfo info = (StoreInfo) _data.elementAt(i);
// checking for empty object
if (!_data.isEmpty()) {
lastUserName = (info.getElement(StoreInfo.LastNAME));
if(lastUserName.equalsIgnoreCase(userName))
{
// if not empty
// create a new object of Store Info class
// stored information retrieved in strings
firstUserName = (info.getElement(StoreInfo.NAME));
userEmail = (info.getElement(StoreInfo.EMail));
userGender = (info.getElement(StoreInfo.GenDer));
userStatus = (info.getElement(StoreInfo.setStatus));
final int sn = i;
// calling the listAll method
mGrid.add(new NullField(FOCUSABLE));
mGrid.add(new LabelField(firstUserName + " "
+ lastUserName));
mGrid.add(new LabelField(userEmail));
mGrid.add(new LabelField(userGender));
mGrid.add(new LabelField(userStatus));
btnDelete = new ButtonField("Delete",ButtonField.CONSUME_CLICK);
btnDelete.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
_data.removeElementAt(sn);
}
});
add(btnDelete);
// SeparatorField sps1 = new SeparatorField();
//mGrid.add(sps1);
}
}
}
} catch (Exception e) {
}
}
}
class EmailScreen extends MainScreen
{
String userName;
private Manager mGrid;
String firstUserName;
String lastUserName;
String userEmail;
String userGender;
String userStatus;
ButtonField btnBack;
Font font;
public EmailScreen(String mail)
{
setTitle(new LabelField("your Search Results"));
add(new RichTextField("Search results for"+mail));
userName = mail;
searchEmail();
btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK);
btnBa
What are the benefits of integrating with the built-in alarm application? Would it be better for your application to place an event in the device's calendar and make the event show a reminder?
If you have to have a more prominent alarm, why not do it yourself? An alarm is an action the phone does (either make a sound and/or vibrate) that shows on the screen why it is taking that action and the action stops when someone responds to it.
Can you just make an app that starts in the background, checks the day, and makes a sound/vibrates on that day?
The default Alarm app on my phone only supports one time to ring. If I set it to wake me up at 4 a.m., but your app reschedules the alarm on my phone for 8 a.m., you would instantly lose a customer (after I wake up 4 hours too late).

Resources