diff options
author | Steffen Pingel | 2011-12-05 16:34:12 +0000 |
---|---|---|
committer | Steffen Pingel | 2011-12-05 16:34:12 +0000 |
commit | 37fc151f7c3bcd975ea83fdc7d02a41a77e7f538 (patch) | |
tree | 76d541fa2009856d01e6e398b132caabf3ecb3f7 | |
parent | e16cd7c253208a4324c43854bfb743e693beb1e7 (diff) | |
download | org.eclipse.mylyn.tasks-37fc151f7c3bcd975ea83fdc7d02a41a77e7f538.tar.gz org.eclipse.mylyn.tasks-37fc151f7c3bcd975ea83fdc7d02a41a77e7f538.tar.xz org.eclipse.mylyn.tasks-37fc151f7c3bcd975ea83fdc7d02a41a77e7f538.zip |
NEW - bug 361048: [api] move service message implementation to
notifications component
https://bugs.eclipse.org/bugs/show_bug.cgi?id=361048
Change-Id: I4f88348bfc60a084a01378931fd8210817fa8d79
24 files changed, 55 insertions, 1279 deletions
diff --git a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF index 6b5736925..c348a2394 100644 --- a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF @@ -17,16 +17,10 @@ Export-Package: org.eclipse.mylyn.internal.provisional.tasks.core;x-internal:=tr org.eclipse.mylyn.internal.tasks.core.context;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs", org.eclipse.mylyn.internal.tasks.core.data;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs", org.eclipse.mylyn.internal.tasks.core.externalization;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs", - org.eclipse.mylyn.internal.tasks.core.notifications;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs", org.eclipse.mylyn.internal.tasks.core.sync;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs", org.eclipse.mylyn.tasks.core, org.eclipse.mylyn.tasks.core.activity, org.eclipse.mylyn.tasks.core.context, org.eclipse.mylyn.tasks.core.data, org.eclipse.mylyn.tasks.core.sync -Import-Package: com.sun.syndication.feed;version="0.9.0", - com.sun.syndication.feed.module;version="0.9.0", - com.sun.syndication.feed.synd;version="0.9.0", - com.sun.syndication.io;version="0.9.0", - org.jdom;version="1.0.0" Bundle-Localization: plugin diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/Environment.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/Environment.java deleted file mode 100644 index cceae9426..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/Environment.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 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 - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.core.notifications; - -import java.util.Collections; -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Platform; -import org.eclipse.mylyn.commons.core.CoreUtil; -import org.eclipse.osgi.service.resolver.VersionRange; -import org.osgi.framework.Bundle; -import org.osgi.framework.Filter; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.Version; - -/** - * @author Steffen Pingel - */ -public class Environment { - - private final Dictionary<Object, Object> environment; - - public Environment() { - environment = new Hashtable<Object, Object>(System.getProperties()); - } - - public Version getFrameworkVersion() { - Bundle bundle = Platform.getBundle("org.eclipse.mylyn"); //$NON-NLS-1$ - if (bundle != null) { - return CoreUtil.getVersion(bundle); - } else { - return Version.emptyVersion; - } - } - - public Version getPlatformVersion() { - Bundle bundle = Platform.getBundle("org.eclipse.platform"); //$NON-NLS-1$ - if (bundle == null) { - bundle = Platform.getBundle(Platform.PI_RUNTIME); - } - if (bundle != null) { - String versionString = (String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION); - try { - return new Version(versionString); - } catch (IllegalArgumentException e) { - // should never happen - } - } - return Version.emptyVersion; - } - - public Version getRuntimeVersion() { - Version result = parseRuntimeVersion(System.getProperty("java.runtime.version")); //$NON-NLS-1$ - if (result == Version.emptyVersion) { - result = parseRuntimeVersion(System.getProperty("java.version")); //$NON-NLS-1$ - } - return result; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public boolean matches(FeedEntry entry, IProgressMonitor monitor) { - if (!matchesVersion(entry.getFilter("frameworkVersion"), getFrameworkVersion())) { //$NON-NLS-1$ - return false; - } - if (!matchesVersion(entry.getFilter("platformVersion"), getPlatformVersion())) { //$NON-NLS-1$ - return false; - } - if (!matchesVersion(entry.getFilter("runtimeVersion"), getRuntimeVersion())) { //$NON-NLS-1$ - return false; - } - List<String> filterExpressions = entry.getFilters("filter"); //$NON-NLS-1$ - for (String filterExpression : filterExpressions) { - try { - Filter filter = FrameworkUtil.createFilter(filterExpression); - if (!filter.match((Dictionary) environment)) { - return false; - } - } catch (InvalidSyntaxException e) { - // ignore that filter - } - } - List<String> requiredFeatures = entry.getFilters("requires"); //$NON-NLS-1$ - for (String requiredFeature : requiredFeatures) { - if (!getInstalledFeatures(monitor).contains(parseFeature(requiredFeature))) { - return false; - } - } - List<String> conflictedFeatures = entry.getFilters("conflicts"); //$NON-NLS-1$ - for (String conflictedFeature : conflictedFeatures) { - if (getInstalledFeatures(monitor).contains(parseFeature(conflictedFeature))) { - return false; - } - } - return true; - } - - private int findLastNumberIndex(String versionString, int secondSeparator) { - int lastDigit = secondSeparator; - for (int i = secondSeparator + 1; i < versionString.length(); i++) { - if (Character.isDigit(versionString.charAt(i))) { - lastDigit++; - } else { - break; - } - } - if (lastDigit == secondSeparator) { - return secondSeparator - 1; - } - return lastDigit; - } - - public Set<String> getInstalledFeatures(IProgressMonitor monitor) { - return Collections.emptySet(); - } - - private boolean matchesVersion(String expectedVersionRangeExpression, Version actualVersion) { - if (expectedVersionRangeExpression != null) { - try { - VersionRange versionRange = new VersionRange(expectedVersionRangeExpression); - if (!versionRange.isIncluded(actualVersion)) { - return false; - } - } catch (IllegalArgumentException e) { - // ignore - } - } - return true; - } - - private String parseFeature(String requiredFeature) { - int i = requiredFeature.indexOf(";"); //$NON-NLS-1$ - if (i != -1) { - return requiredFeature.substring(0, i); - } - return requiredFeature; - } - - private Version parseRuntimeVersion(String versionString) { - if (versionString != null) { - int firstSeparator = versionString.indexOf('.'); - if (firstSeparator != -1) { - try { - int secondSeparator = versionString.indexOf('.', firstSeparator + 1); - if (secondSeparator != -1) { - return new Version(versionString.substring(0, - findLastNumberIndex(versionString, secondSeparator) + 1)); - } - return new Version(versionString.substring(0, - findLastNumberIndex(versionString, firstSeparator) + 1)); - } catch (IllegalArgumentException e) { - // ignore - } - } - } - return Version.emptyVersion; - } - -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedEntry.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedEntry.java deleted file mode 100644 index 4098c4c88..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedEntry.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 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 - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.core.notifications; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.Assert; - -import com.sun.syndication.feed.module.DCModule; -import com.sun.syndication.feed.module.DCSubject; -import com.sun.syndication.feed.synd.SyndEntry; - -/** - * @author Steffen Pingel - */ -public class FeedEntry extends ServiceMessage { - - private final SyndEntry source; - - public FeedEntry(SyndEntry source) { - this.source = source; - setId(source.getUri()); - setTitle(source.getTitle()); - if (source.getDescription() != null) { - setDescription(source.getDescription().getValue()); - } - setUrl(source.getLink()); - setImage("dialog_messasge_info_image"); //$NON-NLS-1$ - } - - public FeedEntry() { - this.source = null; - } - - public SyndEntry getSource() { - return source; - } - - public List<String> getFilters(String key) { - Assert.isNotNull(key); - List<String> result = new ArrayList<String>(); - DCModule module = (DCModule) source.getModule(DCModule.URI); - if (module != null && module.getSubjects() != null) { - for (Iterator<?> it = module.getSubjects().iterator(); it.hasNext();) { - DCSubject category = (DCSubject) it.next(); - String value = parseFilter(key, category.getValue()); - if (value != null) { - result.add(value); - } - } - } -// for (Iterator<?> it = source.getCategories().iterator(); it.hasNext();) { -// SyndCategory category = (SyndCategory) it.next(); -// String value = parseFilter(key, category.getName()); -// if (value != null) { -// result.add(value); -// } -// } - return result; - } - - public String getFilter(String key) { - Assert.isNotNull(key); - DCModule module = (DCModule) source.getModule(DCModule.URI); - if (module != null && module.getSubjects() != null) { - for (Iterator<?> it = module.getSubjects().iterator(); it.hasNext();) { - DCSubject category = (DCSubject) it.next(); - String value = parseFilter(key, category.getValue()); - if (value != null) { - return value; - } - } - } -// for (Iterator<?> it = source.getCategories().iterator(); it.hasNext();) { -// SyndCategory category = (SyndCategory) it.next(); -// String value = parseCategory(key, category.getName()); -// if (value != null) { -// return value; -// } -// } - return null; - } - - private String parseFilter(String key, String category) { - if (category != null) { - int i = category.indexOf("="); //$NON-NLS-1$ - if (i != -1) { - if (category.substring(0, i).trim().equals(key)) { - return category.substring(i + 1).trim(); - } - } - } - return null; - } - -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedReader.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedReader.java deleted file mode 100644 index bba4dfc1e..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedReader.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 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 - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.core.notifications; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants; - -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.io.SyndFeedInput; -import com.sun.syndication.io.XmlReader; - -/** - * @author Steffen Pingel - */ -public class FeedReader { - - private final Environment environment; - - private final List<FeedEntry> entries; - - public FeedReader(Environment environment) { - this.environment = environment; - this.entries = new ArrayList<FeedEntry>(); - } - - public IStatus parse(InputStream in, IProgressMonitor monitor) { - SyndFeedInput input = new SyndFeedInput(); - try { - SyndFeed feed = input.build(new XmlReader(in)); - for (Iterator<?> it = feed.getEntries().iterator(); it.hasNext();) { - SyndEntry syndEntry = (SyndEntry) it.next(); - FeedEntry entry = new FeedEntry(syndEntry); - if (environment.matches(entry, monitor)) { - entries.add(entry); - } - } - return Status.OK_STATUS; - } catch (Exception e) { - return new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, IStatus.ERROR, - "Failed to parse RSS feed", e); //$NON-NLS-1$ - } - } - - public List<FeedEntry> getEntries() { - return entries; - } - -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/IServiceMessageListener.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/IServiceMessageListener.java deleted file mode 100644 index eca6e93c3..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/IServiceMessageListener.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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 - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.core.notifications; - -/** - * @author Robert Elves - */ -public interface IServiceMessageListener { - - public void handleEvent(ServiceMessageEvent event); - -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessage.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessage.java deleted file mode 100644 index 144e82d7a..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessage.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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 - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.core.notifications; - -/** - * @author Robert Elves - */ -public class ServiceMessage implements Comparable<ServiceMessage> { - - public enum Element { - ID, TITLE, DESCRIPTION, URL, IMAGE - }; - - private String id; - - private String title; - - private String description; - - private String url; - - private String image; - - private String eTag; - - private String lastModified; - - public String getId() { - return id; - } - - public String getTitle() { - return title; - } - - public String getDescription() { - return description; - } - - public String getUrl() { - return url; - } - - public String getImage() { - return image; - } - - public void setETag(String eTag) { - this.eTag = eTag; - } - - public void setLastModified(String lastModified) { - this.lastModified = lastModified; - } - - public String getETag() { - return eTag; - } - - public String getLastModified() { - return lastModified; - } - - public void setId(String id) { - this.id = id; - } - - public void setTitle(String title) { - this.title = title; - } - - public void setDescription(String description) { - this.description = description; - } - - public void setUrl(String url) { - this.url = url; - } - - public void setImage(String image) { - this.image = image; - } - - public boolean isValid() { - return id != null && title != null && description != null && image != null; - } - - public int compareTo(ServiceMessage o) { - return -getId().compareTo(o.getId()); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("ServiceMessage [id="); //$NON-NLS-1$ - builder.append(id); - builder.append(", title="); //$NON-NLS-1$ - builder.append(title); - builder.append(", description="); //$NON-NLS-1$ - builder.append(description); - builder.append(", url="); //$NON-NLS-1$ - builder.append(url); - builder.append(", image="); //$NON-NLS-1$ - builder.append(image); - builder.append(", eTag="); //$NON-NLS-1$ - builder.append(eTag); - builder.append(", lastModified="); //$NON-NLS-1$ - builder.append(lastModified); - builder.append("]"); //$NON-NLS-1$ - return builder.toString(); - } - -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageEvent.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageEvent.java deleted file mode 100644 index 8483cd5c7..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageEvent.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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 - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.core.notifications; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.EventObject; -import java.util.List; - -/** - * @author Steffen Pingel - */ -public class ServiceMessageEvent extends EventObject { - - public enum EVENT_KIND { - MESSAGE_UPDATE, STOP - }; - - private static final long serialVersionUID = 1L; - - private final List<ServiceMessage> messages; - - private final EVENT_KIND eventKind; - - public ServiceMessageEvent(ServiceMessageManager manager, EVENT_KIND kind) { - this(manager, kind, new ArrayList<ServiceMessage>()); - } - - public ServiceMessageEvent(ServiceMessageManager manager, EVENT_KIND eventKind, List<ServiceMessage> messages) { - super(manager); - this.eventKind = eventKind; - this.messages = Collections.unmodifiableList(new ArrayList<ServiceMessage>(messages)); - } - - public List<ServiceMessage> getMessages() { - return messages; - } - - public EVENT_KIND getEventKind() { - return eventKind; - } - -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageManager.java deleted file mode 100644 index 8c19a2ef5..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageManager.java +++ /dev/null @@ -1,266 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2010 Tasktop Technologies. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Tasktop EULA - * which accompanies this distribution, and is available at - * http://tasktop.com/legal - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.core.notifications; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HostConfiguration; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.GetMethod; -import org.eclipse.core.runtime.IProgressMonitor; -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.core.runtime.SubProgressMonitor; -import org.eclipse.core.runtime.jobs.IJobChangeEvent; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.jobs.JobChangeAdapter; -import org.eclipse.mylyn.commons.core.StatusHandler; -import org.eclipse.mylyn.commons.net.WebLocation; -import org.eclipse.mylyn.commons.net.WebUtil; -import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants; - -/** - * @author Robert Elves - * @author Steffen Pingel - */ -public class ServiceMessageManager { - - protected static final long START_DELAY = 30 * 1000; - - protected static final long RECHECK_DELAY = 14 * 24 * 60 * 60 * 1000; - - private String serviceMessageUrl; - - private volatile List<? extends ServiceMessage> messages = Collections.emptyList(); - - private Job messageCheckJob; - - private final List<IServiceMessageListener> listeners = new CopyOnWriteArrayList<IServiceMessageListener>(); - - private String lastModified; - - private String eTag; - - private boolean statusLogged; - - private final long checktime; - - private final Environment environment; - - public ServiceMessageManager(String serviceMessageUrl, String lastModified, String eTag, long checktime, - Environment environment) { - this.serviceMessageUrl = serviceMessageUrl; - this.lastModified = lastModified; - this.checktime = checktime; - this.eTag = eTag; - this.environment = environment; - } - - public ServiceMessageManager(String serviceMessageUrl, String lastModified, String eTag, long checktime) { - this(serviceMessageUrl, lastModified, eTag, checktime, new Environment()); - } - - public void start() { - if (messageCheckJob == null) { - messageCheckJob = new Job("Checking for new service message") { //$NON-NLS-1$ - @Override - protected IStatus run(IProgressMonitor monitor) { - try { - updateServiceMessage(monitor); - return Status.OK_STATUS; - } catch (Throwable t) { - // fail silently - return Status.CANCEL_STATUS; - } - } - - }; - messageCheckJob.setSystem(true); - messageCheckJob.setPriority(Job.DECORATE); - messageCheckJob.addJobChangeListener(new JobChangeAdapter() { - @Override - public void done(IJobChangeEvent event) { - if (messageCheckJob != null) { - messageCheckJob.schedule(RECHECK_DELAY); - } - } - }); - } - if (checktime == 0) { - messageCheckJob.schedule(START_DELAY); - } else { - long nextCheckTime = checktime + RECHECK_DELAY; - long now = System.currentTimeMillis(); - if (nextCheckTime < now) { - messageCheckJob.schedule(START_DELAY); - } else if (nextCheckTime > now) { - if (nextCheckTime - now < START_DELAY) { - messageCheckJob.schedule(START_DELAY); - } else { - messageCheckJob.schedule(nextCheckTime - now); - } - } - } - } - - public void stop() { - if (messageCheckJob != null) { - messageCheckJob.cancel(); - messageCheckJob = null; - } - - final ServiceMessageEvent event = new ServiceMessageEvent(this, ServiceMessageEvent.EVENT_KIND.STOP); - - for (final IServiceMessageListener listener : listeners) { - SafeRunner.run(new ISafeRunnable() { - public void run() throws Exception { - listener.handleEvent(event); - } - - public void handleException(Throwable e) { - StatusHandler.log(new Status(IStatus.WARNING, ITasksCoreConstants.ID_PLUGIN, "Listener failed: " //$NON-NLS-1$ - + listener.getClass(), e)); - } - }); - } - } - - public void setServiceMessageUrl(String url) { - this.serviceMessageUrl = url; - } - - public void addServiceMessageListener(IServiceMessageListener listener) { - listeners.add(listener); - } - - public void removeServiceMessageListener(IServiceMessageListener listener) { - listeners.remove(listener); - } - - private void notifyListeners(List<? extends ServiceMessage> messages) { - this.messages = messages; - for (final ServiceMessage message : messages) { - message.setETag(eTag); - message.setLastModified(lastModified); - } - - ArrayList<ServiceMessage> sortedMessages = new ArrayList<ServiceMessage>(messages); - Collections.sort(messages); - final ServiceMessageEvent event = new ServiceMessageEvent(this, ServiceMessageEvent.EVENT_KIND.MESSAGE_UPDATE, - sortedMessages); - for (final IServiceMessageListener listener : listeners) { - SafeRunner.run(new ISafeRunnable() { - public void run() throws Exception { - listener.handleEvent(event); - } - - public void handleException(Throwable e) { - StatusHandler.log(new Status(IStatus.WARNING, ITasksCoreConstants.ID_PLUGIN, "Listener failed: " //$NON-NLS-1$ - + listener.getClass(), e)); - } - }); - } - } - - public List<ServiceMessage> getServiceMessages() { - return new ArrayList<ServiceMessage>(this.messages); - } - - /** - * Public for testing - */ - public int updateServiceMessage(IProgressMonitor monitor) { - int status = -1; - List<? extends ServiceMessage> messages = null; - try { - HttpClient httpClient = new HttpClient(WebUtil.getConnectionManager()); - WebUtil.configureHttpClient(httpClient, null); - - WebLocation location = new WebLocation(serviceMessageUrl); - HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, - new SubProgressMonitor(monitor, 1)); - - GetMethod method = new GetMethod(serviceMessageUrl); - method.setRequestHeader("If-Modified-Since", lastModified); //$NON-NLS-1$ - method.setRequestHeader("If-None-Match", eTag); //$NON-NLS-1$ - - try { - status = WebUtil.execute(httpClient, hostConfiguration, method, monitor); - if (status == HttpStatus.SC_OK && !monitor.isCanceled()) { - Header lastModifiedHeader = method.getResponseHeader("Last-Modified"); //$NON-NLS-1$ - if (lastModifiedHeader != null) { - lastModified = lastModifiedHeader.getValue(); - } - Header eTagHeader = method.getResponseHeader("ETag"); //$NON-NLS-1$ - if (eTagHeader != null) { - eTag = eTagHeader.getValue(); - } - - InputStream in = WebUtil.getResponseBodyAsStream(method, monitor); - try { - messages = readMessages(in, monitor); - } finally { - in.close(); - } - } else if (status == HttpStatus.SC_NOT_FOUND) { - // no messages - } else if (status == HttpStatus.SC_NOT_MODIFIED) { - // no new messages - } else { - logStatus(new Status(IStatus.WARNING, ITasksCoreConstants.ID_PLUGIN, - "Http error retrieving service message: " + HttpStatus.getStatusText(status))); //$NON-NLS-1$ - } - } finally { - WebUtil.releaseConnection(method, monitor); - } - } catch (Exception e) { - logStatus(new Status(IStatus.WARNING, ITasksCoreConstants.ID_PLUGIN, - "Http error retrieving service message.", e)); //$NON-NLS-1$ - } - - if (messages != null && messages.size() > 0) { - notifyListeners(messages); - } - return status; - } - - private void logStatus(IStatus status) { - if (!statusLogged) { - statusLogged = true; - //StatusHandler.log(status); - } - } - -// private List<ServiceMessage> readMessages(InputStream in) throws ParserConfigurationException, SAXException, -// IOException { -// SAXParserFactory factory = SAXParserFactory.newInstance(); -// factory.setValidating(false); -// SAXParser parser = factory.newSAXParser(); -// -// ServiceMessageXmlHandler handler = new ServiceMessageXmlHandler(); -// parser.parse(in, handler); -// return handler.getMessages(); -// } - - private List<? extends ServiceMessage> readMessages(InputStream in, IProgressMonitor monitor) throws IOException { - FeedReader reader = new FeedReader(environment); - reader.parse(in, monitor); - return reader.getEntries(); - } - -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageXmlHandler.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageXmlHandler.java deleted file mode 100644 index 27b5fa6fe..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageXmlHandler.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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 - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.core.notifications; - -import java.util.ArrayList; -import java.util.List; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * @author Robert Elves - * @author Steffen Pingel - */ -public class ServiceMessageXmlHandler extends DefaultHandler { - - private static final String TAG_MESSAGE = "ServiceMessage"; //$NON-NLS-1$ - - private StringBuilder characters; - - private final List<ServiceMessage> messages = new ArrayList<ServiceMessage>(); - - private ServiceMessage message; - - @Override - public void characters(char[] ch, int start, int length) throws SAXException { - characters.append(ch, start, length); - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - if (TAG_MESSAGE.equals(qName.trim())) { - message = new ServiceMessage(); - } - characters = new StringBuilder(); - } - - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - if (message == null) { - return; - } - if (TAG_MESSAGE.equals(qName.trim())) { - if (message.isValid()) { - messages.add(message); - } - } else { - String parsedText = characters.toString(); - ServiceMessage.Element element; - try { - element = ServiceMessage.Element.valueOf(qName.trim().toUpperCase()); - switch (element) { - case ID: - message.setId(parsedText); - break; - case DESCRIPTION: - message.setDescription(parsedText); - break; - case TITLE: - message.setTitle(parsedText); - break; - case URL: - message.setUrl(parsedText); - break; - case IMAGE: - message.setImage(parsedText); - break; - } - } catch (IllegalArgumentException e) { - // ignore unrecognized elements - } - } - } - - public List<ServiceMessage> getMessages() { - return new ArrayList<ServiceMessage>(messages); - } - -} diff --git a/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF index 67b304562..3ae3738c8 100644 --- a/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF @@ -20,6 +20,7 @@ Require-Bundle: org.junit, org.eclipse.mylyn.commons.core, org.eclipse.mylyn.commons.net, org.eclipse.mylyn.commons.sdk.util, + org.eclipse.mylyn.commons.notifications.ui, org.eclipse.mylyn.commons.ui, org.eclipse.mylyn.commons.workbench, org.eclipse.mylyn.monitor.core, diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/EnvironmentTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/EnvironmentTest.java deleted file mode 100644 index 04d311efc..000000000 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/EnvironmentTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Tasktop Technologies. - * 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.tests.core; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import junit.framework.TestCase; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Platform; -import org.eclipse.mylyn.internal.tasks.core.notifications.Environment; -import org.eclipse.mylyn.internal.tasks.core.notifications.FeedEntry; -import org.eclipse.osgi.service.resolver.VersionRange; -import org.osgi.framework.Version; - -/** - * @author Steffen Pingel - */ -public class EnvironmentTest extends TestCase { - - private class StubEntry extends FeedEntry { - - private final Map<String, String> map; - - public StubEntry(Map<String, String> map) { - this.map = map; - } - - @Override - public List<String> getFilters(String key) { - String value = getFilter(key); - if (value != null) { - return Collections.singletonList(value); - } - return Collections.emptyList(); - } - - @Override - public String getFilter(String key) { - return map.get(key); - } - - } - - private Environment environment; - - Set<String> installedFeatures; - - @Override - protected void setUp() throws Exception { - installedFeatures = new HashSet<String>(); - System.setProperty("EnvironmentTest", "2"); - environment = new Environment() { - @Override - public Set<String> getInstalledFeatures(IProgressMonitor monitor) { - return installedFeatures; - } - }; - } - - public void testGetRuntimeVersion() { - Version runtimeVersion = environment.getRuntimeVersion(); - assertTrue("Expected value between 1.5-1.8, got " + runtimeVersion, - new VersionRange("[1.5.0,1.8.0)").isIncluded(runtimeVersion)); - } - - public void testGetPlatformVersion() { - Version platformVersion = environment.getPlatformVersion(); - if (Platform.isRunning()) { - assertTrue("Expected value between 3.4-5.0, got " + platformVersion, - new VersionRange("[3.4.0,5.0.0)").isIncluded(platformVersion)); - } else { - assertEquals(Version.emptyVersion, platformVersion); - } - } - - public void testGetFrameworkVersion() { - Version frameworkVersion = environment.getFrameworkVersion(); - if (Platform.isRunning()) { - assertTrue("Expected value > 3.6, got " + frameworkVersion, - new VersionRange("3.6.0").isIncluded(frameworkVersion)); - } else { - assertEquals(Version.emptyVersion, frameworkVersion); - } - } - - public void testMatchesFrameworkVersion() { - Map<String, String> values = new HashMap<String, String>(); - assertTrue(environment.matches(new StubEntry(values), null)); - - values.put("frameworkVersion", "[1.0.0,2.0.0)"); - assertFalse(environment.matches(new StubEntry(values), null)); - - values.put("frameworkVersion", "[0.0.0,10.0.0)"); - assertTrue(environment.matches(new StubEntry(values), null)); - } - - public void testMatchesRequires() { - Map<String, String> values = new HashMap<String, String>(); - values.put("requires", "org.eclipse.mylyn"); - assertFalse(environment.matches(new StubEntry(values), null)); - - installedFeatures.add("org.eclipse.mylyn"); - assertTrue(environment.matches(new StubEntry(values), null)); - } - - public void testMatchesConflicts() { - Map<String, String> values = new HashMap<String, String>(); - values.put("conflicts", "org.eclipse.mylyn"); - assertTrue(environment.matches(new StubEntry(values), null)); - - installedFeatures.add("org.eclipse.mylyn"); - assertFalse(environment.matches(new StubEntry(values), null)); - } - - public void testMatchesRequiresConflicts() { - Map<String, String> values = new HashMap<String, String>(); - values.put("requires", "org.eclipse.mylyn"); - values.put("conflicts", "org.eclipse.cdt"); - assertFalse(environment.matches(new StubEntry(values), null)); - - installedFeatures.add("org.eclipse.mylyn"); - assertTrue(environment.matches(new StubEntry(values), null)); - - installedFeatures.add("org.eclipse.cdt"); - assertFalse(environment.matches(new StubEntry(values), null)); - } - - public void testMatchesFilter() { - Map<String, String> values = new HashMap<String, String>(); - values.put("filter", "(EnvironmentTest<=1)"); - assertFalse(environment.matches(new StubEntry(values), null)); - - values.put("filter", "(EnvironmentTest=2)"); - assertTrue(environment.matches(new StubEntry(values), null)); - } - -} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/FeedReaderTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/FeedReaderTest.java deleted file mode 100644 index 45c735753..000000000 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/FeedReaderTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Tasktop Technologies. - * 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.tests.core; - -import java.util.Collections; -import java.util.Set; - -import junit.framework.TestCase; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil; -import org.eclipse.mylyn.internal.tasks.core.notifications.Environment; -import org.eclipse.mylyn.internal.tasks.core.notifications.FeedEntry; -import org.eclipse.mylyn.internal.tasks.core.notifications.FeedReader; - -/** - * @author Steffen Pingel - */ -public class FeedReaderTest extends TestCase { - - private FeedReader reader; - - private Environment environment; - - @Override - protected void setUp() throws Exception { - environment = new Environment() { - @Override - public Set<String> getInstalledFeatures(IProgressMonitor monitor) { - return Collections.singleton("org.eclipse.mylyn"); - } - }; - reader = new FeedReader(environment); - } - - public void testParse() throws Exception { - assertEquals(Status.OK_STATUS, reader.parse( - CommonTestUtil.getResource(FeedReaderTest.class, "testdata/FeedReaderTest/update1.xml"), null)); - assertEquals(2, reader.getEntries().size()); - Collections.sort(reader.getEntries()); - - FeedEntry entry = reader.getEntries().get(0); - assertEquals("New Connectors", entry.getTitle()); - assertEquals("[0.0.0,3.7.0)", entry.getFilter("frameworkVersion")); - assertEquals("New connectors are now available. <a href=\"#discovery\">Show connectors</a>.", - entry.getDescription()); - - entry = reader.getEntries().get(1); - assertEquals("Mylyn 3.6 is now available", entry.getTitle()); - assertEquals("1.5.0", entry.getFilter("runtimeVersion")); - assertEquals( - "Mylyn 3.7 is now available. <a href=\"http://eclipse.org/mylyn/new/\">See New and Noteworthy</a> for details.", - entry.getDescription()); - } - -} diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/util/ServiceMessageManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/util/ServiceMessageManagerTest.java deleted file mode 100644 index 72aaf758f..000000000 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/util/ServiceMessageManagerTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.tests.util; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; - -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import junit.framework.TestCase; - -import org.apache.commons.httpclient.HttpStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.mylyn.internal.tasks.core.notifications.ServiceMessage; -import org.eclipse.mylyn.internal.tasks.core.notifications.ServiceMessageManager; -import org.eclipse.mylyn.internal.tasks.core.notifications.ServiceMessageXmlHandler; - -/** - * @author Robert Elves - */ -public class ServiceMessageManagerTest extends TestCase { - - private static final String MESSAGE_XML_URL = "http://mylyn.eclipse.org/message.xml"; - - public void testRetrievingMessage() throws Exception { - ServiceMessageManager manager = new ServiceMessageManager(MESSAGE_XML_URL, "", "", 0l); - int status = manager.updateServiceMessage(new NullProgressMonitor()); - assertEquals(HttpStatus.SC_OK, status); - assertEquals(2, manager.getServiceMessages().size()); - - ServiceMessage message = manager.getServiceMessages().get(1); - assertEquals("1", message.getId()); - assertEquals("140 character description here....", message.getDescription()); - assertEquals("Mylyn 3.4 now available!", message.getTitle()); - assertEquals("http://eclipse.org/mylyn/downloads", message.getUrl()); - assertEquals("Mylyn 3.4 now available!", message.getTitle()); - assertEquals("dialog_messasge_info_image", message.getImage()); - } - - public void testETag() throws Exception { - - ServiceMessageManager manager = new ServiceMessageManager(MESSAGE_XML_URL, "", "", 0l); - int status = manager.updateServiceMessage(new NullProgressMonitor()); - assertEquals(HttpStatus.SC_OK, status); - ServiceMessage message = manager.getServiceMessages().get(0); - - assertNotNull(message.getLastModified()); - assertNotNull(message.getETag()); - - status = manager.updateServiceMessage(new NullProgressMonitor()); - assertEquals(HttpStatus.SC_NOT_MODIFIED, status); - } - - public void testParsingMessageXml() throws Exception { - String messageXml = "<ServiceMessage> <id>1</id><description>140 character description here....</description><title>Mylyn 3.4 now available!</title><url>http://eclipse.org/mylyn/downloads</url><image>dialog_messasge_info_image</image></ServiceMessage>"; - InputStream is = new ByteArrayInputStream(messageXml.getBytes("UTF-8")); - SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setValidating(false); - SAXParser parser = factory.newSAXParser(); - ServiceMessageXmlHandler handler = new ServiceMessageXmlHandler(); - parser.parse(is, handler); - ServiceMessage message = handler.getMessages().get(0); - - assertEquals("1", message.getId()); - assertEquals("140 character description here....", message.getDescription()); - assertEquals("Mylyn 3.4 now available!", message.getTitle()); - assertEquals("http://eclipse.org/mylyn/downloads", message.getUrl()); - assertEquals("Mylyn 3.4 now available!", message.getTitle()); - assertEquals("dialog_messasge_info_image", message.getImage()); - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF index 3691cefd2..03ae49d2a 100644 --- a/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF @@ -23,6 +23,9 @@ Require-Bundle: org.eclipse.ui, org.eclipse.mylyn.commons.repositories;bundle-version="0.1.0", org.eclipse.mylyn.commons.identity;bundle-version="0.8.0", org.eclipse.mylyn.commons.net;bundle-version="[3.0.0,4.0.0)", + org.eclipse.mylyn.commons.notifications.core, + org.eclipse.mylyn.commons.notifications.feed, + org.eclipse.mylyn.commons.notifications.ui, org.eclipse.mylyn.commons.repositories;bundle-version="0.1.0", org.eclipse.mylyn.commons.ui;bundle-version="[3.0.0,4.0.0)", org.eclipse.mylyn.commons.workbench;bundle-version="[3.0.0,4.0.0)", diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskListNotificationProvider.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskListNotificationProvider.java index 3f41a9e5b..6b17d2d71 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskListNotificationProvider.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskListNotificationProvider.java @@ -13,13 +13,13 @@ package org.eclipse.mylyn.internal.tasks.ui; import java.util.Set; -import org.eclipse.mylyn.internal.tasks.ui.notifications.AbstractNotification; +import org.eclipse.mylyn.commons.notifications.ui.AbstractUiNotification; /** * @author Rob Elves */ public interface ITaskListNotificationProvider { - public Set<AbstractNotification> getNotifications(); + public Set<AbstractUiNotification> getNotifications(); } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationManager.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationManager.java index 08d06e77d..9e255696d 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationManager.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationManager.java @@ -27,7 +27,7 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.window.Window; -import org.eclipse.mylyn.internal.tasks.ui.notifications.AbstractNotification; +import org.eclipse.mylyn.commons.notifications.ui.AbstractUiNotification; import org.eclipse.mylyn.internal.tasks.ui.notifications.TaskListNotificationPopup; import org.eclipse.mylyn.internal.tasks.ui.notifications.TaskListNotifier; import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; @@ -45,9 +45,9 @@ public class TaskListNotificationManager implements IPropertyChangeListener { private TaskListNotificationPopup popup; - private final Set<AbstractNotification> notifications = new HashSet<AbstractNotification>(); + private final Set<AbstractUiNotification> notifications = new HashSet<AbstractUiNotification>(); - private final Set<AbstractNotification> currentlyNotifying = Collections.synchronizedSet(notifications); + private final Set<AbstractUiNotification> currentlyNotifying = Collections.synchronizedSet(notifications); private final List<ITaskListNotificationProvider> notificationProviders = new ArrayList<ITaskListNotificationProvider>(); @@ -67,16 +67,16 @@ public class TaskListNotificationManager implements IPropertyChangeListener { collectNotifications(); if (popup != null && popup.getReturnCode() == Window.CANCEL) { - List<AbstractNotification> notifications = popup.getNotifications(); - for (AbstractNotification notification : notifications) { + List<AbstractUiNotification> notifications = popup.getNotifications(); + for (AbstractUiNotification notification : notifications) { if (notification.getToken() != null) { cancelledTokens.put(notification.getToken(), null); } } } - for (Iterator<AbstractNotification> it = currentlyNotifying.iterator(); it.hasNext();) { - AbstractNotification notification = it.next(); + for (Iterator<AbstractUiNotification> it = currentlyNotifying.iterator(); it.hasNext();) { + AbstractUiNotification notification = it.next(); if (notification.getToken() != null && cancelledTokens.containsKey(notification.getToken())) { it.remove(); @@ -120,7 +120,7 @@ public class TaskListNotificationManager implements IPropertyChangeListener { Shell shell = new Shell(PlatformUI.getWorkbench().getDisplay()); popup = new TaskListNotificationPopup(shell); popup.setFadingEnabled(TasksUiInternal.isAnimationsEnabled()); - List<AbstractNotification> toDisplay = new ArrayList<AbstractNotification>(currentlyNotifying); + List<AbstractUiNotification> toDisplay = new ArrayList<AbstractUiNotification>(currentlyNotifying); Collections.sort(toDisplay); popup.setContents(toDisplay); cleanNotified(); @@ -186,7 +186,7 @@ public class TaskListNotificationManager implements IPropertyChangeListener { /** * public for testing purposes */ - public Set<AbstractNotification> getNotifications() { + public Set<AbstractUiNotification> getNotifications() { synchronized (TaskListNotificationManager.class) { return currentlyNotifying; } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java index 12e711abe..8278bb284 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java @@ -52,6 +52,9 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.SafeRunnable; import org.eclipse.mylyn.commons.core.StatusHandler; import org.eclipse.mylyn.commons.net.WebUtil; +import org.eclipse.mylyn.commons.notifications.core.NotificationEnvironment; +import org.eclipse.mylyn.commons.notifications.feed.ServiceMessageManager; +import org.eclipse.mylyn.commons.notifications.ui.AbstractUiNotification; import org.eclipse.mylyn.commons.ui.compatibility.CommonColors; import org.eclipse.mylyn.commons.ui.compatibility.CommonFonts; import org.eclipse.mylyn.commons.workbench.TaskBarManager; @@ -80,11 +83,8 @@ import org.eclipse.mylyn.internal.tasks.core.externalization.ExternalizationMana import org.eclipse.mylyn.internal.tasks.core.externalization.IExternalizationParticipant; import org.eclipse.mylyn.internal.tasks.core.externalization.TaskListExternalizationParticipant; import org.eclipse.mylyn.internal.tasks.core.externalization.TaskListExternalizer; -import org.eclipse.mylyn.internal.tasks.core.notifications.Environment; -import org.eclipse.mylyn.internal.tasks.core.notifications.ServiceMessageManager; import org.eclipse.mylyn.internal.tasks.ui.actions.ActivateTaskDialogAction; import org.eclipse.mylyn.internal.tasks.ui.actions.NewTaskAction; -import org.eclipse.mylyn.internal.tasks.ui.notifications.AbstractNotification; import org.eclipse.mylyn.internal.tasks.ui.notifications.TaskListNotificationReminder; import org.eclipse.mylyn.internal.tasks.ui.notifications.TaskListNotifier; import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiExtensionReader; @@ -256,9 +256,9 @@ public class TasksUiPlugin extends AbstractUIPlugin { private static ITaskListNotificationProvider REMINDER_NOTIFICATION_PROVIDER = new ITaskListNotificationProvider() { - public Set<AbstractNotification> getNotifications() { + public Set<AbstractUiNotification> getNotifications() { Collection<AbstractTask> allTasks = TasksUiPlugin.getTaskList().getAllTasks(); - Set<AbstractNotification> reminders = new HashSet<AbstractNotification>(); + Set<AbstractUiNotification> reminders = new HashSet<AbstractUiNotification>(); for (AbstractTask task : allTasks) { if (TasksUiPlugin.getTaskActivityManager().isPastReminder(task) && !task.isReminded()) { reminders.add(new TaskListNotificationReminder(task)); @@ -640,7 +640,7 @@ public class TasksUiPlugin extends AbstractUIPlugin { Long checktime = getPreferenceStore().getLong(ITasksUiPreferenceConstants.LAST_SERVICE_MESSAGE_CHECKTIME); serviceMessageManager = new ServiceMessageManager(serviceMessageUrl, lastMod, etag, checktime, - new Environment() { + new NotificationEnvironment() { private Set<String> installedFeatures; @Override diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/AbstractNotification.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/AbstractNotification.java deleted file mode 100644 index 4997c1410..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/AbstractNotification.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 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 - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.ui.notifications; - -import java.util.Date; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.swt.graphics.Image; - -/** - * @author Rob Elves - * @author Mik Kersten - * @deprecated use {@link org.org.eclipse.mylyn.internal.tasks.ui.notifications.notifications.AbstractNotification} instead - */ -@Deprecated -public abstract class AbstractNotification implements Comparable<AbstractNotification>, IAdaptable { - - public abstract void open(); - - public abstract String getDescription(); - - public abstract String getLabel(); - - public abstract Image getNotificationImage(); - - public abstract Image getNotificationKindImage(); - - public abstract Date getDate(); - - public abstract void setDate(Date date); - - public Object getToken() { - return null; - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotification.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotification.java index e5a0c2a6a..c768ce4e3 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotification.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotification.java @@ -16,6 +16,8 @@ import java.util.Date; import org.eclipse.core.runtime.Assert; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.mylyn.commons.notifications.core.AbstractNotification; +import org.eclipse.mylyn.commons.notifications.ui.AbstractUiNotification; import org.eclipse.mylyn.commons.ui.CommonImages; import org.eclipse.mylyn.internal.tasks.core.AbstractTask; import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; @@ -29,7 +31,9 @@ import org.eclipse.ui.PlatformUI; * @author Rob Elves * @author Mik Kersten */ -public class TaskListNotification extends AbstractNotification { +public class TaskListNotification extends AbstractUiNotification { + + private final static String ID_EVENT_TASK_CHANGED = "org.eclipse.mylyn.tasks.ui.events.TaskChanged"; private static DecoratingLabelProvider labelProvider; @@ -42,10 +46,19 @@ public class TaskListNotification extends AbstractNotification { private final Object token; public TaskListNotification(ITask task) { - this(task, null); + this(ID_EVENT_TASK_CHANGED, task, null); + } + + public TaskListNotification(String eventId, ITask task) { + this(eventId, task, null); } public TaskListNotification(ITask task, Object token) { + this(ID_EVENT_TASK_CHANGED, task, token); + } + + public TaskListNotification(String eventId, ITask task, Object token) { + super(eventId); Assert.isNotNull(task); this.task = task; this.token = token; @@ -109,11 +122,11 @@ public class TaskListNotification extends AbstractNotification { return date; } - @Override public void setDate(Date date) { this.date = date; } + @Override public int compareTo(AbstractNotification anotherNotification) throws ClassCastException { Date anotherDate = anotherNotification.getDate(); if (date != null && anotherDate != null) { diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotificationPopup.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotificationPopup.java index 54dbca419..71961901b 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotificationPopup.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotificationPopup.java @@ -16,6 +16,7 @@ import java.util.List; import org.eclipse.jface.action.LegacyActionTools; import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.mylyn.commons.notifications.ui.AbstractUiNotification; import org.eclipse.mylyn.commons.workbench.AbstractWorkbenchNotificationPopup; import org.eclipse.mylyn.internal.tasks.core.AbstractTask; import org.eclipse.mylyn.internal.tasks.ui.TaskScalingHyperlink; @@ -46,18 +47,18 @@ public class TaskListNotificationPopup extends AbstractWorkbenchNotificationPopu private static final int NUM_NOTIFICATIONS_TO_DISPLAY = 4; - private List<AbstractNotification> notifications; + private List<AbstractUiNotification> notifications; public TaskListNotificationPopup(Shell parent) { super(parent.getDisplay()); } - public void setContents(List<AbstractNotification> notifications) { + public void setContents(List<AbstractUiNotification> notifications) { this.notifications = notifications; } - public List<AbstractNotification> getNotifications() { - return new ArrayList<AbstractNotification>(notifications); + public List<AbstractUiNotification> getNotifications() { + return new ArrayList<AbstractUiNotification>(notifications); } @Override @@ -74,7 +75,7 @@ public class TaskListNotificationPopup extends AbstractWorkbenchNotificationPopu @Override protected void createContentArea(Composite parent) { int count = 0; - for (final AbstractNotification notification : notifications) { + for (final AbstractUiNotification 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); diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotificationReminder.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotificationReminder.java index da75f3ac0..7624adbdb 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotificationReminder.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotificationReminder.java @@ -21,8 +21,10 @@ import org.eclipse.swt.graphics.Image; */ public class TaskListNotificationReminder extends TaskListNotification { + private final static String ID_EVENT_TASK_DUE = "org.eclipse.mylyn.tasks.ui.events.TaskDue"; + public TaskListNotificationReminder(AbstractTask task) { - super(task); + super(ID_EVENT_TASK_DUE, task); } @Override diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotifier.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotifier.java index 19a88bd72..3ee82ea33 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotifier.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListNotifier.java @@ -22,6 +22,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.mylyn.commons.core.StatusHandler; +import org.eclipse.mylyn.commons.notifications.ui.AbstractUiNotification; import org.eclipse.mylyn.internal.tasks.core.RepositoryModel; import org.eclipse.mylyn.internal.tasks.core.data.ITaskDataManagerListener; import org.eclipse.mylyn.internal.tasks.core.data.SynchronizationManger; @@ -116,12 +117,12 @@ public class TaskListNotifier implements ITaskDataManagerListener, ITaskListNoti } } - public Set<AbstractNotification> getNotifications() { + public Set<AbstractUiNotification> getNotifications() { synchronized (notificationQueue) { if (notificationQueue.isEmpty()) { return Collections.emptySet(); } - HashSet<AbstractNotification> result = new HashSet<AbstractNotification>(notificationQueue); + HashSet<AbstractUiNotification> result = new HashSet<AbstractUiNotification>(notificationQueue); notificationQueue.clear(); return result; } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListServiceMessageControl.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListServiceMessageControl.java index 960d3a310..71992b9ef 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListServiceMessageControl.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/notifications/TaskListServiceMessageControl.java @@ -23,11 +23,11 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.mylyn.commons.workbench.forms.NotificationControl; +import org.eclipse.mylyn.commons.notifications.feed.IServiceMessageListener; +import org.eclipse.mylyn.commons.notifications.feed.ServiceMessageEvent; +import org.eclipse.mylyn.commons.notifications.ui.NotificationControl; +import org.eclipse.mylyn.internal.commons.notifications.feed.ServiceMessage; import org.eclipse.mylyn.internal.tasks.core.LocalTask; -import org.eclipse.mylyn.internal.tasks.core.notifications.IServiceMessageListener; -import org.eclipse.mylyn.internal.tasks.core.notifications.ServiceMessage; -import org.eclipse.mylyn.internal.tasks.core.notifications.ServiceMessageEvent; import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; import org.eclipse.mylyn.internal.tasks.ui.actions.AddRepositoryAction; diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java index 06c672bec..9f19810b2 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java @@ -64,6 +64,7 @@ import org.eclipse.mylyn.commons.ui.PlatformUiUtil; import org.eclipse.mylyn.commons.ui.compatibility.CommonThemes; import org.eclipse.mylyn.commons.workbench.DelayedRefreshJob; import org.eclipse.mylyn.commons.workbench.GradientDrawer; +import org.eclipse.mylyn.internal.commons.notifications.feed.ServiceMessage; import org.eclipse.mylyn.internal.tasks.core.AbstractTask; import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer; import org.eclipse.mylyn.internal.tasks.core.ITaskListChangeListener; @@ -72,7 +73,6 @@ import org.eclipse.mylyn.internal.tasks.core.TaskContainerDelta; import org.eclipse.mylyn.internal.tasks.core.UncategorizedTaskContainer; import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer; import org.eclipse.mylyn.internal.tasks.core.UnsubmittedTaskContainer; -import org.eclipse.mylyn.internal.tasks.core.notifications.ServiceMessage; import org.eclipse.mylyn.internal.tasks.ui.AbstractTaskListFilter; import org.eclipse.mylyn.internal.tasks.ui.CategorizedPresentation; import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; @@ -1015,7 +1015,7 @@ public class TaskListView extends ViewPart implements IPropertyChangeListener, I .getString(ITasksUiPreferenceConstants.LAST_SERVICE_MESSAGE_ID); if (showMessage && lastClosedId.equals("")) { //$NON-NLS-1$ - ServiceMessage message = new ServiceMessage(); + ServiceMessage message = new ServiceMessage("welcome"); message.setDescription(Messages.TaskListView_Welcome_Message); message.setTitle(Messages.TaskListView_Welcome_Message_Title); message.setImage(Dialog.DLG_IMG_MESSAGE_INFO); |