View | Details | Raw Unified | Return to bug 298392 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/viewers/TextCellEditor.java (-14 / +67 lines)
Lines 46-52 Link Here
46
     */
46
     */
47
    protected Text text;
47
    protected Text text;
48
48
49
    private ModifyListener modifyListener;
49
    /**
50
     * 
51
     */
52
    protected ModifyListener modifyListener;
50
53
51
    /**
54
    /**
52
     * State information for updating action enablement
55
     * State information for updating action enablement
Lines 104-110 Link Here
104
     * nothing to delete) has changed and if so fire an
107
     * nothing to delete) has changed and if so fire an
105
     * enablement changed notification.
108
     * enablement changed notification.
106
     */
109
     */
107
    private void checkDeleteable() {
110
    protected void checkDeleteable() {
108
        boolean oldIsDeleteable = isDeleteable;
111
        boolean oldIsDeleteable = isDeleteable;
109
        isDeleteable = isDeleteEnabled();
112
        isDeleteable = isDeleteEnabled();
110
        if (oldIsDeleteable != isDeleteable) {
113
        if (oldIsDeleteable != isDeleteable) {
Lines 116-122 Link Here
116
     * Checks to see if the "selectable" state (can select)
119
     * Checks to see if the "selectable" state (can select)
117
     * has changed and if so fire an enablement changed notification.
120
     * has changed and if so fire an enablement changed notification.
118
     */
121
     */
119
    private void checkSelectable() {
122
    protected void checkSelectable() {
120
        boolean oldIsSelectable = isSelectable;
123
        boolean oldIsSelectable = isSelectable;
121
        isSelectable = isSelectAllEnabled();
124
        isSelectable = isSelectAllEnabled();
122
        if (oldIsSelectable != isSelectable) {
125
        if (oldIsSelectable != isSelectable) {
Lines 129-143 Link Here
129
     * no selection) has changed and if so fire an
132
     * no selection) has changed and if so fire an
130
     * enablement changed notification.
133
     * enablement changed notification.
131
     */
134
     */
132
    private void checkSelection() {
135
    protected void checkSelection() {
133
        boolean oldIsSelection = isSelection;
136
        boolean oldIsSelection = isSelection;
134
        isSelection = text.getSelectionCount() > 0;
137
        isSelection = getTextSelectionCount() > 0;
135
        if (oldIsSelection != isSelection) {
138
        if (oldIsSelection != isSelection) {
136
            fireEnablementChanged(COPY);
139
            fireEnablementChanged(COPY);
137
            fireEnablementChanged(CUT);
140
            fireEnablementChanged(CUT);
138
        }
141
        }
139
    }
142
    }
140
143
    /**
144
     * @return int
145
     */
146
    protected int getTextSelectionCount(){
147
    	return text.getSelectionCount();
148
    }
149
    
150
    /**
151
     * @return int
152
     */
153
    protected int getTextCaretPosition(){
154
    	return text.getCaretPosition();
155
    }
156
    
157
    /**
158
     * @return int
159
     */
160
    protected int getTextCharCount(){
161
    	return text.getCharCount();
162
    }
141
    /* (non-Javadoc)
163
    /* (non-Javadoc)
142
     * Method declared on CellEditor.
164
     * Method declared on CellEditor.
143
     */
165
     */
Lines 208-214 Link Here
208
     * Method declared on CellEditor.
230
     * Method declared on CellEditor.
209
     */
231
     */
210
    protected void doSetFocus() {
232
    protected void doSetFocus() {
211
        if (text != null) {
233
        if (getTextWidget() != null) {
212
            text.selectAll();
234
            text.selectAll();
213
            text.setFocus();
235
            text.setFocus();
214
            checkSelection();
236
            checkSelection();
Lines 241-247 Link Here
241
     * @param e the SWT modify event
263
     * @param e the SWT modify event
242
     */
264
     */
243
    protected void editOccured(ModifyEvent e) {
265
    protected void editOccured(ModifyEvent e) {
244
        String value = text.getText();
266
        String value = getText();
245
        if (value == null) {
267
        if (value == null) {
246
			value = "";//$NON-NLS-1$
268
			value = "";//$NON-NLS-1$
247
		}
269
		}
Lines 261-266 Link Here
261
    }
283
    }
262
284
263
    /**
285
    /**
286
	 * @return text value
287
	 */
288
	protected String getText() {
289
		return text.getText();
290
	}
291
292
	/**
264
     * Since a text editor field is scrollable we don't
293
     * Since a text editor field is scrollable we don't
265
     * set a minimumSize.
294
     * set a minimumSize.
266
     */
295
     */
Lines 272-279 Link Here
272
301
273
    /**
302
    /**
274
     * Return the modify listener.
303
     * Return the modify listener.
304
     * @return ModifyListener
275
     */
305
     */
276
    private ModifyListener getModifyListener() {
306
    protected ModifyListener getModifyListener() {
277
        if (modifyListener == null) {
307
        if (modifyListener == null) {
278
            modifyListener = new ModifyListener() {
308
            modifyListener = new ModifyListener() {
279
                public void modifyText(ModifyEvent e) {
309
                public void modifyText(ModifyEvent e) {
Lines 329-339 Link Here
329
     * at the end of the text.
359
     * at the end of the text.
330
     */
360
     */
331
    public boolean isDeleteEnabled() {
361
    public boolean isDeleteEnabled() {
332
        if (text == null || text.isDisposed()) {
362
        if (getTextWidget() == null || getTextWidget().isDisposed()) {
333
			return false;
363
			return false;
334
		}
364
		}
335
        return text.getSelectionCount() > 0
365
        return getTextSelectionCount() > 0
336
                || text.getCaretPosition() < text.getCharCount();
366
                || getTextCaretPosition() < getTextCharCount();
337
    }
367
    }
338
368
339
    /**
369
    /**
Lines 372-381 Link Here
372
     *  <code>false</code> otherwise
402
     *  <code>false</code> otherwise
373
     */
403
     */
374
    public boolean isSelectAllEnabled() {
404
    public boolean isSelectAllEnabled() {
375
        if (text == null || text.isDisposed()) {
405
        if (getTextWidget() == null || getTextWidget().isDisposed()) {
376
			return false;
406
			return false;
377
		}
407
		}
378
        return text.getCharCount() > 0;
408
        return getTextCharCount() > 0;
379
    }
409
    }
380
410
381
    /**
411
    /**
Lines 490-493 Link Here
490
	protected boolean dependsOnExternalFocusListener() {
520
	protected boolean dependsOnExternalFocusListener() {
491
		return getClass() != TextCellEditor.class;
521
		return getClass() != TextCellEditor.class;
492
	}
522
	}
523
	
524
	/**
525
	 * @return Control
526
	 */
527
	protected Control getTextWidget(){
528
		return text;
529
	}
530
	
531
	/**
532
	 * @return a
533
	 */
534
	protected boolean getIsSelection() {
535
		return isSelection;
536
	}
537
	/**
538
	 * @param b
539
	 */
540
	protected void setIsSelection(boolean b) {
541
		isSelection = b;
542
		
543
	}
544
	
545
493
}
546
}
(-)src/org/eclipse/jface/viewers/Field3270CellEditor.java (+188 lines)
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
}

Return to bug 298392