Revision a172dbf0
Added by Katja Luther almost 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/RichTextWithLabelElement.java | ||
---|---|---|
8 | 8 |
import org.eclipse.jface.dialogs.MessageDialog; |
9 | 9 |
import org.eclipse.jface.layout.GridDataFactory; |
10 | 10 |
import org.eclipse.jface.viewers.CellEditor.LayoutData; |
11 |
import org.eclipse.nebula.widgets.richtext.RichTextEditor; |
|
12 |
import org.eclipse.nebula.widgets.richtext.RichTextEditorConfiguration; |
|
13 |
import org.eclipse.nebula.widgets.richtext.toolbar.ToolbarButton; |
|
14 |
import org.eclipse.nebula.widgets.richtext.toolbar.ToolbarConfiguration; |
|
11 |
//import org.eclipse.nebula.widgets.richtext.RichTextEditor;
|
|
12 |
//import org.eclipse.nebula.widgets.richtext.RichTextEditorConfiguration;
|
|
13 |
//import org.eclipse.nebula.widgets.richtext.toolbar.ToolbarButton;
|
|
14 |
//import org.eclipse.nebula.widgets.richtext.toolbar.ToolbarConfiguration;
|
|
15 | 15 |
import org.eclipse.swt.SWT; |
16 | 16 |
import org.eclipse.swt.events.KeyAdapter; |
17 | 17 |
import org.eclipse.swt.events.KeyEvent; |
... | ... | |
38 | 38 |
* @author n.hoffmann |
39 | 39 |
* @version $Id: $ |
40 | 40 |
*/ |
41 |
public class RichTextWithLabelElement extends AbstractCdmFormElement implements ModifyListener, IEnableableFormElement,
|
|
42 |
ISelectable { |
|
41 |
public class RichTextWithLabelElement{ //extends AbstractCdmFormElement implements ModifyListener, IEnableableFormElement,
|
|
42 |
// ISelectable {
|
|
43 | 43 |
|
44 | 44 |
|
45 |
protected RichTextEditor richtextEditor; |
|
45 |
//protected RichTextEditor richtextEditor;
|
|
46 | 46 |
private Label label; |
47 | 47 |
private boolean buttonVisible = true; |
48 | 48 |
|
... | ... | |
52 | 52 |
public static final int SINGLE = -1; |
53 | 53 |
|
54 | 54 |
protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, boolean isMultiLine) { |
55 |
super(formFactory, parentElement); |
|
55 |
// super(formFactory, parentElement);
|
|
56 | 56 |
this.isMultiLine = isMultiLine; |
57 | 57 |
} |
58 | 58 |
|
... | ... | |
73 | 73 |
|
74 | 74 |
protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString, |
75 | 75 |
String initialText, Integer textHeight, Integer textLimit, boolean isMultiLine, int style) { |
76 |
super(formFactory, parentElement); |
|
76 |
// super(formFactory, parentElement);
|
|
77 | 77 |
|
78 | 78 |
this.isMultiLine = isMultiLine; |
79 | 79 |
|
80 | 80 |
// initLabel(formFactory, labelString, isMultiLine, getLayoutComposite()); |
81 | 81 |
|
82 |
initText( initialText, textHeight, textLimit, isMultiLine, style, getLayoutComposite()); |
|
82 |
// initText( initialText, textHeight, textLimit, isMultiLine, style, getLayoutComposite());
|
|
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
protected void initText(String initialText, Integer textHeight, Integer textLimit, |
... | ... | |
87 | 87 |
layoutComposite.setLayout(new GridLayout(1, true)); |
88 | 88 |
|
89 | 89 |
|
90 |
ToolbarConfiguration toolBarConfig = new ToolbarConfiguration(); |
|
91 |
|
|
92 |
RichTextEditorConfiguration config = new RichTextEditorConfiguration(); |
|
93 |
config.setMinSize(800, 600); |
|
94 |
|
|
95 |
final RichTextEditor editor = new RichTextEditor(layoutComposite, config); |
|
96 |
GridDataFactory.fillDefaults().grab(true, true).applyTo(editor); |
|
97 |
//editor.setText(initialText); |
|
98 |
//editor.setEditable(true); |
|
90 |
// ToolbarConfiguration toolBarConfig = new ToolbarConfiguration();
|
|
91 |
// |
|
92 |
// RichTextEditorConfiguration config = new RichTextEditorConfiguration();
|
|
93 |
// config.setMinSize(800, 600);
|
|
94 |
// |
|
95 |
// final RichTextEditor editor = new RichTextEditor(layoutComposite, config);
|
|
96 |
// GridDataFactory.fillDefaults().grab(true, true).applyTo(editor);
|
|
97 |
// //editor.setText(initialText);
|
|
98 |
// //editor.setEditable(true);
|
|
99 | 99 |
|
100 | 100 |
final Text htmlOutput = new Text(layoutComposite, |
101 | 101 |
SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY); |
... | ... | |
104 | 104 |
|
105 | 105 |
|
106 | 106 |
|
107 |
editor.addModifyListener(new ModifyListener() { |
|
108 |
|
|
109 |
@Override |
|
110 |
public void modifyText(ModifyEvent e) { |
|
111 |
org.eclipse.swt.graphics.Point point = htmlOutput.getSelection(); |
|
112 |
htmlOutput.setText(htmlOutput.getText() + " - " + point.x + ":"+point.y); |
|
113 |
} |
|
114 |
}); |
|
115 |
|
|
116 |
editor.addKeyListener(new KeyAdapter() { |
|
107 |
// editor.addModifyListener(new ModifyListener() { |
|
108 |
// |
|
109 |
// @Override |
|
110 |
// public void modifyText(ModifyEvent e) { |
|
111 |
// org.eclipse.swt.graphics.Point point = htmlOutput.getSelection(); |
|
112 |
// htmlOutput.setText(htmlOutput.getText() + " - " + point.x + ":"+point.y); |
|
113 |
// } |
|
114 |
// }); |
|
117 | 115 |
|
118 |
@Override |
|
119 |
public void keyPressed(KeyEvent e) { |
|
120 |
org.eclipse.swt.graphics.Point point = htmlOutput.getSelection(); |
|
121 |
htmlOutput.setText(htmlOutput.getText() + " - " + point.x + ":"+point.y); |
|
122 |
|
|
123 |
} |
|
124 |
}); |
|
116 |
// editor.addKeyListener(new KeyAdapter() { |
|
117 |
// |
|
118 |
// @Override |
|
119 |
// public void keyPressed(KeyEvent e) { |
|
120 |
// org.eclipse.swt.graphics.Point point = htmlOutput.getSelection(); |
|
121 |
// htmlOutput.setText(htmlOutput.getText() + " - " + point.x + ":"+point.y); |
|
122 |
// |
|
123 |
// } |
|
124 |
// }); |
|
125 | 125 |
|
126 | 126 |
// editor.addToolbarButton(new ToolbarButton("jsButton", |
127 | 127 |
// "myScriptCommand", "Execute Javascript", "other,0", |
... | ... | |
134 | 134 |
|
135 | 135 |
// add additional controls for showing interactions |
136 | 136 |
|
137 |
createControlPanel(layoutComposite, editor, textHeight); |
|
137 |
// createControlPanel(layoutComposite, editor, textHeight);
|
|
138 | 138 |
|
139 | 139 |
} |
140 | 140 |
|
141 |
protected void createControlPanel(Composite parent, final RichTextEditor editor, int textHeight) { |
|
142 |
Composite controlPanel = new Composite(parent, SWT.NONE); |
|
143 |
TableWrapLayout layout; |
|
144 |
layout = LayoutConstants.LAYOUT(3, false); |
|
145 |
controlPanel.setLayout(layout); |
|
146 |
GridDataFactory.fillDefaults().grab(true, false).applyTo(controlPanel); |
|
147 |
|
|
148 |
Label inputLabel = new Label(controlPanel, SWT.NONE); |
|
149 |
inputLabel.setText("Text to set:"); |
|
150 |
// GridDataFactory.fillDefaults().applyTo(inputLabel); |
|
151 |
|
|
152 |
Text input = new Text(controlPanel, SWT.BORDER); |
|
153 |
TableWrapData layoutData; |
|
154 |
if(isMultiLine){ |
|
155 |
layoutData = LayoutConstants.FILL_HORIZONTALLY(2, 1); |
|
156 |
} |
|
157 |
else{ |
|
158 |
layoutData = LayoutConstants.FILL(); |
|
159 |
} |
|
160 |
input.setLayoutData(layoutData); |
|
161 |
// GridDataFactory.fillDefaults().grab(true, false).applyTo(input); |
|
162 |
|
|
163 |
input.addKeyListener(new KeyAdapter() { |
|
164 |
@Override |
|
165 |
public void keyPressed(KeyEvent e) { |
|
166 |
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { |
|
167 |
editor.setText(input.getText()); |
|
168 |
} |
|
169 |
} |
|
170 |
}); |
|
171 |
|
|
172 |
Button setButton = new Button(controlPanel, SWT.PUSH); |
|
173 |
setButton.setText("Set Text"); |
|
174 |
// GridDataFactory.defaultsFor(setButton).applyTo(setButton); |
|
175 |
|
|
176 |
setButton.addSelectionListener(new SelectionAdapter() { |
|
177 |
@Override |
|
178 |
public void widgetSelected(SelectionEvent e) { |
|
179 |
editor.setText(input.getText()); |
|
180 |
} |
|
181 |
}); |
|
182 |
|
|
183 |
Composite buttonPanel = new Composite(controlPanel, SWT.NONE); |
|
184 |
buttonPanel.setLayout(new RowLayout()); |
|
185 |
// GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(buttonPanel); |
|
186 |
|
|
187 |
Button getButton = new Button(buttonPanel, SWT.PUSH); |
|
188 |
getButton.setText("Get text"); |
|
189 |
getButton.addSelectionListener(new SelectionAdapter() { |
|
190 |
@Override |
|
191 |
public void widgetSelected(SelectionEvent e) { |
|
192 |
MessageDialog.openInformation(null, "Editor Input", |
|
193 |
editor.getText()); |
|
194 |
} |
|
195 |
}); |
|
196 |
|
|
197 |
final Button enableButton = new Button(buttonPanel, SWT.PUSH); |
|
198 |
enableButton.setText("Disable"); |
|
199 |
enableButton.addSelectionListener(new SelectionAdapter() { |
|
200 |
@Override |
|
201 |
public void widgetSelected(SelectionEvent e) { |
|
202 |
boolean editable = editor.isEditable(); |
|
203 |
editor.setEditable(!editable); |
|
204 |
|
|
205 |
enableButton.setText(editable ? "Enable" : "Disable"); |
|
206 |
} |
|
207 |
}); |
|
208 |
|
|
209 |
final Button updateButton = new Button(buttonPanel, SWT.PUSH); |
|
210 |
updateButton.setText("Update Toolbar"); |
|
211 |
|
|
212 |
final ToolbarButton button = new ToolbarButton("javaButton", |
|
213 |
"myJavaCommand", "Execute Java", "other", |
|
214 |
null) { |
|
215 |
|
|
216 |
@Override |
|
217 |
public Object execute() { |
|
218 |
MessageDialog.openInformation(null, "Information", |
|
219 |
"Java callback: " + editor.getSelectedHTML()); |
|
220 |
|
|
221 |
editor.insertHTML("<em>" + editor.getSelectedHTML() + "</em>"); |
|
222 |
return null; |
|
223 |
} |
|
224 |
}; |
|
225 |
|
|
226 |
updateButton.addSelectionListener(new SelectionAdapter() { |
|
227 |
@Override |
|
228 |
public void widgetSelected(SelectionEvent e) { |
|
229 |
if (!buttonVisible) { |
|
230 |
editor.addToolbarButton(button); |
|
231 |
} else { |
|
232 |
editor.removeToolbarButton(button); |
|
233 |
} |
|
234 |
buttonVisible = !buttonVisible; |
|
235 |
editor.updateToolbar(); |
|
236 |
} |
|
237 |
}); |
|
238 |
|
|
239 |
Button setFocusButton = new Button(buttonPanel, SWT.PUSH); |
|
240 |
setFocusButton.setText("Set Focus"); |
|
241 |
setFocusButton.addSelectionListener(new SelectionAdapter() { |
|
242 |
@Override |
|
243 |
public void widgetSelected(SelectionEvent e) { |
|
244 |
editor.setFocus(); |
|
245 |
} |
|
246 |
}); |
|
247 |
|
|
248 |
} |
|
249 |
|
|
250 |
protected void initLabel(CdmFormFactory formFactory, String labelString, boolean isMultiLine, Composite layoutComposite) { |
|
251 |
if (labelString != null) { |
|
252 |
label = formFactory.createLabel(layoutComposite, CdmUtils.Nz(labelString), SWT.NULL); |
|
253 |
addControl(label); |
|
254 |
if(isMultiLine){ |
|
255 |
label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1)); |
|
256 |
((TableWrapData)label.getLayoutData()).valign = TableWrapData.MIDDLE; |
|
257 |
} |
|
258 |
else{ |
|
259 |
label.setLayoutData(LayoutConstants.LEFT()); |
|
260 |
((TableWrapData)label.getLayoutData()).valign = TableWrapData.MIDDLE; |
|
261 |
} |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
/** {@inheritDoc} */ |
|
269 |
@Override |
|
270 |
public void setBackground(Color color) { |
|
271 |
if (label != null) { |
|
272 |
label.setBackground(color); |
|
273 |
} |
|
274 |
} |
|
275 |
|
|
276 |
@Override |
|
277 |
public void setSelected(boolean selected) { |
|
278 |
setBackground(selected ? SELECTED : getPersistentBackground()); |
|
279 |
} |
|
280 |
|
|
281 |
@Override |
|
282 |
public void setIrrelevant(boolean irrelevant) { |
|
283 |
// TODO Auto-generated method stub |
|
284 |
|
|
285 |
} |
|
286 |
|
|
287 |
@Override |
|
288 |
public void setEnabled(boolean enabled) { |
|
289 |
// TODO Auto-generated method stub |
|
290 |
|
|
291 |
} |
|
292 |
|
|
293 |
@Override |
|
294 |
public boolean isEnabled() { |
|
295 |
// TODO Auto-generated method stub |
|
296 |
return false; |
|
297 |
} |
|
298 |
|
|
299 |
@Override |
|
300 |
public void modifyText(ModifyEvent e) { |
|
301 |
// TODO Auto-generated method stub |
|
302 |
|
|
303 |
} |
|
141 |
// protected void createControlPanel(Composite parent, final RichTextEditor editor, int textHeight) {
|
|
142 |
// Composite controlPanel = new Composite(parent, SWT.NONE);
|
|
143 |
// TableWrapLayout layout;
|
|
144 |
// layout = LayoutConstants.LAYOUT(3, false);
|
|
145 |
// controlPanel.setLayout(layout);
|
|
146 |
// GridDataFactory.fillDefaults().grab(true, false).applyTo(controlPanel);
|
|
147 |
// |
|
148 |
// Label inputLabel = new Label(controlPanel, SWT.NONE);
|
|
149 |
// inputLabel.setText("Text to set:");
|
|
150 |
// // GridDataFactory.fillDefaults().applyTo(inputLabel);
|
|
151 |
// |
|
152 |
// Text input = new Text(controlPanel, SWT.BORDER);
|
|
153 |
// TableWrapData layoutData;
|
|
154 |
// if(isMultiLine){
|
|
155 |
// layoutData = LayoutConstants.FILL_HORIZONTALLY(2, 1);
|
|
156 |
// }
|
|
157 |
// else{
|
|
158 |
// layoutData = LayoutConstants.FILL();
|
|
159 |
// }
|
|
160 |
// input.setLayoutData(layoutData);
|
|
161 |
// // GridDataFactory.fillDefaults().grab(true, false).applyTo(input);
|
|
162 |
// |
|
163 |
// input.addKeyListener(new KeyAdapter() {
|
|
164 |
// @Override
|
|
165 |
// public void keyPressed(KeyEvent e) {
|
|
166 |
// if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
|
|
167 |
// editor.setText(input.getText());
|
|
168 |
// }
|
|
169 |
// }
|
|
170 |
// });
|
|
171 |
// |
|
172 |
// Button setButton = new Button(controlPanel, SWT.PUSH);
|
|
173 |
// setButton.setText("Set Text");
|
|
174 |
// // GridDataFactory.defaultsFor(setButton).applyTo(setButton);
|
|
175 |
// |
|
176 |
// setButton.addSelectionListener(new SelectionAdapter() {
|
|
177 |
// @Override
|
|
178 |
// public void widgetSelected(SelectionEvent e) {
|
|
179 |
// editor.setText(input.getText());
|
|
180 |
// }
|
|
181 |
// });
|
|
182 |
// |
|
183 |
// Composite buttonPanel = new Composite(controlPanel, SWT.NONE);
|
|
184 |
// buttonPanel.setLayout(new RowLayout());
|
|
185 |
// // GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(buttonPanel);
|
|
186 |
// |
|
187 |
// Button getButton = new Button(buttonPanel, SWT.PUSH);
|
|
188 |
// getButton.setText("Get text");
|
|
189 |
// getButton.addSelectionListener(new SelectionAdapter() {
|
|
190 |
// @Override
|
|
191 |
// public void widgetSelected(SelectionEvent e) {
|
|
192 |
// MessageDialog.openInformation(null, "Editor Input",
|
|
193 |
// editor.getText());
|
|
194 |
// }
|
|
195 |
// });
|
|
196 |
// |
|
197 |
// final Button enableButton = new Button(buttonPanel, SWT.PUSH);
|
|
198 |
// enableButton.setText("Disable");
|
|
199 |
// enableButton.addSelectionListener(new SelectionAdapter() {
|
|
200 |
// @Override
|
|
201 |
// public void widgetSelected(SelectionEvent e) {
|
|
202 |
// boolean editable = editor.isEditable();
|
|
203 |
// editor.setEditable(!editable);
|
|
204 |
// |
|
205 |
// enableButton.setText(editable ? "Enable" : "Disable");
|
|
206 |
// }
|
|
207 |
// });
|
|
208 |
// |
|
209 |
// final Button updateButton = new Button(buttonPanel, SWT.PUSH);
|
|
210 |
// updateButton.setText("Update Toolbar");
|
|
211 |
// |
|
212 |
// final ToolbarButton button = new ToolbarButton("javaButton",
|
|
213 |
// "myJavaCommand", "Execute Java", "other",
|
|
214 |
// null) {
|
|
215 |
// |
|
216 |
// @Override
|
|
217 |
// public Object execute() {
|
|
218 |
// MessageDialog.openInformation(null, "Information",
|
|
219 |
// "Java callback: " + editor.getSelectedHTML());
|
|
220 |
// |
|
221 |
// editor.insertHTML("<em>" + editor.getSelectedHTML() + "</em>");
|
|
222 |
// return null;
|
|
223 |
// }
|
|
224 |
// };
|
|
225 |
// |
|
226 |
// updateButton.addSelectionListener(new SelectionAdapter() {
|
|
227 |
// @Override
|
|
228 |
// public void widgetSelected(SelectionEvent e) {
|
|
229 |
// if (!buttonVisible) {
|
|
230 |
// editor.addToolbarButton(button);
|
|
231 |
// } else {
|
|
232 |
// editor.removeToolbarButton(button);
|
|
233 |
// }
|
|
234 |
// buttonVisible = !buttonVisible;
|
|
235 |
// editor.updateToolbar();
|
|
236 |
// }
|
|
237 |
// });
|
|
238 |
// |
|
239 |
// Button setFocusButton = new Button(buttonPanel, SWT.PUSH);
|
|
240 |
// setFocusButton.setText("Set Focus");
|
|
241 |
// setFocusButton.addSelectionListener(new SelectionAdapter() {
|
|
242 |
// @Override
|
|
243 |
// public void widgetSelected(SelectionEvent e) {
|
|
244 |
// editor.setFocus();
|
|
245 |
// }
|
|
246 |
// });
|
|
247 |
// |
|
248 |
// }
|
|
249 |
// |
|
250 |
// protected void initLabel(CdmFormFactory formFactory, String labelString, boolean isMultiLine, Composite layoutComposite) {
|
|
251 |
// if (labelString != null) {
|
|
252 |
// label = formFactory.createLabel(layoutComposite, CdmUtils.Nz(labelString), SWT.NULL);
|
|
253 |
// addControl(label);
|
|
254 |
// if(isMultiLine){
|
|
255 |
// label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
|
256 |
// ((TableWrapData)label.getLayoutData()).valign = TableWrapData.MIDDLE;
|
|
257 |
// }
|
|
258 |
// else{
|
|
259 |
// label.setLayoutData(LayoutConstants.LEFT());
|
|
260 |
// ((TableWrapData)label.getLayoutData()).valign = TableWrapData.MIDDLE;
|
|
261 |
// }
|
|
262 |
// }
|
|
263 |
// }
|
|
264 |
// |
|
265 |
// |
|
266 |
// |
|
267 |
// |
|
268 |
// /** {@inheritDoc} */
|
|
269 |
// @Override
|
|
270 |
// public void setBackground(Color color) {
|
|
271 |
// if (label != null) {
|
|
272 |
// label.setBackground(color);
|
|
273 |
// }
|
|
274 |
// }
|
|
275 |
// |
|
276 |
// @Override
|
|
277 |
// public void setSelected(boolean selected) {
|
|
278 |
// setBackground(selected ? SELECTED : getPersistentBackground());
|
|
279 |
// }
|
|
280 |
// |
|
281 |
// @Override
|
|
282 |
// public void setIrrelevant(boolean irrelevant) {
|
|
283 |
// // TODO Auto-generated method stub
|
|
284 |
// |
|
285 |
// }
|
|
286 |
// |
|
287 |
// @Override
|
|
288 |
// public void setEnabled(boolean enabled) {
|
|
289 |
// // TODO Auto-generated method stub
|
|
290 |
// |
|
291 |
// }
|
|
292 |
// |
|
293 |
// @Override
|
|
294 |
// public boolean isEnabled() {
|
|
295 |
// // TODO Auto-generated method stub
|
|
296 |
// return false;
|
|
297 |
// }
|
|
298 |
// |
|
299 |
// @Override
|
|
300 |
// public void modifyText(ModifyEvent e) {
|
|
301 |
// // TODO Auto-generated method stub
|
|
302 |
// |
|
303 |
// }
|
|
304 | 304 |
|
305 | 305 |
|
306 | 306 |
} |
Also available in: Unified diff
revert richtext elements