in plugins/ldapbrowser.ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java [275:473]
public void entryUpdated( EntryModificationEvent event )
{
IEntry modifiedEntry = event.getModifiedEntry();
IBrowserConnection browserConnection = modifiedEntry.getBrowserConnection();
IEntry originalEntry = browserConnection.getEntryFromCache( modifiedEntry.getDn() );
if ( modifiedEntry == originalEntry )
{
// an original entry has been modified, check if we could update the editors
// if the OSC editor is not dirty we could update the working copy
IEntry oscSharedReferenceCopy = oscSharedReferenceCopies.get( originalEntry );
IEntry oscSharedWorkingCopy = oscSharedWorkingCopies.get( originalEntry );
if ( ( oscSharedReferenceCopy != null ) && ( oscSharedWorkingCopy != null ) )
{
LdifFile refDiff = Utils.computeDiff( originalEntry, oscSharedReferenceCopy );
if ( refDiff != null )
{
// diff between original entry and reference copy
LdifFile workDiff = Utils.computeDiff( oscSharedReferenceCopy, oscSharedWorkingCopy );
if ( workDiff == null )
{
// no changes on working copy, update
updateOscSharedReferenceCopy( originalEntry );
updateOscSharedWorkingCopy( originalEntry );
// inform all OSC editors
List<IEntryEditor> oscEditors = getOscEditors( oscSharedWorkingCopy );
for ( IEntryEditor editor : oscEditors )
{
editor.workingCopyModified( event.getSource() );
}
}
else
{
// changes on working copy, ask before update
IWorkbenchPartReference reference = getActivePartRef( getOscEditors( oscSharedWorkingCopy ) );
if ( reference != null )
{
askUpdateSharedWorkingCopy( reference, originalEntry, oscSharedWorkingCopy, event
.getSource() );
}
}
}
else
{
// no diff betweeen original entry and reference copy, check if editor is dirty
LdifFile workDiff = Utils.computeDiff( oscSharedReferenceCopy, oscSharedWorkingCopy );
if ( workDiff != null )
{
// changes on working copy, ask before update
IWorkbenchPartReference reference = getActivePartRef( getOscEditors( oscSharedWorkingCopy ) );
if ( reference != null )
{
askUpdateSharedWorkingCopy( reference, originalEntry, oscSharedWorkingCopy, event
.getSource() );
}
}
}
}
// always update auto-save working copies, if necessary
IEntry autoSaveSharedReferenceCopy = autoSaveSharedReferenceCopies.get( originalEntry );
IEntry autoSaveSharedWorkingCopy = autoSaveSharedWorkingCopies.get( originalEntry );
if ( ( autoSaveSharedReferenceCopy != null ) && ( autoSaveSharedWorkingCopy != null ) )
{
LdifFile diff = Utils.computeDiff( originalEntry, autoSaveSharedReferenceCopy );
if ( diff != null )
{
updateAutoSaveSharedReferenceCopy( originalEntry );
updateAutoSaveSharedWorkingCopy( originalEntry );
List<IEntryEditor> editors = getAutoSaveEditors( autoSaveSharedWorkingCopy );
for ( IEntryEditor editor : editors )
{
editor.workingCopyModified( event.getSource() );
}
}
}
// check all editors: if the input does not exist any more then close the editor
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
// Collecting editor references to close
List<IEditorReference> editorReferences = new ArrayList<>();
for ( IEditorReference ref : activePage.getEditorReferences() )
{
IEntryEditor editor = getEntryEditor( ref );
if ( editor != null )
{
EntryEditorInput entryEditorInput = editor.getEntryEditorInput();
if ( entryEditorInput != null )
{
IEntry resolvedEntry = entryEditorInput.getResolvedEntry();
if ( ( editor != null ) && ( resolvedEntry != null ) )
{
IBrowserConnection bc = resolvedEntry.getBrowserConnection();
Dn dn = resolvedEntry.getDn();
if ( bc.getEntryFromCache( dn ) == null )
{
editorReferences.add( ref );
}
}
}
}
}
// Closing the corresponding editor references
if ( !editorReferences.isEmpty() )
{
activePage.closeEditors( editorReferences.toArray( new IEditorReference[0] ), false );
}
}
else if ( oscSharedWorkingCopies.containsKey( originalEntry )
&& ( oscSharedWorkingCopies.get( originalEntry ) == modifiedEntry ) )
{
// OSC working copy has been modified: inform OSC editors
IEntry oscSharedWorkingCopy = oscSharedWorkingCopies.get( originalEntry );
List<IEntryEditor> oscEditors = getOscEditors( oscSharedWorkingCopy );
for ( IEntryEditor editor : oscEditors )
{
editor.workingCopyModified( event.getSource() );
}
}
else if ( autoSaveSharedWorkingCopies.containsValue( originalEntry )
&& ( autoSaveSharedWorkingCopies.get( originalEntry ) == modifiedEntry ) )
{
// auto-save working copy has been modified: save and inform all auto-save editors
IEntry autoSaveSharedReferenceCopy = autoSaveSharedReferenceCopies.get( originalEntry );
IEntry autoSaveSharedWorkingCopy = autoSaveSharedWorkingCopies.get( originalEntry );
// sanity check: never save if event source is the EntryEditorManager
if ( event.getSource() instanceof EntryEditorManager )
{
return;
}
// only save if we receive a real value modification event
if ( !( ( event instanceof ValueAddedEvent ) ||
( event instanceof ValueDeletedEvent ) ||
( event instanceof ValueModifiedEvent ) ||
( event instanceof ValueRenamedEvent ) ||
( event instanceof ValueMultiModificationEvent ) ) )
{
return;
}
// consistency check: don't save if there is an empty value, silently return in that case
for ( IAttribute attribute : autoSaveSharedWorkingCopy.getAttributes() )
{
for ( IValue value : attribute.getValues() )
{
if ( value.isEmpty() )
{
return;
}
}
}
LdifFile diff = Utils.computeDiff( autoSaveSharedReferenceCopy, autoSaveSharedWorkingCopy );
if ( diff != null )
{
// remove entry from map, reduces number of fired events
autoSaveSharedReferenceCopies.remove( originalEntry );
autoSaveSharedWorkingCopies.remove( originalEntry );
UpdateEntryRunnable runnable = new UpdateEntryRunnable( originalEntry, diff
.toFormattedString( LdifFormatParameters.DEFAULT ) );
RunnableContextRunner.execute( runnable, null, true );
// put entry back to map
autoSaveSharedReferenceCopies.put( originalEntry, autoSaveSharedReferenceCopy );
autoSaveSharedWorkingCopies.put( originalEntry, autoSaveSharedWorkingCopy );
// don't care if status is ok or not: always update
updateAutoSaveSharedReferenceCopy( originalEntry );
updateAutoSaveSharedWorkingCopy( originalEntry );
List<IEntryEditor> editors = getAutoSaveEditors( autoSaveSharedWorkingCopy );
for ( IEntryEditor editor : editors )
{
editor.workingCopyModified( event.getSource() );
}
}
}
}