mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 16:56:04 +02:00
Patch from Alex Chapiro to fix createCombo.
This commit is contained in:
parent
5e33757eef
commit
115779a5ee
1 changed files with 147 additions and 45 deletions
|
@ -46,14 +46,22 @@ public class ControlFactory {
|
||||||
* @return the newly-created coposite
|
* @return the newly-created coposite
|
||||||
*/
|
*/
|
||||||
public static Composite createComposite(Composite parent, int numColumns) {
|
public static Composite createComposite(Composite parent, int numColumns) {
|
||||||
|
return createCompositeEx(parent, numColumns, GridData.FILL_HORIZONTAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates composite control and sets the specified layout data.
|
||||||
|
*
|
||||||
|
* @param parent the parent of the new composite
|
||||||
|
* @param numColumns the number of columns for the new composite
|
||||||
|
* @param layoutMode - GridData modes that should be applied to this control
|
||||||
|
* @return the newly-created coposite
|
||||||
|
*/
|
||||||
|
public static Composite createCompositeEx(Composite parent, int numColumns, int layoutMode) {
|
||||||
Composite composite = new Composite(parent, SWT.NULL);
|
Composite composite = new Composite(parent, SWT.NULL);
|
||||||
|
|
||||||
//GridLayout
|
composite.setLayout(new GridLayout(numColumns, true));
|
||||||
GridLayout layout = new GridLayout();
|
composite.setLayoutData(new GridData(layoutMode));
|
||||||
layout.numColumns = numColumns;
|
|
||||||
layout.makeColumnsEqualWidth = true;
|
|
||||||
composite.setLayout(layout);
|
|
||||||
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
|
||||||
return composite;
|
return composite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +96,29 @@ public class ControlFactory {
|
||||||
return separator;
|
return separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an new label (basic method)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param parent parent object
|
||||||
|
* @param text the label text
|
||||||
|
* @param widthHint - recommended widget width
|
||||||
|
* @param heightHint - recommended widget height
|
||||||
|
* @param style - control style
|
||||||
|
* @return the new label
|
||||||
|
*/
|
||||||
|
public static Label createLabel(Composite parent, String text, int widthHint, int heightHint, int style) {
|
||||||
|
|
||||||
|
Label label = new Label(parent, style);
|
||||||
|
label.setText(text);
|
||||||
|
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||||
|
gd.horizontalSpan = 1;
|
||||||
|
gd.widthHint = widthHint;
|
||||||
|
gd.heightHint = heightHint;
|
||||||
|
label.setLayoutData(gd);
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method that creates a label instance
|
* Utility method that creates a label instance
|
||||||
* and sets the default layout data.
|
* and sets the default layout data.
|
||||||
|
@ -97,12 +128,7 @@ public class ControlFactory {
|
||||||
* @return the new label
|
* @return the new label
|
||||||
*/
|
*/
|
||||||
public static Label createLabel(Composite parent, String text) {
|
public static Label createLabel(Composite parent, String text) {
|
||||||
Label label = new Label(parent, SWT.LEFT );
|
return createLabel(parent, text, SWT.DEFAULT, SWT.DEFAULT, SWT.LEFT);
|
||||||
label.setText(text);
|
|
||||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
|
||||||
data.horizontalSpan = 1;
|
|
||||||
label.setLayoutData(data);
|
|
||||||
return label;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,17 +160,8 @@ public class ControlFactory {
|
||||||
* @param heightHint - recommended widget height
|
* @param heightHint - recommended widget height
|
||||||
* @return the new label
|
* @return the new label
|
||||||
*/
|
*/
|
||||||
public static Text createWrappedLabel(Composite parent, String text, int widthHint, int heightHint) {
|
public static Label createWrappedLabel(Composite parent, String text, int widthHint, int heightHint) {
|
||||||
|
return createLabel(parent, text, widthHint, heightHint, SWT.LEFT | SWT.WRAP);
|
||||||
Text wlabel = new Text(parent, SWT.WRAP | SWT.MULTI | SWT.READ_ONLY);
|
|
||||||
wlabel.setText(text);
|
|
||||||
GridData data = new GridData(GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
|
|
||||||
data.heightHint = heightHint;
|
|
||||||
data.widthHint = widthHint;
|
|
||||||
wlabel.setLayoutData(data);
|
|
||||||
wlabel.setBackground(parent.getBackground());
|
|
||||||
wlabel.setForeground(parent.getForeground());
|
|
||||||
return wlabel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -300,7 +317,7 @@ public class ControlFactory {
|
||||||
List list = new List(parent, SWT.SINGLE);
|
List list = new List(parent, SWT.SINGLE);
|
||||||
GridData data = new GridData();
|
GridData data = new GridData();
|
||||||
list.setLayoutData(data);
|
list.setLayoutData(data);
|
||||||
StringTokenizer st = new StringTokenizer(strdata, ",");
|
StringTokenizer st = new StringTokenizer(strdata, ","); //$NON-NLS-1$
|
||||||
while(st.hasMoreTokens())
|
while(st.hasMoreTokens())
|
||||||
list.add(st.nextToken());
|
list.add(st.nextToken());
|
||||||
if(selData == null) {
|
if(selData == null) {
|
||||||
|
@ -312,6 +329,14 @@ public class ControlFactory {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void selectList(List list, String selData) {
|
||||||
|
int n_sel = list.indexOf(selData);
|
||||||
|
if(0 > n_sel)
|
||||||
|
n_sel = 0;
|
||||||
|
list.select(n_sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -439,16 +464,86 @@ public class ControlFactory {
|
||||||
* @param string of comma separated tokens to fill selection list
|
* @param string of comma separated tokens to fill selection list
|
||||||
* @return the new combo
|
* @return the new combo
|
||||||
*/
|
*/
|
||||||
public static CCombo createSelectCombo(Composite parent, String strdata, String selData) {
|
public static CCombo createSelectCCombo(Composite parent, String strdata, String selData) {
|
||||||
|
return createSelectCCombo(parent, strdata, selData,
|
||||||
|
SWT.READ_ONLY | SWT.BORDER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CCombo createSelectCCombo(Composite parent, String strdata, String selData, int style) {
|
||||||
|
CCombo combo = new CCombo(parent, style);
|
||||||
|
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||||
|
combo.setLayoutData(data);
|
||||||
|
StringTokenizer st = new StringTokenizer(strdata, ","); //$NON-NLS-1$
|
||||||
|
while(st.hasMoreTokens())
|
||||||
|
combo.add(st.nextToken());
|
||||||
|
if(selData == null || selData.length() == 0) {
|
||||||
|
if(combo.getItemCount() > 0)
|
||||||
|
combo.select(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
selectCCombo(combo, selData);
|
||||||
|
return combo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a selection combo
|
||||||
|
*
|
||||||
|
* @param parent the parent of the new text field
|
||||||
|
* @param array of elements + selected element
|
||||||
|
* @return the new combo
|
||||||
|
*/
|
||||||
|
public static CCombo createSelectCCombo(Composite parent, String[] strdata, String selData) {
|
||||||
|
return createSelectCCombo(parent, strdata, selData, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CCombo createSelectCCombo(Composite parent, String[] strdata, String selData, int style) {
|
||||||
|
CCombo combo = new CCombo(parent, style);
|
||||||
|
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||||
|
combo.setLayoutData(data);
|
||||||
|
for(int i = 0; i < strdata.length; ++i) {
|
||||||
|
combo.add(strdata[i]);
|
||||||
|
}
|
||||||
|
if(selData == null)
|
||||||
|
combo.select(0);
|
||||||
|
else
|
||||||
|
selectCCombo(combo, selData);
|
||||||
|
return combo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void selectCCombo(CCombo combo, String selData) {
|
||||||
|
int n_sel = combo.indexOf(selData);
|
||||||
|
if(0 > n_sel)
|
||||||
|
n_sel = 0;
|
||||||
|
combo.select(n_sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a selection combo
|
||||||
|
*
|
||||||
|
* @param parent the parent of the new text field
|
||||||
|
* @param string of comma separated tokens to fill selection list
|
||||||
|
* @return the new combo
|
||||||
|
*/
|
||||||
|
public static Combo createSelectCombo(Composite parent, String strdata, String selData) {
|
||||||
return createSelectCombo(parent, strdata, selData,
|
return createSelectCombo(parent, strdata, selData,
|
||||||
SWT.READ_ONLY | SWT.BORDER);
|
SWT.READ_ONLY | SWT.BORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CCombo createSelectCombo(Composite parent, String strdata, String selData, int style) {
|
public static Combo createSelectCombo(Composite parent, String strdata, String selData, int style) {
|
||||||
CCombo combo = new CCombo(parent, style);
|
Combo combo = new Combo(parent, style);
|
||||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||||
combo.setLayoutData(data);
|
combo.setLayoutData(data);
|
||||||
StringTokenizer st = new StringTokenizer(strdata, ",");
|
StringTokenizer st = new StringTokenizer(strdata, ","); //$NON-NLS-1$
|
||||||
while(st.hasMoreTokens())
|
while(st.hasMoreTokens())
|
||||||
combo.add(st.nextToken());
|
combo.add(st.nextToken());
|
||||||
if(selData == null || selData.length() == 0) {
|
if(selData == null || selData.length() == 0) {
|
||||||
|
@ -468,12 +563,12 @@ public class ControlFactory {
|
||||||
* @param array of elements + selected element
|
* @param array of elements + selected element
|
||||||
* @return the new combo
|
* @return the new combo
|
||||||
*/
|
*/
|
||||||
public static CCombo createSelectCombo(Composite parent, String[] strdata, String selData) {
|
public static Combo createSelectCombo(Composite parent, String[] strdata, String selData) {
|
||||||
return createSelectCombo(parent, strdata, selData, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
|
return createSelectCombo(parent, strdata, selData, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CCombo createSelectCombo(Composite parent, String[] strdata, String selData, int style) {
|
public static Combo createSelectCombo(Composite parent, String[] strdata, String selData, int style) {
|
||||||
CCombo combo = new CCombo(parent, style);
|
Combo combo = new Combo(parent, style);
|
||||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||||
combo.setLayoutData(data);
|
combo.setLayoutData(data);
|
||||||
for(int i = 0; i < strdata.length; ++i) {
|
for(int i = 0; i < strdata.length; ++i) {
|
||||||
|
@ -486,6 +581,27 @@ public class ControlFactory {
|
||||||
return combo;
|
return combo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void selectCombo(Combo combo, String selData) {
|
||||||
|
int n_sel = combo.indexOf(selData);
|
||||||
|
if(0 > n_sel) {
|
||||||
|
if( ( combo.getStyle() & SWT.READ_ONLY ) == 0 ) {
|
||||||
|
combo.setText( selData );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
n_sel = 0;
|
||||||
|
}
|
||||||
|
combo.select(n_sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a dialog shell, child to the top level workbench shell.
|
* Create a dialog shell, child to the top level workbench shell.
|
||||||
|
@ -501,21 +617,7 @@ public class ControlFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void selectCombo(CCombo combo, String selData) {
|
|
||||||
int n_sel = combo.indexOf(selData);
|
|
||||||
if(0 > n_sel)
|
|
||||||
n_sel = 0;
|
|
||||||
combo.select(n_sel);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void selectList(List list, String selData) {
|
|
||||||
int n_sel = list.indexOf(selData);
|
|
||||||
if(0 > n_sel)
|
|
||||||
n_sel = 0;
|
|
||||||
list.select(n_sel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Composite insertSpace(Composite parent, int nSpan, int height) {
|
public static Composite insertSpace(Composite parent, int nSpan, int height) {
|
||||||
Composite space = ControlFactory.createCompositeSeparator(parent, parent.getBackground(),
|
Composite space = ControlFactory.createCompositeSeparator(parent, parent.getBackground(),
|
||||||
(SWT.DEFAULT != height ? height : 5));
|
(SWT.DEFAULT != height ? height : 5));
|
||||||
|
|
Loading…
Add table
Reference in a new issue