Skip to content

Commit 1d6c7aa

Browse files
committed
Feature #617 | #41
SQL result table: The detail data display now allows to automatically reformat XML or Json data. To configure automatic reformatting go to menu File --> Global preferences --> tab "Data type controls" --> section General Note: For detail data display double click a table cell or switch on cell detail display. Furthermore the reformat button was made a toggle button which allows to switch back to the unformatted data.
1 parent f7e6688 commit 1d6c7aa

File tree

8 files changed

+223
-82
lines changed

8 files changed

+223
-82
lines changed

sql12/core/doc/changes.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Not yet released, available in our GIT repository, snapshots and future releases
66

77
Enhancements:
88

9+
#617 | https://github.com/squirrel-sql-client/squirrel-sql-code/issues/41
10+
SQL result table: The detail data display now allows to automatically reformat XML or Json data.
11+
To configure automatic reformatting go to menu File --> Global preferences
12+
--> tab "Data type controls" --> section General
13+
Note: For detail data display double click a table cell or switch on cell detail display.
14+
Furthermore the reformat button was made a toggle button which allows to switch back to the unformatted data.
15+
916
SQL result table: The find function now allows to narrow the columns to search.
1017

1118
Refactoring: Dropping Foreign Keys is now available by default.

sql12/core/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeGeneral.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
public class DataTypeGeneral
1414
{
1515
public static final String USE_COLUMN_LABEL_INSTEAD_COLUMN_NAME = "useColumnLabelInsteadColumnName";
16+
public static final String FORMAT_XML_JSON_WHEN_DISPLAYED_IN_POPUP_PANEL = "formatXmlJsonWhenDisplayedInPopupPanel";
1617

17-
private static final StringManager s_stringMgr =
18-
StringManagerFactory.getStringManager(DataTypeGeneral.class);
18+
private static final StringManager s_stringMgr = StringManagerFactory.getStringManager(DataTypeGeneral.class);
1919

2020

2121
private static boolean propertiesAlreadyLoaded = false;
2222
private static boolean _useColumnLabelInsteadColumnName = false;
23+
private static boolean _formatXmlJsonWhenDisplayedInPopupPanel = false;
2324

2425
public static OkJPanel getControlPanel()
2526
{
@@ -33,6 +34,12 @@ public static boolean isUseColumnLabelInsteadColumnName()
3334
return _useColumnLabelInsteadColumnName;
3435
}
3536

37+
public static boolean isFormatXmlJsonWhenDisplayedInPopupPanel()
38+
{
39+
loadProperties();
40+
return _formatXmlJsonWhenDisplayedInPopupPanel;
41+
}
42+
3643
private static void loadProperties()
3744
{
3845

@@ -46,6 +53,14 @@ private static void loadProperties()
4653
_useColumnLabelInsteadColumnName = true;
4754
}
4855

56+
String formatXmlJsonWhenDisplayedInPopupPanel =
57+
DataTypeProps.getProperty(DataTypeGeneral.class.getName(), FORMAT_XML_JSON_WHEN_DISPLAYED_IN_POPUP_PANEL);
58+
59+
if (formatXmlJsonWhenDisplayedInPopupPanel != null && formatXmlJsonWhenDisplayedInPopupPanel.equals("true"))
60+
{
61+
_formatXmlJsonWhenDisplayedInPopupPanel = true;
62+
}
63+
4964
propertiesAlreadyLoaded = true;
5065
}
5166
}
@@ -55,24 +70,27 @@ private static class GeneralOkJPanel extends OkJPanel
5570
private JCheckBox _chkUseColumnLabelInsteadColumnName =
5671
new JCheckBox(s_stringMgr.getString("dataTypeBlob.useColumnLabelInsteadColumnName"));
5772

73+
private JCheckBox _chkFormatXmlJsonWhenDisplayedInPopupPanel =
74+
new JCheckBox(s_stringMgr.getString("dataTypeGeneral.formatXmlJsonWhenDisplayedInPopupPanel"));
75+
5876

5977
public GeneralOkJPanel()
6078
{
79+
loadProperties();
80+
6181
_chkUseColumnLabelInsteadColumnName.setSelected(DataTypeGeneral._useColumnLabelInsteadColumnName);
82+
_chkFormatXmlJsonWhenDisplayedInPopupPanel.setSelected(DataTypeGeneral._formatXmlJsonWhenDisplayedInPopupPanel);
6283

6384
setLayout(new GridBagLayout());
6485
setBorder(BorderFactory.createTitledBorder(s_stringMgr.getString("dataTypeGeneral.generalType")));
65-
final GridBagConstraints gbc = new GridBagConstraints();
66-
gbc.fill = GridBagConstraints.HORIZONTAL;
67-
gbc.insets = new Insets(4, 4, 4, 4);
68-
gbc.anchor = GridBagConstraints.WEST;
6986

70-
gbc.gridx = 0;
71-
gbc.gridy = 0;
87+
GridBagConstraints gbc;
7288

73-
gbc.gridwidth = 1;
89+
gbc = new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(4, 4, 0, 4), 0,0);
7490
add(_chkUseColumnLabelInsteadColumnName, gbc);
7591

92+
gbc = new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 0,0);
93+
add(_chkFormatXmlJsonWhenDisplayedInPopupPanel, gbc);
7694
}
7795

7896

