Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 00f61634803e911804f92bdf64343990260a5634 (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
/*******************************************************************************
 * Copyright (c) 2005, 2015 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ui.navigator;

import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.ui.internal.navigator.NavigatorContentService;


/**
 * Provides a factory pattern for creating {@link INavigatorContentService}s
 * for given viewer ids.
 *
 * <p>
 * Clients may supply the viewer in {@link #createContentService(String, StructuredViewer) }
 * or wait until the content provider is created by the service
 * and set on the viewer. When the content provider is set, the
 * viewer will call inputChanged(), and the content service
 * will update its managed viewer accordingly. Therefore, each
 * content service should be attached to at most one viewer.
 * </p>
 *
 * @since 3.2
 *
 */
public final class NavigatorContentServiceFactory {

	/**
	 * The singleton instance for creating NavigatorContentServices.
	 */
	public static final NavigatorContentServiceFactory INSTANCE = new NavigatorContentServiceFactory();


	/**
	 * Returns an instance of INavigatorContentService configured
	 * for the given id. Instances are not shared for the same
	 * viewerId.
	 *
	 * @param aViewerId The viewer id of interest
	 * @return An instance of INavigatorContentService configured for the given id.
	 */
	public INavigatorContentService createContentService(String aViewerId) {
		return createContentService(aViewerId, null);
	}

	/**
	 * Returns an instance of INavigatorContentService configured
	 * for the given id. Instances are not shared for the same
	 * viewerId.
	 *
	 * @param aViewerId The viewer id of interest
	 * @param aViewer The content service can use the given viewer to initialize content providers
	 * @return An instance of INavigatorContentService configured for the given id.
	 * @see IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, Object, Object)
	 */
	public INavigatorContentService createContentService(String aViewerId, StructuredViewer aViewer) {
		if(aViewer == null) {
			return new NavigatorContentService(aViewerId);
		}
		return new NavigatorContentService(aViewerId, aViewer);
	}

}

Back to the top