How to give keycodes from a properties file in javafx - javafx

Currently i have configured JavaFX keyEvents for key board controllers for each task. What i want is to configure there keys from a properties file rather than hard coding in the code.
The implementation :
final KeyCombination keyCombinationShiftC = new KeyCodeCombination(
KeyCode.ENTER, KeyCombination.CONTROL_DOWN);
javafx.event.EventHandler<javafx.scene.input.KeyEvent> handler = event -> {
if (keyCombinationShiftC.match(event)) {
try {
if (finalSubTotalPrice > 0) {
paymentAction();
} else {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle(app.values.getProperty("WARNING_TITLE"));
alert.setHeaderText(app.values.getProperty("INVALID_NO_OF_ITEMS"));
alert.setContentText(app.values.getProperty("INVALID_NO_OF_ITEMS_DIALOG"));
alert.showAndWait();
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
switch (event.getCode()) {
case F10:
try {
removeAction();
} catch (Exception e1) {
e1.printStackTrace();
}
break;
case F1:
try {
searchField.requestFocus();
} catch (Exception e1) {
e1.printStackTrace();
}
break;
case F5:
try {
customVatDiscountCalculation();
} catch (Exception e1) {
e1.printStackTrace();
}
break;
}
The ENTER+CNTRL_DOWN, F5, F10, F1 keys need to be assign for other keys without changing the code using a properties file.
If i try to get the Strings from the properties file, i fail to do that. as below. It says a constant expression is required for the case.
public static final KeyCode REMOVE_KEY = KeyCode.getKeyCode(app.values.getProperty("REMOVE_KEY"));
switch (event.getCode()) {
case REMOVE_KEY:
try {
removeAction();
} catch (Exception e1) {
e1.printStackTrace();
}
break;
}

Related

How to check if the record exist in xamarin

public bool insertIntoTablePerson(Person person)
{
try
{
using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db")))
{
connection.Insert(person);
return true;
}
} catch (SQLiteException ex) {
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
generally, if the item already has a non-zero PK then it already exists
if (item.ID != 0)
{
return database.UpdateAsync(item);
}
else {
return database.InsertAsync(item);
}

JFoenix Drawer .hide(); and .drawer(); functions are not working

I am tired on this point, JFoenix Drawer .hide(); and .drawer(); functions are not working
try {
VBox box = FXMLLoader.load(getClass().getResource("/chatroom/ui/chatingwindow/DrawerContent.fxml"));
drawer.setSidePane(box);
HamburgerBackArrowBasicTransition arrowBasicTransition = new HamburgerBackArrowBasicTransition(hamburger);
arrowBasicTransition.setRate(-1);
hamburger.addEventHandler(MouseEvent.MOUSE_PRESSED, (e) -> {
arrowBasicTransition.setRate(arrowBasicTransition.getRate() * -1);
arrowBasicTransition.play();
if (drawer.isShown()) {
drawer.hide();
} else {
drawer.draw();
}
});
} catch (IOException ex) {
Logger.getLogger(ChatingWindowController.class.getName()).log(Level.SEVERE, null, ex);
}
why is that, any Jfoenix tutorials are used that functions, but I couldn't use that?
It is because they do not exist it should be:
if (drawer.isOpened()) {
drawer.close();
} else {
drawer.open();
}

Spring MVC Multipart file upload random FileNotFoundException

I built a web application using spring MVC, everything is working fine except the file upload in which I got random FileNotFoundExceptions. I found some solutions online like using a different tmp folder but I keep getting random error.
My code is:
#RequestMapping(value="/upload", method=RequestMethod.POST)
public #ResponseBody String handleFileUpload(#RequestParam("file") final MultipartFile multipartFile,
#RequestHeader("email") final String email, #RequestHeader("password") String password){
if (authenticateUser(email, password)) {
if (!multipartFile.isEmpty()) {
System.out.println("Start processing");
Thread thread = new Thread(){
public void run(){
ProcessCSV obj = new ProcessCSV();
try {
File file = multipartToFile(multipartFile);
if(file !=null) {
obj.extractEvents(file, email, cluster, session);
}
else {
System.out.println("null File");
}
} catch (IOException e) {
System.out.println("File conversion error");
e.printStackTrace();
}
}
};
thread.start();
return "true";
} else {
return "false";
}
}
else {
return "false";
}
}
and:
public File multipartToFile(MultipartFile multipartFile) throws IOException {
File uploadFile = null;
if(multipartFile != null && multipartFile.getSize() > 0) {
uploadFile = new File("/tmp/" + multipartFile.getOriginalFilename());
FileOutputStream fos = null;
try {
uploadFile.createNewFile();
fos = new FileOutputStream(uploadFile);
IOUtils.copy(multipartFile.getInputStream(), fos);
} catch (FileNotFoundException e) {
System.out.println("File conversion error");
e.printStackTrace();
} catch (IOException e) {
System.out.println("File conversion error");
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
System.out.println("File conversion error");
e.printStackTrace();
}
}
}
}
else {
System.out.println("null MultipartFile");
}
return uploadFile;
}
and the configuration file:
multipart.maxFileSize: 100MB
multipart.maxRequestSize: 100MB
multipart.location = ${user.home}
server.port = 8090
I used different versions of the multipartToFile function, one was using multipartfile.transferTo() but I was getting the same random error. Any advice?
Thank you
EDIT stack trace:
java.io.IOException: java.io.FileNotFoundException: /Users/aaa/upload_07720775_4b37_4b86_b370_40280388f3a4_00000003.tmp (No such file or directory)
at org.apache.catalina.core.ApplicationPart.write(ApplicationPart.java:121)
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile.transferTo(StandardMultipartHttpServletRequest.java:260)
at main.RESTController.multipartToFile(RESTController.java:358)
at main.RESTController$1.run(RESTController.java:241)
Caused by: java.io.FileNotFoundException: /Users/aaa/upload_07720775_4b37_4b86_b370_40280388f3a4_00000003.tmp (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.write(DiskFileItem.java:392)
at org.apache.catalina.core.ApplicationPart.write(ApplicationPart.java:119)
... 3 more
I had just had a night of terror with this error. I found out that MultiPartFile is only recognisable to and by the #Controller class. So if you pass it to another bean which is not a controller, Spring will not be able to help you. It somewhat makes sense that the #Controller is tightly bound to the front screen (communication from the browser to the system - Controllers are the entry point from the browser). So any conversation must happen there in the Controller.
In my case, I did something like the following:
#Controller
public class FileUploadingController{
#PostMapping("/uploadHistoricData")
public String saveUploadedDataFromBrowser(#RequestParam("file") MultipartFile file) {
try {
String pathToFile = "/home/username/destination/"
new File(pathToFile).mkdir();
File newFile = new File(pathToFile + "/uploadedFile.csv");
file.transferTo(newFile); //transfer the uploaded file data to a java.io.File which can be passed between layers
dataService.processUploadedFile( newFile);
} catch (IOException e) {
//handle your exception here please
}
return "redirect:/index?successfulDataUpload";
}
}`
I had the same problem, it looks like MultipartFile is using different current dir internally, so all not absolute paths are not working.
I had to convert my path to an absolute path and then it worked.
It is working inside #RestController and in other beans too.
Path path = Paths.get(filename).toAbsolutePath();
fileToImport.transferTo(path.toFile());
fileToImport is MultipartFile.

WinRun4J - service not stopping

I'm using this to install my application as a windows service. Everything works fine except the service does not stop;
#Override
public int serviceMain(String[] strings) throws ServiceException {
try {
System.out.println("BootService: init");
System.out.println("BootService: service loop start");
while (ws.isServiceRunning()) {
System.out.println("BootService: loop");
ws.serviceHandler();
}
System.out.println("BootService: stopped");
return 0;
} catch (Exception ex) {
throw new ServiceException(ex);
}
}
#Override
public int serviceRequest(int control) throws ServiceException {
try {
switch (control) {
case SERVICE_CONTROL_SHUTDOWN:
case SERVICE_CONTROL_STOP:
if (ws!=null) {
ws.stopService();
}
break;
}
return 0;
} catch (WindowsServiceException ex) {
throw new ServiceException(ex);
}
}
My service backend code is stopped by the call to serviceRequest(), which in turn makes the loop in serviceMain() exit. I see the message "BootService: stopped" in my logs, yet the Window Control Panel Services Applet just sits says "Stopping service...", but it never does.
What would stop the service from stopping even though I'm sure it has exited the serviceMain() without error?
I donĀ“t know if you could solve it, but I had a simmilar problem and I fixed it by adding a timer that called System.exit(0)
public int serviceMain(String[] args) throws ServiceException {
while (!shutdown) {
try {
if (!myservice.isRunning()) {
(new Thread(new LaucherRunnable(args))).start();
}
Thread.sleep(6000);
} catch (InterruptedException e) {
}
}
periodicRunner.stop();
Timer t = new Timer(1000, new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
t.setRepeats(false);
t.start();
return 0;
}

SQLite Database opening issues With Blackberry Simulator?

I don't have any knowledge on working with Sqlite database on Blackberry. Recently i delved into database with Blackberry. When i tried to create the database, the database gets successfully created on Simulator(Simulate-->ChangeSDCard-->MountDirectory) on Some particular folder.
Next when i try to Open the database for creating tables & inserting data--
String db_url ="file:///SDCard/Databases/"+"sampleTest.db";
db = DatabaseFactory.open(db_url);
It through the DatabaseException error with message :"Invalid path name. Path does not contains a proper root list. See FileSystemRegistry class for details."
Please help me !! What is going Wrong here.
First set Sdcard in Simulator:
Go Simulate-->change sdcard-->Add directories(sdcard folder path)
Write Query like this:
public Vector GetData()
{
Cursor c = null;
Statement st = null;
Vector tableVector=new Vector();
try
{
URI myURI = URI.create("/SDCard/" + "abc.db");
d = DatabaseFactory.open(myURI);
st= d.createStatement("Query"););
st.prepare();
c = st.getCursor();
Row r;
while(c.next())
{
r = c.getRow();
tableVector.addElement(r.getString(0));
}
}
catch ( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}
finally
{
try {
c.close();
} catch (DatabaseException e) {
e.printStackTrace();
}
try {
st.close();
} catch (DatabaseException e) {
e.printStackTrace();
}
try {
d.close();
} catch (DatabaseIOException e) {
e.printStackTrace();
}
}
return tableVector;
}

Resources