下面列出了怎么用org.eclipse.ui.forms.widgets.SharedScrolledComposite的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testCorrectPanelIsShownForFacetedProject() {
DeployPropertyPage page = new DeployPropertyPage(loginService, googleApiFactory);
Shell parent = shellTestResource.getShell();
page.setElement(getProject());
page.createControl(parent);
page.setVisible(true);
Composite preferencePageComposite = (Composite) parent.getChildren()[0];
for (Control control : preferencePageComposite.getChildren()) {
if (control instanceof SharedScrolledComposite) {
assertThat(getDeployPreferencesPanel((Composite) control), instanceOf(getPanelClass()));
return;
}
}
fail("Did not find the deploy preferences panel");
}
@Override
protected Control createContents(Composite parent) {
container = new SharedScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL) {};
container.setExpandHorizontal(true);
container.setExpandVertical(true);
container.setLayout(new GridLayout());
IProject project = AdapterUtil.adapt(getElement(), IProject.class);
try {
facetedProject = ProjectFacetsManager.create(project);
} catch (CoreException ex) {
logger.log(Level.WARNING, ex.getMessage());
return container;
}
GridDataFactory.fillDefaults().grab(true, true).applyTo(container);
evaluateFacetConfiguration();
return container;
}
/**
* Creates a scrolled composite
*
* @param parent the parent to add to
* @param columns the number of columns for the composite
* @param hspan the horizontal span to take up in the parent
* @param marginwidth the width of the margins
* @param marginheight the height of the margins
* @return a new scrolled composite
*/
public static SharedScrolledComposite createScrolledComposite(Composite parent, int columns, int hspan, int marginwidth, int marginheight) {
SharedScrolledComposite comp = new SharedScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL) {};
GridLayout layout = new GridLayout(columns, false);
layout.marginHeight = marginheight;
layout.marginWidth = marginwidth;
comp.setLayout(layout);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = hspan;
comp.setLayoutData(gd);
comp.setExpandHorizontal(true);
comp.setExpandVertical(true);
return comp;
}
/**
* The default constructor. Creates a {@link ScrollClientComposite}
* constructor. The parent and style are passed to the {@link Composite}
* constructor. The {@link #minWidth} is set to its default value. The
* closest scrolled ancestor is determined automatically, but an
* {@code IllegalArgumentException} is thrown if one cannot be found.
*
* @param parent
* A widget which will be the parent of the new instance (cannot
* be null).
* @param style
* The style of widget to construct.
*/
public ScrollClientComposite(Composite parent, int style) {
super(parent, style);
// Find the ancestor ScrolledComposite.
while (parent != null && !(parent instanceof SharedScrolledComposite)) {
parent = parent.getParent();
}
// If a ScrolledComposite was found, then set the class reference to it.
// Otherwise throw an exception.
if (parent != null) {
scrolledAncestor = (SharedScrolledComposite) parent;
} else {
scrolledAncestor = null;
throw new IllegalArgumentException("HorizontalScrollManager error: "
+ "Client Control does not have a ScrolledComposite ancestor.");
}
// We need to add a resize listener to reflow the ancestor
// ScrolledComposite when it's client area is too small.
createResizeListener();
// We must ensure the padding is correct for resizing.
recomputePads();
return;
}
/**
* Creates a {@link ScrollClientComposite}. The parent and style are passed
* to the {@link Composite} constructor. The ancestor is verified, and the
* {@link #minWidth} is set to its default value.
*
* @param parent
* A widget which will be the parent of the new instance (cannot
* be null).
* @param style
* The style of widget to construct.
* @param scrolledAncestor
* The ancestor scrolled {@code Composite}. Must be a non-null
* ancestor (parent, grandparent, etc.), else an
* {@code IllegalArgumentException} will be thrown.
*/
public ScrollClientComposite(Composite parent, int style,
SharedScrolledComposite scrolledAncestor) {
super(parent, style);
// Check the scrolledAncestor parameter for null.
if (scrolledAncestor == null) {
this.scrolledAncestor = null;
throw new IllegalArgumentException("HorizontalScrollManager error: "
+ "Null ancestor ScrolledComposite passed to constructor!");
}
// Find the scrolledAncestor among this Composite's ancestors.
while (parent != null && parent != scrolledAncestor) {
parent = parent.getParent();
}
// If the correct ancestor was found, then set the class reference to
// it. Otherwise, throw an exception.
if (parent != null) {
this.scrolledAncestor = scrolledAncestor;
} else {
this.scrolledAncestor = null;
throw new IllegalArgumentException("HorizontalScrollManager error: "
+ "Specified ScrolledComposite is not an ancestor of client Control.");
}
// We need to add a resize listener to reflow the ancestor
// ScrolledComposite when it's client area is too small.
createResizeListener();
// We must ensure the padding is correct for resizing.
recomputePads();
return;
}
/**
* The full {@link ScrollClientComposite} constructor. The parent and style
* are passed to the {@link Composite} constructor. The ancestor is
* verified, and the {@link #minWidth} is set.
*
* @param parent
* A widget which will be the parent of the new instance (cannot
* be null).
* @param style
* The style of widget to construct.
* @param scrolledAncestor
* The ancestor scrolled {@code Composite}. Must be a non-null
* ancestor (parent, grandparent, etc.), else an
* {@code IllegalArgumentException} will be thrown.
* @param minWidth
* The width at which this {@code Composite} will stop getting
* smaller, thus forcing its ancestor {@code ScrolledComposite}
* to use a horizontal scroll bar. If less than 0, the value 0
* will be used instead.
*/
public ScrollClientComposite(Composite parent, int style,
SharedScrolledComposite scrolledAncestor, int minWidth) {
this(parent, style, scrolledAncestor);
setMinWidth(minWidth);
}