Normand Briere
2018-07-07 e416acb9b012b17d1efe49ad2199ea7132d874d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package timeflow.app.ui;
 
import timeflow.data.db.*;
import timeflow.model.*;
import timeflow.views.*;
 
import javax.swing.*;
import javax.swing.table.*;
 
import java.awt.*;
import java.util.*;
 
public class MassDeletePanel extends ModelPanel
{
   TableView table;
   ActList keepers;
   
   public MassDeletePanel(TFModel model, ActList keepers, String title)
   {
       super(model);
       this.keepers=keepers;
       setLayout(new BorderLayout());
       
       JPanel top=new JPanel();
       top.setLayout(new GridLayout(4,1));
       top.add(new JPanel());
       top.add(new JLabel(title));
       int n=keepers.size();
       String message=null;
       if (n>1)
           message="These are the "+n+" items that will remain.";
       else if (n==1)
           message="This in the only item that will remain.";
       else 
           message="No items will remain!";
       
       JLabel instructions=new JLabel(message);
       top.add(instructions);
       top.add(new JPanel());
       add(top, BorderLayout.NORTH);
       
       table=new TableView(model);
       model.removeListener(table);
       add(table, BorderLayout.CENTER);
       table.setEditable(false);
       table.setActs(keepers);
   }
   
   public void applyAction()
   {
       ActDB db=getModel().getDB();
       HashSet<Act> keepSet=new HashSet<Act>();
       keepSet.addAll(keepers);
 
       for (Act a: db.all())
           if (!keepSet.contains(a))
               db.delete(a);
       
       // we assume the caller will decide what event to fire.
   }
   
   public void detachFromModel()
   {
       TFModel model=getModel();
       model.removeListener(table);
       model.removeListener(this);
   }
   
   public Dimension getPreferredSize()
   {
       Dimension d=super.getPreferredSize();
       return new Dimension(Math.max(700, d.width), 250);
   }
 
   @Override
   public void note(TFEvent e) {
       // TODO Auto-generated method stub
       
   }
}