~veger/ganttproject/manual-import

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
/*
GanttProject is an opensource project management tool.
Copyright (C) 2011 GanttProject team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
package net.sourceforge.ganttproject.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.Calendar;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.SpringLayout;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import net.sourceforge.ganttproject.GanttCalendar;
import net.sourceforge.ganttproject.GanttGraphicArea;
import net.sourceforge.ganttproject.GanttProject;
import net.sourceforge.ganttproject.GanttTask;
import net.sourceforge.ganttproject.IGanttProject;
import net.sourceforge.ganttproject.gui.options.SpringUtilities;
import net.sourceforge.ganttproject.gui.taskproperties.CustomColumnsPanel;
import net.sourceforge.ganttproject.gui.taskproperties.TaskAllocationsPanel;
import net.sourceforge.ganttproject.gui.taskproperties.TaskDependenciesPanel;
import net.sourceforge.ganttproject.language.GanttLanguage;
import net.sourceforge.ganttproject.resource.HumanResourceManager;
import net.sourceforge.ganttproject.roles.RoleManager;
import net.sourceforge.ganttproject.shape.JPaintCombo;
import net.sourceforge.ganttproject.shape.ShapeConstants;
import net.sourceforge.ganttproject.shape.ShapePaint;
import net.sourceforge.ganttproject.task.Task;
import net.sourceforge.ganttproject.task.TaskContainmentHierarchyFacade;
import net.sourceforge.ganttproject.task.TaskImpl;
import net.sourceforge.ganttproject.task.TaskManager;
import net.sourceforge.ganttproject.task.TaskMutator;
import net.sourceforge.ganttproject.util.BrowserControl;
import net.sourceforge.ganttproject.util.collect.Pair;

import org.jdesktop.swing.JXDatePicker;

/**
 * Real panel for editing task properties
 */
public class GanttTaskPropertiesBean extends JPanel {

    private static final JColorChooser colorChooser = new JColorChooser();

    private JXDatePicker myStartDatePicker;
    private JXDatePicker myEndDatePicker;
    private JXDatePicker myThirdDatePicker;

    protected GanttTask[] selectedTasks;

    private static final GanttLanguage language = GanttLanguage.getInstance();

    private GanttCalendar myStart;

    private GanttCalendar myEnd;

    private GanttCalendar myThird;

    private JTabbedPane tabbedPane; // TabbedPane that includes the following four items

    private JPanel generalPanel;

    private JComponent predecessorsPanel;

    private JPanel resourcesPanel;

    private JPanel notesPanel;

    private JTextField nameField1;

    private JTextField durationField1;

    private JTextField tfWebLink;

    private JButton bWebLink;

    private JSpinner percentCompleteSlider;

    private JComboBox priorityComboBox;

    private JComboBox thirdDateComboBox;

    private JCheckBox mileStoneCheckBox1;

    private JCheckBox projectTaskCheckBox1;

    private boolean isColorChanged;

    private JButton colorButton;

    private JButton defaultColorButton;

    /** Shape chooser combo Box */
    private JPaintCombo shapeComboBox;

    private JScrollPane scrollPaneNotes;

    private JTextArea noteAreaNotes;

    private JPanel secondRowPanelNotes;

    private String taskWebLink;

    private boolean taskIsMilestone;

    private GanttCalendar taskStartDate;

    private GanttCalendar taskThirdDate;

    private int taskThirdDateConstraint;

    private boolean taskIsProjectTask;

    private int taskLength;

    private String taskNotes;

    private int taskCompletionPercentage;

    private Task.Priority taskPriority;

    private ShapePaint taskShape;

    private CustomColumnsPanel myCustomColumnPanel = null;

    private TaskDependenciesPanel myDependenciesPanel;

    private TaskAllocationsPanel myAllocationsPanel;

    private final HumanResourceManager myHumanResourceManager;

    private final RoleManager myRoleManager;

    private Task myUnpluggedClone;
    private final TaskManager myTaskManager;
    private final IGanttProject myProject;
    private final UIFacade myUIfacade;

    private TaskMutator mutator;

    public GanttTaskPropertiesBean(GanttTask[] selectedTasks, IGanttProject project, UIFacade uifacade) {
        this.selectedTasks = selectedTasks;
        setInitialValues(selectedTasks[0]);
        myHumanResourceManager = project.getHumanResourceManager();
        myRoleManager = project.getRoleManager();
        myTaskManager = project.getTaskManager();
        myProject = project;
        myUIfacade = uifacade;
        init();
        setSelectedTask();
    }

