new feature: "subject tables row limit"

This commit is contained in:
Wisser
2020-01-27 15:28:40 +01:00
parent da4f9cdc9b
commit 48be5a3a17
3 changed files with 797 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
/*
* Copyright 2007 - 2020 Ralf Wisser.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.jailer.extractionmodel;
/**
* Defines a limit of rows to be exported per subject table wrt an ordering.
*
* @author Ralf Wisser
*/
public class SubjectLimitDefinition {
/**
* Row limit.
*/
public Long limit;
/**
* "order by" clause.
*/
public String orderBy;
/**
* Constructor.
*
* @param limit row limit
* @param orderBy "order by" clause
*/
public SubjectLimitDefinition(Long limit, String orderBy) {
this.limit = limit;
this.orderBy = orderBy;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((limit == null) ? 0 : limit.hashCode());
result = prime * result + ((orderBy == null) ? 0 : orderBy.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SubjectLimitDefinition other = (SubjectLimitDefinition) obj;
if (limit == null) {
if (other.limit != null)
return false;
} else if (!limit.equals(other.limit))
return false;
if (orderBy == null) {
if (other.orderBy != null)
return false;
} else if (!orderBy.equals(other.orderBy))
return false;
return true;
}
}

View File

@@ -0,0 +1,185 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,2,75"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel1">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="10" gridY="10" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel2">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
<EtchetBorder/>
</Border>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="10" gridY="5" gridWidth="20" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value=" Export only the first "/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Container class="javax.swing.JPanel" name="jPanel5">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="10" gridWidth="10" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
</Container>
<Component class="javax.swing.JTextField" name="limitTextField">
<Properties>
<Property name="columns" type="int" value="6"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value=" rows"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="2" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="orderByCheckBox">
<Properties>
<Property name="text" type="java.lang.String" value="according to the order:"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="orderByCheckBoxActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="2" gridWidth="10" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel3">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="20" gridWidth="30" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="0.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Component class="javax.swing.JButton" name="okButton">
<Properties>
<Property name="text" type="java.lang.String" value=" Ok "/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okButtonActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="16" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="cancelButton">
<Properties>
<Property name="text" type="java.lang.String" value=" Cancel "/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="16" anchor="16" weightX="1.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel4">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
<EtchetBorder/>
</Border>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="30" gridWidth="30" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="0.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Component class="javax.swing.JLabel" name="hintLabel">
<Properties>
<Property name="text" type="java.lang.String" value="&lt;html&gt; &lt;i&gt;Ctrl+Space&lt;/i&gt; for code completion. &lt;i&gt;Ctrl+Enter&lt;/i&gt; for Ok.&lt;i&gt;Esc&lt;/i&gt; for Cancel.&lt;/html&gt;"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="1.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Container class="javax.swing.JPanel" name="gripPanel">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="2" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="14" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
<Property name="horizontalGap" type="int" value="0"/>
<Property name="verticalGap" type="int" value="0"/>
</Layout>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@@ -0,0 +1,535 @@
/*
* Copyright 2007 - 2020 Ralf Wisser.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.jailer.ui;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.sql.SQLException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.Icon;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import org.fife.rsta.ui.EscapableDialog;
import net.sf.jailer.datamodel.DataModel;
import net.sf.jailer.datamodel.Table;
import net.sf.jailer.extractionmodel.SubjectLimitDefinition;
import net.sf.jailer.ui.syntaxtextarea.DataModelBasedSQLCompletionProvider;
import net.sf.jailer.ui.syntaxtextarea.RSyntaxTextAreaWithSQLSyntaxStyle;
import net.sf.jailer.ui.syntaxtextarea.SQLAutoCompletion;
import net.sf.jailer.ui.syntaxtextarea.SQLCompletionProvider;
import net.sf.jailer.ui.util.SizeGrip;
/**
* Editor for {@link SubjectLimitDefinition}.
*
* @author Ralf Wisser
*/
public abstract class SubjectLimitEditor extends EscapableDialog {
private boolean ok;
private boolean escaped;
private DataModelBasedSQLCompletionProvider provider;
/** Creates new form */
public SubjectLimitEditor(java.awt.Frame parent, DataModel dataModel) {
super(parent, false);
init(dataModel, false);
}
/** Creates new form
* @param modal */
public SubjectLimitEditor(Dialog parent, DataModel dataModel, boolean modal) {
super(parent, modal);
init(dataModel, modal);
}
@SuppressWarnings("serial")
private void init(DataModel dataModel, boolean modal) {
if (!modal) {
setUndecorated(true);
}
initComponents();
addWindowFocusListener(new WindowFocusListener() {
@Override
public void windowLostFocus(WindowEvent e) {
ok = !escaped;
setVisible(false);
}
@Override
public void windowGainedFocus(WindowEvent e) {
}
});
addComponentListener(new ComponentListener() {
@Override
public void componentShown(ComponentEvent e) {
limitTextField.grabFocus();
}
@Override
public void componentResized(ComponentEvent e) {
}
@Override
public void componentMoved(ComponentEvent e) {
}
@Override
public void componentHidden(ComponentEvent e) {
consume();
}
});
this.editorPane = new RSyntaxTextAreaWithSQLSyntaxStyle(false, false) {
@Override
protected void runBlock() {
super.runBlock();
okButtonActionPerformed(null);
}
@Override
protected boolean withFindAndReplace() {
return false;
}
};
JScrollPane jScrollPane2 = new JScrollPane();
jScrollPane2.setViewportView(editorPane);
JPanel corner = new SizeGrip();
gripPanel.add(corner);
GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 10;
gridBagConstraints.gridy = 10;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
jPanel5.add(jScrollPane2, gridBagConstraints);
jScrollPane2.setViewportView(editorPane);
if (dataModel != null) {
try {
provider = new DataModelBasedSQLCompletionProvider(null, dataModel);
provider.setDefaultClause(SQLCompletionProvider.Clause.WHERE);
sqlAutoCompletion = new SQLAutoCompletion(provider, editorPane);
} catch (SQLException e) {
}
}
setLocation(400, 150);
setSize(600, 200);
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanel5 = new javax.swing.JPanel();
limitTextField = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
orderByCheckBox = new javax.swing.JCheckBox();
jPanel3 = new javax.swing.JPanel();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
hintLabel = new javax.swing.JLabel();
gripPanel = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(new java.awt.GridBagLayout());
jPanel1.setLayout(new java.awt.GridBagLayout());
jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel2.setLayout(new java.awt.GridBagLayout());
jLabel1.setText(" Export only the first ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
jPanel2.add(jLabel1, gridBagConstraints);
jPanel5.setLayout(new java.awt.GridBagLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 10;
gridBagConstraints.gridwidth = 10;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
jPanel2.add(jPanel5, gridBagConstraints);
limitTextField.setColumns(6);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
jPanel2.add(limitTextField, gridBagConstraints);
jLabel2.setText(" rows");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
jPanel2.add(jLabel2, gridBagConstraints);
orderByCheckBox.setText("according to the order:");
orderByCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
orderByCheckBoxActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 10;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel2.add(orderByCheckBox, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 10;
gridBagConstraints.gridy = 5;
gridBagConstraints.gridwidth = 20;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
jPanel1.add(jPanel2, gridBagConstraints);
jPanel3.setLayout(new java.awt.GridBagLayout());
okButton.setText(" Ok ");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
jPanel3.add(okButton, gridBagConstraints);
cancelButton.setText(" Cancel ");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 16);
jPanel3.add(cancelButton, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 20;
gridBagConstraints.gridwidth = 30;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
jPanel1.add(jPanel3, gridBagConstraints);
jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel4.setLayout(new java.awt.GridBagLayout());
hintLabel.setText("<html> <i>Ctrl+Space</i> for code completion. <i>Ctrl+Enter</i> for Ok.<i>Esc</i> for Cancel.</html>");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weightx = 1.0;
jPanel4.add(hintLabel, gridBagConstraints);
gripPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
jPanel4.add(gripPanel, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 30;
gridBagConstraints.gridwidth = 30;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
jPanel1.add(jPanel4, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 10;
gridBagConstraints.gridy = 10;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
getContentPane().add(jPanel1, gridBagConstraints);
pack();
}// </editor-fold>//GEN-END:initComponents
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
ok = true;
setVisible(false);
}//GEN-LAST:event_okButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
escaped = true;
setVisible(false);
}//GEN-LAST:event_cancelButtonActionPerformed
private void orderByCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orderByCheckBoxActionPerformed
if (orderByCheckBox.isSelected()) {
editorPane.setText("order by ");
editorPane.setEnabled(true);
editorPane.grabFocus();
} else {
editorPane.setText("");
editorPane.setEnabled(false);
}
}//GEN-LAST:event_orderByCheckBoxActionPerformed
private SubjectLimitDefinition subjectLimitDefinition;
/**
* Edits a given definition.
*/
public void edit(JComponent locator, Table table, SubjectLimitDefinition subjectLimitDefinition) {
this.subjectLimitDefinition = subjectLimitDefinition;
ok = false;
escaped = false;
limitTextField.setText(subjectLimitDefinition.limit == null? "" : subjectLimitDefinition.limit.toString());
if (subjectLimitDefinition.orderBy != null) {
orderByCheckBox.setSelected(true);
editorPane.setText("order by " + subjectLimitDefinition.orderBy);
editorPane.setEnabled(true);
} else {
orderByCheckBox.setSelected(false);
editorPane.setText("");
editorPane.setEnabled(false);
}
editorPane.setCaretPosition(0);
editorPane.discardAllEdits();
if (provider != null) {
provider.removeAliases();
if (table != null) {
provider.addAlias("T", table);
}
}
UIUtil.invokeLater(new Runnable() {
@Override
public void run() {
editorPane.grabFocus();
}
});
if (locator != null) {
Point locationLocation = locator.getLocationOnScreen();
Point location;
location = new Point(locationLocation.x - 4, locationLocation.y + locator.getHeight() + 4);
setLocationAndFit(location);
}
setVisible(true);
}
@Override
protected void escapePressed() {
escaped = true;
super.escapePressed();
}
/**
* Removes single line comments.
*
* @param statement
* the statement
*
* @return statement the statement without comments and literals
*/
private String removeSingleLineComments(String statement) {
Pattern pattern = Pattern.compile("('(?:[^']*'))|(/\\*.*?\\*/)|(\\-\\-.*?(?=\n|$))", Pattern.DOTALL);
Matcher matcher = pattern.matcher(statement);
boolean result = matcher.find();
StringBuffer sb = new StringBuffer();
if (result) {
do {
if (matcher.group(3) == null) {
matcher.appendReplacement(sb, "$0");
result = matcher.find();
continue;
}
int l = matcher.group(0).length();
matcher.appendReplacement(sb, "");
if (matcher.group(1) != null) {
l -= 2;
sb.append("'");
}
while (l > 0) {
--l;
sb.append(' ');
}
if (matcher.group(1) != null) {
sb.append("'");
}
result = matcher.find();
} while (result);
}
matcher.appendTail(sb);
return sb.toString();
}
public void setLocationAndFit(Point pos) {
setLocation(pos);
UIUtil.fit(this);
try {
// Get the size of the screen
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
int hd = getY() - (dim.height - 80);
if (hd > 0) {
setLocation(getX(), Math.max(getY() - hd, 0));
}
} catch (Throwable t) {
// ignore
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JPanel gripPanel;
private javax.swing.JLabel hintLabel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JTextField limitTextField;
private javax.swing.JButton okButton;
private javax.swing.JCheckBox orderByCheckBox;
// End of variables declaration//GEN-END:variables
private Icon dropDownIcon;
{
// load images
dropDownIcon = UIUtil.readImage("/dropdown.png");
}
public RSyntaxTextAreaWithSQLSyntaxStyle editorPane;
private SQLAutoCompletion sqlAutoCompletion;
public void observe(final JTextField textfield, final Runnable open) {
InputMap im = textfield.getInputMap();
@SuppressWarnings("serial")
Action a = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
String origText = textfield.getText();
String caretMarker;
for (int suffix = 0; ; suffix++) {
caretMarker = "CARET" + suffix;
if (!origText.contains(caretMarker)) {
break;
}
}
try {
textfield.getDocument().insertString(textfield.getCaretPosition(), caretMarker, null);
} catch (BadLocationException e1) {
e1.printStackTrace();
}
open.run();
textfield.setText(origText);
String text = editorPane.getText();
int i = text.indexOf(caretMarker);
if (i >= 0) {
editorPane.setText(text.substring(0, i) + text.substring(i + caretMarker.length()));
editorPane.setCaretPosition(i);
}
UIUtil.invokeLater(1, new Runnable() {
@Override
public void run() {
sqlAutoCompletion.doCompletion();
}
});
}
};
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_DOWN_MASK);
im.put(ks, a);
ActionMap am = textfield.getActionMap();
am.put(a, a);
}
private void consume() {
Long limit = null;
try {
limit = Long.parseLong(limitTextField.getText().trim());
} catch (Exception e) {
limit = null;
}
String orderBy = removeSingleLineComments(editorPane.getText())
.replaceAll("\\n(\\r?) *", " ")
.replace('\n', ' ')
.replace('\r', ' ')
.replaceFirst("(?is)^order\\s+by\\s*", "");
SubjectLimitDefinition def = new SubjectLimitDefinition(limit, limit != null && orderBy.length() > 0? orderBy : null);
if (ok && def.equals(subjectLimitDefinition)) {
ok = false;
}
consume(ok? def : null);
}
public static String subjectLimitDefinitionRender(SubjectLimitDefinition limitDefinition) {
if (limitDefinition.limit == null) {
return "<html><i>no limit</i></html>";
} else {
return "<html><b>" + limitDefinition.limit + "</b> rows" + (limitDefinition.orderBy != null ? " (ordered)" : "") + "</html>";
}
}
protected abstract void consume(SubjectLimitDefinition subjectLimitDefinition);
private static final long serialVersionUID = -5169934807182707970L;
}