FileDocCategorySizeDatePackage
DomainPathSelectionDialog.javaAPI DocGlassfish v2 API20276Fri May 04 22:35:06 BST 2007com.sun.enterprise.tools.upgrade.gui

DomainPathSelectionDialog

public class DomainPathSelectionDialog extends JDialog
author
prakash

Fields Summary
private com.sun.enterprise.util.i18n.StringManager
stringManager
private DomainPathTableModel
domainPathTableModel
private JTable
domainPathTable
private JScrollPane
domainPathTableScrollPane
private JPanel
domainPathsPanel
private JPanel
addRemoveButtonsPanel
private JButton
addDomainPathButton
private JButton
removeDomainPathButton
private JFileChooser
fileChooser
public static final int
OK_ACTION
public static final int
CANCEL_ACTION
public static final int
HELP_ACTION
public int
USER_ACTION
private Vector
dialogListeners
Constructors Summary
public DomainPathSelectionDialog()
Creates a new instance of DomainPathSelectionDialog

    
           
      
        this.setTitle(stringManager.getString("upgrade.gui.domainPanel.dialogTitle"));
        this.initComponents();
        super.setModal(true);
    
Methods Summary
private voidaddComponetWithConstraints(javax.swing.JComponent compo, java.awt.Container parent, int gx, int gy, int gw, int gh, int fill, java.awt.Insets in, double wx, double wy)

        java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = gx; gridBagConstraints.gridy = gy;
        gridBagConstraints.gridwidth = gw; gridBagConstraints.gridheight = gh;
        gridBagConstraints.fill = fill;
        gridBagConstraints.insets = in;
        gridBagConstraints.weightx = wx;
        gridBagConstraints.weighty = wy;
        parent.add(compo, gridBagConstraints);
    
public voidaddDialogListener(DialogListener listener)

        this.dialogListeners.addElement(listener);
    
public voidaddDomainPathAction()

        int returnedValue = getfileChooser().showOpenDialog(this);
        if(returnedValue == javax.swing.JFileChooser.APPROVE_OPTION){
            getDomainPathTableModel().addDomainPath(String.valueOf(getfileChooser().getSelectedFile()));
        }
    
private voidcancelButtonActionPerformed()

        this.USER_ACTION = CANCEL_ACTION;
        this.dispose();
        /*DialogEvent de = new DialogEvent(this, DialogEvent.CANCEL_ACTION);
        for(int i=0 ; i<this.dialogListeners.size(); i++){
            ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de);
        }*/
    
public voidenableDisableRemoveButton(javax.swing.JTable table, javax.swing.JButton removeButton)

        if (table.getSelectionModel().isSelectionEmpty()) {
            removeButton.setEnabled(false);
            
        } else {
            if (table.getSelectedRowCount() > 1) {
                //editButton.setEnabled(false);
            } else {
                removeButton.setEnabled(true);
            }
        }
    
private javax.swing.JPanelgetButtonsPanel()

        javax.swing.JPanel buttonsPanel = new javax.swing.JPanel();
        javax.swing.JButton okButton = new javax.swing.JButton();
        javax.swing.JButton cancelButton = new javax.swing.JButton();
        javax.swing.JButton helpButton = new javax.swing.JButton();
        buttonsPanel.setLayout(new java.awt.GridBagLayout());
        
        okButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.okButtonText"));
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed();
            }
        });
        this.addComponetWithConstraints(okButton, buttonsPanel, 1, 0, 1,1, GridBagConstraints.NONE, new Insets(5, 5, 10, 10), 0.0,0.0);
        
        cancelButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.cancelButtonText"));
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed();
            }
        });
        this.addComponetWithConstraints(cancelButton, buttonsPanel, 2, 0, 1,1, GridBagConstraints.NONE, new Insets(5, 5, 10, 10), 0.0,0.0);
        
        helpButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.helpButtonText"));
        helpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpButtonActionPerformed();
            }
        });
        this.addComponetWithConstraints(helpButton, buttonsPanel, 3, 0, 1,1, GridBagConstraints.NONE, new Insets(5, 5, 10, 10), 0.0,0.0);
        this.addComponetWithConstraints(new JPanel(), buttonsPanel, 0, 0, 1,1, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 10, 10), 1.0,0.0);
        if(Utils.getHelpBroker() != null)
            Utils.getHelpBroker().enableHelpOnButton(helpButton, "ADD_DOMAIN_DIALOG", null);
        return buttonsPanel;
    
