REOPENED - bug 329897: [patch] Add configuration icon to service message dialog
https://bugs.eclipse.org/bugs/show_bug.cgi?id=329897
diff --git a/org.eclipse.mylyn.commons.notifications/src/org/eclipse/mylyn/internal/commons/ui/notifications/NotificationsPreferencesPage.java b/org.eclipse.mylyn.commons.notifications/src/org/eclipse/mylyn/internal/commons/ui/notifications/NotificationsPreferencesPage.java
index 5e11f11..ee67764 100644
--- a/org.eclipse.mylyn.commons.notifications/src/org/eclipse/mylyn/internal/commons/ui/notifications/NotificationsPreferencesPage.java
+++ b/org.eclipse.mylyn.commons.notifications/src/org/eclipse/mylyn/internal/commons/ui/notifications/NotificationsPreferencesPage.java
@@ -7,9 +7,13 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
+ * Itema AS - Select event type on open if available. Bug #329897
*******************************************************************************/
package org.eclipse.mylyn.internal.commons.ui.notifications;
+import java.util.Collection;
+import java.util.List;
+
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -19,6 +23,7 @@
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ICheckStateProvider;
+import org.eclipse.jface.viewers.IElementComparer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -48,9 +53,33 @@
/**
* @author Steffen Pingel
+ * @author Torkild Ulvøy Resheim
*/
public class NotificationsPreferencesPage extends PreferencePage implements IWorkbenchPreferencePage {
+ /**
+ * We need this in order to make sure that the correct element is selected in the {@link TreeViewer} when the
+ * selection is set.
+ *
+ * @author Torkild Ulvøy Resheim
+ */
+ public class NotificationEventComparer implements IElementComparer {
+
+ public boolean equals(Object a, Object b) {
+ if (a instanceof NotificationEvent && b instanceof NotificationEvent) {
+ String idA = ((NotificationEvent) a).getId();
+ String idB = ((NotificationEvent) b).getId();
+ return (idA.equals(idB));
+ }
+ return a.equals(b);
+ }
+
+ public int hashCode(Object element) {
+ return element.hashCode();
+ }
+
+ }
+
private static final Object[] EMPTY = new Object[0];
private final class EventContentProvider implements ITreeContentProvider {
@@ -198,6 +227,7 @@
FilteredTree tree = new FilteredTree(composite, SWT.BORDER, new SubstringPatternFilter(), true);
eventsViewer = tree.getViewer();
GridDataFactory.fillDefaults().span(1, 2).grab(false, true).applyTo(tree);
+ eventsViewer.setComparer(new NotificationEventComparer());
eventsViewer.setContentProvider(new EventContentProvider());
eventsViewer.setLabelProvider(new NotificationLabelProvider());
eventsViewer.setInput(model.getCategories().toArray());
@@ -269,6 +299,30 @@
return composite;
}
+ @Override
+ public void applyData(Object data) {
+ // We may or may not have a NotificationEvent supplied when this
+ // preference dialog is opened. If we do have this data we want to
+ // highlight the appropriate instance.
+ if (data instanceof String) {
+ String selectedEventId = (String) data;
+ Collection<NotificationCategory> items = model.getCategories();
+ NotificationEvent selectedEvent = null;
+ for (NotificationCategory notificationCategory : items) {
+ List<NotificationEvent> event = notificationCategory.getEvents();
+ for (NotificationEvent notificationEvent : event) {
+ if (notificationEvent.getId().equals(selectedEventId)) {
+ selectedEvent = notificationEvent;
+ break;
+ }
+ }
+ }
+ if (selectedEvent != null) {
+ eventsViewer.setSelection(new StructuredSelection(selectedEvent), true);
+ }
+ }
+ }
+
private void updateEnablement() {
boolean enabled = enableNotificationsButton.getSelection();
eventsViewer.getControl().setEnabled(enabled);
diff --git a/org.eclipse.mylyn.commons.ui/icons/etool16/notification-configure-active.gif b/org.eclipse.mylyn.commons.ui/icons/etool16/notification-configure-active.gif
new file mode 100644
index 0000000..0d14fc2
--- /dev/null
+++ b/org.eclipse.mylyn.commons.ui/icons/etool16/notification-configure-active.gif
Binary files differ
diff --git a/org.eclipse.mylyn.commons.ui/icons/etool16/notification-configure.gif b/org.eclipse.mylyn.commons.ui/icons/etool16/notification-configure.gif
new file mode 100644
index 0000000..51e32c6
--- /dev/null
+++ b/org.eclipse.mylyn.commons.ui/icons/etool16/notification-configure.gif
Binary files differ
diff --git a/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImages.java b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImages.java
index 5b86fe9..8e57069 100644
--- a/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImages.java
+++ b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImages.java
@@ -261,6 +261,11 @@
public static final ImageDescriptor VALIDATE = create(T_OBJ, "resource_obj.gif"); //$NON-NLS-1$
+ public static final ImageDescriptor NOTIFICATION_CONFIGURE = create(T_TOOL, "notification-configure.gif"); //$NON-NLS-1$;
+
+ public static final ImageDescriptor NOTIFICATION_CONFIGURE_HOVER = create(T_TOOL,
+ "notification-configure-active.gif"); //$NON-NLS-1$;
+
private static ImageDescriptor create(String prefix, String name) {
try {
return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
diff --git a/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/ServiceMessageControl.java b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/ServiceMessageControl.java
index 25bc637..0fc5437 100644
--- a/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/ServiceMessageControl.java
+++ b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/ServiceMessageControl.java
@@ -8,10 +8,12 @@
* Contributors:
* Tasktop Technologies - initial API and implementation
* Itema AS - Refactored into commons
+ * Itema AS - Added configure button, bug #329897
*******************************************************************************/
package org.eclipse.mylyn.internal.provisional.commons.ui;
+import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
@@ -28,6 +30,7 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.forms.FormColors;
import org.eclipse.ui.forms.IFormColors;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
@@ -47,6 +50,8 @@
*/
public abstract class ServiceMessageControl {
+ private static final String NOTIFICATIONS_PREF_PAGE = "org.eclipse.mylyn.commons.notifications.preferencePages.Notifications";
+
protected static Font setHeaderFontSizeAndStyle(Control text) {
float sizeFactor = 1.2f;
Font initialFont = text.getFont();
@@ -79,6 +84,8 @@
private ImageHyperlink closeLink;
+ private ImageHyperlink configureLink;
+
private Link descriptionLabel;
private GradientCanvas head;
@@ -91,6 +98,8 @@
private Label titleLabel;
+ private String eventId;
+
public ServiceMessageControl(Composite parent) {
this.parent = parent;
}
@@ -201,6 +210,31 @@
// settingsLink.setImage(CommonImages.getImage(CommonImages.NOTIFICATION_PREFERENCES));
// }
// });
+ configureLink = new ImageHyperlink(buttonsComp, SWT.NONE);
+ configureLink.setImage(CommonImages.getImage(CommonImages.NOTIFICATION_CONFIGURE));
+ configureLink.addHyperlinkListener(new HyperlinkAdapter() {
+ @Override
+ public void linkEntered(HyperlinkEvent e) {
+ configureLink.setImage(CommonImages.getImage(CommonImages.NOTIFICATION_CONFIGURE_HOVER));
+ }
+
+ @Override
+ public void linkExited(HyperlinkEvent e) {
+ configureLink.setImage(CommonImages.getImage(CommonImages.NOTIFICATION_CONFIGURE));
+ }
+
+ @Override
+ public void linkActivated(HyperlinkEvent e) {
+ PreferenceDialog pd = PreferencesUtil.createPreferenceDialogOn(getShell(), NOTIFICATIONS_PREF_PAGE,
+ new String[0], eventId);
+ // Only close the message if the did not cancel the operation
+ if (pd != null) {
+ pd.open();
+ }
+ }
+ });
+ // Initially invisible, must have eventId for this to be of any use.
+ configureLink.setVisible(eventId != null);
closeLink = new ImageHyperlink(buttonsComp, SWT.NONE);
closeLink.setImage(CommonImages.getImage(CommonImages.NOTIFICATION_CLOSE));
@@ -263,6 +297,19 @@
}
/**
+ * Sets the eventId of the message being displayed. How to handle certain kind of messages can be configured in
+ * preference settings if this property is set to a legal value. The event identifiers are declared using the
+ * <i>org.eclipse.mylyn.commons.notifications.notifications</i> extension point.
+ *
+ * @param eventId
+ * the event identifier for the displayed message
+ */
+ protected void setEventId(String eventId) {
+ this.eventId = eventId;
+ configureLink.setVisible(eventId != null);
+ }
+
+ /**
* Sets the title image of the control.
*
* @param image