diff options
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org')
23 files changed, 365 insertions, 925 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/activator/UIPlugin.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/activator/UIPlugin.java index 3712b8089..256b5b5cb 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/activator/UIPlugin.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/activator/UIPlugin.java @@ -16,9 +16,8 @@ import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.swt.graphics.Image; import org.eclipse.tcf.te.runtime.tracing.TraceHandler; import org.eclipse.tcf.te.ui.notifications.interfaces.ImageConsts; -import org.eclipse.tcf.te.ui.notifications.internal.NotificationModel; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.forms.FormColors; +import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -31,10 +30,8 @@ public class UIPlugin extends AbstractUIPlugin { // The trace handler instance private static volatile TraceHandler traceHandler; - private volatile NotificationModel model; - - // The form colors instance - private volatile FormColors formColors = null; + // The form toolkit instance + private volatile FormToolkit formToolkit = null; /** * The constructor @@ -74,28 +71,15 @@ public class UIPlugin extends AbstractUIPlugin { } /** - * Returns the notification model instance. - * - * @return The notification model. - */ - public NotificationModel getModel() { - if (model == null) { - model = new NotificationModel(); - } - return model; - } - - /** - * Returns a form colors instance. + * Returns a form toolkit instance. * - * @return The form colors instance. + * @return The form toolkit instance. */ - public FormColors getFormColors() { - if (formColors == null) { - formColors = new FormColors(PlatformUI.getWorkbench().getDisplay()); - formColors.markShared(); + public FormToolkit getFormToolkit() { + if (formToolkit == null) { + formToolkit = new FormToolkit(PlatformUI.getWorkbench().getDisplay()); } - return formColors; + return formToolkit; } /* (non-Javadoc) @@ -112,9 +96,9 @@ public class UIPlugin extends AbstractUIPlugin { */ @Override public void stop(BundleContext context) throws Exception { - if (formColors != null) { - formColors.dispose(); - formColors = null; + if (formToolkit != null) { + formToolkit.dispose(); + formToolkit = null; } plugin = null; traceHandler = null; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/interfaces/IFormTextFactoryDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/interfaces/IFormTextFactoryDelegate.java new file mode 100644 index 000000000..44c9ecd14 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/interfaces/IFormTextFactoryDelegate.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2013 Wind River Systems, Inc. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.ui.notifications.interfaces; + +import org.eclipse.tcf.te.runtime.events.NotifyEvent; +import org.eclipse.ui.forms.widgets.FormText; +import org.eclipse.ui.forms.widgets.FormToolkit; + + +/** + * Interface to be implemented by notification form text factory delegates. + */ +public interface IFormTextFactoryDelegate { + + /** + * Populate the given form text widget based on the given notification event. + * <p> + * See {@link FormText} for details. + * + * @param toolkit The form toolkit. Must not be <code>null</code>. + * @param widget The form text widget. Must not be <code>null</code>. + * @param event The notification event. Must not be <code>null</code>. + */ + public void populateFormText(FormToolkit toolkit, FormText widget, NotifyEvent event); +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationAction.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationAction.java deleted file mode 100644 index 34f46ac55..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2013 Tasktop Technologies 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: - * Tasktop Technologies - initial API and implementation - * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer - *******************************************************************************/ - -package org.eclipse.tcf.te.ui.notifications.internal; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.tcf.te.runtime.notifications.NotificationSink; - -/** - * Describes how a {@link NotificationEvent} is handled. {@link NotificationAction}s store enablement and parameters - * that determine how the {@link NotificationSink} executes the action. - * - * @author Steffen Pingel - */ -public class NotificationAction { - - private boolean selected; - - private final NotificationSinkDescriptor sinkDescriptor; - - public NotificationAction(NotificationSinkDescriptor sinkDescriptor) { - Assert.isNotNull(sinkDescriptor); - this.sinkDescriptor = sinkDescriptor; - } - - public NotificationSinkDescriptor getSinkDescriptor() { - return sinkDescriptor; - } - - public boolean isSelected() { - return selected; - } - - public void setSelected(boolean selected) { - this.selected = selected; - } - - @Override - public String toString() { - return sinkDescriptor.getLabel(); - } - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationCategory.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationCategory.java deleted file mode 100644 index c9a261922..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationCategory.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2013 Tasktop Technologies 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: - * Tasktop Technologies - initial API and implementation - * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer - *******************************************************************************/ - -package org.eclipse.tcf.te.ui.notifications.internal; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IConfigurationElement; - -/** - * @author Steffen Pingel - */ -public class NotificationCategory extends NotificationElement { - - private final List<NotificationEvent> events; - - public NotificationCategory(IConfigurationElement element) { - super(element); - this.events = new ArrayList<NotificationEvent>(); - } - - public void addEvent(NotificationEvent event) { - event.setCategory(this); - events.add(event); - } - - public List<NotificationEvent> getEvents() { - return events; - } - - public void removeEvent(NotificationEvent event) { - event.setCategory(null); - events.remove(event); - } - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationElement.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationElement.java deleted file mode 100644 index 7de3b44ee..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationElement.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2013 Tasktop Technologies 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: - * Tasktop Technologies - initial API and implementation - * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer - *******************************************************************************/ - -package org.eclipse.tcf.te.ui.notifications.internal; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.osgi.util.NLS; -import org.eclipse.tcf.te.ui.notifications.activator.UIPlugin; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -/** - * @author Steffen Pingel - */ -public class NotificationElement { - - protected final IConfigurationElement element; - - private ImageDescriptor iconDescriptor; - - private final String id; - - private final String label; - - public NotificationElement(IConfigurationElement element) { - Assert.isNotNull(element); - this.element = element; - this.id = element.getAttribute("id"); //$NON-NLS-1$ - this.label = element.getAttribute("label"); //$NON-NLS-1$ - } - - public String getId() { - return id; - } - - public ImageDescriptor getImageDescriptor() { - if (iconDescriptor == null) { - if (element != null) { - String iconPath = element.getAttribute("icon"); //$NON-NLS-1$ - if (iconPath != null) { - iconDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(element.getContributor().getName(), iconPath); - } - } - } - return iconDescriptor; - } - - public String getLabel() { - return label; - } - - public String getPluginId() { - return element.getContributor().getName(); - } - - public IStatus validate() { - if (id == null) { - return new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), - NLS.bind("Extension {0} contributed by {1} does not specify id attribute", element.getNamespaceIdentifier(), getPluginId())); //$NON-NLS-1$ - } - else if (label == null) { - return new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), - NLS.bind("Extension {0} contributed by {1} does not specify label attribute", element.getNamespaceIdentifier(), getPluginId())); //$NON-NLS-1$ - } - return Status.OK_STATUS; - } - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationEvent.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationEvent.java deleted file mode 100644 index 195072533..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationEvent.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2013 Tasktop Technologies 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: - * Tasktop Technologies - initial API and implementation - * Itema AS - bug 331424 handle default event-sink action associations - * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer - *******************************************************************************/ - -package org.eclipse.tcf.te.ui.notifications.internal; - -import java.util.ArrayList; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.tcf.te.runtime.notifications.NotificationSink; - -/** - * Describes an event that is handled through a notification. The handling of event is stored in - * {@link NotificationAction} objects that delegate to {@link NotificationSink} objects for the handling of actual - * events. - * - * @author Steffen Pingel - * @author Torkild U. Resheim - */ -public class NotificationEvent extends NotificationElement { - - private static final String EXTENSION_POINT_ID = "org.eclipse.tcf.te.ui.notifications.notifications"; //$NON-NLS-1$ - - private NotificationCategory category; - - private final ArrayList<String> defaultSinks; - - /** - * Tests whether or not the event should per default be handled by the sink with the specified identifier. - * - * @param sinkId - * the sink identifier - * @return <code>true</code> if the - */ - public boolean defaultHandledBySink(String sinkId) { - if (defaultSinks.isEmpty() || defaultSinks.contains(sinkId)) { - return true; - } - return false; - } - - public NotificationEvent(IConfigurationElement element) { - super(element); - defaultSinks = new ArrayList<String>(); - IConfigurationElement[] children = element.getChildren("defaultHandler"); //$NON-NLS-1$ - for (IConfigurationElement child : children) { - defaultSinks.add(child.getAttribute("sinkId")); //$NON-NLS-1$ - } - doEventMappings(); - } - - private void doEventMappings() { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint point = registry.getExtensionPoint(EXTENSION_POINT_ID); - if (point != null) { - IConfigurationElement[] elements = point.getConfigurationElements(); - for (IConfigurationElement mapping : elements) { - if (mapping.getName().equals("eventMapping")) { //$NON-NLS-1$ - String eventIds = mapping.getAttribute("eventIds"); //$NON-NLS-1$ - String[] list = eventIds.split(","); //$NON-NLS-1$ - for (String item : list) { - if (wildCardMatch(getId(), item)) { - defaultSinks.add(mapping.getAttribute("sinkId")); //$NON-NLS-1$ - } - } - } - } - } - } - - private boolean wildCardMatch(String text, String pattern) { - String[] cards = pattern.split("\\*"); //$NON-NLS-1$ - for (String card : cards) { - int idx = text.indexOf(card); - if (idx == -1) { - return false; - } - text = text.substring(idx + card.length()); - } - - return true; - } - - public NotificationCategory getCategory() { - return category; - } - - public String getCategoryId() { - return element.getAttribute("categoryId"); //$NON-NLS-1$ - } - - public String getDescription() { - IConfigurationElement[] children = element.getChildren("description"); //$NON-NLS-1$ - if (children.length > 0) { - return children[0].getValue(); - } - return ""; //$NON-NLS-1$ - } - - public void setCategory(NotificationCategory category) { - this.category = category; - } - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationHandler.java deleted file mode 100644 index cd15cf446..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationHandler.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2013 Tasktop Technologies 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: - * Tasktop Technologies - initial API and implementation - * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer - *******************************************************************************/ - -package org.eclipse.tcf.te.ui.notifications.internal; - -import java.util.List; - -/** - * Manages actions that are triggered when a {@link NotificationEvent} occurs. - * - * @author Steffen Pingel - */ -public class NotificationHandler { - - private final List<NotificationAction> actions; - - private final NotificationEvent event; - - public NotificationHandler(NotificationEvent event, List<NotificationAction> actions) { - this.event = event; - this.actions = actions; - } - - public List<NotificationAction> getActions() { - return actions; - } - - public NotificationEvent getEvent() { - return event; - } - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationModel.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationModel.java deleted file mode 100644 index 6b4e7763a..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationModel.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2013 Tasktop Technologies 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: - * Tasktop Technologies - initial API and implementation - * Itema AS - bug 330064 notification filtering and model persistence - * Itema AS - bug 331424 handle default event-sink action associations - * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer - *******************************************************************************/ - -package org.eclipse.tcf.te.ui.notifications.internal; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Steffen Pingel - * @author Torkild U. Resheim - */ -public class NotificationModel { - - private Map<String, NotificationHandler> handlerByEventId; - - /** - * Constructor - */ - public NotificationModel() { - this.handlerByEventId = new HashMap<String, NotificationHandler>(); - // We need the handlerByEventId map to be populated early - for (NotificationCategory category : getCategories()) { - for (NotificationEvent event : category.getEvents()) { - getOrCreateNotificationHandler(event); - } - } - } - - public Collection<NotificationCategory> getCategories() { - return NotificationsExtensionReader.getCategories(); - } - - public NotificationHandler getNotificationHandler(String eventId) { - return handlerByEventId.get(eventId); - } - - public NotificationHandler getOrCreateNotificationHandler(NotificationEvent event) { - NotificationHandler handler = getNotificationHandler(event.getId()); - if (handler == null) { - handler = new NotificationHandler(event, getActions(event)); - handlerByEventId.put(event.getId(), handler); - } - return handler; - } - - private List<NotificationAction> getActions(NotificationEvent event) { - List<NotificationSinkDescriptor> descriptors = NotificationsExtensionReader.getSinks(); - List<NotificationAction> actions = new ArrayList<NotificationAction>(descriptors.size()); - for (NotificationSinkDescriptor descriptor : descriptors) { - NotificationAction action = new NotificationAction(descriptor); - if (event.defaultHandledBySink(descriptor.getId())) { - action.setSelected(true); - } - actions.add(action); - } - return actions; - } - - public boolean isSelected(NotificationEvent event) { - NotificationHandler handler = getOrCreateNotificationHandler(event); - for (NotificationAction action : handler.getActions()) { - if (action.isSelected()) { - return true; - } - } - return false; - } -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationService.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationService.java index 0f95e8f97..dfff769f6 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationService.java @@ -1,100 +1,81 @@ /******************************************************************************* - * Copyright (c) 2010, 2013 Tasktop Technologies 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 + * Copyright (c) 2013 Wind River Systems, Inc. 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: - * Tasktop Technologies - initial API and implementation - * Itema AS - bug 330064 notification filtering and model persistence - * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer + * Wind River Systems - initial API and implementation *******************************************************************************/ - package org.eclipse.tcf.te.ui.notifications.internal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; - +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.Status; -import org.eclipse.tcf.te.runtime.notifications.AbstractNotification; -import org.eclipse.tcf.te.runtime.notifications.NotificationSink; -import org.eclipse.tcf.te.runtime.notifications.NotificationSinkEvent; -import org.eclipse.tcf.te.runtime.notifications.interfaces.INotificationService; -import org.eclipse.tcf.te.runtime.services.AbstractService; +import org.eclipse.tcf.te.runtime.events.NotifyEvent; import org.eclipse.tcf.te.ui.notifications.activator.UIPlugin; -import org.eclipse.tcf.te.ui.notifications.preferences.IPreferenceKeys; +import org.eclipse.tcf.te.ui.notifications.internal.popup.PopupNotificationSink; /** - * @author Steffen Pingel - * @author Torkild U. Resheim + * Notification service implementation. */ -public class NotificationService extends AbstractService implements INotificationService { +public class NotificationService { + // Reference to the popup notification sink we use exclusively + /* default */ final PopupNotificationSink sink = new PopupNotificationSink(); - /* (non-Javadoc) - * @see org.eclipse.tcf.te.runtime.notifications.interfaces.INotificationService#notify(org.eclipse.tcf.te.runtime.notifications.AbstractNotification) + /* + * Thread save singleton instance creation. */ - @Override - public void notify(AbstractNotification notification) { - notify(new AbstractNotification[] { notification }); + private static class LazyInstance { + public static NotificationService instance = new NotificationService(); } - /* (non-Javadoc) - * @see org.eclipse.tcf.te.runtime.notifications.interfaces.INotificationService#notify(org.eclipse.tcf.te.runtime.notifications.AbstractNotification[]) + /** + * Constructor. */ - @Override - public void notify(AbstractNotification[] notifications) { - // Return if notifications are not globally enabled. - if (!UIPlugin.getDefault().getPreferenceStore().getBoolean(IPreferenceKeys.PREF_SERVICE_ENABLED)) { - return; - } + NotificationService() { + super(); + } + + /** + * Returns the singleton instance of the notification service. + */ + public static NotificationService getInstance() { + return LazyInstance.instance; + } + + /** + * Shows a single notification. + * + * @param event The notification event. Must not be <code>null</code>. + */ + public void notify(NotifyEvent event) { + Assert.isNotNull(event); + notify(new NotifyEvent[] { event }); + } + + /** + * Shows a set of notifications. + * + * @param events The notification events. Must not be <code>null</code>. + */ + public void notify(final NotifyEvent[] events) { + Assert.isNotNull(events); + + SafeRunner.run(new ISafeRunnable() { + @Override + public void run() throws Exception { + sink.notify(events); + } - // For each sink assemble a list of notifications that are not blocked - // and pass these along. - HashMap<NotificationSink, ArrayList<AbstractNotification>> filtered = new HashMap<NotificationSink, ArrayList<AbstractNotification>>(); - for (AbstractNotification notification : notifications) { - String id = notification.getEventId(); - NotificationHandler handler = UIPlugin.getDefault().getModel().getNotificationHandler(id); - if (handler != null) { - List<NotificationAction> actions = handler.getActions(); - for (NotificationAction action : actions) { - if (action.isSelected()) { - NotificationSink sink = action.getSinkDescriptor().getSink(); - if (sink != null) { - ArrayList<AbstractNotification> list = filtered.get(sink); - if (list == null) { - list = new ArrayList<AbstractNotification>(); - filtered.put(sink, list); - } - list.add(notification); - } - } - } + @Override + public void handleException(Throwable e) { + UIPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, UIPlugin.getUniqueIdentifier(), "Sink failed: " + sink.getClass(), e)); //$NON-NLS-1$ } - } - // Go through all the sinks that have notifications to display and let - // them do their job. - for (Entry<NotificationSink, ArrayList<AbstractNotification>> entry : filtered.entrySet()) { - final NotificationSink sink = entry.getKey(); - final NotificationSinkEvent event = new NotificationSinkEvent(new ArrayList<AbstractNotification>( - entry.getValue())); - SafeRunner.run(new ISafeRunnable() { - @Override - public void handleException(Throwable e) { - UIPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, UIPlugin.getUniqueIdentifier(), "Sink failed: " + sink.getClass(), e)); //$NON-NLS-1$ - } - @Override - public void run() throws Exception { - sink.notify(event); - } - }); - } + }); } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationSinkDescriptor.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationSinkDescriptor.java deleted file mode 100644 index 55de73fb2..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationSinkDescriptor.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2013 Tasktop Technologies 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: - * Tasktop Technologies - initial API and implementation - * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer - *******************************************************************************/ - -package org.eclipse.tcf.te.ui.notifications.internal; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.osgi.util.NLS; -import org.eclipse.tcf.te.runtime.notifications.NotificationSink; -import org.eclipse.tcf.te.ui.notifications.activator.UIPlugin; -import org.eclipse.ui.statushandlers.StatusManager; - -/** - * @author Steffen Pingel - */ -public class NotificationSinkDescriptor extends NotificationElement { - - private NotificationSink sink; - - private Status status; - - public NotificationSinkDescriptor(IConfigurationElement element) { - super(element); - } - - public NotificationSink getSink() { - if (sink != null || status != null) { - return sink; - } - - try { - Object object = element.createExecutableExtension("class"); //$NON-NLS-1$ - if (object instanceof NotificationSink) { - sink = (NotificationSink) object; - return sink; - } - - status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), NLS.bind("Sink ''{0}'' does not extend expected class for extension contributed by {1}", //$NON-NLS-1$ - object.getClass().getCanonicalName(), getPluginId())); - } - catch (Throwable e) { - status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), NLS.bind("Sink failed to load for extension contributed by {0}", getPluginId()), e); //$NON-NLS-1$ - } - - StatusManager.getManager().handle(status); - return null; - } - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationsExtensionReader.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationsExtensionReader.java deleted file mode 100644 index a5e728c4a..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/NotificationsExtensionReader.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2013 Tasktop Technologies 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: - * Tasktop Technologies - initial API and implementation - * Itema AS - bug 330064 notification filtering and model persistence - * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer - *******************************************************************************/ - -package org.eclipse.tcf.te.ui.notifications.internal; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.osgi.util.NLS; -import org.eclipse.tcf.te.ui.notifications.activator.UIPlugin; -import org.eclipse.ui.statushandlers.StatusManager; - -/** - * @author Steffen Pingel - * @author Torkild U. Resheim - */ -public class NotificationsExtensionReader { - - private static boolean errorLogged = false; - - static List<NotificationSinkDescriptor> sinks; - - private static Collection<NotificationCategory> categories; - - /** - * Returns a list of notification categories, each containing their belonging notification - * events. Once initialised the same list will be returned upon subsequent calls of this method. - * - * @return a list of notification categories. - * @see NotificationModel#save(org.eclipse.ui.IMemento) - * @see NotificationModel#load(org.eclipse.ui.IMemento) - */ - public static Collection<NotificationCategory> getCategories() { - if (categories != null) { - return categories; - } - HashMap<String, NotificationCategory> categoryById = new HashMap<String, NotificationCategory>(); - - MultiStatus result = new MultiStatus(UIPlugin.getUniqueIdentifier(), 0, "Notifcation extensions failed to load", null); //$NON-NLS-1$ - - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint repositoriesExtensionPoint = registry.getExtensionPoint(UIPlugin.getUniqueIdentifier() + ".notifications"); //$NON-NLS-1$ - IExtension[] extensions = repositoriesExtensionPoint.getExtensions(); - for (IExtension extension : extensions) { - IConfigurationElement[] elements = extension.getConfigurationElements(); - for (IConfigurationElement element : elements) { - if ("category".equals(element.getName())) { //$NON-NLS-1$ - NotificationCategory category = new NotificationCategory(element); - IStatus status = category.validate(); - if (status.isOK()) { - categoryById.put(category.getId(), category); - } - else { - result.add(status); - } - } - } - for (IConfigurationElement element : elements) { - if ("event".equals(element.getName())) { //$NON-NLS-1$ - NotificationEvent event = new NotificationEvent(element); - IStatus status = event.validate(); - if (status.isOK()) { - NotificationCategory category = categoryById.get(event.getCategoryId()); - if (category != null) { - category.addEvent(event); - } - else { - result.add(new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), - NLS.bind("Extension {0} contributed by {1} specify unknown category ''{2}''", new String[] { element.getNamespaceIdentifier(), element.getContributor().getName(), event.getCategoryId() }))); //NON-NLS-1$ //$NON-NLS-1$ - } - } - else { - result.add(status); - } - } - } - } - - if (!result.isOK() && !errorLogged) { - StatusManager.getManager().handle(result); - errorLogged = true; - } - - categories = categoryById.values(); - return categories; - } - - public static List<NotificationSinkDescriptor> getSinks() { - if (sinks != null) { - return sinks; - } - - sinks = new ArrayList<NotificationSinkDescriptor>(); - - MultiStatus result = new MultiStatus(UIPlugin.getUniqueIdentifier(), 0, "Notifcation extensions failed to load", null); //$NON-NLS-1$ - - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint repositoriesExtensionPoint = registry.getExtensionPoint(UIPlugin.getUniqueIdentifier() + ".notifications"); //$NON-NLS-1$ - IExtension[] extensions = repositoriesExtensionPoint.getExtensions(); - for (IExtension extension : extensions) { - IConfigurationElement[] elements = extension.getConfigurationElements(); - for (IConfigurationElement element : elements) { - if ("sink".equals(element.getName())) { //$NON-NLS-1$ - NotificationSinkDescriptor descriptor = new NotificationSinkDescriptor(element); - IStatus status = descriptor.validate(); - if (status.isOK()) { - sinks.add(descriptor); - } - else { - result.add(status); - } - } - } - } - - if (!result.isOK()) { - StatusManager.getManager().handle(result); - } - - return sinks; - } -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/events/EventListener.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/events/EventListener.java new file mode 100644 index 000000000..18211fb41 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/events/EventListener.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2013 Wind River Systems, Inc. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.ui.notifications.internal.events; + +import java.util.EventObject; + +import org.eclipse.tcf.te.runtime.events.NotifyEvent; +import org.eclipse.tcf.te.runtime.interfaces.events.IEventListener; +import org.eclipse.tcf.te.ui.notifications.internal.NotificationService; + +/** + * Event listener implementation. Handle events of type {@link NotifyEvent}. + */ +public class EventListener implements IEventListener { + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.interfaces.events.IEventListener#eventFired(java.util.EventObject) + */ + @Override + public void eventFired(EventObject event) { + if (event instanceof NotifyEvent) { + NotificationService.getInstance().notify((NotifyEvent)event); + } + } + +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/factory/DefaultFormTextFactoryDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/factory/DefaultFormTextFactoryDelegate.java new file mode 100644 index 000000000..f80c6c8b5 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/factory/DefaultFormTextFactoryDelegate.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2013 Wind River Systems, Inc. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.ui.notifications.internal.factory; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.graphics.Image; +import org.eclipse.tcf.te.runtime.events.NotifyEvent; +import org.eclipse.tcf.te.ui.notifications.activator.UIPlugin; +import org.eclipse.tcf.te.ui.notifications.interfaces.IFormTextFactoryDelegate; +import org.eclipse.ui.forms.IFormColors; +import org.eclipse.ui.forms.widgets.FormText; +import org.eclipse.ui.forms.widgets.FormToolkit; + +/** + * Default notification form text factory delegate implementation. + */ +public class DefaultFormTextFactoryDelegate implements IFormTextFactoryDelegate { + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.notifications.interfaces.IFormTextFactoryDelegate#populateFormText(org.eclipse.ui.forms.widgets.FormToolkit, org.eclipse.ui.forms.widgets.FormText, org.eclipse.tcf.te.runtime.events.NotifyEvent) + */ + @Override + public void populateFormText(FormToolkit toolkit, FormText widget, NotifyEvent event) { + Assert.isNotNull(toolkit); + Assert.isNotNull(widget); + Assert.isNotNull(event); + + // Get properties + String titleText = event.getProperties().getStringProperty(NotifyEvent.PROP_TITLE_TEXT); + String titleImageId = event.getProperties().getStringProperty(NotifyEvent.PROP_TITLE_IMAGE_ID); + String description = event.getProperties().getStringProperty(NotifyEvent.PROP_DESCRIPTION_TEXT); + + // At least the title text and the description must be not null + if (titleText != null && description != null) { + StringBuilder buffer = new StringBuilder(); + + buffer.append("<form>"); //$NON-NLS-1$ + + // If the title image id is set, try to load the image + if (titleImageId != null) { + Image image = UIPlugin.getImage(titleImageId); + if (image != null) { + buffer.append("<img href=\"titleImage\"> "); //$NON-NLS-1$ + widget.setImage("titleImage", image); //$NON-NLS-1$ + } + } + + // Set the title using the default header font + buffer.append("<span color=\"header\" font=\"header\">"); //$NON-NLS-1$ + buffer.append(titleText); + buffer.append("</span>"); //$NON-NLS-1$ + + // Add the description + buffer.append("<p>"); //$NON-NLS-1$ + buffer.append(description); + buffer.append("</p>"); //$NON-NLS-1$ + + buffer.append("</form>"); //$NON-NLS-1$ + + widget.setColor("header", toolkit.getColors().getColor(IFormColors.TITLE)); //$NON-NLS-1$ + widget.setFont("header", JFaceResources.getHeaderFont()); //$NON-NLS-1$ + + widget.setText(buffer.toString(), true, false); + } + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/factory/FactoryDelegateManager.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/factory/FactoryDelegateManager.java new file mode 100644 index 000000000..fc832f2a1 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/factory/FactoryDelegateManager.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2013 Wind River Systems, Inc. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.ui.notifications.internal.factory; + +import java.util.Collection; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager; +import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy; +import org.eclipse.tcf.te.ui.notifications.interfaces.IFormTextFactoryDelegate; + + +/** + * Notification form text factory delegate extension point manager implementation. + */ +public class FactoryDelegateManager extends AbstractExtensionPointManager<IFormTextFactoryDelegate> { + private final IFormTextFactoryDelegate defaultDelegate = new DefaultFormTextFactoryDelegate(); + + /* + * Thread save singleton instance creation. + */ + private static class LazyInstance { + public static FactoryDelegateManager instance = new FactoryDelegateManager(); + } + + /** + * Constructor. + */ + FactoryDelegateManager() { + super(); + } + + /** + * Returns the singleton instance of the notification form text factory delegate manager. + */ + public static FactoryDelegateManager getInstance() { + return LazyInstance.instance; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getExtensionPointId() + */ + @Override + protected String getExtensionPointId() { + return "org.eclipse.tcf.te.ui.notifications.factoryDelegates"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getConfigurationElementName() + */ + @Override + protected String getConfigurationElementName() { + return "delegate"; //$NON-NLS-1$ + } + + /** + * Returns the notification form text factory delegate matching the given id. + * + * @param id The notification form text factory delegate id. Must not be <code>null</code>. + * @return The notification form text factory delegate or <code>null</code>. + */ + public IFormTextFactoryDelegate getFactoryDelegate(String id) { + Assert.isNotNull(id); + + IFormTextFactoryDelegate delegate = null; + + Collection<ExecutableExtensionProxy<IFormTextFactoryDelegate>> delegates = getExtensions().values(); + for (ExecutableExtensionProxy<IFormTextFactoryDelegate> candidate : delegates) { + if (id.equals(candidate.getId())) { + delegate = candidate.getInstance(); + break; + } + } + + return delegate; + } + + /** + * Returns the default notification form text factory delegate. + * + * @return The default notification form text factory delegate. + */ + public IFormTextFactoryDelegate getDefaultFactoryDelegate() { + return defaultDelegate; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/popup/AbstractNotificationPopup.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/AbstractNotificationPopup.java index a47a303f5..1c3596a64 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/popup/AbstractNotificationPopup.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/AbstractNotificationPopup.java @@ -11,7 +11,7 @@ * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer *******************************************************************************/ -package org.eclipse.tcf.te.ui.notifications.popup; +package org.eclipse.tcf.te.ui.notifications.internal.popup; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -40,12 +40,10 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; -import org.eclipse.tcf.te.ui.notifications.AnimationUtil; -import org.eclipse.tcf.te.ui.notifications.AnimationUtil.FadeJob; -import org.eclipse.tcf.te.ui.notifications.AnimationUtil.IFadeListener; -import org.eclipse.tcf.te.ui.notifications.GradientColors; import org.eclipse.tcf.te.ui.notifications.activator.UIPlugin; import org.eclipse.tcf.te.ui.notifications.interfaces.ImageConsts; +import org.eclipse.tcf.te.ui.notifications.internal.popup.AnimationUtil.FadeJob; +import org.eclipse.tcf.te.ui.notifications.internal.popup.AnimationUtil.IFadeListener; import org.eclipse.tcf.te.ui.notifications.nls.Messages; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/AnimationUtil.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/AnimationUtil.java index 6a3c33384..cffee0f20 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/AnimationUtil.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/AnimationUtil.java @@ -10,7 +10,7 @@ * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer *******************************************************************************/ -package org.eclipse.tcf.te.ui.notifications; +package org.eclipse.tcf.te.ui.notifications.internal.popup; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/GradientColors.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/GradientColors.java index 62105e371..a50425f87 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/GradientColors.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/GradientColors.java @@ -11,7 +11,7 @@ * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer *******************************************************************************/ -package org.eclipse.tcf.te.ui.notifications; +package org.eclipse.tcf.te.ui.notifications.internal.popup; import org.eclipse.jface.resource.DeviceResourceException; import org.eclipse.jface.resource.ResourceManager; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/popup/NotificationPopup.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/NotificationPopup.java index 793f14968..3145dfc43 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/popup/NotificationPopup.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/NotificationPopup.java @@ -10,13 +10,12 @@ * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer *******************************************************************************/ -package org.eclipse.tcf.te.ui.notifications.popup; +package org.eclipse.tcf.te.ui.notifications.internal.popup; import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.LegacyActionTools; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; @@ -25,16 +24,18 @@ import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; -import org.eclipse.tcf.te.runtime.notifications.AbstractNotification; -import org.eclipse.tcf.te.ui.notifications.ScalingHyperlink; +import org.eclipse.tcf.te.runtime.events.NotifyEvent; import org.eclipse.tcf.te.ui.notifications.activator.UIPlugin; +import org.eclipse.tcf.te.ui.notifications.interfaces.IFormTextFactoryDelegate; +import org.eclipse.tcf.te.ui.notifications.internal.factory.FactoryDelegateManager; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.IFormColors; import org.eclipse.ui.forms.events.HyperlinkAdapter; import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.FormText; +import org.eclipse.ui.forms.widgets.FormToolkit; /** * @author Rob Elves @@ -46,7 +47,7 @@ public class NotificationPopup extends AbstractNotificationPopup { /* default */ Color hyperlinkWidget = null; - private List<AbstractNotification> notifications; + private List<NotifyEvent> notifications; /** * Constructor @@ -75,64 +76,32 @@ public class NotificationPopup extends AbstractNotificationPopup { }); int count = 0; - for (final AbstractNotification notification : notifications) { + for (final NotifyEvent notification : notifications) { Composite notificationComposite = new Composite(parent, SWT.NO_FOCUS); - GridLayout gridLayout = new GridLayout(2, false); - GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(notificationComposite); + GridLayout gridLayout = new GridLayout(1, false); + GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(notificationComposite); notificationComposite.setLayout(gridLayout); notificationComposite.setBackground(parent.getBackground()); if (count < NUM_NOTIFICATIONS_TO_DISPLAY) { - final Label notificationLabelIcon = new Label(notificationComposite, SWT.NO_FOCUS); - notificationLabelIcon.setBackground(parent.getBackground()); - if (notification instanceof AbstractUiNotification) { - notificationLabelIcon.setImage(((AbstractUiNotification) notification).getNotificationKindImage()); + // Get the notification form text factory delegate for the current notification + IFormTextFactoryDelegate delegate = null; + if (notification.getFactoryId() != null) { + delegate = FactoryDelegateManager.getInstance().getFactoryDelegate(notification.getFactoryId()); } + if (delegate == null) delegate = FactoryDelegateManager.getInstance().getDefaultFactoryDelegate(); + Assert.isNotNull(delegate); - final ScalingHyperlink itemLink = new ScalingHyperlink(notificationComposite, SWT.BEGINNING | SWT.NO_FOCUS); - GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(itemLink); - itemLink.setForeground(hyperlinkWidget); - itemLink.registerMouseTrackListener(); - itemLink.setText(LegacyActionTools.escapeMnemonics(notification.getLabel())); - if (notification instanceof AbstractUiNotification) { - itemLink.setImage(((AbstractUiNotification) notification).getNotificationImage()); - } - itemLink.setBackground(parent.getBackground()); - itemLink.addHyperlinkListener(new HyperlinkAdapter() { - @Override - public void linkActivated(HyperlinkEvent e) { - if (notification instanceof AbstractUiNotification) { - ((AbstractUiNotification) notification).open(); - } - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window != null) { - Shell windowShell = window.getShell(); - if (windowShell != null) { - if (windowShell.getMinimized()) { - windowShell.setMinimized(false); - } + // Get the form toolkit to use + FormToolkit toolkit = UIPlugin.getDefault().getFormToolkit(); + Assert.isNotNull(toolkit); - windowShell.open(); - windowShell.forceActive(); - } - } - } - }); + // Create the form text widget. + FormText widget = toolkit.createFormText(notificationComposite, true); + widget.setBackground(parent.getBackground()); - String descriptionText = null; - if (notification.getDescription() != null) { - descriptionText = notification.getDescription(); - } - if (descriptionText != null && !descriptionText.trim().equals("")) { //$NON-NLS-1$ - Label descriptionLabel = new Label(notificationComposite, SWT.NO_FOCUS); - descriptionLabel.setText(LegacyActionTools.escapeMnemonics(descriptionText)); - descriptionLabel.setBackground(parent.getBackground()); - GridDataFactory.fillDefaults() - .span(2, SWT.DEFAULT) - .grab(true, false) - .align(SWT.FILL, SWT.TOP) - .applyTo(descriptionLabel); - } + // Populate the widget content based on the current notification event + delegate.populateFormText(toolkit, widget, notification); } else { int numNotificationsRemain = notifications.size() - count; ScalingHyperlink remainingLink = new ScalingHyperlink(notificationComposite, SWT.NO_FOCUS); @@ -141,7 +110,6 @@ public class NotificationPopup extends AbstractNotificationPopup { remainingLink.setBackground(parent.getBackground()); remainingLink.setText(NLS.bind("{0} more", Integer.valueOf(numNotificationsRemain))); //$NON-NLS-1$ - GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(remainingLink); remainingLink.addHyperlinkListener(new HyperlinkAdapter() { @Override public void linkActivated(HyperlinkEvent e) { @@ -161,8 +129,8 @@ public class NotificationPopup extends AbstractNotificationPopup { } } - public List<AbstractNotification> getNotifications() { - return new ArrayList<AbstractNotification>(notifications); + public List<NotifyEvent> getNotifications() { + return new ArrayList<NotifyEvent>(notifications); } /* (non-Javadoc) @@ -170,10 +138,16 @@ public class NotificationPopup extends AbstractNotificationPopup { */ @Override protected Color getTitleForeground() { - return UIPlugin.getDefault().getFormColors().getColor(IFormColors.TITLE); + return UIPlugin.getDefault().getFormToolkit().getColors().getColor(IFormColors.TITLE); } - public void setContents(List<AbstractNotification> notifications) { + /** + * Sets the content of the notify popup. + * + * @param notifications The notification events. Must not be <code>null</code>. + */ + public void setContents(List<NotifyEvent> notifications) { + Assert.isNotNull(notifications); this.notifications = notifications; } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/popup/sink/PopupNotificationSink.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/PopupNotificationSink.java index dc7c0675f..20357aa25 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/popup/sink/PopupNotificationSink.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/PopupNotificationSink.java @@ -10,16 +10,17 @@ * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer *******************************************************************************/ -package org.eclipse.tcf.te.ui.notifications.popup.sink; +package org.eclipse.tcf.te.ui.notifications.internal.popup; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; -import java.util.WeakHashMap; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; @@ -28,11 +29,8 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; -import org.eclipse.tcf.te.runtime.notifications.AbstractNotification; -import org.eclipse.tcf.te.runtime.notifications.NotificationSink; -import org.eclipse.tcf.te.runtime.notifications.NotificationSinkEvent; +import org.eclipse.tcf.te.runtime.events.NotifyEvent; import org.eclipse.tcf.te.ui.notifications.nls.Messages; -import org.eclipse.tcf.te.ui.notifications.popup.NotificationPopup; import org.eclipse.ui.IWorkbenchPreferenceConstants; import org.eclipse.ui.PlatformUI; @@ -40,7 +38,7 @@ import org.eclipse.ui.PlatformUI; * @author Rob Elves * @author Steffen Pingel */ -public class PopupNotificationSink extends NotificationSink { +public class PopupNotificationSink { private static final long DELAY_OPEN = 1 * 1000; @@ -48,11 +46,11 @@ public class PopupNotificationSink extends NotificationSink { /* default */ NotificationPopup popup; - /* default */ final WeakHashMap<Object, Object> cancelledTokens = new WeakHashMap<Object, Object>(); + /* default */ final List<NotifyEvent> cancelledNotifications = new ArrayList<NotifyEvent>(); - private final Set<AbstractNotification> notifications = new HashSet<AbstractNotification>(); + private final Set<NotifyEvent> notifications = new HashSet<NotifyEvent>(); - /* default */ final Set<AbstractNotification> currentlyNotifying = Collections.synchronizedSet(notifications); + /* default */ final Set<NotifyEvent> currentlyNotifying = Collections.synchronizedSet(notifications); private final Job openJob = new Job(Messages.PopupNotificationSink_Popup_Notifier_Job_Label) { @Override @@ -65,21 +63,18 @@ public class PopupNotificationSink extends NotificationSink { @Override public void run() { - collectNotifications(); - if (popup != null && popup.getReturnCode() == Window.CANCEL) { - List<AbstractNotification> notifications = popup.getNotifications(); - for (AbstractNotification notification : notifications) { - if (notification.getToken() != null) { - cancelledTokens.put(notification.getToken(), null); + List<NotifyEvent> notifications = popup.getNotifications(); + for (NotifyEvent notification : notifications) { + if (!cancelledNotifications.contains(notification)) { + cancelledNotifications.add(notification); } } } - for (Iterator<AbstractNotification> it = currentlyNotifying.iterator(); it.hasNext();) { - AbstractNotification notification = it.next(); - if (notification.getToken() != null - && cancelledTokens.containsKey(notification.getToken())) { + for (Iterator<NotifyEvent> it = currentlyNotifying.iterator(); it.hasNext();) { + NotifyEvent notification = it.next(); + if (cancelledNotifications.contains(notification)) { it.remove(); } } @@ -116,27 +111,21 @@ public class PopupNotificationSink extends NotificationSink { currentlyNotifying.clear(); } - /** public for testing */ - public void collectNotifications() { - } - - /** - * public for testing purposes - */ - public Set<AbstractNotification> getNotifications() { - synchronized (PopupNotificationSink.class) { - return currentlyNotifying; - } - } public boolean isAnimationsEnabled() { IPreferenceStore store = PlatformUI.getPreferenceStore(); return store.getBoolean(IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS); } - @Override - public void notify(NotificationSinkEvent event) { - currentlyNotifying.addAll(event.getNotifications()); + /** + * Notify the given notification events. + * + * @param events The notification events. Must not be <code>null</code>. + */ + public void notify(NotifyEvent[] events) { + Assert.isNotNull(events); + + currentlyNotifying.addAll(Arrays.asList(events)); if (!openJob.cancel()) { try { @@ -156,7 +145,7 @@ public class PopupNotificationSink extends NotificationSink { Shell shell = new Shell(PlatformUI.getWorkbench().getDisplay()); popup = new NotificationPopup(shell); popup.setFadingEnabled(isAnimationsEnabled()); - List<AbstractNotification> toDisplay = new ArrayList<AbstractNotification>(currentlyNotifying); + List<NotifyEvent> toDisplay = new ArrayList<NotifyEvent>(currentlyNotifying); Collections.sort(toDisplay); popup.setContents(toDisplay); cleanNotified(); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/ScalingHyperlink.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/ScalingHyperlink.java index 6b685b104..ab2132c30 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/ScalingHyperlink.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/ScalingHyperlink.java @@ -10,7 +10,7 @@ * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer *******************************************************************************/ -package org.eclipse.tcf.te.ui.notifications; +package org.eclipse.tcf.te.ui.notifications.internal.popup; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseEvent; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/popup/AbstractUiNotification.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/popup/AbstractUiNotification.java deleted file mode 100644 index 710a4fd36..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/popup/AbstractUiNotification.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Tasktop Technologies 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: - * Tasktop Technologies - initial API and implementation - * Wind River Systems - Extracted from o.e.mylyn.commons and adapted for Target Explorer - *******************************************************************************/ - -package org.eclipse.tcf.te.ui.notifications.popup; - -import org.eclipse.swt.graphics.Image; -import org.eclipse.tcf.te.runtime.notifications.AbstractNotification; - -/** - * A notification with UI specific extensions. - * - * @author Steffen Pingel - */ -public abstract class AbstractUiNotification extends AbstractNotification { - - public AbstractUiNotification(String eventId) { - super(eventId); - } - - public abstract Image getNotificationImage(); - - public abstract Image getNotificationKindImage(); - - /** - * Executes the default action for opening the notification. - */ - public abstract void open(); - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/preferences/IPreferenceKeys.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/preferences/IPreferenceKeys.java deleted file mode 100644 index 82008acb7..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/preferences/IPreferenceKeys.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Wind River Systems, Inc. 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.te.ui.notifications.preferences; - -import org.eclipse.tcf.te.ui.notifications.activator.UIPlugin; - - -/** - * Preference key identifiers. - */ -public interface IPreferenceKeys { - /** - * Common prefix for all core preference keys - */ - public final String PREFIX = UIPlugin.getUniqueIdentifier(); - - /** - * If set to <code>true</code>, the notifications service is enabled. - */ - public static final String PREF_SERVICE_ENABLED = PREFIX + ".service.enabled"; //$NON-NLS-1$ - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/preferences/PreferencesInitializer.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/preferences/PreferencesInitializer.java deleted file mode 100644 index 718bd9220..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/preferences/PreferencesInitializer.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Wind River Systems, Inc. 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.te.ui.notifications.preferences; - -import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.tcf.te.ui.notifications.activator.UIPlugin; - -/** - * Preferences initializer implementation. - */ -public class PreferencesInitializer extends AbstractPreferenceInitializer { - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() - */ - @Override - public void initializeDefaultPreferences() { - // Get the preferences store - IPreferenceStore store = UIPlugin.getDefault().getPreferenceStore(); - // [Hidden] Enable notifications service: default on - store.setDefault(IPreferenceKeys.PREF_SERVICE_ENABLED, true); - } - -} |