Java Code Examples for com.intellij.openapi.project.DumbService#showDumbModeNotification()

The following examples show how to use com.intellij.openapi.project.DumbService#showDumbModeNotification() . 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: SQLGeneratorAction.java    From CodeGen with MIT License 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent anActionEvent) {

    Project project = PsiUtil.getProject(anActionEvent);
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService.showDumbModeNotification(CodeGenBundle.message("codegen.plugin.is.not.available.during.indexing"));
        return;
    }

    JFrame frame = new JFrame();
    SqlEditorPanel sqlPane = new SqlEditorPanel(new IdeaContext(project));
    frame.setContentPane(sqlPane.getRootComponent());
    MyDialogWrapper frameWrapper = new MyDialogWrapper(project, frame.getRootPane());
    frameWrapper.setActionOperator(sqlPane);
    frameWrapper.setTitle("CodeGen-SQL");
    frameWrapper.setSize(600, 400);
    frameWrapper.setResizable(false);
    frameWrapper.show();
}
 
Example 2
Source File: FileGeneratorAction.java    From CodeGen with MIT License 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = PsiUtil.getProject(e);
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService.showDumbModeNotification(CodeGenBundle.message("codegen.plugin.is.not.available.during.indexing"));
        return;
    }
    IdeaContext ideaContext = new IdeaContext(project);
    // 获取所有模板, 渲染选择控件
    // TODO: 是否需要自定义参数的表格
    List<CodeRoot> codeRoots =  SettingManager.getInstance().getTemplates().getRoots();
    SelectGroupPanel selectGroupPanel = new SelectGroupPanel(codeRoots, project);
    MyDialogWrapper frameWrapper = new MyDialogWrapper(project, selectGroupPanel.getRootPanel());
    frameWrapper.setActionOperator(new FileGeneratorActionOperator(ideaContext, selectGroupPanel));
    frameWrapper.setTitle("CodeGen-Files");
    frameWrapper.setSize(600, 400);
    frameWrapper.setResizable(false);
    frameWrapper.show();
}
 
Example 3
Source File: DocGenerateAction.java    From CodeMaker with Apache License 2.0 6 votes vote down vote up
/**
 * @see com.intellij.openapi.actionSystem.AnAction#actionPerformed(com.intellij.openapi.actionSystem.AnActionEvent)
 */
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) {
        return;
    }
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService.showDumbModeNotification("CodeMaker plugin is not available during indexing");
        return;
    }
    PsiFile javaFile = e.getData(CommonDataKeys.PSI_FILE);
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (javaFile == null || editor == null) {
        return;
    }
    List<PsiClass> classes = CodeMakerUtil.getClasses(javaFile);
    PsiElementFactory psiElementFactory = PsiElementFactory.SERVICE.getInstance(project);
    for (PsiClass psiClass : classes) {
        for (PsiMethod psiMethod : PsiTreeUtil.getChildrenOfTypeAsList(psiClass, PsiMethod.class)) {
            createDocForMethod(psiMethod, psiElementFactory);
        }
    }

}
 
Example 4
Source File: CodeGeneratorAction.java    From code-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    Project project = anActionEvent.getProject();
    if (project == null) {
        return;
    }
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService.showDumbModeNotification("CodeGenerator plugin is not available during indexing");
        return;
    }

    SelectPathDialog dialog = new SelectPathDialog(project, templateSettings.getTemplateGroupMap());
    dialog.show();
    if (dialog.isOK()) {
        String basePackage = dialog.getBasePackage();
        String outputPath = dialog.getOutputPath();
        String templateGroup = dialog.getTemplateGroup();

        PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);
        if (Objects.isNull(psiFile) || !(psiFile instanceof PsiJavaFile)) {
            return;
        }

        PsiJavaFile psiJavaFile = (PsiJavaFile) psiFile;
        PsiClass[] psiClasses = psiJavaFile.getClasses();
        try {
            Map<String, Template> templateMap = templateSettings.getTemplateGroup(templateGroup).getTemplateMap();
            Entity entity = buildClassEntity(psiClasses[0]);
            TemplateUtils.generate(templateMap, entity, basePackage, outputPath);
        } catch (Exception e) {
            Messages.showMessageDialog(project, e.getMessage(), "Generate Failed", null);
            return;
        }
        Messages.showMessageDialog(project, "Code generation successful", "Success", null);
    }
}
 
