KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > apacheds > configuration > dialogs > AttributeValueDialog


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.apacheds.configuration.dialogs;
21
22
23 import org.apache.directory.ldapstudio.apacheds.configuration.editor.AttributeValueObject;
24 import org.eclipse.jface.dialogs.Dialog;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.ModifyEvent;
27 import org.eclipse.swt.events.ModifyListener;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.swt.widgets.Shell;
34 import org.eclipse.swt.widgets.Text;
35 import org.eclipse.ui.PlatformUI;
36
37
38 /**
39  * This class implements the Dialog for Attribute Value.
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class AttributeValueDialog extends Dialog
45 {
46     /** The Attribute Value Object */
47     private AttributeValueObject attributeValueObject;
48
49     /** The dirty flag */
50     private boolean dirty = false;
51
52     // UI Fields
53
private Text attributeText;
54     private Text valueText;
55
56
57     /**
58      * Creates a new instance of AttributeValueDialog.
59      */

60     public AttributeValueDialog( AttributeValueObject attributeValueObject )
61     {
62         super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() );
63         this.attributeValueObject = attributeValueObject;
64     }
65
66
67     /* (non-Javadoc)
68      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
69      */

70     protected void configureShell( Shell newShell )
71     {
72         super.configureShell( newShell );
73         newShell.setText( "Attribute Value Dialog" );
74     }
75
76
77     /* (non-Javadoc)
78      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
79      */

80     protected Control createDialogArea( Composite parent )
81     {
82         Composite composite = new Composite( parent, SWT.NONE );
83         GridLayout layout = new GridLayout( 2, false );
84         composite.setLayout( layout );
85         composite.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) );
86
87         Label attributeLabel = new Label( composite, SWT.NONE );
88         attributeLabel.setText( "Attribute:" );
89
90         attributeText = new Text( composite, SWT.BORDER );
91         attributeText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
92
93         Label valueLabel = new Label( composite, SWT.NONE );
94         valueLabel.setText( "Value:" );
95
96         valueText = new Text( composite, SWT.BORDER );
97         valueText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
98
99         initFromInput();
100         addListeners();
101
102         return composite;
103     }
104
105
106     /**
107      * Initializes the UI from the input.
108      */

109     private void initFromInput()
110     {
111         String JavaDoc attribute = attributeValueObject.getAttribute();
112         attributeText.setText( ( attribute == null ) ? "" : attribute );
113
114         Object JavaDoc value = attributeValueObject.getValue();
115         valueText.setText( ( value == null ) ? "" : value.toString() );
116     }
117
118
119     /**
120      * Adds listeners to the UI Fields.
121      */

122     private void addListeners()
123     {
124         attributeText.addModifyListener( new ModifyListener()
125         {
126             public void modifyText( ModifyEvent e )
127             {
128                 dirty = true;
129             }
130         } );
131
132         valueText.addModifyListener( new ModifyListener()
133         {
134             public void modifyText( ModifyEvent e )
135             {
136                 dirty = true;
137             }
138         } );
139     }
140
141
142     /* (non-Javadoc)
143      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
144      */

145     protected void okPressed()
146     {
147         attributeValueObject.setId( attributeText.getText() );
148         attributeValueObject.setValue( valueText.getText() );
149
150         super.okPressed();
151     }
152
153
154     /**
155      * Gets the Attribute Value Object.
156      *
157      * @return
158      * the Attribute Value Object
159      */

160     public AttributeValueObject getAttributeValueObject()
161     {
162         return attributeValueObject;
163     }
164
165
166     /**
167      * Returns the dirty flag of the dialog.
168      *
169      * @return
170      * the dirty flag of the dialog
171      */

172     public boolean isDirty()
173     {
174         return dirty;
175     }
176 }
177
Popular Tags