SMARTGWT, menu item width not changing - smartgwt

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?.

Related

How to JavaEE Vaadin Framework TextField1 Enter next move to cursor TextField2?

How to Abone no ENTER ----> Sicil no ENTER ----> TC Kimlik no ENTER BORÇ_BUL ?
If you are triyng to use ENTER key as TAB key. The code below isn't very elegant, but it works. You can refactor, set the order from an array, etc...
Imagine a Login form (user and password fields and signin button):
public class LoginView extends VerticalLayout {
private TextField username;
private PasswordField passwordFld;
private AbstractTextField current;
public LoginView(
buildFields();
}
private void buildFields(){
HorizontalLayout fields = new HorizontalLayout();
username = new TextField("User");
passwordFld = new PasswordField("Pwd");
Button signin = new Button("Sign");
fields.addComponents(username, passwordFld,signin);
username.addFocusListener(new FocusListener() {
public void focus(FocusEvent event) {
current = username;
}
});
passwordFld.addFocusListener(new FocusListener() {
public void focus(FocusEvent event) {
current = passwordFld;
}
});
ShortcutListener enterkey = new ShortcutListener ("Enter", KeyCode.ENTER, null){
public void handleAction(Object sender, Object target) {
if (current.equals(username)){
passwordFld.focus();
}else if (current.equals(passwordFld)){
sign();
}else{
sign();
}
}
};
fields.addShortcutListener(enterkey );
signin.addClickListener(getClickListener());
addComponent(fields);
}
private ClickListener getClickListener() {
return new ClickListener() {
public void buttonClick(final ClickEvent event) {
sign();
}
};
}
private void sign(){
//Do the sign in or fail
}
}

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
}
}

Java Blackberry Refresh Field Label

I have a main class and a screen class. I have a button that launches a datepicker. When the datepicker is closed I need the label of the button to be refreshed with the selected value. How should I do that?
I tried with invalidate, creating a CustomButtonField that implements different onFocus, onUnFocus, and some other stuff but I guess I implemented them in a wrong way...
My two clases are these ones...
Main...
public class TestClass extends UiApplication
{
public static Calendar alarm1time = Calendar.getInstance(TimeZone.getTimeZone("GMT-3"));
public static void main(String[] args)
{
TestClass testClass = new TestClass ();
testClass.enterEventDispatcher();
}
public TestClass()
{
pushScreen(new TestClassScreen());
}
}
Screen...
public final class TestClassScreen extends MainScreen
{
public TestClassScreen()
{
ButtonField alarm1 = new ButtonField("Alarm : " + TestClass.alarm1time.get(Calendar.HOUR_OF_DAY) + ":" + TestClass.alarm1time.get(Calendar.MINUTE) ,ButtonField.FOCUSABLE)
{
public boolean navigationClick (int status , int time)
{
datePicker(1);
return true;
}
};
setTitle("Test Alarm");
add(new RichTextField(" "));
add(alarm1 );
}
public void datePicker(final int alarmNumber)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
DateTimePicker datePicker = null;
datePicker = DateTimePicker.createInstance(TestClass.alarm1time, null, "HH:mm");
if(datePicker.doModal())
{
Calendar cal = datePicker.getDateTime();
TestClass.alarm1time = cal;
//Here I need the label to be refreshed, after the datePicker is Ok
}
}
});
}
}
I found one way in the Blackberry Development Forum...
public boolean navigationClick (int status , int time)
{
datePicker(1, this);
return true;
}
public void datePicker(final int alarmNumber, final ButtonField buttonToUpdate)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
DateTimePicker datePicker = null;
datePicker = DateTimePicker.createInstance(TestClass.alarm1time, null, "HH:mm");
if(datePicker.doModal())
{
Calendar cal = datePicker.getDateTime();
TestClass.alarm1time = cal;
buttonToUpdate.setLabel(....)
}
}
});
}
A more usual way would be to have change listener listen for Button Clicks and do similar processing in there.
I think, this helps you:
public class Def extends MainScreen
{
ButtonField show;
LabelField label;
String str="";
ObjectChoiceField choiceField;
public Def()
{
createGUI();
}
private void createGUI()
{
String st_ar[]={"Date Picker"};
choiceField=new ObjectChoiceField("Select Date: ", st_ar)
{
protected boolean navigationClick(int status, int time)
{
DateTimePicker datePicker = DateTimePicker.createInstance( Calendar.getInstance(), "yyyy-MM-dd", null);
datePicker.doModal();
Calendar calendar=datePicker.getDateTime();
str=String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))+"-"+String.valueOf(calendar.get(Calendar.MONTH)+1)+"-"+calendar.get(Calendar.YEAR);
return true;
}
};
add(choiceField);
label=new LabelField("",Field.NON_FOCUSABLE);
add(label);
show=new ButtonField("Show");
show.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
label.setText("Time is: "+str);
}
});
add(show);
}
}

vaadin submenu addind problem

