/*
Copyright 2008-2010 Gephi
Authors : Eduardo Ramos <eduramiba@gmail.com>
Website : http://www.gephi.org
This file is part of Gephi.
Gephi is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Gephi 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Gephi. If not, see <http://www.gnu.org/licenses/>.
*/
package org.gephi.datalab.plugin.manipulators.columns.merge.ui;
import javax.swing.JPanel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.datalab.plugin.manipulators.columns.merge.GeneralColumnTitleChooser;
import org.gephi.datalab.spi.DialogControls;
import org.gephi.datalab.spi.Manipulator;
import org.gephi.datalab.spi.ManipulatorUI;
import org.gephi.ui.utils.ColumnTitleValidator;
import org.netbeans.validation.api.ui.ValidationGroup;
import org.netbeans.validation.api.ui.ValidationPanel;
/**
* UI for general merge strategies that only need to select a title for the column to create.
* Takes care to validate the column title.
* @author Eduardo Ramos <eduramiba@gmail.com>
*/
public class GeneralColumnTitleChooserUI extends javax.swing.JPanel implements ManipulatorUI {
private GeneralColumnTitleChooser manipulator;
private DialogControls dialogControls;
private AttributeTable table;
private String displayName;
/** Creates new form GeneralColumnTitleChooserUI */
public GeneralColumnTitleChooserUI() {
initComponents();
titleTextField.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
refreshOkButton();
}
public void removeUpdate(DocumentEvent e) {
refreshOkButton();
}
public void changedUpdate(DocumentEvent e) {
refreshOkButton();
}
});
}
private void refreshOkButton() {
String text = titleTextField.getText();
dialogControls.setOkButtonEnabled(text != null && !text.isEmpty() && table != null && !table.hasColumn(text));//Title not empty and not repeated.
}
public void setup(Manipulator m, DialogControls dialogControls) {
this.manipulator = (GeneralColumnTitleChooser) m;
this.table = manipulator.getTable();
this.dialogControls = dialogControls;
this.displayName = m.getName();
titleTextField.setText(manipulator.getColumnTitle());
refreshOkButton();
}
public void unSetup() {
manipulator.setColumnTitle(titleTextField.getText());
}
public String getDisplayName() {
return displayName;
}
public JPanel getSettingsPanel() {
ValidationPanel validationPanel = new ValidationPanel();
validationPanel.setInnerComponent(this);
ValidationGroup group = validationPanel.getValidationGroup();
group.add(titleTextField, new ColumnTitleValidator(table));
return validationPanel;
}
public boolean isModal() {
return true;
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
titleLabel = new javax.swing.JLabel();
titleTextField = new javax.swing.JTextField();
titleLabel.setText(org.openide.util.NbBundle.getMessage(GeneralColumnTitleChooserUI.class, "GeneralColumnTitleChooserUI.titleLabel.text")); // NOI18N
titleTextField.setText(org.openide.util.NbBundle.getMessage(GeneralColumnTitleChooserUI.class, "GeneralColumnTitleChooserUI.titleTextField.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()
.addComponent(titleLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(titleTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 150, 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(titleLabel)
.addComponent(titleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel titleLabel;
private javax.swing.JTextField titleTextField;
// End of variables declaration//GEN-END:variables
}