KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > editors > attributeType > AttributeTypeEditor


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
21 package org.apache.directory.ldapstudio.schemas.view.editors.attributeType;
22
23
24 import org.apache.directory.ldapstudio.schemas.Activator;
25 import org.apache.directory.ldapstudio.schemas.Messages;
26 import org.apache.directory.ldapstudio.schemas.model.AttributeType;
27 import org.apache.log4j.Logger;
28 import org.eclipse.core.runtime.IProgressMonitor;
29 import org.eclipse.jface.dialogs.IPageChangedListener;
30 import org.eclipse.jface.dialogs.PageChangedEvent;
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.widgets.MessageBox;
33 import org.eclipse.ui.IEditorInput;
34 import org.eclipse.ui.IEditorSite;
35 import org.eclipse.ui.PartInitException;
36 import org.eclipse.ui.PlatformUI;
37 import org.eclipse.ui.forms.editor.FormEditor;
38
39
40 /**
41  * This class is the Attribute Type Editor main class
42  */

43 public class AttributeTypeEditor extends FormEditor
44 {
45     /** The logger */
46     private static Logger logger = Logger.getLogger( AttributeTypeEditor.class );
47
48     /** The ID of the Editor */
49     public static final String JavaDoc ID = Activator.PLUGIN_ID + ".view.attributeTypeEditor"; //$NON-NLS-1$
50

51     /** The Overview page */
52     private AttributeTypeEditorOverviewPage overview;
53
54     /** The Source Code page */
55     private AttributeTypeEditorSourceCodePage sourceCode;
56
57     /** The Used By page */
58     private AttributeTypeEditorUsedByPage usedBy;
59
60     /** The dirty state flag */
61     private boolean dirty = false;
62
63     /** The original attribute type */
64     private AttributeType originalAttributeType;
65
66     /** The attribute type used to save modifications */
67     private AttributeType modifiedAttributeType;
68
69     /** The listener for page changed */
70     private IPageChangedListener pageChangedListener = new IPageChangedListener()
71     {
72         public void pageChanged( PageChangedEvent event )
73         {
74             Object JavaDoc selectedPage = event.getSelectedPage();
75
76             if ( selectedPage instanceof AttributeTypeEditorOverviewPage )
77             {
78                 if ( !sourceCode.canLeaveThePage() )
79                 {
80                     notifyError( Messages
81                         .getString( "AttributeTypeEditor.Souce_Code_Error_cannot_return_to_Overview_page" ) ); //$NON-NLS-1$
82
return;
83                 }
84
85                 overview.refreshUI();
86             }
87             else if ( selectedPage instanceof AttributeTypeEditorSourceCodePage )
88             {
89                 if ( sourceCode.canLeaveThePage() )
90                 {
91                     sourceCode.refreshUI();
92                 }
93             }
94         }
95     };
96
97
98     /**
99      * Default constructor
100      */

101     public AttributeTypeEditor()
102     {
103         super();
104     }
105
106
107     /*
108      * (non-Javadoc)
109      *
110      * @see org.eclipse.ui.forms.editor.FormEditor#init(org.eclipse.ui.IEditorSite,
111      * org.eclipse.ui.IEditorInput)
112      */

113     @Override JavaDoc
114     public void init( IEditorSite site, IEditorInput input ) throws PartInitException
115     {
116         setSite( site );
117         setInput( input );
118         setPartName( input.getName() );
119
120         originalAttributeType = ( ( AttributeTypeEditorInput ) getEditorInput() ).getAttributeType();
121         originalAttributeType.setEditor( this );
122
123         try
124         {
125             modifiedAttributeType = ( AttributeType ) originalAttributeType.clone();
126         }
127         catch ( CloneNotSupportedException JavaDoc e )
128         {
129             // Will never occurr.
130
}
131
132         addPageChangedListener( pageChangedListener );
133     }
134
135
136     /*
137      * (non-Javadoc)
138      *
139      * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
140      */

141     @Override JavaDoc
142     public void dispose()
143     {
144         originalAttributeType.removeEditor( this );
145     }
146
147
148     /*
149      * (non-Javadoc)
150      *
151      * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
152      */

153     @Override JavaDoc
154     protected void addPages()
155     {
156         try
157         {
158             overview = new AttributeTypeEditorOverviewPage( this );
159             addPage( overview );
160             sourceCode = new AttributeTypeEditorSourceCodePage( this );
161             addPage( sourceCode );
162             usedBy = new AttributeTypeEditorUsedByPage( this );
163             addPage( usedBy );
164         }
165         catch ( PartInitException e )
166         {
167             logger.debug( "error when adding pages" ); //$NON-NLS-1$
168
}
169     }
170
171
172     /*
173      * (non-Javadoc)
174      *
175      * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
176      */

177     @Override JavaDoc
178     public void doSave( IProgressMonitor monitor )
179     {
180         // Verifying if there is an error on the source code page
181
if ( !sourceCode.canLeaveThePage() )
182         {
183             notifyError( Messages.getString( "AttributeTypeEditor.Souce_Code_Error_cannot_save_object_class" ) ); //$NON-NLS-1$
184
monitor.setCanceled( true );
185             return;
186         }
187
188         originalAttributeType.update( modifiedAttributeType );
189
190         setPartName( getEditorInput().getName() );
191         if ( !monitor.isCanceled() )
192         {
193             setDirty( false );
194         }
195     }
196
197
198     /*
199      * (non-Javadoc)
200      *
201      * @see org.eclipse.ui.part.EditorPart#doSaveAs()
202      */

203     @Override JavaDoc
204     public void doSaveAs()
205     {
206     }
207
208
209     /*
210      * (non-Javadoc)
211      *
212      * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
213      */

214     @Override JavaDoc
215     public boolean isSaveAsAllowed()
216     {
217         return false;
218     }
219
220
221     /*
222      * (non-Javadoc)
223      *
224      * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
225      */

226     @Override JavaDoc
227     public boolean isDirty()
228     {
229         return this.dirty;
230     }
231
232
233     /**
234      * Sets the dirty state of the editor
235      *
236      * @param dirty
237      * the dirty state
238      */

239     public void setDirty( boolean dirty )
240     {
241         this.dirty = dirty;
242         editorDirtyStateChanged();
243     }
244
245
246     /**
247      * Gets the original attribute type.
248      *
249      * @return
250      * the original attribute type
251      */

252     public AttributeType getOriginalAttributeType()
253     {
254         return originalAttributeType;
255     }
256
257
258     /**
259      * Gets the modified attribute type.
260      *
261      * @return
262      * the modified attribute type
263      */

264     public AttributeType getModifiedAttributeType()
265     {
266         return modifiedAttributeType;
267     }
268
269
270     /**
271      * Sets the modified attribute type.
272      *
273      * @param modifiedAttributeType
274      * the modified attribute type to set.
275      */

276     public void setModifiedAttributeType( AttributeType modifiedAttributeType )
277     {
278         this.modifiedAttributeType = modifiedAttributeType;
279     }
280
281
282     /**
283      * Opens an error dialog displaying the given message.
284      *
285      * @param message
286      * the message to display
287      */

288     private void notifyError( String JavaDoc message )
289     {
290         MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK
291             | SWT.ICON_ERROR );
292         messageBox.setMessage( message );
293         messageBox.open();
294     }
295 }
296
Popular Tags