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.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. Generator.generate(options);
  42. }
  43. }
  44. @Override
  45. public void update(AnActionEvent e) {
  46. if (e.getPlace().equals("MainMenu")) {
  47. super.update(e);
  48. }
  49. else {
  50. final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
  51. e.getPresentation().setVisible(file != null && file.getName().endsWith(".json"));
  52. }
  53. }
  54. }