Skip to content

Commit

Permalink
user selects the db properties file when MIPMap starts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostis-K committed Apr 30, 2020
1 parent 7d8eaf9 commit 62a1afd
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 11 deletions.
1 change: 1 addition & 0 deletions .~lock.MIPMap Report.docx#
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,kostis,kostis-lab-pc,14.04.2020 17:40,file:///home/kostis/.config/libreoffice/4;
1 change: 1 addition & 0 deletions .~lock.MIPMap Tutorial.docx#
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,kostis,kostis-lab-pc,29.04.2020 18:08,file:///home/kostis/.config/libreoffice/4;
4 changes: 4 additions & 0 deletions MIPMapGUI/mipmapgui/src/it/unibas/spicygui/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,7 @@ SOLUTION =Solution #
MESSAGE_BEST_MAPPINGS =Following is a list of the solutions that have been found.\nSelect the ones you want to view
MESSAGE_NO_BEST_MAPPINGS =No solutions were found. Add more lines and run the search again
MESSAGE_RANKED_TRANSFORMATIONS =Following is a ranked list of transformations for this mapping task.\nSelect the ones you want to view
getPropertiesFilePanel1.AccessibleContext.accessibleName=
getPropertiesFileJFrame.jTextField1.text=Select the database properties file:
getPropertiesFileJFrame.jLabel1.text=Please select the database properties file:
DBPropertiesChooserJFrame.jLabel1.text=Please provide the db properties file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[500, 450]"/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="78" max="32767" attributes="0"/>
<Component id="jFileChooser1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="66" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="92" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="68" max="32767" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="jFileChooser1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="66" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JFileChooser" name="jFileChooser1">
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jFileChooser1ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="it/unibas/spicygui/Bundle.properties" key="DBPropertiesChooserJFrame.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package it.unibas.spicygui;

import it.unibas.spicygui.vista.Vista;
import java.io.File;
import java.sql.Timestamp;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.openide.util.Lookup;
import org.openide.windows.WindowManager;

/**
*
* @author kostis
*/
public class DBPropertiesChooserJFrame extends javax.swing.JFrame {
private Vista vista;
private String dbPropertiesFile;
private Installer installer;
private int returnVal;
/**
* Creates new form DBPropertiesChooserJFrame
*/
public DBPropertiesChooserJFrame(Installer inst) {
System.out.println("~~~ This is the DBPropertiesChooserJFrame constructor ~~~");
executeInjection();
initComponents();
this.installer = inst;
setFileChooserProperties();
System.out.println("~~~ We done initializing and preparing swing components!! ~~~");
}

//kostisk
public void setFileChooserProperties() {
this.jFileChooser1.resetChoosableFileFilters();
this.jFileChooser1.setDialogType(JFileChooser.SAVE_DIALOG);
this.jFileChooser1.setFileFilter(new FileNameExtensionFilter("PROPERTIES FILE", "properties"));
this.jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
//return fileChooser;
}

private void executeInjection() {
/*if (this.modello == null) {
this.modello = Lookup.getDefault().lookup(Modello.class);
}*/
if (this.vista == null) {
this.vista = Lookup.getDefault().lookup(Vista.class);
}
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

jFileChooser1 = new javax.swing.JFileChooser();
jLabel1 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(500, 450));

jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jFileChooser1ActionPerformed(evt);
}
});

org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(DBPropertiesChooserJFrame.class, "DBPropertiesChooserJFrame.jLabel1.text")); // NOI18N

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(78, Short.MAX_VALUE)
.addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(66, 66, 66))
.addGroup(layout.createSequentialGroup()
.addGap(92, 92, 92)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(68, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(66, 66, 66))
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser1ActionPerformed
// TODO add your handling code here:
//this.returnVal = jFileChooser1.showOpenDialog(WindowManager.getDefault().getMainWindow());

if (returnVal == jFileChooser1.APPROVE_OPTION) {
File file = jFileChooser1.getSelectedFile();
this.dbPropertiesFile=file.getAbsolutePath();
this.installer.setPostgresDbConfFile(this.dbPropertiesFile);
this.installer.configureDatabaseProperties();
this.installer.createDB();
java.util.Date date2= new java.util.Date();
System.out.println("~~~ MIPMap done loading: "+new Timestamp(date2.getTime())+" ~~~");
this.dispose();
}
}//GEN-LAST:event_jFileChooser1ActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Metal".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(DBPropertiesChooserJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(DBPropertiesChooserJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(DBPropertiesChooserJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(DBPropertiesChooserJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
//new DBPropertiesChooserJFrame().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JLabel jLabel1;
// End of variables declaration//GEN-END:variables
}
57 changes: 47 additions & 10 deletions MIPMapGUI/mipmapgui/src/it/unibas/spicygui/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import it.unibas.spicygui.commons.Modello;
import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;
import com.jgoodies.looks.plastic.theme.LightGray;

