Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
******************************************************************************/ |
11 |
|
12 |
package org.eclipse.jface.viewers; |
13 |
|
14 |
import org.eclipse.core.runtime.Assert; |
15 |
import org.eclipse.swt.SWT; |
16 |
import org.eclipse.swt.custom.Field3270; |
17 |
import org.eclipse.swt.events.FocusAdapter; |
18 |
import org.eclipse.swt.events.FocusEvent; |
19 |
import org.eclipse.swt.events.KeyAdapter; |
20 |
import org.eclipse.swt.events.KeyEvent; |
21 |
import org.eclipse.swt.events.MouseAdapter; |
22 |
import org.eclipse.swt.events.MouseEvent; |
23 |
import org.eclipse.swt.events.SelectionAdapter; |
24 |
import org.eclipse.swt.events.SelectionEvent; |
25 |
import org.eclipse.swt.events.TraverseEvent; |
26 |
import org.eclipse.swt.events.TraverseListener; |
27 |
import org.eclipse.swt.widgets.Composite; |
28 |
import org.eclipse.swt.widgets.Control; |
29 |
import org.eclipse.swt.widgets.Event; |
30 |
|
31 |
/** |
32 |
* A cell editor that manages a text entry field. |
33 |
* The cell editor's value is the text string itself. |
34 |
* The class is used when JDBC connection is of 3270 type |
35 |
* (one of the optional properties of JDBC connection |
36 |
* should be: 3270_FIELD_SUPPORT=true) |
37 |
*/ |
38 |
public class Field3270CellEditor extends TextCellEditor { |
39 |
/* |
40 |
* The Field3270 control; initially <code>null</code>. |
41 |
*/ |
42 |
private Field3270 field3270; |
43 |
|
44 |
/** |
45 |
* Creates a new Field3279 string cell editor with no control |
46 |
* The cell editor value is the string itself, which is initially the empty |
47 |
* string. |
48 |
*/ |
49 |
public Field3270CellEditor() { |
50 |
super(); |
51 |
} |
52 |
|
53 |
/** |
54 |
* Creates a new Field3279 string cell editor with no control |
55 |
* The cell editor value is the string itself, which is initially the empty |
56 |
* string. |
57 |
* @param parent |
58 |
*/ |
59 |
public Field3270CellEditor(Composite parent) { |
60 |
super(parent); |
61 |
} |
62 |
|
63 |
/** |
64 |
* Creates a new Field3270 string cell editor with no control |
65 |
* The cell editor value is the string itself, which is initially the empty |
66 |
* string. |
67 |
* @param parent |
68 |
* @param style |
69 |
*/ |
70 |
public Field3270CellEditor(Composite parent, int style) { |
71 |
super(parent, style); |
72 |
} |
73 |
|
74 |
protected Control createControl(Composite parent) { |
75 |
field3270 = new Field3270(parent, getStyle()); |
76 |
field3270.setArrOfIgnoredChars(new char[] {'\t'}); |
77 |
field3270.addSelectionListener(new SelectionAdapter() { |
78 |
public void widgetDefaultSelected(SelectionEvent e) { |
79 |
handleDefaultSelection(e); |
80 |
} |
81 |
}); |
82 |
field3270.addKeyListener(new KeyAdapter() { |
83 |
public void keyPressed(KeyEvent e) { |
84 |
keyReleaseOccured(e); |
85 |
if ((getControl() == null) || getControl().isDisposed()) { |
86 |
return; |
87 |
} |
88 |
checkSelection(); |
89 |
checkDeleteable(); |
90 |
checkSelectable(); |
91 |
if (e.character == '\r') { // Return key |
92 |
Event event = new Event(); |
93 |
event.widget = e.widget; |
94 |
event.stateMask = e.stateMask; |
95 |
event.doit = e.doit; |
96 |
|
97 |
SelectionEvent selectionEvent = new SelectionEvent(event); |
98 |
handleDefaultSelection(selectionEvent); |
99 |
} |
100 |
} |
101 |
}); |
102 |
field3270.getStyledText().addTraverseListener(new TraverseListener() { |
103 |
public void keyTraversed(TraverseEvent e) { |
104 |
if (e.detail == SWT.TRAVERSE_ESCAPE |
105 |
|| e.detail == SWT.TRAVERSE_RETURN) { |
106 |
e.doit = false; |
107 |
} |
108 |
|
109 |
} |
110 |
}); |
111 |
|
112 |
field3270.addMouseListener(new MouseAdapter() { |
113 |
public void mouseUp(MouseEvent e) { |
114 |
checkSelection(); |
115 |
checkDeleteable(); |
116 |
checkSelectable(); |
117 |
} |
118 |
}); |
119 |
field3270.addFocusListener(new FocusAdapter() { |
120 |
public void focusLost(FocusEvent e) { |
121 |
Field3270CellEditor.this.focusLost(); |
122 |
} |
123 |
}); |
124 |
field3270.setFont(parent.getFont()); |
125 |
field3270.setBackground(parent.getBackground()); |
126 |
field3270.setText("");//$NON-NLS-1$ |
127 |
field3270.addModifyListener(getModifyListener()); |
128 |
return field3270.getStyledText(); |
129 |
} |
130 |
|
131 |
protected Object doGetValue() { |
132 |
|
133 |
String returnStr; |
134 |
if (field3270.isWidgetReversed() ^ field3270.isPushMode()) |
135 |
returnStr = Field3270.reverseStr(field3270.getText()); |
136 |
else |
137 |
returnStr = field3270.getText(); |
138 |
if (field3270.isPushMode()) |
139 |
field3270.setPush(false); |
140 |
return returnStr; |
141 |
} |
142 |
|
143 |
protected void doSetValue(Object value) { |
144 |
Assert.isTrue(field3270 != null && field3270.getStyledText() != null && (value instanceof String)); |
145 |
field3270.removeModifyListener(getModifyListener()); |
146 |
String bidiValue; |
147 |
if (field3270.isWidgetReversed() ^ field3270.isPushMode()) |
148 |
bidiValue = Field3270.reverseStr((String) value); |
149 |
else |
150 |
bidiValue = (String) value; |
151 |
field3270.setText(bidiValue); |
152 |
|
153 |
field3270.addModifyListener(getModifyListener()); |
154 |
} |
155 |
protected void doSetFocus() { |
156 |
if ((field3270 != null) && (field3270.getStyledText() != null)) { |
157 |
field3270.selectAll(); |
158 |
field3270.getStyledText().setFocus(); |
159 |
checkSelection(); |
160 |
checkDeleteable(); |
161 |
checkSelectable(); |
162 |
} |
163 |
} |
164 |
|
165 |
|
166 |
protected int getTextSelectionCount(){ |
167 |
return field3270.getSelectionCount(); |
168 |
} |
169 |
|
170 |
protected Control getTextWidget(){ |
171 |
return field3270; |
172 |
} |
173 |
|
174 |
protected int getTextCaretPosition(){ |
175 |
return field3270.getCaretOffset(); |
176 |
} |
177 |
|
178 |
protected int getTextCharCount(){ |
179 |
return field3270.getCharCount(); |
180 |
} |
181 |
|
182 |
protected String getText() { |
183 |
return field3270.getText(); |
184 |
} |
185 |
|
186 |
|
187 |
|
188 |
} |