how to display list of items (e1 , e2 ,.., en) in a CellFactory in Javafx - uitableview

let's consider this
We have an article and an article may be stored in many magasins(Stores)
and vice versa we can store many articles in one Store.
lets say we have
class Article{
int id_article;
String name;
List<Magasin> magasins;
List<Magasin> getMagasins{
return magasins;
}
lets say that Magasin class look like this
class Magasin{
int id_magasin;
String name;
//getters and setters
}
And let's say I have My tableView in javafx :
TableView tblArticles;
first column contain article name and second column Want it to contain name of all magasins (stores ) that the articles is stored in ( magasin-1, magasin-2 .. magasin-N)
I want also to ask if I can make the cell as a column that means that every name of song will be display vertically just like a list view and all of them for sure for one specif artist ..
UPDATE :
this is the code I have added to my controller :
//FRom FXML file
#FXML
TableColumn<Article, List<Magasin>> colMag ;
PropertyValueFactory<Article, List<Magasin>> mag = new PropertyValueFactory<>("magasins");
//CellValueFactory
colMag.setCellValueFactory(mag);
//cell Factory
colMag2.setCellFactory( col -> {
ListView<Magasin> listView = new ListView<>();
listView.setCellFactory(lv -> new ListCell<Magasin>() {
#Override
public void updateItem(Magasin magasin, boolean empty) {
super.updateItem(magasin, empty);
if (empty) {
setText(null);
} else {
setText(magasin.getLibelle());
}
}
});
return new TableCell<Article, List<Magasin>>() {
#Override
public void updateItem(List<Magasin> mags, boolean empty) {
super.updateItem(mags, empty);
if (empty) {
setGraphic(null);
} else {
listView.getItems().setAll(mags);
setGraphic(listView);
}
}
};
});
When I run this I got the error :
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at java.util.AbstractCollection.addAll(AbstractCollection.java:343)
at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:99)
at javafx.collections.ModifiableObservableListBase.setAll(ModifiableObservableListBase.java:88)
at controllers.DashboardController$6.updateItem(DashboardController.java:1180)
at controllers.DashboardController$6.updateItem(DashboardController.java:1173)
at javafx.scene.control.TableCell.updateItem(TableCell.java:663)
at javafx.scene.control.TableCell.indexChanged(TableCell.java:468)
at javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:116)
at com.sun.javafx.scene.control.skin.TableRowSkinBase.updateCells(TableRowSkinBase.java:533)
at com.sun.javafx.scene.control.skin.TableRowSkinBase.init(TableRowSkinBase.java:147)
at com.sun.javafx.scene.control.skin.TableRowSkin.<init>(TableRowSkin.java:64)
at javafx.scene.control.TableRow.createDefaultSkin(TableRow.java:212)
at javafx.scene.control.Control.impl_processCSS(Control.java:872)

Related

Jena simple example java.lang.NoClassDefFoundError

I have tried this simple example and after hours spent still can not resolve the problem. I was wondering if anyone has any idea?
import org.apache.jena.rdf.model.*;
import org.apache.jena.vocabulary.*;
/** Tutorial 1 creating a simple model
*/
public class Tutorial01 extends Object {
// some definitions
static String personURI = "http://somewhere/JohnSmith";
static String fullName = "John Smith";
public static void main (String args[]) {
// create an empty model
Model model = ModelFactory.createDefaultModel();
// create the resource
Resource johnSmith = model.createResource(personURI);
// add the property
johnSmith.addProperty(VCARD.FN, fullName);
}
}
After running the program..
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/jena/rdf/model/ModelFactory
at jena.Tutorial01.main(Tutorial01.java:17)
Caused by: java.lang.ClassNotFoundException:
org.apache.jena.rdf.model.ModelFactory
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more

how to add arraylist contents to menu in jsf 2

