下面列出了org.eclipse.swt.widgets.Layout#org.eclipse.swt.widgets.Button 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Enables or disables the mapping button. We can only enable it if the target steps allows a mapping to be made
* against it.
*
* @param button The button to disable or enable
* @param input input or output. If it's true, we keep the button enabled all the time.
* @param sourceStepname The mapping output step
* @param targetStepname The target step to verify
* @throws KettleException
*/
private void enableMappingButton( final Button button, boolean input, String sourceStepname, String targetStepname ) throws KettleException {
if ( input ) {
return; // nothing to do
}
boolean enabled = false;
if ( mappingTransMeta != null ) {
StepMeta mappingInputStep = mappingTransMeta.findMappingInputStep( sourceStepname );
if ( mappingInputStep != null ) {
StepMeta mappingOutputStep = transMeta.findMappingOutputStep( targetStepname );
RowMetaInterface requiredFields = mappingOutputStep.getStepMetaInterface().getRequiredFields( transMeta );
if ( requiredFields != null && requiredFields.size() > 0 ) {
enabled = true;
}
}
}
button.setEnabled( enabled );
}
/**
* Creates and returns a new push button with the given label and/or image.
*
* @param parent
* parent control
* @param label
* button label or <code>null</code>
* @param image
* image or <code>null</code>
* @return a new push button
*/
public static Button createPushButton(Composite parent, String label, Image image)
{
Button button = new Button(parent, SWT.PUSH);
button.setFont(parent.getFont());
if (image != null)
{
button.setImage(image);
}
if (label != null)
{
button.setText(label);
}
GridData gd = new GridData();
button.setLayoutData(gd);
SWTFactory.setButtonDimensionHint(button);
return button;
}
/**
* Creates the "plus" button
*
* @param buttonHolder aprent composite
*/
private void createPlusButton(final Composite buttonHolder) {
final Button plusButton = new Button(buttonHolder, SWT.PUSH);
plusButton.setText("...");
plusButton.setToolTipText(ResourceManager.getLabel(ResourceManager.EDIT_PROPERTY));
plusButton.setEnabled(property.isEnabled());
plusButton.addListener(SWT.Selection, event -> {
openWindow(widget, item, property);
});
plusButton.addListener(SWT.FocusIn, event -> {
widget.updateDescriptionPanel(property);
});
plusButton.pack();
}
public void createControl(Composite parent) {
setTitle(Messages.getString("AssignChoicePage_title"));//$NON-NLS-1$
setDescription(Messages.getString("AssignChoicePage_message"));//$NON-NLS-1$
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
newJob = new Button(composite, SWT.RADIO);
newJob.setText(Messages.getString("AssignChoicePage_newJobLabel"));//$NON-NLS-1$
assignJob = new Button(composite, SWT.RADIO);
assignJob.setText(Messages.getString("AssignChoicePage_assignJobLabel"));//$NON-NLS-1$
newJob.setSelection(true);
setControl(composite);
}
private void initRadioButton( Button button,
IParameterSelectionChoice choice, String choiceLabel )
{
if ( ( choice.getValue( ) == defaultValue )
|| ( choice.getValue( ) != null && choice.getValue( )
.equals( defaultValue ) ) )
{
button.setSelection( true );
putConfigValue( paramterHandleName, button.getData( ) );
clearSelectRadio( radioItems );
}
else if ( defaultValue == null
&& choiceLabel.equals( InputParameterSelectionChoice.NULLVALUECHOICE ) )
{
button.setSelection( true );
removeConfigValue( paramterHandleName );
clearSelectRadio( radioItems );
}
radioItems.add( button );
}
public TimeNowActionController ( final ControllerManager controllerManager, final ChartContext chartContext, final TimeNowAction controller )
{
super ( controllerManager.getContext (), chartContext, controller );
final Composite space = chartContext.getExtensionSpaceProvider ().getExtensionSpace ();
if ( space != null )
{
this.button = new Button ( space, SWT.PUSH );
this.button.setText ( Messages.TimeNowActionController_Label );
this.button.setToolTipText ( Messages.TimeNowActionController_Description );
this.button.addSelectionListener ( new SelectionAdapter () {
@Override
public void widgetSelected ( final SelectionEvent e )
{
action ();
};
} );
space.layout ();
}
else
{
this.button = null;
}
}
@Override
protected void buttonPressed(int buttonId){
super.buttonPressed(buttonId);
if (IDialogConstants.NEXT_ID == buttonId) {
Button nextBtn = getButton(IDialogConstants.NEXT_ID);
// the text of the button will be changed
if ("Korrigierte Rechnung öffnen".equals(nextBtn.getText())) {
if (invoiceCorrectionDTO != null) {
invoiceCorrectionDTO.setOpenNewInvoice(true);
finishPressed();
return;
}
} else if (invoiceCorrectionDTO != null && invoiceCorrectionDTO.isCorrectionSuccess()) {
nextBtn.setEnabled(true);
nextBtn.setText("Korrigierte Rechnung öffnen");
}
getButton(IDialogConstants.CANCEL_ID).setEnabled(false);
getButton(IDialogConstants.FINISH_ID).setVisible(true);
}
}
private void addAutoclosingSection(Composite composite) {
GridLayout layout= new GridLayout();
layout.numColumns= 1;
composite.setLayout(layout);
String label;
Button master, slave;
label= PreferencesMessages.JavaEditorPreferencePage_closeStrings;
addCheckBox(composite, label, PreferenceConstants.EDITOR_CLOSE_STRINGS, 0);
label= PreferencesMessages.JavaEditorPreferencePage_closeBrackets;
addCheckBox(composite, label, PreferenceConstants.EDITOR_CLOSE_BRACKETS, 0);
label= PreferencesMessages.JavaEditorPreferencePage_closeBraces;
addCheckBox(composite, label, PreferenceConstants.EDITOR_CLOSE_BRACES, 0);
label= PreferencesMessages.JavaEditorPreferencePage_closeJavaDocs;
master= addCheckBox(composite, label, PreferenceConstants.EDITOR_CLOSE_JAVADOCS, 0);
label= PreferencesMessages.JavaEditorPreferencePage_addJavaDocTags;
slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS, 0);
createDependency(master, slave);
}
private void createExistingSection(Composite body) {
Button existingCheck = new Button(body, SWT.RADIO);
existingCheck.setText("Existing database");
existingCheck.setSelection(true);
Controls.onSelect(existingCheck, (e) -> {
setSelection(config.EXISTING_MODE);
});
Composite composite = new Composite(body, SWT.NONE);
UI.gridLayout(composite, 1);
UI.gridData(composite, true, false);
existingViewer = new ComboViewer(composite);
UI.gridData(existingViewer.getControl(), true, false);
existingViewer.setLabelProvider(new DbLabel());
existingViewer.setContentProvider(ArrayContentProvider.getInstance());
existingViewer.addSelectionChangedListener(e -> selectDatabase());
fillExistingViewer();
}
/**
* Creates a check box button using the parents' font
*
* @param parent
* the parent to add the button to
* @param label
* the label for the button
* @param image
* the image for the button
* @param checked
* the initial checked state of the button
* @param hspan
* the horizontal span to take up in the parent composite
* @return a new checked button set to the initial checked state
*/
public static Button createCheckButton(Composite parent, String label, Image image, boolean checked, int hspan)
{
Button button = new Button(parent, SWT.CHECK);
button.setFont(parent.getFont());
button.setSelection(checked);
if (image != null)
{
button.setImage(image);
}
if (label != null)
{
button.setText(label);
}
GridData gd = new GridData();
gd.horizontalSpan = hspan;
button.setLayoutData(gd);
setButtonDimensionHint(button);
return button;
}
/**
* Aligns the buttons as right-aligned on the dialog.
*
* @param buttons the array of buttons to align
* @param width the standardized width of all the buttons
* @param margin the margin between buttons
* @param lastControl (optional) the bottom most control used for aligning the buttons relative to the bottom of the
* controls on the dialog
*/
protected static void rightAlignButtons( Button[] buttons, int width, int margin, Control lastControl ) {
for ( int i = buttons.length - 1; i >= 0; --i ) {
FormData formData = createDefaultFormData( buttons[ i ], width, margin, lastControl );
// Set the right side of the buttons (either offset from the edge, or relative to the previous button)
if ( i == buttons.length - 1 ) {
formData.left = new FormAttachment( 100, -( width + margin ) );
} else {
formData.left = new FormAttachment( buttons[ i + 1 ], -( 2 * ( width + margin ) ) - margin );
}
// Apply the layout data
buttons[ i ].setLayoutData( formData );
}
}
FilterEqualsNodeComposite(Composite parent, TmfFilterEqualsNode node) {
super(parent, node);
fNode = node;
createAspectControls();
createValueText(fNode);
new Label(this, SWT.NONE);
fIgnoreCaseButton = new Button(this, SWT.CHECK);
fIgnoreCaseButton.setSelection(fNode.isIgnoreCase());
fIgnoreCaseButton.setText(Messages.FilterViewer_IgnoreCaseButtonText);
fIgnoreCaseButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
fNode.setIgnoreCase(fIgnoreCaseButton.getSelection());
fViewer.refresh(fNode);
}
});
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
((GridLayout) parent.getLayout()).numColumns++;
Button button = new Button(parent, SWT.PUSH);
button.setText("Apply");
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
data.widthHint = Math.max(widthHint, minSize.x);
button.setLayoutData(data);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
applyChanges();
}
});
super.createButtonsForButtonBar(parent);
Shell shell = parent.getShell();
if (shell != null) {
shell.setDefaultButton(button);
}
}
protected void createRemoveButton(Composite composite) {
removeButton = new Button(composite,SWT.PUSH) ;
removeButton.setText(Messages.removeData);
removeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (!configurationViewers.getSelection().isEmpty()) {
final Object selection = ((StructuredSelection) configurationViewers.getSelection()).getFirstElement();
if(selection instanceof ConnectorConfiguration){
final Resource r = ((ConnectorConfiguration)selection).eResource() ;
final String fileName = URI.decode(r.getURI().lastSegment()) ;
final IRepositoryFileStore artifact = configurationStore.getChild(fileName, true) ;
if(artifact != null){
if(FileActionDialog.confirmDeletionQuestion(fileName)){
artifact.delete();
}
}
configurationViewers.setInput(new Object());
}
}
}
});
removeButton.setEnabled(false);
}
private void renderDirection(Shell shell) {
Group group = new Group(shell, SWT.NONE);
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 3, 1));
group.setLayout(new GridLayout(1, false));
group.setText("Direction");
directionForward = new Button(group, SWT.RADIO);
directionForward.setText("Fordward");
directionBackward = new Button(group, SWT.RADIO);
directionBackward.setText("Backwards");
directionForward.setSelection(true);
}
private void updateEnableState(boolean isCustom, final ListDialogField<IJavaProject> settingsField, Button configureCustom, BulletListBlock bulletListBlock) {
settingsField.getListControl(null).setEnabled(!isCustom);
if (isCustom) {
fEnableState= ControlEnableState.disable(settingsField.getButtonBox(null));
} else if (fEnableState != null) {
fEnableState.restore();
fEnableState= null;
}
bulletListBlock.setEnabled(isCustom);
configureCustom.setEnabled(isCustom);
}
public static Button createAddButton(Composite composite) {
GridData gridData = new GridData();
gridData.grabExcessVerticalSpace = true;
gridData.verticalAlignment = GridData.END;
gridData.widthHint = Resources.BUTTON_WIDTH;
Button button = new Button(composite, SWT.NONE);
button.setText(ResourceString.getResourceString("label.right.arrow"));
button.setLayoutData(gridData);
return button;
}
/**
* Create a check box
*
* @param numberOfColumns
*/
private void createCheckBox() {
final Button button = new Button(bottomComponent, SWT.CHECK);
button.setText(checkBoxLabel);
button.setSelection(checkBoxValue);
button.setLayoutData(new GridData(SWT.BEGINNING, SWT.BOTTOM, true, true, 1, 1));
button.addListener(SWT.Selection, e -> {
checkBoxValue = button.getSelection();
});
}
/**
* Returns a width hint for a button control.
*/
public static int getButtonWidthHint(Button button) {
/*button.setFont(JFaceResources.getDialogFont());*/
PixelConverter converter= new PixelConverter(button);
int widthHint= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
for (int i = 0; i <= 10; i++) {
Button button = new Button(shell, SWT.PUSH);
button.setText("Button " + 1);
button.setBounds(i*10, i*10, 200, 200);
button.moveAbove(null);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Control control = (Control) e.widget;
control.moveAbove(null);
}
});
}
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
private void addDropListener(Composite parent) {
LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
DropTargetAdapter dragAdapter = new DropTargetAdapter() {
@Override
public void drop(DropTargetEvent event) {
Control droppedObj = (Control) ((StructuredSelection) transfer.getSelection()).getFirstElement();
// Get the existing parent of the dragged control
Composite oldParent = droppedObj.getParent();
if (oldParent == parent) {
return;
}
if (droppedObj instanceof Label) {
System.out.println("Dropped");
}
// handle the drop
if (droppedObj instanceof Label) {
Label droppedLabel = (Label) droppedObj;
droppedLabel.setParent(parent); // Change parent
}
if (droppedObj instanceof Button) {
Button droppedButton = (Button) droppedObj;
droppedButton.setParent(parent); // Change parent
}
// request a layout pass
oldParent.requestLayout();
// If you change that to layout the layout will be correct
parent.layout();
}
};
DropTarget dropTarget = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY);
dropTarget.setTransfer(new Transfer[] { transfer });
dropTarget.addDropListener(dragAdapter);
}
private Button createAccountGroupButton(
Composite composite, Image icon, String text, Listener listener) {
Button button = new Button(composite, SWT.PUSH);
button.setImage(icon);
button.setText(text);
button.addListener(SWT.Selection, listener);
button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
return button;
}
public void setUp1() throws Exception {
Shell shell = getShell();
shell.setLayout(new GridLayout(2, true));
// row 1
button1 = new Button(shell, SWT.PUSH);
button1.setText("B1");
button1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
VCanvas c1 = new VCanvas(shell, SWT.NONE);
c1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
c1.getPanel().setLayout(new VSimpleLayout());
vbutton1 = new VButton(c1.getPanel(), SWT.PUSH);
vbutton1.setText("VB1");
// row 2
button2 = new Button(shell, SWT.PUSH);
button2.setText("B2");
button2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
VCanvas c2 = new VCanvas(shell, SWT.NONE);
c2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
c2.getPanel().setLayout(new VSimpleLayout());
vbutton2 = new VButton(c2.getPanel(), SWT.PUSH);
vbutton2.setText("VB2");
}
/**
* Update the status of the ok button to reflect the given status.
* Subclasses may override this method to update additional buttons.
*
* @param status
*/
protected void updateButtonsEnableState( IStatus status )
{
Button okButton = getOkButton( );
if ( okButton != null && !okButton.isDisposed( ) )
{
okButton.setEnabled( !status.matches( IStatus.ERROR ) );
}
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
Button ok= getButton(IDialogConstants.OK_ID);
ok.setText( RefactoringMessages.ChangeExceptionHandler_undo_button);
Button abort= createButton(parent, IDialogConstants.CANCEL_ID, RefactoringMessages.ChangeExceptionHandler_abort_button, true);
abort.moveBelow(ok);
abort.setFocus();
}
public void validatePage() {
if (targetCategory != null) {
List<NodeElement> selectedNodeElementList = new ArrayList<NodeElement>();
for (NodeElement table : this.nodeCheckMap.keySet()) {
Button selectCheckButton = (Button) this.nodeCheckMap
.get(table).getEditor();
if (selectCheckButton.getSelection()) {
selectedNodeElementList.add(table);
}
}
targetCategory.setContents(selectedNodeElementList);
}
List<VGroup> selectedCategories = new ArrayList<VGroup>();
for (VGroup category : erModel.getGroups()) {
Button button = (Button) this.categoryCheckMap.get(category).getEditor();
if (button.getSelection()) {
selectedCategories.add(category);
}
}
// categorySettings.setSelectedCategories(selectedCategories);
}
/**
* This method initializes composite
*
*/
private void createGroupListComposite(Composite parent) {
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
gridLayout.verticalSpacing = 10;
GridData gridData = new GridData();
gridData.heightHint = HEIGHT;
Composite composite = new Composite(parent, SWT.BORDER);
composite.setLayoutData(gridData);
composite.setLayout(gridLayout);
createGroup(composite);
groupAddButton = new Button(composite, SWT.NONE);
groupAddButton.setText(ResourceString
.getResourceString("label.button.group.add"));
groupEditButton = new Button(composite, SWT.NONE);
groupEditButton.setText(ResourceString
.getResourceString("label.button.group.edit"));
this.groupDeleteButton = new Button(composite, SWT.NONE);
this.groupDeleteButton.setText(ResourceString
.getResourceString("label.button.group.delete"));
this.addToGlobalGroupButton = new Button(composite, SWT.NONE);
this.addToGlobalGroupButton.setText(ResourceString
.getResourceString("label.button.add.to.global.group"));
GridData gridData3 = new GridData();
gridData3.horizontalSpan = 3;
this.addToGlobalGroupButton.setLayoutData(gridData3);
if (this.globalGroup) {
this.addToGlobalGroupButton.setVisible(false);
}
setButtonEnabled(false);
}
/**
* @param key
* @param checkBox
*
*/
protected void checkBoxChange( Button checkBox, String key )
{
dirtyProperties.put( key, Boolean.valueOf( checkBox.getSelection( ) ) );
if ( CHECKBOX_ISREQUIRED.equals( key )
|| CHECKBOX_DISTINCT.equals( key ) )
{
if ( ( isStatic( ) && !distinct.isEnabled( ) )
|| ( distinct.isEnabled( ) && !distinct.getSelection( ) ) )
{
boolean change = makeUniqueAndValid( );
if ( change )
{
if ( isStatic( ) )
{
refreshStaticValueTable( );
}
else
{
refreshDynamicValueTable( );
}
}
}
if ( getSelectedDataType( ).equals( DesignChoiceConstants.PARAM_TYPE_STRING ) )
{
clearDefaultValueChooser( checkBox.getSelection( ) );
}
handleDefaultValueModifyEvent( );
updateMessageLine( );
}
}
public RadioProfileEntry ( final DataBindingContext dbc, final Composite parent, final ProfileManager profileManager, final Profile profile, final ChartContext chartContext )
{
super ( dbc, profileManager, profile, chartContext );
this.widget = new Button ( parent, SWT.RADIO );
addBinding ( dbc.bindValue ( SWTObservables.observeText ( this.widget ), EMFObservables.observeValue ( profile, ChartPackage.Literals.PROFILE__LABEL ) ) );
this.widget.addSelectionListener ( new SelectionAdapter () {
@Override
public void widgetSelected ( final SelectionEvent e )
{
fireSelection ( RadioProfileEntry.this.widget.getSelection () );
};
} );
}
private void createFileTypeChoice(Composite composite, int cols2) {
Group group1 = new Group(composite, SWT.SHADOW_IN);
group1.setText("Model syntax");
group1.setLayout(new RowLayout(SWT.VERTICAL));
group1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 3, 1));
xtxt = new Button(group1, SWT.RADIO);
xtxt.setText("XtxtUML (custom syntax)");
xtxt.setSelection(true);
txt = new Button(group1, SWT.RADIO);
txt.setText("JtxtUML (Java syntax)");
}