/*
* Gamer's Own Instant Messenger
* Copyright (C) 2005-2006 Herbert Poul (kahless@sphene.net)
* http://goim.sphene.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package net.sphene.goim.rcp;
import net.sphene.goim.rcp.ui.dialogs.GOIMErrorDialog;
import net.sphene.goim.rcp.views.ChatView;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
private static final String PERSPECTIVE_ID = "net.sphene.goim.rcp.perspective";
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
IWorkbenchWindowConfigurer configurer) {
return new ApplicationWorkbenchWindowAdvisor(configurer);
}
public String getInitialWindowPerspectiveId() {
return PERSPECTIVE_ID;
}
@Override
public void preStartup() {
super.preStartup();
getWorkbenchConfigurer().setSaveAndRestore(true);
}
@Override
public void postStartup() {
super.postStartup();
}
@Override
public boolean preShutdown() {
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for(IWorkbenchWindow window : windows) {
IWorkbenchPage[] pages = window.getPages();
for(IWorkbenchPage page : pages) {
IViewReference[] viewRef = page.getViewReferences();
for(IViewReference ref : viewRef) {
if(ref.getId().equals(ChatView.ID))
page.hideView(ref);
}
if(page.getViewReferences().length < 1)
page.close();
}
if(window.getPages().length < 1 && PlatformUI.getWorkbench().getWorkbenchWindowCount() > 1) // Don't close last window (would result in a recursion)
window.close();
}
return super.preShutdown();
}
@Override
public IStatus saveState(IMemento memento) {
return super.saveState(memento);
}
@Override
public void eventLoopException(Throwable exception) {
super.eventLoopException(exception);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
//ErrorDialog.openError(shell,"Error in Event Loop","An error occurred during processing event: " + exception.getLocalizedMessage(),new Status(IStatus.ERROR,GOIMPlugin.ID,IStatus.OK,"Error occurred during event: " + exception.getLocalizedMessage(),exception));
new GOIMErrorDialog(shell,"Error in Event Loop","An error occurred during processing event: " + exception.getLocalizedMessage(),new Status(IStatus.ERROR,GOIMPlugin.ID,IStatus.OK,"Error occurred during event: " + exception.getLocalizedMessage(),exception),IStatus.ERROR).open();
}
}