I want to add the contents of an arraylist has meu in a jsf page but playing me anything can you help me !!!! thnks
this is the method where i fill my arraylist from database in bean
public List<String> profession_pere_list;
public String profession_pere;
//....setters & getters
public List<String> getSelectProfessions() throws SQLException, NamingException{
profession_pere_list = new ArrayList<String>();
initctx = (Context) new InitialContext();
Context envContext = (Context) initctx.lookup("java:comp/env");
ds = (DataSource) envContext.lookup("jdbc/reinscription");
cnx = ds.getConnection();
state = cnx.createStatement();
rst = state.executeQuery("select profession from professions");
while(rst.next())
{
etu = new etudiants();
prof =rst.getString(1);
etu.setProfession_pere(prof);
//profession_pere=prof;
//etu.setProfession_pere(rst.getString(1).toString());
profession_pere_list.add(prof);
}
return profession_pere_list;}
and my jsf page:
<h:selectOneMenu value="#{etudiants.profession_pere}">
<f:selectItems value="#{etudiants.profession_pere_list}"/>
so i have this error unknown source !!!
javax.servlet.ServletException
javax.faces.webapp.FacesServlet.service(Unknown Source)
cause mère
java.lang.NullPointerException
com.sun.faces.renderkit.SelectItemsIterator$GenericObjectSelectItemIterator$GenericObjectSelectItem.updateItem(Unknown Source)
com.sun.faces.renderkit.SelectItemsIterator$GenericObjectSelectItemIterator$GenericObjectSelectItem.access$600(Unknown Source)
com.sun.faces.renderkit.SelectItemsIterator$GenericObjectSelectItemIterator.getSelectItemFor(Unknown Source)
com.sun.faces.renderkit.SelectItemsIterator$IterableItemIterator.next(Unknown Source)
com.sun.faces.renderkit.SelectItemsIterator$IterableItemIterator.next(Unknown Source)
com.sun.faces.renderkit.SelectItemsIterator.next(Unknown Source)
com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(Unknown Source)
com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(Unknown Source)
com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(Unknown Source)
javax.faces.component.UIComponentBase.encodeEnd(Unknown Source)
javax.faces.component.UIComponent.encodeAll(Unknown Source)
javax.faces.component.UIComponent.encodeAll(Unknown Source)
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(Unknown Source)
com.sun.faces.application.view.MultiViewHandler.renderView(Unknown Source)
com.sun.faces.lifecycle.RenderResponsePhase.execute(Unknown Source)
com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
com.sun.faces.lifecycle.LifecycleImpl.render(Unknown Source)
javax.faces.webapp.FacesServlet.service(Unknown Source)
I had the same issue and the rason was a List modified concurently by different HTTP threads in ViewScoped bean:
#ViewScoped
public class Bean {
private List<Object> list;
public List<Object> getList() {
this.list = new ArrayList<>();
// code which modifies list
return this.list;
}
}
Solution - synchronize access to list:
public synchronized List<Object> getList() {
In my case I had sometimes your exception and sometimes ConcurrentModificationException.
I have also found another explanation:
http://www.adam-bien.com/roller/abien/entry/jsf_nullpointerexception_in_selectitemsiterator_java
When SelectItem label is null - you can also get your exception.

Processing using ControlP5 listbox

I encountered really a strange problem with using a ControlP5 ListBox in my program. I found an example of ListBox use from the official page of ControlP5 library: http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5listBox/ControlP5listBox.pde I did some simple changes like changing listbox width and height, setting different colors. The main difference consist in the fact I'm using an arrayList of Strings to populate listbox. Here is the complete code for this scetch:
import javax.swing.*;
PFrame f;
public class PFrame extends JFrame {
public SecondApplet s;
public PFrame(int width, int height,ArrayList<String> companiesTxt) {
setBounds(100, 100, width, height);
s = new SecondApplet(companiesTxt);
add(s);
s.init();
show();
}
}
public class SecondApplet extends PApplet {
ArrayList<String> companiesText;
ControlP5 cp5;
ListBox l;
ControlWindow controlWindow;
SecondApplet(ArrayList<String> cmpTxt){
companiesText = cmpTxt;
}
void setup(){
size(400, 720);
ControlP5.printPublicMethodsFor(ListBox.class);
cp5 = new ControlP5(this);
l = cp5.addListBox("myList")
.setPosition(0, 0)
.setSize(382, 720)
.setItemHeight(18)
.setBarHeight(18)
.setColorBackground(color(243, 45,98))
.setColorActive(color(0))
.setColorForeground(color(255, 100,0))
;
l.captionLabel().toUpperCase(true);
l.captionLabel().set("Companies");
l.captionLabel().setColor(0xffff0000);
l.captionLabel().style().marginTop = 3;
l.valueLabel().style().marginTop = 3;
for (int i=0;i != companiesText.size();i++) {
ListBoxItem lbi = l.addItem(companiesText.get(i), i);
lbi.setColorBackground(color(243, 45,98));
}
}
void draw(){
}
}
When I try to scroll this listbox, I get an exception:
java.lang.ArrayIndexOutOfBoundsException: 8217
at controlP5.BitFont.getGlyph(Unknown Source)
at processing.core.PGraphics.textCharImpl(PGraphics.java:4681)
at processing.core.PGraphics.textLineImpl(PGraphics.java:4669)
at processing.core.PGraphicsJava2D.textLineImpl(PGraphicsJava2D.java:1787)
at processing.core.PGraphics.textLineAlignImpl(PGraphics.java:4659)
at processing.core.PGraphics.text(PGraphics.java:4356)
at processing.core.PGraphics.text(PGraphics.java:4307)
at processing.core.PApplet.text(PApplet.java:13183)
at controlP5.ControlFont.draw(Unknown Source)
at controlP5.Label.draw(Unknown Source)
at controlP5.Label$SinglelineLabel.draw(Unknown Source)
at controlP5.Label.draw(Unknown Source)
at controlP5.Button$ButtonView.display(Unknown Source)
at controlP5.Button$ButtonView.display(Unknown Source)
at controlP5.Controller.draw(Unknown Source)
at controlP5.ControllerGroup.drawControllers(Unknown Source)
at controlP5.ControllerGroup.draw(Unknown Source)
at controlP5.ControllerGroup.drawControllers(Unknown Source)
at controlP5.ControllerGroup.draw(Unknown Source)
at controlP5.ControlWindow.draw(Unknown Source)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1236)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1229)
at processing.core.PApplet.handleMethods(PApplet.java:1423)
at processing.core.PApplet.handleDraw(PApplet.java:2401)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
at processing.core.PApplet.run(PApplet.java:2256)
at java.lang.Thread.run(Unknown Source)
I'm almost desperate because I do not understand what can be wrong in this case? Please, can you give me any suggestions?
The problem was resolved. I was using some strings that are not aschii characters. GetGlyph function looks like this:
public Glyph getGlyph(char c) {
return glyphs[(int) (c)];
}
So, when you want to use a listbox convert characters to aschii:
for (int i=0;i < companiesText.size();i++) {
try{
ListBoxItem lbi = l.addItem(newString(companiesText.get(i).getBytes("US-ASCII"),"US-ASCII"), i);
lbi.setColorBackground(color(243, 45,98));
}catch(Exception e){
}
}

