KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > search > VSchedule


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps.search;
15
16 import java.awt.*;
17 import javax.swing.*;
18 import java.util.*;
19 import java.sql.*;
20
21 import org.compiere.util.*;
22 import org.compiere.model.*;
23
24 /**
25  * Visual and Control Part of Schedule.
26  * Contains Time and Schedule Panels
27  *
28  * @author Jorg Janke
29  * @version $Id: VSchedule.java,v 1.7 2003/02/25 05:48:45 jjanke Exp $
30  */

31 public class VSchedule extends JPanel
32 {
33     /**
34      * Constructor
35      * @param is InfoSchedule for call back
36      * @param type Type of schedule TYPE_...
37      */

38     public VSchedule (InfoSchedule is, int type)
39     {
40         m_type = type;
41         m_model = new MSchedule (Env.getCtx());
42         schedulePanel.setType (m_type);
43         schedulePanel.setTimePanel (timePanel);
44         schedulePanel.setInfoSchedule (is); // for callback
45
try
46         {
47             jbInit();
48         }
49         catch(Exception JavaDoc e)
50         {
51             Log.error("VSchedule", e);
52         }
53     } // VSchedule
54

55     /** Day Display */
56     static public final int TYPE_DAY = Calendar.DAY_OF_MONTH;
57     /** Week Display */
58     static public final int TYPE_WEEK = Calendar.WEEK_OF_YEAR;
59     /** Month Display */
60     static public final int TYPE_MONTH = Calendar.MONTH;
61
62     /** Type */
63     private int m_type = TYPE_DAY;
64     /** Model */
65     private MSchedule m_model = null;
66     /** Start Date */
67     private Timestamp m_startDate;
68     /** End Date */
69     private Timestamp m_endDate;
70
71
72     private BorderLayout mainLayout = new BorderLayout();
73     private VScheduleTimePanel timePanel = new VScheduleTimePanel();
74     private VSchedulePanel schedulePanel = new VSchedulePanel();
75     private JScrollPane schedulePane = new JScrollPane();
76
77     /**
78      * Static init
79      * <pre>
80      * timePanel (West)
81      * schedlePanel (in schedulePane - Center)
82      * </pre>
83      * @throws Exception
84      */

85     private void jbInit() throws Exception JavaDoc
86     {
87         this.setLayout(mainLayout);
88         this.add(timePanel, BorderLayout.WEST);
89         //
90
// schedulePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
91
schedulePane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
92         schedulePane.getViewport().add(schedulePanel, null);
93         schedulePane.setPreferredSize(new Dimension(200, 200));
94         schedulePane.setBorder(null);
95         this.add(schedulePane, BorderLayout.CENTER);
96     } // jbInit
97

98     /**
99      * Recreate View
100      * @param S_Resource_ID Resource
101      * @param date Date
102      */

103     public void recreate (int S_Resource_ID, Timestamp date)
104     {
105         // Calculate Start Day
106
GregorianCalendar cal = new GregorianCalendar();
107         cal.setTime(date);
108         cal.set(Calendar.HOUR, 0);
109         cal.set(Calendar.MINUTE, 0);
110         cal.set(Calendar.SECOND, 0);
111         cal.set(Calendar.MILLISECOND, 0);
112         if (m_type == TYPE_WEEK)
113             cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
114         else if (m_type == TYPE_MONTH)
115             cal.set(Calendar.DAY_OF_MONTH, 1);
116         m_startDate = new Timestamp(cal.getTimeInMillis());
117         // Calculate End Date
118
cal.add(m_type, 1);
119         m_endDate = new Timestamp (cal.getTimeInMillis());
120         //
121
Log.trace(Log.l3_Util, "VSchedule.recreate (" + m_type + ") Resource_ID=" + S_Resource_ID, m_startDate + "->" + m_endDate);
122         // Create Slots
123
MAssignmentSlot[] mas = m_model.getAssignmentSlots (S_Resource_ID, m_startDate, m_endDate, null, true);
124         MAssignmentSlot[] mts = m_model.getDayTimeSlots ();
125         // Set Panels
126
timePanel.setTimeSlots(mts);
127         schedulePanel.setAssignmentSlots(mas, S_Resource_ID, m_startDate, m_endDate);
128         // Set Height
129
schedulePanel.setHeight(timePanel.getPreferredSize().height);
130     // repaint();
131
} // recreate
132

133     /**
134      * Enable/disable to Create New Assignments
135      * @param createNew if true, allows to create new Assignments
136      */

137     public void setCreateNew (boolean createNew)
138     {
139         schedulePanel.setCreateNew(createNew);
140     } // setCreateNew
141

142     /**
143      * Dispose
144      */

145     public void dispose()
146     {
147         m_model = null;
148         timePanel = null;
149         if (schedulePanel != null)
150             schedulePanel.dispose();
151         schedulePanel = null;
152         this.removeAll();
153     } // dispose
154

155     /**
156      * Get Start Date
157      * @return start date
158      */

159     public Timestamp getStartDate()
160     {
161         return m_startDate;
162     } // getStartDate
163

164 } // VSchedule
165
Popular Tags