Java 类com.intellij.openapi.actionSystem.DataKey 实例源码

项目:intellij-ce-playground    文件:LazyUiDisposable.java   
private static AsyncResult<Disposable> findDisposable(Disposable defaultValue, final DataKey<? extends Disposable> key) {
  if (defaultValue == null) {
    if (ApplicationManager.getApplication() != null) {
      final AsyncResult<Disposable> result = new AsyncResult<Disposable>();
      DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {
        public void consume(DataContext context) {
          Disposable disposable = key.getData(context);
          if (disposable == null) {
            disposable = Disposer.get("ui");
          }
          result.setDone(disposable);
        }
      });
      return result;
    }
    else {
      return null;
    }
  }
  else {
    return new AsyncResult.Done<Disposable>(defaultValue);
  }
}
项目:intellij-ce-playground    文件:PopupPositionManager.java   
private static Component discoverPopup(final DataKey<JBPopup> datakey, Component focusOwner) {
  if (focusOwner == null) {
    focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
  }

  if (focusOwner == null) return null;

  final DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner);
  if (dataContext == null) return null;

  final JBPopup popup = datakey.getData(dataContext);
  if (popup != null && popup.isVisible()) {
    return popup.getContent();
  }

  return null;
}
项目:intellij-ce-playground    文件:EditorsPanel.java   
public void calcData(DataKey key, DataSink sink) {
  if (key.equals(CommonDataKeys.PROJECT)) {
    sink.put(CommonDataKeys.PROJECT, myProject);
  }
  else if (key.equals(CommonDataKeys.NAVIGATABLE)) {
    final EditorInfo editorInfo = myTable.getSelectedObject();
    if (editorInfo == null) {
      return;
    }
    String filePath = editorInfo.getFilePath();
    final int pos = filePath.lastIndexOf('/');
    if (pos >= 0) {
      filePath = filePath.substring(pos+1);
    }
    final File file = new File(editorInfo.getPath(), filePath);
    final VirtualFile vf = LocalFileSystem.getInstance().findFileByIoFile(file);
    if (vf != null) {
      sink.put(CommonDataKeys.NAVIGATABLE, new OpenFileDescriptor(myProject, vf));
    }
  }
}
项目:tools-idea    文件:LazyUiDisposable.java   
private static AsyncResult<Disposable> findDisposable(Disposable defaultValue, final DataKey<? extends Disposable> key) {
  if (defaultValue == null) {
    if (ApplicationManager.getApplication() != null) {
      final AsyncResult<Disposable> result = new AsyncResult<Disposable>();
      DataManager.getInstance().getDataContextFromFocus().doWhenDone(new AsyncResult.Handler<DataContext>() {
        public void run(DataContext context) {
          Disposable disposable = key.getData(context);
          if (disposable == null) {
            disposable = Disposer.get("ui");
          }
          result.setDone(disposable);
        }
      });
      return result;
    }
    else {
      return null;
    }
  }
  else {
    return new AsyncResult.Done<Disposable>(defaultValue);
  }
}
项目:tools-idea    文件:PopupPositionManager.java   
private static Component discoverPopup(final DataKey<JBPopup> datakey, Component focusOwner) {
  if (focusOwner == null) {
    focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
  }

  if (focusOwner == null) return null;

  final DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner);
  if (dataContext == null) return null;

  final JBPopup popup = datakey.getData(dataContext);
  if (popup != null && popup.isVisible()) {
    return popup.getContent();
  }

  return null;
}
项目:tools-idea    文件:EditorsPanel.java   
public void calcData(DataKey key, DataSink sink) {
  if (key.equals(PlatformDataKeys.PROJECT)) {
    sink.put(PlatformDataKeys.PROJECT, myProject);
  }
  else if (key.equals(PlatformDataKeys.NAVIGATABLE)) {
    final EditorInfo editorInfo = myTable.getSelectedObject();
    if (editorInfo == null) {
      return;
    }
    String filePath = editorInfo.getFilePath();
    final int pos = filePath.lastIndexOf('/');
    if (pos >= 0) {
      filePath = filePath.substring(pos+1);
    }
    final File file = new File(editorInfo.getPath(), filePath);
    final VirtualFile vf = LocalFileSystem.getInstance().findFileByIoFile(file);
    if (vf != null) {
      sink.put(PlatformDataKeys.NAVIGATABLE, new OpenFileDescriptor(myProject, vf));
    }
  }
}
项目:intellij-ce-playground    文件:PackageGroupingRule.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (!isValid()) return;
  if (CommonDataKeys.PSI_ELEMENT == key) {
    sink.put(CommonDataKeys.PSI_ELEMENT, myPackage);
  }
}
项目:intellij-ce-playground    文件:ClassGroupingRule.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (!isValid()) return;
  if (CommonDataKeys.PSI_ELEMENT == key) {
    sink.put(CommonDataKeys.PSI_ELEMENT, getPsiClass());
  }
  if (UsageView.USAGE_INFO_KEY == key) {
    PsiClass psiClass = getPsiClass();
    if (psiClass != null) {
      sink.put(UsageView.USAGE_INFO_KEY, new UsageInfo(psiClass));
    }
  }
}
项目:intellij-ce-playground    文件:MethodGroupingRule.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (!isValid()) return;
  if (CommonDataKeys.PSI_ELEMENT == key) {
    sink.put(CommonDataKeys.PSI_ELEMENT, getMethod());
  }
  if (UsageView.USAGE_INFO_KEY == key) {
    PsiMethod method = getMethod();
    if (method != null) {
      sink.put(UsageView.USAGE_INFO_KEY, new UsageInfo(method));
    }
  }
}
项目:intellij-ce-playground    文件:PsiElementUsageGroupBase.java   
public void calcData(final DataKey key, final DataSink sink) {
  if (!isValid()) return;
  if (CommonDataKeys.PSI_ELEMENT == key) {
    sink.put(CommonDataKeys.PSI_ELEMENT, getElement());
  }
  if (UsageView.USAGE_INFO_KEY == key) {
    T element = getElement();
    if (element != null) {
      sink.put(UsageView.USAGE_INFO_KEY, new UsageInfo(element));
    }
  }
}
项目:intellij-ce-playground    文件:ModuleGroupingRule.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (!isValid()) return;
  if (LangDataKeys.MODULE_CONTEXT == key) {
    sink.put(LangDataKeys.MODULE_CONTEXT, myModule);
  }
}
项目:intellij-ce-playground    文件:DirectoryGroupingRule.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (!isValid()) return;
  if (CommonDataKeys.VIRTUAL_FILE == key) {
    sink.put(CommonDataKeys.VIRTUAL_FILE, myDir);
  }
  if (CommonDataKeys.PSI_ELEMENT == key) {
    sink.put(CommonDataKeys.PSI_ELEMENT, getDirectory());
  }
}
项目:intellij-ce-playground    文件:UsageViewManagerImpl.java   
@NotNull
SearchScope getMaxSearchScopeToWarnOfFallingOutOf(@NotNull UsageTarget[] searchFor) {
  UsageTarget target = searchFor[0];
  if (target instanceof TypeSafeDataProvider) {
    final SearchScope[] scope = new SearchScope[1];
    ((TypeSafeDataProvider)target).calcData(UsageView.USAGE_SCOPE, new DataSink() {
      @Override
      public <T> void put(DataKey<T> key, T data) {
        scope[0] = (SearchScope)data;
      }
    });
    return scope[0];
  }
  return GlobalSearchScope.allScope(myProject); // by default do not warn of falling out of scope
}
项目:intellij-ce-playground    文件:UsageInfo2UsageAdapter.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (key == UsageView.USAGE_INFO_KEY) {
    sink.put(UsageView.USAGE_INFO_KEY, getUsageInfo());
  }
  if (key == UsageView.USAGE_INFO_LIST_KEY) {
    List<UsageInfo> list = Arrays.asList(getMergedInfos());
    sink.put(UsageView.USAGE_INFO_LIST_KEY, list);
  }
}
项目:intellij-ce-playground    文件:DiffRequest.java   
public void passForDataContext(final DataKey key, final Object value) {
  myGenericData.put(key.getName(), value);
  if (haveMultipleLayers()) {
    for (Pair<String, DiffRequest> pair : myAdditional) {
      pair.getSecond().passForDataContext(key, value);
    }
  }
}
项目:intellij-ce-playground    文件:TypeSafeDataProviderAdapter.java   
@Override
@Nullable
public synchronized Object getData(@NonNls String dataId) {
  myValue = null;
  myLastKey = DataKey.create(dataId);
  myProvider.calcData(myLastKey, this);
  return myValue;
}
项目:intellij-ce-playground    文件:XDebugView.java   
@Nullable
public static <T> T getData(DataKey<T> key, @NotNull Component component) {
  DataContext dataContext = DataManager.getInstance().getDataContext(component);
  ViewContext viewContext = ViewContext.CONTEXT_KEY.getData(dataContext);
  ContentManager contentManager = viewContext == null ? null : viewContext.getContentManager();
  if (contentManager != null) {
    T data = key.getData(DataManager.getInstance().getDataContext(contentManager.getComponent()));
    if (data != null) {
      return data;
    }
  }
  return key.getData(dataContext);
}
项目:intellij-ce-playground    文件:CommitChangeListDialog.java   
@Override
public void calcData(DataKey key, DataSink sink) {
  if (key == Refreshable.PANEL_KEY) {
    sink.put(Refreshable.PANEL_KEY, this);
  }
  else {
    myBrowser.calcData(key, sink);
  }
}
项目:intellij-ce-playground    文件:PsiElement2UsageTargetAdapter.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (key == UsageView.USAGE_INFO_KEY) {
    PsiElement element = getElement();
    if (element != null && element.getTextRange() != null) {
      sink.put(UsageView.USAGE_INFO_KEY, new UsageInfo(element));
    }
  }
  else if (key == UsageView.USAGE_SCOPE) {
    sink.put(UsageView.USAGE_SCOPE, myOptions.searchScope);
  }
}
项目:intellij-ce-playground    文件:AbstractMemberSelectionTable.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (key == CommonDataKeys.PSI_ELEMENT) {
    final Collection<M> memberInfos = getSelectedMemberInfos();
    if (memberInfos.size() > 0) {
      sink.put(CommonDataKeys.PSI_ELEMENT, memberInfos.iterator().next().getMember());
    }
  }
}
项目:tools-idea    文件:ClassGroupingRule.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (!isValid()) return;
  if (LangDataKeys.PSI_ELEMENT == key) {
    sink.put(LangDataKeys.PSI_ELEMENT, getPsiClass());
  }
  if (UsageView.USAGE_INFO_KEY == key) {
    PsiClass psiClass = getPsiClass();
    if (psiClass != null) {
      sink.put(UsageView.USAGE_INFO_KEY, new UsageInfo(psiClass));
    }
  }
}
项目:tools-idea    文件:MethodGroupingRule.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (!isValid()) return;
  if (LangDataKeys.PSI_ELEMENT == key) {
    sink.put(LangDataKeys.PSI_ELEMENT, getMethod());
  }
  if (UsageView.USAGE_INFO_KEY == key) {
    PsiMethod method = getMethod();
    if (method != null) {
      sink.put(UsageView.USAGE_INFO_KEY, new UsageInfo(method));
    }
  }
}
项目:tools-idea    文件:ModuleGroupingRule.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (!isValid()) return;
  if (LangDataKeys.MODULE_CONTEXT == key) {
    sink.put(LangDataKeys.MODULE_CONTEXT, myModule);
  }
}
项目:tools-idea    文件:UsageInfo2UsageAdapter.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (key == UsageView.USAGE_INFO_KEY) {
    sink.put(UsageView.USAGE_INFO_KEY, getUsageInfo());
  }
  if (key == UsageView.USAGE_INFO_LIST_KEY) {
    List<UsageInfo> list = Arrays.asList(getMergedInfos());
    sink.put(UsageView.USAGE_INFO_LIST_KEY, list);
  }
}
项目:tools-idea    文件:PsiNamedElementUsageGroupBase.java   
public void calcData(final DataKey key, final DataSink sink) {
  if (!isValid()) return;
  if (LangDataKeys.PSI_ELEMENT == key) {
    sink.put(LangDataKeys.PSI_ELEMENT, getElement());
  }
  if (UsageView.USAGE_INFO_KEY == key) {
    T element = getElement();
    if (element != null) {
      sink.put(UsageView.USAGE_INFO_KEY, new UsageInfo(element));
    }
  }
}
项目:tools-idea    文件:DiffRequest.java   
public void passForDataContext(final DataKey key, final Object value) {
  myGenericData.put(key.getName(), value);
  if (haveMultipleLayers()) {
    for (Pair<String, DiffRequest> pair : myAdditional) {
      pair.getSecond().passForDataContext(key, value);
    }
  }
}
项目:tools-idea    文件:ExternalSystemUtil.java   
@SuppressWarnings("unchecked")
@Nullable
public static <T> T getToolWindowElement(@NotNull Class<T> clazz,
                                         @NotNull Project project,
                                         @NotNull DataKey<T> key,
                                         @NotNull ProjectSystemId externalSystemId)
{
  if (project.isDisposed() || !project.isOpen()) {
    return null;
  }
  final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
  if (toolWindowManager == null) {
    return null;
  }
  final ToolWindow toolWindow = toolWindowManager.getToolWindow(externalSystemId.getReadableName());
  if (toolWindow == null) {
    return null;
  }
  if (toolWindow instanceof ToolWindowImpl) {
    ((ToolWindowImpl)toolWindow).ensureContentInitialized();
  }

  final ContentManager contentManager = toolWindow.getContentManager();
  if (contentManager == null) {
    return null;
  }

  for (Content content : contentManager.getContents()) {
    final JComponent component = content.getComponent();
    if (component instanceof DataProvider) {
      final Object data = ((DataProvider)component).getData(key.getName());
      if (data != null && clazz.isInstance(data)) {
        return (T)data;
      }
    }
  }
  return null;
}
项目:tools-idea    文件:TypeSafeDataProviderAdapter.java   
@Nullable
public synchronized Object getData(@NonNls String dataId) {
  myValue = null;
  myLastKey = DataKey.create(dataId);
  myProvider.calcData(myLastKey, this);
  return myValue;
}
项目:tools-idea    文件:CommitChangeListDialog.java   
public void calcData(DataKey key, DataSink sink) {
  if (key == CheckinProjectPanel.PANEL_KEY) {
    sink.put(CheckinProjectPanel.PANEL_KEY, this);
  }
  else {
    myBrowser.calcData(key, sink);
  }
}
项目:tools-idea    文件:PsiElement2UsageTargetAdapter.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (key == UsageView.USAGE_INFO_KEY) {
    PsiElement element = getElement();
    if (element != null && element.getTextRange() != null) {
      sink.put(UsageView.USAGE_INFO_KEY, new UsageInfo(element));
    }
  }
}
项目:tools-idea    文件:AbstractMemberSelectionTable.java   
@Override
public void calcData(final DataKey key, final DataSink sink) {
  if (key == LangDataKeys.PSI_ELEMENT) {
    final Collection<M> memberInfos = getSelectedMemberInfos();
    if (memberInfos.size() > 0) {
      sink.put(LangDataKeys.PSI_ELEMENT, memberInfos.iterator().next().getMember());
    }
  }
}
项目:tools-idea    文件:GitPushLog.java   
@Override
public void calcData(DataKey key, DataSink sink) {
  if (VcsDataKeys.CHANGES.equals(key)) {
    DefaultMutableTreeNode[] selectedNodes = myTree.getSelectedNodes(DefaultMutableTreeNode.class, null);
    if (selectedNodes.length == 0) {
      return;
    }
    Object object = selectedNodes[0].getUserObject();
    if (object instanceof GitCommit) {
      sink.put(key, ArrayUtil.toObjectArray(((GitCommit)object).getChanges(), Change.class));
    }
  }
}
项目:intellij-ce-playground    文件:FileChooserDescriptor.java   
@Nullable
public <T> T getUserData(@NotNull DataKey<T> key) {
  @SuppressWarnings({"unchecked"}) final T t = (T)myUserData.get(key.getName());
  return t;
}
项目:intellij-ce-playground    文件:FileChooserDescriptor.java   
public <T> void putUserData(@NotNull DataKey<T> key, @Nullable T data) {
  myUserData.put(key.getName(), data);
}
项目:intellij-ce-playground    文件:FileSystemTree.java   
@Nullable
<T> T getData(DataKey<T> key);
项目:intellij-ce-playground    文件:DialogAwareDataContext.java   
DialogAwareDataContext(DataContext context) {
  for (DataKey key : keys) {
    values.put(key.getName(), key.getData(context));
  }
}
项目:intellij-ce-playground    文件:MapDataContext.java   
public <T> void put(DataKey<T> dataKey, T data) {
  put(dataKey.getName(), data);
}
项目:intellij-ce-playground    文件:GenericDataProvider.java   
public void putData(DataKey key, Object value) {
  myGenericData.put(key.getName(), value);
}
项目:intellij-ce-playground    文件:FileSystemTreeImpl.java   
public <T> T getData(DataKey<T> key) {
  return myDescriptor.getUserData(key);
}
项目:intellij-ce-playground    文件:TypeSafeDataProviderAdapter.java   
@Override
public synchronized <T> void put(DataKey<T> key, T data) {
  if (key == myLastKey) {
    myValue = data;
  }
}