1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
1 |
/*
|
2 |
GanttProject is an opensource project management tool.
|
|
3 |
Copyright (C) 2011 GanttProject team
|
|
4 |
||
5 |
This program is free software; you can redistribute it and/or
|
|
6 |
modify it under the terms of the GNU General Public License
|
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
7 |
as published by the Free Software Foundation; either version 3
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
8 |
of the License, or (at your option) any later version.
|
9 |
||
10 |
This program is distributed in the hope that it will be useful,
|
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
GNU General Public License for more details.
|
|
14 |
||
15 |
You should have received a copy of the GNU General Public License
|
|
16 |
along with this program; if not, write to the Free Software
|
|
17 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
18 |
*/
|
|
19 |
package net.sourceforge.ganttproject.gui; |
|
20 |
||
21 |
import java.awt.BorderLayout; |
|
22 |
import java.awt.Color; |
|
23 |
import java.awt.Dimension; |
|
24 |
import java.awt.event.ActionEvent; |
|
25 |
import java.awt.event.ActionListener; |
|
26 |
import java.awt.event.FocusAdapter; |
|
27 |
import java.awt.event.FocusEvent; |
|
28 |
import java.awt.event.FocusListener; |
|
29 |
import java.util.Calendar; |
|
30 |
||
31 |
import javax.swing.AbstractAction; |
|
32 |
import javax.swing.BorderFactory; |
|
33 |
import javax.swing.Box; |
|
34 |
import javax.swing.Icon; |
|
35 |
import javax.swing.ImageIcon; |
|
36 |
import javax.swing.JButton; |
|
37 |
import javax.swing.JCheckBox; |
|
38 |
import javax.swing.JColorChooser; |
|
39 |
import javax.swing.JComboBox; |
|
40 |
import javax.swing.JComponent; |
|
41 |
import javax.swing.JDialog; |
|
42 |
import javax.swing.JLabel; |
|
43 |
import javax.swing.JPanel; |
|
44 |
import javax.swing.JScrollPane; |
|
45 |
import javax.swing.JSpinner; |
|
46 |
import javax.swing.JTabbedPane; |
|
47 |
import javax.swing.JTextArea; |
|
48 |
import javax.swing.JTextField; |
|
49 |
import javax.swing.SpinnerNumberModel; |
|
50 |
import javax.swing.SpringLayout; |
|
51 |
import javax.swing.UIManager; |
|
52 |
import javax.swing.event.ChangeEvent; |
|
53 |
import javax.swing.event.ChangeListener; |
|
54 |
||
55 |
import net.sourceforge.ganttproject.GanttCalendar; |
|
56 |
import net.sourceforge.ganttproject.GanttGraphicArea; |
|
57 |
import net.sourceforge.ganttproject.GanttProject; |
|
58 |
import net.sourceforge.ganttproject.GanttTask; |
|
59 |
import net.sourceforge.ganttproject.IGanttProject; |
|
60 |
import net.sourceforge.ganttproject.gui.options.SpringUtilities; |
|
61 |
import net.sourceforge.ganttproject.gui.taskproperties.CustomColumnsPanel; |
|
62 |
import net.sourceforge.ganttproject.gui.taskproperties.TaskAllocationsPanel; |
|
63 |
import net.sourceforge.ganttproject.gui.taskproperties.TaskDependenciesPanel; |
|
64 |
import net.sourceforge.ganttproject.language.GanttLanguage; |
|
65 |
import net.sourceforge.ganttproject.resource.HumanResourceManager; |
|
66 |
import net.sourceforge.ganttproject.roles.RoleManager; |
|
67 |
import net.sourceforge.ganttproject.shape.JPaintCombo; |
|
68 |
import net.sourceforge.ganttproject.shape.ShapeConstants; |
|
69 |
import net.sourceforge.ganttproject.shape.ShapePaint; |
|
70 |
import net.sourceforge.ganttproject.task.Task; |
|
71 |
import net.sourceforge.ganttproject.task.TaskContainmentHierarchyFacade; |
|
72 |
import net.sourceforge.ganttproject.task.TaskImpl; |
|
73 |
import net.sourceforge.ganttproject.task.TaskManager; |
|
74 |
import net.sourceforge.ganttproject.task.TaskMutator; |
|
75 |
import net.sourceforge.ganttproject.util.BrowserControl; |
|
76 |
import net.sourceforge.ganttproject.util.collect.Pair; |
|
77 |
||
78 |
import org.jdesktop.swing.JXDatePicker; |
|
79 |
||
80 |
/**
|
|
81 |
* Real panel for editing task properties
|
|
82 |
*/
|
|
83 |
public class GanttTaskPropertiesBean extends JPanel { |
|
84 |
||
85 |
private static final JColorChooser colorChooser = new JColorChooser(); |
|
86 |
||
87 |
private JXDatePicker myStartDatePicker; |
|
88 |
private JXDatePicker myEndDatePicker; |
|
89 |
private JXDatePicker myThirdDatePicker; |
|
90 |
||
91 |
protected GanttTask[] selectedTasks; |
|
92 |
||
93 |
private static final GanttLanguage language = GanttLanguage.getInstance(); |
|
94 |
||
95 |
private GanttCalendar myStart; |
|
96 |
||
97 |
private GanttCalendar myEnd; |
|
98 |
||
99 |
private GanttCalendar myThird; |
|
100 |
||
101 |
private JTabbedPane tabbedPane; // TabbedPane that includes the following four items |
|
102 |
||
103 |
private JPanel generalPanel; |
|
104 |
||
105 |
private JComponent predecessorsPanel; |
|
106 |
||
107 |
private JPanel resourcesPanel; |
|
108 |
||
109 |
private JPanel notesPanel; |
|
110 |
||
111 |
private JTextField nameField1; |
|
112 |
||
113 |
private JTextField durationField1; |
|
114 |
||
115 |
private JTextField tfWebLink; |
|
116 |
||
117 |
private JButton bWebLink; |
|
118 |
||
119 |
private JSpinner percentCompleteSlider; |
|
120 |
||
121 |
private JComboBox priorityComboBox; |
|
122 |
||
123 |
private JComboBox thirdDateComboBox; |
|
124 |
||
125 |
private JCheckBox mileStoneCheckBox1; |
|
126 |
||
127 |
private JCheckBox projectTaskCheckBox1; |
|
128 |
||
129 |
private boolean isColorChanged; |
|
130 |
||
131 |
private JButton colorButton; |
|
132 |
||
133 |
private JButton defaultColorButton; |
|
134 |
||
135 |
/** Shape chooser combo Box */
|
|
136 |
private JPaintCombo shapeComboBox; |
|
137 |
||
138 |
private JScrollPane scrollPaneNotes; |
|
139 |
||
140 |
private JTextArea noteAreaNotes; |
|
141 |
||
142 |
private JPanel secondRowPanelNotes; |
|
143 |
||
144 |
private String taskWebLink; |
|
145 |
||
146 |
private boolean taskIsMilestone; |
|
147 |
||
148 |
private GanttCalendar taskStartDate; |
|
149 |
||
150 |
private GanttCalendar taskThirdDate; |
|
151 |
||
152 |
private int taskThirdDateConstraint; |
|
153 |
||
154 |
private boolean taskIsProjectTask; |
|
155 |
||
156 |
private int taskLength; |
|
157 |
||
158 |
private String taskNotes; |
|
159 |
||
160 |
private int taskCompletionPercentage; |
|
161 |
||
162 |
private Task.Priority taskPriority; |
|
163 |
||
164 |
private ShapePaint taskShape; |
|
165 |
||
166 |
private CustomColumnsPanel myCustomColumnPanel = null; |
|
167 |
||
168 |
private TaskDependenciesPanel myDependenciesPanel; |
|
169 |
||
170 |
private TaskAllocationsPanel myAllocationsPanel; |
|
171 |
||
172 |
private final HumanResourceManager myHumanResourceManager; |
|
173 |
||
174 |
private final RoleManager myRoleManager; |
|
175 |
||
176 |
private Task myUnpluggedClone; |
|
177 |
private final TaskManager myTaskManager; |
|
178 |
private final IGanttProject myProject; |
|
179 |
private final UIFacade myUIfacade; |
|
180 |
||
181 |
private TaskMutator mutator; |
|
182 |
||
183 |
public GanttTaskPropertiesBean(GanttTask[] selectedTasks, IGanttProject project, UIFacade uifacade) { |
|
184 |
this.selectedTasks = selectedTasks; |
|
185 |
setInitialValues(selectedTasks[0]); |
|
186 |
myHumanResourceManager = project.getHumanResourceManager(); |
|
187 |
myRoleManager = project.getRoleManager(); |
|
188 |
myTaskManager = project.getTaskManager(); |
|
189 |
myProject = project; |
|
190 |
myUIfacade = uifacade; |
|
191 |
init(); |
|
192 |
setSelectedTask(); |
|
193 |
}
|
|
194 |
||
195 |
private static void addEmptyRow(JPanel form) { |
|
196 |
form.add(Box.createRigidArea(new Dimension(1, 10))); |
|
197 |
form.add(Box.createRigidArea(new Dimension(1, 10))); |
|
198 |
}
|
|
199 |
||
200 |
/** Construct the general panel */
|
|
201 |
private void constructGeneralPanel() { |
|
202 |
JPanel propertiesPanel = new JPanel(new SpringLayout()); |
|
203 |
||
204 |
propertiesPanel.add(new JLabel(language.getText("name"))); |
|
205 |
nameField1 = new JTextField(20); |
|
206 |
nameField1.setName("name_of_task"); |
|
207 |
propertiesPanel.add(nameField1); |
|
208 |
Pair<String, JCheckBox> checkBox = constructCheckBox(); |
|
209 |
propertiesPanel.add(new JLabel(checkBox.first())); |
|
210 |
propertiesPanel.add(checkBox.second()); |
|
211 |
||
212 |
addEmptyRow(propertiesPanel); |
|
213 |
propertiesPanel.add(new JLabel(language.getText("dateOfBegining"))); |
|
214 |
myStartDatePicker = createDatePicker(new ActionListener() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
215 |
@Override
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
216 |
public void actionPerformed(ActionEvent e) { |
217 |
setStart(new GanttCalendar(((JXDatePicker)e.getSource()).getDate()), false); |
|
218 |
}
|
|
219 |
});
|
|
220 |
propertiesPanel.add(myStartDatePicker); |
|
221 |
||
222 |
propertiesPanel.add(new JLabel(language.getText("dateOfEnd"))); |
|
223 |
myEndDatePicker = createDatePicker(new ActionListener() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
224 |
@Override
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
225 |
public void actionPerformed(ActionEvent e) { |
226 |
GanttCalendar c = new GanttCalendar(((JXDatePicker)e.getSource()).getDate()); |
|
227 |
c.add(Calendar.DATE, 1); |
|
228 |
setEnd(c, false); |
|
229 |
}
|
|
230 |
});
|
|
231 |
propertiesPanel.add(myEndDatePicker); |
|
232 |
||
233 |
propertiesPanel.add(new JLabel(language.getText("length"))); |
|
234 |
durationField1 = new JTextField(8); |
|
235 |
durationField1.setName("length"); |
|
236 |
durationField1.addFocusListener(new FocusListener() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
237 |
@Override
|
238 |
public void focusLost(FocusEvent e) { |
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
239 |
fireDurationChanged(); |
240 |
}
|
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
241 |
@Override
|
242 |
public void focusGained(FocusEvent e) {} |
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
243 |
});
|
244 |
propertiesPanel.add(durationField1); |
|
245 |
||
246 |
Box extraConstraintBox = Box.createHorizontalBox(); |
|
247 |
thirdDateComboBox = new JComboBox(); |
|
248 |
thirdDateComboBox.addItem(""); |
|
249 |
thirdDateComboBox.addItem(language.getText("earliestBegin")); |
|
250 |
thirdDateComboBox.setName("third"); |
|
251 |
thirdDateComboBox.addActionListener(new ActionListener() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
252 |
@Override
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
253 |
public void actionPerformed(ActionEvent e) { |
254 |
switch (thirdDateComboBox.getSelectedIndex()) { |
|
255 |
case TaskImpl.EARLIESTBEGIN: |
|
256 |
myThirdDatePicker.setEnabled(true); |
|
257 |
break; |
|
258 |
case TaskImpl.NONE: |
|
259 |
myThirdDatePicker.setEnabled(false); |
|
260 |
break; |
|
261 |
}
|
|
262 |
}
|
|
263 |
});
|
|
264 |
extraConstraintBox.add(thirdDateComboBox); |
|
265 |
myThirdDatePicker = createDatePicker(new ActionListener() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
266 |
@Override
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
267 |
public void actionPerformed(ActionEvent e) { |
268 |
setThird(new GanttCalendar(((JXDatePicker)e.getSource()).getDate()), false); |
|
269 |
}
|
|
270 |
});
|
|
271 |
extraConstraintBox.add(Box.createHorizontalStrut(5)); |
|
272 |
extraConstraintBox.add(myThirdDatePicker); |
|
273 |
propertiesPanel.add(new JLabel(language.getText("option.taskProperties.main.extraConstraint.label"))); |
|
274 |
propertiesPanel.add(extraConstraintBox); |
|
275 |
||
276 |
addEmptyRow(propertiesPanel); |
|
277 |
||
278 |
propertiesPanel.add(new JLabel(language.getText("priority"))); |
|
279 |
priorityComboBox = new JComboBox(); |
|
280 |
for (Task.Priority p: Task.Priority.values()) { |
|
281 |
priorityComboBox.addItem(language.getText(p.getI18nKey())); |
|
282 |
}
|
|
283 |
priorityComboBox.setEditable(false); |
|
284 |
propertiesPanel.add(priorityComboBox); |
|
285 |
||
286 |
propertiesPanel.add(new JLabel(language.getText("advancement"))); |
|
287 |
SpinnerNumberModel spinnerModel = new SpinnerNumberModel(0, 0, 100, 1); |
|
288 |
percentCompleteSlider = new JSpinner(spinnerModel); |
|
289 |
propertiesPanel.add(percentCompleteSlider); |
|
290 |
||
291 |
addEmptyRow(propertiesPanel); |
|
292 |
||
293 |
propertiesPanel.add(new JLabel(language.getText("shape"))); |
|
294 |
shapeComboBox = new JPaintCombo(ShapeConstants.PATTERN_LIST); |
|
295 |
propertiesPanel.add(shapeComboBox); |
|
296 |
||
297 |
Box colorBox = Box.createHorizontalBox(); |
|
298 |
colorButton = new JButton(language.getText("colorButton")); |
|
299 |
colorButton.setBackground(selectedTasks[0].getColor()); |
|
300 |
final String colorChooserTitle = language.getText("selectColor"); |
|
301 |
colorButton.addActionListener(new ActionListener() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
302 |
@Override
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
303 |
public void actionPerformed(ActionEvent e) { |
304 |
JDialog dialog = JColorChooser.createDialog( |
|
305 |
GanttTaskPropertiesBean.this, colorChooserTitle, |
|
306 |
true, colorChooser, |
|
307 |
new ActionListener() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
308 |
@Override
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
309 |
public void actionPerformed(ActionEvent e) { |
310 |
colorButton.setBackground(colorChooser.getColor()); |
|
311 |
isColorChanged = true; |
|
312 |
}
|
|
313 |
}, null); |
|
314 |
colorChooser.setColor(colorButton.getBackground()); |
|
315 |
dialog.setVisible(true); |
|
316 |
}
|
|
317 |
});
|
|
318 |
colorBox.add(colorButton); |
|
319 |
colorBox.add(Box.createHorizontalStrut(5)); |
|
320 |
||
321 |
defaultColorButton = new JButton(language.getText("defaultColor")); |
|
322 |
defaultColorButton.setBackground(GanttGraphicArea.taskDefaultColor); |
|
323 |
defaultColorButton.setToolTipText(GanttProject.getToolTip(language |
|
324 |
.getText("resetColor"))); |
|
325 |
defaultColorButton.addActionListener(new ActionListener() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
326 |
@Override
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
327 |
public void actionPerformed(ActionEvent e) { |
328 |
colorButton.setBackground(GanttGraphicArea.taskDefaultColor); |
|
329 |
isColorChanged = true; |
|
330 |
}
|
|
331 |
});
|
|
332 |
colorBox.add(defaultColorButton); |
|
333 |
||
334 |
propertiesPanel.add(new JLabel(language.getText("colors"))); |
|
335 |
propertiesPanel.add(colorBox); |
|
336 |
||
337 |
Box weblinkBox = Box.createHorizontalBox(); |
|
338 |
tfWebLink = new JTextField(20); |
|
339 |
weblinkBox.add(tfWebLink); |
|
340 |
weblinkBox.add(Box.createHorizontalStrut(2)); |
|
341 |
bWebLink = new TestGanttRolloverButton( |
|
342 |
new ImageIcon(getClass().getResource("/icons/web_16.gif"))); |
|
343 |
bWebLink.setToolTipText(GanttProject.getToolTip(language |
|
344 |
.getText("openWebLink"))); |
|
345 |
weblinkBox.add(bWebLink); |
|
346 |
||
347 |
bWebLink.addActionListener(new ActionListener() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
348 |
@Override
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
349 |
public void actionPerformed(ActionEvent e) { |
350 |
// link to open the web link
|
|
351 |
if (!BrowserControl.displayURL(tfWebLink.getText())) { |
|
352 |
GanttDialogInfo gdi = new GanttDialogInfo(null, |
|
353 |
GanttDialogInfo.ERROR, GanttDialogInfo.YES_OPTION, |
|
354 |
language.getText("msg4"), language.getText("error")); |
|
355 |
gdi.setVisible(true); |
|
356 |
}
|
|
357 |
}
|
|
358 |
});
|
|
359 |
propertiesPanel.add(new JLabel(language.getText("webLink"))); |
|
360 |
propertiesPanel.add(weblinkBox); |
|
361 |
||
362 |
SpringUtilities.makeCompactGrid(propertiesPanel, 14, 2, 1, 1, 5, 5); |
|
363 |
||
364 |
generalPanel = new JPanel(new SpringLayout()); |
|
365 |
generalPanel.add(propertiesPanel); |
|
366 |
generalPanel.add(notesPanel); |
|
367 |
SpringUtilities.makeCompactGrid(generalPanel, 1, 2, 1, 1, 10, 5); |
|
368 |
generalPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); |
|
369 |
}
|
|
370 |
||
371 |
/** Add the different action listeners on the different widgets */
|
|
372 |
public void addActionListener(ActionListener l) { |
|
373 |
nameField1.addActionListener(l); |
|
374 |
thirdDateComboBox.addActionListener(l); |
|
375 |
durationField1.addActionListener(l); |
|
376 |
}
|
|
377 |
||
378 |
/** Change the name of the task on all text fields containing task name */
|
|
379 |
private void changeNameOfTask() { |
|
380 |
if (nameField1 != null) { |
|
381 |
String nameOfTask = nameField1.getText().trim(); |
|
382 |
nameField1.setText(nameOfTask); |
|
383 |
}
|
|
384 |
}
|
|
385 |
||
386 |
private void constructCustomColumnPanel() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
387 |
myCustomColumnPanel = new CustomColumnsPanel( |
388 |
myProject.getTaskCustomColumnManager(), |
|
389 |
myUIfacade, |
|
390 |
selectedTasks[0].getCustomValues(), |
|
391 |
myUIfacade.getTaskTree().getVisibleFields()); |
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
392 |
}
|
393 |
||
394 |
/** Construct the predecessors tabbed pane */
|
|
395 |
private void constructPredecessorsPanel() { |
|
396 |
myDependenciesPanel = new TaskDependenciesPanel(); |
|
397 |
myDependenciesPanel.init(selectedTasks[0]); |
|
398 |
predecessorsPanel = myDependenciesPanel.getComponent(); |
|
399 |
}
|
|
400 |
||
401 |
/** Construct the resources panel */
|
|
402 |
private void constructResourcesPanel() { |
|
403 |
myAllocationsPanel = new TaskAllocationsPanel( |
|
404 |
selectedTasks[0], myHumanResourceManager, myRoleManager); |
|
405 |
resourcesPanel = myAllocationsPanel.getComponent(); |
|
406 |
}
|
|
407 |
||
408 |
/** Construct the notes panel */
|
|
409 |
private void constructNotesPanel() { |
|
410 |
secondRowPanelNotes = new JPanel(new BorderLayout()); |
|
411 |
UIUtil.createTitle(secondRowPanelNotes, language.getText("notesTask")); |
|
412 |
||
413 |
noteAreaNotes = new JTextArea(8, 40); |
|
414 |
noteAreaNotes.setLineWrap(true); |
|
415 |
noteAreaNotes.setWrapStyleWord(true); |
|
416 |
noteAreaNotes.setBackground(new Color(1.0f, 1.0f, 1.0f)); |
|
417 |
||
418 |
scrollPaneNotes = new JScrollPane(noteAreaNotes); |
|
419 |
secondRowPanelNotes.add(scrollPaneNotes, BorderLayout.CENTER); |
|
420 |
notesPanel = secondRowPanelNotes; |
|
421 |
}
|
|
422 |
||
423 |
private JXDatePicker createDatePicker(ActionListener listener) { |
|
424 |
ImageIcon calendarImage = new ImageIcon(getClass().getResource( |
|
425 |
"/icons/calendar_16.gif")); |
|
426 |
Icon nextMonth = new ImageIcon(getClass().getResource( |
|
427 |
"/icons/nextmonth.gif")); |
|
428 |
Icon prevMonth = new ImageIcon(getClass().getResource( |
|
429 |
"/icons/prevmonth.gif")); |
|
430 |
UIManager.put("JXDatePicker.arrowDown.image", calendarImage); |
|
431 |
UIManager.put("JXMonthView.monthUp.image", prevMonth); |
|
432 |
UIManager.put("JXMonthView.monthDown.image", nextMonth); |
|
433 |
UIManager.put("JXMonthView.monthCurrent.image", calendarImage); |
|
434 |
JXDatePicker result = new JXDatePicker(); |
|
435 |
result.addActionListener(listener); |
|
436 |
return result; |
|
437 |
}
|
|
438 |
||
439 |
/** Initialize the widgets */
|
|
440 |
private void init() { |
|
441 |
constructNotesPanel(); |
|
442 |
||
443 |
tabbedPane = new JTabbedPane(); |
|
444 |
tabbedPane.getModel().addChangeListener(new ChangeListener() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
445 |
@Override
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
446 |
public void stateChanged(ChangeEvent e) { |
447 |
changeNameOfTask(); |
|
448 |
fireDurationChanged(); |
|
449 |
}
|
|
450 |
});
|
|
451 |
constructGeneralPanel(); |
|
452 |
||
453 |
tabbedPane.addTab(language.getText("general"), new ImageIcon(getClass() |
|
454 |
.getResource("/icons/properties_16.gif")), generalPanel); |
|
455 |
||
456 |
constructPredecessorsPanel(); |
|
457 |
tabbedPane.addTab(language.getText("predecessors"), new ImageIcon( |
|
458 |
getClass().getResource("/icons/relashion.gif")), |
|
459 |
predecessorsPanel); |
|
460 |
||
461 |
constructResourcesPanel(); |
|
462 |
||
463 |
tabbedPane.addTab(language.getCorrectedLabel("human"), new ImageIcon( |
|
464 |
getClass().getResource("/icons/res_16.gif")), resourcesPanel); |
|
465 |
||
466 |
setLayout(new BorderLayout()); |
|
467 |
||
468 |
add(tabbedPane, BorderLayout.CENTER); |
|
469 |
||
470 |
constructCustomColumnPanel(); |
|
471 |
tabbedPane.addTab(language.getText("customColumns"), new ImageIcon( |
|
472 |
getClass().getResource("/icons/custom.gif")), |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
473 |
myCustomColumnPanel.geComponent()); |
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
474 |
tabbedPane.addFocusListener(new FocusAdapter() { |
475 |
private boolean isFirstFocusGain = true; |
|
476 |
@Override
|
|
477 |
public void focusGained(FocusEvent e) { |
|
478 |
super.focusGained(e); |
|
479 |
if (isFirstFocusGain) { |
|
480 |
nameField1.requestFocus(); |
|
481 |
isFirstFocusGain = false; |
|
482 |
}
|
|
483 |
}
|
|
484 |
});
|
|
485 |
tabbedPane.setBorder(BorderFactory.createEmptyBorder(2,0,5,0)); |
|
486 |
}
|
|
487 |
||
488 |
// TODO The name of the method is very confusing... Rename to applySettings and remove return value?
|
|
489 |
public Task[] getReturnTask() { |
|
490 |
GanttTask[] returnTask = new GanttTask[selectedTasks.length]; |
|
491 |
||
492 |
for (int i = 0; i < selectedTasks.length; i++) { |
|
493 |
returnTask[i] = selectedTasks[i]; |
|
494 |
||
495 |
mutator = selectedTasks[0].createMutator(); |
|
496 |
mutator.setName(getTaskName()); // getName() |
|
497 |
mutator.setProjectTask (false); |
|
498 |
if (this.taskWebLink != null && !this.taskWebLink.equals(getWebLink())) { |
|
499 |
returnTask[i].setWebLink(getWebLink()); // getName() |
|
500 |
}
|
|
501 |
if (mileStoneCheckBox1 != null) { |
|
502 |
if (this.taskIsMilestone != isMilestone()) { |
|
503 |
mutator.setMilestone(isMilestone()); |
|
504 |
}
|
|
505 |
}
|
|
506 |
else if (projectTaskCheckBox1 != null) { |
|
507 |
if (this.taskIsProjectTask != isProjectTask()) { |
|
508 |
mutator.setProjectTask(isProjectTask()); |
|
509 |
}
|
|
510 |
}
|
|
511 |
if (!this.taskStartDate.equals(getStart())) { |
|
512 |
mutator.setStart(getStart()); |
|
513 |
}
|
|
514 |
if (this.taskThirdDate == null && getThird() != null |
|
515 |
|| this.taskThirdDate != null && getThird() == null |
|
516 |
|| this.taskThirdDate != null && !this.taskThirdDate |
|
517 |
.equals(getThird()) |
|
518 |
|| this.taskThirdDateConstraint != getThirdDateConstraint()) { |
|
519 |
mutator.setThird(getThird(), getThirdDateConstraint()); |
|
520 |
}
|
|
521 |
||
522 |
if (getLength() > 0) { |
|
523 |
mutator.setDuration(returnTask[i].getManager() |
|
524 |
.createLength(getLength())); |
|
525 |
}
|
|
526 |
if (!this.taskNotes.equals(getNotes())) { |
|
527 |
returnTask[i].setNotes(getNotes()); |
|
528 |
}
|
|
529 |
if (this.taskCompletionPercentage != getPercentComplete()) { |
|
530 |
mutator.setCompletionPercentage(getPercentComplete()); |
|
531 |
}
|
|
532 |
if (this.taskPriority != getPriority()) { |
|
533 |
returnTask[i].setPriority(getPriority()); |
|
534 |
}
|
|
535 |
if (isColorChanged) { |
|
536 |
returnTask[i].setColor(colorButton.getBackground()); |
|
537 |
}
|
|
538 |
if (this.taskShape == null && shapeComboBox.getSelectedIndex() != 0 |
|
539 |
|| this.taskShape != null && !this.taskShape |
|
540 |
.equals(shapeComboBox |
|
541 |
.getSelectedPaint())) { |
|
542 |
returnTask[i].setShape(new ShapePaint( |
|
543 |
(ShapePaint) shapeComboBox.getSelectedPaint(), |
|
544 |
Color.white, returnTask[i].getColor())); |
|
545 |
}
|
|
546 |
if (returnTask[i].getShape() != null) { |
|
547 |
returnTask[i].setShape(new ShapePaint(returnTask[i].getShape(), |
|
548 |
Color.white, returnTask[i].getColor())); |
|
549 |
}
|
|
550 |
||
551 |
mutator.commit(); |
|
552 |
myDependenciesPanel.commit(); |
|
553 |
myAllocationsPanel.commit(); |
|
554 |
returnTask[i].applyThirdDateConstraint(); |
|
555 |
}
|
|
556 |
||
557 |
return returnTask; |
|
558 |
}
|
|
559 |
||
560 |
private void setSelectedTask() { |
|
561 |
nameField1.setText(selectedTasks[0].getName()); |
|
562 |
||
563 |
setName(selectedTasks[0].toString()); |
|
564 |
||
565 |
durationField1.setText(String.valueOf(selectedTasks[0].getLength())); |
|
566 |
||
567 |
percentCompleteSlider.setValue(new Integer(selectedTasks[0] |
|
568 |
.getCompletionPercentage())); |
|
569 |
priorityComboBox.setSelectedIndex(selectedTasks[0].getPriority().ordinal()); |
|
570 |
||
571 |
setStart(selectedTasks[0].getStart().clone(), true); |
|
572 |
setEnd(selectedTasks[0].getEnd().clone(), true); |
|
573 |
if (selectedTasks[0].getThird() != null) { |
|
574 |
setThird(selectedTasks[0].getThird().clone(), true); |
|
575 |
}
|
|
576 |
thirdDateComboBox.setSelectedIndex(selectedTasks[0].getThirdDateConstraint()); |
|
577 |
||
578 |
if (mileStoneCheckBox1 != null) { |
|
579 |
mileStoneCheckBox1.setSelected(selectedTasks[0].isMilestone()); |
|
580 |
} else if (projectTaskCheckBox1 != null) { |
|
581 |
projectTaskCheckBox1.setSelected(selectedTasks[0].isProjectTask()); |
|
582 |
}
|
|
583 |
enableMilestoneUnfriendlyControls(!isMilestone()); |
|
584 |
||
585 |
tfWebLink.setText(selectedTasks[0].getWebLink()); |
|
586 |
||
587 |
if (selectedTasks[0].shapeDefined()) { |
|
588 |
for (int j = 0; j < ShapeConstants.PATTERN_LIST.length; j++) { |
|
589 |
if (selectedTasks[0].getShape().equals( |
|
590 |
ShapeConstants.PATTERN_LIST[j])) { |
|
591 |
shapeComboBox.setSelectedIndex(j); |
|
592 |
break; |
|
593 |
}
|
|
594 |
}
|
|
595 |
}
|
|
596 |
||
597 |
noteAreaNotes.setText(selectedTasks[0].getNotes()); |
|
598 |
myUnpluggedClone = selectedTasks[0].unpluggedClone(); |
|
599 |
}
|
|
600 |
||
601 |
private void enableMilestoneUnfriendlyControls(boolean enable) { |
|
602 |
myEndDatePicker.setEnabled(enable); |
|
603 |
durationField1.setEnabled(enable); |
|
604 |
}
|
|
605 |
||
606 |
private boolean isMilestone() { |
|
607 |
if(mileStoneCheckBox1 == null) { |
|
608 |
return false; |
|
609 |
}
|
|
610 |
return mileStoneCheckBox1.isSelected(); |
|
611 |
}
|
|
612 |
||
613 |
private boolean isProjectTask() { |
|
614 |
return projectTaskCheckBox1.isSelected(); |
|
615 |
}
|
|
616 |
||
617 |
private int getThirdDateConstraint() { |
|
618 |
return thirdDateComboBox.getSelectedIndex(); |
|
619 |
}
|
|
620 |
||
621 |
private int getLength() { |
|
622 |
int length; |
|
623 |
try { |
|
624 |
length = Integer.parseInt(durationField1.getText().trim()); |
|
625 |
} catch (NumberFormatException e) { |
|
626 |
length = 0; |
|
627 |
}
|
|
628 |
return length; |
|
629 |
}
|
|
630 |
||
631 |
private void fireDurationChanged() { |
|
632 |
String value = durationField1.getText(); |
|
633 |
try { |
|
634 |
int duration = Integer.parseInt(value); |
|
635 |
changeLength(duration); |
|
636 |
} catch (NumberFormatException e) { |
|
637 |
||
638 |
}
|
|
639 |
}
|
|
640 |
||
641 |
private void changeLength(int length) { |
|
642 |
if (length <= 0) { |
|
643 |
length = 1; |
|
644 |
}
|
|
645 |
durationField1.setText(String.valueOf(length)); |
|
646 |
||
647 |
// Calculate the end date for the given length
|
|
648 |
myUnpluggedClone.setStart(myStart); |
|
649 |
myUnpluggedClone.setDuration(myUnpluggedClone.getManager().createLength(length)); |
|
650 |
setEnd(myUnpluggedClone.getEnd(), false); |
|
651 |
}
|
|
652 |
||
653 |
private String getNotes() { |
|
654 |
return noteAreaNotes.getText(); |
|
655 |
}
|
|
656 |
||
657 |
private String getTaskName() { |
|
658 |
String text = nameField1.getText(); |
|
659 |
return text == null ? "" : text.trim(); |
|
660 |
}
|
|
661 |
||
662 |
private String getWebLink() { |
|
663 |
String text = tfWebLink.getText(); |
|
664 |
return text == null ? "" : text.trim(); |
|
665 |
}
|
|
666 |
||
667 |
private int getPercentComplete() { |
|
668 |
return ((Integer) percentCompleteSlider.getValue()).hashCode(); |
|
669 |
}
|
|
670 |
||
671 |
private Task.Priority getPriority() { |
|
672 |
return Task.Priority.getPriority(priorityComboBox.getSelectedIndex()); |
|
673 |
}
|
|
674 |
||
675 |
private GanttCalendar getStart() { |
|
676 |
return myStart; |
|
677 |
}
|
|
678 |
||
679 |
private GanttCalendar getThird() { |
|
680 |
return myThird; |
|
681 |
}
|
|
682 |
||
683 |
private void setStart(GanttCalendar start, boolean test) { |
|
684 |
myStart = start; |
|
685 |
myStartDatePicker.setDate(myStart.getTime()); |
|
686 |
if (test == true) { |
|
687 |
return; |
|
688 |
}
|
|
689 |
if (myStart.compareTo(myEnd) < 0) { |
|
690 |
adjustLength(); |
|
691 |
} else { |
|
692 |
myEnd = myStart.clone(); |
|
693 |
myEnd.add(Calendar.DATE, taskLength); |
|
694 |
myEndDatePicker.setDate(myEnd.getTime()); |
|
695 |
}
|
|
696 |
}
|
|
697 |
||
698 |
private void setEnd(GanttCalendar end, boolean test) { |
|
699 |
myEnd = end; |
|
700 |
myEndDatePicker.setDate(myEnd.newAdd(Calendar.DATE, -1).getTime()); |
|
701 |
if (test == true) { |
|
702 |
return; |
|
703 |
}
|
|
704 |
if (myStart.compareTo(myEnd) < 0) { |
|
705 |
adjustLength(); |
|
706 |
} else { |
|
707 |
myStart = myEnd.clone(); |
|
708 |
myStart.add(Calendar.DATE, -1 * getLength()); |
|
709 |
}
|
|
710 |
}
|
|
711 |
||
712 |
private void setThird(GanttCalendar third, boolean test) { |
|
713 |
myThird = third; |
|
714 |
myThirdDatePicker.setDate(myThird.getTime()); |
|
715 |
}
|
|
716 |
||
717 |
private void adjustLength() { |
|
718 |
int length; |
|
719 |
myUnpluggedClone.setStart(this.myStart); |
|
720 |
myUnpluggedClone.setEnd(this.myEnd); |
|
721 |
length = myUnpluggedClone.getDuration().getLength(); |
|
722 |
durationField1.setText(String.valueOf(length)); |
|
723 |
}
|
|
724 |
||
725 |
private void setInitialValues(GanttTask task) { |
|
726 |
taskWebLink = task.getWebLink(); |
|
727 |
taskIsMilestone = task.isMilestone(); |
|
728 |
taskStartDate = task.getStart(); |
|
729 |
taskLength = task.getLength(); |
|
730 |
taskNotes = task.getNotes(); |
|
731 |
taskCompletionPercentage = task.getCompletionPercentage(); |
|
732 |
taskPriority = task.getPriority(); |
|
733 |
taskShape = task.getShape(); |
|
734 |
taskThirdDate = task.getThird(); |
|
735 |
taskThirdDateConstraint = task.getThirdDateConstraint(); |
|
736 |
taskIsProjectTask = task.isProjectTask(); |
|
737 |
}
|
|
738 |
||
739 |
private boolean canBeProjectTask(Task testedTask, TaskContainmentHierarchyFacade taskHierarchy) { |
|
740 |
Task[] nestedTasks = taskHierarchy.getNestedTasks(testedTask); |
|
741 |
if (nestedTasks.length == 0) { |
|
742 |
return false; |
|
743 |
}
|
|
744 |
for (Task parent = taskHierarchy.getContainer(testedTask); parent!=null; parent = taskHierarchy.getContainer(parent)) { |
|
745 |
if (parent.isProjectTask()) { |
|
746 |
return false; |
|
747 |
}
|
|
748 |
}
|
|
749 |
for (Task nestedTask : nestedTasks) { |
|
750 |
if (isProjectTaskOrContainsProjectTask(nestedTask)) { |
|
751 |
return false; |
|
752 |
}
|
|
753 |
}
|
|
754 |
return true; |
|
755 |
}
|
|
756 |
||
757 |
private boolean isProjectTaskOrContainsProjectTask(Task task) { |
|
758 |
if (task.isProjectTask()) { |
|
759 |
return true; |
|
760 |
}
|
|
761 |
for (Task nestedTask : task.getNestedTasks()) { |
|
762 |
if (isProjectTaskOrContainsProjectTask(nestedTask)) { |
|
763 |
return true; |
|
764 |
}
|
|
765 |
}
|
|
766 |
return false; |
|
767 |
}
|
|
768 |
||
769 |
/**
|
|
770 |
* Creates a milestone, a project task or no checkbox depending on the selected task
|
|
771 |
* @return the created checkbox or null
|
|
772 |
*/
|
|
773 |
private Pair<String, JCheckBox> constructCheckBox () { |
|
774 |
boolean canBeProjectTask = true; |
|
775 |
boolean canBeMilestone = true; |
|
776 |
TaskContainmentHierarchyFacade taskHierarchy = myTaskManager.getTaskHierarchy(); |
|
777 |
for (Task task : selectedTasks) { |
|
778 |
canBeMilestone &= !taskHierarchy.hasNestedTasks(task); |
|
779 |
canBeProjectTask &= canBeProjectTask(task, taskHierarchy); |
|
780 |
}
|
|
781 |
assert false == (canBeProjectTask && canBeMilestone); |
|
782 |
||
783 |
final Pair<String, JCheckBox> result; |
|
784 |
if (canBeProjectTask) { |
|
785 |
projectTaskCheckBox1 = new JCheckBox (); |
|
786 |
result = Pair.create(language.getText("projectTask"), projectTaskCheckBox1); |
|
787 |
} else if (canBeMilestone) { |
|
788 |
mileStoneCheckBox1 = new JCheckBox(new AbstractAction() { |
|
2
by Maarten Bezemer
Updated till 2fe683a778c3 |
789 |
@Override
|
1
by Maarten Bezemer
Import from HG (until revision 6d5756fbbc3c) |
790 |
public void actionPerformed(ActionEvent arg0) { |
791 |
enableMilestoneUnfriendlyControls(!isMilestone()); |
|
792 |
}
|
|
793 |
});
|
|
794 |
result = Pair.create(language.getText("meetingPoint"), mileStoneCheckBox1); |
|
795 |
} else { |
|
796 |
throw new IllegalStateException("Can't be here"); |
|
797 |
}
|
|
798 |
return result; |
|
799 |
}
|
|
800 |
}
|