下面列出了org.eclipse.swt.widgets.DateTime#setLayoutData ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void createPartControl(Composite parent) {
GridLayout layout = new GridLayout();
layout.numColumns = 2;
parent.setLayout(layout);
new Label(parent, SWT.NONE).setText("Summary");
Text text = new Text(parent, SWT.BORDER);
text.setText(todo.getSummary());
text.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
new Label(parent, SWT.NONE).setText("Description");
Text lastName = new Text(parent, SWT.BORDER);
lastName.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
lastName.setText(todo.getDescription());
new Label(parent, SWT.NONE).setText("Done");
Button doneBtn = new Button(parent, SWT.CHECK);
doneBtn.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
doneBtn.setSelection(todo.isDone());
new Label(parent, SWT.NONE).setText("Due Date");
DateTime dueDate = new DateTime(parent, SWT.CHECK);
dueDate.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
Date date = todo.getDueDate();
dueDate.setDate(date.getYear(), date.getMonth(), date.getDay());
}
protected void createDatePicker( int style )
{
btnDate = new Button( this, SWT.CHECK );
btnDate.addListener( SWT.Selection, this );
pickerDate = new DateTime( this, SWT.DATE | style );
pickerDate.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
pickerDate.addListener( SWT.Selection, this );
btnTime = new Button( this, SWT.CHECK );
btnTime.addListener( SWT.Selection, this );
pickerTime = new DateTime( this, SWT.TIME | style );
pickerTime.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
pickerTime.addListener( SWT.Selection, this );
}
private Composite createCalendarArea(Composite parent){
Composite composite = new Composite(parent, SWT.NONE);
GridLayout gd = new GridLayout(1, false);
gd.marginLeft = 2; // SWT BUG
composite.setLayout(gd);
dateSelection = new DateTime(composite, SWT.CALENDAR);
dateSelection.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
Composite dateComposite = new Composite(composite, SWT.NONE);
dateComposite.setLayout(new GridLayout(2, true));
dateComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label label = new Label(dateComposite, SWT.NONE);
label.setText("Zeitpunkt");
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
timeSelection = new DateTime(dateComposite, SWT.TIME);
timeSelection.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
timeSelection.setTime(date.get(Calendar.HOUR_OF_DAY), date.get(Calendar.MINUTE),
date.get(Calendar.SECOND));
dateSelection.setDate(date.get(Calendar.YEAR), date.get(Calendar.MONTH),
date.get(Calendar.DAY_OF_MONTH));
getShell().setText(Messages.DateTimeSelectorDialog_enterDate); //$NON-NLS-1$
return composite;
}
private Composite createDefaultArea(Composite parent){
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
Label label = new Label(composite, SWT.NONE);
label.setText("Zeitpunkt");
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
Composite dateComposite = new Composite(composite, SWT.NONE);
dateComposite.setLayout(new GridLayout(2, true));
dateComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
timeSelection = new DateTime(dateComposite, SWT.TIME);
timeSelection.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
dateSelection = new DateTime(dateComposite, SWT.CALENDAR);
dateSelection.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
timeSelection.setTime(date.get(Calendar.HOUR_OF_DAY), date.get(Calendar.MINUTE),
date.get(Calendar.SECOND));
dateSelection.setDate(date.get(Calendar.YEAR), date.get(Calendar.MONTH),
date.get(Calendar.DAY_OF_MONTH));
getShell().setText(Messages.DateTimeSelectorDialog_enterDate); //$NON-NLS-1$
return composite;
}
public static DateTime date(Composite parent, String label, String property, ModelEditor<?> editor,
FormToolkit toolkit) {
toolkit.createLabel(parent, label, SWT.NONE);
DateTime dateTime = new DateTime(parent, SWT.DATE | SWT.DROP_DOWN);
GridData data = new GridData();
data.widthHint = 150;
dateTime.setLayoutData(data);
editor.getBinding().onDate(() -> editor.getModel(), property, dateTime);
new CommentControl(parent, toolkit, property, editor.getComments());
return dateTime;
}