Search in sources :

Example 1 with DataBindingWizard

use of com.intellij.uiDesigner.wizard.DataBindingWizard in project intellij-community by JetBrains.

the class DataBindingWizardAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final Project project;
    final VirtualFile formFile;
    GuiEditor editor = FormEditingUtil.getActiveEditor(e.getDataContext());
    if (editor == null) {
        return;
    }
    project = editor.getProject();
    formFile = editor.getFile();
    try {
        final WizardData wizardData = new WizardData(project, formFile);
        final Module module = ModuleUtilCore.findModuleForFile(formFile, wizardData.myProject);
        LOG.assertTrue(module != null);
        final LwRootContainer[] rootContainer = new LwRootContainer[1];
        Generator.exposeForm(wizardData.myProject, formFile, rootContainer);
        final String classToBind = rootContainer[0].getClassToBind();
        if (classToBind == null) {
            Messages.showInfoMessage(project, UIDesignerBundle.message("info.form.not.bound"), UIDesignerBundle.message("title.data.binding.wizard"));
            return;
        }
        final PsiClass boundClass = FormEditingUtil.findClassToBind(module, classToBind);
        if (boundClass == null) {
            Messages.showErrorDialog(project, UIDesignerBundle.message("error.bound.to.not.found.class", classToBind), UIDesignerBundle.message("title.data.binding.wizard"));
            return;
        }
        Generator.prepareWizardData(wizardData, boundClass);
        if (!hasBinding(rootContainer[0])) {
            Messages.showInfoMessage(project, UIDesignerBundle.message("info.no.bound.components"), UIDesignerBundle.message("title.data.binding.wizard"));
            return;
        }
        if (!wizardData.myBindToNewBean) {
            final String[] variants = new String[] { UIDesignerBundle.message("action.alter.data.binding"), UIDesignerBundle.message("action.bind.to.another.bean"), CommonBundle.getCancelButtonText() };
            final int result = Messages.showYesNoCancelDialog(project, UIDesignerBundle.message("info.data.binding.regenerate", wizardData.myBeanClass.getQualifiedName()), UIDesignerBundle.message("title.data.binding"), variants[0], variants[1], variants[2], Messages.getQuestionIcon());
            if (result == Messages.YES) {
            // do nothing here
            } else if (result == Messages.NO) {
                wizardData.myBindToNewBean = true;
            } else {
                return;
            }
        }
        final DataBindingWizard wizard = new DataBindingWizard(project, wizardData);
        wizard.show();
    } catch (Generator.MyException exc) {
        Messages.showErrorDialog(project, exc.getMessage(), CommonBundle.getErrorTitle());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiClass(com.intellij.psi.PsiClass) WizardData(com.intellij.uiDesigner.wizard.WizardData) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) LwRootContainer(com.intellij.uiDesigner.lw.LwRootContainer) Project(com.intellij.openapi.project.Project) DataBindingWizard(com.intellij.uiDesigner.wizard.DataBindingWizard) Module(com.intellij.openapi.module.Module) Generator(com.intellij.uiDesigner.wizard.Generator)

Aggregations

Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiClass (com.intellij.psi.PsiClass)1 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)1 LwRootContainer (com.intellij.uiDesigner.lw.LwRootContainer)1 DataBindingWizard (com.intellij.uiDesigner.wizard.DataBindingWizard)1 Generator (com.intellij.uiDesigner.wizard.Generator)1 WizardData (com.intellij.uiDesigner.wizard.WizardData)1