001/**
002 * Copyright (c) 2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: crawl $'
006 * '$Date: 2010-06-03 16:45:10 -0700 (Thu, 03 Jun 2010) $' 
007 * '$Revision: 24730 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029package org.kepler.workflowscheduler.gui;
030
031import javax.swing.table.AbstractTableModel;
032
033import org.kepler.objectmanager.repository.Repository;
034
035/**
036 * Data model for display the schedule table
037 * @author tao
038 *
039 */
040public class ScheduleTableModel extends AbstractTableModel
041{
042  private static final String BLANK = "";
043  private static final int STATUSCOL = 0;
044  private static final int STARTTIMECOL =1;
045  private static final int ENDTIMECOL =2;
046  private static final int INTERVALCOL = 3;
047  private static final int RUNENGINECOL = 4;
048  private static final int DESTINATIONCOL = 5;
049  
050  private static final String[] COLUMNNAMES = {"Status", "Start Time",
051                      "End Time", "Interval", "Run Engine", "Destination" }; 
052  public static final String ENABLED = "Enabled";
053  public static final String DISABLED = "Disabled";
054  private Schedule[] scheduleList = null;
055 
056  /**
057   * Constructor
058   * @param scheduleList the array of the schedules
059   */
060  public ScheduleTableModel(Schedule[] scheduleList)
061  {
062    this.scheduleList = scheduleList;
063  }
064  
065  /**
066   * Get the number of row 
067   */
068  public int getRowCount()
069  {
070    if(scheduleList == null)
071    {
072      return 0;
073    }
074    else
075    {
076      return scheduleList.length;
077    }
078  }
079  
080  /**
081   * Get the number of column
082   */
083  public int getColumnCount()
084  {
085    return COLUMNNAMES.length;
086  }
087  
088  /**
089   * Get the value of the cell at row and column.
090   */
091  public Object getValueAt(int row, int column)
092  {
093    String returnValue = null;   
094    if(scheduleList != null)
095    {
096      Schedule schedule = scheduleList[row];
097      if(schedule == null)
098      {
099        returnValue = BLANK;
100      }
101      else
102      {
103       
104        switch(column)
105        {
106          case STATUSCOL:
107                  boolean enabled = schedule.isEnabled();
108                  if(enabled)
109                  {
110                    returnValue = ENABLED;
111                  }
112                  else
113                  {
114                    returnValue = DISABLED;
115                  }
116                  break;
117          case STARTTIMECOL:
118                 returnValue= schedule.getStartTimeLabel();
119                 if(returnValue == null)
120                 {
121                   returnValue = BLANK;
122                 }
123                 else
124                 {
125                   returnValue = returnValue;
126                 }
127                 break;
128          case ENDTIMECOL:
129                  returnValue = schedule.getEndTimeLabel();
130                  if(returnValue == null)
131                  {
132                    returnValue = BLANK;
133                  }
134                  else
135                  {
136                    returnValue = returnValue;
137                  }
138                  break;
139          case INTERVALCOL:
140                 int interval =schedule.getInterval();
141                 String unit = schedule.getIntervalUnit();
142                 returnValue =interval+" "+unit;
143                 
144                 break;
145          
146          case RUNENGINECOL:
147                 WorkflowRunEngine engine = schedule.getWorkflowRunEngine();
148                 if(engine == null)
149                 {
150                   returnValue = BLANK;
151                 }
152                 else
153                 {
154                   returnValue = engine.getName();
155                   if(returnValue == null)
156                   {
157                     returnValue = BLANK;
158                   }
159                 }
160                 break;
161          case DESTINATIONCOL:
162                 Repository repository = schedule.getWorkflowRunDestination();
163                 if(repository == null)
164                 {
165                   returnValue = BLANK;
166                 }
167                 else
168                 {
169                   returnValue = repository.getName();
170                   if(returnValue == null)
171                   {
172                     returnValue = BLANK;
173                   }
174                 }
175                 break;
176          default:
177                 returnValue =BLANK;
178                 break;
179         
180        }
181      }
182    }
183    return returnValue;
184  }
185  
186  /**
187   * Get the column name
188   */
189  public String getColumnName(int columnIndex)
190  {
191    return COLUMNNAMES[columnIndex];
192  }
193  
194  
195
196
197}