update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / wizard / BindToNewBeanStep.java
blob068bf0f1fed73ec0d188702c3dbb375ab81ae572
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.ide.wizard.CommitStepException;
19 import com.intellij.ide.wizard.StepAdapter;
20 import com.intellij.openapi.diagnostic.Logger;
21 import com.intellij.openapi.util.IconLoader;
22 import com.intellij.psi.JavaPsiFacade;
23 import com.intellij.psi.PsiNameHelper;
24 import com.intellij.uiDesigner.UIDesignerBundle;
25 import org.jetbrains.annotations.NotNull;
27 import javax.swing.*;
28 import javax.swing.table.AbstractTableModel;
29 import javax.swing.table.TableCellEditor;
30 import javax.swing.table.TableColumn;
32 /**
33 * @author Anton Katilin
34 * @author Vladimir Kondratyev
36 final class BindToNewBeanStep extends StepAdapter{
37 private static final Logger LOG = Logger.getInstance("#com.intellij.uiDesigner.wizard.BindToNewBeanStep");
39 private JScrollPane myScrollPane;
40 private JTable myTable;
41 private final WizardData myData;
42 private final MyTableModel myTableModel;
43 private JCheckBox myChkIsModified;
44 private JCheckBox myChkSetData;
45 private JCheckBox myChkGetData;
46 private JPanel myPanel;
48 BindToNewBeanStep(@NotNull final WizardData data) {
49 myData = data;
50 myTableModel = new MyTableModel();
51 myTable.setModel(myTableModel);
52 myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
53 myScrollPane.getViewport().setBackground(myTable.getBackground());
54 myTable.setSurrendersFocusOnKeystroke(true);
56 // Customize "Form Property" column
58 final TableColumn column = myTable.getColumnModel().getColumn(0/*Form Property*/);
59 column.setCellRenderer(new FormPropertyTableCellRenderer(myData.myProject));
62 // Customize "Bean Property" column
64 final TableColumn column = myTable.getColumnModel().getColumn(1/*Bean Property*/);
65 column.setCellRenderer(new BeanPropertyTableCellRenderer());
66 column.setCellEditor(new BeanPropertyTableCellEditor());
68 final DefaultCellEditor editor = (DefaultCellEditor)myTable.getDefaultEditor(Object.class);
69 editor.setClickCountToStart(1);
72 myChkGetData.setSelected(true);
73 myChkGetData.setEnabled(false);
74 myChkSetData.setSelected(true);
75 myChkSetData.setEnabled(false);
76 myChkIsModified.setSelected(myData.myGenerateIsModified);
79 public JComponent getComponent() {
80 return myPanel;
83 public void _init() {
84 // Check that data is correct
85 LOG.assertTrue(myData.myBindToNewBean);
86 myTableModel.fireTableDataChanged();
89 public void _commit(boolean finishChosen) throws CommitStepException {
90 // Stop editing if any
91 final TableCellEditor cellEditor = myTable.getCellEditor();
92 if(cellEditor != null){
93 cellEditor.stopCellEditing();
96 // Check that all included fields are bound to valid bean properties
97 final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(myData.myProject).getNameHelper();
98 for(int i = 0; i <myData.myBindings.length; i++){
99 final FormProperty2BeanProperty binding = myData.myBindings[i];
100 if(binding.myBeanProperty == null){
101 continue;
104 if (!nameHelper.isIdentifier(binding.myBeanProperty.myName)){
105 throw new CommitStepException(
106 UIDesignerBundle.message("error.X.is.not.a.valid.property.name", binding.myBeanProperty.myName)
111 myData.myGenerateIsModified = myChkIsModified.isSelected();
114 public Icon getIcon() {
115 return IconLoader.getIcon("/com/intellij/uiDesigner/icons/dataBinding.png");
118 private final class MyTableModel extends AbstractTableModel{
119 private final String[] myColumnNames;
120 private final Class[] myColumnClasses;
122 public MyTableModel() {
123 myColumnNames = new String[]{
124 UIDesignerBundle.message("column.form.field"),
125 UIDesignerBundle.message("column.bean.property")};
126 myColumnClasses = new Class[]{Object.class, Object.class};
129 public int getColumnCount() {
130 return myColumnNames.length;
133 public String getColumnName(final int column) {
134 return myColumnNames[column];
137 public Class getColumnClass(final int column) {
138 return myColumnClasses[column];
141 public int getRowCount() {
142 return myData.myBindings.length;
145 public boolean isCellEditable(final int row, final int column) {
146 return column == 1/*Bean Property*/;
149 public Object getValueAt(final int row, final int column) {
150 final FormProperty2BeanProperty binding = myData.myBindings[row];
151 if(column == 0/*Form Property*/){
152 return binding.myFormProperty;
154 else if(column == 1/*Bean Property*/){
155 return binding.myBeanProperty;
157 else{
158 throw new IllegalArgumentException("unknown column: " + column);
162 public void setValueAt(final Object value, final int row, final int column) {
163 final FormProperty2BeanProperty binding = myData.myBindings[row];
164 if(column == 1/*Bean Property*/){
165 binding.myBeanProperty = (BeanProperty)value;
167 else{
168 throw new IllegalArgumentException("unknown column: " + column);