diff options
author | Dirk Fauth | 2013-07-26 08:08:38 -0400 |
---|---|---|
committer | Dirk Fauth | 2013-07-26 08:08:38 -0400 |
commit | e3130e1378435ab4e250dad5594930d20c9c4ad0 (patch) | |
tree | de627b78864284b10e221826f5665fe6c5e00f62 | |
parent | 9e55389741155975abef4ad2e021e434ee290c14 (diff) | |
download | org.eclipse.nebula-e3130e1378435ab4e250dad5594930d20c9c4ad0.zip org.eclipse.nebula-e3130e1378435ab4e250dad5594930d20c9c4ad0.tar.gz org.eclipse.nebula-e3130e1378435ab4e250dad5594930d20c9c4ad0.tar.xz |
Bug 413804 - Add possibility to add custom menu items to the context
menu of the GanttChart in general and the context menu of GanttEvents
3 files changed, 102 insertions, 20 deletions
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 262bbde..4b08f8f 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 @@ -327,6 +327,9 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse private IEventFactory eventFactory = new DefaultEventFactory(); + private IEventMenuItemFactory eventMenuItemFactory; + private IMenuItemFactory menuItemFactory; + private final Calendar[] holidays; private IZoomHandler zoomHandler; @@ -1447,30 +1450,44 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse //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) { + if (_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); + } + + // add custom actions + if (menuItemFactory != null) { + menuItemFactory.addCustomMenuItems(_rightClickMenu); + new MenuItem(_rightClickMenu, SWT.SEPARATOR); + } } if (event != null) { + // add custom actions + if (eventMenuItemFactory != null) { + eventMenuItemFactory.addCustomMenuItems(_rightClickMenu, event); + new MenuItem(_rightClickMenu, SWT.SEPARATOR); + } + // We can't use JFace actions.. so we need to make copies.. Dirty // but at least not reinventing a wheel (as much) final Menu eventMenu = event.getMenu(); @@ -8659,6 +8676,15 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse public void setEventFactory(IEventFactory factory) { this.eventFactory = factory; } + + public void setEventMenuItemFactory(IEventMenuItemFactory factory) { + this.eventMenuItemFactory = factory; + } + + public void setMenuItemFactory(IMenuItemFactory factory) { + this.menuItemFactory = 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/IEventMenuItemFactory.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IEventMenuItemFactory.java new file mode 100644 index 0000000..34fff3c --- /dev/null +++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IEventMenuItemFactory.java @@ -0,0 +1,28 @@ +/*******************************************************************************
+ * 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 org.eclipse.swt.widgets.Menu;
+
+/**
+ * Interface for a factory that creates menu items in the context menu of a
+ * GanttEvent in the GanttChart.
+ */
+public interface IEventMenuItemFactory {
+
+ /**
+ * Adds new custom menu items to the context menu of a GanttEvent
+ * in the GanttChart.
+ * @param menu The menu to add the custom actions to.
+ * @param ganttEvent The GanttEvent for which the menu is opened
+ */
+ void addCustomMenuItems(final Menu menu, final GanttEvent ganttEvent);
+}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IMenuItemFactory.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IMenuItemFactory.java new file mode 100644 index 0000000..1c0c2e4 --- /dev/null +++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IMenuItemFactory.java @@ -0,0 +1,28 @@ +/*******************************************************************************
+ * 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 org.eclipse.swt.widgets.Menu;
+
+/**
+ * Interface for a factory that creates menu items in the context menu of the GanttChart.
+ * Note that this factory will only add the menu items in case the context menu is
+ * NOT opened for a GanttEvent. If you want to add custom menu items for the context
+ * menu you need to use the IEventMenuItemFactory.
+ */
+public interface IMenuItemFactory {
+
+ /**
+ * Adds new custom menu items to the context menu of the GanttChart.
+ * @param menu The menu to add the custom actions to.
+ */
+ void addCustomMenuItems(final Menu menu);
+}
|