    private static void addEmptyRow(JPanel form) {
        form.add(Box.createRigidArea(new Dimension(1, 10)));
        form.add(Box.createRigidArea(new Dimension(1, 10)));
    }

    /** Construct the general panel */
    private void constructGeneralPanel() {
        JPanel propertiesPanel = new JPanel(new SpringLayout());

        propertiesPanel.add(new JLabel(language.getText("name")));
        nameField1 = new JTextField(20);
        nameField1.setName("name_of_task");
        propertiesPanel.add(nameField1);
        Pair<String, JCheckBox> checkBox = constructCheckBox();
        propertiesPanel.add(new JLabel(checkBox.first()));
        propertiesPanel.add(checkBox.second());

        addEmptyRow(propertiesPanel);
        propertiesPanel.add(new JLabel(language.getText("dateOfBegining")));
        myStartDatePicker = createDatePicker(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setStart(new GanttCalendar(((JXDatePicker)e.getSource()).getDate()), false);
            }
        });
        propertiesPanel.add(myStartDatePicker);

        propertiesPanel.add(new JLabel(language.getText("dateOfEnd")));
        myEndDatePicker = createDatePicker(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                GanttCalendar c = new GanttCalendar(((JXDatePicker)e.getSource()).getDate());
                c.add(Calendar.DATE, 1);
                setEnd(c, false);
            }
        });
        propertiesPanel.add(myEndDatePicker);

        propertiesPanel.add(new JLabel(language.getText("length")));
        durationField1 = new JTextField(8);
        durationField1.setName("length");
        durationField1.addFocusListener(new FocusListener() {
                       @Override
                    public void focusLost(FocusEvent e) {
                               fireDurationChanged();
                       }
                       @Override
                    public void focusGained(FocusEvent e) {}
               });
        propertiesPanel.add(durationField1);

        Box extraConstraintBox = Box.createHorizontalBox();
        thirdDateComboBox = new JComboBox();
        thirdDateComboBox.addItem("");
        thirdDateComboBox.addItem(language.getText("earliestBegin"));
        thirdDateComboBox.setName("third");
        thirdDateComboBox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                switch (thirdDateComboBox.getSelectedIndex()) {
                case TaskImpl.EARLIESTBEGIN:
                    myThirdDatePicker.setEnabled(true);
                    break;
                case TaskImpl.NONE:
                    myThirdDatePicker.setEnabled(false);
                    break;
                }
            }
        });
        extraConstraintBox.add(thirdDateComboBox);
        myThirdDatePicker = createDatePicker(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setThird(new GanttCalendar(((JXDatePicker)e.getSource()).getDate()), false);
            }
        });
        extraConstraintBox.add(Box.createHorizontalStrut(5));
        extraConstraintBox.add(myThirdDatePicker);
        propertiesPanel.add(new JLabel(language.getText("option.taskProperties.main.extraConstraint.label")));
        propertiesPanel.add(extraConstraintBox);

        addEmptyRow(propertiesPanel);

        propertiesPanel.add(new JLabel(language.getText("priority")));
        priorityComboBox = new JComboBox();
        for (Task.Priority p: Task.Priority.values()) {
            priorityComboBox.addItem(language.getText(p.getI18nKey()));
        }
        priorityComboBox.setEditable(false);
        propertiesPanel.add(priorityComboBox);

        propertiesPanel.add(new JLabel(language.getText("advancement")));
        SpinnerNumberModel spinnerModel = new SpinnerNumberModel(0, 0, 100, 1);
        percentCompleteSlider = new JSpinner(spinnerModel);
        propertiesPanel.add(percentCompleteSlider);

        addEmptyRow(propertiesPanel);

        propertiesPanel.add(new JLabel(language.getText("shape")));
        shapeComboBox = new JPaintCombo(ShapeConstants.PATTERN_LIST);
        propertiesPanel.add(shapeComboBox);

        Box colorBox = Box.createHorizontalBox();
        colorButton = new JButton(language.getText("colorButton"));
        colorButton.setBackground(selectedTasks[0].getColor());
        final String colorChooserTitle = language.getText("selectColor");
        colorButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JDialog dialog = JColorChooser.createDialog(
                        GanttTaskPropertiesBean.this, colorChooserTitle,
                        true, colorChooser,
                        new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                colorButton.setBackground(colorChooser.getColor());
                                isColorChanged = true;
                            }
                        }, null);
                colorChooser.setColor(colorButton.getBackground());
                dialog.setVisible(true);
            }
        });
        colorBox.add(colorButton);
        colorBox.add(Box.createHorizontalStrut(5));

        defaultColorButton = new JButton(language.getText("defaultColor"));
        defaultColorButton.setBackground(GanttGraphicArea.taskDefaultColor);
        defaultColorButton.setToolTipText(GanttProject.getToolTip(language
                .getText("resetColor")));
        defaultColorButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                colorButton.setBackground(GanttGraphicArea.taskDefaultColor);
                isColorChanged = true;
            }
        });
        colorBox.add(defaultColorButton);

        propertiesPanel.add(new JLabel(language.getText("colors")));
        propertiesPanel.add(colorBox);

        Box weblinkBox = Box.createHorizontalBox();
        tfWebLink = new JTextField(20);
        weblinkBox.add(tfWebLink);
        weblinkBox.add(Box.createHorizontalStrut(2));
        bWebLink = new TestGanttRolloverButton(
                new ImageIcon(getClass().getResource("/icons/web_16.gif")));
        bWebLink.setToolTipText(GanttProject.getToolTip(language
                .getText("openWebLink")));
        weblinkBox.add(bWebLink);

        bWebLink.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // link to open the web link
                if (!BrowserControl.displayURL(tfWebLink.getText())) {
                    GanttDialogInfo gdi = new GanttDialogInfo(null,
                            GanttDialogInfo.ERROR, GanttDialogInfo.YES_OPTION,
                            language.getText("msg4"), language.getText("error"));
                    gdi.setVisible(true);
                }
            }
        });
        propertiesPanel.add(new JLabel(language.getText("webLink")));
        propertiesPanel.add(weblinkBox);

        SpringUtilities.makeCompactGrid(propertiesPanel, 14, 2, 1, 1, 5, 5);

        generalPanel = new JPanel(new SpringLayout());
        generalPanel.add(propertiesPanel);
        generalPanel.add(notesPanel);
        SpringUtilities.makeCompactGrid(generalPanel, 1, 2, 1, 1, 10, 5);
        generalPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    }

    /** Add the different action listeners on the different widgets */
    public void addActionListener(ActionListener l) {
        nameField1.addActionListener(l);
        thirdDateComboBox.addActionListener(l);
        durationField1.addActionListener(l);
    }

    /** Change the name of the task on all text fields containing task name */
    private void changeNameOfTask() {
        if (nameField1 != null) {
            String nameOfTask = nameField1.getText().trim();
            nameField1.setText(nameOfTask);
        }
    }

    private void constructCustomColumnPanel() {
        myCustomColumnPanel = new CustomColumnsPanel(
                myProject.getTaskCustomColumnManager(),
                myUIfacade,
                selectedTasks[0].getCustomValues(),
                myUIfacade.getTaskTree().getVisibleFields());
    }

    /** Construct the predecessors tabbed pane */
    private void constructPredecessorsPanel() {
        myDependenciesPanel = new TaskDependenciesPanel();
        myDependenciesPanel.init(selectedTasks[0]);
        predecessorsPanel = myDependenciesPanel.getComponent();
    }

    /** Construct the resources panel */
    private void constructResourcesPanel() {
        myAllocationsPanel = new TaskAllocationsPanel(
                selectedTasks[0], myHumanResourceManager, myRoleManager);
        resourcesPanel = myAllocationsPanel.getComponent();
    }

    /** Construct the notes panel */
    private void constructNotesPanel() {
        secondRowPanelNotes = new JPanel(new BorderLayout());
        UIUtil.createTitle(secondRowPanelNotes, language.getText("notesTask"));

        noteAreaNotes = new JTextArea(8, 40);
        noteAreaNotes.setLineWrap(true);
        noteAreaNotes.setWrapStyleWord(true);
        noteAreaNotes.setBackground(new Color(1.0f, 1.0f, 1.0f));

        scrollPaneNotes = new JScrollPane(noteAreaNotes);
        secondRowPanelNotes.add(scrollPaneNotes, BorderLayout.CENTER);
        notesPanel = secondRowPanelNotes;
    }

    private JXDatePicker createDatePicker(ActionListener listener) {
        ImageIcon calendarImage = new ImageIcon(getClass().getResource(
                "/icons/calendar_16.gif"));
        Icon nextMonth = new ImageIcon(getClass().getResource(
                "/icons/nextmonth.gif"));
        Icon prevMonth = new ImageIcon(getClass().getResource(
                "/icons/prevmonth.gif"));
        UIManager.put("JXDatePicker.arrowDown.image", calendarImage);
        UIManager.put("JXMonthView.monthUp.image", prevMonth);
        UIManager.put("JXMonthView.monthDown.image", nextMonth);
        UIManager.put("JXMonthView.monthCurrent.image", calendarImage);
        JXDatePicker result = new JXDatePicker();
        result.addActionListener(listener);
        return result;
    }

    /** Initialize the widgets */
    private void init() {
        constructNotesPanel();

        tabbedPane = new JTabbedPane();
        tabbedPane.getModel().addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                changeNameOfTask();
                fireDurationChanged();
            }
        });
        constructGeneralPanel();

        tabbedPane.addTab(language.getText("general"), new ImageIcon(getClass()
                .getResource("/icons/properties_16.gif")), generalPanel);

        constructPredecessorsPanel();
        tabbedPane.addTab(language.getText("predecessors"), new ImageIcon(
                getClass().getResource("/icons/relashion.gif")),
                predecessorsPanel);

        constructResourcesPanel();

        tabbedPane.addTab(language.getCorrectedLabel("human"), new ImageIcon(
                getClass().getResource("/icons/res_16.gif")), resourcesPanel);

        setLayout(new BorderLayout());

        add(tabbedPane, BorderLayout.CENTER);

        constructCustomColumnPanel();
        tabbedPane.addTab(language.getText("customColumns"), new ImageIcon(
                getClass().getResource("/icons/custom.gif")),
                myCustomColumnPanel.geComponent());
        tabbedPane.addFocusListener(new FocusAdapter() {
            private boolean isFirstFocusGain = true;
            @Override
            public void focusGained(FocusEvent e) {
                super.focusGained(e);
                if (isFirstFocusGain) {
                    nameField1.requestFocus();
                    isFirstFocusGain = false;
                }
            }
        });
        tabbedPane.setBorder(BorderFactory.createEmptyBorder(2,0,5,0));
    }

    // TODO The name of the method is very confusing... Rename to applySettings and remove return value?
    public Task[] getReturnTask() {
        GanttTask[] returnTask = new GanttTask[selectedTasks.length];

        for (int i = 0; i < selectedTasks.length; i++) {
            returnTask[i] = selectedTasks[i];

            mutator = selectedTasks[0].createMutator();
            mutator.setName(getTaskName()); // getName()
            mutator.setProjectTask (false);
            if (this.taskWebLink != null && !this.taskWebLink.equals(getWebLink())) {
                returnTask[i].setWebLink(getWebLink()); // getName()
            }
            if (mileStoneCheckBox1 != null) {
                if (this.taskIsMilestone != isMilestone()) {
                    mutator.setMilestone(isMilestone());
                }
            }
            else if (projectTaskCheckBox1 != null) {
                if (this.taskIsProjectTask != isProjectTask()) {
                    mutator.setProjectTask(isProjectTask());
                }
            }
            if (!this.taskStartDate.equals(getStart())) {
                mutator.setStart(getStart());
            }
            if (this.taskThirdDate == null && getThird() != null
                    || this.taskThirdDate != null && getThird() == null
                    || this.taskThirdDate != null && !this.taskThirdDate
                            .equals(getThird())
                    || this.taskThirdDateConstraint != getThirdDateConstraint()) {
                mutator.setThird(getThird(), getThirdDateConstraint());
            }

            if (getLength() > 0) {
                    mutator.setDuration(returnTask[i].getManager()
                            .createLength(getLength()));
            }
            if (!this.taskNotes.equals(getNotes())) {
                returnTask[i].setNotes(getNotes());
            }
            if (this.taskCompletionPercentage != getPercentComplete()) {
                mutator.setCompletionPercentage(getPercentComplete());
            }
            if (this.taskPriority != getPriority()) {
                returnTask[i].setPriority(getPriority());
            }
            if (isColorChanged) {
                returnTask[i].setColor(colorButton.getBackground());
            }
            if (this.taskShape == null && shapeComboBox.getSelectedIndex() != 0
                    || this.taskShape != null && !this.taskShape
                            .equals(shapeComboBox
                                    .getSelectedPaint())) {
                returnTask[i].setShape(new ShapePaint(
                        (ShapePaint) shapeComboBox.getSelectedPaint(),
                        Color.white, returnTask[i].getColor()));
            }
            if (returnTask[i].getShape() != null) {
                returnTask[i].setShape(new ShapePaint(returnTask[i].getShape(),
                        Color.white, returnTask[i].getColor()));
            }

            mutator.commit();
            myDependenciesPanel.commit();
            myAllocationsPanel.commit();
            returnTask[i].applyThirdDateConstraint();
        }

        return returnTask;
    }

    private void setSelectedTask() {
        nameField1.setText(selectedTasks[0].getName());

        setName(selectedTasks[0].toString());

        durationField1.setText(String.valueOf(selectedTasks[0].getLength()));

        percentCompleteSlider.setValue(new Integer(selectedTasks[0]
                .getCompletionPercentage()));
        priorityComboBox.setSelectedIndex(selectedTasks[0].getPriority().ordinal());

        setStart(selectedTasks[0].getStart().clone(), true);
        setEnd(selectedTasks[0].getEnd().clone(), true);
        if (selectedTasks[0].getThird() != null) {
            setThird(selectedTasks[0].getThird().clone(), true);
        }
        thirdDateComboBox.setSelectedIndex(selectedTasks[0].getThirdDateConstraint());

        if (mileStoneCheckBox1 != null) {
            mileStoneCheckBox1.setSelected(selectedTasks[0].isMilestone());
        } else if (projectTaskCheckBox1 != null) {
            projectTaskCheckBox1.setSelected(selectedTasks[0].isProjectTask());
        }
        enableMilestoneUnfriendlyControls(!isMilestone());

        tfWebLink.setText(selectedTasks[0].getWebLink());

        if (selectedTasks[0].shapeDefined()) {
            for (int j = 0; j < ShapeConstants.PATTERN_LIST.length; j++) {
                if (selectedTasks[0].getShape().equals(
                        ShapeConstants.PATTERN_LIST[j])) {
                    shapeComboBox.setSelectedIndex(j);
                    break;
                }
            }
        }

        noteAreaNotes.setText(selectedTasks[0].getNotes());
        myUnpluggedClone = selectedTasks[0].unpluggedClone();
    }

    private void enableMilestoneUnfriendlyControls(boolean enable) {
        myEndDatePicker.setEnabled(enable);
        durationField1.setEnabled(enable);
    }

    private boolean isMilestone() {
        if(mileStoneCheckBox1 == null) {
            return false;
        }
        return mileStoneCheckBox1.isSelected();
    }

    private boolean isProjectTask() {
        return projectTaskCheckBox1.isSelected();
    }

    private int getThirdDateConstraint() {
        return thirdDateComboBox.getSelectedIndex();
    }

    private int getLength() {
        int length;
        try {
            length = Integer.parseInt(durationField1.getText().trim());
        } catch (NumberFormatException e) {
            length = 0;
        }
        return length;
    }

    private void fireDurationChanged() {
        String value = durationField1.getText();
        try {
            int duration = Integer.parseInt(value);
            changeLength(duration);
        } catch (NumberFormatException e) {

        }
    }

    private void changeLength(int length) {
        if (length <= 0) {
            length = 1;
        }
        durationField1.setText(String.valueOf(length));

        // Calculate the end date for the given length
        myUnpluggedClone.setStart(myStart);
        myUnpluggedClone.setDuration(myUnpluggedClone.getManager().createLength(length));
        setEnd(myUnpluggedClone.getEnd(), false);
    }

    private String getNotes() {
        return noteAreaNotes.getText();
    }

    private String getTaskName() {
        String text = nameField1.getText();
        return text == null ? "" : text.trim();
    }

    private String getWebLink() {
        String text = tfWebLink.getText();
        return text == null ? "" : text.trim();
    }

    private int getPercentComplete() {
        return ((Integer) percentCompleteSlider.getValue()).hashCode();
    }

    private Task.Priority getPriority() {
        return Task.Priority.getPriority(priorityComboBox.getSelectedIndex());
    }

    private GanttCalendar getStart() {
        return myStart;
    }

    private GanttCalendar getThird() {
        return myThird;
    }

    private void setStart(GanttCalendar start, boolean test) {
        myStart = start;
        myStartDatePicker.setDate(myStart.getTime());
        if (test == true) {
            return;
        }
        if (myStart.compareTo(myEnd) < 0) {
            adjustLength();
        } else {
            myEnd = myStart.clone();
            myEnd.add(Calendar.DATE, taskLength);
            myEndDatePicker.setDate(myEnd.getTime());
        }
    }

    private void setEnd(GanttCalendar end, boolean test) {
        myEnd = end;
        myEndDatePicker.setDate(myEnd.newAdd(Calendar.DATE, -1).getTime());
        if (test == true) {
            return;
        }
        if (myStart.compareTo(myEnd) < 0) {
            adjustLength();
        } else {
            myStart = myEnd.clone();
            myStart.add(Calendar.DATE, -1 * getLength());
        }
    }

    private void setThird(GanttCalendar third, boolean test) {
        myThird = third;
        myThirdDatePicker.setDate(myThird.getTime());
    }

    private void adjustLength() {
        int length;
        myUnpluggedClone.setStart(this.myStart);
        myUnpluggedClone.setEnd(this.myEnd);
        length = myUnpluggedClone.getDuration().getLength();
        durationField1.setText(String.valueOf(length));
    }

    private void setInitialValues(GanttTask task) {
        taskWebLink = task.getWebLink();
        taskIsMilestone = task.isMilestone();
        taskStartDate = task.getStart();
        taskLength = task.getLength();
        taskNotes = task.getNotes();
        taskCompletionPercentage = task.getCompletionPercentage();
        taskPriority = task.getPriority();
        taskShape = task.getShape();
        taskThirdDate = task.getThird();
        taskThirdDateConstraint = task.getThirdDateConstraint();
        taskIsProjectTask = task.isProjectTask();
    }

    private boolean canBeProjectTask(Task testedTask, TaskContainmentHierarchyFacade taskHierarchy) {
        Task[] nestedTasks = taskHierarchy.getNestedTasks(testedTask);
        if (nestedTasks.length == 0) {
            return false;
        }
        for (Task parent = taskHierarchy.getContainer(testedTask); parent!=null; parent = taskHierarchy.getContainer(parent)) {
            if (parent.isProjectTask()) {
                return false;
            }
        }
        for (Task nestedTask : nestedTasks) {
            if (isProjectTaskOrContainsProjectTask(nestedTask)) {
                return false;
            }
        }
        return true;
    }

    private boolean isProjectTaskOrContainsProjectTask(Task task) {
        if (task.isProjectTask()) {
            return true;
        }
        for (Task nestedTask : task.getNestedTasks()) {
            if (isProjectTaskOrContainsProjectTask(nestedTask)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Creates a milestone, a project task or no checkbox depending on the selected task
     * @return the created checkbox or null
     */
    private Pair<String, JCheckBox> constructCheckBox () {
        boolean canBeProjectTask = true;
        boolean canBeMilestone = true;
        TaskContainmentHierarchyFacade taskHierarchy = myTaskManager.getTaskHierarchy();
        for (Task task : selectedTasks) {
            canBeMilestone &= !taskHierarchy.hasNestedTasks(task);
            canBeProjectTask &= canBeProjectTask(task, taskHierarchy);
        }
        assert false == (canBeProjectTask && canBeMilestone);

        final Pair<String, JCheckBox> result;
        if (canBeProjectTask) {
            projectTaskCheckBox1 = new JCheckBox ();
            result = Pair.create(language.getText("projectTask"), projectTaskCheckBox1);
        } else if (canBeMilestone) {
            mileStoneCheckBox1 = new JCheckBox(new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent arg0) {
                    enableMilestoneUnfriendlyControls(!isMilestone());
                }
            });
            result = Pair.create(language.getText("meetingPoint"), mileStoneCheckBox1);
        } else {
            throw new IllegalStateException("Can't be here");
        }
        return result;
    }
}