下面列出了org.eclipse.swt.widgets.Composite#getChildren ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static void
collapseAll(
Composite comp )
{
// don't like this but meh
Object obj = comp.getData( "MyTorrentsView.instance" );
if ( obj != null ){
((MyTorrentsView)obj).collapseAll();
}
Control[] kids = comp.getChildren();
for ( Control k: kids ){
if ( k instanceof Composite ){
collapseAll((Composite)k);
}
}
}
/**
* 获取指定容器下的源文本框和目标文本框组件。第一个为源文本框,第二个为目标文本框。
* @param parent
* 每行的 txtComposite
* @return ;
*/
private StyledText[] getTextWidgets(Composite parent) {
StyledText[] sts = new StyledText[2];
Control[] ctrls = parent.getChildren();
for (Control ctrl : ctrls) {
if (ctrl instanceof StyledText) {
sts[0] = (StyledText) ctrl;
}
if (ctrl instanceof Composite) {
Control[] children = ((Composite) ctrl).getChildren();
for (Control child : children) {
if (child instanceof StyledText) {
sts[1] = (StyledText) child;
return sts;
}
}
}
}
return sts;
}
public void updateClaferContainer() {
final Composite compositeContentOfThisScrolledComposite = (Composite) getContent();
// first dispose all the granular UI elements (which includes the deleted one).
for (final Control uiRepresentationOfClaferFeatures : compositeContentOfThisScrolledComposite.getChildren()) {
uiRepresentationOfClaferFeatures.dispose();
}
// update the size values.
setLowestWidgetYAxisValue(0);
setMinHeight(getLowestWidgetYAxisValue());
// add all the clafer features excluding the deleted one.
for (final ClaferFeature featureUnderConsideration : this.claferModel) {
addGranularClaferUIElements(featureUnderConsideration);
}
((Composite) getContent()).layout();
}
/**
* Recursively reads the enable/disable state for the given window and disables all controls.
*
* @param control
* Control
*/
@SuppressWarnings("unchecked")
private void readStateForAndDisable(Control control)
{
if ((exceptions != null && exceptions.contains(control)))
{
return;
}
if (control instanceof Composite)
{
Composite c = (Composite) control;
Control[] children = c.getChildren();
for (int i = 0; i < children.length; i++)
{
readStateForAndDisable(children[i]);
}
}
// XXX: Workaround for 1G2Q8SS: ITPUI:Linux - Combo box is not enabled
// in "File->New->Solution"
states.add(new ItemState(control, true));
control.setEnabled(false);
}
@Override
protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
int width = 0;
int height = 0;
Point textDimension = textDimensions();
Control[] children = composite.getChildren();
for (Control child : children) {
if (child instanceof Text) {
final String textContent = ((Text) child).getText();
textDimension = gc.textExtent(textContent);
width += textDimension.x;
height += textDimension.y;
}
if (child instanceof Label) {
Point computedSize = child.computeSize(0, 0);
width += computedSize.x;
}
}
return new Point(width, height + 4);
}
/**
* Creates the field editors. Field editors are abstractions of the common GUI blocks needed to manipulate various
* types of preferences. Each field editor knows how to save and restore itself.
*/
protected void createFieldEditors()
{
appearanceComposite = getFieldEditorParent();
createMarkOccurrenceOptions(appearanceComposite);
createTextEditingOptions(appearanceComposite, Messages.CommonEditorPreferencePage_Text_Editing_Label);
Composite group = AptanaPreferencePage.createGroup(appearanceComposite,
Messages.CommonEditorPreferencePage_Folding);
group.setLayout(GridLayoutFactory.swtDefaults().create());
group.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
createFoldingOptions(group);
Composite caGroup = AptanaPreferencePage.createGroup(appearanceComposite,
Messages.CommonEditorPreferencePage_ContentAssist);
caGroup.setLayout(GridLayoutFactory.swtDefaults().create());
caGroup.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
Composite caOptions = createContentAssistOptions(caGroup);
if (caOptions.getChildren().length == 1)
{
caGroup.getParent().setVisible(false);
}
}
public void layout(Composite composite, boolean force) {
Rectangle rect = getClientArea(composite);
Control[] children = composite.getChildren();
for (int i = 0; i < children.length; i++) {
children[i].setBounds(rect);
}
}
public static Control findControl(Composite composite, Predicate<Control> predicate) {
for (Control control : composite.getChildren()) {
if (predicate.test(control)) {
return control;
} else if (control instanceof Composite) {
Control result = findControl((Composite) control, predicate);
if (result != null) {
return result;
}
}
}
return null;
}
protected int computeMaxHeight(Composite rowOrHeader) {
Control[] children = rowOrHeader.getChildren();
int maxHeight = 0;
for (int i = 0; i < children.length; i++) {
int height = children[i].computeSize(SWT.DEFAULT, SWT.DEFAULT,
false).y;
if (maxHeight < height) {
maxHeight = height;
}
}
++maxHeight;
return maxHeight;
}
/**
* Recursively sets enabled on this control and all of its descendants. This
* is necessary on Windows, since just disabling the parent control will
* result in the child controls appearing enabled, but not responding to any
* user interaction.
*/
public static void setEnabledRecursive(Control control, boolean enabled) {
control.setEnabled(enabled);
if (control instanceof Composite) {
Composite composite = (Composite) control;
for (Control child : composite.getChildren()) {
setEnabledRecursive(child, enabled);
}
}
}
protected Point computeSize(Composite composite, int wHint, int hHint,
boolean flushCache) {
if (preferredSize.x == -1 || flushCache) {
preferredSize.x = wHint;
preferredSize.y = -1; // NOTE: This assumes at least one child
// control
Control[] children = composite.getChildren();
for (int i = 0; i < children.length; i++) {
Control child = children[i];
preferredSize.y = Math.max(preferredSize.y, child
.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).y);
}
}
return preferredSize;
}
protected void layout( Composite composite, boolean changed )
{
Control[] children = composite.getChildren( );
children[0].setBounds( 44, 0, 16, 12 );
children[1].setBounds( 44, 13, 16, 12 );
children[2].setBounds( 0, 0, 46, 25 );
children[3].setBounds( 44, 12, 17, 3 );
}
/** Sets the enable state of the composite's children, recursively. */
public static void recursiveSetEnabled(Composite composite, boolean enabled) {
for(Control control : composite.getChildren() ) {
if(control instanceof Composite) {
recursiveSetEnabled((Composite) control, enabled);
}
control.setEnabled(enabled);
}
}
private static void nestedSetEnabled(Composite control, boolean enabled) {
control.setEnabled(enabled);
for (Control childControl : control.getChildren()) {
if (childControl instanceof Composite) {
nestedSetEnabled((Composite) childControl, enabled);
} else {
childControl.setEnabled(enabled);
}
}
}
protected void layout(Composite composite, boolean flushCache) {
int bheight = mSettings.getButtonHeight();
int bwidth = mSettings.getButtonWidth();
int vspacer = mSettings.getButtonVerticalSpace();
int bspacer = mSettings.getButtonsHorizontalSpace();
if (CalendarCombo.OS_CARBON) {
bwidth = mSettings.getButtonWidthCarbon();
bheight = mSettings.getCarbonButtonHeight();
vspacer = mSettings.getCarbonButtonVerticalSpace();
bspacer = mSettings.getCarbonButtonsHorizontalSpace();
}
// see how much space we put on the left and right sides of the
// buttons
int width = mSettings.getCalendarWidth() - (bwidth * 2) - bspacer;
width /= 2;
int button1Left = width;
int button2Left = mSettings.getCalendarWidth() - width - bwidth;
Control[] children = composite.getChildren();
for (int i = 0; i < children.length; i++) {
switch (i) {
case 0:
children[i].setBounds(button1Left, vspacer, bwidth, bheight);
break;
case 1:
children[i].setBounds(button2Left, vspacer, bwidth, bheight);
break;
}
}
}
@Override
protected Composite createToolbar2() {
final Composite t = super.createToolbar2();
t.setBackground(getNormalBackground());
for (final Control c : t.getChildren()) {
c.setBackground(getNormalBackground());
}
return t;
}
protected final static boolean containsControl(Control control, Composite composite) {
if(composite != null && !composite.isDisposed()) {
Control[] children = composite.getChildren();
for(Control child : children) {
if(!child.isDisposed()) {
if(child == control) {
return true;
} else if(child instanceof Composite){
return containsControl(control, (Composite) child);
}
}
}
}
return false;
}
private void updateBackground(Composite composite, Color background) {
composite.setBackground(background);
for (Control control : composite.getChildren()) {
if (control instanceof Composite) {
updateBackground((Composite) control, background);
} else {
control.setBackground(background);
}
}
}
protected Widget getColumnAt(Composite rowOrHeader, int offset) {
return rowOrHeader.getChildren()[offset];
}
public void createPartControl( Composite parent )
{
super.createPartControl( parent );
Control[] children = parent.getChildren( );
control = children[children.length - 1];
}