Search in sources :

Example 1 with PanelTable

use of com.jsql.view.swing.table.PanelTable in project jsql-injection by ron190.

the class ActionSaveTab method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    this.filechooser.setDialogTitle("Save Tab As");
    Component component = MediatorGui.tabResults().getSelectedComponent();
    if (component instanceof PanelTable) {
        this.saveTablePanel();
    } else if (component instanceof LightScrollPane && ((LightScrollPane) component).scrollPane.getViewport().getView() instanceof JTextComponent) {
        this.saveJTextComponent();
    }
}
Also used : LightScrollPane(com.jsql.view.swing.scrollpane.LightScrollPane) PanelTable(com.jsql.view.swing.table.PanelTable) JTextComponent(javax.swing.text.JTextComponent) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent)

Example 2 with PanelTable

use of com.jsql.view.swing.table.PanelTable in project jsql-injection by ron190.

the class ActionSaveTab method saveTablePanel.

private void saveTablePanel() {
    JTable table = ((PanelTable) MediatorGui.tabResults().getSelectedComponent()).getTableValues();
    if (table == null) {
        return;
    }
    int returnVal = this.filechooser.showSaveDialog(MediatorGui.frame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = this.filechooser.getSelectedFile();
        PreferencesUtil.set(this.filechooser.getCurrentDirectory().toString());
        try (FileWriter excel = new FileWriter(file)) {
            TableModel model = table.getModel();
            for (int i = 2; i < model.getColumnCount(); i++) {
                excel.write(model.getColumnName(i) + "\t");
            }
            excel.write("\n");
            for (int i = 0; i < model.getRowCount(); i++) {
                for (int j = 2; j < model.getColumnCount(); j++) {
                    /*
                         * Cell empty when string was too long to be injected (columnTooLong|cellEmpty|cellEmpty).
                         */
                    if (model.getValueAt(i, j) == null) {
                        excel.write("\t");
                    /*
                         * Remove line break.
                         */
                    } else {
                        excel.write(model.getValueAt(i, j).toString().replaceAll("\n", "\\n").replaceAll("\t", "\\t") + "\t");
                    }
                }
                excel.write("\n");
            }
        } catch (IOException e) {
            LOGGER.warn("Error writing to " + file.getName(), e);
        }
    }
}
Also used : JTable(javax.swing.JTable) FileWriter(java.io.FileWriter) PanelTable(com.jsql.view.swing.table.PanelTable) IOException(java.io.IOException) File(java.io.File) TableModel(javax.swing.table.TableModel)

Example 3 with PanelTable

use of com.jsql.view.swing.table.PanelTable in project jsql-injection by ron190.

the class CreateValuesTab method execute.

@Override
public void execute() {
    if (MediatorGui.frame() == null) {
        LOGGER.error("Unexpected unregistered MediatorGui.frame() in " + this.getClass());
    }
    // Report NullPointerException #1683
    DefaultMutableTreeNode node = MediatorGui.frame().getTreeNodeModels().get(this.table);
    if (node != null) {
        // Get the node
        AbstractNodeModel progressingTreeNodeModel = (AbstractNodeModel) node.getUserObject();
        // Update the progress value of the model, end the progress
        progressingTreeNodeModel.setIndexProgress(this.table.getChildCount());
        // Mark the node model as 'no stop/pause/resume button'
        progressingTreeNodeModel.setRunning(false);
        // Create a new table to display the values
        PanelTable newTableJPanel = new PanelTable(this.data, this.columnNames);
        // Create a new tab: add header and table
        MediatorGui.tabResults().addTab(StringUtil.detectUtf8(this.table.toString()), newTableJPanel);
        newTableJPanel.setComponentOrientation(ComponentOrientation.getOrientation(I18n.getLocaleDefault()));
        // Focus on the new tab
        MediatorGui.tabResults().setSelectedComponent(newTableJPanel);
        // Create a custom tab header with close button
        TabHeader header = new TabHeader(StringUtil.detectUtf8Html(this.table.toString()));
        MediatorGui.tabResults().setToolTipTextAt(MediatorGui.tabResults().indexOfComponent(newTableJPanel), "<html>" + "<b>" + this.table.getParent() + "." + this.table + "</b><br>" + "<i>" + String.join("<br>", Arrays.copyOfRange(this.columnNames, 2, this.columnNames.length)) + "</i>" + "</html>");
        // Apply the custom header to the tab
        MediatorGui.tabResults().setTabComponentAt(MediatorGui.tabResults().indexOfComponent(newTableJPanel), header);
    }
}
Also used : TabHeader(com.jsql.view.swing.tab.TabHeader) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AbstractNodeModel(com.jsql.view.swing.tree.model.AbstractNodeModel) PanelTable(com.jsql.view.swing.table.PanelTable)

Aggregations

PanelTable (com.jsql.view.swing.table.PanelTable)3 LightScrollPane (com.jsql.view.swing.scrollpane.LightScrollPane)1 TabHeader (com.jsql.view.swing.tab.TabHeader)1 AbstractNodeModel (com.jsql.view.swing.tree.model.AbstractNodeModel)1 Component (java.awt.Component)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 JTable (javax.swing.JTable)1 TableModel (javax.swing.table.TableModel)1 JTextComponent (javax.swing.text.JTextComponent)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1