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

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 <marc-andre.laperle@ericsson.com>
This commit is contained in:
Marc-Andre Laperle 2017-03-24 16:43:54 -04:00 committed by Marc-André Laperle
parent 525d8a23fb
commit 44067d9115
2 changed files with 55 additions and 1 deletions

View file

@ -3488,8 +3488,11 @@
name="%CDTLanguagesProperty.name">
<enabledWhen>
<and>
<adapt type="org.eclipse.core.resources.IFile">
<test property="org.eclipse.core.resources.projectNature"
value="org.eclipse.cdt.core.cnature"/>
</adapt>
<adapt type="org.eclipse.cdt.core.model.ITranslationUnit"/>
<adapt type="org.eclipse.core.resources.IFile"/>
</and>
</enabledWhen>
</page>
@ -5010,5 +5013,15 @@
</tagReference>
</template>
</extension>
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="org.eclipse.core.resources.IFile"
class="org.eclipse.cdt.internal.ui.ResourceToCElementAdapterFactory">
<adapter
type="org.eclipse.cdt.core.model.ITranslationUnit">
</adapter>
</factory>
</extension>
</plugin>

View file

@ -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> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (adaptableObject instanceof IFile && adapterType.equals(ITranslationUnit.class)) {
return (T) CoreModelUtil.findTranslationUnit((IFile) adaptableObject);
}
return null;
}
@Override
public Class<?>[] getAdapterList() {
return ADAPTER_LIST;
}
}