com.intellij.openapi.actionSystem.DataKeys Java Examples

The following examples show how to use com.intellij.openapi.actionSystem.DataKeys. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateAction.java    From haystack with MIT License 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent event) {
    DataContext dataContext = event.getDataContext();
    project = event.getProject();
    if (project == null) return;
    sourcePath = project.getBasePath() + "/lib";
    selectGroup = DataKeys.VIRTUAL_FILE.getData(dataContext);
    if (selectGroup == null || !selectGroup.getParent().getPath().endsWith("redux")) {
        Messages.showMessageDialog("You must select a subfolder of redux folder, the action " +
                "would be created in it.", "Error", Messages.getErrorIcon());
        return;
    }
    entry = selectGroup.getPath().substring(selectGroup.getPath().lastIndexOf("/") + 1);

    CreateActionDialog dialog = new CreateActionDialog(this);
    dialog.pack();
    dialog.setLocationRelativeTo(null);
    dialog.setVisible(true);
}
 
Example #2
Source File: NewClassAction.java    From json2java4idea with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent event) {
    if (!isAvailable(event)) {
        return;
    }

    project = event.getProject();
    ideView = event.getData(DataKeys.IDE_VIEW);

    final Injector injector = GuiceManager.getInstance(project).getInjector();
    injector.injectMembers(this);

    // 'selected' is null when directory selection is canceled although multiple directories are chosen.
    final PsiDirectory selected = ideView.getOrChooseDirectory();
    if (selected == null) {
        return;
    }

    final NewClassDialog dialog = NewClassDialog.builder(project, bundle)
            .nameValidator(nameValidatorProvider.get())
            .jsonValidator(jsonValidatorProvider.get())
            .actionListener(this)
            .build();
    dialog.show();
}
 
Example #3
Source File: AndroidMvpAction.java    From KotlinMvp with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    project = e.getProject();
    selectGroup = DataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    String className = Messages.showInputDialog(project, "请输入类名称", "NewMvpGroup", Messages.getQuestionIcon());
    if (className == null || className.equals("")) {
        System.out.print("没有输入类名");
        return;
    }
    if (className.equals("base") || className.equals("BASE") || className.equals("Base")) {
        createMvpBase();
    } else {
        createClassMvp(className);
    }
    project.getBaseDir().refresh(false, true);
}
 
Example #4
Source File: BuckTreeViewPanelImpl.java    From buck with Apache License 2.0 6 votes vote down vote up
private static void handleClickOnError(BuckErrorItemNode node) {
  TreeNode parentNode = node.getParent();
  if (parentNode instanceof BuckFileErrorNode) {
    BuckFileErrorNode buckParentNode = (BuckFileErrorNode) parentNode;
    DataContext dataContext = DataManager.getInstance().getDataContext();
    Project project = DataKeys.PROJECT.getData(dataContext);

    String relativePath = buckParentNode.getText().replace(project.getBasePath(), "");

    VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath);
    if (virtualFile != null) {
      OpenFileDescriptor openFileDescriptor =
          new OpenFileDescriptor(project, virtualFile, node.getLine() - 1, node.getColumn() - 1);
      openFileDescriptor.navigate(true);
    }
  }
}
 
Example #5
Source File: CreatePatcherAction.java    From patcher with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    VirtualFile[] data = e.getData(DataKeys.VIRTUAL_FILE_ARRAY);
    // TODO: insert action logic here
    PatcherDialog dialog = new PatcherDialog(e);
    dialog.setSize(600, 400);
    dialog.setLocationRelativeTo(null);
    dialog.setVisible(true);
    dialog.requestFocus();
}
 
Example #6
Source File: PatcherDialog.java    From patcher with Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
    VirtualFile[] data = event.getData(DataKeys.VIRTUAL_FILE_ARRAY);
    fieldList = new JBList(data);
    fieldList.setEmptyText("No File Selected!");
    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(fieldList);
    filePanel = decorator.createPanel();
}
 
Example #7
Source File: ClassesExportAction.java    From patcher with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    try {
        com.intellij.openapi.actionSystem.DataContext dataContext = e.getDataContext();
        PsiJavaFile javaFile = (PsiJavaFile) ((PsiFile) DataKeys.PSI_FILE.getData(dataContext)).getContainingFile();
        String sourceName = javaFile.getName();
        Module module = (Module) DataKeys.MODULE.getData(dataContext);
        String compileRoot = CompilerModuleExtension.getInstance(module).getCompilerOutputPath().getPath();
        getVirtualFile(sourceName, CompilerModuleExtension.getInstance(module).getCompilerOutputPath().getChildren(), compileRoot);
        VirtualFileManager.getInstance().syncRefresh();
    } catch (Exception ex) {
        ex.printStackTrace();
        Messages.showErrorDialog("Please build your module or project!!!", "error");
    }
}
 
