01: package net.sourceforge.squirrel_sql.client.gui.session;
02:
03: import net.sourceforge.squirrel_sql.fw.completion.CompletionInfo;
04: import net.sourceforge.squirrel_sql.fw.util.Resources;
05: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
06:
07: import javax.swing.*;
08:
09: public class ToolsPopupCompletionInfo extends CompletionInfo {
10: private String _selectionString;
11: private Action _action;
12: private int _maxCandidateSelectionStringName;
13: private String _description;
14:
15: public ToolsPopupCompletionInfo(String selectionString,
16: Action action) {
17: _selectionString = selectionString;
18: _action = action;
19: }
20:
21: public String getCompareString() {
22: return _selectionString;
23: }
24:
25: public String getCompletionString() {
26: return "";
27: }
28:
29: public Action getAction() {
30: return _action;
31: }
32:
33: public String toString() {
34: return _selectionString + getDist() + getDescription();
35: }
36:
37: private Object getDescription() {
38: if (null == _description) {
39: if (null != _action.getValue(Action.SHORT_DESCRIPTION)) {
40: _description = _action.getValue(
41: Action.SHORT_DESCRIPTION).toString();
42: } else {
43: _description = "";
44: }
45:
46: if (false == _action instanceof SquirrelAction // SquirrelAction descriptions already contain the accelerator
47: && null != _action
48: .getValue(Resources.ACCELERATOR_STRING)
49: && 0 != _action.getValue(
50: Resources.ACCELERATOR_STRING).toString()
51: .trim().length()) {
52: _description += " ("
53: + _action
54: .getValue(Resources.ACCELERATOR_STRING)
55: + ")";
56: }
57: }
58: return _description;
59: }
60:
61: private String getDist() {
62: int len = _maxCandidateSelectionStringName
63: - _selectionString.length() + 4;
64:
65: StringBuffer ret = new StringBuffer();
66:
67: for (int i = 0; i < len; ++i) {
68: ret.append(' ');
69: }
70:
71: return ret.toString();
72: }
73:
74: public void setMaxCandidateSelectionStringName(
75: int maxCandidateSelectionStringName) {
76: _maxCandidateSelectionStringName = maxCandidateSelectionStringName;
77: }
78:
79: public String getSelectionString() {
80: return _selectionString;
81: }
82: }
|