How to create a tableview for this?

Hey, I was glued to this party for a long time and not able to find the answers, maybe I can get help from you guys.

See I have a scenario where I have different 'items', which each will belong to a predefined category. These elements have different types and names (depends on the category), in turn, each of these types have a price.

For example if I Item1 (water bottle), belongs to category 1 and there are different types: 200ml, 500 ml, 1000ml with labels of 10,20,30 price respectively.

Similarly, I have Item2 (box of butter), belongs to Category2 and there are different types: 100 g, 200 g with labels of 15 and 25 price respectively.

Now I want the data to appear on an editable table, when I press a button in the category, all items in the category (with the same type) must be included, with the sections divided into:


The pressing of category 1


NAME | PRICE |
| 200ml | 500ml | 1000ml |
| |
Water bottle | 10. 20. 30.
. . . .
. . . .




The pressing of category 2


NAME | PRICE |
| 100 GM | 200ml |
| |
Butter box | 15. 25.




So, I want a dyanamic table which can have dynamic nested columns.

I was trying to make a table of the class

public class ItemVO()
{
String itemName;
The list type < ItemTypeVO >;
}

and my ItemTypeVO has the following attributes:

public class ItemTypeVO()
{
String typeName;
Full price;
}

But not able to get anywhere with it.

A lot of places I found dynamic columns with attributes like this:

public class ItemVO()
{
String itemName;
Type ItemTypeVO;
}

But it is not my job. I think so.

Can someone help me with this change can I do in my class, so that I can make a table and provide me with a code as well.

Thanks in advance.

I don't really know what you're trying to do in this Test class.

I mocked this upward with the object model, I proposed and the mock object data access codes hard just a few items and it works fine.

Type.Java

package itemtable;

public class Type {

  private final String name ;

  public Type(String name) {
    this.name = name ;
  }

  public String getName() {
    return name ;
  }
}

Category.Java

package itemtable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Category {

  private final List types ;
  private final String name ;

  public Category(String name, List types) {
    this.name = name ;
    this.types = new ArrayList();
    this.types.addAll(types);
  }

  public List getTypes() {
    return Collections.unmodifiableList(types);
  }

  public String getName() {
    return name ;
  }

  @Override
  public String toString() {
    return name ;
  }
}

Item.Java

package itemtable;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Item {
  private final StringProperty name ;
  private final ReadOnlyObjectProperty category ;
  private final Map prices ;

  public Item(String name, Category category, Map prices) {
    this.name = new SimpleStringProperty(name);
    this.category = new SimpleObjectProperty(category);
    this.prices = new HashMap();
    for (Type type : prices.keySet()) {
      validateType(type);
      this.prices.put(type, new SimpleDoubleProperty(prices.get(type)));
    }
  }

  public String getName() {
    return name.get();
  }
  public Category getCategory() {
    return category.get();
  }
  public double getPrice(Type type) {
    validateType(type);
    return prices.get(type).get();
  }
  public void setName(String name) {
    this.name.set(name);
  }
  public void setPrice(Type type, double price) {
    validateType(type);
    prices.get(type).set(price);
  }
  public StringProperty nameProperty() {
    return name ;
  }
  public ReadOnlyObjectProperty categoryProperty() {
    return category ;
  }
  public DoubleProperty priceProperty(Type type) {
    return prices.get(type);
  }

  private void validateType(Type type) {
    final List allowedTypes = category.get().getTypes();
    if (! allowedTypes.contains(type)) {
      throw new IllegalArgumentException("Cannot set a price for "+type.getName()+": it is not a type for the category "+category.getName());
    }
  }
}

DAO.java

package itemtable;

import java.util.List;

public interface DAO {
  public List getCategories();
  public List getItemsByCategory(Category category);
}

MockDAO.java

