1 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 43 public class ObjectClassEditor extends FormEditor 44 { 45 46 private static Logger logger = Logger.getLogger( ObjectClassEditor.class ); 47 48 49 public static final String ID = Activator.PLUGIN_ID + ".view.objectClassEditor"; 51 52 private ObjectClassEditorOverviewPage overview; 53 54 55 private ObjectClassEditorSourceCodePage sourceCode; 56 57 58 private boolean dirty = false; 59 60 61 private ObjectClass originalObjectClass; 62 63 64 private ObjectClass modifiedObjectClass; 65 66 67 private IPageChangedListener pageChangedListener = new IPageChangedListener() 68 { 69 public void pageChanged( PageChangedEvent event ) 70 { 71 Object 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" ) ); 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 98 public ObjectClassEditor() 99 { 100 super(); 101 } 102 103 104 107 @Override 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 e ) 122 { 123 } 125 126 addPageChangedListener( pageChangedListener ); 127 } 128 129 130 133 @Override 134 public void dispose() 135 { 136 originalObjectClass.removeEditor( this ); 137 } 138 139 140 143 @Override 144 protected void addPages() 145 { 146 try 147 { 148 overview = new ObjectClassEditorOverviewPage( this ); addPage( overview ); 150 sourceCode = new ObjectClassEditorSourceCodePage( this ); addPage( sourceCode ); 152 } 153 catch ( PartInitException e ) 154 { 155 logger.debug( "error when adding pages" ); } 157 } 158 159 160 163 @Override 164 public void doSave( IProgressMonitor monitor ) 165 { 166 if ( !sourceCode.canLeaveThePage() ) 168 { 169 notifyError( Messages.getString( "ObjectClassEditor.Source_Code_Error_cannot_save_object_class" ) ); 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 187 @Override 188 public void doSaveAs() 189 { 190 } 191 192 193 196 @Override 197 public boolean isSaveAsAllowed() 198 { 199 return false; 200 } 201 202 203 206 @Override 207 public boolean isDirty() 208 { 209 return dirty; 210 } 211 212 213 219 public void setDirty( boolean dirty ) 220 { 221 this.dirty = dirty; 222 editorDirtyStateChanged(); 223 } 224 225 226 232 public ObjectClass getOriginalObjectClass() 233 { 234 return originalObjectClass; 235 } 236 237 238 244 public ObjectClass getModifiedObjectClass() 245 { 246 return modifiedObjectClass; 247 } 248 249 250 256 public void setModifiedObjectClass( ObjectClass modifiedObjectClass ) 257 { 258 this.modifiedObjectClass = modifiedObjectClass; 259 } 260 261 262 268 private void notifyError( String 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 |