001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: Message.java 3512 2006-12-08 05:52:03Z yling $
023: */
024: package com.bostechcorp.cbesb.ui.util.ucm;
025:
026: import java.util.List;
027:
028: import org.eclipse.swt.SWT;
029: import org.eclipse.swt.events.SelectionAdapter;
030: import org.eclipse.swt.events.SelectionEvent;
031: import org.eclipse.swt.widgets.Button;
032: import org.eclipse.swt.widgets.Combo;
033: import org.eclipse.swt.widgets.Dialog;
034: import org.eclipse.swt.widgets.Display;
035: import org.eclipse.swt.widgets.Label;
036: import org.eclipse.swt.widgets.Shell;
037: import org.eclipse.swt.widgets.Text;
038:
039: import com.bostechcorp.cbesb.ui.util.resource.SWTResourceManager;
040:
041: public class UcmSelectionDialog extends Dialog {
042:
043: private Combo combo;
044:
045: protected Object result;
046:
047: protected Shell shell;
048:
049: private List list;
050:
051: private String name;
052:
053: private Text text;
054:
055: /**
056: * Create the dialog
057: *
058: * @param parent
059: * @param style
060: */
061: public UcmSelectionDialog(Shell parent, int style) {
062: super (parent, style);
063: }
064:
065: /**
066: * Create the dialog
067: *
068: * @param parent
069: */
070: public UcmSelectionDialog(Shell parent, List list, String name,
071: Text text) {
072: this (parent, SWT.NONE);
073: this .list = list;
074: this .name = name;
075: this .text = text;
076: }
077:
078: /**
079: * Open the dialog
080: *
081: * @return the result
082: */
083: public Object open() {
084: createContents();
085: shell.open();
086: shell.layout();
087: Display display = getParent().getDisplay();
088: while (!shell.isDisposed()) {
089: if (!display.readAndDispatch())
090: display.sleep();
091: }
092: return result;
093: }
094:
095: /**
096: * Create contents of the dialog
097: */
098: protected void createContents() {
099: shell = new Shell(getParent(), SWT.DIALOG_TRIM
100: | SWT.APPLICATION_MODAL);
101: shell.setSize(380, 286);
102: shell.setText(name + " Selection");
103:
104: final Label selectionLabel = new Label(shell, SWT.NONE);
105: selectionLabel.setFont(SWTResourceManager.getFont("Arial", 16,
106: SWT.BOLD));
107: selectionLabel.setText(name + " Selection");
108: selectionLabel.setBounds(28, 25, 215, 30);
109:
110: combo = new Combo(shell, SWT.READ_ONLY);
111: combo.setBounds(30, 89, 300, 20);
112: if (list != null && list.size() > 0) {
113: for (int i = 0; i < list.size(); i++) {
114: combo.add(list.get(i).toString());
115:
116: }
117: combo.setText(combo.getItem(0));
118: }
119:
120: final Button okButton = new Button(shell, SWT.NONE);
121: okButton.setText("OK");
122: okButton.setBounds(95, 165, 75, 20);
123:
124: final Button cancelButton = new Button(shell, SWT.NONE);
125: cancelButton.setBounds(208, 165, 75, 20);
126: cancelButton.setText("Cancel");
127: //
128: okButton.addSelectionListener(new SelectionAdapter() {
129:
130: public void widgetSelected(SelectionEvent e) {
131:
132: text.setText(combo.getText());
133: shell.dispose();
134: }
135:
136: });
137:
138: cancelButton.addSelectionListener(new SelectionAdapter() {
139:
140: public void widgetSelected(SelectionEvent e) {
141:
142: shell.dispose();
143: }
144:
145: });
146: }
147:
148: }
|