package itemtable;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MockDAO implements DAO {

  private final List categories ;
  private final Map> itemLookup ;

  public MockDAO() {
    final Type spreadType100g = new Type("100g");
    final Type spreadType200g = new Type("200g");
    final Type drinkType200ml = new Type("200ml");
    final Type drinkType500ml = new Type("500ml");
    final Type drinkType1000ml = new Type("1000ml");
    final Category spreads = new Category(
        "Spreads",
        Arrays.asList(spreadType100g, spreadType200g)
    );
    final Category drinks = new Category(
        "Drinks",
        Arrays.asList(drinkType200ml, drinkType500ml, drinkType1000ml)
    );
    final Map waterPrices = new HashMap();
    waterPrices.put(drinkType200ml, 10.0);
    waterPrices.put(drinkType500ml, 20.0);
    waterPrices.put(drinkType1000ml, 30.0);
    final Map pepsiPrices = new HashMap();
    pepsiPrices.put(drinkType200ml, 25.0);
    pepsiPrices.put(drinkType500ml, 45.0);
    pepsiPrices.put(drinkType1000ml, 75.0);
    final Map butterPrices = new HashMap();
    butterPrices.put(spreadType100g, 15.0);
    butterPrices.put(spreadType200g, 25.0);
    final Map margarinePrices = new HashMap();
    margarinePrices.put(spreadType100g, 12.0);
    margarinePrices.put(spreadType200g, 20.0);
    final Map mayoPrices = new HashMap();
    mayoPrices.put(spreadType100g, 20.0);
    mayoPrices.put(spreadType200g, 35.0);
    final Item water = new Item("Water", drinks, waterPrices);
    final Item pepsi = new Item("Pepsi", drinks, pepsiPrices);
    final Item butter = new Item("Butter", spreads, butterPrices);
    final Item margarine = new Item("Margarine", spreads, margarinePrices);
    final Item mayonnaise = new Item("Mayonnaise", spreads, mayoPrices);

    this.categories = Arrays.asList(drinks, spreads);
    this.itemLookup = new HashMap>();
    itemLookup.put(drinks, Arrays.asList(water, pepsi));
    itemLookup.put(spreads, Arrays.asList(butter, margarine, mayonnaise));
  }

  @Override
  public List getCategories() {
    return categories ;
  }

  @Override
  public List getItemsByCategory(Category category) {
    return itemLookup.get(category);
  }

}

ItemTable.java

package itemtable;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.util.Callback;

public class ItemTable extends Application {

  @Override
  public void start(Stage primaryStage) {
    final DAO dao = new MockDAO();
    final ChoiceBox choiceBox = new ChoiceBox();
    choiceBox.getItems().setAll(dao.getCategories());

    final TableView table = new TableView();
    final TableColumn nameCol = new TableColumn("Name");
    nameCol.setCellValueFactory(new PropertyValueFactory("name"));
    final TableColumn priceCol = new TableColumn("Price");
    table.getColumns().addAll(nameCol, priceCol);

    choiceBox.getSelectionModel().selectedItemProperty()
        .addListener(new ChangeListener() {
          @Override
          public void changed(ObservableValue observable, Category oldValue, Category newValue) {
            table.getItems().clear();
            priceCol.getColumns().clear();
            for (final Type type : newValue.getTypes()) {
              final TableColumn col = new TableColumn(type.getName());
              col.setCellValueFactory(new Callback, ObservableValue>() {
                @Override
                public ObservableValue call(CellDataFeatures cellData) {
                  Item item = cellData.getValue();
                  if (item == null) {
                    return null;
                  } else {
                    return item.priceProperty(type);
                  }
                }
              });
              priceCol.getColumns().add(col);
            }
            table.getItems().setAll(dao.getItemsByCategory(newValue));
          }
        });

    BorderPane root = new BorderPane();
    root.setTop(choiceBox);
    root.setCenter(table);

    Scene scene = new Scene(root, 600, 600);
    primaryStage.setScene(scene);
    primaryStage.show();
  }

