KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > editors > objectClass > ObjectClassEditor


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.objectClass;
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.ObjectClass;
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 ObjectClass Editor main class
42  */

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

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

98     public ObjectClassEditor()
99     {
100         super();
101     }
102
103
104     /* (non-Javadoc)
105      * @see org.eclipse.ui.forms.editor.FormEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
106      */

107     @Override JavaDoc
108     public void init( IEditorSite site, IEditorInput input ) throws PartInitException
109     {
110         setSite( site );
111         setInput( input );
112         setPartName( input.getName() );
113
114         originalObjectClass = ( ( ObjectClassEditorInput ) getEditorInput() ).getObjectClass();
115         originalObjectClass.setEditor( this );
116
117         try
118         {
119             modifiedObjectClass = ( ObjectClass ) originalObjectClass.clone();
120         }
121         catch ( CloneNotSupportedException JavaDoc e )
122         {
123             // Will never occurr.
124
}
125
126         addPageChangedListener( pageChangedListener );
127     }
128
129
130     /* (non-Javadoc)
131      * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
132      */

133     @Override JavaDoc
134     public void dispose()
135     {
136         originalObjectClass.removeEditor( this );
137     }
138
139
140     /* (non-Javadoc)
141      * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
142      */

143     @Override JavaDoc
144     protected void addPages()
145     {
146         try
147         {
148             overview = new ObjectClassEditorOverviewPage( this ); //$NON-NLS-1$ //$NON-NLS-2$
149
addPage( overview );
150             sourceCode = new ObjectClassEditorSourceCodePage( this ); //$NON-NLS-1$ //$NON-NLS-2$
151
addPage( sourceCode );
152         }
153         catch ( PartInitException e )
154         {
155             logger.debug( "error when adding pages" ); //$NON-NLS-1$
156
}
157     }
158
159
160     /* (non-Javadoc)
161      * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
162      */

163     @Override JavaDoc
164     public void doSave( IProgressMonitor monitor )
165     {
166         // Verifying if there is an error on the source code page
167
if ( !sourceCode.canLeaveThePage() )
168         {
169             notifyError( Messages.getString( "ObjectClassEditor.Source_Code_Error_cannot_save_object_class" ) ); //$NON-NLS-1$
170
monitor.setCanceled( true );
171             return;
172         }
173
174         originalObjectClass.update( modifiedObjectClass );
175
176         setPartName( getEditorInput().getName() );
177         if ( !monitor.isCanceled() )
178         {
179             setDirty( false );
180         }
181     }
182
183
184     /* (non-Javadoc)
185      * @see org.eclipse.ui.part.EditorPart#doSaveAs()
186      */

187     @Override JavaDoc
188     public void doSaveAs()
189     {
190     }
191
192
193     /* (non-Javadoc)
194      * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
195      */

196     @Override JavaDoc
197     public boolean isSaveAsAllowed()
198     {
199         return false;
200     }
201
202
203     /* (non-Javadoc)
204      * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
205      */

206     @Override JavaDoc
207     public boolean isDirty()
208     {
209         return dirty;
210     }
211
212
213     /**
214      * Sets the dirty state of the editor
215      *
216      * @param dirty
217      * the dirty state
218      */

219     public void setDirty( boolean dirty )
220     {
221         this.dirty = dirty;
222         editorDirtyStateChanged();
223     }
224
225
226     /**
227      * Gets the original object class.
228      *
229      * @return
230      * the original object class
231      */

232     public ObjectClass getOriginalObjectClass()
233     {
234         return originalObjectClass;
235     }
236
237
238     /**
239      * Gets the modified object class.
240      *
241      * @return
242      * the modified object class
243      */

244     public ObjectClass getModifiedObjectClass()
245     {
246         return modifiedObjectClass;
247     }
248
249
250     /**
251      * Sets the modified object class.
252      *
253      * @param modifiedObjectClass
254      * the modified object class to set.
255      */

256     public void setModifiedObjectClass( ObjectClass modifiedObjectClass )
257     {
258         this.modifiedObjectClass = modifiedObjectClass;
259     }
260
261
262     /**
263      * Opens an error dialog displaying the given message.
264      *
265      * @param message
266      * the message to display
267      */

268     private void notifyError( String JavaDoc message )
269     {
270         MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK
271             | SWT.ICON_ERROR );
272         messageBox.setMessage( message );
273         messageBox.open();
274     }
275 }
276
Popular Tags