@@ -85,6 +103,9 @@ public void ok()
85103
// get the values from the controls and set them in the static properties
86104
_useColumnLabelInsteadColumnName = _chkUseColumnLabelInsteadColumnName.isSelected();
87105
DataTypeProps.putDataTypeProperty(DataTypeGeneral.class.getName(), USE_COLUMN_LABEL_INSTEAD_COLUMN_NAME, Boolean.valueOf(_useColumnLabelInsteadColumnName).toString());
106+
107+
_formatXmlJsonWhenDisplayedInPopupPanel = _chkFormatXmlJsonWhenDisplayedInPopupPanel.isSelected();
108+
DataTypeProps.putDataTypeProperty(DataTypeGeneral.class.getName(), FORMAT_XML_JSON_WHEN_DISPLAYED_IN_POPUP_PANEL, Boolean.valueOf(_formatXmlJsonWhenDisplayedInPopupPanel).toString());
88109
}
89110

90111
}

sql12/core/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/I18NStrings.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ floatingPointBase.uselocaleDependendFormat=Use locale-dependent format ({0}), ({
8585
floatingPointBase.uselocaleDependendFormat.minDecimalDigits=a) minimum number of decimal digits of (0 means no minimum)
8686
floatingPointBase.uselocaleDependendFormat.maxDecimalDigits=b) maximum number of decimal digits of
8787
dataTypeBlob.useColumnLabelInsteadColumnName=Use column labels instead of column names in result headers
88+
dataTypeGeneral.formatXmlJsonWhenDisplayedInPopupPanel=Format Xml/Json when table data is displayed in detail panel.
8889

8990
dataTypeGeneral.generalType=General (applies to all types)
9091
BigDataToTextareaLoader.loading=Loading...

sql12/core/src/net/sourceforge/squirrel_sql/fw/datasetviewer/celldatapopup/CellDataPopupFormatter.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,39 @@ public class CellDataPopupFormatter
2828
private static final ILogger s_log = LoggerController.createLogger(CellDataPopupFormatter.class);
2929

3030

31-
public static String format(String toFormat)
31+
public static FormattingResult format(String toFormat, boolean silent)
3232
{
3333
Exception jsonFormatException = null;
3434

3535
FormatResult formatResult = tryJson(toFormat);
3636
jsonFormatException = formatResult.error;
3737
if (null == jsonFormatException)
3838
{
39-
return formatResult.result;
39+
return new FormattingResult(formatResult.result, true);
4040
}
4141

4242
formatResult = tryXml(toFormat);
4343
if (null == formatResult.error)
4444
{
45-
return formatResult.result;
45+
return new FormattingResult(formatResult.result, true);
4646
}
4747

48-
String msg = s_stringMgr.getString(
49-
"CellDataPopupFormatter.failed.reformat",
50-
StringUtilities.removeNewLine("" + jsonFormatException),
51-
StringUtilities.removeNewLine("" + formatResult.error));
48+
if(false == silent)
49+
{
50+
String msg = s_stringMgr.getString(
51+
"CellDataPopupFormatter.failed.reformat",
52+
StringUtilities.removeNewLine("" + jsonFormatException),
53+
StringUtilities.removeNewLine("" + formatResult.error));
5254

53-
Main.getApplication().getMessageHandler().showErrorMessage(msg);
55+
Main.getApplication().getMessageHandler().showErrorMessage(msg);
5456

55-
s_log.error("Failed to reformat cell data as JSON and as XML.\n" +
56-
"JSON error:\n" + Utilities.getStackTrace(jsonFormatException) +
57-
"XML error:\n" + Utilities.getStackTrace(formatResult.error));
57+
s_log.error("Failed to reformat cell data as JSON and as XML.\n" +
58+
"JSON error:\n" + Utilities.getStackTrace(jsonFormatException) +
59+
"XML error:\n" + Utilities.getStackTrace(formatResult.error));
60+
}
5861

5962

60-
return toFormat;
63+
return new FormattingResult(toFormat, false);
6164
}
6265

6366
private static FormatResult tryXml(String toFormat)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package net.sourceforge.squirrel_sql.fw.datasetviewer.celldatapopup;
2+
3+
public class FormattingResult
4+
{
5+
private final String _result;
6+
private final boolean _success;
7+
8+
public FormattingResult(String result, boolean success)
9+
{
10+
_result = result;
11+
_success = success;
12+
}
13+
14+
public String getResult()
15+
{
16+
return _result;
17+
}
18+
19+
public boolean isSuccess()
20+
{
21+
return _success;
22+
}
23+
}

sql12/core/src/net/sourceforge/squirrel_sql/fw/datasetviewer/celldatapopup/I18NStrings.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ popupeditableIoPanel.errorWritingFile=There was an error while writing file {0}.
5555
popupeditableIoPanel.exportError100=Export Error
5656
popupEditableIoPanel.wrapLines=Wrap Lines on/off
5757
popupEditableIoPanel.wrapWord=Wrap Word on/off
58-
popupEditableIoPanel.reformatXml=Reformat Xml/Json
58+
ReformatHandler.reformatXml=Reformat Xml/Json
59+
popupEditableIoPanel.popup.menu.reformatXml=Reformat Xml/Json
60+
5961

6062
popupeditableIoPanel.browse.tooltip=Select the file to export into
6163
popupeditableIoPanel.export.tooltip=Export to file

0 commit comments

Comments
 (0)