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