package com.weecode.plugin.comics.ui.dialogs; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import com.weecode.plugin.comics.model.eo.Title; /** * * @author Jason Kusnier and Tim Hollosy * */ public class TitleDialog extends TitleAreaDialog { private Text nameText; private Text formatText; private Title title = null; public TitleDialog(Shell parentShell) { super(parentShell); } /** * Create the dialog * @param parentShell */ public TitleDialog(Shell parentShell, Title title) { super(parentShell); this.title = title; } /** * Create contents of the dialog * @param parent */ @Override protected Control createDialogArea(Composite parent) { Composite area = (Composite) super.createDialogArea(parent); Composite container = new Composite(area, SWT.NONE); final GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; container.setLayout(gridLayout); container.setLayoutData(new GridData(GridData.FILL_BOTH)); final Label formatLabel = new Label(container, SWT.NONE); formatLabel.setText("Format"); formatText = new Text(container, SWT.BORDER); final GridData gd_formatText = new GridData(SWT.FILL, SWT.CENTER, true, false); formatText.setLayoutData(gd_formatText); final Label nameLabel = new Label(container, SWT.NONE); nameLabel.setText("Name"); nameText = new Text(container, SWT.BORDER); final GridData gd_nameText = new GridData(SWT.FILL, SWT.CENTER, true, false); nameText.setLayoutData(gd_nameText); setTitle("Setup the Title"); if (title != null) { formatText.setText(title.getFormat() != null ? title.getFormat() : ""); nameText.setText(title.getName() != null ? title.getName() : ""); } return area; } /** * Create contents of the button bar * @param parent */ @Override protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); } /** * Return the initial size of the dialog */ @Override protected Point getInitialSize() { return new Point(500, 375); } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText("Title"); } @Override protected void okPressed() { if (title == null) title = new Title(); title.setFormat(formatText.getText()); title.setName(nameText.getText()); super.okPressed(); } public Title getTitle() { return title; } }