Hi I m using navigation window and class view to create menu bar for our application it works fine,but when i m added submenu inside the menu bar it showing error saying like
SEVERE: Terminal error:
java.lang.IllegalStateException: Composition root must be set to non-null value before the com.vaadin.incubator.spring.ui.Reference2 can be painted
at com.vaadin.ui.CustomComponent.paintContent(CustomComponent.java:125)
my code is like
for (final Class viewClass : new Class[] { Trade.class, Position.class,
Cash.class, Recon.class, Price.class, Accounting.class,
Reference.class, Report.class, }) {
navigator.addView(viewClass.getSimpleName(), viewClass);
if (viewClass.getSimpleName().equals("Price")) {
MenuBar.MenuItem Price = menu.addItem("Price", null);
for (final Class viewClasssubmenu : new Class[] {
PriceActivity.class, ViewPrice.class, }) {
navigator.addView(viewClasssubmenu.getSimpleName(),
viewClasssubmenu);
Price.addItem(viewClasssubmenu.getSimpleName(),
new MenuBar.Command() {
public void menuSelected(MenuItem selectedItem) {
// TODO Auto-generated method stub
navigator.navigateTo(viewClasssubmenu);
}
});
}
} else if (viewClass.getSimpleName().equals("Recon")) {
if (viewClass.getSimpleName().equals("Recon")) {
MenuBar.MenuItem Recon = menu.addItem("Recon", null);
for (final Class viewClasssubmenu : new Class[] {
Recon1.class, Recon2.class, }) {
navigator.addView(viewClasssubmenu.getSimpleName(),
viewClasssubmenu);
Recon.addItem(viewClasssubmenu.getSimpleName(),
new MenuBar.Command() {
public void menuSelected(
MenuItem selectedItem) {
// TODO Auto-generated method stub
navigator.navigateTo(viewClasssubmenu);
}
});
}
}
} else if (viewClass.getSimpleName().equals("Reference")) {
if (viewClass.getSimpleName().equals("Reference")) {
MenuBar.MenuItem Reference = menu
.addItem("Reference", null);
for (final Class viewClasssubmenu : new Class[] {
Reference1.class, Reference2.class, }) {
navigator.addView(viewClasssubmenu.getSimpleName(),
viewClasssubmenu);
Reference.addItem(viewClasssubmenu.getSimpleName(),
new MenuBar.Command() {
public void menuSelected(
MenuItem selectedItem) {
// TODO Auto-generated method stub
navigator.navigateTo(viewClasssubmenu);
}
});
}
}
} else {
menu.addItem(viewClass.getSimpleName(), new MenuBar.Command() {
public void menuSelected(MenuItem selectedItem) {
navigator.navigateTo(viewClass);
}
});
}
}
return w;
}
Any one help me out in navigation class viwes how to add submenu items ?if you provide me exaple it will be great help for me..
This may not have anything to do with the menu. The error says that there is a CustomComponent (i.e. "composite" in Vaadin language) that you have extended that has not a set the composition root component. Maybe it is one of your view classes?
Anyway, you should set that in the constructor of the component to make sure that one exists on rendering time. See this for details and example: http://vaadin.com/book/-/page/components.customcomponent.html

BlackBerry - Programmatically fetching data in calendar

i have invoked blackberry calender from my application
can anyone tell me how to fetch :
date
duration
notes
from the selected date
my code :
MenuItem importCalender = new MenuItem("Import from Calender",100,11)
{
public void run()
{
UiApplication.getUiApplication().invokeAndWait(new Runnable()
{
public void run()
{
try
{
EventList list = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE);
Enumeration events = list.items();
BlackBerryEvent e = (BlackBerryEvent) events.nextElement();
Invoke.invokeApplication(Invoke.APP_TYPE_CALENDAR, new CalendarArguments( CalendarArguments.ARG_VIEW_DEFAULT,e) );
}
catch (PIMException e)
{
//e.printStackTrace();
}
}
});
}
};
protected void makeMenu(Menu menu, int instance)
{
menu.add(importCalender);
}
You should register custom menu item for calendar application.
See How To - Add a custom menu item to an existing BlackBerry application
UPDATE
alt text http://img517.imageshack.us/img517/2789/caledar3.jpg
class Scr extends MainScreen {
VerticalFieldManager mManager;
UiApplication mApp;
public Scr() {
mApp = UiApplication.getUiApplication();
mManager = (VerticalFieldManager) this.getMainManager();
MyMenuItem myMenuitem = new MyMenuItem(0);
ApplicationMenuItemRepository.getInstance().addMenuItem(
ApplicationMenuItemRepository.MENUITEM_CALENDAR, myMenuitem);
}
class MyMenuItem extends ApplicationMenuItem {
MyMenuItem(int order) {
super(order);
}
public Object run(Object context) {
if (context instanceof Event) {
Event event = (Event) context;
final String text = "start: "
+ (new Date(event.getDate(Event.START, 0))).toString()
+ "\nend: "
+ (new Date(event.getDate(Event.END, 0))).toString()
+ "\nnote: " + event.getString(Event.NOTE, 0);
String message = "Import event\n" + text;
if (Dialog.YES == Dialog.ask(Dialog.D_YES_NO, message)) {
mApp.invokeLater(new Runnable() {
public void run() {
mApp.requestForeground();
mManager.add(new LabelField(text));
}
});
}
}
return context;
}
public String toString() {
return "Import Event";
}
}
MenuItem importCalender = new MenuItem("Import from Calender", 100, 11) {
public void run() {
UiApplication.getUiApplication().invokeAndWait(new Runnable() {
public void run() {
Invoke.invokeApplication(Invoke.APP_TYPE_CALENDAR,
new CalendarArguments(
CalendarArguments.ARG_VIEW_DEFAULT));
}
});
}
};
protected void makeMenu(Menu menu, int instance) {
menu.add(importCalender);
}
}

Resources