Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 20354 invoked from network); 14 Jan 2010 13:59:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Jan 2010 13:59:08 -0000 Received: (qmail 58221 invoked by uid 500); 14 Jan 2010 13:59:08 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 58156 invoked by uid 500); 14 Jan 2010 13:59:07 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 58147 invoked by uid 99); 14 Jan 2010 13:59:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2010 13:59:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2010 13:59:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A3E092388993; Thu, 14 Jan 2010 13:58:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r899200 - in /directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors: EntryEditorManager.java OpenEntryEditorJob.java Date: Thu, 14 Jan 2010 13:58:46 -0000 To: commits@directory.apache.org From: pamarcelot@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100114135846.A3E092388993@eris.apache.org> Author: pamarcelot Date: Thu Jan 14 13:58:46 2010 New Revision: 899200 URL: http://svn.apache.org/viewvc?rev=899200&view=rev Log: Fix for DIRSTUDIO-616 (Entry Editor Manager does not ensure that the entry's attributes are initialized (loaded) before testing and opening editors). New fix as the previous one introduced a regression (the opening of the editor was synchronous with the load of attributes of the entry in the UI thread which could lead to a non responding UI in case the load of attributes takes a while). This fix uses an asynchronous job, separate from the UI thread which gives the control back to the UI as soon as the job is scheduled. Added: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/OpenEntryEditorJob.java Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java 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=899200&r1=899199&r2=899200&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 Jan 14 13:58:46 2010 @@ -47,16 +47,13 @@ import org.apache.directory.studio.ldapbrowser.core.events.ValueModifiedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueMultiModificationEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueRenamedEvent; -import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.jobs.UpdateEntryRunnable; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; -import org.apache.directory.studio.ldapbrowser.core.model.IContinuation; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.apache.directory.studio.ldapbrowser.core.model.IValue; -import org.apache.directory.studio.ldapbrowser.core.model.IContinuation.State; import org.apache.directory.studio.ldapbrowser.core.utils.CompoundModification; import org.apache.directory.studio.ldapbrowser.core.utils.Utils; import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants; @@ -81,7 +78,6 @@ import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -730,72 +726,8 @@ public void openEntryEditor( EntryEditorExtension extension, IEntry[] entries, ISearchResult[] searchResults, IBookmark[] bookmarks ) { - EntryEditorInput input = null; - IEntry entry; - if ( entries.length == 1 ) - { - input = new EntryEditorInput( entries[0], extension ); - entry = entries[0]; - } - else if ( searchResults.length == 1 ) - { - input = new EntryEditorInput( searchResults[0], extension ); - entry = searchResults[0].getEntry(); - } - else if ( bookmarks.length == 1 ) - { - input = new EntryEditorInput( bookmarks[0], extension ); - entry = bookmarks[0].getEntry(); - if ( entry.getBrowserConnection().getEntryFromCache( entry.getDn() ) == null ) - { - EntryEditorUtils.ensureAttributesInitialized( entry ); - } - } - else - { - input = new EntryEditorInput( ( IEntry ) null, extension ); - entry = null; - } - - if ( entry != null ) - { - if ( entry instanceof IContinuation ) - { - IContinuation continuation = ( IContinuation ) entry; - if ( continuation.getState() == State.UNRESOLVED ) - { - continuation.resolve(); - } - } - else - { - try - { - // Making sure attributes are initialized - StudioBrowserJob job = EntryEditorUtils.ensureAttributesInitialized( entry ); - if ( job != null ) - { - // Waiting for the entry's attributes to be initialized - job.join(); - } - } - catch ( InterruptedException e ) - { - // Nothing to do - } - } - } - - String editorId = extension.getEditorId(); - - try - { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor( input, editorId, false ); - } - catch ( PartInitException e ) - { - throw new RuntimeException( e ); - } + OpenEntryEditorJob runnable = new OpenEntryEditorJob( extension, entries, searchResults, bookmarks ); + runnable.schedule(); } @@ -813,50 +745,8 @@ */ public void openEntryEditor( IEntry[] entries, ISearchResult[] searchResults, IBookmark[] bookmarks ) { - // Looking for the entry to test the editor on - IEntry entry = null; - if ( entries.length == 1 ) - { - entry = entries[0]; - } - else if ( searchResults.length == 1 ) - { - entry = searchResults[0].getEntry(); - } - else if ( bookmarks.length == 1 ) - { - entry = bookmarks[0].getEntry(); - } - - if ( entry != null ) - { - try - { - // Making sure attributes are initialized - StudioBrowserJob job = EntryEditorUtils.ensureAttributesInitialized( entry ); - if ( job != null ) - { - // Waiting for the entry's attributes to be initialized - job.join(); - } - } - catch ( InterruptedException e ) - { - // Nothing to do - } - } - - // Looking for the correct entry editor - for ( EntryEditorExtension entryEditor : getSortedEntryEditorExtensions() ) - { - // Verifying that the editor can handle the entry - if ( entryEditor.getEditorInstance().canHandle( entry ) ) - { - // The correct editor has been found, let's open the entry in the editor - openEntryEditor( entryEditor, entries, searchResults, bookmarks ); - return; - } - } + OpenEntryEditorJob runnable = new OpenEntryEditorJob( entries, searchResults, bookmarks ); + runnable.schedule(); } Added: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/OpenEntryEditorJob.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/OpenEntryEditorJob.java?rev=899200&view=auto ============================================================================== --- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/OpenEntryEditorJob.java (added) +++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/OpenEntryEditorJob.java Thu Jan 14 13:58:46 2010 @@ -0,0 +1,214 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.directory.studio.entryeditors; + + +import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; +import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; +import org.apache.directory.studio.ldapbrowser.core.model.IContinuation; +import org.apache.directory.studio.ldapbrowser.core.model.IEntry; +import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; +import org.apache.directory.studio.ldapbrowser.core.model.IContinuation.State; +import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; + + +/** + * Job to open an entry editor. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class OpenEntryEditorJob extends Job +{ + private IEntry[] entries; + private ISearchResult[] searchResults; + private IBookmark[] bookmarks; + private EntryEditorExtension extension; + + + /** + * Creates a new instance of OpenEntryEditorJob. + *

