aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Hermsdorf2014-01-13 06:26:48 (EST)
committerPeter Hermsdorf2014-01-13 09:15:51 (EST)
commiteb6269b8cd0475e43a30fc116aa5cbf7d1adaa1e (patch)
tree07e38968f891b48b46301534c94538d04541ae57
parentaeb327460488be89e6e71edcce2cb9d0a1dc204b (diff)
downloadorg.eclipse.nebula-eb6269b8cd0475e43a30fc116aa5cbf7d1adaa1e.zip
org.eclipse.nebula-eb6269b8cd0475e43a30fc116aa5cbf7d1adaa1e.tar.gz
org.eclipse.nebula-eb6269b8cd0475e43a30fc116aa5cbf7d1adaa1e.tar.bz2
Bug 421320 add Tooltips to Holidays in the GanttChartrefs/changes/63/18363/6
the patch adds the ability to show a tooltip with the name/description of the holiday when the mouse hovers over it modifications: * introduce new holiday pojo * changes in the tooltip behaviour * added setter for the list of holidays to enable reuse of an already created GanttChart for different data sets * modified GanttTester to show Holidays Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=421320 Change-Id: I50c028a4f070fe58b34b758c841ac6f6ed5d95eb Signed-off-by: Peter Hermsdorf <peter.hermsdorf@godyo.com>
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractLanguageManager.java4
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractSettings.java4
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttChart.java41
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java63
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttTester.java46
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/Holiday.java77
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ILanguageManager.java7
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ISettings.java8
8 files changed, 234 insertions, 16 deletions
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractLanguageManager.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractLanguageManager.java
index 3c66024..1062cfe 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractLanguageManager.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractLanguageManager.java
@@ -99,4 +99,8 @@ public abstract class AbstractLanguageManager implements ILanguageManager {
public String getSectionDetailMoreText() {
return "More";
}
+
+ public String getHolidayText() {
+ return "Holiday";
+ }
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractSettings.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractSettings.java
index a038f4e..cca255b 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractSettings.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractSettings.java
@@ -574,4 +574,8 @@ public abstract class AbstractSettings implements ISettings {
public boolean showSectionDetailMore() {
return false;
}
+
+ public boolean showHolidayToolTips() {
+ return false;
+ }
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttChart.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttChart.java
index a910339..4226693 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttChart.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttChart.java
@@ -84,7 +84,7 @@ public class GanttChart extends Composite {
private IPaintManager _paintManager;
private ILanguageManager _languageManager;
- private Calendar[] _holidays;
+ private Holiday[] _holidays;
private GanttChartPrinter _printer;
@@ -102,7 +102,7 @@ public class GanttChart extends Composite {
* </ul>
*/
public GanttChart(final Composite parent, final int style) {
- this(parent, style, null, null, null, null);
+ this(parent, style, null);
}
/**
@@ -120,7 +120,7 @@ public class GanttChart extends Composite {
* </ul>
*/
public GanttChart(final Composite parent, final int style, final ISettings settings) {
- this(parent, style, settings, null, null, null);
+ this(parent, style, settings, null);
}
/**
@@ -139,7 +139,7 @@ public class GanttChart extends Composite {
* </ul>
*/
public GanttChart(final Composite parent, final int style, final ISettings settings, final IColorManager colorManager) {
- this(parent, style, settings, colorManager, null, null);
+ this(parent, style, settings, colorManager, null, null, new Calendar[]{});
}
/**
@@ -162,6 +162,29 @@ public class GanttChart extends Composite {
* </ul>
*/
public GanttChart(final Composite parent, final int style, final ISettings settings, final IColorManager colorManager, final IPaintManager paintManager, final ILanguageManager languageManager, Calendar... holidays) {
+ this(parent, style, settings, colorManager, paintManager, languageManager, convertToHolidays(holidays));
+ }
+
+ /**
+ * Constructs a new GANTT chart widget with custom settings, custom color manager {@link IColorManager}, a custom paint manager {@link IPaintManager} and a custom language
+ * manager {@link ILanguageManager}. If any of the managers is set to null the default manager using that implementation will be used. For styles, please see {@link GanttFlags}.
+ *
+ * @param parent Parent composite
+ * @param style Widget style
+ * @param settings ISettings implementation or null
+ * @param colorManager IColorManager implementation or null
+ * @param paintManager IPaintManager implementation or null
+ * @param languageManager {@link ILanguageManager} implementation or null
+ * @param holidays Holiday objects specifying holidays
+ * @throws IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @throws org.eclipse.swt.SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed
+ * subclass</li>
+ * </ul>
+ */
+ public GanttChart(final Composite parent, final int style, final ISettings settings, final IColorManager colorManager, final IPaintManager paintManager, final ILanguageManager languageManager, Holiday... holidays) {
super(parent, SWT.NONE);
int styleToUse = style;
@@ -233,6 +256,16 @@ public class GanttChart extends Composite {
_ganttComposite = new GanttComposite(this, _style, _settings, _colorManager, _paintManager, _languageManager, _holidays);
_ganttComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
}
+
+ private static Holiday[] convertToHolidays(Calendar[] holidays) {
+ Holiday[] list = new Holiday[holidays.length];
+
+ for (int i = 0; i < holidays.length; i++) {
+ list[i] = new Holiday(holidays[i]);
+ }
+ return list;
+ }
+
/**
* Adds a dependency between two events.
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java
index d7db698..7ceb3bd 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java
@@ -333,7 +333,7 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
private IEventMenuItemFactory eventMenuItemFactory;
private IMenuItemFactory menuItemFactory;
- private final Calendar[] holidays;
+ private Holiday[] holidays;
private IZoomHandler zoomHandler;
@@ -360,7 +360,7 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
this(parent, style, settings, colorManager, paintManager, languageManager, null);
}
- public GanttComposite(final GanttChart parent, final int style, final ISettings settings, final IColorManager colorManager, final IPaintManager paintManager, final ILanguageManager languageManager, final Calendar[] holidays) {
+ public GanttComposite(final GanttChart parent, final int style, final ISettings settings, final IColorManager colorManager, final IPaintManager paintManager, final ILanguageManager languageManager, final Holiday[] holidays) {
super(parent, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED | SWT.V_SCROLL | SWT.H_SCROLL);
_parentChart = parent;
@@ -427,6 +427,8 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
_undoRedoManager = new GanttUndoRedoManager(this, GanttUndoRedoManager.STACK_SIZE);
_drawToMinute = _settings.drawEventsDownToTheHourAndMinute();
+ this.holidays = holidays;
+
updateZoomLevel();
if (_currentView == ISettings.VIEW_D_DAY) {
@@ -452,7 +454,6 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
}
});
- this.holidays = holidays;
this.zoomHandler = this;
if (_settings.showSectionDetailMore()) {
@@ -1930,12 +1931,15 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
gc.fillGradientRectangle(startX, startY, dayWidth, heightY, true);
}
- if (isHoliday(temp)) {
+ Holiday h = getHoliday(temp);
+ if (h != null) {
gc.setForeground(getHolidayBackgroundGradient(true, gs));
gc.setBackground(getHolidayBackgroundGradient(false, gs));
// fill the whole thing all the way down
gc.fillGradientRectangle(startX, startY, dayWidth, heightY, true);
+
+ h.updateBounds(new Rectangle(startX, startY, dayWidth, heightY));
}
if (DateHelper.isToday(temp)) {
@@ -1957,19 +1961,17 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
}
-
- private boolean isHoliday(Calendar day) {
+ private Holiday getHoliday(Calendar day) {
if (holidays != null) {
- for (Calendar h : holidays) {
- if (h.equals(day)) {
- return true;
+ for (Holiday h : holidays) {
+ if (DateHelper.sameDate(day, h.getDate())) {
+ return h;
}
}
}
- return false;
+ return null;
}
-
// draws the zoom level box in the corner, only shown when zooming
private void drawZoomLevel(final GC gc) {
@@ -5406,6 +5408,13 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
final GanttEvent ge = (GanttEvent) objs[i];
ge.updateX(ge.getX() + (positive ? dw : -dw));
}
+
+ for (int i = 0; i < holidays.length; i++) {
+ final Holiday holiday = holidays[i];
+ if(holiday.getBounds() != null) {
+ holiday.updateX(holiday.getBounds().x + (positive ? dw : -dw));
+ }
+ }
}
/*private void moveXBounds(int move) {
@@ -5426,6 +5435,13 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
final GanttEvent ge = (GanttEvent) objs[i];
ge.updateY(ge.getY() - move);
}
+
+ for (int i = 0; i < holidays.length; i++) {
+ final Holiday holiday = holidays[i];
+ if(holiday.getBounds() != null) {
+ holiday.updateY(holiday.getBounds().y -move);
+ }
+ }
_visibleBounds.y += move;
@@ -8020,6 +8036,15 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
showTooltip(event, me);
return;
}
+
+ if (_settings.showHolidayToolTips()) {
+ for (Holiday holiday : holidays) {
+ if (holiday.hasTooltip() && isInside(me.x, me.y, holiday.getBounds())) {
+ showTooltip(holiday, me);
+ return;
+ }
+ }
+ }
}
}
}
@@ -8195,6 +8220,14 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
return null;
}
+
+ private void showTooltip(Holiday holiday, MouseEvent me) {
+ int xPlus = 0;
+
+ Point displayLocation = super.toDisplay(new Point(me.x + xPlus, me.y));
+ GanttToolTip.makeDialog(_colorManager, _languageManager.getHolidayText(), holiday.getTooltip(), displayLocation);
+ }
+
/**
* Returns a rectangle with the bounds of what is actually visible inside the chart.
@@ -8559,6 +8592,10 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
if (dDay) {
_currentView = ISettings.VIEW_D_DAY;
}
+
+ for (Holiday holiday : holidays) {
+ holiday.resetBounds();
+ }
}
/**
@@ -8963,4 +9000,8 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
public void removeSelectionDetailClickListener(ISectionDetailMoreClickListener listener) {
this.sectionDetailMoreClickListener.remove(listener);
}
+
+ public void setHolidays(Holiday[] holidays) {
+ this.holidays = holidays;
+ }
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttTester.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttTester.java
index 198f84f..3c2782c 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttTester.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttTester.java
@@ -11,6 +11,7 @@
package org.eclipse.nebula.widgets.ganttchart;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
@@ -77,6 +78,7 @@ public class GanttTester {
private Button _bIncreaseDates;
private Button _bCreate;
private Button _bCreatePlannedDates;
+ private Button _bShowHolidays;
private Button _bUndo;
private Button _bRedo;
private Button _bRandomEventLength;
@@ -687,6 +689,15 @@ public class GanttTester {
_bDrawHorizontalLines.setData(KEY, "bDrawHorizontalLines");
prefLoad(_bDrawHorizontalLines);
prefHook(_bDrawHorizontalLines);
+
+ _bShowHolidays = new Button(gLeft, SWT.CHECK);
+ _bShowHolidays.setText("Show Holidays");
+ _bShowHolidays.setSelection(false);
+ _bShowHolidays.setToolTipText("Draw Holidays in Chart");
+ _bShowHolidays.setData(KEY, "bShowHolidays");
+ prefLoad(_bShowHolidays);
+ prefHook(_bShowHolidays);
+
final Group sections = new Group(gLeft, SWT.NONE);
sections.setText("Use GanttSections");
@@ -1285,6 +1296,36 @@ public class GanttTester {
}
}
}
+
+ if(_bShowHolidays.getSelection()) {
+ Calendar start = Calendar.getInstance();
+ Calendar end = Calendar.getInstance();
+
+ for(int i = 0; i < _ganttComposite.getEvents().size(); i++) {
+ GanttEvent event = (GanttEvent) _ganttComposite.getEvents().get(i);
+ if(event.getActualStartDate().before(start)) {
+ start = event.getActualStartDate();
+ }
+ if(event.getActualEndDate().after(end)) {
+ end = event.getActualEndDate();
+ }
+ }
+ List<Holiday> holidays = new ArrayList<Holiday>();
+ Calendar day = Calendar.getInstance();
+ day.setTime(start.getTime());
+
+ int i = 1;
+ while(day.before(end)) {
+ day.add(Calendar.DATE, 5 + r.nextInt(5));
+ int dow = day.get(Calendar.DAY_OF_WEEK);
+
+ if (dow != Calendar.SATURDAY && dow != Calendar.SUNDAY) {
+ Calendar date = (Calendar) day.clone();
+ holidays.add(new Holiday(date, "Special free Day " + i++));
+ }
+ }
+ _ganttComposite.setHolidays(holidays.toArray(new Holiday[holidays.size()]));
+ }
final long time2 = System.currentTimeMillis();
_timerText.setText("Initial chart creation took " + (time2 - time1) + " ms");
@@ -1911,8 +1952,11 @@ public class GanttTester {
public boolean allowArrowKeysToScrollChart() {
return _bAllowArrowKeysToMoveChart.getSelection();
}
-
+ @Override
+ public boolean showHolidayToolTips() {
+ return _bShowHolidays.getSelection();
+ }
}
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/Holiday.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/Holiday.java
new file mode 100644
index 0000000..6036643
--- /dev/null
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/Holiday.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2013 GODYO Business Solutions AG and others.
+ * 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:
+ * Peter Hermsdorf - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.nebula.widgets.ganttchart;
+
+import java.util.Calendar;
+
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * One Holiday Object represents one Holiday/Spare/Special Day in the GANTT chart.<br>
+ * <br>
+ * This object can take an additional tooltip which pops up when hovering the mouse over a holiday.<br>
+ * <br>
+ * The Tooltip is only displayed when the tooltip is not null and {@link ISettings#showHolidayToolTips()}
+ * is configured to return true.
+ * <br>
+ *
+ */
+public class Holiday {
+
+ private final Calendar date;
+ private final String tooltip;
+ private Rectangle bounds;
+
+ public Holiday(Calendar date) {
+ this(date, null);
+ }
+
+ public Holiday(Calendar date, String tooltip) {
+ this.date = date;
+ this.tooltip = tooltip;
+ }
+
+ void resetBounds() {
+ bounds = null;
+ }
+
+ void updateBounds(Rectangle rec) {
+ if(bounds == null) {
+ bounds = rec;
+ }else {
+ this.bounds = bounds.union(rec);
+ }
+ }
+
+ Rectangle getBounds() {
+ return bounds;
+ }
+
+ public String getTooltip() {
+ return tooltip;
+ }
+
+ public Calendar getDate() {
+ return date;
+ }
+
+ public void updateX(int x) {
+ bounds.x = x;
+ }
+
+ public void updateY(int y) {
+ bounds.y = y;
+ }
+
+ public boolean hasTooltip() {
+ return tooltip != null;
+ }
+}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ILanguageManager.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ILanguageManager.java
index f0a7af4..f3579dd 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ILanguageManager.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ILanguageManager.java
@@ -173,4 +173,11 @@ public interface ILanguageManager {
* @return Text
*/
String getSectionDetailMoreText();
+
+ /**
+ * The default text that gets rendered in the Tooltip for Holidays
+ *
+ * @return Text
+ */
+ String getHolidayText();
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ISettings.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ISettings.java
index 137ebc9..0473464 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ISettings.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ISettings.java
@@ -1218,4 +1218,12 @@ public interface ISettings {
* informations by e.g. opening a dialog.
*/
public boolean showSectionDetailMore();
+
+ /**
+ * Configure whether a tooltip pops up when hovering the mouse over a holiday
+ *
+ * @return <code>true</code> to show a "holiday" popup with the configured name of the holiday,
+ * <code>false</code> if not (default)
+ */
+ public boolean showHolidayToolTips();
}