Project

General

Profile

Download (9.68 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 *
3
 */
4
package eu.etaxonomy.taxeditor.ui.element;
5

    
6
import org.eclipse.jface.layout.GridDataFactory;
7
//import org.eclipse.nebula.widgets.richtext.RichTextEditor;
8
//import org.eclipse.nebula.widgets.richtext.RichTextEditorConfiguration;
9
//import org.eclipse.nebula.widgets.richtext.toolbar.ToolbarButton;
10
//import org.eclipse.nebula.widgets.richtext.toolbar.ToolbarConfiguration;
11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.layout.GridLayout;
13
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.swt.widgets.Label;
15
import org.eclipse.swt.widgets.Text;
16

    
17
/**
18
 * @author n.hoffmann
19
 */
20
public class RichTextWithLabelElement{ //extends AbstractCdmFormElement implements ModifyListener, IEnableableFormElement,
21
   //     ISelectable {
22

    
23
    //protected RichTextEditor richtextEditor;
24
    private Label label;
25
    private boolean buttonVisible = true;
26

    
27
    private final boolean isMultiLine;
28

    
29
    public static final int MAX_HEIGHT = 0;
30
    public static final int SINGLE = -1;
31

    
32
    protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, boolean isMultiLine) {
33
      //  super(formFactory, parentElement);
34
        this.isMultiLine = isMultiLine;
35
    }
36

    
37
    protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
38
            String initialText, Integer textHeight, int style) {
39
        this(formFactory, parentElement, labelString, initialText, textHeight, null, true, style);
40
    }
41

    
42
    protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
43
            String initialText, Integer textHeight, boolean isMultiLine, int style) {
44
        this(formFactory, parentElement, labelString, initialText, textHeight, null, isMultiLine, style);
45
    }
46

    
47
    protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
48
            String initialText, Integer textHeight, Integer textLimit, int style) {
49
        this(formFactory, parentElement, labelString, initialText, textHeight, textLimit, false, style);
50
    }
51

    
52
    protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
53
            String initialText, Integer textHeight, Integer textLimit, boolean isMultiLine, int style) {
54
      //  super(formFactory, parentElement);
55

    
56
        this.isMultiLine = isMultiLine;
57

    
58
       // initLabel(formFactory, labelString, isMultiLine, getLayoutComposite());
59

    
60
   //     initText( initialText, textHeight, textLimit, isMultiLine, style, getLayoutComposite());
61
    }
62

    
63
    protected void initText(String initialText, Integer textHeight, Integer textLimit,
64
            boolean isMultiLine, int style, Composite layoutComposite) {
65
    	layoutComposite.setLayout(new GridLayout(1, true));
66

    
67

    
68
//		ToolbarConfiguration toolBarConfig = new ToolbarConfiguration();
69
//
70
//		RichTextEditorConfiguration config = new RichTextEditorConfiguration();
71
//		config.setMinSize(800, 600);
72
//
73
//		final RichTextEditor editor = new RichTextEditor(layoutComposite, config);
74
//		GridDataFactory.fillDefaults().grab(true, true).applyTo(editor);
75
//		//editor.setText(initialText);
76
//		//editor.setEditable(true);
77

    
78
		final Text htmlOutput = new Text(layoutComposite,
79
				SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
80
		GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 100).applyTo(htmlOutput);
81
		htmlOutput.setEditable(true);
82

    
83

    
84

    
85
//		editor.addModifyListener(new ModifyListener() {
86
//
87
//			@Override
88
//			public void modifyText(ModifyEvent e) {
89
//				org.eclipse.swt.graphics.Point point = htmlOutput.getSelection();
90
//				htmlOutput.setText(htmlOutput.getText() + " - " + point.x + ":"+point.y);
91
//			}
92
//		});
93

    
94
//		editor.addKeyListener(new KeyAdapter() {
95
//
96
//			@Override
97
//			public void keyPressed(KeyEvent e) {
98
//				org.eclipse.swt.graphics.Point point = htmlOutput.getSelection();
99
//				htmlOutput.setText(htmlOutput.getText() + " - " + point.x + ":"+point.y);
100
//
101
//			}
102
//		});
103

    
104
//		editor.addToolbarButton(new ToolbarButton("jsButton",
105
//				"myScriptCommand", "Execute Javascript", "other,0",
106
//				null) {
107
//			@Override
108
//			public String getJavascriptToExecute() {
109
//				return "alert('Javascript call')";
110
//			}
111
//		});
112

    
113
		// add additional controls for showing interactions
114

    
115
//    	  createControlPanel(layoutComposite, editor, textHeight);
116

    
117
    }
