You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GenerateAction.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.rthoni.intellij.codefromds.ui.actions;
  2. import com.intellij.openapi.actionSystem.AnAction;
  3. import com.intellij.openapi.actionSystem.AnActionEvent;
  4. import com.intellij.openapi.actionSystem.CommonDataKeys;
  5. import com.intellij.openapi.actionSystem.DataContext;
  6. import com.intellij.openapi.project.Project;
  7. import com.intellij.openapi.project.ProjectManager;
  8. import com.intellij.openapi.ui.DialogWrapper;
  9. import com.intellij.openapi.vfs.VirtualFile;
  10. import com.rthoni.intellij.codefromds.business.Generator;
  11. import com.rthoni.intellij.codefromds.dbo.GenerateOptions;
  12. import com.rthoni.intellij.codefromds.ui.dialogs.GenerateDialog;
  13. import javax.swing.*;
  14. /**
  15. * Created by robin on 11/14/16.
  16. */
  17. public class GenerateAction extends AnAction {
  18. @Override
  19. public void actionPerformed(AnActionEvent e) {
  20. GenerateDialog dlg = new GenerateDialog(null);
  21. if (!e.getPlace().equals("MainMenu")) {
  22. final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
  23. if (file != null) {
  24. try {
  25. GenerateOptions options = Generator.loadOptions(file.getPath());
  26. dlg.setOptions(options);
  27. } catch (Exception e1) {
  28. e1.printStackTrace();
  29. }
  30. }
  31. }
  32. dlg.show();
  33. int res = dlg.getExitCode();
  34. if (res == DialogWrapper.OK_EXIT_CODE) {
  35. GenerateOptions options = dlg.getOptions();
  36. try {
  37. Generator.saveOptions(options);
  38. } catch (Exception e1) {
  39. e1.printStackTrace();
  40. }
  41. try {
  42. Generator.generate(options);
  43. } catch (Exception e1) {
  44. e1.printStackTrace();
  45. }
  46. }
  47. }
  48. @Override
  49. public void update(AnActionEvent e) {
  50. if (e.getPlace().equals("MainMenu")) {
  51. super.update(e);
  52. }
  53. else {
  54. final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
  55. e.getPresentation().setVisible(file != null && file.getName().endsWith(".json"));
  56. }
  57. }
  58. }