Example 5
Source File: DBGeneratorAction.java    From CodeGen with MIT License 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = PsiUtil.getProject(e);
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService.showDumbModeNotification(CodeGenBundle.message("codegen.plugin.is.not.available.during.indexing"));
        return;
    }

    Iterator<DbElement> iterator = DatabaseView.getSelectedElements(e.getDataContext(), DbElement.class).iterator();

    List<DbTable> tables = new ArrayList<>();
    while (iterator.hasNext()) {
        DbElement table = iterator.next();
        if (table instanceof DbTable) {
            tables.add((DbTable) table);
        }
    }

    ColumnEditorFrame frame = new ColumnEditorFrame();
    frame.newColumnEditorByDb(new IdeaContext(project), tables);
    MyDialogWrapper frameWrapper = new MyDialogWrapper(project, frame.getRootPane());
    frameWrapper.setActionOperator(frame);
    frameWrapper.setTitle("CodeGen-DB");
    frameWrapper.setSize(800, 550);
    frameWrapper.setResizable(false);
    frameWrapper.show();
}
 
Example 6
Source File: GenerateApiTableHtmlAction.java    From CodeMaker with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) {
        return;
    }
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService
            .showDumbModeNotification("CodeMaker plugin is not available during indexing");
        return;
    }
    PsiFile javaFile = e.getData(CommonDataKeys.PSI_FILE);
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (javaFile == null || editor == null) {
        return;
    }
    List<PsiClass> classes = CodeMakerUtil.getClasses(javaFile);
    StringBuilder table = new StringBuilder(128);
    table.append("<table border=\"1\">");
    for (PsiClass psiClass : classes) {
        for (ClassEntry.Field field : CodeMakerUtil.getAllFields(psiClass)) {
            if (field.getModifier().contains("static")) {
                continue;
            }
            table.append("<tr>");
            table.append("<th>").append(field.getName()).append("</th>");
            table.append("<th>").append(StringEscapeUtils.escapeHtml(field.getType()))
                .append("</th>");
            table.append("<th>").append(StringEscapeUtils.escapeHtml(field.getComment()))
                .append("</th>");
            table.append("</tr>");
        }
    }
    table.append("</table>");
    CopyPasteManager.getInstance()
        .setContents(new SimpleTransferable(table.toString(), DataFlavor.allHtmlFlavor));
}
 
Example 7
Source File: GenerateApiTableMarkdownAction.java    From CodeMaker with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) {
        return;
    }
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService
            .showDumbModeNotification("CodeMaker plugin is not available during indexing");
        return;
    }
    PsiFile javaFile = e.getData(CommonDataKeys.PSI_FILE);
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (javaFile == null || editor == null) {
        return;
    }
    List<PsiClass> classes = CodeMakerUtil.getClasses(javaFile);
    StringBuilder table = new StringBuilder(128);
    table.append("|     |     |     |\n");
    table.append("| --- | --- | --- |\n");
    for (PsiClass psiClass : classes) {
        for (ClassEntry.Field field : CodeMakerUtil.getAllFields(psiClass)) {
            if (field.getModifier().contains("static")) {
                continue;
            }
            table.append("|").append(field.getName());
            table.append("|").append(CodeMakerUtil.escapeMarkdown(field.getType()));
            table.append("|").append(CodeMakerUtil.escapeMarkdown(field.getComment()))
                .append("|\n");
        }
    }
    CopyPasteManager.getInstance()
        .setContents(new SimpleTransferable(table.toString(), DataFlavor.stringFlavor));
}
 
