aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Fauth2013-07-25 11:27:19 (EDT)
committerDirk Fauth2013-07-25 11:27:19 (EDT)
commit9e55389741155975abef4ad2e021e434ee290c14 (patch)
tree7946f1fcbf54fd40ce5528c7a28b7f7ab29ce11e
parent1ffec0314e1737879c63738abaf94bf7c468869b (diff)
downloadorg.eclipse.nebula-9e55389741155975abef4ad2e021e434ee290c14.zip
org.eclipse.nebula-9e55389741155975abef4ad2e021e434ee290c14.tar.gz
org.eclipse.nebula-9e55389741155975abef4ad2e021e434ee290c14.tar.bz2
Bug 413748 - Add the possibility to add events via context menu to the
GanttChart. This feature can be enabled via ISettings. If enabled the context menu of the GanttChart will contain a new menu item for adding an event. How it should look like can be configured via the newly introduced IEventFactory.
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractLanguageManager.java6
-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/DefaultEventFactory.java35
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java69
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IEventFactory.java36
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ILanguageManager.java14
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ISettings.java12
7 files changed, 176 insertions, 0 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 ea7c425..7a04b49 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
@@ -80,6 +80,12 @@ public abstract class AbstractLanguageManager implements ILanguageManager {
return "Reset Zoom Level";
}
+ public String getAddEventMenuText() {
+ return "Add event";
+ }
+ public String getNewEventDefaultText() {
+ return "Event";
+ }
}
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 084bf53..0eb06e5 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
@@ -527,6 +527,10 @@ public abstract class AbstractSettings implements ISettings {
return false;
}
+ public boolean enableAddEvent() {
+ return false;
+ }
+
public boolean drawEventString() {
return true;
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/DefaultEventFactory.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/DefaultEventFactory.java
new file mode 100644
index 0000000..60041ed
--- /dev/null
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/DefaultEventFactory.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Dirk Fauth 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:
+ * Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.nebula.widgets.ganttchart;
+
+import java.util.Calendar;
+
+public class DefaultEventFactory implements IEventFactory {
+
+ public GanttEvent createGanttEvent(
+ GanttChart parent,
+ GanttSection gs,
+ String name,
+ Calendar start,
+ Calendar end) {
+
+ GanttEvent newEvent = new GanttEvent(parent, name, start, end, 0);
+ newEvent.setStatusColor(ColorCache.getColor(24, 43, 69));
+
+ //add event to section
+ if (gs != null) {
+ gs.addGanttEvent(newEvent);
+ }
+
+ return newEvent;
+ }
+
+}
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 45648a6..262bbde 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
@@ -326,6 +326,7 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
private int _daysToAppendForEndOfDay;
+ private IEventFactory eventFactory = new DefaultEventFactory();
private final Calendar[] holidays;
private IZoomHandler zoomHandler;
@@ -1444,6 +1445,31 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
_rightClickMenu = new Menu(getDisplay().getActiveShell(), SWT.POP_UP);
+
+ //add new event
+ if (event == null && _settings.enableAddEvent()) {
+ final MenuItem addEvent = new MenuItem(_rightClickMenu, SWT.PUSH);
+ addEvent.setText(_languageManager.getAddEventMenuText());
+ addEvent.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(final Event event) {
+ //add event to chart
+ Calendar start = getDateAt(me.x);
+ Calendar end = getDateAt(me.x);
+ end.add(Calendar.DATE, 1);
+
+ addEvent(eventFactory.createGanttEvent(
+ _parentChart,
+ getSectionAt(me),
+ _languageManager.getNewEventDefaultText(),
+ start,
+ end));
+ }
+ });
+
+ new MenuItem(_rightClickMenu, SWT.SEPARATOR);
+ }
+
+
if (event != null) {
// We can't use JFace actions.. so we need to make copies.. Dirty
// but at least not reinventing a wheel (as much)
@@ -6100,6 +6126,46 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
}
/**
+ * Returns a section that corresponds to where the given MouseEvent is fired
+ *
+ * @param event MouseEvent to check
+ * @return Section it is over or null if none
+ */
+ public GanttSection getSectionAt(final MouseEvent me) {
+ if (!hasGanttSections()) { return null; }
+
+ for (int i = 0; i < _ganttSections.size(); i++) {
+ final GanttSection gs = (GanttSection) _ganttSections.get(i);
+
+ // must account for scroll position as the event itself has no clue there's a scrollbar and obviously doesn't account for it
+ if (gs.getBounds().contains(me.x, me.y + _vScrollPos)) { return gs; }
+ }
+
+ // if we get here, we had a null hit, which means we might be between two sections, make it easy, check if we're oob first
+ if (me.y < getHeaderHeight()) {
+ // we could return null but that's not a good idea, rather, lets tell the target it's in the first section
+ return (GanttSection) _ganttSections.get(0);
+ }
+
+ // ok, we're not oob at the top, so we're probably between two, easy check
+ for (int i = 0; i < _ganttSections.size(); i++) {
+ final GanttSection gs = (GanttSection) _ganttSections.get(i);
+ GanttSection next = null;
+ if (i != _ganttSections.size() - 1) {
+ next = (GanttSection) _ganttSections.get(i + 1);
+
+ if (next != null) {
+ if (me.y >= (gs.getBounds().y + gs.getBounds().height) && me.y <= next.getBounds().y) {
+ return gs;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
* Returns a list of all surrounding vertical events to a given event. If a GanttSection is given, only the events
* in that section will be used in calculating.
*
@@ -8590,6 +8656,9 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
return _settings;
}
+ public void setEventFactory(IEventFactory factory) {
+ this.eventFactory = factory;
+ }
public void setZoomHandler(IZoomHandler zoomHandler) {
this.zoomHandler = zoomHandler;
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IEventFactory.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IEventFactory.java
new file mode 100644
index 0000000..9d05546
--- /dev/null
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IEventFactory.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Dirk Fauth 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:
+ * Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.nebula.widgets.ganttchart;
+
+import java.util.Calendar;
+
+public interface IEventFactory {
+
+ /**
+ * Creates a new GanttEvent and adds it to the given GanttChart.
+ * If a GanttSection is specified, it is directly added to the
+ * GanttSection aswell.
+ * @param parent The GanttChart to add the GanttEvent to.
+ * @param gs The GanttSection to add the GanttEvent to.
+ * Can be <code>null</code>.
+ * @param name The name that should be set to the GanttEvent.
+ * @param start The start date of the GanttEvent.
+ * @param end The end date of the GanttEvent.
+ * @return The newly created GanttEvent that was added to the
+ * GanttChart.
+ */
+ GanttEvent createGanttEvent(
+ GanttChart parent,
+ GanttSection gs,
+ String name,
+ Calendar start,
+ Calendar end);
+}
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 bae8d17..57f705b 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
@@ -137,4 +137,18 @@ public interface ILanguageManager {
* @return Text
*/
String getNotAvailableText();
+
+ /**
+ * The menu item text for the "Add event" menu item
+ *
+ * @return Text
+ */
+ String getAddEventMenuText();
+
+ /**
+ * The default text for new created events
+ *
+ * @return Text
+ */
+ String getNewEventDefaultText();
}
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 62c21d4..d8c0fc9 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
@@ -1107,6 +1107,18 @@ public interface ISettings {
*/
public boolean shiftHorizontalCenteredEventString();
+ /**
+ * @return <code>true</code> to enable the menu action for adding an event to the GanttChart,
+ * <code>false</code> if this action should not be available to the user.
+ */
+ public boolean enableAddEvent();
+
+ /**
+ * Global configuration to specify if the text of GanttEvents should be rendered or not.
+ * It is also possible to configure this per GanttEvent via _showText property.
+ * @return <code>true</code> if the event text should be rendered, <code>false</code>
+ * if not.
+ */
public boolean drawEventString();
/**