1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2005, 2006 IBM Corporation and others.
|
3
|
* All rights reserved. This program and the accompanying materials
|
4
|
* are made available under the terms of the Eclipse Public License v1.0
|
5
|
* which accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors:
|
9
|
* IBM Corporation - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
package org.eclipse.ui.navigator;
|
12
|
|
13
|
import org.eclipse.jface.viewers.IContentProvider;
|
14
|
import org.eclipse.jface.viewers.StructuredViewer;
|
15
|
import org.eclipse.ui.internal.navigator.NavigatorContentService;
|
16
|
|
17
|
|
18
|
/**
|
19
|
* Provides a factory pattern for creating {@link INavigatorContentService}s
|
20
|
* for given viewer ids.
|
21
|
*
|
22
|
* <p>
|
23
|
* Clients may supply the viewer in {@link #createContentService(String, StructuredViewer) }
|
24
|
* or wait until the content provider is created by the service
|
25
|
* and set on the viewer. When the content provider is set, the
|
26
|
* viewer will call inputChanged(), and the content service
|
27
|
* will update its managed viewer accordingly. Therefore, each
|
28
|
* content service should be attached to at most one viewer.
|
29
|
* </p>
|
30
|
*
|
31
|
* @since 3.2
|
32
|
*
|
33
|
*/
|
34
|
public final class NavigatorContentServiceFactory {
|
35
|
|
36
|
/**
|
37
|
* The singleton instance for creating NavigatorContentServices.
|
38
|
*/
|
39
|
public static final NavigatorContentServiceFactory INSTANCE = new NavigatorContentServiceFactory();
|
40
|
|
41
|
|
42
|
/**
|
43
|
* Returns an instance of INavigatorContentService configured
|
44
|
* for the given id. Instances are not shared for the same
|
45
|
* viewerId.
|
46
|
*
|
47
|
* @param aViewerId The viewer id of interest
|
48
|
* @return An instance of INavigatorContentService configured for the given id.
|
49
|
*/
|
50
|
public INavigatorContentService createContentService(String aViewerId) {
|
51
|
return createContentService(aViewerId, null);
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* Returns an instance of INavigatorContentService configured
|
56
|
* for the given id. Instances are not shared for the same
|
57
|
* viewerId.
|
58
|
*
|
59
|
* @param aViewerId The viewer id of interest
|
60
|
* @param aViewer The content service can use the given viewer to initialize content providers
|
61
|
* @return An instance of INavigatorContentService configured for the given id.
|
62
|
* @see IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, Object, Object)
|
63
|
*/
|
64
|
public INavigatorContentService createContentService(String aViewerId, StructuredViewer aViewer) {
|
65
|
if(aViewer == null) {
|
66
|
return new NavigatorContentService(aViewerId);
|
67
|
}
|
68
|
return new NavigatorContentService(aViewerId, aViewer);
|
69
|
}
|
70
|
|
71
|
}
|