You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2009/10/01 17:06:37 UTC
svn commit: r820680 - in /directory/studio/trunk:
ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/wizards/
ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/
ldapbrowser-core/src/main/jav...
Author: seelmann
Date: Thu Oct 1 15:06:36 2009
New Revision: 820680
URL: http://svn.apache.org/viewvc?rev=820680&view=rev
Log:
DIRSTUDIO-515:
- update/reset entry editor after error
- ask for update if an dirty entry editor is refreshed
- use event source to avoid event loop
- fixed revert action in LDIF entry editor
- renamed some methods
Modified:
directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/wizards/EditEntryWizard.java
directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryModificationEvent.java
directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EventRegistry.java
directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/CompoundModification.java
directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorInput.java
directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java
directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/IEntryEditor.java
directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/EntryEditor.java
directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditor.java
directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditorDocumentProvider.java
Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/wizards/EditEntryWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/wizards/EditEntryWizard.java?rev=820680&r1=820679&r2=820680&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/wizards/EditEntryWizard.java (original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/wizards/EditEntryWizard.java Thu Oct 1 15:06:36 2009
@@ -98,7 +98,7 @@
*/
public boolean performFinish()
{
- new CompoundModification().replaceAttributes( prototypeEntry, selectedEntry );
+ new CompoundModification().replaceAttributes( prototypeEntry, selectedEntry, this );
return true;
}
Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryModificationEvent.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryModificationEvent.java?rev=820680&r1=820679&r2=820680&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryModificationEvent.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryModificationEvent.java Thu Oct 1 15:06:36 2009
@@ -33,6 +33,8 @@
*/
public abstract class EntryModificationEvent
{
+ /** The event source */
+ protected Object source;
/** The connection. */
protected IBrowserConnection connection;
@@ -75,4 +77,26 @@
return modifiedEntry;
}
+
+ /**
+ * Gets the event source.
+ *
+ * @return the event source, may be null
+ */
+ public Object getSource()
+ {
+ return source;
+ }
+
+
+ /**
+ * Sets the source.
+ *
+ * @param source the new source
+ */
+ public void setSource( Object source )
+ {
+ this.source = source;
+ }
+
}
Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EventRegistry.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EventRegistry.java?rev=820680&r1=820679&r2=820680&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EventRegistry.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EventRegistry.java Thu Oct 1 15:06:36 2009
@@ -226,6 +226,7 @@
*/
public static void fireEntryUpdated( final EntryModificationEvent entryUpdateEvent, final Object source )
{
+ entryUpdateEvent.setSource( source );
EventRunnableFactory<EntryUpdateListener> factory = new EventRunnableFactory<EntryUpdateListener>()
{
public EventRunnable createEventRunnable( final EntryUpdateListener listener )
Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/CompoundModification.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/CompoundModification.java?rev=820680&r1=820679&r2=820680&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/CompoundModification.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/CompoundModification.java Thu Oct 1 15:06:36 2009
@@ -314,7 +314,7 @@
* @param fromEntry
* @param toEntry
*/
- public void replaceAttributes( IEntry fromEntry, IEntry toEntry )
+ public void replaceAttributes( IEntry fromEntry, IEntry toEntry, Object source )
{
EventRegistry.suspendEventFiringInCurrentThread();
for ( IAttribute attribute : toEntry.getAttributes() )
@@ -336,7 +336,7 @@
EventRegistry.resumeEventFiringInCurrentThread();
EntryModificationEvent event = new AttributesInitializedEvent( toEntry );
- EventRegistry.fireEntryUpdated( event, this );
+ EventRegistry.fireEntryUpdated( event, source );
}
Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorInput.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorInput.java?rev=820680&r1=820679&r2=820680&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorInput.java (original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorInput.java Thu Oct 1 15:06:36 2009
@@ -235,18 +235,30 @@
* to the directory server.
*
* @param handleError the handle error
+ * @param editor the entry editor
*
* @return the status or null if there was nothing to save
*/
public IStatus saveSharedWorkingCopy( boolean handleError, IEntryEditor editor )
{
- IStatus status = BrowserUIPlugin.getDefault().getEntryEditorManager().saveSharedWorkingCopyDirty(
+ IStatus status = BrowserUIPlugin.getDefault().getEntryEditorManager().saveSharedWorkingCopy(
getResolvedEntry(), handleError, editor );
return status;
}
/**
+ * Resets the shared reference copy and the shared working copy.
+ *
+ * @param editor the entry editor
+ */
+ public void resetSharedWorkingCopy( IEntryEditor editor )
+ {
+ BrowserUIPlugin.getDefault().getEntryEditorManager().resetSharedWorkingCopy( getResolvedEntry(), editor );
+ }
+
+
+ /**
* Gets the entry input, may be null.
*
* @return the entry input or null
Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java?rev=820680&r1=820679&r2=820680&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java (original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java Thu Oct 1 15:06:36 2009
@@ -58,6 +58,7 @@
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IWorkbenchPart;
@@ -421,25 +422,14 @@
private Map<IEntry, IEntry> autoSaveSharedWorkingCopies = new HashMap<IEntry, IEntry>();
- // IEntry getSharedReferenceCopy( IEntry entry )
- // {
- // EntryEditorUtils.ensureAttributesInitialized( entry );
- //
- // if ( !oscSharedReferenceCopies.containsKey( entry ) )
- // {
- // oscSharedReferenceCopies.put( entry, new CompoundModification().cloneEntry( entry ) );
- // }
- // return oscSharedReferenceCopies.get( entry );
- // }
- //
- //
private void updateOscSharedReferenceCopy( IEntry entry )
{
+ IEntry referenceEntry = oscSharedReferenceCopies.remove( entry );
EntryEditorUtils.ensureAttributesInitialized( entry );
- IEntry referenceEntry = oscSharedReferenceCopies.get( entry );
EventRegistry.suspendEventFiringInCurrentThread();
- new CompoundModification().replaceAttributes( entry, referenceEntry );
+ new CompoundModification().replaceAttributes( entry, referenceEntry, this );
EventRegistry.resumeEventFiringInCurrentThread();
+ oscSharedReferenceCopies.put( entry, referenceEntry );
}
@@ -447,7 +437,7 @@
{
EntryEditorUtils.ensureAttributesInitialized( entry );
IEntry workingCopy = oscSharedWorkingCopies.get( entry );
- new CompoundModification().replaceAttributes( entry, workingCopy );
+ new CompoundModification().replaceAttributes( entry, workingCopy, this );
}
@@ -456,7 +446,7 @@
EntryEditorUtils.ensureAttributesInitialized( entry );
IEntry workingCopy = autoSaveSharedReferenceCopies.get( entry );
EventRegistry.suspendEventFiringInCurrentThread();
- new CompoundModification().replaceAttributes( entry, workingCopy );
+ new CompoundModification().replaceAttributes( entry, workingCopy, this );
EventRegistry.resumeEventFiringInCurrentThread();
}
@@ -465,7 +455,7 @@
{
EntryEditorUtils.ensureAttributesInitialized( entry );
IEntry workingCopy = autoSaveSharedWorkingCopies.get( entry );
- new CompoundModification().replaceAttributes( entry, workingCopy );
+ new CompoundModification().replaceAttributes( entry, workingCopy, this );
}
@@ -570,7 +560,7 @@
}
- IStatus saveSharedWorkingCopyDirty( IEntry originalEntry, boolean handleError, IEntryEditor editor )
+ IStatus saveSharedWorkingCopy( IEntry originalEntry, boolean handleError, IEntryEditor editor )
{
if ( editor == null || !editor.isAutoSave() )
{
@@ -597,12 +587,120 @@
return null;
}
+
+ void resetSharedWorkingCopy( IEntry originalEntry, IEntryEditor editor )
+ {
+ if ( editor == null || !editor.isAutoSave() )
+ {
+ IEntry referenceCopy = oscSharedReferenceCopies.get( originalEntry );
+ IEntry workingCopy = oscSharedWorkingCopies.get( originalEntry );
+ if ( referenceCopy != null && workingCopy != null )
+ {
+ updateOscSharedReferenceCopy( originalEntry );
+ updateOscSharedWorkingCopy( originalEntry );
+ }
+ }
+ }
+
+
+ private void askUpdateSharedWorkingCopy( IWorkbenchPartReference partRef, IEntry originalEntry,
+ IEntry oscSharedWorkingCopy, Object source )
+ {
+ MessageDialog dialog = new MessageDialog(
+ partRef.getPart( false ).getSite().getShell(),
+ "Entry Changed",
+ null,
+ "The entry has been changed in the directory server. Do you want to replace the editor contents with these changes?",
+ MessageDialog.QUESTION, new String[]
+ { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0 );
+ int result = dialog.open();
+ if ( result == 0 )
+ {
+ // update reference copy and working copy
+ updateOscSharedReferenceCopy( originalEntry );
+ updateOscSharedWorkingCopy( originalEntry );
+
+ // inform all OSC editors
+ List<IEntryEditor> oscEditors = getOscEditors( oscSharedWorkingCopy );
+ for ( IEntryEditor oscEditor : oscEditors )
+ {
+ oscEditor.workingCopyModified( source );
+ }
+ }
+ else
+ {
+ // only update the reference copy
+ updateOscSharedReferenceCopy( originalEntry );
+ }
+ }
+
+
+ private void cleanupCopies( IWorkbenchPartReference partRef )
+ {
+ // cleanup unused copies (OSC + auto-save)
+ Set<IEntry> oscEntries = new HashSet<IEntry>();
+ Set<IEntry> autoSaveEntries = new HashSet<IEntry>();
+ IEditorReference[] editorReferences = partRef.getPage().getEditorReferences();
+ for ( IEditorReference ref : editorReferences )
+ {
+ IEntryEditor editor = getEntryEditor( ref );
+ if ( editor != null )
+ {
+ EntryEditorInput input = editor.getEntryEditorInput();
+ if ( input != null )
+ {
+ IEntry entry = input.getResolvedEntry();
+ if ( editor.isAutoSave() )
+ {
+ autoSaveEntries.add( entry );
+ }
+ else
+ {
+ oscEntries.add( entry );
+ }
+ }
+ }
+ }
+ for ( Iterator<IEntry> it = oscSharedReferenceCopies.keySet().iterator(); it.hasNext(); )
+ {
+ IEntry entry = it.next();
+ if ( !oscEntries.contains( entry ) )
+ {
+ it.remove();
+ oscSharedWorkingCopies.remove( entry );
+ }
+ }
+ for ( Iterator<IEntry> it = oscSharedWorkingCopies.keySet().iterator(); it.hasNext(); )
+ {
+ IEntry entry = it.next();
+ if ( !oscEntries.contains( entry ) )
+ {
+ it.remove();
+ }
+ }
+ for ( Iterator<IEntry> it = autoSaveSharedReferenceCopies.keySet().iterator(); it.hasNext(); )
+ {
+ IEntry entry = it.next();
+ if ( !autoSaveEntries.contains( entry ) )
+ {
+ it.remove();
+ }
+ }
+ for ( Iterator<IEntry> it = autoSaveSharedWorkingCopies.keySet().iterator(); it.hasNext(); )
+ {
+ IEntry entry = it.next();
+ if ( !autoSaveEntries.contains( entry ) )
+ {
+ it.remove();
+ }
+ }
+ }
+
private IPartListener2 partListener = new IPartListener2()
{
public void partActivated( IWorkbenchPartReference partRef )
{
-
- partClosed( partRef );
+ cleanupCopies( partRef );
IEntryEditor editor = getEntryEditor( partRef );
if ( editor != null )
@@ -626,7 +724,7 @@
int result = dialog.open();
if ( result == 0 )
{
- saveSharedWorkingCopyDirty( originalEntry, true, null );
+ saveSharedWorkingCopy( originalEntry, true, null );
}
}
}
@@ -644,32 +742,7 @@
oscSharedWorkingCopy );
if ( workDiff != null )
{
- MessageDialog dialog = new MessageDialog(
- partRef.getPart( false ).getSite().getShell(),
- "Entry Changed",
- null,
- "The entry has been changed in the directory server. Do you want to replace the editor contents with these changes?",
- MessageDialog.QUESTION, new String[]
- { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0 );
- int result = dialog.open();
- if ( result == 0 )
- {
- // update reference copy and working copy
- updateOscSharedReferenceCopy( originalEntry );
- updateOscSharedWorkingCopy( originalEntry );
-
- // inform all OSC editors
- List<IEntryEditor> oscEditors = getOscEditors( oscSharedWorkingCopy );
- for ( IEntryEditor oscEditor : oscEditors )
- {
- oscEditor.workingCopyModified();
- }
- }
- else
- {
- // only update the reference copy
- updateOscSharedReferenceCopy( originalEntry );
- }
+ askUpdateSharedWorkingCopy( partRef, originalEntry, oscSharedWorkingCopy, null );
}
}
}
@@ -686,69 +759,13 @@
public void partClosed( IWorkbenchPartReference partRef )
{
- // cleanup unused copies (OSC + auto-save)
- Set<IEntry> oscEntries = new HashSet<IEntry>();
- Set<IEntry> autoSaveEntries = new HashSet<IEntry>();
- IEditorReference[] editorReferences = partRef.getPage().getEditorReferences();
- for ( IEditorReference ref : editorReferences )
- {
- IEntryEditor editor = getEntryEditor( ref );
- if ( editor != null )
- {
- EntryEditorInput input = editor.getEntryEditorInput();
- if ( input != null )
- {
- IEntry entry = input.getResolvedEntry();
- if ( editor.isAutoSave() )
- {
- autoSaveEntries.add( entry );
- }
- else
- {
- oscEntries.add( entry );
- }
- }
- }
- }
- for ( Iterator<IEntry> it = oscSharedReferenceCopies.keySet().iterator(); it.hasNext(); )
- {
- IEntry entry = it.next();
- if ( !oscEntries.contains( entry ) )
- {
- it.remove();
- oscSharedWorkingCopies.remove( entry );
- }
- }
- for ( Iterator<IEntry> it = oscSharedWorkingCopies.keySet().iterator(); it.hasNext(); )
- {
- IEntry entry = it.next();
- if ( !oscEntries.contains( entry ) )
- {
- it.remove();
- }
- }
- for ( Iterator<IEntry> it = autoSaveSharedReferenceCopies.keySet().iterator(); it.hasNext(); )
- {
- IEntry entry = it.next();
- if ( !autoSaveEntries.contains( entry ) )
- {
- it.remove();
- }
- }
- for ( Iterator<IEntry> it = autoSaveSharedWorkingCopies.keySet().iterator(); it.hasNext(); )
- {
- IEntry entry = it.next();
- if ( !autoSaveEntries.contains( entry ) )
- {
- it.remove();
- }
- }
+ cleanupCopies( partRef );
}
public void partInputChanged( IWorkbenchPartReference partRef )
{
- partClosed( partRef );
+ cleanupCopies( partRef );
}
@@ -807,7 +824,22 @@
List<IEntryEditor> oscEditors = getOscEditors( oscSharedWorkingCopy );
for ( IEntryEditor editor : oscEditors )
{
- editor.workingCopyModified();
+ editor.workingCopyModified( event.getSource() );
+ }
+ }
+ else
+ {
+ List<IEntryEditor> oscEditors = getOscEditors( oscSharedWorkingCopy );
+ for ( IEntryEditor entryEditor : oscEditors )
+ {
+ IWorkbenchPart part = ( IWorkbenchPart ) entryEditor;
+ IEditorPart activeEditor = part.getSite().getPage().getActiveEditor();
+ if ( part == activeEditor )
+ {
+ IWorkbenchPartReference reference = part.getSite().getPage().getReference( part );
+ askUpdateSharedWorkingCopy( reference, originalEntry, oscSharedWorkingCopy, event
+ .getSource() );
+ }
}
}
}
@@ -826,7 +858,7 @@
List<IEntryEditor> editors = getAutoSaveEditors( autoSaveSharedWorkingCopy );
for ( IEntryEditor editor : editors )
{
- editor.workingCopyModified();
+ editor.workingCopyModified( event.getSource() );
}
}
}
@@ -857,7 +889,7 @@
List<IEntryEditor> oscEditors = getOscEditors( oscSharedWorkingCopy );
for ( IEntryEditor editor : oscEditors )
{
- editor.workingCopyModified();
+ editor.workingCopyModified( event.getSource() );
}
}
@@ -867,26 +899,19 @@
// auto-save working copy has been modified: save and inform all auto-save editors
IEntry autoSaveSharedReferenceCopy = autoSaveSharedReferenceCopies.get( originalEntry );
IEntry autoSaveSharedWorkingCopy = autoSaveSharedWorkingCopies.get( originalEntry );
- LdifChangeModifyRecord diff = Utils.computeDiff( autoSaveSharedReferenceCopy, autoSaveSharedWorkingCopy );
+ LdifChangeModifyRecord diff = Utils
+ .computeDiff( autoSaveSharedReferenceCopy, autoSaveSharedWorkingCopy );
if ( diff != null )
{
ExecuteLdifRunnable runnable = new ExecuteLdifRunnable( browserConnection, diff
.toFormattedString( LdifFormatParameters.DEFAULT ), false, false );
RunnableContextRunner.execute( runnable, null, true );
// don't care if status is ok or not: always update
- EntryEditorUtils.ensureAttributesInitialized( originalEntry );
- // updateAutoSaveSharedReferenceCopy( originalEntry );
- // updateAutoSaveSharedWorkingCopy( originalEntry );
- //
- // List<IEntryEditor> editors = getAutoSaveEditors( autoSaveSharedWorkingCopy );
- // for ( IEntryEditor editor : editors )
- // {
- // editor.workingCopyModified();
- // }
+ updateAutoSaveSharedReferenceCopy( originalEntry );
+ updateAutoSaveSharedWorkingCopy( originalEntry );
}
}
}
-
};
}
Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/IEntryEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/IEntryEditor.java?rev=820680&r1=820679&r2=820680&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/IEntryEditor.java (original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/IEntryEditor.java Thu Oct 1 15:06:36 2009
@@ -43,9 +43,11 @@
/**
- * Informs the entry editor that the working copy was modified
+ * Informs the entry editor that the working copy was modified.
+ *
+ * @param source the source of the modification, may be null
*/
- public void workingCopyModified();
+ public void workingCopyModified( Object source );
/**
Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/EntryEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/EntryEditor.java?rev=820680&r1=820679&r2=820680&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/EntryEditor.java (original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/EntryEditor.java Thu Oct 1 15:06:36 2009
@@ -357,7 +357,10 @@
}
- public void workingCopyModified()
+ /**
+ * {@inheritDoc}
+ */
+ public void workingCopyModified( Object source )
{
if ( isAutoSave() )
{
Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditor.java?rev=820680&r1=820679&r2=820680&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditor.java (original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditor.java Thu Oct 1 15:06:36 2009
@@ -140,16 +140,9 @@
/**
* {@inheritDoc}
*/
- public void workingCopyModified()
+ public void workingCopyModified( Object source )
{
- if ( getSite().getPage().getActivePart() == LdifEntryEditor.this )
- {
- // This editor instance is the active editor.
- // Don't apply its own modifications.
- return;
- }
-
- ( ( LdifEntryEditorDocumentProvider ) getDocumentProvider() ).setContent( getEntryEditorInput() );
+ ( ( LdifEntryEditorDocumentProvider ) getDocumentProvider() ).workingCopyModified( getEntryEditorInput(), source );
}
Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditorDocumentProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditorDocumentProvider.java?rev=820680&r1=820679&r2=820680&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditorDocumentProvider.java (original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/LdifEntryEditorDocumentProvider.java Thu Oct 1 15:06:36 2009
@@ -53,6 +53,7 @@
{
private EntryEditorInput input;
+
private boolean inSetContent = false;
private LdifEntryEditor editor;
@@ -106,7 +107,7 @@
LdifContentRecord modifiedRecord = ( LdifContentRecord ) records[0];
IBrowserConnection browserConnection = input.getSharedWorkingCopy( editor ).getBrowserConnection();
DummyEntry modifiedEntry = ModelConverter.ldifContentRecordToEntry( modifiedRecord, browserConnection );
- new CompoundModification().replaceAttributes( modifiedEntry, input.getSharedWorkingCopy( editor ) );
+ new CompoundModification().replaceAttributes( modifiedEntry, input.getSharedWorkingCopy( editor ), this );
}
catch ( InvalidNameException e )
{
@@ -115,31 +116,55 @@
}
- public void setContent( EntryEditorInput input )
+ @Override
+ protected void doResetDocument( Object element, IProgressMonitor monitor ) throws CoreException
{
- IEntry sharedWorkingCopy = input.getSharedWorkingCopy( editor );
- LdifContentRecord record = ModelConverter.entryToLdifContentRecord( sharedWorkingCopy );
- String newContent = record.toFormattedString( Utils.getLdifFormatParameters() );
+ // reset working copy first
+ if ( input != null )
+ {
+ input.resetSharedWorkingCopy( editor );
+ }
+
+ super.doResetDocument( element, monitor );
+ }
+
+
+ public void workingCopyModified( EntryEditorInput input, Object source )
+ {
+ // the model change was caused by the document change
+ // no need to set the content again, don't fire more events
+ if ( source == this )
+ {
+ return;
+ }
IDocument document = getDocument( input );
if ( document != null )
{
- inSetContent = true;
- document.set( newContent );
-
- // reset dirty state
- if ( !input.isSharedWorkingCopyDirty( editor ) )
+ try
{
- try
- {
- doResetDocument( input, null );
- }
- catch ( CoreException e )
+ inSetContent = true;
+
+ // set content
+ IEntry sharedWorkingCopy = input.getSharedWorkingCopy( editor );
+ LdifContentRecord record = ModelConverter.entryToLdifContentRecord( sharedWorkingCopy );
+ String newContent = record.toFormattedString( Utils.getLdifFormatParameters() );
+ document.set( newContent );
+
+ // reset dirty state
+ if ( !input.isSharedWorkingCopyDirty( editor ) )
{
- throw new RuntimeException( e );
+ super.doResetDocument( input, null );
}
}
- inSetContent = false;
+ catch ( CoreException e )
+ {
+ throw new RuntimeException( e );
+ }
+ finally
+ {
+ inSetContent = false;
+ }
}
}