From 44067d9115cd219e12e13e46740f0c5173021e44 Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Fri, 24 Mar 2017 16:43:54 -0400 Subject: [PATCH] Bug 514069 - Language Mappings section not shown in file properties if opened from Java's "Package Explorer" view The Package Explorer's content provider is not extensible the same way as the CommonNavigator so it does not contain CElement in its tree; instead it contains IResources (IFile, etc) and Java specific elements. However, the file language mapping property page is set to be displayed on selections that adapt to translation units. So this change allows IFiles to be adapted to ITranslationUnits therefore the property page can still be shown from the Package Explorer. Change-Id: Ia52a62c2d8800e2a4f0404bc00e346decbacaa3b Signed-off-by: Marc-Andre Laperle --- core/org.eclipse.cdt.ui/plugin.xml | 15 ++++++- .../ui/ResourceToCElementAdapterFactory.java | 41 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ResourceToCElementAdapterFactory.java diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index adf2b468f0f..d90fbcd062b 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -3488,8 +3488,11 @@ name="%CDTLanguagesProperty.name"> + + + - @@ -5010,5 +5013,15 @@ + + + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ResourceToCElementAdapterFactory.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ResourceToCElementAdapterFactory.java new file mode 100644 index 00000000000..638dfa2ac45 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ResourceToCElementAdapterFactory.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2017 Ericsson. + * 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 + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IAdapterFactory; + +import org.eclipse.cdt.core.model.CoreModelUtil; +import org.eclipse.cdt.core.model.ITranslationUnit; + + +/** + * An adapter factory that adapts resources to CElements. This was introduced in + * the context of non-extensible content providers (Package Explorer) which + * contain plain resources and not CElements. This allows some contributions to + * work without explicitly depending the content provider in order to extend it. + */ +public class ResourceToCElementAdapterFactory implements IAdapterFactory { + + private static final Class[] ADAPTER_LIST = new Class[] { ITranslationUnit.class }; + + @SuppressWarnings("unchecked") + @Override + public T getAdapter(Object adaptableObject, Class adapterType) { + if (adaptableObject instanceof IFile && adapterType.equals(ITranslationUnit.class)) { + return (T) CoreModelUtil.findTranslationUnit((IFile) adaptableObject); + } + return null; + } + + @Override + public Class[] getAdapterList() { + return ADAPTER_LIST; + } +}