private javax.swing.JTablegetDomainPathTable()

        if (domainPathTable == null) {
            domainPathTable = new javax.swing.JTable();
            domainPathTable.setName("domainPathTable");
            getDomainPathTableScrollPane().setColumnHeaderView(domainPathTable.getTableHeader());
            getDomainPathTableScrollPane().getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
            domainPathTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
            domainPathTable.setAutoCreateColumnsFromModel(true);
            domainPathTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
            domainPathTable.setAutoCreateColumnsFromModel(true);
            
            ListSelectionModel rowSM = domainPathTable.getSelectionModel();
            rowSM.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
                    //Ignore extra messages.
                    if (e.getValueIsAdjusting()) return;
                    
                    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                    enableDisableRemoveButton(domainPathTable,getremoveDomainPathButton());
                }
            });
            final DefaultCellEditor editor = (DefaultCellEditor)domainPathTable.getDefaultEditor(String.class);
            editor.getComponent().addKeyListener(new java.awt.event.KeyAdapter(){
                public void keyReleased(java.awt.event.KeyEvent ke){
                    try{
                        getDomainPathTableModel().setValueAt(((JTextField)editor.getComponent()).getText().trim(),domainPathTable.getEditingRow(),0);
                    }catch(Exception e){
                    }
                }
                
            });
            
        }
        return domainPathTable;
    
public com.sun.enterprise.tools.upgrade.gui.DomainPathSelectionDialog$DomainPathTableModelgetDomainPathTableModel()

        if(this.domainPathTableModel == null){
            domainPathTableModel = new DomainPathTableModel(this);
        }
        return domainPathTableModel;
    
private javax.swing.JScrollPanegetDomainPathTableScrollPane()

        if (domainPathTableScrollPane == null) {
            domainPathTableScrollPane = new javax.swing.JScrollPane();
            domainPathTableScrollPane.setName("getDomainPathTable");
            domainPathTableScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            domainPathTableScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            domainPathTableScrollPane.setMaximumSize(new java.awt.Dimension(21, 20));
            domainPathTableScrollPane.setPreferredSize(new java.awt.Dimension(21, 20));
            domainPathTableScrollPane.setMinimumSize(new java.awt.Dimension(21, 20));
            domainPathTableScrollPane.setViewportView(getDomainPathTable());
        }
        return domainPathTableScrollPane;
    
private javax.swing.JPanelgetDomainPathsPanel()

        if (domainPathsPanel == null) {
            domainPathsPanel = new javax.swing.JPanel();
            domainPathsPanel.setName("domainPathsPanel");
            domainPathsPanel.setLayout(new java.awt.GridBagLayout());
            
            JLabel tableTitleLabel = new JLabel();
            tableTitleLabel.setText(stringManager.getString("upgrade.gui.domainPanel.tableTitleName"));
            this.addComponetWithConstraints(tableTitleLabel, domainPathsPanel, 0, 0,3,1, GridBagConstraints.NONE, new Insets(10, 10, 5, 0), 0.0,0.0);
            this.addComponetWithConstraints(getDomainPathTableScrollPane(), domainPathsPanel, 0, 1,2,1, GridBagConstraints.BOTH, new Insets(5, 10, 5, 0), 1.0,1.0);
            this.addComponetWithConstraints(getaddRemoveButtonsPanel(), domainPathsPanel, 2, 1,1,1, GridBagConstraints.VERTICAL, new Insets(5, 0, 5, 0), 0.0,1.0);
        }
        return domainPathsPanel;
    
private javax.swing.JButtongetaddDomainPathButton()

        if (addDomainPathButton == null) {
            addDomainPathButton = new javax.swing.JButton();
            addDomainPathButton.setName("addDomainPathButton");
            addDomainPathButton.setText(stringManager.getString("upgrade.gui.domainPanel.addButtonText"));
            addDomainPathButton.addActionListener(new java.awt.event.ActionListener(){
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    addDomainPathAction();
                }
            });
        }
        return addDomainPathButton;
    
