/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.openapi.actionSystem.impl;

import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.IdeFocusManager;
import java.util.HashMap;

import java.util.Map;

public class SimpleDataContext implements DataContext {
  private final Map<String, Object> myDataId2Data;
  private final DataContext myParent;

  private SimpleDataContext(String dataId, Object data, DataContext parent) {
    myDataId2Data = new HashMap<>(1);
    myDataId2Data.put(dataId, data);
    myParent = parent;
  }
  
  private SimpleDataContext(Map<String, Object> dataid2data, DataContext parent) {
    myDataId2Data = dataid2data;
    myParent = parent;
  }

  @Override
  public Object getData(String dataId) {
    Object result =  myDataId2Data.containsKey(dataId) ? myDataId2Data.get(dataId) : 
           myParent == null ? null : myParent.getData(dataId);
    
    if (result == null && PlatformDataKeys.CONTEXT_COMPONENT.getName().equals(dataId)) {
      result = IdeFocusManager.getGlobalInstance().getFocusOwner();
    }

    return result;
  }

  public static DataContext getSimpleContext(String dataId, Object data, DataContext parent) {
    return new SimpleDataContext(dataId, data, parent);
  }
  
  public static DataContext getSimpleContext(Map<String,Object> dataId2data, DataContext parent) {
    return new SimpleDataContext(dataId2data, parent);
  }

  public static DataContext getSimpleContext(String dataId, Object data) {
    return getSimpleContext(dataId, data, null);
  }

  public static DataContext getProjectContext(Project project) {
    return getSimpleContext(CommonDataKeys.PROJECT.getName(), project);
  }
}

@@ -1,13 +1,10 @@
 /
-*%0A *
+/
  Copyrig
@@ -18,9 +18,9 @@
 -201
-3
+8
  Jet
@@ -36,615 +36,293 @@
 r.o.
-%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.intellij.openapi.actionSystem.impl;%0A
+ Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.%0Apackage com.intellij.openapi.actionSystem.impl;%0A%0Aimport com.intellij.ide.DataManager;%0Aimport com.intellij.ide.impl.DataManagerImpl;%0Aimport com.intellij.ide.impl.dataRules.GetDataRule;
 %0Aimp
@@ -429,16 +429,71 @@
 ontext;%0A
+import com.intellij.openapi.actionSystem.DataProvider;%0A
 import c
@@ -632,24 +632,68 @@
 cusManager;%0A
+import org.jetbrains.annotations.Nullable;%0A%0A
 import java.
@@ -706,17 +706,16 @@
 ashMap;%0A
-%0A
 import j
@@ -873,16 +873,94 @@
 yParent;
+%0A  private boolean myWithRules = false;%0A  private DataProvider myDataProvider;
 %0A%0A  priv
@@ -1207,32 +1207,51 @@
 taContext parent
+, boolean withRules
 ) %7B%0A    myDataId
@@ -1290,24 +1290,270 @@
 t = parent;%0A
+    myWithRules = withRules;%0A    if (withRules) %7B%0A      myDataProvider = new DataProvider() %7B%0A        @Nullable%0A        @Override%0A        public Object getData(String dataId) %7B%0A          return myDataId2Data.get(dataId);%0A        %7D%0A      %7D;%0A    %7D%0A
   %7D%0A%0A  @Over
@@ -1916,16 +1916,234 @@
 %0A    %7D%0A%0A
+    if (result == null && myWithRules) %7B%0A      GetDataRule rule = ((DataManagerImpl)DataManager.getInstance()).getDataRule(dataId);%0A      if (rule != null) %7B%0A        return rule.getData(myDataProvider);%0A      %7D%0A    %7D%0A%0A
     retu
@@ -2463,24 +2463,296 @@
 data, parent
+, false);%0A  %7D%0A%0A  /**%0A   * Creates a simple data context which can apply data rules.%0A   */%0A  public static DataContext getSimpleContext(Map%3CString, Object%3E dataId2data, DataContext parent, boolean withRules) %7B%0A    return new SimpleDataContext(dataId2data, parent, withRules
 );%0A  %7D%0A%0A  pu

Support data rules in SimpleDataContext