Merge branch 'master' of git@git.labs.intellij.net:idea/community into tool-window
[fedora-idea.git] / platform / platform-impl / src / com / intellij / ide / impl / TypeSafeDataProviderAdapter.java
blobdc94380c8049a4b65bfe715ddce4a03d072844ff
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Created by IntelliJ IDEA.
19 * User: yole
20 * Date: 25.10.2006
21 * Time: 17:24:41
23 package com.intellij.ide.impl;
25 import com.intellij.openapi.actionSystem.DataKey;
26 import com.intellij.openapi.actionSystem.DataProvider;
27 import com.intellij.openapi.actionSystem.DataSink;
28 import com.intellij.openapi.actionSystem.TypeSafeDataProvider;
29 import org.jetbrains.annotations.NonNls;
30 import org.jetbrains.annotations.Nullable;
32 public class TypeSafeDataProviderAdapter implements DataProvider, DataSink {
33 private final TypeSafeDataProvider myProvider;
34 private DataKey myLastKey = null;
35 private Object myValue = null;
37 public TypeSafeDataProviderAdapter(final TypeSafeDataProvider provider) {
38 myProvider = provider;
41 @Nullable
42 synchronized public Object getData(@NonNls String dataId) {
43 myValue = null;
44 myLastKey = DataKey.create(dataId);
45 myProvider.calcData(myLastKey, this);
46 return myValue;
49 synchronized public <T> void put(DataKey<T> key, T data) {
50 if (key == myLastKey) {
51 myValue = data;
55 @Override
56 public String toString() {
57 return super.toString()+'('+ myProvider + ')';