Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe

Commits:

2 changed files:

Changes:

  • client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/export/actions/Prepare.java
    ... ... @@ -58,7 +58,7 @@ public class Prepare extends ExportUIActionSupport {
    58 58
             addAdminWorker(ui.getPrepare().getToolTipText(), this::doPrepareAction0);
    
    59 59
         }
    
    60 60
     
    
    61
    -    private WizardState doPrepareAction0() throws Exception {
    
    61
    +    private WizardState doPrepareAction0() {
    
    62 62
     
    
    63 63
             AdminUIModel model = ui.getModel();
    
    64 64
             List<CopyDataTask> data = CopyDataTask.of(TaskSide.FROM_LEFT, model.getSelectDataModel().getSelectionDataModel()).collect(Collectors.toList());
    
    ... ... @@ -70,10 +70,6 @@ public class Prepare extends ExportUIActionSupport {
    70 70
     
    
    71 71
             ConfigModel configModel = model.getConfigModel();
    
    72 72
             ObserveSwingDataSource targetSource = configModel.getRightSourceModel().getSafeSourceNotOpened();
    
    73
    -        if (!targetSource.canWriteData()) {
    
    74
    -            throw new IllegalStateException(String.format("Can't export if target source (%s) has no data rights", targetSource.getLabel()));
    
    75
    -        }
    
    76
    -
    
    77 73
             ObserveSwingDataSource incomingSource = configModel.getLeftSourceModel().getSafeSourceNotOpened();
    
    78 74
     
    
    79 75
             stepModel.setData(data);
    

  • client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ReportModel.java
    ... ... @@ -57,7 +57,11 @@ import javax.swing.JComboBox;
    57 57
     import javax.swing.JLabel;
    
    58 58
     import javax.swing.JPanel;
    
    59 59
     import javax.swing.SwingUtilities;
    
    60
    +import javax.swing.table.TableCellRenderer;
    
    61
    +import javax.swing.table.TableColumn;
    
    62
    +import javax.swing.table.TableColumnModel;
    
    60 63
     import java.awt.BorderLayout;
    
    64
    +import java.awt.Component;
    
    61 65
     import java.awt.event.ItemEvent;
    
    62 66
     import java.beans.PropertyChangeListener;
    
    63 67
     import java.io.File;
    
    ... ... @@ -508,6 +512,9 @@ public class ReportModel extends AdminActionModel {
    508 512
                 if (reportColumnRenderersParameters != null) {
    
    509 513
                     reportColumnRenderersParameters.consumeColumnRenderersSwing(resultTable);
    
    510 514
                 }
    
    515
    +            resizeColumnWidth(resultTable,-1);
    
    516
    +
    
    517
    +
    
    511 518
             } catch (Exception e) {
    
    512 519
                 clearResult(ui);
    
    513 520
                 throw e;
    
    ... ... @@ -516,6 +523,30 @@ public class ReportModel extends AdminActionModel {
    516 523
             }
    
    517 524
         }
    
    518 525
     
    
    526
    +    public static void resizeColumnWidth(JXTable table, int maxWidth) {
    
    527
    +        final TableColumnModel columnModel = table.getColumnModel();
    
    528
    +        for (int column = 0; column < table.getColumnCount(); column++) {
    
    529
    +            // Account for header size
    
    530
    +            TableColumn tableColumn = table.getColumnModel().getColumn(column);
    
    531
    +            TableCellRenderer renderer = tableColumn.getCellRenderer();
    
    532
    +            if (renderer==null) {
    
    533
    +                renderer = table.getTableHeader().getDefaultRenderer();
    
    534
    +            }
    
    535
    +            Component component = renderer.getTableCellRendererComponent(table, tableColumn.getHeaderValue(), false, false, -1, column);
    
    536
    +            double width     = component.getPreferredSize().width;
    
    537
    +            for (int row = 0; row < table.getRowCount(); row++) {
    
    538
    +                renderer = table.getCellRenderer(row, column);
    
    539
    +                Component comp = table.prepareRenderer(renderer, row, column);
    
    540
    +                width = Math.max(comp.getPreferredSize().width + 1, width);
    
    541
    +            }
    
    542
    +            if (maxWidth>0 && width > maxWidth) {
    
    543
    +                width = maxWidth;
    
    544
    +            }
    
    545
    +            tableColumn.setPreferredWidth((int) width);
    
    546
    +            log.debug("Column {} - width (min/max/pref): {} {}/{}/{}", tableColumn.getModelIndex(), tableColumn.getWidth(), tableColumn.getMinWidth(), tableColumn.getMaxWidth(), tableColumn.getPreferredWidth());
    
    547
    +        }
    
    548
    +    }
    
    549
    +
    
    519 550
         private void clearResult(ReportUI ui) {
    
    520 551
             getResultModel().clear();
    
    521 552
             ui.getConfigurationPane().setTitle(null);