blob: 78610e928b8503b17df4a73531a91a8dfaaa7b02 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/*
* Copyright (c) 2013 Eike Stepper (Berlin, Germany) 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:
* Christian W. Damus (CEA LIST) - initial API and implementation
*/
package org.eclipse.emf.cdo.security.internal.ui.util;
import org.eclipse.jface.viewers.DialogCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import java.text.MessageFormat;
/**
* A dialog cell editor in which the text field is editable: the user
* can directly edit the value without opening the dialog.
*
* @author Christian W. Damus (CEA LIST)
*/
public abstract class EditableDialogCellEditor extends DialogCellEditor
{
private Text text;
public EditableDialogCellEditor()
{
}
public EditableDialogCellEditor(Composite parent)
{
super(parent);
}
public EditableDialogCellEditor(Composite parent, int style)
{
super(parent, style);
}
@Override
protected Control createContents(Composite cell)
{
text = new Text(cell, SWT.SINGLE);
text.setFont(cell.getFont());
text.setBackground(cell.getBackground());
text.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetDefaultSelected(SelectionEvent e)
{
String newValue = text.getText();
if (isCorrect(newValue))
{
markDirty();
doSetValue(newValue);
}
else
{
setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] { newValue.toString() }));
}
fireApplyEditorValue();
deactivate();
}
});
return text;
}
@Override
protected void updateContents(Object value)
{
text.setText(value == null ? "" : value.toString()); //$NON-NLS-1$
}
@Override
public void setFocus()
{
text.setFocus();
}
}
|