KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > ViewUtils


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20 package org.apache.directory.ldapstudio.schemas.view;
21
22
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.graphics.Color;
25 import org.eclipse.swt.widgets.MessageBox;
26 import org.eclipse.ui.PlatformUI;
27
28
29 /**
30  * This Helper Class contains useful methods used to create the UI.
31  *
32  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
33  * @version $Rev$, $Date$
34  */

35 public class ViewUtils
36 {
37     /** The Black Color */
38     public static final Color COLOR_BLACK = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()
39         .getDisplay().getSystemColor( SWT.COLOR_BLACK );
40
41     /** The Red Color */
42     public static final Color COLOR_RED = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay()
43         .getSystemColor( SWT.COLOR_RED );
44
45
46     /**
47      * Concatenates all aliases in a String format. Aliases are separated with a comma (',')
48      *
49      * @param aliases
50      * the aliases to concatenate
51      * @return
52      * a String representing all aliases
53      */

54     public static String JavaDoc concateAliases( String JavaDoc[] aliases )
55     {
56         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
57         if ( aliases.length > 0 )
58         {
59             sb.append( aliases[0] );
60             for ( int i = 1; i < aliases.length; i++ )
61             {
62                 sb.append( ", " ); //$NON-NLS-1$
63
sb.append( aliases[i] );
64             }
65         }
66
67         return sb.toString();
68     }
69
70
71     /**
72      * Verifies that the given name is syntaxely correct according to the RFC 2252
73      * (Lightweight Directory Access Protocol (v3): Attribute Syntax Definitions).
74      *
75      * @param name
76      * the name to test
77      * @return
78      * true if the name is correct, false if the name is not correct.
79      */

80     public static boolean verifyName( String JavaDoc name )
81     {
82         return name.matches( "[a-zA-Z]+[a-zA-Z0-9;-]*" ); //$NON-NLS-1$
83
}
84
85
86     /**
87      * Displays an Error Message Box with the given title and message.
88      *
89      * @param title
90      * the title of the window
91      * @param message
92      * the message to display
93      * @return
94      * the ID of the button that was selected to dismiss
95      * the message box (e.g. SWT.OK, SWT.CANCEL, etc...)
96      */

97     public static int displayErrorMessageBox( String JavaDoc title, String JavaDoc message )
98     {
99         return displayMessageBox( SWT.OK | SWT.ICON_ERROR, title, message );
100     }
101
102
103     /**
104      * Displays a Information Message Box with the given title and message.
105      *
106      * @param title
107      * the title of the window
108      * @param message
109      * the message to display
110      * @return
111      * the ID of the button that was selected to dismiss
112      * the message box (e.g. SWT.OK, SWT.CANCEL, etc...)
113      */

114     public static int displayWarningMessageBox( String JavaDoc title, String JavaDoc message )
115     {
116         return displayMessageBox( SWT.OK | SWT.ICON_WARNING, title, message );
117     }
118
119
120     /**
121      * Displays a Information Message Box with the given title and message.
122      *
123      * @param title
124      * the title of the window
125      * @param message
126      * the message to display
127      * @return
128      * the ID of the button that was selected to dismiss
129      * the message box (e.g. SWT.OK, SWT.CANCEL, etc...)
130      */

131     public static int displayInformationMessageBox( String JavaDoc title, String JavaDoc message )
132     {
133         return displayMessageBox( SWT.OK | SWT.ICON_INFORMATION, title, message );
134     }
135
136
137     /**
138      * Displays a Information Question Box with the given title and message.
139      *
140      * @param buttonStyle
141      * the style of the buttons of the dialog (e.g. SWT.OK, SWT.CANCEL, etc...)
142      * @param title
143      * the title of the window
144      * @param message
145      * the message to display
146      * @return
147      * the ID of the button that was selected to dismiss
148      * the message box (e.g. SWT.OK, SWT.CANCEL, etc...)
149      */

150     public static int displayQuestionMessageBox( int buttonStyle, String JavaDoc title, String JavaDoc message )
151     {
152         return displayMessageBox( SWT.ICON_QUESTION | buttonStyle, title, message );
153     }
154
155
156     /**
157      * Displays a Message Box with the given style, title and message.
158      *
159      * @param style
160      * the style of dialog
161      * @param title
162      * the title of the window
163      * @param message
164      * the message to display
165      * @return
166      * the ID of the button that was selected to dismiss
167      * the message box (e.g. SWT.OK, SWT.CANCEL, etc...)
168      */

169     private static int displayMessageBox( int style, String JavaDoc title, String JavaDoc message )
170     {
171         MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), style );
172         messageBox.setText( title );
173         messageBox.setMessage( message );
174         return messageBox.open();
175     }
176
177 }
178
Popular Tags