private javax.swing.JPanelgetaddRemoveButtonsPanel()

        if (addRemoveButtonsPanel == null) {
            addRemoveButtonsPanel = new javax.swing.JPanel();
            addRemoveButtonsPanel.setName("addRemoveButtonsPanel");
            addRemoveButtonsPanel.setLayout(new java.awt.GridBagLayout());
            
            this.addComponetWithConstraints(getaddDomainPathButton(), addRemoveButtonsPanel, 0, 0,1,1, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0.0,0.0);
            this.addComponetWithConstraints(getremoveDomainPathButton(), addRemoveButtonsPanel, 0, 1,1,1, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0.0,0.0);
        }
        return addRemoveButtonsPanel;
    
private javax.swing.JFileChoosergetfileChooser()

        if (fileChooser == null) {
            fileChooser = new javax.swing.JFileChooser();
            fileChooser.setName("fileChooser");
            fileChooser.setBounds(668, 49, 500, 300);
            fileChooser.setDialogTitle(stringManager.getString("upgrade.gui.certpanel.chooseFile"));
            fileChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
        }
        return fileChooser;
    
private javax.swing.JButtongetremoveDomainPathButton()

        if (removeDomainPathButton == null) {
            removeDomainPathButton = new javax.swing.JButton();
            removeDomainPathButton.setName("removeDomainPathButton");
            removeDomainPathButton.setText(stringManager.getString("upgrade.gui.domainPanel.deleteButtonText"));
            removeDomainPathButton.addActionListener(new java.awt.event.ActionListener(){
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    removeDomainPathAction();
                }
            });
        }
        return removeDomainPathButton;
    
private voidhelpButtonActionPerformed()

        this.USER_ACTION = HELP_ACTION;
        //this.dispose();
        /*DialogEvent de = new DialogEvent(this, DialogEvent.HELP_ACTION);
        for(int i=0 ; i<this.dialogListeners.size(); i++){
            ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de);
        }*/
    
private voidinitComponents()

        this.getContentPane().setLayout(new java.awt.GridBagLayout());
        javax.swing.JSeparator separatorPanel = new javax.swing.JSeparator();
        
        this.addComponetWithConstraints(getDomainPathsPanel(), this.getContentPane(), 0, 0,1,1, GridBagConstraints.BOTH, new Insets(10, 0, 0, 5), 1.0,1.0);
        this.addComponetWithConstraints(separatorPanel, this.getContentPane(), 0, 1,1,1, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 1.0,0.0);
        this.addComponetWithConstraints(getButtonsPanel(), this.getContentPane(), 0, 2,1,1, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 1.0,0.0);
        getDomainPathTableScrollPane().setViewportView(getDomainPathTable());
        
        getDomainPathTable().setModel(this.getDomainPathTableModel());
        getDomainPathTable().createDefaultColumnsFromModel();
        
        this.setSize(500, 350);
    
private voidokButtonActionPerformed()

        this.USER_ACTION = OK_ACTION;
        this.dispose();
    
private voidprocessDialogEvent()

        DialogEvent de = new DialogEvent(this, DialogEvent.CHANGE_ACTION);
        for(int i=0 ; i<this.dialogListeners.size(); i++){
            ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de);
        }
    
public voidremoveDialogListener(DialogListener listener)

        this.dialogListeners.removeElement(listener);
    
public voidremoveDomainPathAction()

        
        int rows[] = getDomainPathTable().getSelectedRows();
        String[] rowPropNames = new String[rows.length];
        int option =
        javax.swing.JOptionPane.showConfirmDialog(
        this,
        stringManager.getString("upgrade.gui.domainPanel.removeConfirmMsg"),
        stringManager.getString("upgrade.gui.domainPanel.removeConfirmTitle"),
        javax.swing.JOptionPane.YES_NO_OPTION,
        javax.swing.JOptionPane.QUESTION_MESSAGE);
        if (option == javax.swing.JOptionPane.NO_OPTION) {
            return;
        }
        
        for (int i = 0; i < rows.length; i++) {
            rowPropNames[i] =
            (String)getDomainPathTableModel().getDomainPath(rows[i]);
        }
        for (int i = 0; i < rows.length; i++) {
            getDomainPathTableModel().removeDomainPath(rowPropNames[i]);
        }
        // Un select items rows in table.
        getDomainPathTable().clearSelection();
        enableDisableRemoveButton(getDomainPathTable(), getremoveDomainPathButton());