### Eclipse Workspace Patch 1.0
#P org.eclipse.jface
Index: src/org/eclipse/jface/viewers/TextCellEditor.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/TextCellEditor.java,v
retrieving revision 1.31
diff -u -r1.31 TextCellEditor.java
--- src/org/eclipse/jface/viewers/TextCellEditor.java 24 Nov 2009 20:54:09 -0000 1.31
+++ src/org/eclipse/jface/viewers/TextCellEditor.java 3 Feb 2010 11:35:02 -0000
@@ -46,7 +46,10 @@
*/
protected Text text;
- private ModifyListener modifyListener;
+ /**
+ *
+ */
+ protected ModifyListener modifyListener;
/**
* State information for updating action enablement
@@ -104,7 +107,7 @@
* nothing to delete) has changed and if so fire an
* enablement changed notification.
*/
- private void checkDeleteable() {
+ protected void checkDeleteable() {
boolean oldIsDeleteable = isDeleteable;
isDeleteable = isDeleteEnabled();
if (oldIsDeleteable != isDeleteable) {
@@ -116,7 +119,7 @@
* Checks to see if the "selectable" state (can select)
* has changed and if so fire an enablement changed notification.
*/
- private void checkSelectable() {
+ protected void checkSelectable() {
boolean oldIsSelectable = isSelectable;
isSelectable = isSelectAllEnabled();
if (oldIsSelectable != isSelectable) {
@@ -129,15 +132,34 @@
* no selection) has changed and if so fire an
* enablement changed notification.
*/
- private void checkSelection() {
+ protected void checkSelection() {
boolean oldIsSelection = isSelection;
- isSelection = text.getSelectionCount() > 0;
+ isSelection = getTextSelectionCount() > 0;
if (oldIsSelection != isSelection) {
fireEnablementChanged(COPY);
fireEnablementChanged(CUT);
}
}
-
+ /**
+ * @return int
+ */
+ protected int getTextSelectionCount(){
+ return text.getSelectionCount();
+ }
+
+ /**
+ * @return int
+ */
+ protected int getTextCaretPosition(){
+ return text.getCaretPosition();
+ }
+
+ /**
+ * @return int
+ */
+ protected int getTextCharCount(){
+ return text.getCharCount();
+ }
/* (non-Javadoc)
* Method declared on CellEditor.
*/
@@ -208,7 +230,7 @@
* Method declared on CellEditor.
*/
protected void doSetFocus() {
- if (text != null) {
+ if (getTextWidget() != null) {
text.selectAll();
text.setFocus();
checkSelection();
@@ -241,7 +263,7 @@
* @param e the SWT modify event
*/
protected void editOccured(ModifyEvent e) {
- String value = text.getText();
+ String value = getText();
if (value == null) {
value = "";//$NON-NLS-1$
}
@@ -261,6 +283,13 @@
}
/**
+ * @return text value
+ */
+ protected String getText() {
+ return text.getText();
+ }
+
+ /**
* Since a text editor field is scrollable we don't
* set a minimumSize.
*/
@@ -272,8 +301,9 @@
/**
* Return the modify listener.
+ * @return ModifyListener
*/
- private ModifyListener getModifyListener() {
+ protected ModifyListener getModifyListener() {
if (modifyListener == null) {
modifyListener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
@@ -329,11 +359,11 @@
* at the end of the text.
*/
public boolean isDeleteEnabled() {
- if (text == null || text.isDisposed()) {
+ if (getTextWidget() == null || getTextWidget().isDisposed()) {
return false;
}
- return text.getSelectionCount() > 0
- || text.getCaretPosition() < text.getCharCount();
+ return getTextSelectionCount() > 0
+ || getTextCaretPosition() < getTextCharCount();
}
/**
@@ -372,10 +402,10 @@
* false
otherwise
*/
public boolean isSelectAllEnabled() {
- if (text == null || text.isDisposed()) {
+ if (getTextWidget() == null || getTextWidget().isDisposed()) {
return false;
}
- return text.getCharCount() > 0;
+ return getTextCharCount() > 0;
}
/**
@@ -490,4 +520,27 @@
protected boolean dependsOnExternalFocusListener() {
return getClass() != TextCellEditor.class;
}
+
+ /**
+ * @return Control
+ */
+ protected Control getTextWidget(){
+ return text;
+ }
+
+ /**
+ * @return a
+ */
+ protected boolean getIsSelection() {
+ return isSelection;
+ }
+ /**
+ * @param b
+ */
+ protected void setIsSelection(boolean b) {
+ isSelection = b;
+
+ }
+
+
}
Index: src/org/eclipse/jface/viewers/Field3270CellEditor.java
===================================================================
RCS file: src/org/eclipse/jface/viewers/Field3270CellEditor.java
diff -N src/org/eclipse/jface/viewers/Field3270CellEditor.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/jface/viewers/Field3270CellEditor.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jface.viewers;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.Field3270;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * A cell editor that manages a text entry field.
+ * The cell editor's value is the text string itself.
+ * The class is used when JDBC connection is of 3270 type
+ * (one of the optional properties of JDBC connection
+ * should be: 3270_FIELD_SUPPORT=true)
+ */
+public class Field3270CellEditor extends TextCellEditor {
+ /*
+ * The Field3270 control; initially null
.
+ */
+ private Field3270 field3270;
+
+ /**
+ * Creates a new Field3279 string cell editor with no control
+ * The cell editor value is the string itself, which is initially the empty
+ * string.
+ */
+ public Field3270CellEditor() {
+ super();
+ }
+
+ /**
+ * Creates a new Field3279 string cell editor with no control
+ * The cell editor value is the string itself, which is initially the empty
+ * string.
+ * @param parent
+ */
+ public Field3270CellEditor(Composite parent) {
+ super(parent);
+ }
+
+ /**
+ * Creates a new Field3270 string cell editor with no control
+ * The cell editor value is the string itself, which is initially the empty
+ * string.
+ * @param parent
+ * @param style
+ */
+ public Field3270CellEditor(Composite parent, int style) {
+ super(parent, style);
+ }
+
+ protected Control createControl(Composite parent) {
+ field3270 = new Field3270(parent, getStyle());
+ field3270.setArrOfIgnoredChars(new char[] {'\t'});
+ field3270.addSelectionListener(new SelectionAdapter() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ handleDefaultSelection(e);
+ }
+ });
+ field3270.addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent e) {
+ keyReleaseOccured(e);
+ if ((getControl() == null) || getControl().isDisposed()) {
+ return;
+ }
+ checkSelection();
+ checkDeleteable();
+ checkSelectable();
+ if (e.character == '\r') { // Return key
+ Event event = new Event();
+ event.widget = e.widget;
+ event.stateMask = e.stateMask;
+ event.doit = e.doit;
+
+ SelectionEvent selectionEvent = new SelectionEvent(event);
+ handleDefaultSelection(selectionEvent);
+ }
+ }
+ });
+ field3270.getStyledText().addTraverseListener(new TraverseListener() {
+ public void keyTraversed(TraverseEvent e) {
+ if (e.detail == SWT.TRAVERSE_ESCAPE
+ || e.detail == SWT.TRAVERSE_RETURN) {
+ e.doit = false;
+ }
+
+ }
+ });
+
+ field3270.addMouseListener(new MouseAdapter() {
+ public void mouseUp(MouseEvent e) {
+ checkSelection();
+ checkDeleteable();
+ checkSelectable();
+ }
+ });
+ field3270.addFocusListener(new FocusAdapter() {
+ public void focusLost(FocusEvent e) {
+ Field3270CellEditor.this.focusLost();
+ }
+ });
+ field3270.setFont(parent.getFont());
+ field3270.setBackground(parent.getBackground());
+ field3270.setText("");//$NON-NLS-1$
+ field3270.addModifyListener(getModifyListener());
+ return field3270.getStyledText();
+ }
+
+ protected Object doGetValue() {
+
+ String returnStr;
+ if (field3270.isWidgetReversed() ^ field3270.isPushMode())
+ returnStr = Field3270.reverseStr(field3270.getText());
+ else
+ returnStr = field3270.getText();
+ if (field3270.isPushMode())
+ field3270.setPush(false);
+ return returnStr;
+ }
+
+ protected void doSetValue(Object value) {
+ Assert.isTrue(field3270 != null && field3270.getStyledText() != null && (value instanceof String));
+ field3270.removeModifyListener(getModifyListener());
+ String bidiValue;
+ if (field3270.isWidgetReversed() ^ field3270.isPushMode())
+ bidiValue = Field3270.reverseStr((String) value);
+ else
+ bidiValue = (String) value;
+ field3270.setText(bidiValue);
+
+ field3270.addModifyListener(getModifyListener());
+ }
+ protected void doSetFocus() {
+ if ((field3270 != null) && (field3270.getStyledText() != null)) {
+ field3270.selectAll();
+ field3270.getStyledText().setFocus();
+ checkSelection();
+ checkDeleteable();
+ checkSelectable();
+ }
+ }
+
+
+ protected int getTextSelectionCount(){
+ return field3270.getSelectionCount();
+ }
+
+ protected Control getTextWidget(){
+ return field3270;
+ }
+
+ protected int getTextCaretPosition(){
+ return field3270.getCaretOffset();
+ }
+
+ protected int getTextCharCount(){
+ return field3270.getCharCount();
+ }
+
+ protected String getText() {
+ return field3270.getText();
+ }
+
+
+
+}