-
Notifications
You must be signed in to change notification settings - Fork 96
/
PTBaseTextEditor.java
93 lines (77 loc) · 2.86 KB
/
PTBaseTextEditor.java
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
92
93
/*******************************************************************************
* Copyright (c) 2012 Laurent CARON
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: Laurent CARON (laurent.caron at gmail dot com) - initial API
* and implementation
*******************************************************************************/
package org.eclipse.nebula.widgets.opal.propertytable.editor;
import org.eclipse.nebula.widgets.opal.commons.StringUtil;
import org.eclipse.nebula.widgets.opal.propertytable.PTProperty;
import org.eclipse.nebula.widgets.opal.propertytable.PTWidget;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ControlEditor;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
/**
* This abstract class represents all text-based editors (float editor, integer
* editor, password editor, String editor, URL editor)
*
*/
public abstract class PTBaseTextEditor extends PTEditor {
protected Text text;
/**
* @see org.eclipse.nebula.widgets.opal.propertytable.editor.PTEditor#render(org.eclipse.nebula.widgets.opal.propertytable.PTWidget,
* org.eclipse.swt.widgets.Item, org.eclipse.nebula.widgets.opal.propertytable.PTProperty)
*/
@Override
public ControlEditor render(final PTWidget widget, final Item item, final PTProperty property) {
ControlEditor editor;
if (widget.getWidget() instanceof Table) {
editor = new TableEditor((Table) widget.getWidget());
} else {
editor = new TreeEditor((Tree) widget.getWidget());
}
widget.updateDescriptionPanel(property);
text = new Text(widget.getWidget(), getStyle());
addVerifyListeners();
text.setText(StringUtil.safeToString(property.getValue()));
text.addListener(SWT.Modify, event -> {
property.setValue(convertValue());
});
text.addListener(SWT.FocusIn, event -> {
widget.updateDescriptionPanel(property);
});
editor.grabHorizontal = true;
if (widget.getWidget() instanceof Table) {
((TableEditor) editor).setEditor(text, (TableItem) item, 1);
} else {
((TreeEditor) editor).setEditor(text, (TreeItem) item, 1);
}
text.setEnabled(property.isEnabled());
return editor;
}
/**
* Add the verify listeners
*/
public abstract void addVerifyListeners();
/**
* @return the value of the data typed by the user in the correct format
*/
public abstract Object convertValue();
/**
* @return the style (SWT.NONE or SWT.PASSWORD)
*/
public abstract int getStyle();
}