Visualise relationships between CSV file and custom datastructure - java

I'm working on an application where I need to map fields in one CSV file to fields in a data structure defined by the application. I'd thought of different ways of doing this, but the method that I like the best is the one where I would have a graphical user interface where the user could just drag columns from an entity representing the CSV file to an entity representing the internal data structure. This way, it would be all drag and drop.
Does anyone know of a Java library I can use to achieve something like this?
UPDATE
I'd like to point out that I am looking for components which can help me with the visualisation. I do know that I can't find any ready made components which will take care of the entire mapping and data transformations for me. It's a matter of trying to track down swing components which can help me visualise relationships between entities and their fields (CSV file being an entity and internal data structure being another entity).

Consider using JList or JTable containing a checkbox column, either of which would leverage the existing DnD support for those components. A common interface uses two parallel lists flanking a column of controls. For example,
(source: java2s.com)

Related

Use TableModel to save and handle data or let it just show Objects (contents)

I am writing an application that uses a JTable containing a model (DefaultTableModel). Now after working on it for some time I am not really sure if it's the best Idea to store all the data in the model.
What benefits are there if all the data is stored in Objects (in an ArrayList for example) and the model only shows the data from the objects of the list?
This came into my mind particularly after I need to write some sorting algorithms which would be way easier to handle on some kind of list. Also saving the "model" --> the list of objects (then) would be easier than saving a table model.
Is it more efficient to stay with my current concept (save data in model | serialize model to save table | sort model itself) or is it better to save everything in Objects each Object representing one row, which are stored in a list?
I need to write some sorting algorithms
JTable supports sorting of the data in the TableModel directly. Read the section from the Swing tutorial on Sorting and Filtering for more information. So this can be handled directly by the table so you don't need external code.
each Object representing one row, which are stored in a list?
Yes this is a valid approach, but the data must still reside in the TableModel. That is the List containing your custom Objects that represent a row in the table must be defined in the TableModel. If for some reason you need to access the List you add helper methods to the TableModel. Don't keep the data in two places.
For example, check out Row Table Model which was designed for this concept. The JButtonTableModel.java code shows what you would need to code for each custom object you want to store in a table.

JavaFx TableView CRUD for large database tables

I'm looking for sample apps or documentation for displaying a large table in JavaFx TableView , without loading the entire table into memory beforehand. CRUD capabilities would be nice, too, though I can write this myself if necessary.
All the examples I have found pre-load data into a an observable list (in memory, I assume), which I can't do for, say, 5 million records!
I have worked in Java Swing with table models that get their data from JDBC ResultSets, is there something similar I can do for JavaFx TableView? I also added my own sort and column layout persistence in Swing, and am looking to do something similar in JavaFx.
This may be a "beginner" question, or it's possible that I missed something simple while scouring through the JavaFx info.
Each TableView must has a model class. you can easily set your model class to table view.
For example you have class Student with (id,name,avg)
define an ObservableList of Student just like
ObservableList<Student> stdList = FXCollections.observableArrayList();
then set the list to the table view by
tableView.setDate(stdList);
and Now you can do anything you imagine (CRUD) on the list.

JTable data persistence advice

I am seeking advice in persisting my JTable data in an elegant manner. So far my research has indicated I can iterate through the many columns and rows and extract the data for saving (seems convoluted) or that I can save the table and related data as an Object in an Object file.
I would love to hear some advice from those more versed in this area as I am quite new to JTables and their workings. Are there many other solutions available that may be a better choice?
It depends on what you want to do with the persisted data. If you only want to persist it so that you can display it again later, look at serializing (Java Serializable or Java Externalizable) it to a data-stream that you put somewhere. Later you can read it back (deserialize) and display it again.
If you want to put it in a database where the information is useable for other purposes, then you probably want to implement some object which models your data to keep it clear and simple. Then you can present this in a Swing Jtable by adapting your model to a table model. This still means you need to write the adaptation/transformation logic but it shouldn't be onerous and you get the most usable result. The TableModel is simply a way of looking at your data that a JTable is able to understand. Look at Adaptor patterns to get one idea about the mapping.
Hope that helps.

dynamic object relation mapping

I am trying to create an application in java which pulls out records from the database and maps it to objects. It does that without knowing what the schema of the database looks like. All i want to do is fetch all rows from all tables and store them somewhere. There could be a thousand tables with thousands of records each. The application doesn't know the name of any table or attribute. It should map "on the fly". I looked at hibernate but it doesnt give me what i want for this app. I don't want to create hard-coded xml files and classes for mapping. Any ideas how i can accomplish this ?
Thanks
Oracle has a bunch of data dictionary views for metadata.
ALL_TABLES, ALL_TAB_COLUMNS would be first places to start. Then you'd build ad-hoc queries based on what you get out of there. Not sure whether you have to deal with all data types (dates, blobs, spatial, user-defined....).
Not sure what you mean by "store them somewhere". If you start thinking CSV or XML files, you'll need to escape various characters from VARCHAR2 columns.
If you are looking for some generic extract/unload routines, you should look at what is already available in the database or open-source/commercially.
MyBatis provides a pretty simple way to map data results to objects and back, maybe check that out?
http://code.google.com/p/mybatis/
Not to be flip, but for this task, you might want to check out Ruby on Rails and its ActiveRecord approach

Web form data structure alternatives

Once I created a form builder where user could select any number of fields for a web form. The tool then produced a code snippet which user could copy in the JSP.
The submitted form data was stored as a key-value pairs in the DB, so basically just two columns were required for the form specific data. If I remember right, the processing of the DB data was required to be done outside Java.
So creating nice excel output of this was a bit tricky. I ended up using iReport and its crosstab functionality but it wasn't a nice experience.
Are there better ways to store such form data than just using key-value pairs?
Or are there some nice approaches to crosstab/pivot key-value data for reporting?
I try to follow the The Rule of Least Power - Using the simplest structure possible for the data gives you much more flexibility in display. That said, Excel's pivot table functionality is definitely very nice for simple data structures. After creating one, you might want to try the pivot chart functionality connected to it to visualize the data flexibly - Any changes to the pivot table are reflected in the pivot chart automatically.

Categories

Resources