Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ee16b586aa41e0ea673f8bfba872cabc26ffe09b (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2011 BSI Business Systems Integration AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/
package org.eclipse.scout.rt.ui.swt.basic.calendar.widgets;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.scout.commons.logger.IScoutLogger;
import org.eclipse.scout.commons.logger.ScoutLogManager;
import org.eclipse.scout.rt.ui.swt.basic.calendar.CalendarConstants;
import org.eclipse.scout.rt.ui.swt.basic.calendar.CalendarModel;
import org.eclipse.scout.rt.ui.swt.basic.calendar.CalendarViewEvent;
import org.eclipse.scout.rt.ui.swt.basic.calendar.DisplayMode;
import org.eclipse.scout.rt.ui.swt.basic.calendar.EmptyCalendarModel;
import org.eclipse.scout.rt.ui.swt.basic.calendar.ICalendarViewListener;
import org.eclipse.scout.rt.ui.swt.basic.calendar.SwtColors;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

/**
 * This class represents an SWT calendar widget.<br>
 * <br>
 * <b>Date concept regarding this calendar:</b>
 * <ul>
 * <li>A SwtCalendar object has a viewDate, which represent the day which we want to visualize (within a certain viewing
 * interval)</li>
 * <li>There is a view date start and view date end (m_viewDateStart, m_viewDateEnd) representing the visualized period</li>
 * <li>We find additionnaly and optionnaly a selected date (m_selectedDate)</li>
 * <li>When a new JCalendar object is created, the view date is set to today</li>
 * <li>If the display mode is changed, the view date start/end is recalculated</li>
 * <li>If the current view date is changed, the view date start/end are also recalculated</li>
 * </ul>
 * 
 * @author Michael Rudolf, Andreas Hoegger
 */
public class SwtCalendar extends Composite implements PaintListener {
  protected static final IScoutLogger LOG = ScoutLogManager.getLogger(SwtCalendar.class);

  private ArrayList<ICalendarViewListener> calendarViewListeners;

  private int m_workDayCount = 5;

  private Map m_itemMap;

  /** selected date */
  private Calendar m_selectedDate;

  /** current calendar date */
  private Calendar m_viewDate;
  /** start calendar date */
  private Calendar m_viewDateStart;
  /** end calendar date */
  private Calendar m_viewDateEnd;

  private CalendarModel m_model;
  private Object m_selectedItem;
  private boolean m_calendarUpdating;

  /** date browser bar to set the date backward/forward */
  private DateBrowserBar m_browserBar;

  /** central composite to hold the calendar area */
  private Composite m_centralComposite;

  /** reference to the calendar area (child of m_centralComposite) */
  private CentralPanel m_calendarPanel;

  /** selection scope widget (month, week, work week, day */
  private SelectionScopeBar m_selectionScope;

  /** workingHour settings **/
  private int m_startHour = CalendarConstants.DAY_TIMELINE_START_TIME;
  private int m_endHour = CalendarConstants.DAY_TIMELINE_END_TIME;
  private boolean m_useOverflowCells = true;
  private boolean m_markNoonHour = true;
  private boolean m_markOutOfMonthDays = true;

  public SwtCalendar(Composite parent, int style) {
    super(parent, style);

    // just create a dummy model
    m_model = new EmptyCalendarModel();

    // create listener arrays
    calendarViewListeners = new ArrayList<ICalendarViewListener>();
    createControls();
    addPaintListener(this);
    // set date to now + refresh layout
    setToday();

  }

  protected void createControls() {

    // layout and layout data for this component
    GridLayout toplayout = new GridLayout();
    toplayout.numColumns = 1;
    toplayout.verticalSpacing = 1;
    toplayout.marginHeight = 2;
    toplayout.marginWidth = 2;
    this.setLayout(toplayout);
    //
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = GridData.FILL;
    gd.verticalAlignment = GridData.FILL;
    this.setLayoutData(gd);

    // new date browser bar
    m_browserBar = new DateBrowserBar(this, SWT.NONE);

    // main calendar area
    m_centralComposite = new Composite(this, SWT.NONE);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = GridData.FILL;
    gd.verticalAlignment = GridData.FILL;
    m_centralComposite.setLayoutData(gd);
    //
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.verticalSpacing = 1;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    m_centralComposite.setLayout(layout);

    // scope selection at the bottom
    m_selectionScope = new SelectionScopeBar(this, SWT.NONE);

  }

  /** force a reload of all items within calendar cells */
  protected void reloadCalendarItems() {
    m_calendarPanel.reloadCalendarItems();
  }

  public void refreshLayout() {
    //logger.debug("Refreshing layout...");

    // get rid of old panel
    if (m_calendarPanel != null && !m_calendarPanel.isDisposed()) {
      m_calendarPanel.dispose();
    }

    // create a new one
    m_calendarPanel = new CentralPanel(m_centralComposite, SWT.NONE, this);

    // set state of panel
    m_calendarPanel.setState();

    // update selection
    m_calendarPanel.updateSelection(m_selectedDate);

    // redraw calendar panel
    m_centralComposite.layout();
    layout(true);

  }

  public void setModel(CalendarModel model) {
    m_model = model;
    modelChanged();
  }

  public CalendarModel getModel() {
    return m_model;
  }

  public Composite getCentralComposite() {
    return m_centralComposite;
  }

  public CentralPanel getCentralPanel() {
    return m_calendarPanel;
  }

  protected void fireSelectionChanged() {
    if (calendarViewListeners != null && calendarViewListeners.size() > 0) {
      Date viewDate = getViewDate().getTime();
      Date viewDateStart = getViewDateStart().getTime();
      Date viewDateEnd = getViewDateEnd().getTime();
      CalendarViewEvent e = new CalendarViewEvent(this, CalendarViewEvent.TYPE_SELECTION_CHANGED, viewDate, viewDateStart, viewDateEnd);
      for (int i = 0; i < calendarViewListeners.size(); i++) {
        (calendarViewListeners.get(i)).viewChanged(e);
      }
    }
  }

  protected void fireViewDateChanged() {
    if (calendarViewListeners != null && calendarViewListeners.size() > 0) {
      Date viewDate = getViewDate().getTime();
      Date viewDateStart = getViewDateStart().getTime();
      Date viewDateEnd = getViewDateEnd().getTime();
      CalendarViewEvent e = new CalendarViewEvent(this, CalendarViewEvent.TYPE_VISIBLE_RANGE_CHANGED, viewDate, viewDateStart, viewDateEnd);
      for (int i = 0; i < calendarViewListeners.size(); i++) {
        (calendarViewListeners.get(i)).viewChanged(e);
      }
    }
  }

  /**
   * @param item
   *          some calendar item type, e.g. CalendarItem
   */
  public void setSelectedItem(Object item) {
    Object oldItem = m_selectedItem;
    m_selectedItem = item;
    CalendarModel model = getModel();
    // do we need to repaint the old item range?
    if (oldItem != null) {
      Date a = model.getFromDate(oldItem);
      Date b = model.getToDate(oldItem);
      repaintCellRange(a, b);
      // do we need to repaint the new item range?
    }
    if (item != null) {
      Date a = model.getFromDate(item);
      Date b = model.getToDate(item);
      repaintCellRange(a, b);
    }

    fireSelectionChanged();
  }

  protected void repaintCellRange(Date a, Date b) {
    if (b == null) {
      b = a;
    }
    Calendar cal = Calendar.getInstance();
    cal.setTime(truncDate(a));
    while (cal.getTime().compareTo(b) <= 0) {
      AbstractCell cell = m_calendarPanel.getCellFromDate(cal.getTime());
      // repaint?
      if (cell != null) {
        cell.redraw();
      }

      cal.add(Calendar.DATE, 1);
    }
  }

  /** @return a Calendar object corresponding to the given date */
  public static Calendar getCalendarFromDate(Date d) {
    Calendar c = Calendar.getInstance();
    c.setTime(d);
    return c;
  }

  /** @return some calendar item type, e.g. CalendarItem */
  public Object getSelectedItem() {
    return m_selectedItem;
  }

  public void modelChanged() {
    LOG.debug("Reloading items...");

    // reset
    if (m_calendarPanel != null) {
      m_calendarPanel.reloadCalendarItems();
    }
  }

  /**
   * @param showDisplayModeSelection
   */
  public void setShowDisplayModeSelection(boolean showDisplayModeSelection) {
    m_selectionScope.setVisible(showDisplayModeSelection);
    ((GridData) m_selectionScope.getLayoutData()).exclude = !showDisplayModeSelection;
  }

  public void setWorkingHours(int startHour, int endHour, boolean useOverflowCells) {
    m_startHour = startHour;
    // to keep swt in sync with swing, swt needs an extra hour to draw timeline
    m_endHour = endHour + 1;
    m_useOverflowCells = useOverflowCells;
  }

  public void setMarkNoonHour(boolean markNoonHour) {
    m_markNoonHour = markNoonHour;
  }

  public void setMarkOutOfMonthDays(boolean markOutOfMonthDays) {
    m_markOutOfMonthDays = markOutOfMonthDays;
  }

  public int getStartHour() {
    return m_startHour;
  }

  public int getEndHour() {
    return m_endHour;
  }

  public boolean getUseOverflowCells() {
    return m_useOverflowCells;
  }

  public boolean getMarkNoonHour() {
    return m_markNoonHour;
  }

  public boolean getMarkOutOfMonthDays() {
    return m_markOutOfMonthDays;
  }

  public void setDisplayMode(int newMode) {
    // check argument
    if (newMode != DisplayMode.MONTH &&
        newMode != DisplayMode.WEEK &&
        newMode != DisplayMode.WORKWEEK &&
        newMode != DisplayMode.DAY) {
      throw new IllegalArgumentException("illegal display mode: " + newMode);
    }

    // changed?
    int oldMode = m_selectionScope.getDisplayMode();
    if (oldMode == newMode) {
      return;
    }

    // set new mode
    m_selectionScope.setDisplayMode(newMode);

    // calc start/end date
    calcViewDateInterval();

    LOG.debug("displayMode set to " + newMode);
  }

  public int getDisplayMode() {
    return m_selectionScope.getDisplayMode();
  }

  public void setCondensedMode(boolean mode) {

    // changed?
    boolean oldMode = m_selectionScope.getCondensedMode();
    if (oldMode == mode) {
      return;
    }

    // set new condensed mode
    m_selectionScope.setCondensedMode(mode);

    LOG.debug("set to condensed mode " + mode);
  }

  public boolean getCondensedMode() {
    return m_selectionScope.getCondensedMode();
  }

  public void setFirstDayOfWeek(int day) {

    if (day < 1 || day > 7) {
      throw new IllegalArgumentException("Illegal first day of week: " + day);
    }

    // changed?
    int oldDay = m_selectionScope.getFirstDayOfWeek();
    if (oldDay == day) {
      return;
    }

    // set new day
    //m_selectionScope.setFirstDayOfWeek(day);

    // calc start/end date
    calcViewDateInterval();

    LOG.debug("first day of week set to " + day);
  }

  /** set the header of the browser bar */
  public void setDateBrowserHeader(String header) {
    if (m_browserBar != null) {
      m_browserBar.setHeaderText(header);
      m_browserBar.layout(true);
    }
  }

  public int getFirstDayOfWeek() {
    return m_selectionScope.getFirstDayOfWeek();
  }

  public void addCalendarViewListener(ICalendarViewListener listener) {
    calendarViewListeners.add(listener);
  }

  public void removeCalendarViewListener(ICalendarViewListener listener) {
    calendarViewListeners.remove(listener);
  }

  // --- end listener handling

  /**
   * do nothing in the JCalendar version, needs to be overriden to do smth
   * e.g. in SWTScoutCalendar
   */
  public void showGeneralContextMenu(IMenuManager manager) {
  }

  /**
   * do nothing in the JCalendar version, needs to be overriden to do smth
   * e.g. in SWTScoutCalendar
   */
  public void showItemContextMenu(IMenuManager manager, Object item) {
  }

  @Override
  public void paintControl(PaintEvent e) {
    setBackground(SwtColors.getInstance().getWhite());
    setForeground(SwtColors.getInstance().getDarkgray());

    drawBorders(e);
  }

  protected void drawBorders(PaintEvent e) {
    Rectangle bounds = getBounds();
    e.gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
  }

  /** has the view date interval changed, i.e. view date start/end */
  protected boolean changedViewDateInterval(Calendar newViewDate) {

    switch (getDisplayMode()) {
      case DisplayMode.DAY:
        return !newViewDate.equals(m_viewDate);

      case DisplayMode.WEEK:
      case DisplayMode.WORKWEEK:
        // date start
        Calendar viewDateStart = Calendar.getInstance();
        viewDateStart.setTime(newViewDate.getTime());
        // go back to first day of week
        viewDateStart.add(Calendar.DAY_OF_WEEK, -((viewDateStart.get(Calendar.DAY_OF_WEEK) - getFirstDayOfWeek() + 7) % 7));

        // date start changed?
        return !viewDateStart.equals(m_viewDateStart);

      case DisplayMode.MONTH:
        // date start
        viewDateStart = Calendar.getInstance();
        viewDateStart.setTime(newViewDate.getTime());
        //Calculate Startdate; go back to 1st of month, then back to 1st day of week (1=sunday)
        viewDateStart.add(Calendar.DAY_OF_MONTH, -(viewDateStart.get(Calendar.DAY_OF_MONTH) - 1));
        viewDateStart.add(Calendar.DAY_OF_WEEK, -((viewDateStart.get(Calendar.DAY_OF_WEEK) - getFirstDayOfWeek() + 7) % 7));

        // date start changed?
        return !viewDateStart.equals(m_viewDateStart);

      default:
        LOG.error("Should not reach this case");
        return false;
    }

  }

  /** calculate view date start/end corresponding to the truncated current viewdate */
  protected void calcViewDateInterval() {

    switch (getDisplayMode()) {
      case DisplayMode.DAY:
        m_viewDateStart = Calendar.getInstance();
        m_viewDateStart.setTime(m_viewDate.getTime());
        m_viewDateEnd = (Calendar) m_viewDateStart.clone();
        m_viewDateEnd.set(Calendar.HOUR, 23);
        m_viewDateEnd.set(Calendar.MINUTE, 59);

        break;
      case DisplayMode.WEEK:
      case DisplayMode.WORKWEEK:

        // date start
        m_viewDateStart = Calendar.getInstance();
        m_viewDateStart.setTime(m_viewDate.getTime());
        // go back to first day of week
        m_viewDateStart.add(Calendar.DAY_OF_WEEK, -((m_viewDateStart.get(Calendar.DAY_OF_WEEK) - getFirstDayOfWeek() + 7) % 7));

        // date end
        m_viewDateEnd = Calendar.getInstance();
        m_viewDateEnd.setTime(m_viewDateStart.getTime());
        // add the corresponding number of days
        m_viewDateEnd.add(Calendar.DATE, getDisplayMode() == DisplayMode.WEEK ? 7 : 5);

        break;
      case DisplayMode.MONTH:

        // date start
        m_viewDateStart = Calendar.getInstance();
        m_viewDateStart.setTime(m_viewDate.getTime());
        //Calculate Startdate; go back to 1st of month, then back to 1st day of week (1=sunday)
        m_viewDateStart.add(Calendar.DAY_OF_MONTH, -(m_viewDateStart.get(Calendar.DAY_OF_MONTH) - 1));
        m_viewDateStart.add(Calendar.DAY_OF_WEEK, -((m_viewDateStart.get(Calendar.DAY_OF_WEEK) - getFirstDayOfWeek() + 7) % 7));

        // date end
        m_viewDateEnd = Calendar.getInstance();
        m_viewDateEnd.setTime(m_viewDateStart.getTime());
        // the month view shows 42 days, so add 41 days to start date
        m_viewDateEnd.add(Calendar.DATE, 41);

        break;
    }
  }

  /** shift view date, same semantic than Calendar.add */
  protected void shiftViewDate(int type, int amount) {
    shiftViewDate(type, amount, true);
  }

  /**
   * @param type
   * @param amount
   * @param fireNotification
   *          set false to avoid circular firing.
   * @since 07.02.2006 - tha@bsiag.com
   */
  protected void shiftViewDate(int type, int amount, boolean fireNotification) {
    m_viewDate.add(type, amount);

    // calc new start/end dates
    calcViewDateInterval();

    LOG.debug("new date: " + m_viewDate.getTime().toString());

  }

  /** set view date to the truncated date of now */
  public void setToday() {
    // set view date to now
    m_viewDate = truncDate(Calendar.getInstance());

    LOG.debug("new date: " + m_viewDate.getTime().toString());

    // calculate view date start/end
    calcViewDateInterval();

    // set selected date
    setSelectedDate(m_viewDate);

    refreshLayout();
  }

  /** set view date to the given calendar date, truncate it */
  public void setViewDate(Calendar c) {

    // null check
    if (c == null) {
      if (m_viewDate != null) {
        return;
      }
      c = Calendar.getInstance();
    }

    // changed?
    c = truncDate(c);
    if (m_viewDate.equals(c)) {
      return;
    }

    // for refresh
    boolean showingScopeChanged = changedViewDateInterval(c);

    // set view date
    m_viewDate = c;

    //logger.debug("new date: " + m_viewDate.getTime().toString());

    // calculate view date start/end
    calcViewDateInterval();

    if (showingScopeChanged) {
      refreshLayout();
    }

  }

  /** get view date, truncated */
  public Calendar getViewDate() {
    return m_viewDate;
  }

  /** get view date start, truncated */
  public Calendar getViewDateStart() {
    return m_viewDateStart;
  }

  /** get view date end, truncated */
  public Calendar getViewDateEnd() {
    return m_viewDateEnd;
  }

  public static Date truncDate(Date d) {
    Calendar c = Calendar.getInstance();
    c.setTime(d);
    return truncDate(c).getTime();
  }

  public static Calendar truncDate(Calendar c) {
    if (c == null) {
      return null;
    }
    c.set(Calendar.HOUR, 0);
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c;
  }

  public void prevDay() {
    shiftViewDate(Calendar.DATE, -1);
  }

  public void prevWeek() {
    shiftViewDate(Calendar.WEEK_OF_YEAR, -1);
  }

  public void prevMonth() {
    shiftViewDate(Calendar.MONTH, -1);
  }

  public void prevYear() {
    shiftViewDate(Calendar.YEAR, -1);
  }

  public void nextDay() {
    shiftViewDate(Calendar.DATE, 1);
  }

  public void nextWeek() {
    shiftViewDate(Calendar.WEEK_OF_YEAR, 1);
  }

  public void nextMonth() {
    shiftViewDate(Calendar.MONTH, 1);
  }

  public void nextYear() {
    shiftViewDate(Calendar.YEAR, 1);
  }

  /** set selection to the given date c */
  public void setSelectedDate(Calendar c) {
    c = truncDate(c);
    if (c != null) {
      m_selectedDate = c;
    }
  }

  public void setSelectedDateFromUI(Calendar c) {
    setSelectedDate(c);
  }

  /** update selection with the set selected date */
  public void updateSelection() {
    if (m_calendarPanel != null) {
      m_calendarPanel.updateSelection(m_selectedDate);
    }
  }

  public Calendar getSelectedDate() {
    return m_selectedDate;
  }

  public void fastBackward() {
    LOG.debug("fast backward");

    switch (m_selectionScope.getDisplayMode()) {
      case DisplayMode.MONTH:
        prevYear();
        break;
      case DisplayMode.WEEK:
      case DisplayMode.WORKWEEK:
        prevMonth();
        break;
      case DisplayMode.DAY:
      default:
        prevMonth();
    }
  }

  public void backward() {
    LOG.debug("backward");

    switch (m_selectionScope.getDisplayMode()) {
      case DisplayMode.MONTH:
        prevMonth();
        break;
      case DisplayMode.WEEK:
      case DisplayMode.WORKWEEK:
        prevWeek();
        break;
      case DisplayMode.DAY:
      default:
        prevDay();
    }
  }

  public void forward() {
    LOG.debug("forward");

    switch (m_selectionScope.getDisplayMode()) {
      case DisplayMode.MONTH:
        nextMonth();
        break;
      case DisplayMode.WEEK:
      case DisplayMode.WORKWEEK:
        nextWeek();
        break;
      case DisplayMode.DAY:
      default:
        nextDay();
    }
  }

  public void fastForward() {
    LOG.debug("fast forward");

    switch (m_selectionScope.getDisplayMode()) {
      case DisplayMode.MONTH:
        nextYear();
        break;
      case DisplayMode.WEEK:
      case DisplayMode.WORKWEEK:
        nextMonth();
        break;
      case DisplayMode.DAY:
      default:
        nextMonth();
    }
  }

  @Override
  public void dispose() {
    // dispose all contained swt widgets
    if (m_browserBar != null && !m_browserBar.isDisposed()) {
      m_browserBar.dispose();
    }

    if (m_centralComposite != null && !m_centralComposite.isDisposed()) {
      m_centralComposite.dispose();
    }

    if (m_calendarPanel != null && !m_calendarPanel.isDisposed()) {
      m_calendarPanel.dispose();
    }

    if (m_selectionScope != null && !m_selectionScope.isDisposed()) {
      m_selectionScope.dispose();
    }

    super.dispose();
  }
}

Back to the top