import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
import static net.argius.stew.ui.window.ConnectorMapEditDialog.ActionKey.*;
-
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
-
import javax.swing.*;
import javax.swing.event.*;
-
import net.argius.stew.*;
final class ConnectorMapEditDialog extends JDialog implements ChangeListener, AnyActionListener {
}
private final class IdListMouseListener extends MouseAdapter {
+ IdListMouseListener() {
+ } // empty
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() % 2 == 0) {
- ConnectorEntry entry = (ConnectorEntry)idList.getSelectedValue();
- openConnectorEditDialog(entry.getConnector());
+ openConnectorEditDialog();
}
}
}
return button;
}
+ void openConnectorEditDialog() {
+ ConnectorEntry entry = (ConnectorEntry)idList.getSelectedValue();
+ openConnectorEditDialog(entry.getConnector());
+ }
+
private void openConnectorEditDialog(Connector connector) {
ConnectorEditDialog dialog = new ConnectorEditDialog(this, connector);
dialog.addChangeListener(this);
}
private final class TextSearchKeyListener extends KeyAdapter {
+ TextSearchKeyListener() {
+ } // empty
@Override
public void keyTyped(KeyEvent e) {
removeKeyListener(this);
toggleShowColumnNumber
}
- private static final Logger log = Logger.getLogger(DatabaseInfoTree.class);
+ static final Logger log = Logger.getLogger(DatabaseInfoTree.class);
+
private static final ResourceManager res = ResourceManager.getInstance(DatabaseInfoTree.class);
private static final String TABLE_TYPE_TABLE = "TABLE";
private static final String TABLE_TYPE_VIEW = "VIEW";
private static final String TABLE_TYPE_INDEX = "INDEX";
private static final String TABLE_TYPE_SEQUENCE = "SEQUENCE";
- private static final List<String> DEFAULT_TABLE_TYPES = //
+ static final List<String> DEFAULT_TABLE_TYPES = //
Arrays.asList(TABLE_TYPE_TABLE, TABLE_TYPE_VIEW, TABLE_TYPE_INDEX, TABLE_TYPE_SEQUENCE);
static volatile boolean showColumnNumber;
expandNode(connectorNode, dbmeta);
createdStatusSet.add(connectorNode);
// events
- addTreeWillExpandListener(new TreeWillExpandListener() {
+ class TreeWillExpandListenerImpl implements TreeWillExpandListener {
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
TreePath path = event.getPath();
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
// ignore
}
- });
+ }
+ addTreeWillExpandListener(new TreeWillExpandListenerImpl());
this.dbmeta = dbmeta;
// showing
model.reload();
return;
}
final DefaultTreeModel model = (DefaultTreeModel)getModel();
- final InfoNode tmpNode = new InfoNode(res.get("i.paren-in-processing")) {
- @Override
- protected List<InfoNode> createChildren(DatabaseMetaData dbmeta) throws SQLException {
- return Collections.emptyList();
- }
- @Override
- public boolean isLeaf() {
- return true;
- }
- };
- invokeLater(new Runnable() {
- @Override
- public void run() {
- model.insertNodeInto(tmpNode, parent, 0);
- }
- });
+ final DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(res.get("i.paren-in-processing"));
// asynchronous
- DaemonThreadFactory.execute(new Runnable() {
+ class NodeExpansionTask implements Runnable {
@Override
public void run() {
+ class Task1 implements Runnable {
+ @Override
+ public void run() {
+ model.insertNodeInto(tmpNode, parent, 0);
+ }
+ }
+ invokeLater(new Task1());
+ final List<InfoNode> children;
try {
- final List<InfoNode> children = new ArrayList<InfoNode>(parent.createChildren(dbmeta));
- invokeLater(new Runnable() {
- @Override
- public void run() {
- for (InfoNode child : children) {
- model.insertNodeInto(child, parent, parent.getChildCount());
- }
- model.removeNodeFromParent(tmpNode);
- }
- });
+ children = new ArrayList<InfoNode>(parent.createChildren(dbmeta));
} catch (SQLException ex) {
try {
if (dbmeta.getConnection().isClosed())
}
throw new RuntimeException(ex);
}
+ class Task2 implements Runnable {
+ @Override
+ public void run() {
+ for (InfoNode child : children) {
+ model.insertNodeInto(child, parent, parent.getChildCount());
+ }
+ model.removeNodeFromParent(tmpNode);
+ }
+ }
+ invokeLater(new Task2());
}
- });
+ }
+ DaemonThreadFactory.execute(new NodeExpansionTask());
}
/**
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
- if (value instanceof InfoNode) {
- setIcon(Utilities.getImageIcon(((InfoNode)value).getIconName()));
- }
+ setIcon((value instanceof InfoNode) ? Utilities.getImageIcon(((InfoNode)value).getIconName()) : null);
if (value instanceof ColumnNode) {
if (showColumnNumber) {
TreePath path = tree.getPathForRow(row);
ResultSet rs = dbmeta.getColumns(catalog, schema, name, null);
try {
while (rs.next()) {
- a.add(new ColumnNode(rs.getString(4),
- rs.getString(6),
- rs.getInt(7),
- rs.getString(18),
- this));
+ a.add(new ColumnNode(rs.getString(4), rs.getString(6), rs.getInt(7), rs.getString(18), this));
}
} finally {
rs.close();
import static javax.swing.KeyStroke.getKeyStroke;
import static net.argius.stew.ui.window.AnyActionKey.*;
import static net.argius.stew.ui.window.ResultSetTable.ActionKey.*;
-
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.sql.*;
import java.util.*;
import java.util.List;
-
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import javax.swing.text.*;
-
import net.argius.stew.*;
import net.argius.stew.io.*;
import net.argius.stew.text.*;
}
private final class RowHeaderMouseInputListener extends MouseInputAdapter {
-
+
@SuppressWarnings("hiding")
private final RowHeader rowHeader;
private int dragStartRow;
-
+
RowHeaderMouseInputListener(RowHeader rowHeader) {
this.rowHeader = rowHeader;
}
-
+
@Override
public void mousePressed(MouseEvent e) {
changeSelection(e);
}
-
+
@Override
public void mouseDragged(MouseEvent e) {
changeSelection(e);
}
-
+
private void changeSelection(MouseEvent e) {
Point p = new Point(e.getX(), e.getY());
if (SwingUtilities.isLeftMouseButton(e)) {
}
private final class ColumnHeaderMouseInputListener extends MouseInputAdapter {
-
+
private int dragStartColumn;
-
+
ColumnHeaderMouseInputListener() {
} // empty
}
mousePositionForColumnHeader.setLocation(e.getPoint());
}
-
+
@Override
public void mouseDragged(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
changeSelection(e);
}
}
-
+
private void changeSelection(MouseEvent e) {
final Point p = e.getPoint();
int id = e.getID();
} else {
for (final int i : getSelectedColumns()) {
a.add(m.getColumnName(i));
- }
+ }
}
ClipboardHelper.setString(TextUtilities.join(TAB, a));
} else if (ev.isAnyOf(findColumnName)) {
final JTextComponent text = (JTextComponent)c;
AnyAction aa = new AnyAction(text);
aa.setUndoAction();
- c.addFocusListener(new FocusAdapter() {
+ class EditCanceledOnCellFocusLost extends FocusAdapter {
@Override
public void focusLost(FocusEvent e) {
editingCanceled(new ChangeEvent(e.getSource()));
}
- });
+ }
+ c.addFocusListener(new EditCanceledOnCellFocusLost());
}
}
}
}
table.changeSelection(ri, ci, false, extend);
}
-
+
}
private static final class NullValueRenderer extends DefaultTableCellRenderer {
import static java.sql.Types.*;
import static java.util.Collections.nCopies;
import static net.argius.stew.text.TextUtilities.join;
-
import java.math.*;
import java.sql.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.*;
import java.util.regex.*;
-
import javax.swing.table.*;
-
import net.argius.stew.*;
/**
*/
final class ResultSetTableModel extends DefaultTableModel {
- private static final Logger log = Logger.getLogger(ResultSetTableModel.class);
+ static final Logger log = Logger.getLogger(ResultSetTableModel.class);
private static final long serialVersionUID = -8861356207097438822L;
private static final String PTN1 = "\\s*SELECT\\s.+?\\sFROM\\s+([^\\s]+).*";
}
private static final class RowComparator implements Comparator<List<Object>> {
-
+
private final int f;
private final int columnIndex;
-
+
RowComparator(int f, int columnIndex) {
this.f = f;
this.columnIndex = columnIndex;
}
-
+
@Override
public int compare(List<Object> row1, List<Object> row2) {
return c(row1, row2) * f;
}
-
+
private int c(List<Object> row1, List<Object> row2) {
if (row1 == null || row2 == null) {
return row1 == null ? row2 == null ? 0 : -1 : 1;
}
/**
- * Checks whether this table is linkable.
+ * Checks whether this table is linkable.
* @return
*/
boolean isLinkable() {
}
final CountDownLatch latch = new CountDownLatch(1);
final List<SQLException> errors = new ArrayList<SQLException>();
+ final Connection conn = this.conn;
+ final int[] types = this.types;
// asynchronous execution
- DaemonThreadFactory.execute(new Runnable() {
- @SuppressWarnings("synthetic-access")
+ class SqlTask implements Runnable {
@Override
public void run() {
try {
}
latch.countDown();
}
- });
+ }
+ DaemonThreadFactory.execute(new SqlTask());
try {
// waits for a task to stop
latch.await(3L, TimeUnit.SECONDS);
throw new RuntimeException(ex);
}
if (latch.getCount() != 0) {
- DaemonThreadFactory.execute(new Runnable() {
+ class SqlTaskErrorHandler implements Runnable {
@Override
public void run() {
try {
log.warn(ex);
}
if (!errors.isEmpty()) {
- invokeLater(new Runnable() {
+ class ErrorNotifier implements Runnable {
@Override
public void run() {
WindowOutputProcessor.showErrorDialog(null, errors.get(0));
}
- });
+ }
+ invokeLater(new ErrorNotifier());
}
}
- });
+ }
+ DaemonThreadFactory.execute(new SqlTaskErrorHandler());
} else if (!errors.isEmpty()) {
if (log.isDebugEnabled()) {
for (final Exception ex : errors) {
import static javax.swing.JOptionPane.showMessageDialog;
import static javax.swing.KeyStroke.getKeyStroke;
import static net.argius.stew.ui.window.TextSearchPanel.ActionKey.*;
-
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
-
import javax.swing.*;
-
import net.argius.stew.*;
import net.argius.stew.ui.window.TextSearch.Matcher;
add(ignoreCaseCheck);
// [Setup Focus Policy]
final FocusTraversalPolicy parentPolicy = frame.getFocusTraversalPolicy();
- frame.setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {
+ class LayoutFocusTraversalPolicyImpl extends LayoutFocusTraversalPolicy {
@Override
public Component getComponentAfter(Container focusCycleRoot, Component component) {
if (component == ignoreCaseCheck) {
}
return parentPolicy.getComponentBefore(focusCycleRoot, component);
}
- });
+ }
+ frame.setFocusTraversalPolicy(new LayoutFocusTraversalPolicyImpl());
// [Events]
// text field
ContextMenu.createForText(text);
*/
public final class WindowLauncher implements
Launcher,
+ FocusListener,
AnyActionListener,
Runnable,
UncaughtExceptionHandler {
+ static final ResourceManager res = ResourceManager.getInstance(WindowLauncher.class);
private static final Logger log = Logger.getLogger(WindowLauncher.class);
- private static final ResourceManager res = ResourceManager.getInstance(WindowLauncher.class);
+
private static final List<WindowLauncher> instances = Collections.synchronizedList(new ArrayList<WindowLauncher>());
private final WindowOutputProcessor op;
textSearchMap.put(textArea, textArea);
for (Entry<JComponent, TextSearch> entry : textSearchMap.entrySet()) {
final JComponent c = entry.getKey();
- c.addFocusListener(new FocusAdapter() {
- @Override
- public void focusGained(FocusEvent e) {
- focused = c;
- textSearchPanel.setCurrentTarget(textSearchMap.get(c));
- }
- });
+ c.addFocusListener(this);
textSearchPanel.addTarget(entry.getValue());
}
// status bar
}
@Override
+ public void focusGained(FocusEvent e) {
+ JComponent c = (JComponent)e.getSource();
+ focused = c;
+ textSearchPanel.setCurrentTarget(textSearchMap.get(c));
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ // ignore
+ }
+
+ @Override
public void anyActionPerformed(AnyActionEvent ev) {
log.atEnter("anyActionPerformed", ev);
ev.validate();
final JLabel statusBar = this.statusBar;
final OutputProcessor opref = env.getOutputProcessor();
final AnyAction invoker = new AnyAction(this);
- try {
- doPreProcess();
- executorService.execute(new Runnable() {
- @Override
- public void run() {
- Connection conn = env.getCurrentConnection();
- long time = System.currentTimeMillis();
- if (!Command.invoke(env, cmd)) {
- exit();
- }
- if (infoTree.isEnabled()) {
- try {
- if (env.getCurrentConnection() != conn) {
- infoTree.clear();
- if (env.getCurrentConnection() != null) {
- infoTree.refreshRoot(env);
- }
+ final class CommandTask implements Runnable {
+ @Override
+ public void run() {
+ Connection conn = env.getCurrentConnection();
+ long time = System.currentTimeMillis();
+ if (!Command.invoke(env, cmd)) {
+ exit();
+ }
+ if (infoTree.isEnabled()) {
+ try {
+ if (env.getCurrentConnection() != conn) {
+ infoTree.clear();
+ if (env.getCurrentConnection() != null) {
+ infoTree.refreshRoot(env);
}
- } catch (Throwable th) {
- handleError(th);
}
- }
- if (env.getOutputProcessor() == opref) {
- time = System.currentTimeMillis() - time;
- statusBar.setText(res.get("i.statusbar-message", time / 1000f, cmd));
- invoker.doLater("doPostProcess");
+ } catch (Throwable th) {
+ handleError(th);
}
}
- });
+ if (env.getOutputProcessor() == opref) {
+ time = System.currentTimeMillis() - time;
+ statusBar.setText(res.get("i.statusbar-message", time / 1000f, cmd));
+ invoker.doLater("doPostProcess");
+ }
+ }
+ }
+ try {
+ doPreProcess();
+ executorService.execute(new CommandTask());
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
}
private static final class WakeupTimerTask extends TimerTask {
+ WakeupTimerTask() {
+ } // empty
private final AnyAction aa = new AnyAction(this);
@Override
public void run() {
import static net.argius.stew.ui.window.AnyActionKey.*;
import static net.argius.stew.ui.window.Utilities.getImageIcon;
import static net.argius.stew.ui.window.Utilities.sleep;
-
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.List;
-
import javax.swing.*;
import javax.swing.table.*;
-
import net.argius.stew.*;
import net.argius.stew.io.*;
import net.argius.stew.ui.*;
aa.doLater("removeComponent", p);
}
- private void requestFocusToTextAreaInWindow() {
+ void requestFocusToTextAreaInWindow() {
textArea.requestFocusInWindow();
}
- private void moveWindow(int incX, int incY) {
- setLocation(getX() + incX, getY() + incY);
- }
-
final class PostProcessAction extends JPanel {
int sign = -1;
byte[] alpha;
}
void shakeWindow(int range) {
sign *= -1;
- moveWindow(range * sign, 0);
+ setLocation(getX() + range * sign, getY() + 0);
}
void showComponent(JComponent c) {
requestFocusToTextAreaInWindow();