+ * Opens an entry editor from one of the given entries, + * search results or bookmarks. + * + * @param entries + * an array of entries + * @param searchResults + * an array of search results + * @param bookmarks + * an arrays of bookmarks + */ + public OpenEntryEditorJob( IEntry[] entries, ISearchResult[] searchResults, IBookmark[] bookmarks ) + { + super( "" ); //$NON-NLS-1$ + this.entries = entries; + this.searchResults = searchResults; + this.bookmarks = bookmarks; + + // Using a high priority for this job + setPriority( Job.INTERACTIVE ); + } + + + /** + * Creates a new instance of OpenEntryEditorJob. + *

+ * Opens an entry editor with the given entry editor extension and one of + * the given entries, search results or bookmarks. + * + * @param extension + * the entry editor extension + * @param entries + * an array of entries + * @param searchResults + * an array of search results + * @param bookmarks + * an arrays of bookmarks + */ + public OpenEntryEditorJob( EntryEditorExtension extension, IEntry[] entries, ISearchResult[] searchResults, + IBookmark[] bookmarks ) + { + super( "" ); //$NON-NLS-1$ + this.extension = extension; + this.entries = entries; + this.searchResults = searchResults; + this.bookmarks = bookmarks; + + // Using a high priority for this job + setPriority( Job.INTERACTIVE ); + } + + + /** + * {@inheritDoc} + */ + protected IStatus run( IProgressMonitor monitor ) + { + // Getting the entry to open + IEntry entry = null; + + if ( entries.length == 1 ) + { + entry = entries[0]; + } + else if ( searchResults.length == 1 ) + { + entry = searchResults[0].getEntry(); + } + else if ( bookmarks.length == 1 ) + { + entry = bookmarks[0].getEntry(); + } + + if ( entry != null ) + { + if ( entry instanceof IContinuation ) + { + IContinuation continuation = ( IContinuation ) entry; + if ( continuation.getState() == State.UNRESOLVED ) + { + continuation.resolve(); + } + } + else + { + try + { + // Making sure attributes are initialized + StudioBrowserJob job = EntryEditorUtils.ensureAttributesInitialized( entry ); + if ( job != null ) + { + // Waiting for the entry's attributes to be initialized + job.join(); + } + } + catch ( InterruptedException e ) + { + // Nothing to do + } + } + } + + // If no entry editor was provided, find the correct one + if ( extension == null ) + { + // Looking for the correct entry editor + for ( EntryEditorExtension entryEditorExtension : BrowserUIPlugin.getDefault().getEntryEditorManager() + .getSortedEntryEditorExtensions() ) + { + // Verifying that the editor can handle the entry + if ( entryEditorExtension.getEditorInstance().canHandle( entry ) ) + { + extension = entryEditorExtension; + break; + } + } + } + + // Getting the editor's ID and creating the proper editor input + final String editorId = extension.getEditorId(); + final EntryEditorInput editorInput; + if ( entries.length == 1 ) + { + editorInput = new EntryEditorInput( entries[0], extension ); + } + else if ( searchResults.length == 1 ) + { + editorInput = new EntryEditorInput( searchResults[0], extension ); + } + else if ( bookmarks.length == 1 ) + { + editorInput = new EntryEditorInput( bookmarks[0], extension ); + } + else + { + editorInput = new EntryEditorInput( ( IEntry ) null, extension ); + } + + // Opening the editor + Display.getDefault().asyncExec( new Runnable() + { + + public void run() + { + try + { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor( editorInput, + editorId, true ); + } + catch ( PartInitException e ) + { + throw new RuntimeException( e ); + } + } + } ); + + return Status.OK_STATUS; + } +}