Example #8
Source File: CreateFileAction.java    From CodeMaker with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        VirtualFileManager manager = VirtualFileManager.getInstance();
        VirtualFile virtualFile = manager
                .refreshAndFindFileByUrl(VfsUtil.pathToUrl(outputFile));

        if (virtualFile != null && virtualFile.exists()) {
            virtualFile.setBinaryContent(content.getBytes(fileEncoding));
        } else {
            File file = new File(outputFile);
            FileUtils.writeStringToFile(file, content, fileEncoding);
            virtualFile = manager.refreshAndFindFileByUrl(VfsUtil.pathToUrl(outputFile));
        }
        VirtualFile finalVirtualFile = virtualFile;
        Project project = DataKeys.PROJECT.getData(dataContext);
        if (finalVirtualFile == null || project == null) {
            LOGGER.error(this);
            return;
        }
        ApplicationManager.getApplication()
                .invokeLater(
                        () -> FileEditorManager.getInstance(project).openFile(finalVirtualFile, true,
                                true));

    } catch (UnsupportedCharsetException ex) {
        ApplicationManager.getApplication().invokeLater(() -> Messages.showMessageDialog("Unknown Charset: " + fileEncoding + ", please use the correct charset", "Generate Failed", null));
    } catch (Exception e) {
        LOGGER.error("Create file failed", e);
    }

}
 
Example #9
Source File: BaseAction.java    From freeline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public final void actionPerformed(AnActionEvent anActionEvent) {
    DocumentUtil.saveDocument();
    this.anActionEvent = anActionEvent;
    this.currentProject = DataKeys.PROJECT.getData(anActionEvent.getDataContext());
    this.projectDir = new File(currentProject.getBasePath());
    actionPerformed();
}
 
Example #10
Source File: ObjectFinder.java    From tmc-intellij with MIT License 5 votes vote down vote up
public Project findCurrentProject() {
    logger.info("Trying to findCurrentProject. @ObjectFinder");
    DataContext dataContext = DataManager.getInstance().getDataContextFromFocus().getResult();

    if (dataContext == null) {
        Project[] projects = ProjectManager.getInstance().getOpenProjects();

        if (projects.length > 0) {
            return projects[projects.length - 1];
        }
        return null;
    }
    return DataKeys.PROJECT.getData(dataContext);
}
 
Example #11
Source File: StylerUtils.java    From android-styler with Apache License 2.0 5 votes vote down vote up
public static void showBalloonPopup(DataContext dataContext, String htmlText, MessageType messageType) {
    StatusBar statusBar = WindowManager.getInstance().getStatusBar(DataKeys.PROJECT.getData(dataContext));

    JBPopupFactory.getInstance()
            .createHtmlTextBalloonBuilder(htmlText, messageType, null)
            .setFadeoutTime(7500)
            .createBalloon()
            .show(RelativePoint.getCenterOf(statusBar.getComponent()), Balloon.Position.atRight);
}
 
Example #12
Source File: LaunchArenaAction.java    From intellijcoder with MIT License 5 votes vote down vote up
public void actionPerformed(AnActionEvent event) {
    try {
        Project project = DataKeys.PROJECT.getData(event.getDataContext());
        IntelliJCoderApplication application = Injector.injectIntelliJCoderApplication(project);
        application.launch();
    } catch (IntelliJCoderException e) {
        IntelliJIDEA.showErrorMessage("Failed to start Competition Arena. " + e.getMessage());
    }
}
 
Example #13
Source File: IntelliJIDEA.java    From intellijcoder with MIT License 5 votes vote down vote up
private Project getCurrentProject() throws IntelliJCoderException {
    //if project was closed
    if(!project.isInitialized()) {
        // we try to locate project by currently focused component
        @SuppressWarnings({"deprecation"})
        DataContext dataContext = DataManager.getInstance().getDataContext();
        project = DataKeys.PROJECT.getData(dataContext);
    }
    if(project == null) {
        throw new IntelliJCoderException("There is no opened project.");
    }
    return project;
}
 
Example #14
Source File: NewFileAction.java    From crud-intellij-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
	Project project = e.getProject();
	VirtualFile virtualFile = e.getData(DataKeys.VIRTUAL_FILE);
	if (!virtualFile.isDirectory()) {
		virtualFile = virtualFile.getParent();
	}
	Module module = ModuleUtil.findModuleForFile(virtualFile, project);

	String moduleRootPath = ModuleRootManager.getInstance(module).getContentRoots()[0].getPath();
	String actionDir = virtualFile.getPath();

	String str = StringUtils.substringAfter(actionDir, moduleRootPath + "/src/main/java/");
	String basePackage = StringUtils.replace(str, "/", ".");
	SelectionContext.clearAllSet();

	SelectionContext.setPackage(basePackage);
	if (StringUtils.isNotBlank(basePackage)) {
		basePackage += ".";
	}
	SelectionContext.setControllerPackage(basePackage + "controller");
	SelectionContext.setServicePackage(basePackage + "service");
	SelectionContext.setDaoPackage(basePackage + "dao");
	SelectionContext.setModelPackage(basePackage + "model");
	SelectionContext.setMapperDir(moduleRootPath + "/src/main/resources/mapper");

	CrudActionDialog dialog = new CrudActionDialog(project, module);
	if (!dialog.showAndGet()) {
		return;
	}
	DumbService.getInstance(project).runWhenSmart((DumbAwareRunnable) () -> new WriteCommandAction(project) {
		@Override
		protected void run(@NotNull Result result) {
			Selection selection = SelectionContext.copyToSelection();
			SelectionContext.clearAllSet();
			try {
				PsiFileUtils.createCrud(project, selection, moduleRootPath);
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			//优化生成的所有Java类
			CrudUtils.doOptimize(project);
		}
	}.execute());
}