Neo4j Spatial: Supplied index configuration doesn't match stored config

I am using Neo4j 1.8.2 with spatial 0.9.
I get the following exception when I try to get a handle to the spatial index on an existing graph that contains the index already:
Exception in thread "main" java.lang.IllegalArgumentException: Supplied index configuration:
{geometry_type=point, lon=lon, provider=spatial, lat=lat}
doesn't match stored config in a valid way:
{geometry_type=point, lon=lon, provider=spatial, lat=lat}
for 'testspatial'
at org.neo4j.kernel.IndexManagerImpl.assertConfigMatches(IndexManagerImpl.java:156)
at org.neo4j.kernel.IndexManagerImpl.findIndexConfig(IndexManagerImpl.java:137)
at org.neo4j.kernel.IndexManagerImpl.getOrCreateIndexConfig(IndexManagerImpl.java:198)
at org.neo4j.kernel.IndexManagerImpl.getOrCreateNodeIndex(IndexManagerImpl.java:301)
at org.neo4j.kernel.IndexManagerImpl.forNodes(IndexManagerImpl.java:289)
at TestSpatialIndexFetch.createSpatialIndex(TestSpatialIndexFetch.java:22)
at TestSpatialIndexFetch.main(TestSpatialIndexFetch.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
If I delete the database, the index is created successfully. If I use this database now to get the index back, it fails.
Any ideas?
Sample test code:
public class TestSpatialIndexFetch {
public static void main(String[] args) {
EmbeddedGraphDatabase db = new EmbeddedGraphDatabase("c://neo4jdbs//testindex");
registerShutdownHook(db);
Index<Node> index = createSpatialIndex(db, "testspatial");
}
private static Index<Node> createSpatialIndex(EmbeddedGraphDatabase db, String indexName) {
return db.index().forNodes(indexName, SpatialIndexProvider.SIMPLE_POINT_CONFIG);
}
private static void registerShutdownHook( final GraphDatabaseService graphDb )
{
Runtime.getRuntime().addShutdownHook( new Thread()
{
#Override
public void run()
{
graphDb.shutdown();
}
} );
}
}
Fixed and released at http://m2.neo4j.org/content/repositories/releases/org/neo4j/neo4j-spatial/0.9.1-neo4j-1.8.2/
Issue 93: https://github.com/neo4j/spatial/issues/93

Neo4 Example does not work - Class not found

I have copied and pasted a simple neo4j example from the tutorial section but currently i got the messages:
[INFO] Surefire report directory: /home/kama/ws-git/neo4jexample/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNGMapConfigurator#17bd6a1
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 2.995 sec <<< FAILURE!
Results :
Failed tests: firstTest(com.soebes.tutorials.Neo4JAppTest): com/soebes/tutorials/neo4jexample/RelationTypes
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
The detailed error message:
java.lang.NoClassDefFoundError: com/soebes/tutorials/neo4jexample/RelationTypes
at com.soebes.tutorials.neo4jexample.Neo4JApp.createDb(Neo4JApp.java:44)
at com.soebes.tutorials.neo4jexample.Neo4JApp.main(Neo4JApp.java:25)
at com.soebes.tutorials.Neo4JAppTest.firstTest(Neo4JAppTest.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:691)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:883)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1208)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:758)
at org.testng.TestRunner.run(TestRunner.java:613)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1137)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1062)
at org.testng.TestNG.run(TestNG.java:974)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:76)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:161)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:101)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:115)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
Caused by: java.lang.ClassNotFoundException: com.soebes.tutorials.neo4jexample.RelationTypes
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
The source code of this looks like this:
public class Neo4JApp {
private String greeting;
private GraphDatabaseService graphDb;
private Node firstNode;
private Node secondNode;
private Relationship relationship;
public static void main(final String[] args) {
Neo4JApp hello = new Neo4JApp();
hello.createDb(args[0]);
hello.removeData();
hello.shutDown();
}
void createDb(String path) {
clearDb(path);
graphDb = new EmbeddedGraphDatabase(path);
registerShutdownHook(graphDb);
Transaction tx = graphDb.beginTx();
try {
firstNode = graphDb.createNode();
firstNode.setProperty("message", "Hello, ");
secondNode = graphDb.createNode();
secondNode.setProperty("message", "World!");
relationship = firstNode.createRelationshipTo(secondNode, RelationTypes.KNOWS);
relationship.setProperty("message", "brave Neo4j ");
System.out.print(firstNode.getProperty("message"));
System.out.print(relationship.getProperty("message"));
System.out.print(secondNode.getProperty("message"));
greeting = ((String) firstNode.getProperty("message"))
+ ((String) relationship.getProperty("message"))
+ ((String) secondNode.getProperty("message"));
tx.success();
} finally {
tx.finish();
}
}
private void clearDb(String path) {
try {
FileUtils.deleteRecursively(new File(path));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
void removeData() {
Transaction tx = graphDb.beginTx();
try {
firstNode.getSingleRelationship(RelationTypes.KNOWS, Direction.OUTGOING).delete();
firstNode.delete();
secondNode.delete();
tx.success();
} finally {
tx.finish();
}
}
void shutDown() {
System.out.println();
System.out.println("Shutting down database ...");
graphDb.shutdown();
}
private static void registerShutdownHook(final GraphDatabaseService graphDb) {
// Registers a shutdown hook for the Neo4j instance so that it
// shuts down nicely when the VM exits (even if you "Ctrl-C" the
// running example before it's completed)
Runtime.getRuntime().addShutdownHook(new Thread() {
#Override
public void run() {
graphDb.shutdown();
}
});
}
And the used class RelationTypes looks like this:
public enum RelationTypes implements RelationshipType {
KNOWS,
WHOKNOWS,
}
The project can be found at github.
Currently i don't see the problem?...The RelationTypes are defined in the correct location...May be someone has a hint for me?
The problem was the directory of the unit test which is not allowed to be the target folder itself. It must be a separate folder under target.

Resources