Skip to content

Commit

Permalink
renaming of menu items regarding DDL generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Wisser committed May 8, 2024
1 parent 13a5c4f commit f4d8643
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/main/gui/net/sf/jailer/ui/ExtractionModelFrame.form
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
<MenuItem class="javax.swing.JMenuItem" name="generateDDLMenuItem">
<Properties>
<Property name="text" type="java.lang.String" value="Generate DDL Script"/>
<Property name="toolTipText" type="java.lang.String" value="Generate a DDL script that creates the database objects (CREATE TABLE, VIEW etc.)"/>
<Property name="toolTipText" type="java.lang.String" value="Generate a SQL/DDL script that creates the database objects (CREATE TABLE, VIEW etc.)"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="generateDDLMenuItemActionPerformed"/>
Expand Down
2 changes: 1 addition & 1 deletion src/main/gui/net/sf/jailer/ui/ExtractionModelFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenu1.add(jSeparator25);

generateDDLMenuItem.setText("Generate DDL Script");
generateDDLMenuItem.setToolTipText("Generate a DDL script that creates the database objects (CREATE TABLE, VIEW etc.)");
generateDDLMenuItem.setToolTipText("Generate a SQL/DDL script that creates the database objects (CREATE TABLE, VIEW etc.)");
generateDDLMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
generateDDLMenuItemActionPerformed(evt);
Expand Down
4 changes: 2 additions & 2 deletions src/main/gui/net/sf/jailer/ui/UIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2668,9 +2668,9 @@ public void paintBorder(Component c, Graphics g, int x, int y, int width,
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

int b = 10;
int b = 12;
if (c instanceof JCheckBox || c instanceof JRadioButton) {
b = 7;
b = 8;
}

g2d.setColor(((c instanceof JLabel) && ((JLabel) c).getIcon() == null) || c instanceof JTextField?
Expand Down
2 changes: 1 addition & 1 deletion src/main/gui/net/sf/jailer/ui/databrowser/DataBrowser.form
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
<MenuItem class="javax.swing.JMenuItem" name="generateDDLMenuItem">
<Properties>
<Property name="text" type="java.lang.String" value="Generate DDL Script"/>
<Property name="toolTipText" type="java.lang.String" value="Generate a DDL script that creates the database objects (CREATE TABLE, VIEW etc.)"/>
<Property name="toolTipText" type="java.lang.String" value="Generate a SQL/DDL script that creates the database objects (CREATE TABLE, VIEW etc.)"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="generateDDLMenuItemActionPerformed"/>
Expand Down
22 changes: 11 additions & 11 deletions src/main/gui/net/sf/jailer/ui/databrowser/DataBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ protected void openConditionEditor(BrowserContentPane browserContentPane, Point

@Override
protected void loadScriptFile(String fileName) {
loadSQLScriptFile(new File(fileName), false);
loadSQLScriptFile(new File(fileName), false, null);
}

@Override
Expand Down Expand Up @@ -3461,7 +3461,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
menuTools.add(jSeparator25);

generateDDLMenuItem.setText("Generate DDL Script");
generateDDLMenuItem.setToolTipText("Generate a DDL script that creates the database objects (CREATE TABLE, VIEW etc.)");
generateDDLMenuItem.setToolTipText("Generate a SQL/DDL script that creates the database objects (CREATE TABLE, VIEW etc.)");
generateDDLMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
generateDDLMenuItemActionPerformed(evt);
Expand Down Expand Up @@ -6131,7 +6131,7 @@ protected void onContentStateChange(File file, boolean dirty) {
titleLbl.setToolTipText(null);
} else {
title = file.getName();
titleLbl.setToolTipText(file.getAbsolutePath());
titleLbl.setToolTipText(alternativeToolTip == null? file.getAbsolutePath() : alternativeToolTip);
}
if (dirty && file != null) {
titleLbl.setText("* " + title);
Expand Down Expand Up @@ -6237,7 +6237,7 @@ private boolean closeAllSQLConsoles() {
List<SQLConsoleWithTitle> toClose = new ArrayList<SQLConsoleWithTitle>(sqlConsoles);
for (SQLConsoleWithTitle sqlConsole : toClose) {
workbenchTabbedPane.setSelectedComponent(sqlConsole);
if (sqlConsole.getFile() != null && sqlConsole.isDirty()) {
if (sqlConsole.getFile() != null && sqlConsole.isDirty() && !sqlConsole.isTempFileBased()) {
if (!closeSQLConsole(sqlConsole, true)) {
return false;
}
Expand All @@ -6258,7 +6258,7 @@ private boolean closeSQLConsole(SQLConsole sqlConsole, boolean ask) {
if (!sqlConsole.isEmpty() && !(sqlConsole.getFile() != null && !sqlConsole.isDirty())) {
if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(DataBrowser.this,
"Close \"" + (sqlConsole instanceof SQLConsoleWithTitle? ((SQLConsoleWithTitle) sqlConsole).getTitle() : "SQL Console") + "\""
+ (sqlConsole.getFile() == null ? "?" : " without saving?"),
+ (sqlConsole.getFile() == null && !sqlConsole.isTempFileBased()? "?" : " without saving?"),
"Close Console", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)) {
return false;
}
Expand All @@ -6281,7 +6281,7 @@ private void updateLoadSaveScriptMenuItemsState() {
if (sc instanceof SQLConsole) {
sqlConsole = (SQLConsole) sc;
}
saveScriptMenuItem.setEnabled(sqlConsole != null && sqlConsole.isDirty());
saveScriptMenuItem.setEnabled(sqlConsole != null && (sqlConsole.isDirty() && !sqlConsole.isTempFileBased()));
saveScriptAsMenuItem.setEnabled(sqlConsole != null && !sqlConsole.isEmpty());
if (sqlConsole != null) {
goBackItem.setEnabled(false);
Expand All @@ -6295,11 +6295,11 @@ private void loadScriptMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
String fName = UIUtil.choseFile(null, ".", "Load SQL Script", "", this, false, true);
if (fName != null) {
File file = new File(fName);
loadSQLScriptFile(file, false);
loadSQLScriptFile(file, false, null);
}
}// GEN-LAST:event_loadScriptMenuItemActionPerformed

public void loadSQLScriptFile(File file, boolean silent) {
public void loadSQLScriptFile(File file, boolean silent, String alternativeToolTip) {
if (file.exists() && file.isDirectory()) {
return;
}
Expand All @@ -6317,7 +6317,7 @@ public void loadSQLScriptFile(File file, boolean silent) {
}
try {
UIUtil.setWaitCursor(this);
createNewSQLConsole(getMetaDataSource()).loadFromFile(file, silent);
createNewSQLConsole(getMetaDataSource()).loadFromFile(file, silent, alternativeToolTip);
} catch (Throwable e) {
UIUtil.showException(this, "Error", e, session);
} finally {
Expand All @@ -6328,7 +6328,7 @@ public void loadSQLScriptFile(File file, boolean silent) {
private void saveScriptMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_saveScriptMenuItemActionPerformed
SQLConsole sqlConsole = getCurrentSQLConsole();
if (sqlConsole != null) {
if (sqlConsole.getFile() == null) {
if (sqlConsole.getFile() == null && sqlConsole.isTempFileBased()) {
saveScriptAsMenuItemActionPerformed(evt);
} else {
try {
Expand Down Expand Up @@ -6570,7 +6570,7 @@ public void drop(DropTargetDropEvent dtde) {
@SuppressWarnings("unchecked")
java.util.List<File> files = (java.util.List<File>) tr.getTransferData(flavors[i]);
for (int k = 0; k < files.size(); k++) {
loadSQLScriptFile(files.get(k), false);
loadSQLScriptFile(files.get(k), false, null);
}

dtde.dropComplete(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,25 @@

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="consoleContainerPanel">
<Container class="javax.swing.JPanel" name="jPanel7">
<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="4" 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.DesignBorderLayout"/>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="consoleContainerPanel">
<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="4" 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.DesignBorderLayout"/>
</Container>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel5">
<Constraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ public abstract class SQLConsole extends javax.swing.JPanel {
private final ImageIcon scaledExplainIcon;
private final SQLPlusSupport sqlPlusSupport = new SQLPlusSupport();
private File file;
private boolean tempFileBased;
protected String alternativeToolTip;
private JMenuItem menuItemToggle;
private JMenuItem menuItemToSingleLine;
private JMenuItem menuItemSubstituteVariables;
Expand Down Expand Up @@ -2600,6 +2602,7 @@ private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jSplitPane2 = new javax.swing.JSplitPane();
jPanel2 = new javax.swing.JPanel();
jPanel7 = new javax.swing.JPanel();
consoleContainerPanel = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
Expand Down Expand Up @@ -2635,6 +2638,8 @@ private void initComponents() {

jPanel2.setLayout(new java.awt.GridBagLayout());

jPanel7.setLayout(new java.awt.GridBagLayout());

consoleContainerPanel.setLayout(new java.awt.BorderLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
Expand All @@ -2643,7 +2648,16 @@ private void initComponents() {
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
jPanel2.add(consoleContainerPanel, gridBagConstraints);
jPanel7.add(consoleContainerPanel, gridBagConstraints);

gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 4;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
jPanel2.add(jPanel7, gridBagConstraints);

jPanel5.setLayout(new java.awt.GridBagLayout());

Expand Down Expand Up @@ -2857,6 +2871,7 @@ private void continueButtonActionPerformed(java.awt.event.ActionEvent evt) {//GE
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JToolBar.Separator jSeparator1;
private javax.swing.JToolBar.Separator jSeparator2;
private javax.swing.JToolBar.Separator jSeparator3;
Expand Down Expand Up @@ -4104,10 +4119,10 @@ public void setRowLimit(Integer limit) {
*
* @param file the file
*/
public void loadFromFile(File file, boolean silent) throws IOException {
if (!silent) {
this.file = file;
}
public void loadFromFile(File file, boolean tempFileBased, String alternativeToolTip) throws IOException {
this.file = file;
this.tempFileBased = tempFileBased;
this.alternativeToolTip = alternativeToolTip;
if (file.exists()) {
String path = file.getPath();
Charset encoding = SqlUtil.retrieveEncoding(path);
Expand Down Expand Up @@ -4142,20 +4157,61 @@ public void loadFromFile(File file, boolean silent) throws IOException {
initialContentSize = editorPane.getDocument().getLength();
initialContentHash = editorPane.getText().hashCode();
consoleContainerPanel.setVisible(false);
UIUtil.invokeLater(new Runnable() {
UIUtil.invokeLater(4, new Runnable() {
@Override
public void run() {
consoleContainerPanel.setVisible(true);
grabFocus();
if (file.exists()) {
startAfterLoadIndicatorTimer();
}
}
});
setCaretPosition(0);
if (!silent) {
onContentStateChange(file, dirty);
}
onContentStateChange(file, dirty);
UIUtil.invokeLater(2, () -> editorPane.scrollRectToVisible(new Rectangle(0, 0, 1, 1)));
}

private void startAfterLoadIndicatorTimer() {
final double DELTA = 0.03;
int delay = 25;
Color c0 = editorPane.getBackground();
Color c1 = new Color(100, 255, 100);
if (c0 != null) {
Timer[] timer = new Timer[1];
timer[0] = new Timer(delay, new ActionListener() {
double x = 0;
double delta = DELTA;

// TODO
{ delta = delta / 10; }

private int fade(int a, int b) {
double fScaled = 1 -Math.pow(x, 4);

double rf = Math.sin(fScaled / Math.PI);
int color = (int) (a + rf * (b - a));
if (color < 0 || color > 255) {
throw new IllegalStateException(color + " not in color range");
}
return color;
}
@Override
public void actionPerformed(ActionEvent e) {
if ((x += delta) > 1.0) {
editorPane.setBackground(c0);
timer[0].stop();
} else {
editorPane.setBackground(new Color(fade(c0.getRed(), c1.getRed()), fade(c0.getGreen(), c1.getGreen()), fade(c0.getBlue(), c1.getBlue())));
}
}
});
timer[0].setInitialDelay(delay);
timer[0].setRepeats(true);
timer[0].start();
}
}

/**
* Stores content to file if console is dirty or new file is given.
*
Expand Down Expand Up @@ -4205,6 +4261,8 @@ public void storeToFile(File newFile) throws IOException {
initialContentSize = editorPane.getDocument().getLength();
initialContentHash = editorPane.getText().hashCode();
dirty = false;
tempFileBased = false;
alternativeToolTip = null;
onContentStateChange(file, dirty);
}
}
Expand Down Expand Up @@ -4396,6 +4454,10 @@ public void updateConnectionType(ConnectionType connectionType) {
}
}

public boolean isTempFileBased() {
return tempFileBased;
}

// TODO 2
// TODO ordering per column: break down to SQL?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jPanel1.add(includeAllButton, gridBagConstraints);

includeClosureButton.setText("Tables associated with a subject table");
includeClosureButton.setToolTipText("<html>Generate DDL statements only for the tables that are directly or indirectly associated with a subject table. (the <i>Closure</i>)<br>Note that this excludes sequences.</html>");
includeClosureButton.setToolTipText("<html>Generate SQL/DDL statements only for the tables that are directly or indirectly associated with a subject table. (the <i>Closure</i>)<br>Note that this excludes sequences.</html>");
includeClosureButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
includeClosureButtonActionPerformed(evt);
Expand Down Expand Up @@ -1141,13 +1141,17 @@ private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
}
}//GEN-LAST:event_closeButtonActionPerformed

private static File silentDDLScriptFileName;

private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
String fileName;

if (silent) {
File tmp = Configuration.getInstance().createTempFile();
tmp.deleteOnExit();
fileName = tmp.getAbsolutePath();
if (silentDDLScriptFileName == null) {
silentDDLScriptFileName = new File(Configuration.getInstance().createTempFile(), "DDL");
silentDDLScriptFileName.deleteOnExit();
}
fileName = silentDDLScriptFileName.getAbsolutePath();
} else {
String fn = scriptFileTextField.getText().trim();
if (fn.isEmpty()) {
Expand All @@ -1172,7 +1176,7 @@ private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
UIUtil.invokeLater(4, () -> {
try {
if (owner instanceof DataBrowser) {
((DataBrowser) owner).loadSQLScriptFile(new File(fileName), silent);
((DataBrowser) owner).loadSQLScriptFile(new File(fileName), silent, "Generated SQL/DDL Script.");
} else {
new FileView(owner, owner, fileName, true);
}
Expand Down

0 comments on commit f4d8643

Please sign in to comment.