下面列出了怎么用org.eclipse.swt.widgets.ExpandBar的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* @param aStrategyPanelList
* @return
* @throws Atdl4jClassLoadException
*/
protected void buildAtdl4jWidgetMap( List<StrategyPanelT> aStrategyPanelList )
{
Map<String, SWTWidget<?>> tempSWTWidgetMap = new HashMap<String, SWTWidget<?>>();
setExpandBarList( new ArrayList<ExpandBar>() );
// build panels and widgets recursively
for ( StrategyPanelT panel : aStrategyPanelList )
{
tempSWTWidgetMap.putAll( SWTStrategyPanelFactory.createStrategyPanelAndWidgets( getParent(), panel, getParameterMap(), SWT.NONE, getExpandBarList(), getAtdl4jWidgetFactory() ) );
}
// 3/13/2010 John Shields HACK: make the first panel take the full width of the window
Composite c = getParent();
for ( Control child : c.getChildren() )
{
if (child instanceof Composite)
{
Composite composite = (Composite) child;
composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
}
}
setSWTWidgetMap( tempSWTWidgetMap );
}
/**
* Creates the layout and fill it with data
*/
public void createPartControl(Composite parent)
{
bar = new ExpandBar(parent, SWT.V_SCROLL | SWT.BORDER);
bar.setSpacing(8);
UIHelper.setHelp(bar, "ProblemView");
fillData(Activator.getSpecManager().getSpecLoaded());
}
public void createPartControl(Composite parent)
{
/*
* Create the expand bar that will contain
* a list of ExpandItems with interesting information
* about obligations. The items for each obligation are created
* in the method newMarker().
*/
bar = new ExpandBar(parent, SWT.V_SCROLL | SWT.BORDER);
bar.setSpacing(8);
fillFromCurrentSpec();
}
public void relayoutCollapsibleStrategyPanels()
{
// -- avoid lots of 'thrash' during initial build/load of the various Strategy panels containing one or more collapsible panels --
for ( ExpandBar tempExpandBar : getExpandBarList() )
{
// -- Force re-sizing (to support non-collapsed, collapsible ExpandBar components) --
if ( tempExpandBar.getItem( 0 ).getExpanded() )
{
SWTStrategyPanelHelper.relayoutExpandBar( tempExpandBar, false );
}
}
}
public SWTRelayoutExpandBarThread( ExpandBar anExpandBar )
{
expandBar = anExpandBar;
Display.getCurrent().asyncExec(new Runnable()
{
public void run()
{
SWTStrategyPanelHelper.relayoutExpandBar( expandBar );
}
});
}
public static void relayoutExpandBar(ExpandBar expandBar, boolean relayoutParents)
{
Composite c = expandBar;
int tempMaxControlX = 0;
logger.debug( "----- relayoutExpandBar (relayoutParents: " + relayoutParents + " expandBar: " + expandBar + " -----" );
do
{
logger.debug( "c: " + c.getClass() + " c.getParent(): " + c.getParent().getClass() );
if ( c instanceof ExpandBar )
{
ExpandBar eb = (ExpandBar) c;
logger.debug( "ExpandBar.getSize(): " + eb.getSize() );
for ( ExpandItem expandItem : eb.getItems() )
{
logger.debug( "expandItem: " + expandItem + " text: " + expandItem.getText() + " control: " + expandItem.getControl() + " controlLocation: " + expandItem.getControl().getLocation());
logger.debug( "before pack(): expandItem.getControl().getSize(): " + expandItem.getControl().getSize() );
expandItem.getControl().pack();
if ( expandItem.getControl().getSize().x > tempMaxControlX )
{
tempMaxControlX = expandItem.getControl().getSize().x;
}
logger.debug( "before: expandItem.getHeight(): " + expandItem.getHeight() + " expandItem.getControl().getSize(): " + expandItem.getControl().getSize() );
expandItem.setHeight( expandItem.getControl().computeSize( eb.getSize().x, SWT.DEFAULT, true ).y );
}
// -- Need to set ExpandBar's GridData.widthHint to the width of the widest control within it --
GridData tempGridData2 = (GridData) expandBar.getLayoutData();
tempGridData2.widthHint = tempMaxControlX;
// do not set height as ExpandBar handles this tempGridData2.heightHint = expandBar.getSize().y;
expandBar.setLayoutData( tempGridData2 );
if ( relayoutParents )
{
Control p = c.getParent();
if ( p instanceof ScrolledComposite )
{
ScrolledComposite scrolledComposite = (ScrolledComposite) p;
if ( scrolledComposite.getExpandHorizontal() || scrolledComposite.getExpandVertical() )
{
scrolledComposite.setMinSize( scrolledComposite.getContent().computeSize( SWT.DEFAULT, SWT.DEFAULT, true ) );
}
else
{
scrolledComposite.getContent().pack( true );
}
}
if ( p instanceof Composite )
{
Composite composite = (Composite) p;
composite.layout();
}
}
else
{
// -- this (or relayoutParents=true) is needed (otherwise ExampleStrategyPanelTests2.xml with 2 "columns" of StrategyPanels may not draw all of the ExpandBars initially) --
expandBar.getParent().layout();
}
}
c = c.getParent();
}
while ( c != null && c.getParent() != null && !( c instanceof ScrolledComposite ) );
// -- Needed to ensure that strategy panel is expanded vertically as panels go from collapsed to expanded
expandBar.getShell().layout();
expandBar.getShell().pack();
}
/**
* @return the expandBarList
*/
protected List<ExpandBar> getExpandBarList()
{
return this.expandBarList;
}
/**
* @param aExpandBarList the expandBarList to set
*/
protected void setExpandBarList(List<ExpandBar> aExpandBarList)
{
this.expandBarList = aExpandBarList;
}
public static Map<String, SWTWidget<?>> createStrategyPanelAndWidgets(Composite parent, StrategyPanelT panel, Map<String, ParameterT> parameters, int style, List<ExpandBar> aExpandBarList, Atdl4jWidgetFactory aAtdl4jWidgetFactory)
{
logger.debug( "createStrategyPanelAndWidgets(Composite parent, StrategyPanelT panel, Map<String, ParameterT> parameters, int style)" + " invoked with parms parent: "
+ parent + " panel: " + panel + " parameters: " + parameters + " style: " + style );
Map<String, SWTWidget<?>> controlWidgets = new HashMap<String, SWTWidget<?>>();
// -- Handles StrategyPanel's Collapsible, Title, Border, etc. Sets its layout and layoutData and data. --
Composite c = SWTStrategyPanelHelper.createStrategyPanelContainer( panel, parent, style );
if ( panel.getStrategyPanel().size() > 0 && panel.getControl().size() > 0 )
{
// -- Wrap each Control with an auto-built StrategyPanel if setting is true --
if ( aAtdl4jWidgetFactory.getAtdl4jOptions().isAccommodateMixOfStrategyPanelsAndControls() )
{
// -- FIXatdl 1.1 spec recommends against vs. prohibits. Mixed list may not be displayed 'in sequence' of file. --
logger.warn( "StrategyPanel contains both StrategyPanel (" + panel.getStrategyPanel().size() +") and Control ( " + panel.getControl().size() + " elements.\nSee Atdl4jOptions.setAccommodateMixOfStrategyPanelsAndControls() as potential work-around, though Controls will appear after StrategyPanels." );
StrategyPanelT tempPanel = new StrategyPanelT();
tempPanel.setCollapsible( Boolean.FALSE );
tempPanel.setCollapsed( Boolean.FALSE );
tempPanel.setOrientation( panel.getOrientation() );
tempPanel.setColor( panel.getColor() );
logger.warn( "Creating a StrategyPanel to contain " + panel.getControl().size() + " Controls." );
tempPanel.getControl().addAll( panel.getControl() );
panel.getControl().clear();
panel.getStrategyPanel().add( tempPanel );
}
else
{
// 7/20/2010 -- original behavior:
throw new IllegalStateException( "StrategyPanel may not contain both StrategyPanel and Control elements." );
}
}
// build panels widgets recursively
for ( StrategyPanelT p : panel.getStrategyPanel() )
{
Map<String, SWTWidget<?>> widgets = createStrategyPanelAndWidgets( c, p, parameters, style, aExpandBarList, aAtdl4jWidgetFactory );
// check for duplicate IDs
for ( String newID : widgets.keySet() )
{
for ( String existingID : controlWidgets.keySet() )
{
if ( newID.equals( existingID ) )
throw new IllegalStateException( "Duplicate Control ID: \"" + newID + "\"" );
}
}
controlWidgets.putAll( widgets );
}
// build control widgets recursively
for ( ControlT control : panel.getControl() )
{
ParameterT parameter = null;
if ( control.getParameterRef() != null )
{
parameter = parameters.get( control.getParameterRef() );
if ( parameter == null )
throw new IllegalStateException( "Cannot find Parameter \"" + control.getParameterRef() + "\" for Control ID: \"" + control.getID() + "\"" );
}
SWTWidget<?> widget = SWTWidgetFactory.createWidget( c, control, parameter, style, aAtdl4jWidgetFactory );
widget.setParentStrategyPanel( panel );
widget.setParent( c );
// check for duplicate Control IDs
if ( control.getID() != null )
{
// check for duplicate Control IDs
for ( SWTWidget<?> w : controlWidgets.values() )
{
if ( w.getControl().getID().equals( control.getID() ) )
throw new IllegalStateException( "Duplicate Control ID: \"" + control.getID() + "\"" );
}
controlWidgets.put( control.getID(), widget );
}
else
{
throw new IllegalStateException( "Control Type: \"" + control.getClass().getSimpleName() + "\" is missing ID" );
}
}
if ( c.getParent() instanceof ExpandBar )
{
aExpandBarList.add( (ExpandBar)c.getParent() );
}
return controlWidgets;
}
public void itemCollapsed(ExpandEvent aE)
{
SWTStrategyPanelHelper.revalidateLayoutAsync( (ExpandBar)composite.getParent() );
}
public void itemExpanded(ExpandEvent aE)
{
SWTStrategyPanelHelper.revalidateLayoutAsync( (ExpandBar)composite.getParent() );
}
/**
* Helper method contributed on web:
* http://stackoverflow.com/questions/586414
* /why-does-an-swt-composite-sometimes
* -require-a-call-to-resize-to-layout-correctl
*
* @author http://stackoverflow.com/users/63293/peter-walser
* @param control
*/
// 3/13/2010 John Shields
// streamlined method to increase speed; previously was doing too much
// layout work which made the app very slow.
public static void relayoutExpandBar(ExpandBar expandBar)
{
relayoutExpandBar( expandBar, true );
}
/**
* Invokes revalidateLayout() within Display.getCurrent().asyncExec(new
* Runnable() ... )
*
* @param aControl
*/
public static void revalidateLayoutAsync(ExpandBar anExpandBar)
{
SWTRelayoutExpandBarThread tempRevalidateLayoutThread = new SWTRelayoutExpandBarThread( anExpandBar );
tempRevalidateLayoutThread.start();
}