Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4250136
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:29:20+00:00 2026-05-21T04:29:20+00:00

Im trying to create a Table with Vaadin where you have different options in

  • 0

Im trying to create a Table with Vaadin where you have different options in the context menu depending on if you have selected a single row or multiple rows.

It took me a while to do this but now i have a working solution. The problem is that is feel that its not good coding practice and I would gladly take any advice in how to perhaps split my “function” into smaller classes or functions. Could I perhaps create a standalone Action class?. Feel free to comment and advice and please do note that I just started with Vaadin =) !

          Table contactList = new Table("Test table");
 3        contactList.addListener(new Property.ValueChangeListener(){
 4            public void valueChange(ValueChangeEvent event){            
 5                Set<?> value = (Set<?>) event.getProperty().getValue();
 6                if(value == null || value.size() == 0){
 7                    getMainWindow().showNotification("NULL or 0");
 8                }else if(value.size() == 1){
 9                    contactList.removeAllActionHandlers();
10                    contactList.addActionHandler(new Action.Handler(){
11                        public Action[] getActions(Object target, Object sender){                           
12                            return ACTIONS_EDIT;                        
13                        }                        
14                        public void handleAction(Action action, Object sender, Object target){                               
15                            getMainWindow().showNotification("ACTION_EDIT");                               
16                        }
17                    });
18                }else{
19                    contactList.removeAllActionHandlers();
20                    contactList.addActionHandler(new Action.Handler(){
21                        public Action[] getActions(Object target, Object sender){                           
22                            return ACTIONS_EDIT_ALL;                        
23                        }                        
24                        public void handleAction(Action action, Object sender, Object target){                               
25                            getMainWindow().showNotification("ACTION_EDIT_ALL");                               
26                        }
27                    });       
28                }
29            }
30        });

Thx for any help!
/Marthin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:29:20+00:00Added an answer on May 21, 2026 at 4:29 am

    So i broke down the anonymouse classes and made them to inner classes. There are also some new functionalities. All feedback is welcome ofcourse, hopfully this might help someone else to break free the anonymouse classes they like to use in Vaadin.

    class ExtendedTableFieldFactory implements TableFieldFactory{
        private static final long serialVersionUID = 1L;
    
        public Field createField(Container container, Object itemId, Object propertyId, Component uiContext){
            if(selectedRows != null){
                if(selectedRows.contains(itemId)){              
                    return new com.vaadin.ui.TextField();
                }
            }
            return null;
        }
    }
    
    
    /**
     * Event handling for the table.
     * If one or more rows has been selected we set the corresponding action.
     * The action repaints the context menu.
     */ 
    class ExtendedValueChangeListener implements Property.ValueChangeListener
    {
        private static final long serialVersionUID = 1L;
    
        @Override
        public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
            setEditable(false);
            selectedRows = (Set<T>) event.getProperty().getValue();
    
    
            if(selectedRows == null || selectedRows.size() == 0){
                extActionHandler.setCurrentAction(ACTIONS_EDIT);        
            }else if(selectedRows.size() == 1){
                extActionHandler.setCurrentAction(ACTIONS_EDIT);        
                requestRepaint();
            }else{
                if(extActionHandler.getCurrentAction() != ACTIONS_EDIT_ALL)
                {                   
                    extActionHandler.setCurrentAction(ACTIONS_EDIT_ALL);
                    requestRepaint();
                }
            }
        }       
    }
    
    
    /**
     * The action handler is the context menu in the table.
     * We have a handler that takes the appropriate action on events.
     */
    class ExtendedActionHandler implements Action.Handler{
        private static final long serialVersionUID = 1L;
        private Action[] currentAction = null;
    
        @Override
        public Action[] getActions(Object target, Object sender) {          
            System.out.println("calling GETACTIONS!");
            return currentAction;
        }
    
        @Override
        public void handleAction(Action action, Object sender, Object target) {
            System.out.println("calling handleActions aciton: "+action);
            if(action == ACTION_EDIT_ALL_MODAL){
                if (subwindow != null && subwindow.getParent() != null) {
                    subwindow.focus();                  
                } else {          
                    subwindow = new Window("Edit contacts");
                    subwindow.setModal(true);
    
                    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
                    layout.setMargin(true);
                    layout.setSpacing(true);
    
                    T data = selectedRows.iterator().next();
                    try {
                        T dataEmpty = (T) data.getClass().newInstance();                        
                        modalForm.setItemDataSource(new BeanItem<T>(dataEmpty));
    
                    } catch (InstantiationException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
    
    
                    subwindow.addComponent(modalForm);
                    subwindow.setWidth("720px");
                    subwindow.center();                 
                    getParent().getWindow().addWindow(subwindow);
    
                    //getWindow().addWindow(subwindow);
    
                }
            }else{
                setEditable(true);
            }       
    
        }       
        public Action[] getCurrentAction() {
            return currentAction;
        }
    
        public void setCurrentAction(Action[] currentAction) {
            System.out.println("setting current action to: " + currentAction);
            this.currentAction = currentAction;
    
        }
    
    }
    

    Best Regards
    Marthin

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a table row element where the first line contains
I am trying to create a table with the following: CREATE TABLE GTW_WORKFLOW_MON (
I'm trying to create a table with two columns comprising the primary key in
I'm trying to create a Users table that only has OpenId registrations, exactly like
I am trying to create a column in a table that's a foreign key,
I'm trying to create and retrieve a BLOB in a MySQL table via Kohana's
I'm trying to create a jqgrid, but the table is empty. The table renders,
Using Prototype 1.6's new Element(...) I am trying to create a <table> element with
Im trying to create a table with this code: CREATE TABLE IF NOT EXISTS
I am trying to create a table view which has a layout like what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.