Skip to main content
summaryrefslogtreecommitdiffstats
blob: a4e1737c50257d2c8fbd00ee73ac7021ceaf2518 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*****************************************************************************
 * Copyright (c) 2008 CEA LIST.
 *
 *
 * All rights reserved. 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:
 *  Remi Schnekenburger (CEA LIST) Remi.Schnekenburger@cea.fr - Initial API and implementation
 *  Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 497289
 *
 *****************************************************************************/

package org.eclipse.papyrus.extensionpoints.editors.configuration;

import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;

/**
 * Default implementation for the {@link IDirectEditorConfiguration} interface.
 */
public class DefaultDirectEditorConfiguration implements IDirectEditorConfiguration {

	/** Default sourceViewer configuration */
	protected SourceViewerConfiguration sourceViewerConfiguration;

	/** language of the edited body */
	protected String language;

	/** To check if the configuration is available for each type. */
	protected boolean superType;

	/** objectToEdit */
	protected Object objectToEdit;

	/** input validator */
	protected IInputValidator validator;

	/**
	 * Returns the language of the edited body
	 *
	 * @return the language of the edited body
	 */
	public String getLanguage() {
		return language;
	}

	/**
	 * Sets the language of the edited body
	 *
	 * @param language
	 *            the language of the edited body
	 */
	public void setLanguage(String language) {
		this.language = language;
	}

	/**
	 * {@inheritDoc}
	 */
	public Point getPreferedSize() {
		return new Point(SWT.DEFAULT, SWT.DEFAULT);
	}

	/**
	 * {@inheritDoc}
	 */
	public SourceViewerConfiguration getSourceViewerConfiguration() {
		if (sourceViewerConfiguration == null) {
			sourceViewerConfiguration = new SourceViewerConfiguration();
		}
		return sourceViewerConfiguration;
	}

	/**
	 * {@inheritDoc}
	 */
	public int getStyle() {
		return SWT.BORDER | SWT.SINGLE;
	}

	/**
	 * {@inheritDoc}
	 */
	public String getTextToEdit(Object objectToEdit) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * {@inheritDoc}
	 */
	public Object postEditAction(Object objectToEdit, String newText) {
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public Object preEditAction(Object objectToEdit) {
		setObjectToEdit(objectToEdit);
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public Composite createExtendedDialogArea(Composite parent) {
		return null;
	}

	/**
	 * Returns the object to edit
	 *
	 * @return the object to edit
	 */
	public Object getObjectToEdit() {
		return objectToEdit;
	}

	/**
	 * Sets the object to edit
	 *
	 * @param objectToEdit
	 *            the object to edit
	 */
	public void setObjectToEdit(Object objectToEdit) {
		this.objectToEdit = objectToEdit;
	}

	/**
	 * {@inheritDoc}
	 */
	public IInputValidator getInputValidator() {
		if (validator == null) {
			validator = new IInputValidator() {

				public String isValid(String newText) {
					// always valid
					return null;
				}
			};
		}
		return validator;
	}

	/**
	 * {@inheritDoc}
	 */
	public void setInputValidator(IInputValidator validator) {
		this.validator = validator;
	}

	/**
	 * {@inheritDoc}
	 */
	public Selection getTextSelection(String value, Object editedObject) {
		return new Selection(0, value.length());
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean isSuperType() {
		return superType;
	}

	/**
	 * {@inheritDoc}
	 */
	public void setSuperType(boolean superType) {
		this.superType = superType;
	}
}

Back to the top