Project

General

Profile

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

    
6
import java.awt.Point;
7

    
8
import org.eclipse.jface.dialogs.MessageDialog;
9
import org.eclipse.jface.layout.GridDataFactory;
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;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.events.KeyAdapter;
17
import org.eclipse.swt.events.KeyEvent;
18
import org.eclipse.swt.events.ModifyEvent;
19
import org.eclipse.swt.events.ModifyListener;
20
import org.eclipse.swt.events.SelectionAdapter;
21
import org.eclipse.swt.events.SelectionEvent;
22
import org.eclipse.swt.graphics.Color;
23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.layout.RowLayout;
25
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Control;
28
import org.eclipse.swt.widgets.Label;
29
import org.eclipse.swt.widgets.Listener;
30
import org.eclipse.swt.widgets.Text;
31
import org.eclipse.ui.forms.widgets.TableWrapData;
32
import org.eclipse.ui.forms.widgets.TableWrapLayout;
33

    
34
import eu.etaxonomy.cdm.common.CdmUtils;
35
import eu.etaxonomy.taxeditor.preference.Resources;
36

    
37
/**
38
 * @author n.hoffmann
39
 * @version $Id: $
40
 */
41
public class RichTextWithLabelElement{ //extends AbstractCdmFormElement implements ModifyListener, IEnableableFormElement,
42
   //     ISelectable {
43

    
44
    
45
    //protected RichTextEditor richtextEditor;
46
    private Label label;
47
    private boolean buttonVisible = true;
48

    
49
    private final boolean isMultiLine;
50

    
51
    public static final int MAX_HEIGHT = 0;
52
    public static final int SINGLE = -1;
53

    
54
    protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, boolean isMultiLine) {
55
      //  super(formFactory, parentElement);
56
        this.isMultiLine = isMultiLine;
57
    }
58

    
59
    protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
60
            String initialText, Integer textHeight, int style) {
61
        this(formFactory, parentElement, labelString, initialText, textHeight, null, true, style);
62
    }
63

    
64
    protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
65
            String initialText, Integer textHeight, boolean isMultiLine, int style) {
66
        this(formFactory, parentElement, labelString, initialText, textHeight, null, isMultiLine, style);
67
    }
68

    
69
    protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
70
            String initialText, Integer textHeight, Integer textLimit, int style) {
71
        this(formFactory, parentElement, labelString, initialText, textHeight, textLimit, false, style);
72
    }
73

    
74
    protected RichTextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
75
            String initialText, Integer textHeight, Integer textLimit, boolean isMultiLine, int style) {
76
      //  super(formFactory, parentElement);
77

    
78
        this.isMultiLine = isMultiLine;
79

    
80
       // initLabel(formFactory, labelString, isMultiLine, getLayoutComposite());
81

    
82
   //     initText( initialText, textHeight, textLimit, isMultiLine, style, getLayoutComposite());
83
    }
84

    
85
    protected void initText(String initialText, Integer textHeight, Integer textLimit,
86
            boolean isMultiLine, int style, Composite layoutComposite) {
87
    	layoutComposite.setLayout(new GridLayout(1, true));
88

    
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);
99

    
100
		final Text htmlOutput = new Text(layoutComposite,
101
				SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
102
		GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 100).applyTo(htmlOutput);
103
		htmlOutput.setEditable(true);
104
		
105
		
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() {
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

    
126
//		editor.addToolbarButton(new ToolbarButton("jsButton",
127
//				"myScriptCommand", "Execute Javascript", "other,0",
128
//				null) {
129
//			@Override
130
//			public String getJavascriptToExecute() {
131
//				return "alert('Javascript call')";
132
//			}
133
//		});
134

    
135
		// add additional controls for showing interactions
136
	
137
//    	  createControlPanel(layoutComposite, editor, textHeight); 
138
        	 
139
    }
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
//	}
304

    
305
   
306
}
(38-38/48)