update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / wizard / WizardData.java
blob0e6a05be54d6161e55ee719d096e589263ac60f2
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.uiDesigner.wizard;
18 import com.intellij.openapi.diagnostic.Logger;
19 import com.intellij.openapi.project.Project;
20 import com.intellij.openapi.vfs.VirtualFile;
21 import com.intellij.psi.*;
22 import com.intellij.uiDesigner.lw.LwRootContainer;
23 import org.jetbrains.annotations.NotNull;
25 /**
26 * @author Anton Katilin
27 * @author Vladimir Kondratyev
29 public final class WizardData {
30 private static final Logger LOG = Logger.getInstance("#com.intellij.uiDesigner.wizard.WizardData");
32 @NotNull public final Project myProject;
33 /**
34 * Form's file.
36 @NotNull public final VirtualFile myFormFile;
38 /**
39 * If <code>true</code> then {@link #myShortClassName} and {@link #myPackageName} should be
40 * used, otherwise {@link #myBeanClass} should be used.
42 public boolean myBindToNewBean;
43 /**
46 public String myShortClassName;
47 /**
50 public String myPackageName;
52 /**
53 * Bean's class. If <code>null</code> then bean's class is't defined yet.
55 public PsiClass myBeanClass;
56 @NotNull public final FormProperty2BeanProperty[] myBindings;
58 public boolean myGenerateIsModified;
60 public WizardData(@NotNull final Project project, @NotNull final VirtualFile formFile) throws Generator.MyException {
61 myProject = project;
62 myFormFile = formFile;
63 myBindToNewBean = true;
64 myGenerateIsModified = true;
66 final LwRootContainer[] rootContainer = new LwRootContainer[1];
68 // Create initial bingings between form fields and bean's properties.
69 // TODO[vova] ask Anton to not throw exception if form-field doesn't have corresponded field in the Java class
70 final FormProperty[] formProperties = Generator.exposeForm(myProject, myFormFile, rootContainer);
71 myBindings = new FormProperty2BeanProperty[formProperties.length];
72 for(int i = formProperties.length - 1; i >= 0; i--){
73 myBindings[i] = new FormProperty2BeanProperty(formProperties[i]);
76 final PsiManager manager = PsiManager.getInstance(myProject);
77 final VirtualFile directory = formFile.getParent();
78 LOG.assertTrue(directory.isDirectory());
79 final PsiDirectory psiDirectory = manager.findDirectory(directory);
80 LOG.assertTrue(psiDirectory != null);
81 final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
82 if(aPackage != null){
83 myPackageName = aPackage.getQualifiedName();