1 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 43 public class AttributeTypeEditor extends FormEditor 44 { 45 46 private static Logger logger = Logger.getLogger( AttributeTypeEditor.class ); 47 48 49 public static final String ID = Activator.PLUGIN_ID + ".view.attributeTypeEditor"; 51 52 private AttributeTypeEditorOverviewPage overview; 53 54 55 private AttributeTypeEditorSourceCodePage sourceCode; 56 57 58 private AttributeTypeEditorUsedByPage usedBy; 59 60 61 private boolean dirty = false; 62 63 64 private AttributeType originalAttributeType; 65 66 67 private AttributeType modifiedAttributeType; 68 69 70 private IPageChangedListener pageChangedListener = new IPageChangedListener() 71 { 72 public void pageChanged( PageChangedEvent event ) 73 { 74 Object 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" ) ); 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 101 public AttributeTypeEditor() 102 { 103 super(); 104 } 105 106 107 113 @Override 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 e ) 128 { 129 } 131 132 addPageChangedListener( pageChangedListener ); 133 } 134 135 136 141 @Override 142 public void dispose() 143 { 144 originalAttributeType.removeEditor( this ); 145 } 146 147 148 153 @Override 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" ); } 169 } 170 171 172 177 @Override 178 public void doSave( IProgressMonitor monitor ) 179 { 180 if ( !sourceCode.canLeaveThePage() ) 182 { 183 notifyError( Messages.getString( "AttributeTypeEditor.Souce_Code_Error_cannot_save_object_class" ) ); 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 203 @Override 204 public void doSaveAs() 205 { 206 } 207 208 209 214 @Override 215 public boolean isSaveAsAllowed() 216 { 217 return false; 218 } 219 220 221 226 @Override 227 public boolean isDirty() 228 { 229 return this.dirty; 230 } 231 232 233 239 public void setDirty( boolean dirty ) 240 { 241 this.dirty = dirty; 242 editorDirtyStateChanged(); 243 } 244 245 246 252 public AttributeType getOriginalAttributeType() 253 { 254 return originalAttributeType; 255 } 256 257 258 264 public AttributeType getModifiedAttributeType() 265 { 266 return modifiedAttributeType; 267 } 268 269 270 276 public void setModifiedAttributeType( AttributeType modifiedAttributeType ) 277 { 278 this.modifiedAttributeType = modifiedAttributeType; 279 } 280 281 282 288 private void notifyError( String 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 |