01: package net.sourceforge.squirrel_sql.plugins.editextras;
02:
03: /*
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: */
18: import net.sourceforge.squirrel_sql.fw.util.BaseException;
19: import net.sourceforge.squirrel_sql.fw.util.ICommand;
20: import net.sourceforge.squirrel_sql.fw.util.StringUtilities;
21:
22: import net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI;
23:
24: /**
25: * This command will remove "newline" characters from an SQL string.
26: *
27: */
28: class RemoveNewLinesCommand implements ICommand {
29: private final ISQLPanelAPI _api;
30:
31: RemoveNewLinesCommand(ISQLPanelAPI api) {
32: super ();
33: _api = api;
34: }
35:
36: public void execute() throws BaseException {
37: int[] bounds = _api.getSQLEntryPanel()
38: .getBoundsOfSQLToBeExecuted();
39:
40: if (bounds[0] == bounds[1]) {
41: return;
42: }
43:
44: String textToChange = _api.getSQLEntryPanel()
45: .getSQLToBeExecuted();
46:
47: if (null == textToChange) {
48: return;
49: }
50:
51: String[] parts = textToChange.split("\n");
52: String newText = StringUtilities.join(parts, null);
53:
54: _api.getSQLEntryPanel().setSelectionStart(bounds[0]);
55: _api.getSQLEntryPanel().setSelectionEnd(bounds[1]);
56: _api.getSQLEntryPanel().replaceSelection(newText);
57: }
58: }
|