  public static void main(String[] args) {
    launch(args);
  }
}

Tags: Java

Similar Questions

  • How to create the ADC for first name

    Hello

    I have the situation here, I need display the default in the e-mail (Dear) when the value in the first name field is less than 2 characters long or it is empty. Otherwise, I need to insert the value of the field name (Dear John).

    Please let me know how to create an ADC for this.

    Thank you

    Rama

    Use wildcards for searching.

    ? = any 1 character

    * = 0 or any number of characters

    In order to find people with more than 2 characters in this area?: *

    Then, build your default rule to merge the content in case they encounter more rule of character 2.

  • How to create an ERD for the vista sp2 x 64?

    How to create an ERD for the vista sp2 x 64?

    How to create an ERD for the vista sp2 x 64?

    If you do not have a Microsoft Vista DVD, make a repair disc to do a Startup Repair:

    Download the ISO on the link provided and make a record of repair time it starts.

    Go to your Bios/Setup, or the Boot Menu at startup and change the Boot order to make the DVD/CD drive 1st in the boot order, then reboot with the disk in the drive.

    At the startup/power on you should see at the bottom of the screen either F2 or DELETE, go to Setup/Bios or F12 for the Boot Menu.

    When you have changed that, insert the Bootable disk you did in the drive and reboot.

    http://www.bleepingcomputer.com/tutorials/tutorial148.html

    Link above shows what the process looks like and a manual, it load the repair options.

    NeoSmart containing the content of the Windows Vista DVD 'Recovery Centre', as we refer to him. It cannot be used to install or reinstall Windows Vista, and is just a Windows PE interface to recovering your PC. Technically, we could re-create this installation with downloadable media media freely from Microsoft (namely the Microsoft WAIK, several gigabyte download); but it is pretty darn decent of Microsoft to present Windows users who might not be able to create such a thing on their own.

    Read all the info on the website on how to create and use:

    http://NeoSmart.net/blog/2008/Windows-Vista-recovery-disc-download/

    ISO Burner: http://www.snapfiles.com/get/active-isoburner.html

    It's a very good Vista startup repair disk.

    You can do a system restart tool, system, etc it restore.

    It is NOT a disc of resettlement.

    Make sure you get the 64 bit version.

    See you soon. Mick Murphy - Microsoft partner

  • How to create a password for the user account for my child?

    How to create a password for the user account for my child?

    You can create the user with the parental control account. This will act as a protection for the child's account.

    You can take a look at the following links on setting up parental controls:

    http://Windows.Microsoft.com/en-us/Windows/set-up-family-safety#set-up-family-safety=Windows-7

    http://Windows.Microsoft.com/en-us/Windows/set-parental-controls#1TC=Windows-7

    http://www.howtogeek.com/HOWTO/10524/how-to-use-parental-controls-in-Windows-7/

  • How to create a shortcut for all users during installation

    Hi people,

    We have a desktop application that is distributed with Java Webstart and works on Win7 machines. Initially, users all connected using a connection by default, so creating shortcuts was not a problem. Now, because of new networking strategies, each user has his own connection.

    The problem is that the shortcut to the application is created in the user profile (for example "C:\Users\JohnDoe\", so that other users in the same machine can not run the application unless he or she installs the application again.)

    Is there a way to create this shortcut for all users using JNLP API or configuration in the xml file?

    If anyone has need of the solution: during installation I save the jnlp file in a directory accessible to all the world and then start the application using "javaws path\to\file.jnlp". More details in How to create a shortcut for java webstart available for all users on Windows 7?-stack overflow

  • How to create the presentation for the columns variable and use it in the story?

    Hi all

    Someone knows how to create variable presentation for a column (that is, I need to create it in edit section formula itself). And then, I should use it in the Narrative section to display the value of this column. Is this possible? Or do I need to use any other variable for this requirement? If Yes please let me know, how to create it? This is a very urgent requirement.

    Thanks in advance
    Stephanie

    Hello
    You can have any number of columns in the narrative view, he will accept... Just mention the numbers of the columns in the view body narrative...

    check if useful/correct...

    Thank you
    prassu

  • How to create unique variables for... in loop? (AS2)

    Hello

    I have a function onEnterFrame controlling all the movie clips in a table. The movement of each of these clips is controlled by a few variables - speed, acceleration, etc - that are changed on every enterFrame. I can't understand how to create unique variables for each element of the array. Now my variables are the same for all elements, and therefore the proposals of each video clip are the same.

    I used this code to add my video clips in the table:

    for (i = 0; i < starNumber; i ++) {}
    duplicateMovieClip (star, "star" + I, i);
    starArray.push (this ["star" + String (i)]);
    }

    I do a similar thing to create unique variables for each? Or is there something I need to do my loop (myClip in myArray) which is contained in my onEnterFrame function?

    I can post my code if that would help (65 lines).

    Creating unique variables is easy way out. Here's the modified code using unique variables that should solve your problem:

    var i: Number;

    var starArray:Array = [];

    var starArray_X:Array = [];

    var starArray_Y:Array = [];

    var mc:String;

    var scale: number;

    var speedXMod:Number;

    var speedYMod:Number;

    var starNumber:Number = 10;

    var minSize:Number = 15;

    var maxSize:Number = 80;

    var speed: number = 0.2;

    var minSpeed:Number = 0;

    var maxSpeed:Number = 1;

    for (i = 0; i< starnumber;="">

    duplicateMovieClip (star, "star" + I, i);

    starArray.push (this ["star" + String (i)]);

    }

    (MC starArray) {}

    starArray [mc] ._x = (Math.Random () * Stage.width);

    starArray [mc] ._y = (Math.Random () * Stage.height);

    scale = (minSize + (Math.Random () * (maxSize - minSize)));

    ._xscale starArray [mc] = scale;

    starArray [mc] ._yscale = scale;

    var startSpeedX:Number = ((Math.pow (-1, (Math.round (Math.random ())) * (minSpeed + (Math.Random () * (maxSpeed - minSpeed)));)))

    var startSpeedY:Number = ((Math.pow (-1, (Math.round (Math.random ())) * (minSpeed + (Math.Random () * (maxSpeed - minSpeed)));)))

    [mc] starArray_X = startSpeedX;

    [mc] starArray_Y = startSpeedY;

    onEnterFrame = function() {}

    (MC starArray) {}

    speedXMod = ((Math.random () * acceleration)-(0,5 * accélération));

    speedYMod = ((Math.random () * acceleration)-(0,5 * accélération));

    If (((Math.abs (starArray_X [mc] + speedXMod)) < maxspeed)="" &&="" ((math.abs(stararray_x[mc]="" +="" speedxmod))=""> minSpeed)) {}

    [mc] starArray_X += speedXMod;

    } else {}

    [mc] starArray_X = speedXMod;

    }

    If (((Math.abs (starArray_Y [mc] + speedYMod)) < maxspeed)="" &&="" ((math.abs(stararray_y[mc]+="" speedymod))=""> minSpeed)) {}

    [mc] starArray_Y += speedYMod;

    } else {}

    [mc] starArray_Y = speedYMod;

    }

    If (((starArray [mc]._x + starArray_X[mc]) > 0) & ((starArray [mc]._x + starArray_X[mc])))<>

    starArray [mc] ._x += starArray_X [mc];

    } else {}

    starArray_X [mc] * = - 1;

    starArray [mc] ._x += starArray_X [mc];

    }

    If (((starArray [mc]._y + starArray_Y[mc]) > 0) & ((starArray [mc]._y + starArray_Y[mc])))<>

    starArray [mc] ._y += starArray_Y [mc];

    } else {}

    starArray_Y [mc] * = - 1;

    starArray [mc] ._y += starArray_Y [mc];

    }

    }

    }

    }

  • How to create a jar for icons

    Hi all


    How to create a jar for icons? Please help me thanks in advance.


    Sarah

    Hi Sarah!

    To do this, you use at best the jdk (java development kit) which is already
    installed on your pc in forms is installed.

    Copy all your gif icons in a folder
    Open the command prompt and in this folder.

    If we assume that you have installed forms in the default directory, call the jar.exe like this:

     x:\DevSuiteHome_1\jdk\bin\jar -cfv your_icons.jar *.gif
    

    This will create a jar file in the same directory.
    Copy the jar file into your x:\DevSuiteHome_1\forms\java folder.

    Then open your formsweb.cfg x:\DevSuiteHome_1\forms\server and change your configuration entry under the

    archive_jini=frmall_jinit.jar
    

    TO

    archive_jini=frmall_jinit.jar, your_icons.jar
    

    Please check if in your formsweb.cfg so the imagebase is set to the code base.
    If this isn't the case, create a parameter in your config entry:

    imagebase=codebase
    

    Now the jar file is loaded when you start your application and the icons are
    turns red from the jar file.

    Concerning

  • How to create a login for PHP users

    How to create a login for users to access their data, currently, I don't see the first user each time I connect with a different user name. I know that I need session stuff but don't know how to use, add or where to put them.
    Thanks in advance.

    Hello

    Find this in your login page:

    session_register ("MM_Username");

    and then you add a session variable in MX called it:

    MM_Username

    then on any of your pages that calls the base to make sure that you use the = MM_Username and then you're all set; Make sure that the tables have a field to reference the session MM_Username variable.

    See you soon
    Let me know if you just come!

  • Iconia w500 reset stuck at "Create an account for this PC" during windows install only mouse works

    I have the Acer Iconia W500 we have upgraded to Windows 10.  Due to the assumption of updated driver, I decided to reset the tablet.  I have reset the system without discs and then installing Windows, that the computer is blocked "create an account for this PC' because the USB mouse works.  I discovered that the touch screen and a keyboard are unusable during this process so I plugged a USB mouse that works very well.  But installing requires that I type a user name, and it won't let me skip this step.  Without keyboard or touch screen, I am unable to enter a user name in the field.  Thank you for your suggestions.

    Plug a keyboard instead of a mouse, you can tab between fields to be able to live without the mouse. If you do not have a practical USB keyboard, check the local thrift stores. They are generally very cheap there...

  • Why Vista WMP can't play .asf files and why MS has not created a fix for this?

    Why Vista WMP can't play .asf files and why MS has not created a fix for this?

    Hi pdaamckechnie,

    The ASF Format (Advanced Systems) is the preferred Windows Media file format. With Windows Media Player, if the appropriate codecs are installed on your computer, you can play audio content, video content, or both, that is compressed with a wide variety of codecs and that is stored in an .asf file.

    You can check the link below for more information on the types of media files that supports Windows Media Player
    Information on the types of media files that supports Windows Media Player
    http://support.Microsoft.com/kb/316992

    See the link below for more information on codecs.
    Codecs: Frequently asked questions
    http://Windows.Microsoft.com/en-us/Windows-Vista/codecs-frequently-asked-questions

    Please post back and let us know if it helped to solve your problem.

    Kind regards
    KarthiK TP

  • How to create a password for the pdf file

    The Adore Acrobat XI, how to create a password for the file? Aid says going to the Tools Menu and clicking on the Protection tab - but there is no option. In the security file - properties - screen, it shows the security details but doesn't allow for no change.

    I think you can be mixing two different products: (free) Adobe Reader and Acrobat ($$).

  • How to create a card for After Effects?

    How to create a card for After Effects?

    After effects Developer Center

  • How to create a recovery for TPT 2 disc

    Hello

    I really don't like the idea that my only restore options re' is on the same drive. So, if my drive goes down, I have no recovery option. I tried to create a recovery disk using the tools integrated in Windows, but it error. Other forums say that it can happen with OEMs. So, how can I create a recovery for my TPT2 disc? I have a USB DVD burner

    Hello

    Yep, those are the steps I've tried. Then it gives me an error code 80070057 #. I tried with two different CD/DVD burners to ensure it wasn't a burner problem.

    Now, since the announcement, I found another recovery option that seems to work:

    1. tap search in the bar of charms.

    2. Type "Recovery" and then press on to find settings

    3. click on 'create a disc of Recvovery '.

    4. follow the steps in this wizard.

    This creates a recovery USB disk. I still prefer to have a CD through the utility to backup WIndows 7 and recovery screen, but I hope this recovery USB will work as well.

  • How to create a type for an enumeration definition

    Sorry for this question of newbe, but I'm working on cleaning up my Act by using types of producer/consumer for event driven state machines.  To do this, it is convenient to create a type definition for the control of the enumeration that defines the possible States of the loop of the consumer.  I don't understand all of the discussion in the books I read.  I just placed an enumeration of control on the front and edited the State names, using them to define the queue for the loop of the consumer.  However, when I use the other functions of the queue and create a constant for the State to put it on the queue, a constant gets shot at the time of its creation.  If the list of States is modified, the item queue using the defined constant previously shows a symbol of constraint (red dot) and the constant does contain not the new State potential... is what the type definition is to propagate this definition to the constants so that they keep up with additions to the list of enumeration...?

    I've been playing with a short example to see how it works.  If someone could help me with something of definition, I would appretiate it.

    Thank you

    Hummer1

    Hi Hummer1,

    Follow these steps:

    1. under the 'file' menu, select 'new '.... »

    2. a dialog box will appear.  Select "custom control" and click "ok".

    3. a new façade will pop up, called "control1.ctl".  Put your constant listed on this new façade.  Add all your statements for your state machine, the way that you did.

    4. under the menu on your new custom control, you will see a field called 'control '.  Click on it and choose 'type definition' (or 'type strict definition').

    5. save your new control custom as "states.ctl" or "enum.ctl" or any name strikes your fancy.

    Now, go back to your main VI.  In the palette "orders", click on "select control".   Choose the typedef, that you just created.  Put it on the front panel.  Right-click on it and select "search terminal.  Your block diagram will jump upward and terminal control will be highlights.  Right-click on it and select "change constant.  Now, you can wire this constant in your queue.  Do the same for any other subVIs that use the same queue, so that they you are referencing the typedef.

    When you want to make changes to your control, open it in the same way you would open a VI and make the changes.  Then, under the "file" menu, select "apply changes".  Changes will propagate through all your screws

    I have attached a small example of a typedef for you.

    Diane

Maybe you are looking for

  • New to Skype, I thought it was free for iphone?

    I'm new to Skype and want to only download the iphone app, but he keeps asking me to review my payment information to iTunes and then I see a button called 'buy '. I thought that Skype is free? I'm doing something wrong? I have a meeting scheduled ne

  • HP Mini 110: failure of verification of password... fatal error... system halted

    My HP110 mini when it is powered on the screen only I get is 'Enter current password' (I can't remember) after three tries, I get a message saying "failed verification of password...". Fatal error... System stopped. CNU93852LK can you please walk me

  • sleep/wake button Exchange program

    Hi, I would like to know is there an expiration date for the button standby/Exchange program? Thank you.

  • About the game COD5 on windows 7

    Hey there, im for windows 7 Home premium Edition operating and im buy COD5 soon. I need to know if windows 7 can run the game... ?? or should I like it go to properties and make it compatible? answer as soon as POSSIBLE

  • RAM support and use for windows vista and more

    If (my motherboard supports and) I install for example 6 GB of ram, vista/7 32-bit windows will recognize and be able to use it?or they leave half of the unusable ram? for those who want the truth revealed open their hearts and their secrets unseal r