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); } }
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; }
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)); } } }
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); } }
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)); } } }
@Override public void calcData(final DataKey key, final DataSink sink) { if (!isValid()) return; if (CommonDataKeys.PSI_ELEMENT == key) { sink.put(CommonDataKeys.PSI_ELEMENT, myPackage); } }
@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)); } } }
@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)); } } }
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)); } } }
@Override public void calcData(final DataKey key, final DataSink sink) { if (!isValid()) return; if (LangDataKeys.MODULE_CONTEXT == key) { sink.put(LangDataKeys.MODULE_CONTEXT, myModule); } }
@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()); } }
@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 }
@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); } }
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); } } }
@Override @Nullable public synchronized Object getData(@NonNls String dataId) { myValue = null; myLastKey = DataKey.create(dataId); myProvider.calcData(myLastKey, this); return myValue; }
@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); }
@Override public void calcData(DataKey key, DataSink sink) { if (key == Refreshable.PANEL_KEY) { sink.put(Refreshable.PANEL_KEY, this); } else { myBrowser.calcData(key, sink); } }
@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); } }
@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()); } } }
@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)); } } }
@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)); } } }
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)); } } }
@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; }
@Nullable public synchronized Object getData(@NonNls String dataId) { myValue = null; myLastKey = DataKey.create(dataId); myProvider.calcData(myLastKey, this); return myValue; }
public void calcData(DataKey key, DataSink sink) { if (key == CheckinProjectPanel.PANEL_KEY) { sink.put(CheckinProjectPanel.PANEL_KEY, this); } else { myBrowser.calcData(key, sink); } }
@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)); } } }
@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()); } } }
@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)); } } }
@Nullable public <T> T getUserData(@NotNull DataKey<T> key) { @SuppressWarnings({"unchecked"}) final T t = (T)myUserData.get(key.getName()); return t; }
public <T> void putUserData(@NotNull DataKey<T> key, @Nullable T data) { myUserData.put(key.getName(), data); }
@Nullable <T> T getData(DataKey<T> key);
DialogAwareDataContext(DataContext context) { for (DataKey key : keys) { values.put(key.getName(), key.getData(context)); } }
public <T> void put(DataKey<T> dataKey, T data) { put(dataKey.getName(), data); }
public void putData(DataKey key, Object value) { myGenericData.put(key.getName(), value); }
public <T> T getData(DataKey<T> key) { return myDescriptor.getUserData(key); }
@Override public synchronized <T> void put(DataKey<T> key, T data) { if (key == myLastKey) { myValue = data; } }