/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.wcs.netbeans.liquiface.ui.wizards.dropunique;
/*
* #%L
* Liquiface - GUI for Liquibase
* %%
* Copyright (C) 2013 Webstar Csoport Kft.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import com.wcs.netbeans.liquiface.facade.ModelFacade;
import com.wcs.netbeans.liquiface.model.Column;
import com.wcs.netbeans.liquiface.model.Table;
import com.wcs.netbeans.liquiface.model.UniqueConstraint;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JPanel;
public final class DropUniqueConstraintVisualPanel1 extends JPanel {
/**
* Creates new form DropUniqueConstraintVisualPanel1
*/
public DropUniqueConstraintVisualPanel1(String tableName) {
initComponents();
final Table table = ModelFacade.getInstance().getTableByName(tableName);
List<UniqueConstraint> ucList = table.getUniqueConstraints();
List<String> ucNames = new ArrayList<String>();
ucNames.add("");
for (UniqueConstraint uc : ucList) {
ucNames.add(uc.getName());
}
selectedUcField.setModel(new DefaultComboBoxModel(ucNames.toArray()));
selectedUcField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String constraintName = (String) selectedUcField.getSelectedItem();
if (!constraintName.equals("")) {
UniqueConstraint selectedUc = table.getUniqueConstraintByName(constraintName);
if (selectedUc != null) {
List<String> columnNames = new ArrayList<String>();
for (Column column : selectedUc.getColumns()) {
columnNames.add(column.getName());
}
columnList.setListData(columnNames.toArray());
} else {
columnList.setListData(new String[]{});
}
} else {
columnList.setListData(new String[]{});
}
}
});
}
@Override
public String getName() {
return "Choose unique constraint";
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
* content of this method is always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
selectedUcField = new javax.swing.JComboBox();
jScrollPane1 = new javax.swing.JScrollPane();
columnList = new javax.swing.JList();
jLabel2 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(DropUniqueConstraintVisualPanel1.class, "DropUniqueConstraintVisualPanel1.jLabel1.text")); // NOI18N
selectedUcField.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
columnList.setModel(new javax.swing.AbstractListModel() {
String[] strings = { };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
columnList.setEnabled(false);
jScrollPane1.setViewportView(columnList);
org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(DropUniqueConstraintVisualPanel1.class, "DropUniqueConstraintVisualPanel1.jLabel2.text")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(selectedUcField, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(selectedUcField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 92, Short.MAX_VALUE)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JList columnList;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JComboBox selectedUcField;
// End of variables declaration//GEN-END:variables
public JComboBox getSelectedUcField() {
return selectedUcField;
}
}