org.eclipse.ease.modules.unittest.ui.dialogs.AddRemarkDialog.java Source code

Java tutorial

Introduction

Here is the source code for org.eclipse.ease.modules.unittest.ui.dialogs.AddRemarkDialog.java

Source

/*******************************************************************************
 * Copyright (c) 2015 Christian Pontesegger and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Christian Pontesegger - initial API and implementation
 *******************************************************************************/
package org.eclipse.ease.modules.unittest.ui.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
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;

public class AddRemarkDialog extends Dialog {
    private Text fTxtTitle;
    private Text fTxtDescription;

    private String fTitle = "";
    private String fDescription = "";

    /**
     * Create the dialog.
     *
     * @param parentShell
     */
    public AddRemarkDialog(final Shell parentShell) {
        super(parentShell);
    }

    /**
     * Create contents of the dialog.
     *
     * @param parent
     */
    @Override
    protected Control createDialogArea(final Composite parent) {

        final Composite container = (Composite) super.createDialogArea(parent);
        final GridLayout gridLayout = (GridLayout) container.getLayout();
        gridLayout.numColumns = 3;

        final Label lblTitle = new Label(container, SWT.NONE);
        lblTitle.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblTitle.setText("Title:");

        fTxtTitle = new Text(container, SWT.BORDER);
        fTxtTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

        final Label lblDescription = new Label(container, SWT.NONE);
        lblDescription.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
        lblDescription.setText("Description:");

        fTxtDescription = new Text(container, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
        fTxtDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

        return container;
    }

    /**
     * Create contents of the button bar.
     *
     * @param parent
     */
    @Override
    protected void createButtonsForButtonBar(final Composite parent) {
        final Button clearButton = createButton(parent, IDialogConstants.BACK_ID, "Clear", false);
        clearButton.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                fTxtTitle.setText("");
                fTxtDescription.setText("");
            }

            @Override
            public void widgetDefaultSelected(final SelectionEvent e) {
            }
        });

        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(450, 300);
    }

    @Override
    protected void okPressed() {
        fTitle = fTxtTitle.getText();
        fDescription = fTxtDescription.getText();

        super.okPressed();
    }

    public String getTitle() {
        return fTitle;
    }

    public String getDescription() {
        return fDescription;
    }
}