### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.ide Index: src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java,v retrieving revision 1.71 diff -u -r1.71 IDEWorkbenchMessages.java --- src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java 10 Dec 2009 11:21:22 -0000 1.71 +++ src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java 22 Jan 2010 18:51:57 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -868,6 +868,10 @@ public static String UnsupportedVM_message; public static String IDEWorkbenchActivityHelper_jobName; + + public static String OpenDelayedFileAction_title; + public static String OpenDelayedFileAction_message_errorOnOpen; + public static String OpenDelayedFileAction_message_fileNotFound; static { // load message values from bundle file Index: src/org/eclipse/ui/internal/ide/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties,v retrieving revision 1.182 diff -u -r1.182 messages.properties --- src/org/eclipse/ui/internal/ide/messages.properties 10 Dec 2009 16:55:18 -0000 1.182 +++ src/org/eclipse/ui/internal/ide/messages.properties 22 Jan 2010 18:51:57 -0000 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2009 IBM Corporation and others. +# Copyright (c) 2000, 2010 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -881,4 +881,9 @@ SystemSettingsChange_no = No UnsupportedVM_message=GCJ has been detected as the current Java virtual machine. Use of GCJ is untested and unsupported. Please consult the documentation for more information. -IDEWorkbenchActivityHelper_jobName=Update Capability Enablement for Natures \ No newline at end of file +IDEWorkbenchActivityHelper_jobName=Update Capability Enablement for Natures + +OpenDelayedFileAction_title = Open File +OpenDelayedFileAction_message_errorOnOpen = The file ''{0}'' could not be opened.\nSee log for details. +OpenDelayedFileAction_message_fileNotFound= The file ''{0}'' could not be found. + #P org.eclipse.ui.ide.application Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide.application/META-INF/MANIFEST.MF,v retrieving revision 1.14 diff -u -r1.14 MANIFEST.MF --- META-INF/MANIFEST.MF 1 Sep 2009 04:32:22 -0000 1.14 +++ META-INF/MANIFEST.MF 22 Jan 2010 18:51:59 -0000 @@ -12,7 +12,8 @@ org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)", org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui.navigator.resources;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.net;bundle-version="[1.0.0,2.0.0)" + org.eclipse.core.net;bundle-version="[1.0.0,2.0.0)", + org.eclipse.core.filesystem;bundle-version="1.3.0" Export-Package: org.eclipse.ui.internal.ide.application;x-internal:=true, org.eclipse.ui.internal.ide.application.dialogs;x-internal:=true Import-Package: com.ibm.icu.text Index: src/org/eclipse/ui/internal/ide/application/DelayedEventsProcessor.java =================================================================== RCS file: src/org/eclipse/ui/internal/ide/application/DelayedEventsProcessor.java diff -N src/org/eclipse/ui/internal/ide/application/DelayedEventsProcessor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/ide/application/DelayedEventsProcessor.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.ui.internal.ide.application; + +import java.util.ArrayList; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileInfo; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; +import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; + +/** + * Helper class used to process delayed events. + * Events currently supported: + * + * @since 3.3 + */ +public class DelayedEventsProcessor implements Listener { + + private ArrayList filesToOpen = new ArrayList(1); + + /** + * Constructor. + * @param display display used as a source of event + */ + public DelayedEventsProcessor(Display display) { + display.addListener(SWT.OpenDoc, this); + } + + /* (non-Javadoc) + * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) + */ + public void handleEvent(Event event) { + final String path = event.text; + if (path == null) + return; + synchronized (filesToOpen) { + filesToOpen.add(path); + } + } + + /** + * Process delayed events. + * @param display display associated with the workbench + */ + public void catchUp(Display display) { + if (filesToOpen.isEmpty()) // intentionally done outside of the sync block to improve performance + return; + // make a local copy of the list, clear it, and release the lock ASAP + String[] filePaths; + synchronized (filesToOpen) { + filePaths = new String[filesToOpen.size()]; + filesToOpen.toArray(filePaths); + filesToOpen.clear(); + } + for(int i = 0; i < filePaths.length; i++) { + openFile(display, filePaths[i]); + } + } + + private void openFile(Display display, final String path) { + display.asyncExec(new Runnable() { + public void run() { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window == null) + return; + IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(path)); + IFileInfo fetchInfo = fileStore.fetchInfo(); + if (!fetchInfo.isDirectory() && fetchInfo.exists()) { + IWorkbenchPage page = window.getActivePage(); + try { + IDE.openEditorOnFileStore(page, fileStore); + } catch (PartInitException e) { + String msg = NLS.bind(IDEWorkbenchMessages.OpenDelayedFileAction_message_errorOnOpen, + fileStore.getName()); + IDEWorkbenchPlugin.log(msg, e.getStatus()); + MessageDialog.open(MessageDialog.ERROR, window.getShell(), + IDEWorkbenchMessages.OpenDelayedFileAction_title, + msg, SWT.SHEET); + } + } else { + String msg = NLS.bind(IDEWorkbenchMessages.OpenDelayedFileAction_message_fileNotFound, path); + MessageDialog.open(MessageDialog.ERROR, window.getShell(), + IDEWorkbenchMessages.OpenDelayedFileAction_title, + msg, SWT.SHEET); + } + } + }); + } + +} Index: src/org/eclipse/ui/internal/ide/application/IDEApplication.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEApplication.java,v retrieving revision 1.7 diff -u -r1.7 IDEApplication.java --- src/org/eclipse/ui/internal/ide/application/IDEApplication.java 3 Jun 2008 17:56:02 -0000 1.7 +++ src/org/eclipse/ui/internal/ide/application/IDEApplication.java 22 Jan 2010 18:52:00 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2008 IBM Corporation and others. + * Copyright (c) 2003, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -86,6 +86,8 @@ */ public Object start(IApplicationContext appContext) throws Exception { Display display = createDisplay(); + // processor must be created before we start event loop + DelayedEventsProcessor processor = new DelayedEventsProcessor(display); try { @@ -111,7 +113,7 @@ // the workbench globally so that all UI plug-ins can find it using // PlatformUI.getWorkbench() or AbstractUIPlugin.getWorkbench() int returnCode = PlatformUI.createAndRunWorkbench(display, - new IDEWorkbenchAdvisor()); + new IDEWorkbenchAdvisor(processor)); // the workbench doesn't support relaunch yet (bug 61809) so // for now restart is used, and exit data properties are checked Index: src/org/eclipse/ui/internal/ide/application/IDEWorkbenchAdvisor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEWorkbenchAdvisor.java,v retrieving revision 1.24 diff -u -r1.24 IDEWorkbenchAdvisor.java --- src/org/eclipse/ui/internal/ide/application/IDEWorkbenchAdvisor.java 13 Oct 2009 09:28:11 -0000 1.24 +++ src/org/eclipse/ui/internal/ide/application/IDEWorkbenchAdvisor.java 22 Jan 2010 18:52:00 -0000 @@ -144,6 +144,11 @@ private AbstractStatusHandler ideWorkbenchErrorHandler; /** + * Helper class used to process delayed events. + */ + private DelayedEventsProcessor delayedEventsProcessor; + + /** * Creates a new workbench advisor instance. */ public IDEWorkbenchAdvisor() { @@ -154,6 +159,15 @@ workbenchAdvisor = this; } + /** + * Creates a new workbench advisor instance supporting delayed file open. + * @param processor helper class used to process delayed events + */ + public IDEWorkbenchAdvisor(DelayedEventsProcessor processor) { + this(); + this.delayedEventsProcessor = processor; + } + /* * (non-Javadoc) * @@ -852,4 +866,13 @@ } return ideWorkbenchErrorHandler; } + + /* (non-Javadoc) + * @see org.eclipse.ui.application.WorkbenchAdvisor#eventLoopIdle(org.eclipse.swt.widgets.Display) + */ + public void eventLoopIdle(Display display) { + if (delayedEventsProcessor != null) + delayedEventsProcessor.catchUp(display); + super.eventLoopIdle(display); + } }