|
| 1 | +package io.sloeber.ui; |
| 2 | + |
| 3 | +import org.eclipse.cdt.core.parser.util.StringUtil; |
| 4 | +import org.eclipse.cdt.ui.newui.MultiLineTextFieldEditor; |
| 5 | +import org.eclipse.swt.SWT; |
| 6 | +import org.eclipse.swt.layout.GridData; |
| 7 | +import org.eclipse.swt.widgets.Composite; |
| 8 | +import org.eclipse.swt.widgets.Text; |
| 9 | + |
| 10 | + |
| 11 | +/** |
| 12 | + * A class to change MultiLineTextFieldEditor so it puts the label on top of the |
| 13 | + * text field and the text field expands bot horizontal and verical |
| 14 | + * Note I needed a FLAT parent FieldEditorPreferencePage (GRID did not work) |
| 15 | + * public ThirdPartyHardwareSelectionPage() { |
| 16 | + * super(org.eclipse.jface.preference.FieldEditorPreferencePage.FLAT); |
| 17 | + */ |
| 18 | +public class JsonMultiLineTextFieldEditor extends MultiLineTextFieldEditor{ |
| 19 | + |
| 20 | + public JsonMultiLineTextFieldEditor(String name, String labelText, int width, int strategy, Composite parent) { |
| 21 | + super( name, labelText, width,strategy, parent); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * I want 1 column |
| 26 | + */ |
| 27 | + @Override |
| 28 | + public int getNumberOfControls() { |
| 29 | + return 1; |
| 30 | + } |
| 31 | + |
| 32 | + |
| 33 | + /** |
| 34 | + * I want a GridData that has horizontal fill |
| 35 | + */ |
| 36 | + @Override |
| 37 | + protected void doFillIntoGrid(Composite parent, int numColumns) { |
| 38 | + super.doFillIntoGrid( parent, numColumns) ; |
| 39 | + |
| 40 | + Text textField = getTextControl(parent); |
| 41 | + textField.setLayoutData( new GridData(SWT.FILL,SWT.BEGINNING,true,false)); |
| 42 | + |
| 43 | + } |
| 44 | + |
| 45 | + public void setText(String[] text) { |
| 46 | + String actualText=StringUtil.join(text, System.lineSeparator()); |
| 47 | + getPreferenceStore().setValue(getPreferenceName(), actualText); |
| 48 | + setStringValue(actualText ); |
| 49 | + } |
| 50 | + |
| 51 | +} |
0 commit comments