View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, see
18   * <http://www.gnu.org/licenses/>.
19   */
20  package org.jumpmind.symmetric.admin.table;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import javax.swing.table.TableCellEditor;
26  
27  import org.jumpmind.symmetric.admin.SymmetricDatabase;
28  import org.jumpmind.symmetric.model.Channel;
29  import org.jumpmind.symmetric.model.NodeChannel;
30  
31  public class ChannelTableModel extends ModelObjectTableModel<Channel> {
32  
33      private static final long serialVersionUID = -5154253989768004844L;
34  
35      transient List<Channel> dirtyList = new ArrayList<Channel>();
36  
37      @Override
38      public String getColumnName(int index) {
39          switch (index) {
40          case 0:
41              return "Channel Name";
42          case 1:
43              return "Process Order";
44          case 2:
45              return "Max Events Per Batch";
46          case 3:
47              return "Max Batches Per Sync";
48          case 4:
49              return "Enabled";
50          }
51  
52          return "";
53      }
54  
55      @SuppressWarnings("unchecked")
56      @Override
57      public Class getColumnClass(int column) {
58          switch (column) {
59          case 0:
60              return String.class;
61          case 1:
62              return Integer.class;
63          case 2:
64              return Integer.class;
65          case 3:
66              return Integer.class;
67          case 4:
68              return Boolean.class;
69          }
70  
71          return null;
72      }
73  
74      @Override
75      public Object getValueAt(int row, int column) {
76          List<Channel> rows = getRows();
77          Channel object = rows.get(row);
78          if (object != null) {
79              switch (column) {
80              case 0:
81                  return object.getId();
82              case 1:
83                  return object.getProcessingOrder();
84              case 2:
85                  return object.getMaxBatchSize();
86              case 3:
87                  return object.getMaxBatchToSend();
88              case 4:
89                  return object.isEnabled();
90              }
91          }
92  
93          return null;
94      }
95  
96      @Override
97      void setColumnValue(int index, Channel object, Object value) {
98          if (object != null) {
99  
100             this.dirtyList.add(object);
101 
102             switch (index) {
103             case 0:
104                 object.setId((String) value);
105                 break;
106             case 1:
107                 object.setProcessingOrder((Integer) value);
108                 break;
109             case 2:
110                 object.setMaxBatchSize((Integer) value);
111                 break;
112             case 3:
113                 object.setMaxBatchToSend((Integer) value);
114                 break;
115             case 4:
116                 object.setEnabled((Boolean) value);
117                 break;
118             }
119         }
120 
121     }
122 
123     @Override
124     public TableCellEditor getCellEditorForColumn(int column) {
125         switch (column) {
126         case 0:
127         case 1:
128         case 2:
129         case 3:
130         case 4:
131         }
132 
133         return null;
134     }
135 
136     @Override
137     int getNumberOfColumns() {
138         return 5;
139     }
140 
141     @Override
142     List<Channel> getRows() {
143         if (list == null) {
144             list = new ArrayList<Channel>();
145         }
146         return list;
147     }
148 
149     @Override
150     public void setup(SymmetricDatabase db) {
151         List<NodeChannel> nc = db.getChannels();
152         list = new ArrayList<Channel>(nc.size());
153         for (NodeChannel nodeChannel : nc) {
154             list.add(nodeChannel);
155         }
156     }
157 
158     @Override
159     public void save() throws ValidationException {
160         System.out.println("saved " + dirtyList.size() + " objects ");
161         if (dirtyList.size() > 0) {
162             dirtyList.clear();
163             throw new ValidationException();
164         }
165         dirtyList.clear();
166     }
167 
168     @Override
169     Channel newRow() {
170         Channel newChannel = new Channel();
171         this.list.add(newChannel);
172         return newChannel;
173     }
174 
175 }