KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > util > tree > ErrorWarningDialog


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * CLIF
20  *
21  * Contact: clif@objectweb.org
22  */

23 package org.objectweb.clif.scenario.util.isac.util.tree;
24
25 import java.util.Vector JavaDoc;
26
27 import org.apache.log4j.Category;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.custom.StyledText;
30 import org.eclipse.swt.events.SelectionEvent;
31 import org.eclipse.swt.events.SelectionListener;
32 import org.eclipse.swt.layout.GridData;
33 import org.eclipse.swt.layout.GridLayout;
34 import org.eclipse.swt.widgets.Button;
35 import org.eclipse.swt.widgets.Dialog;
36 import org.eclipse.swt.widgets.Display;
37 import org.eclipse.swt.widgets.Shell;
38 import org.objectweb.clif.scenario.util.isac.loadprofile.gui.Size;
39
40 /**
41  * This class is the dialog which permit to show errors and warnings to the user
42  *
43  * @author JC Meillaud
44  * @author A Peyrard
45  */

46 public class ErrorWarningDialog extends Dialog {
47     // logger
48
static Category cat = Category.getInstance(ErrorWarningDialog.class
49             .getName());
50
51     // text of the dialog
52
private static final String JavaDoc DIALOG_TITLE = "Errors and Warnings which append during last process" ;
53     private static final String JavaDoc BOK_LABEL = "OK" ;
54     
55     // default size
56
private static final Size DEFAULT_SIZE = new Size(500,250) ;
57     
58     private Vector JavaDoc lines ;
59     private StyledText styledText ;
60     private Button bOk ;
61     private Shell shell ;
62
63     /**
64      * Build a new errors-warnings dialog
65      *
66      * @param shell
67      * The shell to open the dialog
68      * @param lines
69      * The lines to be printed
70      */

71     public ErrorWarningDialog(Shell shell, Vector JavaDoc lines) {
72         super(shell);
73         // init infos
74
this.lines = lines;
75     }
76
77     /**
78      * Open the dialog
79      */

80     public void open() {
81         this.shell = new Shell(getParent(), SWT.DIALOG_TRIM
82                 | SWT.APPLICATION_MODAL);
83         shell.setText(DIALOG_TITLE);
84         shell.setSize(DEFAULT_SIZE.getWidth(), DEFAULT_SIZE.getHeight());
85         // set the layout of the shell
86
GridLayout gl = new GridLayout();
87         gl.numColumns = 1;
88         shell.setLayout(gl);
89         // create the styled text to print the errors lines
90
this.styledText = new StyledText(shell, SWT.BORDER | SWT.MULTI
91                 | SWT.V_SCROLL | SWT.H_SCROLL);
92         // set the grid data for this element
93
GridData gridData = new GridData() ;
94         gridData.grabExcessHorizontalSpace = true ;
95         gridData.grabExcessVerticalSpace = true ;
96         gridData.horizontalAlignment = GridData.FILL ;
97         gridData.verticalAlignment = GridData.FILL ;
98         this.styledText.setLayoutData(gridData) ;
99         // set the text
100
this.setText() ;
101         
102         // add the ok button
103
this.bOk = new Button(shell, SWT.FLAT) ;
104         this.bOk.setText(BOK_LABEL) ;
105         // add a listener, when we click on the button we exit the dialog
106
this.bOk.addSelectionListener(new SelectionListener() {
107             public void widgetDefaultSelected(SelectionEvent arg0) {
108                 shell.close() ;
109             }
110             public void widgetSelected(SelectionEvent arg0) {
111                 shell.close() ;
112             }
113         }) ;
114         // set the grid data for the button
115
GridData bGrid = new GridData() ;
116         bGrid.grabExcessHorizontalSpace = true ;
117         bGrid.horizontalAlignment = GridData.FILL ;
118         this.bOk.setLayoutData(bGrid) ;
119
120         shell.open();
121         Display display = getParent().getDisplay();
122         while (!shell.isDisposed()) {
123             if (!display.readAndDispatch())
124                 display.sleep();
125         }
126     }
127     
128     /**
129      * This method is used to set the text in the styled text, each element of
130      * the errors vector will be a line
131      */

132     private void setText() {
133         for (int i=0;i<this.lines.size();i++) {
134             this.styledText.append((String JavaDoc)this.lines.elementAt(i)+"\n") ;
135         }
136     }
137 }
Popular Tags