Example 8
Source File: GenerateCodeFromApiTableAction.java    From CodeMaker with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) {
        return;
    }
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService
            .showDumbModeNotification("CodeMaker plugin is not available during indexing");
        return;
    }
    PsiFile javaFile = e.getData(CommonDataKeys.PSI_FILE);
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (javaFile == null || editor == null) {
        return;
    }
    Transferable transferable = CopyPasteManager.getInstance().getContents();
    if (transferable == null) {
        return;
    }
    try {
        String table = (String) transferable.getTransferData(DataFlavor.stringFlavor);
        List<String> tableList = Splitter.onPattern("\n|\t|\r\n").splitToList(table);
        PsiElementFactory psiElementFactory = PsiElementFactory.SERVICE.getInstance(project);
        int mod = tableList.size() % 3;
        int end = tableList.size() - mod;

        for (int i = 0; i < end; i++) {
            String fieldName = tableList.get(i);
            String fieldType = tableList.get(++i);
            String fieldComment = tableList.get(++i);
            PsiField psiField = psiElementFactory.createField(fieldName,
                PsiType.getTypeByName(fieldType, project, GlobalSearchScope.allScope(project)));
            Map<String, Object> map = Maps.newHashMap();
            map.put("comment", fieldComment);
            String vm = "/**\n" + " * ${comment}\n" + " */";
            if (settings.getCodeTemplate("FieldComment.vm") != null) {
                vm = settings.getCodeTemplate("FieldComment.vm").getCodeTemplate();
            }
            String fieldDocComment = VelocityUtil.evaluate(vm, map);
            PsiDocComment docComment = psiElementFactory
                .createDocCommentFromText(fieldDocComment);
            psiField.addBefore(docComment, psiField.getFirstChild());
            WriteCommandAction writeCommandAction = new FieldWriteAction(project,
                CodeMakerUtil.getClasses(javaFile).get(0), psiField, javaFile);
            RunResult result = writeCommandAction.execute();
            if (result.hasException()) {
                LOGGER.error(result.getThrowable());
                Messages.showErrorDialog("CodeMaker plugin is not available, cause: "
                                         + result.getThrowable().getMessage(),
                    "CodeMaker plugin");
            }
        }
    } catch (Exception ex) {
        LOGGER.error(ex);
    }
}
 
Example 9
Source File: CodeMakerAction.java    From CodeMaker with Apache License 2.0 4 votes vote down vote up
/**
 * @see com.intellij.openapi.actionSystem.AnAction#actionPerformed(com.intellij.openapi.actionSystem.AnActionEvent)
 */
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    Project project = anActionEvent.getProject();
    if (project == null) {
        return;
    }
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService.showDumbModeNotification("CodeMaker plugin is not available during indexing");
        return;
    }
    CodeTemplate codeTemplate = settings.getCodeTemplate(templateKey);

    PsiElement psiElement = anActionEvent.getData(LangDataKeys.PSI_ELEMENT);
    if (!(psiElement instanceof PsiClass)) {
        Messages.showMessageDialog(project, "Please focus on a class", "Generate Failed", null);
        return;
    }
    log.info("current pisElement: " + psiElement.getClass().getName() + "(" + psiElement + ")");

    PsiClass psiClass = (PsiClass) psiElement;
    String language = psiElement.getLanguage().getID().toLowerCase();
    List<ClassEntry> selectClasses = getClasses(project, codeTemplate.getClassNumber(), psiClass);

    if (selectClasses.size() < 1) {
        Messages.showMessageDialog(project, "No Classes found", "Generate Failed", null);
        return;
    }

    try {
        ClassEntry currentClass = selectClasses.get(0);
        GeneratedSource generated = generateSource(codeTemplate, selectClasses, currentClass);
        DestinationChooser.Destination destination = chooseDestination(currentClass, project, psiElement);
        if (destination instanceof DestinationChooser.FileDestination) {
            saveToFile(anActionEvent, language, generated.className, generated.content, currentClass, (DestinationChooser.FileDestination) destination, codeTemplate.getFileEncoding());
        }
        else if(destination == DestinationChooser.ShowSourceDestination) {
            showSource(project, codeTemplate.getTargetLanguage(), generated.className, generated.content);
        }

    } catch (Exception e) {
        Messages.showMessageDialog(project, e.getMessage(), "Generate Failed", null);
    }
}