01: /*******************************************************************************
02: * Copyright (c) 2007 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.internal.navigator;
11:
12: import java.util.HashMap;
13: import java.util.Map;
14:
15: import org.eclipse.ui.internal.navigator.extensions.ExtensionStateModel;
16: import org.eclipse.ui.navigator.IExtensionStateModel;
17: import org.eclipse.ui.navigator.INavigatorContentDescriptor;
18: import org.eclipse.ui.navigator.INavigatorContentService;
19:
20: /**
21: *
22: * A content extension may have its content and label providers disposed
23: * whenever the extension is activated or deactivated. However, the state model
24: * lives throughout the life of the viewer to allow Action Providers to drive
25: * their behavior from it.
26: *
27: * @since 3.3
28: *
29: */
30: public class NavigatorExtensionStateService {
31:
32: private final Object lock = new Object();
33: private INavigatorContentService contentService;
34:
35: /**
36: * Create an ExtensionStateServie that will keep track of the state models
37: * of content extensions.
38: *
39: * @param theContentService
40: * The content service which manages this state model service.
41: */
42: public NavigatorExtensionStateService(
43: INavigatorContentService theContentService) {
44: contentService = theContentService;
45: }
46:
47: /*
48: * A map of (String-based-Navigator-Content-Extension-IDs,
49: * NavigatorContentExtension-objects)-pairs
50: */
51: private final Map/* <INavigatorContentDescriptor, IExtensionStateModel> */stateModels = new HashMap();
52:
53: /**
54: * Return the state model for the given descriptor.
55: *
56: * @param aDescriptor A content descriptor
57: * @return The state model for the given descriptor.
58: */
59: public IExtensionStateModel getExtensionStateModel(
60: INavigatorContentDescriptor aDescriptor) {
61: synchronized (lock) {
62: IExtensionStateModel model = (IExtensionStateModel) stateModels
63: .get(aDescriptor);
64: if (model == null)
65: stateModels
66: .put(aDescriptor,
67: model = new ExtensionStateModel(
68: aDescriptor.getId(),
69: contentService.getViewerId()));
70: return model;
71: }
72: }
73:
74: }
|