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$
023: */
024: package com.bostechcorp.cbesb.ui.util;
025:
026: import java.util.ArrayList;
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.layout.FillLayout;
032: import org.eclipse.swt.layout.GridData;
033: import org.eclipse.swt.layout.GridLayout;
034: import org.eclipse.swt.widgets.Button;
035: import org.eclipse.swt.widgets.Composite;
036: import org.eclipse.swt.widgets.Display;
037: import org.eclipse.swt.widgets.Label;
038: import org.eclipse.swt.widgets.Shell;
039: import org.eclipse.swt.widgets.Text;
040: import org.eclipse.ui.PlatformUI;
041:
042: /**
043: * This class demonstrates JFace's ErrorDialog class
044: */
045: public class MessageDetailDialog {
046: private ArrayList<String> errorList = new ArrayList<String>();
047:
048: private Shell parent;
049:
050: private Text list;
051:
052: private Button buttonShow;
053:
054: private boolean state = false;
055:
056: private String title;
057:
058: private String type = TYPE_ERROR;
059:
060: private boolean flag = true;
061:
062: public static String TYPE_ERROR = "Error";
063: public static String TYPE_WARNING = "Warning";
064: public static String TYPE_HINT = "Hint";
065:
066: /**
067: * ShowError constructor
068: *
069: * @param temp
070: */
071: public MessageDetailDialog(Shell parent, ArrayList<String> temp,
072: String title, String type) {
073: // super(null);
074: this (parent, temp, title);
075: this .type = type;
076:
077: }
078:
079: public MessageDetailDialog(Shell parent, ArrayList<String> temp,
080: String title) {
081: // super(null);
082: this .errorList = temp;
083: this .parent = parent;
084: this .title = title;
085:
086: }
087:
088: /**
089: * Runs the application
090: */
091: public boolean run() {
092: Shell tempShell = new Shell(parent, SWT.BORDER | SWT.CLOSE
093: | SWT.APPLICATION_MODAL);
094: // tempShell.addDisposeListener(new DisposeListener() {
095: // public void widgetDisposed(final DisposeEvent e) {
096: // return state;
097: // }
098: // });
099: tempShell.setLayout(new FillLayout());
100: tempShell.setText(this .type);
101: createContents(tempShell);
102: tempShell.open();
103: Display display = PlatformUI.getWorkbench().getDisplay();
104: while (!tempShell.isDisposed()) {
105: if (!display.readAndDispatch()) {
106: display.sleep();
107: }
108: }
109: tempShell.dispose();
110: return state;
111: }
112:
113: protected void createContents(final Shell mainShell) {
114: Composite composite = new Composite(mainShell, SWT.NONE);
115: final GridLayout gridLayout = new GridLayout();
116: gridLayout.numColumns = 4;
117: composite.setLayout(gridLayout);
118:
119: Button buttonCancel;
120:
121: Button buttonOk;
122:
123: final Label thereExistErrorLabel = new Label(composite,
124: SWT.NONE);
125: thereExistErrorLabel.setLayoutData(new GridData(SWT.FILL,
126: SWT.CENTER, false, false));
127: thereExistErrorLabel.setText(title);
128: new Label(composite, SWT.NONE);
129: new Label(composite, SWT.NONE);
130: new Label(composite, SWT.NONE);
131: new Label(composite, SWT.NONE);
132: buttonOk = new Button(composite, SWT.NONE);
133: final GridData gridData = new GridData(SWT.FILL, SWT.CENTER,
134: false, false);
135: gridData.widthHint = 67;
136: buttonOk.setLayoutData(gridData);
137: buttonOk.addSelectionListener(new SelectionAdapter() {
138: public void widgetSelected(final SelectionEvent e) {
139: state = true;
140: mainShell.dispose();
141: }
142: });
143: buttonOk.setText("OK");
144: buttonCancel = new Button(composite, SWT.NONE);
145: final GridData gridData_1 = new GridData(SWT.RIGHT, SWT.CENTER,
146: false, false);
147: gridData_1.widthHint = 65;
148: buttonCancel.setLayoutData(gridData_1);
149: buttonCancel.addSelectionListener(new SelectionAdapter() {
150: public void widgetSelected(final SelectionEvent e) {
151: state = false;
152: mainShell.dispose();
153: }
154: });
155: buttonCancel.setText("Cancel");
156:
157: // Create the button to launch the error dialog
158: buttonShow = new Button(composite, SWT.PUSH);
159: buttonShow.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER,
160: false, false));
161: buttonShow.setText("Show Detail");
162:
163: buttonShow.addSelectionListener(new SelectionAdapter() {
164: public void widgetSelected(SelectionEvent event) {
165: if (flag) {
166: list.setVisible(true);
167: String temp = "";
168: for (int i = 0; i < errorList.size(); i++) {
169: temp = temp + errorList.get(i) + "\n";
170: }
171: list.setText(temp);
172: mainShell.pack();
173: }
174: flag = false;
175: }
176: });
177:
178: // Create a big text box to accept error text
179:
180: list = new Text(composite, SWT.MULTI | SWT.BORDER
181: | SWT.V_SCROLL);
182: list.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
183: false, 4, 1));
184: list.setVisible(false);
185:
186: mainShell.pack();
187: // return composite;
188: }
189: }
|