private void moveClass(Project project, Editor editor, PsiFile file, PsiClass aClass) { RefactoringActionHandler moveHandler = RefactoringActionHandlerFactory.getInstance().createMoveHandler(); DataManager dataManager = DataManager.getInstance(); DataContext dataContext = dataManager.getDataContext(); final String fqName = aClass.getQualifiedName(); LOG.assertTrue(fqName != null); PsiDirectory directory = PackageUtil .findOrCreateDirectoryForPackage(myCurrentModule, StringUtil.getPackageName(fqName), mySourceRoot, true); DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT.getName(), directory, dataContext); moveHandler.invoke(project, new PsiElement[]{aClass}, context); PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset()); PsiClass newClass = JavaPsiFacade.getInstance(project).findClass(fqName, GlobalSearchScope.moduleScope(myCurrentModule)); if (reference != null && newClass != null) { final QuestionAction action = new AddImportAction(project, reference, editor, newClass); action.execute(); } }
@Nullable protected JBPopup createActionGroupPopup(PsiFile file, Project project, Editor editor) { final DefaultActionGroup group = new DefaultActionGroup(); for (final IntentionAction action : IntentionManager.getInstance().getAvailableIntentionActions()) { if (shouldShowInGutterPopup(action) && action.isAvailable(project, editor, file)) { group.add(new ApplyIntentionAction(action, action.getText(), editor, file)); } } if (group.getChildrenCount() > 0) { final DataContext context = SimpleDataContext.getProjectContext(null); return JBPopupFactory.getInstance() .createActionGroupPopup(null, group, context, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true); } return null; }
private void checkMove(File jar, VirtualFile vFile, final PsiFile file) { VirtualFile jarRoot; File libDir = new File(jar.getParent(), "lib"); assertTrue(libDir.mkdir()); final VirtualFile vLibDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libDir); assertNotNull(vLibDir); jarRoot = findByPath(vFile.getPath() + JarFileSystem.JAR_SEPARATOR); assertTrue(jarRoot.isValid()); PsiDirectory directory = getPsiManager().findDirectory(vLibDir); final DataContext psiDataContext = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT.getName(), directory); new WriteCommandAction.Simple(myProject) { @Override protected void run() throws Throwable { new MoveHandler().invoke(myProject, new PsiElement[] {file}, psiDataContext); } }.execute(); assertFalse(jarRoot.isValid()); jarRoot = findByPath(vFile.getPath() + JarFileSystem.JAR_SEPARATOR); assertTrue(jarRoot.isValid()); rename(directory, "lib2"); assertFalse(jarRoot.isValid()); }
@Override public boolean isAvailableFor(@NotNull UsageView usageView) { UsageTarget[] targets = ((UsageViewImpl)usageView).getTargets(); if (targets.length == 0) return false; UsageTarget target = targets[0]; if (!(target instanceof PsiElementUsageTarget)) return false; PsiElement element = ((PsiElementUsageTarget)target).getElement(); if (element == null || !element.isValid()) return false; Project project = element.getProject(); DataContext context = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.getName(), element, SimpleDataContext.getProjectContext(project)); HierarchyProvider provider = BrowseHierarchyActionBase.findBestHierarchyProvider(LanguageCallHierarchy.INSTANCE, element, context); if (provider == null) return false; PsiElement providerTarget = provider.getTarget(context); return providerTarget != null; }
@Override protected void execute(@NotNull Project project, @NotNull DataContext dataContext, final ProgressHandler progressHandler) { DataContext wrappedDataContext = SimpleDataContext.getSimpleContext(VERIFY_CONTENT_WITH_WARNINGS, true, dataContext); boolean verificationSuccessful = doVerify(project, wrappedDataContext, progressHandler); // Notification are added if(ApplicationManager.getApplication().isDispatchThread()) { getMessageManager(project).showAlertWithArguments( NotificationType.INFORMATION, verificationSuccessful ? "server.configuration.verification.successful" : "server.configuration.verification.failed" ); } else { getMessageManager(project).sendNotification( verificationSuccessful ? "server.configuration.verification.successful" : "server.configuration.verification.failed" , NotificationType.INFORMATION ); } }
@Override public boolean isAvailableFor(@NotNull UsageView usageView) { UsageTarget[] targets = ((UsageViewImpl)usageView).getTargets(); if (targets.length == 0) return false; UsageTarget target = targets[0]; if (!(target instanceof PsiElementUsageTarget)) return false; PsiElement element = ((PsiElementUsageTarget)target).getElement(); if (element == null || !element.isValid()) return false; Project project = element.getProject(); DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.PSI_ELEMENT.getName(), element, SimpleDataContext.getProjectContext(project)); HierarchyProvider provider = BrowseHierarchyActionBase.findBestHierarchyProvider(LanguageCallHierarchy.INSTANCE, element, context); if (provider == null) return false; PsiElement providerTarget = provider.getTarget(context); return providerTarget != null; }
@Nullable private static HierarchyBrowser createCallHierarchyPanel(@NotNull PsiElement element) { DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.PSI_ELEMENT.getName(), element, SimpleDataContext.getProjectContext(element.getProject())); HierarchyProvider provider = BrowseHierarchyActionBase.findBestHierarchyProvider(LanguageCallHierarchy.INSTANCE, element, context); if (provider == null) return null; PsiElement providerTarget = provider.getTarget(context); if (providerTarget == null) return null; HierarchyBrowser browser = provider.createHierarchyBrowser(providerTarget); if (browser instanceof HierarchyBrowserBaseEx) { HierarchyBrowserBaseEx browserEx = (HierarchyBrowserBaseEx)browser; browserEx.changeView(CallHierarchyBrowserBase.CALLER_TYPE); final ProgressIndicatorBase indicator = new ProgressIndicatorBase(); Disposer.register(browserEx, new Disposable() { @Override public void dispose() { indicator.cancel(); } }); browserEx.setProgressIndicator(indicator); } return browser; }
protected void doAction(MouseEvent e) { final DefaultActionGroup group = createActionGroup(); final DataContext parent = DataManager.getInstance().getDataContext(myPanel.getParent()); final DataContext dataContext = SimpleDataContext.getSimpleContext(PlatformDataKeys.PROJECT.getName(), myProject, parent); final JBPopup popup = JBPopupFactory.getInstance() .createActionGroupPopup(null, group, dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true, new Runnable() { @Override public void run() { // todo ? } }, 20); if (e != null) { popup.show(new RelativePoint(e)); } else { final Dimension dimension = popup.getContent().getPreferredSize(); final Point at = new Point(-dimension.width / 2, -dimension.height); popup.show(new RelativePoint(myLabel, at)); } }
public BranchActionGroupPopup(@Nonnull String title, @Nonnull Project project, @Nonnull Condition<AnAction> preselectActionCondition, @Nonnull ActionGroup actions, @Nullable String dimensionKey) { super(title, new DefaultActionGroup(actions, createBranchSpeedSearchActionGroup(actions)), SimpleDataContext.getProjectContext(project), preselectActionCondition, true); myProject = project; DataManager.registerDataProvider(getList(), dataId -> POPUP_MODEL == dataId ? getListModel() : null); myKey = dimensionKey; if (myKey != null) { Dimension storedSize = WindowStateService.getInstance(myProject).getSizeFor(myProject, myKey); if (storedSize != null) { //set forced size before component is shown setSize(storedSize); myUserSizeChanged = true; } createTitlePanelToolbar(myKey); } myMeanRowHeight = getList().getCellBounds(0, 0).height + UIUtil.getListCellVPadding() * 2; }
@Override public boolean isAvailableFor(@Nonnull UsageView usageView) { UsageTarget[] targets = ((UsageViewImpl)usageView).getTargets(); if (targets.length == 0) return false; UsageTarget target = targets[0]; if (!(target instanceof PsiElementUsageTarget)) return false; PsiElement element = ((PsiElementUsageTarget)target).getElement(); if (element == null || !element.isValid()) return false; Project project = element.getProject(); DataContext context = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT, element, SimpleDataContext.getProjectContext(project)); HierarchyProvider provider = BrowseHierarchyActionBase.findBestHierarchyProvider(LanguageCallHierarchy.INSTANCE, element, context); if (provider == null) return false; PsiElement providerTarget = provider.getTarget(context); return providerTarget != null; }
private void moveClass(Project project, Editor editor, PsiFile file, PsiClass aClass) { RefactoringActionHandler moveHandler = RefactoringActionHandlerFactory.getInstance().createMoveHandler(); DataManager dataManager = DataManager.getInstance(); DataContext dataContext = dataManager.getDataContext(); final String fqName = aClass.getQualifiedName(); LOG.assertTrue(fqName != null); PsiDirectory directory = PackageUtil .findOrCreateDirectoryForPackage(myCurrentModule, StringUtil.getPackageName(fqName), mySourceRoot, true); DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT, directory, dataContext); moveHandler.invoke(project, new PsiElement[]{aClass}, context); PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset()); PsiClass newClass = JavaPsiFacade.getInstance(project).findClass(fqName, GlobalSearchScope.moduleScope(myCurrentModule)); if (reference != null && newClass != null) { final QuestionAction action = new AddImportAction(project, reference, editor, newClass); action.execute(); } }
@Nullable protected JBPopup createActionGroupPopup(PsiFile file, Project project, Editor editor) { final DefaultActionGroup group = new DefaultActionGroup(); for(final IntentionAction action : IntentionManager.getInstance().getAvailableIntentionActions()) { if(shouldShowInGutterPopup(action) && action.isAvailable(project, editor, file)) { group.add(new ApplyIntentionAction(action, action.getText(), editor, file)); } } if(group.getChildrenCount() > 0) { final DataContext context = SimpleDataContext.getProjectContext(null); return JBPopupFactory.getInstance().createActionGroupPopup(null, group, context, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true); } return null; }
@SuppressWarnings("SameParameterValue") private static DataContext dataContext(@Nullable DataContext parent, boolean autoTriggered) { HashMap<String, Object> dataMap = new HashMap<>(); //dataMap.put(CommonDataKeys.PROJECT.getName(), project); //if (editor != null) dataMap.put(CommonDataKeys.EDITOR.getName(), editor); dataMap.put(AUTO_TRIGGERED_ACTION.getName(), autoTriggered); return SimpleDataContext.getSimpleContext(dataMap, parent); }
@NotNull private static DataContext createEditorContext(@NotNull Editor editor) { Object e = editor; Object hostEditor = editor instanceof EditorWindow ? ((EditorWindow)editor).getDelegate() : editor; Map<String, Object> map = ContainerUtil.newHashMap(Pair.create(CommonDataKeys.HOST_EDITOR.getName(), hostEditor), Pair.createNonNull(CommonDataKeys.EDITOR.getName(), e)); DataContext parent = DataManager.getInstance().getDataContext(editor.getContentComponent()); return SimpleDataContext.getSimpleContext(map, parent); }
@NotNull private DataContext getContext() { Editor editor = getEditor(); DataContext parent = DataManager.getInstance().getDataContext((Component)myStatusBar); return SimpleDataContext.getSimpleContext( CommonDataKeys.VIRTUAL_FILE_ARRAY.getName(), new VirtualFile[] {getSelectedFile()}, SimpleDataContext.getSimpleContext(CommonDataKeys.PROJECT.getName(), getProject(), SimpleDataContext.getSimpleContext(PlatformDataKeys.CONTEXT_COMPONENT.getName(), editor == null ? null : editor.getComponent(), parent) )); }
@NotNull private DataContext getContext() { Editor editor = getEditor(); DataContext parent = DataManager.getInstance().getDataContext((Component)myStatusBar); return SimpleDataContext.getSimpleContext(CommonDataKeys.VIRTUAL_FILE.getName(), getSelectedFile(), SimpleDataContext.getSimpleContext(CommonDataKeys.PROJECT.getName(), getProject(), SimpleDataContext.getSimpleContext(PlatformDataKeys.CONTEXT_COMPONENT.getName(), editor == null ? null : editor.getComponent(), parent) )); }
private static void rename(final PsiNamedElement file, final String newName) { final DataContext psiDataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.getName(), file); final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(psiDataContext); assertNotNull(renameHandler); new WriteCommandAction.Simple(file.getProject()) { @Override public void run() { PsiElementRenameHandler.rename(file, file.getProject(), file, null, newName); } }.execute(); }
public DataContext getContext(VirtualFile file) { Project project = myFixture.getProject(); Map<String, Object> dataId2data = new THashMap<String, Object>(); dataId2data.put(CommonDataKeys.PROJECT.getName(), project); dataId2data.put(CommonDataKeys.VIRTUAL_FILE.getName(), file); dataId2data.put(PlatformDataKeys.PROJECT_FILE_DIRECTORY.getName(), project.getBaseDir()); return SimpleDataContext.getSimpleContext(dataId2data, null); }
@NotNull public static DataContext createDataContext(Editor editor, Component component, VirtualFile selectedFile, Project project) { DataContext parent = DataManager.getInstance().getDataContext(component); DataContext context = SimpleDataContext.getSimpleContext(PlatformDataKeys.CONTEXT_COMPONENT.getName(), editor == null ? null : editor.getComponent(), parent); DataContext projectContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PROJECT.getName(), project, context); return SimpleDataContext.getSimpleContext(CommonDataKeys.VIRTUAL_FILE.getName(), selectedFile, projectContext); }
@Nullable private static HierarchyBrowser createCallHierarchyPanel(@NotNull PsiElement element) { DataContext context = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.getName(), element, SimpleDataContext.getProjectContext(element.getProject())); HierarchyProvider provider = BrowseHierarchyActionBase.findBestHierarchyProvider(LanguageCallHierarchy.INSTANCE, element, context); if (provider == null) return null; PsiElement providerTarget = provider.getTarget(context); if (providerTarget == null) return null; HierarchyBrowser browser = provider.createHierarchyBrowser(providerTarget); if (browser instanceof HierarchyBrowserBaseEx) { HierarchyBrowserBaseEx browserEx = (HierarchyBrowserBaseEx)browser; browserEx.changeView(CallHierarchyBrowserBase.CALLER_TYPE); } return browser; }
public MacrosDialog(Project project) { super(project, true); MacroManager.getInstance().cacheMacrosPreview(SimpleDataContext.getProjectContext(project)); setTitle(IdeBundle.message("title.macros")); setOKButtonText(IdeBundle.message("button.insert")); myMacrosModel = new DefaultListModel(); myMacrosList = new JBList(myMacrosModel); myPreviewTextarea = new JTextArea(); init(); }
@NotNull public Map<String, String> getExternalProperties() { Map<String, String> result = myCachedExternalProperties; if (result == null) { synchronized (myOptionsLock) { result = myCachedExternalProperties; if (result == null) { result = new HashMap<String, String>(); final DataContext context = SimpleDataContext.getProjectContext(myProject); final MacroManager macroManager = MacroManager.getInstance(); Iterator<BuildFileProperty> properties = ANT_PROPERTIES.getIterator(myAllOptions); while (properties.hasNext()) { BuildFileProperty property = properties.next(); try { String value = property.getPropertyValue(); value = macroManager.expandSilentMarcos(value, true, context); value = macroManager.expandSilentMarcos(value, false, context); result.put(property.getPropertyName(), value); } catch (Macro.ExecutionCancelledException e) { LOG.debug(e); } } myCachedExternalProperties = result; } } } return result; }
private void runAntTarget(CompileContext compileContext, final Artifact artifact) { if (myExtensionProperties.myEnabled) { final Project project = compileContext.getProject(); final AntBuildTarget target = findTarget(AntConfiguration.getInstance(project)); if (target != null) { final DataContext dataContext = SimpleDataContext.getProjectContext(project); List<BuildFileProperty> properties = getAllProperties(artifact); final boolean success = AntConfigurationImpl.executeTargetSynchronously(dataContext, target, properties); if (!success) { compileContext.addMessage(CompilerMessageCategory.ERROR, "Cannot build artifact '" + artifact.getName() + "': ant target '" + target.getDisplayName() + "' failed with error", null, -1, -1); } } } }
private void showPopup(@NotNull AnActionEvent event, @NotNull GitFileRevision rev, @NotNull FilePath filePath, @NotNull Collection<GitFileRevision> parents) { ActionGroup parentActions = createActionGroup(rev, filePath, parents); DataContext dataContext = SimpleDataContext.getProjectContext(myProject); ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup("Choose parent to compare", parentActions, dataContext, JBPopupFactory.ActionSelectionAid.NUMBERING, true); showPopupInBestPosition(popup, event, dataContext); }
protected boolean doVerify(@NotNull final Project project, @Nullable final DataContext dataContext, @NotNull final ProgressHandler progressHandler) { // First Run the Verifier and if the Server Configuration has changed also the Purge Cache ActionManager actionManager = ActionManager.getInstance(); final VerifyConfigurationAction verifyConfigurationAction = (VerifyConfigurationAction) actionManager.getAction("AEM.Verify.Configuration.Action"); WaitableRunner<AtomicBoolean> runner = null; if(verifyConfigurationAction != null) { runner = new WaitableRunner<AtomicBoolean>(new AtomicBoolean(true)) { @Override public void run() { progressHandler.next("progress.start.verification"); getResponse().set( verifyConfigurationAction.doVerify(project, SimpleDataContext.getSimpleContext(VerifyConfigurationAction.VERIFY_CONTENT_WITH_WARNINGS, false, dataContext), progressHandler) ); } @Override public void handleException(Exception e) { // Catch and report unexpected exception as debug message to keep it going getMessageManager(project).sendErrorNotification("server.configuration.verification.failed.unexpected", e); } @Override public boolean isAsynchronous() { Boolean forced = progressHandler.forceAsynchronous(); if(forced != null) { return forced; } else { return AbstractProjectAction.this.isAsynchronous(); } } }; runAndWait(runner); } return runner == null || runner.getResponse().get(); }
private DataContext getFakeContext(VirtualFile file) { Map<String, Object> dataId2data = new THashMap<>(); dataId2data.put(CommonDataKeys.PROJECT.getName(), myProject); dataId2data.put(CommonDataKeys.VIRTUAL_FILE.getName(), file); dataId2data.put(PlatformDataKeys.PROJECT_FILE_DIRECTORY.getName(), myProject.getBaseDir()); return SimpleDataContext.getSimpleContext(dataId2data, null); }
@NotNull private DataContext getContext() { Editor editor = getEditor(); DataContext parent = DataManager.getInstance().getDataContext((Component)myStatusBar); return SimpleDataContext.getSimpleContext( PlatformDataKeys.VIRTUAL_FILE_ARRAY.getName(), new VirtualFile[] {getSelectedFile()}, SimpleDataContext.getSimpleContext(PlatformDataKeys.PROJECT.getName(), getProject(), SimpleDataContext.getSimpleContext(PlatformDataKeys.CONTEXT_COMPONENT.getName(), editor == null ? null : editor.getComponent(), parent) )); }
@NotNull private DataContext getContext() { Editor editor = getEditor(); DataContext parent = DataManager.getInstance().getDataContext((Component)myStatusBar); return SimpleDataContext.getSimpleContext(PlatformDataKeys.VIRTUAL_FILE.getName(), getSelectedFile(), SimpleDataContext.getSimpleContext(PlatformDataKeys.PROJECT.getName(), getProject(), SimpleDataContext.getSimpleContext(PlatformDataKeys.CONTEXT_COMPONENT.getName(), editor == null ? null : editor.getComponent(), parent) )); }
public DataContext getContext(VirtualFile file) { Project project = myFixture.getProject(); Map<String, Object> dataId2data = new THashMap<String, Object>(); dataId2data.put(PlatformDataKeys.PROJECT.getName(), project); dataId2data.put(PlatformDataKeys.VIRTUAL_FILE.getName(), file); dataId2data.put(PlatformDataKeys.PROJECT_FILE_DIRECTORY.getName(), project.getBaseDir()); return SimpleDataContext.getSimpleContext(dataId2data, null); }
@NotNull public static DataContext createDataContext(Editor editor, Component component, VirtualFile selectedFile, Project project) { DataContext parent = DataManager.getInstance().getDataContext(component); DataContext context = SimpleDataContext.getSimpleContext(PlatformDataKeys.CONTEXT_COMPONENT.getName(), editor == null ? null : editor.getComponent(), parent); DataContext projectContext = SimpleDataContext.getSimpleContext(PlatformDataKeys.PROJECT.getName(), project, context); return SimpleDataContext.getSimpleContext(PlatformDataKeys.VIRTUAL_FILE.getName(), selectedFile, projectContext); }
public void execute(final MouseEvent e) { final DefaultActionGroup group = createActionGroup(); final DataContext parent = DataManager.getInstance().getDataContext(myEqualToHeadr); final DataContext dataContext = SimpleDataContext.getSimpleContext(PlatformDataKeys.PROJECT.getName(), myProject, parent); final JBPopup popup = JBPopupFactory.getInstance() .createActionGroupPopup(null, group, dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true, new Runnable() { @Override public void run() { } }, 20); popup.show(new RelativePoint(e)); }
@NotNull private DataContext getContext() { Editor editor = getEditor(); DataContext parent = DataManager.getInstance().getDataContext((Component) myStatusBar); return SimpleDataContext.getSimpleContext( CommonDataKeys.VIRTUAL_FILE.getName(), new VirtualFile[] {getSelectedFile()}, SimpleDataContext.getSimpleContext(CommonDataKeys.PROJECT.getName(), getProject(), SimpleDataContext.getSimpleContext(PlatformDataKeys.CONTEXT_COMPONENT.getName(), editor == null ? null : editor.getComponent(), parent) )); }
@Override public boolean execute(CompileContext compileContext) { final DataContext dataContext = SimpleDataContext.getProjectContext(compileContext.getProject()); final AntConfiguration config = AntConfiguration.getInstance(compileContext.getProject()); ((AntConfigurationBase)config).ensureInitialized(); return config.executeTargetBeforeCompile(dataContext); }
@Override public boolean execute(CompileContext compileContext) { final DataContext dataContext = SimpleDataContext.getProjectContext(compileContext.getProject()); final AntConfiguration config = AntConfiguration.getInstance(compileContext.getProject()); ((AntConfigurationBase)config).ensureInitialized(); return config.executeTargetAfterCompile(dataContext); }
@Override @NotNull public Map<String, String> getExternalProperties() { Map<String, String> result = myCachedExternalProperties; if(result == null) { synchronized(myOptionsLock) { result = myCachedExternalProperties; if(result == null) { result = new HashMap<String, String>(); final DataContext context = SimpleDataContext.getProjectContext(myProject); final MacroManager macroManager = MacroManager.getInstance(); Iterator<BuildFileProperty> properties = ANT_PROPERTIES.getIterator(myAllOptions); while(properties.hasNext()) { BuildFileProperty property = properties.next(); try { String value = property.getPropertyValue(); value = macroManager.expandSilentMarcos(value, true, context); value = macroManager.expandSilentMarcos(value, false, context); result.put(property.getPropertyName(), value); } catch(Macro.ExecutionCancelledException e) { LOG.debug(e); } } myCachedExternalProperties = result; } } } return result; }