/*******************************************************************************
* Copyright (c) 2005, 2011 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.jdt.internal.ui.dialogs;
import org.eclipse.swt.SWT;
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.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
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.Text;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.contentassist.SubjectControlContentAssistant;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.ui.contentassist.ContentAssistHandler;
import org.eclipse.jdt.internal.corext.util.Messages;
import org.eclipse.jdt.internal.ui.refactoring.ChangeParametersControl;
import org.eclipse.jdt.internal.ui.refactoring.contentassist.ControlContentAssistHelper;
import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor;
/**
* TableTextCellEditor
is a copy of TextCellEditor, with the
* following changes:
*
*
TextCellEditor
implementation of
* this CellEditor
framework method returns
* the text string.
*
* @return the text string
*/
@Override
protected Object doGetValue() {
return text.getText();
}
@Override
protected void doSetFocus() {
if (text != null) {
text.selectAll();
text.setFocus();
checkSelection();
checkDeleteable();
checkSelectable();
}
}
/**
* The TextCellEditor2
implementation of
* this CellEditor
framework method accepts
* a text string (type String
).
*
* @param value a text string (type String
)
*/
@Override
protected void doSetValue(Object value) {
Assert.isTrue(text != null && (value instanceof String));
text.removeModifyListener(getModifyListener());
text.setText((String) value);
text.addModifyListener(getModifyListener());
}
/**
* Processes a modify event that occurred in this text cell editor.
* This framework method performs validation and sets the error message
* accordingly, and then reports a change via fireEditorValueChanged
.
* Subclasses should call this method at appropriate times. Subclasses
* may extend or reimplement.
*
* @param e the SWT modify event
*/
protected void editOccured(ModifyEvent e) {
String value = text.getText();
boolean oldValidState = isValueValid();
boolean newValidState = isCorrect(value);
if (!newValidState) {
// try to insert the current value into the error message.
setErrorMessage(Messages.format(getErrorMessage(),
new Object[] { value }));
}
valueChanged(oldValidState, newValidState);
fireModifyEvent(text.getText()); // update model on-the-fly
}
@Override
public LayoutData getLayoutData() {
return new LayoutData();
}
protected void handleDefaultSelection(SelectionEvent event) {
// same with enter-key handling code in keyReleaseOccured(e);
fireApplyEditorValue();
deactivate();
}
@Override
public boolean isCopyEnabled() {
if (text == null || text.isDisposed())
return false;
return text.getSelectionCount() > 0;
}
@Override
public boolean isCutEnabled() {
if (text == null || text.isDisposed())
return false;
return text.getSelectionCount() > 0;
}
@Override
public boolean isDeleteEnabled() {
if (text == null || text.isDisposed())
return false;
return text.getSelectionCount() > 0
|| text.getCaretPosition() < text.getCharCount();
}
@Override
public boolean isPasteEnabled() {
if (text == null || text.isDisposed())
return false;
return true;
}
@Override
public boolean isSelectAllEnabled() {
if (text == null || text.isDisposed())
return false;
return text.getCharCount() > 0;
}
@Override
protected void keyReleaseOccured(KeyEvent keyEvent) {
if (keyEvent.character == '\r') { // Return key
// Enter is handled in handleDefaultSelection.
// Do not apply the editor value in response to an Enter key event
// since this can be received from the IME when the intent is -not-
// to apply the value.
// See bug 39074 [CellEditors] [DBCS] canna input mode fires bogus event from Text Control
//
// An exception is made for Ctrl+Enter for multi-line texts, since
// a default selection event is not sent in this case.
if (text != null && !text.isDisposed()
&& (text.getStyle() & SWT.MULTI) != 0) {
if ((keyEvent.stateMask & SWT.CTRL) != 0) {
super.keyReleaseOccured(keyEvent);
}
}
return;
}
super.keyReleaseOccured(keyEvent);
}
@Override
public void performCopy() {
text.copy();
}
@Override
public void performCut() {
text.cut();
checkSelection();
checkDeleteable();
checkSelectable();
}
@Override
public void performDelete() {
if (text.getSelectionCount() > 0)
// remove the contents of the current selection
text.insert(""); //$NON-NLS-1$
else {
// remove the next character
int pos = text.getCaretPosition();
if (pos < text.getCharCount()) {
text.setSelection(pos, pos + 1);
text.insert(""); //$NON-NLS-1$
}
}
checkSelection();
checkDeleteable();
checkSelectable();
}
@Override
public void performPaste() {
text.paste();
checkSelection();
checkDeleteable();
checkSelectable();
}
@Override
public void performSelectAll() {
text.selectAll();
checkSelection();
checkDeleteable();
}
/*
* @see org.eclipse.jface.viewers.CellEditor#dependsOnExternalFocusListener()
*/
@Override
protected boolean dependsOnExternalFocusListener() {
return false;
}
public void generated_8020750380894542173(final TableViewer tableViewer, JavaTypeCompletionProcessor superInterfaceCompletionProcessor) {
SubjectControlContentAssistant contentAssistant= ControlContentAssistHelper.createJavaContentAssistant(superInterfaceCompletionProcessor);
Text cellEditorText= getText();
ContentAssistHandler.createHandlerForText(cellEditorText, contentAssistant);
TextFieldNavigationHandler.install(cellEditorText);
setContentAssistant(contentAssistant);
tableViewer.setCellEditors(new CellEditor[] { this });
}
public void generated_3875397303026142273(final int editorColumn, final ChangeParametersControl changeparameterscontrol) {
getText().addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
switch (e.detail) {
case SWT.TRAVERSE_TAB_NEXT :
changeparameterscontrol.editColumnOrNextPossible(changeparameterscontrol.nextColumn(editorColumn));
e.detail= SWT.TRAVERSE_NONE;
break;
case SWT.TRAVERSE_TAB_PREVIOUS :
changeparameterscontrol.editColumnOrPrevPossible(changeparameterscontrol.prevColumn(editorColumn));
e.detail= SWT.TRAVERSE_NONE;
break;
default :
break;
}
}
});
TextFieldNavigationHandler.install(getText());
}
}