/src/mpv5/ui/panels/ScheduleDayEventsPanel.java
Java | 227 lines | 176 code | 25 blank | 26 comment | 9 complexity | e252ac77cfb7e5c9d91b09f522eb34c5 MD5 | raw file
1/* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5 6/* 7 * SplashScreen.java 8 * 9 * Created on 30.03.2009, 21:55:52 10 */ 11package mpv5.ui.panels; 12 13import java.util.ArrayList; 14 15import java.util.Calendar; 16import java.util.Date; 17import javax.swing.JPanel; 18import mpv5.db.common.Context; 19import mpv5.db.common.DatabaseObject; 20import mpv5.db.common.NodataFoundException; 21import mpv5.db.common.QueryCriteria; 22import mpv5.db.objects.Schedule; 23import mpv5.db.objects.User; 24import mpv5.globals.Headers; 25import mpv5.logging.Log; 26import mpv5.ui.dialogs.ScheduleEvents; 27import mpv5.ui.panels.calendar.ScheduleCalendarDayChooser; 28import mpv5.utils.models.MPTableModel; 29import mpv5.utils.tables.TableFormat; 30 31/** 32 * 33 * 34 */ 35public class ScheduleDayEventsPanel extends JPanel { 36 37 private static final long serialVersionUID = 1L; 38 private static ScheduleDayEventsPanel icke; 39 40 public static ScheduleDayEventsPanel instanceOf() { 41 if (icke == null) { 42 icke = new ScheduleDayEventsPanel(); 43 } else { 44// icke.refresh(null); 45 } 46 return icke; 47 } 48 49 /** 50 * 51 * @param day 52 */ 53 private ScheduleDayEventsPanel() { 54 initComponents(); 55 } 56 57 /** This method is called from within the constructor to 58 * initialize the form. 59 * WARNING: Do NOT modify this code. The content of this method is 60 * always regenerated by the Form Editor. 61 */ 62 @SuppressWarnings("unchecked") 63 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 64 private void initComponents() { 65 66 jPanel1 = new javax.swing.JPanel(); 67 but4 = new javax.swing.JButton(); 68 jScrollPane1 = new javax.swing.JScrollPane(); 69 jTable1 = new javax.swing.JTable(); 70 but5 = new javax.swing.JButton(); 71 72 setName("Form"); // NOI18N 73 setLayout(new java.awt.BorderLayout()); 74 75 java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N 76 jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ScheduleDayEventsPanel.jPanel1.border.title_1"))); // NOI18N 77 jPanel1.setName("jPanel1"); // NOI18N 78 79 but4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/view_right.png"))); // NOI18N 80 but4.setText(bundle.getString("ScheduleDayEventsPanel.but4.text")); // NOI18N 81 but4.setToolTipText(bundle.getString("ScheduleDayEventsPanel.but4.toolTipText")); // NOI18N 82 but4.setContentAreaFilled(false); 83 but4.setFocusable(false); 84 but4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 85 but4.setName("but4"); // NOI18N 86 but4.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/xclock.png"))); // NOI18N 87 but4.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/view_right.png"))); // NOI18N 88 but4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); 89 but4.addActionListener(new java.awt.event.ActionListener() { 90 public void actionPerformed(java.awt.event.ActionEvent evt) { 91 but4ActionPerformed(evt); 92 } 93 }); 94 95 jScrollPane1.setName("jScrollPane1"); // NOI18N 96 97 jTable1.setModel(new javax.swing.table.DefaultTableModel( 98 new Object [][] { 99 {}, 100 {}, 101 {}, 102 {} 103 }, 104 new String [] { 105 106 } 107 )); 108 jTable1.setName("jTable1"); // NOI18N 109 jScrollPane1.setViewportView(jTable1); 110 111 but5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/edittrash.png"))); // NOI18N 112 but5.setText(bundle.getString("ScheduleDayEventsPanel.but5.text")); // NOI18N 113 but5.setToolTipText(bundle.getString("ScheduleDayEventsPanel.but5.toolTipText")); // NOI18N 114 but5.setContentAreaFilled(false); 115 but5.setFocusable(false); 116 but5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 117 but5.setName("but5"); // NOI18N 118 but5.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/xclock.png"))); // NOI18N 119 but5.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/bright_edittrash.png"))); // NOI18N 120 but5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); 121 but5.addActionListener(new java.awt.event.ActionListener() { 122 public void actionPerformed(java.awt.event.ActionEvent evt) { 123 but5ActionPerformed(evt); 124 } 125 }); 126 127 javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 128 jPanel1.setLayout(jPanel1Layout); 129 jPanel1Layout.setHorizontalGroup( 130 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 131 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() 132 .addGap(19, 19, 19) 133 .addComponent(but4, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE) 134 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 109, Short.MAX_VALUE) 135 .addComponent(but5, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE) 136 .addGap(19, 19, 19)) 137 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE) 138 ); 139 jPanel1Layout.setVerticalGroup( 140 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 141 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() 142 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE) 143 .addGap(18, 18, 18) 144 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 145 .addComponent(but5, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE) 146 .addComponent(but4, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)) 147 .addGap(15, 15, 15)) 148 ); 149 150 add(jPanel1, java.awt.BorderLayout.LINE_START); 151 }// </editor-fold>//GEN-END:initComponents 152 153 private void but4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_but4ActionPerformed 154 Log.Debug(this, 155 "adding new schedule from Homescreen"); 156 ScheduleEvents.instanceOf(); 157}//GEN-LAST:event_but4ActionPerformed 158 159 private void but5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_but5ActionPerformed 160 Schedule d = (Schedule) jTable1.getModel().getValueAt(jTable1.convertRowIndexToModel(jTable1.getSelectedRow()), 0); 161 Log.Debug(this, 162 "deleting the marked entry from Homescreen (and database :-) )"); 163 Calendar cal = Calendar.getInstance(); 164 cal.setTime(d.__getStartdate()); 165 Date oldDate = cal.getTime(); 166 ScheduleCalendarDayChooser.instanceOf().refreshDayPanels(oldDate, d, Boolean.FALSE); 167 d.delete(); 168 refresh(ScheduleCalendarDayChooser.instanceOf().getScheduledEvents(d.__getStartdate())); 169}//GEN-LAST:event_but5ActionPerformed 170 171 // Variables declaration - do not modify//GEN-BEGIN:variables 172 private javax.swing.JButton but4; 173 private javax.swing.JButton but5; 174 private javax.swing.JPanel jPanel1; 175 private javax.swing.JScrollPane jScrollPane1; 176 private javax.swing.JTable jTable1; 177 // End of variables declaration//GEN-END:variables 178 179 private void refresh(ArrayList<Schedule> list) { 180 Log.Debug(this, "Refreshing SDEPanel ..."); 181 if (list != null) { 182 Object[][] data = new Object[list.size()][4]; 183 184 for (int i = 0; i < list.size(); i++) { 185 Schedule schedule = list.get(i); 186 data[i][0] = schedule; 187 data[i][1] = schedule.__getCname(); 188 QueryCriteria qc = new QueryCriteria("USERSIDS", User.getCurrentUser().getID()); 189 qc.addAndCondition("IDS", schedule.__getEventtype()); 190 Log.Debug(this, "EventID: " + schedule.__getEventtype()); 191 ArrayList<DatabaseObject> SType; 192 try { 193 SType = DatabaseObject.getObjects(Context.getScheduleTypes(), 194 qc); 195 data[i][3] = SType.get(0).__getCname(); 196 } catch (NodataFoundException ex) { 197 Log.Debug(this, ex); 198 } 199 200 } 201 MPTableModel m = new MPTableModel(data, Headers.SCHEDULE_PANEL); 202 jTable1.setModel(m); 203 TableFormat.stripColumn(jTable1, 0); 204 TableFormat.stripColumn(jTable1, 2); 205 TableFormat.format(jTable1, 0, 140); 206 if (list.isEmpty()) { 207 but5.setEnabled(false); 208 } else { 209 but5.setEnabled(true); 210 } 211 } else { 212 Object[][] data = new Object[0][4]; 213 MPTableModel m = new MPTableModel(data, Headers.SCHEDULE_PANEL); 214 jTable1.setModel(m); 215 TableFormat.stripColumn(jTable1, 0); 216 TableFormat.stripColumn(jTable1, 2); 217 TableFormat.format(jTable1, 0, 140); 218 Log.Debug(this, "Delete off"); 219 but5.setEnabled(false); 220 } 221 this.validate(); 222 } 223 224 public void setDayEvents(ArrayList<Schedule> list) { 225 refresh(list); 226 } 227}