1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Fix NPE in property pages

This commit is contained in:
Anton Leherbauer 2007-01-24 09:37:36 +00:00
parent 2bba2adf86
commit 61ab28f322
2 changed files with 42 additions and 24 deletions

View file

@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2004, 2005 Intel Corporation and others.
* Copyright (c) 2004, 2007 Intel 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
@ -7,6 +7,7 @@
*
* Contributors:
* Intel Corporation - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
**********************************************************************/
package org.eclipse.cdt.ui.dialogs;
@ -14,20 +15,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.CUIMessages;
import org.eclipse.cdt.internal.ui.text.CHelpBookDescriptor;
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
import org.eclipse.cdt.internal.ui.util.PixelConverter;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.CheckedListDialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.SWT;
@ -38,6 +28,20 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.dialogs.PropertyPage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.CUIMessages;
import org.eclipse.cdt.internal.ui.text.CHelpBookDescriptor;
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
import org.eclipse.cdt.internal.ui.util.PixelConverter;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.CheckedListDialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil;
/**
* This class defines a project property page
* for C/C++ project help settings configuration
@ -155,10 +159,18 @@ public class CHelpConfigurationPropertyPage extends PropertyPage implements
*/
protected Control createContents(Composite parent) {
fCHelpSettingsDisplay= new CHelpSettingsDisplay();
fCHelpSettingsDisplay.init((IResource)getElement());
fCHelpSettingsDisplay.init(getResource());
return fCHelpSettingsDisplay.createControl(parent);
}
private IResource getResource() {
IAdaptable element= getElement();
if (element instanceof IResource) {
return (IResource)element;
}
return (IResource)element.getAdapter(IResource.class);
}
public boolean performOk() {
fCHelpSettingsDisplay.performOk();
super.performOk();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2006 IBM Corporation and others.
* Copyright (c) 2004, 2007 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
@ -7,17 +7,14 @@
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.ui.dialogs;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
@ -26,6 +23,13 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PropertyPage;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
public class IndexerOptionPropertyPage extends PropertyPage {
private IndexerBlock optionPage;
@ -72,11 +76,13 @@ public class IndexerOptionPropertyPage extends PropertyPage {
}
public IProject getProject(){
Object tempElement = getElement();
IProject project = null;
if (tempElement != null && tempElement instanceof IProject)
IAdaptable tempElement = getElement();
IProject project;
if (tempElement instanceof IProject) {
project = (IProject) tempElement;
} else {
project = (IProject)tempElement.getAdapter(IProject.class);
}
return project;
}