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