Skip to main content
summaryrefslogtreecommitdiffstats
blob: f18f441580536f0ca962fc1fb8cabe7fcb8711f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*******************************************************************************
 * Copyright (c) 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
 *******************************************************************************/

package org.eclipse.mylyn.tasks.core.spi;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;

import com.google.common.collect.ImmutableList;

/**
 * Specifies branding for a connector. The branding extension is obtained by adapting an
 * {@link AbstractRepositoryConnector} instance to {@link RepositoryConnectorBranding}.
 * <p>
 * To contribute branding clients need to register an {@link IAdapterFactory} for the type
 * {@link AbstractRepositoryConnector}.
 * </p>
 * Example <code>plugin.xml</code>:
 * <p>
 * 
 * <pre>
 *  &lt;extension
 *        point="org.eclipse.core.runtime.adapters"&gt;
 *     &lt;factory
 *           adaptableType="org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector"
 *           class="MyRepositoryConnectorAdapter"&gt;
 *        &lt;adapter
 *              type="org.eclipse.mylyn.tasks.core.spi.RepositoryConnectorBranding"&gt;
 *        &lt;/adapter&gt;
 *     &lt;/factory&gt;
 *  &lt;/extension&gt;
 * </pre>
 * 
 * </p>
 * <p>
 * <code>MyRepositoryConnector</code> needs to return an instance of {@link RepositoryConnectorBranding} for the
 * appropriate connector instance:
 * 
 * <pre>
 * public class MyRepositoryConnectorAdapter implements IAdapterFactory {
 * 
 * 	&#064;Override
 * 	public Object getAdapter(Object adaptableObject, Class adapterType) {
 * 		if (adaptableObject instanceof MyRepositoryConnector) {
 * 			if (adapterType == RepositoryConnectorBranding.class) {
 * 				return new RepositoryConnectorBranding() {
 * 					&#064;Override
 * 					public InputStream getOverlayImageData() throws IOException {
 * 						return getResource(this, &quot;repository-overlay.gif&quot;);
 * 					}
 * 
 * 					&#064;Override
 * 					public InputStream getBrandingImageData() throws IOException {
 * 						return CommonTestUtil.getResource(this, &quot;repository.gif&quot;);
 * 					}
 * 				};
 * 			}
 * 		}
 * 		return null;
 * 	}
 * }
 * </pre>
 * 
 * </p>
 * 
 * @since 3.10
 * @see RepositoryConnectorContributor
 * @see RepositoryConnectorDescriptor
 */
public abstract class RepositoryConnectorBranding {

	/**
	 * Returns an input stream with the image data for a 16x16 branding icon, for a connector that is registered at
	 * runtime using {@link RepositoryConnectorContributor}. This is typically shown in the UI when selecting
	 * connectors. Supported file formats are GIF and PNG.
	 * <p>
	 * Note: for connectors contributed through the <code>org.eclipse.mylyn.tasks.ui.repositories</code> extension
	 * point, the branding image specified in the extension takes precedence; this method is never called.
	 * 
	 * @return input stream for image data
	 * @throws IOException
	 *             thrown if opening of the stream fails
	 */
	@NonNull
	public abstract InputStream getBrandingImageData() throws IOException;

	/**
	 * Returns an input stream with the image data for a 7x8 overlay branding icon, for a connector that is registered
	 * at runtime using {@link RepositoryConnectorContributor}. This is typically a very small version of the branding
	 * icon that is used for overlays over repository icons. Supported file formats are GIF and PNG.
	 * <p>
	 * Note: for connectors contributed through the <code>org.eclipse.mylyn.tasks.ui.repositories</code> extension
	 * point, the overlay image specified in the extension takes precedence; this method is never called.
	 * 
	 * @return input stream for image data
	 * @throws IOException
	 *             thrown if opening of the stream fails
	 */
	@NonNull
	public abstract InputStream getOverlayImageData() throws IOException;

	/**
	 * Returns a list of identifiers of the brands supported by this connector. This is useful for connectors that can
	 * connect to different brands of the same system. Typically, different brands are functionally identical but use
	 * different labels and icons.
	 * <p>
	 * Each brand may be presented in the UI as though it were a separate connector.
	 * 
	 * @since 3.16
	 */
	@NonNull
	public List<String> getBrands() {
		return ImmutableList.of();
	}

	/**
	 * Returns branding image data for a specific brand of the target system. Returns <code>null</code> if the given
	 * brand is unknown to the connector or uses the {@link #getBrandingImageData() default branding image}. The default
	 * implementation always returns <code>null</code>.
	 * 
	 * @return input stream for image data, or <code>null</code>
	 * @throws IOException
	 *             thrown if opening of the stream fails
	 * @see #getBrandingImageData()
	 * @see #getBrands()
	 * @since 3.16
	 */
	@Nullable
	public InputStream getBrandingImageData(@NonNull String brand) throws IOException {
		return null;
	}

	/**
	 * Returns overlay image data for a specific brand of the target system. Returns <code>null</code> if the given
	 * brand is unknown to the connector or uses the {@link #getOverlayImageData() default overlay image}. The default
	 * implementation always returns <code>null</code>.
	 * 
	 * @param brand
	 * @throws IOException
	 *             thrown if opening of the stream fails
	 * @return
	 * @see #getOverlayImageData()
	 * @see #getBrands()
	 * @since 3.16
	 */
	@Nullable
	public InputStream getOverlayImageData(@NonNull String brand) throws IOException {
		return null;
	}

	/**
	 * Returns the connector label to use for a specific brand of the target system. Returns <code>null</code> if the
	 * given brand is unknown to the connector or uses the {@link AbstractRepositoryConnector#getLabel() default
	 * connector label}. The default implementation always returns <code>null</code>.
	 * 
	 * @param brand
	 * @return
	 * @see AbstractRepositoryConnector#getLabel()
	 * @see #getBrands()
	 * @since 3.16
	 */
	@Nullable
	public String getConnectorLabel(@NonNull String brand) {
		return null;
	}

}

Back to the top