/*
 * Created on 2003/06/15
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package jp.sourceforge.projects.ee2e.core.cdt;

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.SWT;
import org.eclipse.jface.resource.*;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.swt.events.*;

import jp.sourceforge.projects.ee2e.core.EE2EDebug;
import jp.sourceforge.projects.ee2e.core.EE2EPlugin;

/**
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 *
 * @author Toshikazu Ando [ ando@park.ruru.ne.jp ]
 */
public class EE2ESharpDialog extends Dialog {

    /**
     * @param parent
     */
    public EE2ESharpDialog(Shell parent) {
        super(parent);
    }

    /**
     * @param parent
     * @param style
     */
    public EE2ESharpDialog(Shell parent, int style) {
        super(parent, style);
    }
    public void open (java.util.Collection collection) {
        Shell parent = this.getParent();
        this.shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.SYSTEM_MODAL);
        // Your code goes here (widget creation, set result, etc).

        this.shell.setText(EE2EPlugin.getResourceString("action.c.sharp"));
        this.shell.setToolTipText(EE2EPlugin.getResourceString("action.c.sharp.tooltip"));
        //
        ImageDescriptor imageDescripter;
        try {
            URL prefix =
                new URL(
                    EE2EPlugin.getDefault().getDescriptor().getInstallURL(),
                    "icons/");
            imageDescripter =
                ImageDescriptor.createFromURL(new URL(prefix, "ee2e.gif"));
            this.shell.setImage(imageDescripter.createImage());
        } catch (MalformedURLException e) {
            /*EMPTY*/
        }

        //
        GridLayout layout = new GridLayout();
        layout.numColumns = 2;
        this.shell.setLayout(layout);
        //
        Label label = new Label(this.shell, SWT.LEFT);
        label.setText(this.shell.getToolTipText());
        GridData grid1 = new GridData();
        grid1.horizontalSpan = 2;
        label.setLayoutData(grid1);
        //
        this.combo = new org.eclipse.swt.widgets.Combo(this.shell,SWT.READ_ONLY);
        java.util.Iterator ite = collection.iterator();
        while (ite.hasNext()) {
            this.combo.add((String) ite.next());
        }
        grid1 = new GridData();
        grid1.horizontalSpan = 2;
        grid1.verticalAlignment = GridData.FILL;
        this.combo.setLayoutData(grid1);
        //
        this.isIf = new Button(this.shell, SWT.RADIO);
        this.isIf.setText("#if delete");
        this.isIf.setSelection(true);
        grid1 = new GridData();
        this.isIf.setLayoutData(grid1);
        //
        Button isElse = new Button(this.shell, SWT.RADIO);
        isElse.setText("#ifndef delete");
        isElse.setSelection(false);
        grid1 = new GridData();
        isElse.setLayoutData(grid1);
        //
        Button chancelButton = new Button(this.shell, SWT.PUSH);
        chancelButton.setText("Cancel");
        chancelButton.addSelectionListener(cancelListener);
        grid1 = new GridData();
        chancelButton.setLayoutData(grid1);
        //
        Button okButton = new Button(this.shell, SWT.PUSH);
        okButton.setText("OK");
        okButton.addSelectionListener(okListener);
        grid1 = new GridData();
        okButton.setLayoutData(grid1);
        //
        this.shell.setSize(256 + 124,124);
        this.shell.open();
        Display display = parent.getDisplay();
        while (!this.shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            } 
        }
    }
    public String getTarget() {
        return this.target;
    }
    public boolean getIsIfOrElse() {
        return this.isIforElse;
    }
    protected SelectionListener okListener = new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            EE2EDebug.printf(10,"okListener");
            isIforElse = EE2ESharpDialog.this.isIf.getSelection();
            int index = EE2ESharpDialog.this.combo.getSelectionIndex();
            if(0 <= index) {
                String [] targets = EE2ESharpDialog.this.combo.getItems();
                String answer = targets[index];
                EE2EDebug.printf(10,"target=" + answer);
                EE2ESharpDialog.this.target = answer;
            } else {
                EE2ESharpDialog.this.target = null;
            }
            EE2ESharpDialog.this.shell.close();
        }
        public void widgetDefaultSelected(SelectionEvent e) {
            /*EMPTY*/
        }
    };
    protected SelectionListener cancelListener = new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            EE2EDebug.printf(10,"cancelListener");
            EE2ESharpDialog.this.target = null;
            EE2ESharpDialog.this.shell.close();
        }
        public void widgetDefaultSelected(SelectionEvent e) {
            /*EMPTY*/
        }
    };
    //
    private boolean isIforElse = true;
    private String target = null;
    private Button isIf;
    private org.eclipse.swt.widgets.Combo combo;
    private Shell shell;
}
