Friday, March 6, 2015
Your Project Website on github
You have some projects on github and you need some webspace for a small Project Webpage or generated Software artifacts? Then https://pages.github.com/ is something for you. With a few steps you create a new repository at github that hosts all your webpages. A short description guides you through all necessary steps. Have fun!
Saturday, February 28, 2015
Pitfall during first Steps with Grails
Yesterday we started a coding night at our company with the goal to checkout the benefits of seperated programming of backend and frontend code. We were free in choosing technologies so i decided to use Grails for the backend and Angular.js as the frontend technology. The first tries saving an entity failed and i did not explain it to myself why that was happening. A simple Adress Entity with some fields (name, street etc. ) but saving did nothing. The solution came to me after i enabled the SQL Debug Logging in Grails (open DataSource.groovy and add logSql=true to the dataSource Definition). The logging revealed that all fields were non nullable so inserting failed without an error message. Not really nice by Grails :-)
About the result of my experiments i will inform you later, so check my block.
About the result of my experiments i will inform you later, so check my block.
Friday, January 9, 2015
Debug Information when using Java's Printing Services
If you work with javax.print and want to know which parameters are sent to the printing device use following VM parameter to enable some debug information on standard out:
-Dsun.print.ippdebug=true
-Dsun.print.ippdebug=true
Saturday, January 3, 2015
Quick Dependency resolving with Grape
Most of the time i use Groovy with the GroovyShell or as a Groovy-Shell Script (remember my Blog-Post in October). Doing it that way you can achieve a lot with some lines of Groovy Script and the Groovy Standard Library Classes. But what if you need some classes from some third party libraries?
If you run your Groovy Script inside the GroovyShell you can simply modify the file groovy-starter.conf (resides in the conf folder of your GroovyShell installation). Add the classpath to the required library and you are done.
But this can get quite difficult if the library has further dependencies and you did not have these ones. Or you have these dependencies but only as maven dependencies, living in a gigantic maven repo on your local harddrive.
To get around this issue Groovy provides a Maven like mechanism called Grape. Grape does all the dependency resolving for you by doing lookups in well known Maven Repositories. So for example, if you like to have the FTPClient class from org.apache.commons.net in your Groovy Script, add the following Grape Statement:
@Grapes(
@Grab(group='commons-net', module='commons-net', version='3.2')
)
Then add the import statement for the FTPClient class and you are done! The full script with its overwhelming functionality ;-):
@Grapes(
@Grab(group='commons-net', module='commons-net', version='3.2')
)
import org.apache.commons.net.ftp.*;
FTPClient ftpClient = new FTPClient();
If the required dependency does not exist in the repositories known by Grape you can tell Grape where to go to find it. Simply add this statement:
@GrabResolver(name='myrepo', root='http://mymavenrepo.org/')
Grape is "supported" by mvnrepository.com. If you look for a dependency mvnrepository.com tells you the grape-code for instant usage!
If you run your Groovy Script inside the GroovyShell you can simply modify the file groovy-starter.conf (resides in the conf folder of your GroovyShell installation). Add the classpath to the required library and you are done.
But this can get quite difficult if the library has further dependencies and you did not have these ones. Or you have these dependencies but only as maven dependencies, living in a gigantic maven repo on your local harddrive.
To get around this issue Groovy provides a Maven like mechanism called Grape. Grape does all the dependency resolving for you by doing lookups in well known Maven Repositories. So for example, if you like to have the FTPClient class from org.apache.commons.net in your Groovy Script, add the following Grape Statement:
@Grapes(
@Grab(group='commons-net', module='commons-net', version='3.2')
)
Then add the import statement for the FTPClient class and you are done! The full script with its overwhelming functionality ;-):
@Grapes(
@Grab(group='commons-net', module='commons-net', version='3.2')
)
import org.apache.commons.net.ftp.*;
FTPClient ftpClient = new FTPClient();
If the required dependency does not exist in the repositories known by Grape you can tell Grape where to go to find it. Simply add this statement:
@GrabResolver(name='myrepo', root='http://mymavenrepo.org/')
Grape is "supported" by mvnrepository.com. If you look for a dependency mvnrepository.com tells you the grape-code for instant usage!
Sunday, December 14, 2014
Collada Unmarshaller
Hey everybody! I just pushed my Collada Unmarshaller to github. It simply does unmarshalling with jaxb. Not more!
You find the sources here: https://github.com/laubfall/collada-loader
You find the sources here: https://github.com/laubfall/collada-loader
Wednesday, December 10, 2014
Stackoverflow in JavaFX ChangeListeners
JavaFXs ChangeListeners are an easy way to monitor changes on JavaFX Properties and do some work if a change happened. But as easy as that is you easily can run into a stackoverflow because you'd changed the monitored property inside the ChangeListener.
Imagine you like to sort a Collection every time it is modified. Do sorting inside the ChangeListener raises a Stackoverflow because the sort itself raises a change event. So, how can we prevent that? The answer is simple: remove the ChangeListener before the code that modifies the property and then add it again!
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Pair<String, L>> change){
change.getList().removeListener(this);
Collections.sort(change.getList(), comparator());
change.getList().addListener(this);
}
In this example we monitor a list and sort it when its content changes.
Imagine you like to sort a Collection every time it is modified. Do sorting inside the ChangeListener raises a Stackoverflow because the sort itself raises a change event. So, how can we prevent that? The answer is simple: remove the ChangeListener before the code that modifies the property and then add it again!
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Pair<String, L>> change){
change.getList().removeListener(this);
Collections.sort(change.getList(), comparator());
change.getList().addListener(this);
}
In this example we monitor a list and sort it when its content changes.
Saturday, November 15, 2014
JavaFX TabPane and Tab change
At the moment i am working with JavaFX building a little Application that has a lot of configurable parameters. For the reason of not getting lost on a dialog with thousand of different checkboxes, textfields and so on, the parameter controls should be grouped with the JavaFX control TabPane. A TabPane was quickly done but soon i realized that it is not so easy to prevent the user from changing the current tab if the parameters grouped in this tab have invalid values. Instead of switching to the selected tab i rather like to show a validation error message. So i did some reading on the JavaFX API but there is no way out of the box to achieve this behavior. You can do some work if the tab has changed but not before it is changed. If you have a similar issue with the TabPane maybe my solution will work for you :-)
class StateAwareChangeListener implements ChangeListener<Tab>
{
/**
* go to previous tab if validation fails and this flag is true.
*/
private boolean roleback;
/**
* If validation is ok change the tab.
*
* {@inheritDoc}
*
*/
@Override
public void changed(ObservableValue<? extends Tab> arg0, Tab arg1, Tab arg2)
{
if (roleback) {
roleback = false;
return;
}
boolean validateConfig = validateIfChangeIsPossible();
if (validateConfig == false) {
roleback = true;
tabPane.getSelectionModel().select(arg1);
}
}
}
This listener calls the method validateIfChangeIsPossible that you have to implement by yourself. If changing the tab is possible return true. If false the old tab is selected again. You can also parse the new tab as a parameter into validateIfChangeIsPossible, if you need the information.
Finally add this class as a ChangeListener to the selectedItemProperty of the TabPane:
tabPane.getSelectionModel().selectedItemProperty().addListener(new StateAwareChangeListener());
class StateAwareChangeListener implements ChangeListener<Tab>
{
/**
* go to previous tab if validation fails and this flag is true.
*/
private boolean roleback;
/**
* If validation is ok change the tab.
*
* {@inheritDoc}
*
*/
@Override
public void changed(ObservableValue<? extends Tab> arg0, Tab arg1, Tab arg2)
{
if (roleback) {
roleback = false;
return;
}
boolean validateConfig = validateIfChangeIsPossible();
if (validateConfig == false) {
roleback = true;
tabPane.getSelectionModel().select(arg1);
}
}
}
This listener calls the method validateIfChangeIsPossible that you have to implement by yourself. If changing the tab is possible return true. If false the old tab is selected again. You can also parse the new tab as a parameter into validateIfChangeIsPossible, if you need the information.
Finally add this class as a ChangeListener to the selectedItemProperty of the TabPane:
tabPane.getSelectionModel().selectedItemProperty().addListener(new StateAwareChangeListener());
Subscribe to:
Posts (Atom)