Search in sources :

Example 1 with CellEditorComponentWithBrowseButton

use of com.intellij.util.ui.CellEditorComponentWithBrowseButton in project intellij-plugins by JetBrains.

the class FilesToPackageForm method initTable.

private void initTable() {
    myFilesToPackageTable = new JBTable();
    // otherwise model is not in sync with view
    myFilesToPackageTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    myFilesToPackageTable.setPreferredScrollableViewportSize(JBUI.size(400, 150));
    myFilesToPackageTable.setRowHeight(new JTextField("Fake").getPreferredSize().height + myFilesToPackageTable.getRowMargin());
    myFilesToPackageTable.setModel(new DefaultTableModel() {

        public int getColumnCount() {
            return Column.values().length;
        }

        public int getRowCount() {
            return myFilesToPackage.size();
        }

        public String getColumnName(int column) {
            return Column.values()[column].getColumnName();
        }

        public Class<?> getColumnClass(int column) {
            return Column.values()[column].getColumnClass();
        }

        public Object getValueAt(int row, int column) {
            return Column.values()[column].getValue(myFilesToPackage.get(row));
        }

        public void setValueAt(Object aValue, int row, int column) {
            Column.values()[column].setValue(myFilesToPackage, row, aValue);
        }
    });
    myFilesToPackageTable.getColumnModel().getColumn(0).setCellEditor(new AbstractTableCellEditor() {

        private CellEditorComponentWithBrowseButton<JTextField> myComponent;

        public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, int row, int column) {
            final ActionListener listener = new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    FileChooserDescriptor d = new FileChooserDescriptor(true, true, false, true, false, false);
                    VirtualFile initialFile = LocalFileSystem.getInstance().findFileByPath((String) getCellEditorValue());
                    VirtualFile file = FileChooser.chooseFile(d, myProject, initialFile);
                    if (file != null) {
                        myComponent.getChildComponent().setText(file.getPresentableUrl());
                    }
                }
            };
            myComponent = new CellEditorComponentWithBrowseButton<>(new TextFieldWithBrowseButton(listener), this);
            myComponent.getChildComponent().setText((String) value);
            return myComponent;
        }

        public Object getCellEditorValue() {
            return myComponent.getChildComponent().getText();
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionEvent(java.awt.event.ActionEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) DefaultTableModel(javax.swing.table.DefaultTableModel) JBTable(com.intellij.ui.table.JBTable) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) CellEditorComponentWithBrowseButton(com.intellij.util.ui.CellEditorComponentWithBrowseButton) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ActionListener(java.awt.event.ActionListener)

Aggregations

FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 JBTable (com.intellij.ui.table.JBTable)1 AbstractTableCellEditor (com.intellij.util.ui.AbstractTableCellEditor)1 CellEditorComponentWithBrowseButton (com.intellij.util.ui.CellEditorComponentWithBrowseButton)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 DefaultTableModel (javax.swing.table.DefaultTableModel)1