KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > aciitemeditor > dialogs > ACIItemDialog


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.aciitemeditor.dialogs;
21
22
23 import java.text.ParseException JavaDoc;
24
25 import org.apache.directory.ldapstudio.aciitemeditor.ACIItemValueWithContext;
26 import org.apache.directory.ldapstudio.aciitemeditor.Activator;
27 import org.apache.directory.ldapstudio.aciitemeditor.widgets.ACIItemTabFolderComposite;
28 import org.eclipse.core.runtime.IStatus;
29 import org.eclipse.core.runtime.Status;
30 import org.eclipse.jface.dialogs.Dialog;
31 import org.eclipse.jface.dialogs.ErrorDialog;
32 import org.eclipse.jface.dialogs.IDialogConstants;
33 import org.eclipse.jface.dialogs.MessageDialog;
34 import org.eclipse.swt.SWT;
35 import org.eclipse.swt.layout.GridData;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Control;
38 import org.eclipse.swt.widgets.Shell;
39
40
41 /**
42  * The main dialog of the ACI item editor.
43  *
44  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
45  * @version $Rev$, $Date$
46  */

47 public class ACIItemDialog extends Dialog
48 {
49
50     /** The context containing the initial value, passed by the constructor */
51     private ACIItemValueWithContext context;
52
53     /** The resulting value returned by getACIItemValue() */
54     private String JavaDoc returnValue;
55
56     /** The child composite with the tabs */
57     private ACIItemTabFolderComposite tabFolderComposite;
58
59
60     /**
61      * Creates a new instance of ACIItemDialog.
62      *
63      * @param parentShell the shell
64      * @param context the context
65      */

66     public ACIItemDialog( Shell parentShell, ACIItemValueWithContext context )
67     {
68         super( parentShell );
69         super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
70
71         assert context != null;
72         assert context.getACIItemValue() != null;
73         assert context.getConnection() != null;
74
75         this.context = context;
76
77         this.returnValue = null;
78     }
79
80
81     /**
82      * Sets the dialog image and text.
83      *
84      * {@inheritDoc}
85      */

86     protected void configureShell( Shell shell )
87     {
88         super.configureShell( shell );
89         shell.setText( Messages.getString( "ACIItemDialog.dialog.text" ) ); //$NON-NLS-1$
90
shell.setImage( Activator.getDefault().getImage( Messages.getString( "ACIItemDialog.dialog.icon" ) ) ); //$NON-NLS-1$
91
}
92
93
94     /**
95      * {@inheritDoc}
96      *
97      * This implementation additionally adds the Format button.
98      */

99     protected Control createButtonBar( Composite parent )
100     {
101         Composite composite = ( Composite ) super.createButtonBar( parent );
102         super.createButton( composite, 987654321, Messages.getString( "ACIItemDialog.button.format" ), false ); //$NON-NLS-1$
103
super.createButton( composite, 876543210, Messages.getString( "ACIItemDialog.button.checkSyntax" ), false ); //$NON-NLS-1$
104
return composite;
105     }
106
107
108     /**
109      * {@inheritDoc}
110      *
111      * This implementation checks if the Format button was pressed.
112      */

113     protected void buttonPressed( int buttonId )
114     {
115         if ( buttonId == 987654321 )
116         {
117             tabFolderComposite.format();
118         }
119         if ( buttonId == 876543210 )
120         {
121             try
122             {
123                 tabFolderComposite.getInput();
124                 MessageDialog
125                     .openInformation(
126                         getShell(),
127                         Messages.getString( "ACIItemDialog.syntaxOk.title" ), Messages.getString( "ACIItemDialog.syntaxOk.text" ) ); //$NON-NLS-1$ //$NON-NLS-2$
128
}
129             catch ( ParseException JavaDoc pe )
130             {
131                 IStatus status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages
132                     .getString( "ACIItemDialog.error.invalidSyntax" ), pe ); //$NON-NLS-1$
133
ErrorDialog.openError( getShell(), Messages.getString( "ACIItemDialog.error.title" ), null, status ); //$NON-NLS-1$
134
}
135         }
136
137         // call super implementation
138
super.buttonPressed( buttonId );
139     }
140
141
142     /**
143      * Reimplementation: Checks for valid syntax first and sets the return value.
144      */

145     protected void okPressed()
146     {
147         try
148         {
149             this.returnValue = tabFolderComposite.getInput();
150             super.okPressed();
151         }
152         catch ( ParseException JavaDoc pe )
153         {
154             IStatus status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages
155                 .getString( "ACIItemDialog.error.invalidSyntax" ), pe ); //$NON-NLS-1$
156
ErrorDialog.openError( getShell(), Messages.getString( "ACIItemDialog.error.title" ), null, status ); //$NON-NLS-1$
157
}
158     }
159
160
161     /**
162      * Creates the tabFolderComposite.
163      *
164      * @param parent the parent
165      *
166      * @return the control
167      */

168     protected Control createDialogArea( Composite parent )
169     {
170         Composite composite = ( Composite ) super.createDialogArea( parent );
171         GridData gd = new GridData( GridData.FILL_BOTH );
172         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 4 / 3;
173         gd.heightHint = convertVerticalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 4 / 3;
174         composite.setLayoutData( gd );
175
176         tabFolderComposite = new ACIItemTabFolderComposite( composite, SWT.NONE );
177
178         // set initial value
179
if ( context != null )
180         {
181             tabFolderComposite.setContext( context );
182             tabFolderComposite.setInput( context.getACIItemValue() );
183         }
184
185         applyDialogFont( composite );
186         return composite;
187     }
188
189
190     /**
191      * Returns the string representation of the ACI item. Returns
192      * null if Cancel button was pressed.
193      *
194      * @return the string representation of the ACI item or null
195      */

196     public String JavaDoc getACIItemValue()
197     {
198         return returnValue;
199     }
200
201 }
202
Popular Tags