import it.unibas.spicy.persistence.DAOException;
import it.unibas.spicy.persistence.DAOHandleDB;
import it.unibas.spicy.utility.SpicyEngineConstants;
import it.unibas.spicygui.commons.LastActionBean;
import it.unibas.spicygui.controllo.Scenario;
import it.unibas.spicygui.controllo.Scenarios;
import it.unibas.spicygui.vista.Vista;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.TrayIcon;
Expand All @@ -51,6 +53,7 @@
import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.apache.log4j.PatternLayout;
Expand All @@ -76,10 +79,11 @@
public class Installer extends ModuleInstall {

public static final String LOG4J_CONFIGURATION_FILE = "/conf/spicyGUI-log4j.properties";
public static final String POSTGRESDB_CONFIGURATION_FILE = "postgresdb.properties";
public static String postgres_db_conf_file; //= "postgresdb.properties"//kostisk: going from constant to variable...
// private ActionExitApplication actionExitApplication = new ActionExitApplication();
private boolean close;


@Override
public void close() {

Expand Down Expand Up @@ -190,20 +194,28 @@ public void restored() {
configureLog4j();
configuraObservable();
configureFavoriteWindow();
//giannisk
configureDatabaseProperties();
createDB();
java.util.Date date2= new java.util.Date();
System.out.println("MIPMap loaded: "+new Timestamp(date2.getTime()));
//kostisk
new DBPropertiesChooserJFrame(this).setVisible(true);
//this.postgres_db_conf_file=adbpc.getConfigurationFile();
//giannisk commented by kostisk, they run once the user selects the properties db file in ActionDBPropertiesChooser
//configureDatabaseProperties();
//createDB();
//java.util.Date date2= new java.util.Date();
//System.out.println("MIPMap loaded: "+new Timestamp(date2.getTime()));
}

private void createDB(){
public void setPostgresDbConfFile(String fullPathFilename)
{ this.postgres_db_conf_file = fullPathFilename;}

public void createDB(){
DAOHandleDB daoCreateDB = new DAOHandleDB();
try {
daoCreateDB.createNewDatabase();
} catch (DAOException ex) {
System.err.println("*** Something went wrong while creating the auxiliary db for the mapping-tasks I guess..? ***");
Exceptions.printStackTrace(ex);
}
System.out.println("*** DB created ***");
}

private File getClassLocation() {
Expand Down Expand Up @@ -259,7 +271,7 @@ private File getClassLocation() {

//giannisk
//reads the properties file with database configuration and sets the appropriate variables
private void configureDatabaseProperties() {
public void configureDatabaseProperties() {
Properties dbproperties = new Properties();
//TO RUN AS AN APPLICATION:
//uncomment the following block and the "else" block
Expand All @@ -274,7 +286,15 @@ private void configureDatabaseProperties() {
try {
stream = new FileInputStream(propertyFile);*/
////
InputStream stream = Installer.class.getResourceAsStream("/conf/"+POSTGRESDB_CONFIGURATION_FILE); //comment for application
//InputStream stream = Installer.class.getResourceAsStream(postgres_db_conf_file); //comment for application
System.out.println("DB Properties file is "+this.postgres_db_conf_file) ;
InputStream stream=null;//changes by kostisk
try {
stream = new FileInputStream(new File (postgres_db_conf_file));
} catch (FileNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
//if (stream == null){System.out.println("---> Why stream is null here (1)...?? <---");}
try { //comment for application
dbproperties.load(stream);
SpicyEngineConstants.setDatabaseParameters(dbproperties.getProperty("driver"),dbproperties.getProperty("uri"),
Expand All @@ -284,6 +304,7 @@ private void configureDatabaseProperties() {
Logger.getLogger(Installer.class.getName()).severe("Unable to load database configuration file");
} finally {
try {
//if (stream == null){System.out.println("---> Why stream is null here (2)...?? <---");}
stream.close();
} catch (IOException ex) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(NbBundle.getMessage(Costanti.class, Costanti.NEW_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE));
Expand Down Expand Up @@ -365,13 +386,29 @@ private Properties caricaProperties() {
}

private void setLookAndFeel() {
try {
/*try {
if ((Utilities.getOperatingSystem() & Utilities.OS_LINUX) != 0) {
Plastic3DLookAndFeel.setPlasticTheme(new LightGray());
UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
}
} catch (UnsupportedLookAndFeelException ex) {
Exceptions.printStackTrace(ex);
}*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Metal".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(DBPropertiesChooserJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(DBPropertiesChooserJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(DBPropertiesChooserJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(DBPropertiesChooserJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public ActionFileChooserSchema() {
super("...");
}

@Override
public void actionPerformed(ActionEvent e) {
executeInjection();

Expand Down
Loading

0 comments on commit 62a1afd

Please sign in to comment.