1
/*******************************************************************************
2
* Copyright (C) 2003-2008, 2013, Guillaume Brocker
4
* All rights reserved. This program and the accompanying materials
5
* are made available under the terms of the Eclipse Public License v1.0
6
* which accompanies this distribution, and is available at
7
* http://www.eclipse.org/legal/epl-v10.html
10
* Guillaume Brocker - Initial API and implementation
12
******************************************************************************/
14
package eclox.ui.editor.editors;
16
import org.eclipse.swt.events.ModifyEvent;
17
import org.eclipse.swt.events.ModifyListener;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.layout.GridLayout;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Text;
22
import org.eclipse.ui.forms.widgets.FormToolkit;
25
* Implements a simple setting editor.
29
public class TextEditor extends SettingEditor {
32
* Defines a modify listener class.
34
private class TextModifyListener implements ModifyListener {
37
* Tells if the listener should sleep (ignore notifications).
39
public boolean sleeping = true;
41
public void modifyText(ModifyEvent e) {
42
if(sleeping == false) {
57
* The current modification listener of the text control
59
private TextModifyListener textModifyListener = new TextModifyListener();
62
* Remerbers if the text has changed.
64
private boolean hasChanged = false;
68
* @see eclox.ui.editor.editors.IEditor#commit()
70
public void commit() {
72
getInput().setValue( text.getText() );
79
* @see eclox.ui.editor.editors.IEditor#createContent(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit)
81
public void createContent( Composite parent, FormToolkit formToolkit ) {
82
// Activates border painting.
83
formToolkit.paintBordersFor( parent );
85
// Prepere the parent's layout.
86
GridLayout layout = new GridLayout();
88
layout.marginLeft = 0;
89
layout.marginBottom = 0;
90
layout.marginRight = 0;
91
layout.marginHeight = 2;
92
layout.marginWidth = 1;
93
layout.horizontalSpacing = 5;
94
parent.setLayout( layout );
96
// Creates the text widget.
97
text = formToolkit.createText(parent, new String());
98
text.setLayoutData( new GridData(GridData.FILL_HORIZONTAL|GridData.VERTICAL_ALIGN_CENTER) );
99
text.addModifyListener( textModifyListener );
103
* @see eclox.ui.editor.editors.IEditor#grabVerticalSpace()
105
public boolean grabVerticalSpace() {
110
* @see eclox.ui.editor.editors.IEditor#dispose()
112
public void dispose() {
117
* @see eclox.ui.editor.editors.IEditor#isDirty()
119
public boolean isDirty() {
124
* @see eclox.ui.editor.editors.IEditor#isStale()
126
public boolean isStale() {
127
boolean result = false;
130
result = text.getText().equals( getInput().getValue() ) == false;
136
* @see eclox.ui.editor.editors.IEditor#refresh()
138
public void refresh() {
140
textModifyListener.sleeping = true;
141
text.setText( getInput().getValue() );
143
textModifyListener.sleeping = false;
149
* @see eclox.ui.editor.editors.IEditor#setEnabled(boolean)
151
public void setEnabled(boolean enabled) {
155
text.setEnabled(enabled);
159
* @see eclox.ui.editor.editors.IEditor#setFocus()
161
public void setFocus() {
167
* @see eclox.ui.editor.editors.SettingEditor#setInput(eclox.core.doxyfiles.Setting)
169
// public void setInput(Setting input) {
170
// super.setInput(input);
172
// if( hasInput() ) {
173
// textModifyListener.sleeping = true;
174
// text.setText(input.getValue());
175
// textModifyListener.sleeping = false;
176
// hasChanged = false;