Skip to content

Commit

Permalink
corretta chiusura finestre dettagli alla chiusura della finestra prin…
Browse files Browse the repository at this point in the history
…cipale
  • Loading branch information
Davide Valsecchi committed Jul 14, 2012
1 parent 06149e8 commit 7272d26
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 60 deletions.
179 changes: 125 additions & 54 deletions QuickAgenda/src/it/valsecchi/quickagenda/windows/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class MainWindow extends JFrame {
private CostumersManagerWindow costsWindow;
private WorksManagerWindow worksWindow;
private AddSessionWindow addSessionWindow;
private SessionDetailWindow sessionDetailWindow;
private List<SessionDetailWindow> sessionDetailWindowList = new ArrayList<>();
private OptionsWindow optionsWindow;
private JPanel panel;
private JTable table;
Expand Down Expand Up @@ -124,45 +124,111 @@ private void initComponent() {
btnRimuovi = new JButton("Rimuovi Sessioni selezionate");
btnRimuovi.addActionListener(new BtnRimuoviActionListener());
btnRimuovi.setFont(new Font("Tahoma", Font.PLAIN, 14));
btnRimuovi.setIcon(new ImageIcon(MainWindow.class.getResource("/ico_small/deletered.png")));
btnRimuovi.setIcon(new ImageIcon(MainWindow.class
.getResource("/ico_small/deletered.png")));
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(toolBar, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(separator, GroupLayout.PREFERRED_SIZE, 3, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(calendar, GroupLayout.PREFERRED_SIZE, 385, GroupLayout.PREFERRED_SIZE)
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
.addComponent(btnRimuovi, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnNewSession, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(panel, GroupLayout.DEFAULT_SIZE, 817, Short.MAX_VALUE)
.addContainerGap())
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(toolBar, GroupLayout.DEFAULT_SIZE, 540, Short.MAX_VALUE)
.addComponent(separator, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 540, Short.MAX_VALUE)
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(panel, GroupLayout.DEFAULT_SIZE, 502, Short.MAX_VALUE)
.addGap(3))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(calendar, GroupLayout.PREFERRED_SIZE, 339, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(btnNewSession)
.addGap(18)
.addComponent(btnRimuovi)))
.addGap(22)))
.addGap(10))
);
gl_contentPane
.setHorizontalGroup(gl_contentPane
.createParallelGroup(Alignment.LEADING)
.addGroup(
gl_contentPane
.createSequentialGroup()
.addComponent(toolBar,
GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
ComponentPlacement.RELATED)
.addComponent(separator,
GroupLayout.PREFERRED_SIZE, 3,
GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addGroup(
gl_contentPane
.createParallelGroup(
Alignment.LEADING)
.addComponent(
calendar,
GroupLayout.PREFERRED_SIZE,
385,
GroupLayout.PREFERRED_SIZE)
.addGroup(
gl_contentPane
.createParallelGroup(
Alignment.TRAILING,
false)
.addComponent(
btnRimuovi,
Alignment.LEADING,
GroupLayout.DEFAULT_SIZE,
GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(
btnNewSession,
Alignment.LEADING,
GroupLayout.DEFAULT_SIZE,
GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)))
.addPreferredGap(
ComponentPlacement.UNRELATED)
.addComponent(panel,
GroupLayout.DEFAULT_SIZE, 817,
Short.MAX_VALUE)
.addContainerGap()));
gl_contentPane
.setVerticalGroup(gl_contentPane
.createParallelGroup(Alignment.TRAILING)
.addGroup(
gl_contentPane
.createSequentialGroup()
.addGroup(
gl_contentPane
.createParallelGroup(
Alignment.LEADING)
.addComponent(
toolBar,
GroupLayout.DEFAULT_SIZE,
540,
Short.MAX_VALUE)
.addComponent(
separator,
Alignment.TRAILING,
GroupLayout.DEFAULT_SIZE,
540,
Short.MAX_VALUE)
.addGroup(
gl_contentPane
.createSequentialGroup()
.addContainerGap()
.addGroup(
gl_contentPane
.createParallelGroup(
Alignment.LEADING)
.addGroup(
gl_contentPane
.createSequentialGroup()
.addComponent(
panel,
GroupLayout.DEFAULT_SIZE,
502,
Short.MAX_VALUE)
.addGap(3))
.addGroup(
gl_contentPane
.createSequentialGroup()
.addComponent(
calendar,
GroupLayout.PREFERRED_SIZE,
339,
GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(
btnNewSession)
.addGap(18)
.addComponent(
btnRimuovi)))
.addGap(22)))
.addGap(10)));
panel.setLayout(new BorderLayout(0, 0));

table = new JTable(this.getTableModel(Calendar.getInstance()));
Expand Down Expand Up @@ -288,10 +354,12 @@ public void windowClosing(WindowEvent arg0) {
if (addSessionWindow != null) {
addSessionWindow.dispose();
}
if(sessionDetailWindow !=null){
sessionDetailWindow.dispose();
for (SessionDetailWindow s : sessionDetailWindowList) {
if (s != null) {
s.dispose();
}
}
if(optionsWindow != null){
if (optionsWindow != null) {
optionsWindow.dispose();
}
// controllo salvataggio
Expand Down Expand Up @@ -424,9 +492,11 @@ public void mouseClicked(MouseEvent arg) {
// si ricava l'id selezionato
String id = (String) table
.getValueAt(table.getSelectedRow(), 0);
//si apre la finestra dettagli sessione
sessionDetailWindow = new SessionDetailWindow(id, data);
// si apre la finestra dettagli sessione
SessionDetailWindow sessionDetailWindow = new SessionDetailWindow(
id, data);
sessionDetailWindow.setVisible(true);
sessionDetailWindowList.add(sessionDetailWindow);
}
}
}
Expand All @@ -439,33 +509,34 @@ public void actionPerformed(ActionEvent e) {

private class BtnRimuoviActionListener implements ActionListener {
public void actionPerformed(ActionEvent arg) {
//Si ricavano le sessioni selezionate
// Si ricavano le sessioni selezionate
int[] selected = table.getSelectedRows();
List<String> ids = new ArrayList<>();
for(int i :selected){
for (int i : selected) {
ids.add((String) table.getValueAt(i, 0));
}
//ora si rimuovono
for(String id :ids){
// ora si rimuovono
for (String id : ids) {
try {
data.removeSession(id);
} catch (IDNotFoundException e) {
//questa eccezione non dovrebbe accadere
// questa eccezione non dovrebbe accadere
Log.error("Sessione non trovata");
}
}
}
}

private class BtnInfoActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
//si apre la finestra info
// si apre la finestra info
new InfoWindow().setVisible(true);
}
}

private class BtnOpzioniActionListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
//si apre la finestra opzioni
// si apre la finestra opzioni
optionsWindow = new OptionsWindow(data);
optionsWindow.setVisible(true);
}
Expand All @@ -477,8 +548,8 @@ private class SessionTableModel extends AbstractTableModel {
// si recuperano le session
List<Session> sessions = new ArrayList<>();
// colonne
String[] columns = { "ID", "Nome Lavoro", "Azienda Cliente","Indirizzo Cliente",
"N° di ore", "Spesa", "Note" };
String[] columns = { "ID", "Nome Lavoro", "Azienda Cliente",
"Indirizzo Cliente", "N° di ore", "Spesa", "Note" };

public SessionTableModel(Calendar d) {
sessions = data.querySessionsByDate(d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void actionPerformed(ActionEvent arg0) {
confirmImage.setIcon(new ImageIcon(OpenDataWindow.class
.getResource("/ico_128/refresh.png")));
lblLog.setText("Caricamento in corso...");
timer1 = new Timer(500, new ActionListener() {
timer1 = new Timer(300, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
timer1.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class WorksManagerWindow extends JFrame {
private JLabel lblIstr;
private JButton btnRimuovi;
private JLabel label;
protected WorkDetailWindow workDetailWindow;
private List<WorkDetailWindow> workDetailWindowList = new ArrayList<>();

public WorksManagerWindow(DataManager _data, int _mode) {
setIconImage(Toolkit.getDefaultToolkit().getImage(
Expand Down Expand Up @@ -286,10 +286,12 @@ public void removeWorkSelectionListener(WorkSelectionListener listener) {
this.listeners.remove(listener);
}

/** Metodo che chiude la finestra dettagli cliente eventualmente aperta*/
/** Metodo che chiude le finestre dettagli cliente eventualmente aperte */
public void closeWorkDetailWindow() {
if (workDetailWindow != null) {
workDetailWindow.dispose();
for (WorkDetailWindow d : workDetailWindowList) {
if (d != null) {
d.dispose();
}
}
}

Expand Down Expand Up @@ -382,8 +384,9 @@ public void mouseClicked(MouseEvent arg) {
String id = (String) table
.getValueAt(table.getSelectedRow(), 0);
// si apre la finestra dettagli lavoro
workDetailWindow = new WorkDetailWindow(id, data);
WorkDetailWindow workDetailWindow = new WorkDetailWindow(id, data);
workDetailWindow.setVisible(true);
workDetailWindowList.add(workDetailWindow);
}
}
}
Expand Down

0 comments on commit 7272d26

Please sign in to comment.