118

    
119
//    protected void createControlPanel(Composite parent, final RichTextEditor editor, int textHeight) {
120
//    	  Composite controlPanel = new Composite(parent, SWT.NONE);
121
//    	  TableWrapLayout layout;
122
//    	  layout = LayoutConstants.LAYOUT(3, false);
123
//    	  controlPanel.setLayout(layout);
124
//    	  GridDataFactory.fillDefaults().grab(true, false).applyTo(controlPanel);
125
//
126
//    	  Label inputLabel = new Label(controlPanel, SWT.NONE);
127
//    	  inputLabel.setText("Text to set:");
128
//    //	  GridDataFactory.fillDefaults().applyTo(inputLabel);
129
//
130
//    	  Text input = new Text(controlPanel, SWT.BORDER);
131
//    	  TableWrapData layoutData;
132
//    	  if(isMultiLine){
133
//              layoutData = LayoutConstants.FILL_HORIZONTALLY(2, 1);
134
//          }
135
//          else{
136
//              layoutData = LayoutConstants.FILL();
137
//          }
138
//    	  input.setLayoutData(layoutData);
139
//    //	  GridDataFactory.fillDefaults().grab(true, false).applyTo(input);
140
//
141
//    	  input.addKeyListener(new KeyAdapter() {
142
//    	   @Override
143
//    	   public void keyPressed(KeyEvent e) {
144
//    	    if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
145
//    	     editor.setText(input.getText());
146
//    	    }
147
//    	   }
148
//    	  });
149
//
150
//    	  Button setButton = new Button(controlPanel, SWT.PUSH);
151
//    	  setButton.setText("Set Text");
152
//    	//  GridDataFactory.defaultsFor(setButton).applyTo(setButton);
153
//
154
//    	  setButton.addSelectionListener(new SelectionAdapter() {
155
//    	   @Override
156
//    	   public void widgetSelected(SelectionEvent e) {
157
//    	    editor.setText(input.getText());
158
//    	   }
159
//    	  });
160
//
161
//    	  Composite buttonPanel = new Composite(controlPanel, SWT.NONE);
162
//    	  buttonPanel.setLayout(new RowLayout());
163
//    	 // GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(buttonPanel);
164
//
165
//    	  Button getButton = new Button(buttonPanel, SWT.PUSH);
166
//    	  getButton.setText("Get text");
167
//    	  getButton.addSelectionListener(new SelectionAdapter() {
168
//    	   @Override
169
//    	   public void widgetSelected(SelectionEvent e) {
170
//    	    MessageDialog.openInformation(null, "Editor Input",
171
//    	      editor.getText());
172
//    	   }
173
//    	  });
174
//
175
//    	  final Button enableButton = new Button(buttonPanel, SWT.PUSH);
176
//    	  enableButton.setText("Disable");
177
//    	  enableButton.addSelectionListener(new SelectionAdapter() {
178
//    	   @Override
179
//    	   public void widgetSelected(SelectionEvent e) {
180
//    	    boolean editable = editor.isEditable();
181
//    	    editor.setEditable(!editable);
182
//
183
//    	    enableButton.setText(editable ? "Enable" : "Disable");
184
//    	   }
185
//    	  });
186
//
187
//    	  final Button updateButton = new Button(buttonPanel, SWT.PUSH);
188
//    	  updateButton.setText("Update Toolbar");
189
//
190
//    	  final ToolbarButton button = new ToolbarButton("javaButton",
191
//    	    "myJavaCommand", "Execute Java", "other",
192
//    	    null) {
193
//
194
//    	   @Override
195
//    	   public Object execute() {
196
//    	    MessageDialog.openInformation(null, "Information",
197
//    	      "Java callback: " + editor.getSelectedHTML());
198
//
199
//    	    editor.insertHTML("<em>" + editor.getSelectedHTML() + "</em>");
200
//    	    return null;
201
//    	   }
202
//    	  };
203
//
204
//    	  updateButton.addSelectionListener(new SelectionAdapter() {
205
//    	   @Override
206
//    	   public void widgetSelected(SelectionEvent e) {
207
//    	    if (!buttonVisible) {
208
//    	     editor.addToolbarButton(button);
209
//    	    } else {
210
//    	     editor.removeToolbarButton(button);
211
//    	    }
212
//    	    buttonVisible = !buttonVisible;
213
//    	    editor.updateToolbar();
214
//    	   }
215
//    	  });
216
//
217
//    	  Button setFocusButton = new Button(buttonPanel, SWT.PUSH);
218
//    	  setFocusButton.setText("Set Focus");
219
//    	  setFocusButton.addSelectionListener(new SelectionAdapter() {
220
//    	   @Override
221
//    	   public void widgetSelected(SelectionEvent e) {
222
//    	    editor.setFocus();
223
//    	   }
224
//    	  });
225
//
226
//    	 }
227
//
228
//    protected void initLabel(CdmFormFactory formFactory, String labelString, boolean isMultiLine, Composite layoutComposite) {
229
//        if (labelString != null) {
230
//            label = formFactory.createLabel(layoutComposite, CdmUtils.Nz(labelString), SWT.NULL);
231
//            addControl(label);
232
//            if(isMultiLine){
233
//                label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
234
//                ((TableWrapData)label.getLayoutData()).valign = TableWrapData.MIDDLE;
235
//            }
236
//            else{
237
//                label.setLayoutData(LayoutConstants.LEFT());
238
//                ((TableWrapData)label.getLayoutData()).valign = TableWrapData.MIDDLE;
239
//            }
240
//        }
241
//    }
242
//
243
//
244
//
245
//
246
//    /** {@inheritDoc} */
247
//    @Override
248
//    public void setBackground(Color color) {
249
//        if (label != null) {
250
//            label.setBackground(color);
251
//        }
252
//    }
253
//
254
//    @Override
255
//    public void setSelected(boolean selected) {
256
//        setBackground(selected ? SELECTED : getPersistentBackground());
257
//    }
258
//
259
//	@Override
260
//	public void setIrrelevant(boolean irrelevant) {
261
//		// TODO Auto-generated method stub
262
//
263
//	}
264
//
265
//	@Override
266
//	public void setEnabled(boolean enabled) {
267
//		// TODO Auto-generated method stub
268
//
269
//	}
270
//
271
//	@Override
272
//	public boolean isEnabled() {
273
//		// TODO Auto-generated method stub
274
//		return false;
275
//	}
276
//
277
//	@Override
278
//	public void modifyText(ModifyEvent e) {
279
//		// TODO Auto-generated method stub
280
//
281
//	}
282

    
283

    
284
}
(47-47/57)