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
Related
I am using Blazor Server.
Inside my startup I am configuring the MenuItems like this:
var menu = new[]
{
new MenuItem
{
Label = "File", Submenu = new[]
{
new MenuItem
{
Label = "Save",
Accelerator = "CmdOrCtrl+S",
Enabled = false,
Click = () =>
{
// How do I execute code inside my component?
},
}
}
}
};
Electron.Menu.SetApplicationMenu(menu);
My component lives on the root and is always rendered. It has a simple method called Save which I want to call.
public async Task SaveProject()
{
await Project.Save();
}
Isn't there some kind of event inside the static Electron class that I could use? Something like OnMenuItemClicked.
Having a static property that I could access inside my component would not only be bad design, it would prevent me from accessing any instance properties.
I came up with a more or less applicable solution myself.
I have created a singleton service IMenuItemService which I am using in both my Startup and my Component. Since MenuItems do not have an ID per se, I created a seperate Enum MenuItemType to seperate them. The service looks something like this:
public class MenuItemService : IMenuItemService
{
public Action<MenuItemType> MenuItemClicked { get; set; }
private Dictionary<MenuItemType, MenuItem> ConfigurableMenuItems { get; }
public MenuItemService()
{
ConfigurableMenuItems = new Dictionary<MenuItemType, MenuItem>();
InitializeMenuItem(MenuItemType.Close, "Close Project", null, false);
}
private void InitializeMenuItem(MenuItemType type, string label, string accelerator, bool enabled)
{
ConfigurableMenuItems.Add(type, new MenuItem
{
Label = label,
Accelerator = accelerator,
Enabled = enabled,
Click = () => { MenuItemClicked?.Invoke(type); },
});
}
public void SetEnabled(MenuItemType menuItemType)
{
ConfigurableMenuItems[menuItemType].Enabled = true;
RenderMenuItems();
}
public void SetDisabled(MenuItemType menuItemType)
{
ConfigurableMenuItems[menuItemType].Enabled = false;
RenderMenuItems();
}
public void RenderMenuItems()
{
Electron.Menu.SetApplicationMenu(new[]
{
new MenuItem
{
Label = "File", Submenu = new []
{
ConfigurableMenuItems[MenuItemType.Close]
}
}
});
}
}
With this approach I can call menuItemService.RenderMenuItems() from anywhere in my application including Startup.cs while in my Components I am setting the MenuItemClicked Action in order to listen to clicks.
[Inject]
public IMenuItemService MenuItemService { get; set; }
private void InitializeMenuItemActions()
{
MenuItemService.SetEnabled(MenuItemType.Close);
MenuItemService.MenuItemClicked = type =>
{
if (type == MenuItemType.Close)
{
ProjectManager.CloseProject();
NavigationManager.NavigateTo("/");
}
};
}
In my case I intentionally used an Action Property instead on an EventHandler since I do not need multiple listeners for my MenuItem.
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.
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
}
}
I need to add buttons for every row of my table. The table's container data source is JPAContainer. How to do that? I have succesfully add buttons for table which data source is not a JPAContainer. This is what I do:
testable.addContainerProperty("button", Button.class, null);
Button btt = new Button("test");
Item newrow = testable.addItem("first");
newrow.getItemProperty("button").setValue(btt);
But if I declare the testable data source : testable.setContainerDataSource(jpa_test);
It does'nt work. Can someone help me please
First, create example class:
public class ExampleBean {
private Integer id;
private Button button;
public ExampleBean() {
button = new Button("Test") {
{
addClickListener(new ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
// code here
}
});
}
}
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setButton(Button button) {
this.id = id;
}
public Button getButton() {
return button;
}
// ToString, Equals and/or HashCode methods if necessary
}
Second, create container:
private BeanItemContainer<ExampleBean> exampleBeanItemContainer = new BeanItemContainer<ExampleBean>(ExampleBean.class);
Next, fill container (add bean/beans to container) and assign container with table:
exampleBeanItemContainer.addBean(new ExampleBean() {
{
setId(1);
}
});
table.setContainerDataSource(exampleBeanItemContainer);
Finally, set table headers and table headers visibility:
table.setVisibleColumns(new Object[] { "id", "button" });
table.setColumnHeaders(new String[] { "ID", "Button" });
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?.