1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

fixed NPE on shutdown

This commit is contained in:
David Inglis 2004-05-26 15:09:48 +00:00
parent f7264a67cd
commit 7aa7748a99

View file

@ -1,13 +1,11 @@
/********************************************************************** /*******************************************************************************
* Copyright (c) 2002,2003,2004 QNX Software Systems and others. * Copyright (c) 2002,2003,2004 QNX Software Systems and others. All rights
* All rights reserved. This program and the accompanying materials * reserved. This program and the accompanying materials are made available
* are made available under the terms of the Common Public License v1.0 * under the terms of the Common Public License v1.0 which accompanies this
* which accompanies this distribution, and is available at * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
* http://www.eclipse.org/legal/cpl-v10.html
* *
* Contributors: * Contributors: QNX Software Systems - Initial API and implementation
* QNX Software Systems - Initial API and implementation ******************************************************************************/
***********************************************************************/
package org.eclipse.cdt.internal.ui.buildconsole; package org.eclipse.cdt.internal.ui.buildconsole;
import java.util.HashMap; import java.util.HashMap;
@ -51,26 +49,27 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
public BuildConsoleManager() { public BuildConsoleManager() {
} }
/** /**
* Notifies the console manager that console activity has started on the project * Notifies the console manager that console activity has started on the
* The manager will open the console if the preference is set to show the console, and notify listeners * project The manager will open the console if the preference is set to
* show the console, and notify listeners
*/ */
protected void startConsoleActivity(IProject project) { protected void startConsoleActivity(IProject project) {
Object[] list = listeners.getListeners(); Object[] list = listeners.getListeners();
if (list.length > 0) { if (list.length > 0) {
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
IBuildConsoleListener listener = (IBuildConsoleListener) list[i]; IBuildConsoleListener listener = (IBuildConsoleListener)list[i];
ConsoleEvent event = new ConsoleEvent(BuildConsoleManager.this, project, ConsoleEvent.CONSOLE_START); ConsoleEvent event = new ConsoleEvent(BuildConsoleManager.this, project, ConsoleEvent.CONSOLE_START);
listener.consoleChange(event); listener.consoleChange(event);
} }
} }
showConsole(); showConsole();
} }
/** /**
* Opens the console view. If the view is already open, it is brought to * Opens the console view. If the view is already open, it is brought to the
* the front. * front.
*/ */
protected void showConsole() { protected void showConsole() {
CUIPlugin.getStandardDisplay().asyncExec(new Runnable() { CUIPlugin.getStandardDisplay().asyncExec(new Runnable() {
@ -98,7 +97,7 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
} }
} }
if (consoleView instanceof IConsoleView) { if (consoleView instanceof IConsoleView) {
((IConsoleView) consoleView).display(fConsole); ((IConsoleView)consoleView).display(fConsole);
} }
} }
} }
@ -109,7 +108,7 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
boolean shouldBringToTop(IViewPart consoleView) { boolean shouldBringToTop(IViewPart consoleView) {
boolean bringToTop = false; boolean bringToTop = false;
if (consoleView instanceof IConsoleView) { if (consoleView instanceof IConsoleView) {
IConsoleView cView = (IConsoleView) consoleView; IConsoleView cView = (IConsoleView)consoleView;
return !cView.isPinned() && BuildConsolePreferencePage.isConsoleOnTop(); return !cView.isPinned() && BuildConsolePreferencePage.isConsoleOnTop();
} }
return bringToTop; return bringToTop;
@ -125,13 +124,13 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
IResource resource = event.getResource(); IResource resource = event.getResource();
if (resource != null && resource.getType() == IResource.PROJECT) { if (resource != null && resource.getType() == IResource.PROJECT) {
if (event.getType() == IResourceChangeEvent.PRE_DELETE || event.getType() == IResourceChangeEvent.PRE_CLOSE) { if (event.getType() == IResourceChangeEvent.PRE_DELETE || event.getType() == IResourceChangeEvent.PRE_CLOSE) {
IDocumentPartitioner partioner = (IDocumentPartitioner) fConsoleMap.remove(resource); IDocumentPartitioner partioner = (IDocumentPartitioner)fConsoleMap.remove(resource);
partioner.disconnect(); partioner.disconnect();
Object[] list = listeners.getListeners(); Object[] list = listeners.getListeners();
if (list.length > 0) { if (list.length > 0) {
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
IBuildConsoleListener listener = (IBuildConsoleListener) list[i]; IBuildConsoleListener listener = (IBuildConsoleListener)list[i];
ConsoleEvent consoleEvent = new ConsoleEvent(this, (IProject) resource, ConsoleEvent.CONSOLE_CLOSE); ConsoleEvent consoleEvent = new ConsoleEvent(this, (IProject)resource, ConsoleEvent.CONSOLE_CLOSE);
listener.consoleChange(consoleEvent); listener.consoleChange(consoleEvent);
} }
} }
@ -140,50 +139,74 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
} }
public void shutdown() { public void shutdown() {
infoColor.dispose(); if (infoColor != null) {
outputColor.dispose(); infoColor.dispose();
errorColor.dispose(); outputColor.dispose();
errorColor.dispose();
}
ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new org.eclipse.ui.console.IConsole[]{fConsole}); ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new org.eclipse.ui.console.IConsole[]{fConsole});
CUIPlugin.getWorkspace().removeResourceChangeListener(this); CUIPlugin.getWorkspace().removeResourceChangeListener(this);
CUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); CUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);
} }
private void runUI(Runnable run) {
Display display;
display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
display.asyncExec(run);
} else {
run.run();
}
}
public void startup() { public void startup() {
fConsole = new BuildConsole(this); fConsole = new BuildConsole(this);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new org.eclipse.ui.console.IConsole[]{fConsole}); ConsolePlugin.getDefault().getConsoleManager().addConsoles(new org.eclipse.ui.console.IConsole[]{fConsole});
// install colors runUI(new Runnable() {
infoColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR);
infoStream = new BuildConsoleStream(fConsole);
infoStream.setColor(infoColor);
outputColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR);
outputStream = new BuildConsoleStream(fConsole);
outputStream.setColor(outputColor);
errorColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR);
errorStream = new BuildConsoleStream(fConsole);
errorStream.setColor(errorColor);
/*
* (non-Javadoc)
*
* @see java.lang.Runnable#run()
*/
public void run() {
// install colors
infoColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR);
infoStream = new BuildConsoleStream(fConsole);
infoStream.setColor(infoColor);
outputColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR);
outputStream = new BuildConsoleStream(fConsole);
outputStream.setColor(outputColor);
errorColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR);
errorStream = new BuildConsoleStream(fConsole);
errorStream.setColor(errorColor);
}
});
CUIPlugin.getWorkspace().addResourceChangeListener(this); CUIPlugin.getWorkspace().addResourceChangeListener(this);
CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
*/ */
public void propertyChange(PropertyChangeEvent event) { public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty(); String property = event.getProperty();
// colors // colors
if(property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR)) { if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR)) {
Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR); Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR);
infoStream.setColor(newColor); infoStream.setColor(newColor);
infoColor.dispose(); infoColor.dispose();
infoColor = newColor; infoColor = newColor;
} else if(property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR)) { } else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR)) {
Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR); Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR);
outputStream.setColor(newColor); outputStream.setColor(newColor);
outputColor.dispose(); outputColor.dispose();
outputColor = newColor; outputColor = newColor;
} else if(property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR)) { } else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR)) {
Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR); Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR);
errorStream.setColor(newColor); errorStream.setColor(newColor);
errorColor.dispose(); errorColor.dispose();
@ -208,8 +231,8 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
} }
private BuildConsolePartitioner getConsolePartioner(IProject project) { private BuildConsolePartitioner getConsolePartioner(IProject project) {
BuildConsolePartitioner partioner = (BuildConsolePartitioner) fConsoleMap.get(project); BuildConsolePartitioner partioner = (BuildConsolePartitioner)fConsoleMap.get(project);
if ( partioner == null) { if (partioner == null) {
partioner = new BuildConsolePartitioner(this); partioner = new BuildConsolePartitioner(this);
fConsoleMap.put(project, partioner); fConsoleMap.put(project, partioner);
} }
@ -217,7 +240,8 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
} }
/** /**
* Returns the document for the projects console, or <code>null</code> if none. * Returns the document for the projects console, or <code>null</code> if
* none.
*/ */
public IDocument getConsoleDocument(IProject project) { public IDocument getConsoleDocument(IProject project) {
Assert.isNotNull(project); Assert.isNotNull(project);
@ -232,4 +256,4 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
listeners.remove(listener); listeners.remove(listener);
} }
} }