1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

2004-09-15 Chris Wiebe

refactoring generic stuff out of browser/ and typeinfo-specific stuff back in
	* src/org/eclipse/cdt/internal/ui/CUIMessages.properties
	* src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java
	* src/org/eclipse/cdt/internal/ui/viewsupport/StatusBarUpdater.java
	* src/org/eclipse/cdt/internal/ui/viewsupport/StorageLabelProvider.java
This commit is contained in:
Chris Wiebe 2004-09-16 00:59:39 +00:00
parent e56e4cf0e7
commit 645ad5303d
5 changed files with 231 additions and 14 deletions

View file

@ -1,3 +1,11 @@
2004-09-15 Chris Wiebe
refactoring generic stuff out of browser/ and typeinfo-specific stuff back in
* src/org/eclipse/cdt/internal/ui/CUIMessages.properties
* src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java
* src/org/eclipse/cdt/internal/ui/viewsupport/StatusBarUpdater.java
* src/org/eclipse/cdt/internal/ui/viewsupport/StorageLabelProvider.java
2004-09-14 Alain Magloire
Pr 73831. Tentative fix

View file

@ -61,3 +61,4 @@ IndexerOptions.enablePreprocessor = Report &preprocessor problems
IndexerOptions.enableSemantic = Report &semantic problems
IndexerOptions.enableSyntactic = Report s&yntactic problems
StatusBarUpdater.num_elements_selected={0} items selected

View file

@ -12,22 +12,16 @@ package org.eclipse.cdt.internal.ui.viewsupport;
import java.util.ArrayList;
import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.internal.ui.browser.cbrowsing.StorageLabelProvider;
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
import org.eclipse.core.resources.IStorage;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
public class CUILabelProvider extends LabelProvider implements IColorProvider {
protected static final TypeInfoLabelProvider fTypeInfoLabelProvider = new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED);
protected CElementImageProvider fImageLabelProvider;
protected StorageLabelProvider fStorageLabelProvider;
@ -130,9 +124,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider {
* @see ILabelProvider#getImage
*/
public Image getImage(Object element) {
if (element instanceof ITypeInfo)
return fTypeInfoLabelProvider.getImage(element);
Image result= fImageLabelProvider.getImageLabel(element, evaluateImageFlags(element));
if (result == null && (element instanceof IStorage)) {
result= fStorageLabelProvider.getImage(element);
@ -156,9 +147,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider {
* @see ILabelProvider#getText
*/
public String getText(Object element) {
if (element instanceof ITypeInfo)
return fTypeInfoLabelProvider.getText(element);
String result= CElementLabels.getTextLabel(element, evaluateTextFlags(element));
if (result.length() == 0 && (element instanceof IStorage)) {
result= fStorageLabelProvider.getText(element);

View file

@ -0,0 +1,91 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.viewsupport;
import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.ui.CUIMessages;
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
/**
* Add the <code>StatusBarUpdater</code> to your ViewPart to have the statusbar
* describing the selected elements.
*/
public class StatusBarUpdater implements ISelectionChangedListener {
private final int LABEL_FLAGS= CElementLabels.DEFAULT_QUALIFIED | CElementLabels.ROOT_POST_QUALIFIED | CElementLabels.APPEND_ROOT_PATH |
CElementLabels.M_PARAMETER_TYPES | CElementLabels.M_PARAMETER_NAMES | CElementLabels.M_APP_RETURNTYPE | CElementLabels.M_EXCEPTIONS |
CElementLabels.F_APP_TYPE_SIGNATURE;
private final TypeInfoLabelProvider fTypeInfoLabelProvider = new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED + TypeInfoLabelProvider.SHOW_PATH);
private IStatusLineManager fStatusLineManager;
public StatusBarUpdater(IStatusLineManager statusLineManager) {
fStatusLineManager= statusLineManager;
}
/*
* @see ISelectionChangedListener#selectionChanged
*/
public void selectionChanged(SelectionChangedEvent event) {
String statusBarMessage= formatMessage(event.getSelection());
fStatusLineManager.setMessage(statusBarMessage);
}
protected String formatMessage(ISelection sel) {
if (sel instanceof IStructuredSelection && !sel.isEmpty()) {
IStructuredSelection selection= (IStructuredSelection) sel;
int nElements= selection.size();
if (nElements > 1) {
return CUIMessages.getFormattedString("StatusBarUpdater.num_elements_selected", String.valueOf(nElements)); //$NON-NLS-1$
} else {
Object elem= selection.getFirstElement();
if (elem instanceof ICElement) {
return formatCElementMessage((ICElement) elem);
} else if (elem instanceof ITypeInfo) {
return formatTypeInfoMessage((ITypeInfo) elem);
} else if (elem instanceof IResource) {
return formatResourceMessage((IResource) elem);
}
}
}
return ""; //$NON-NLS-1$
}
private String formatCElementMessage(ICElement element) {
return CElementLabels.getElementLabel(element, LABEL_FLAGS);
}
private String formatTypeInfoMessage(ITypeInfo info) {
return fTypeInfoLabelProvider.getText(info);
}
private String formatResourceMessage(IResource element) {
IContainer parent= element.getParent();
if (parent != null && parent.getType() != IResource.ROOT)
return element.getName() + CElementLabels.CONCAT_STRING + parent.getFullPath().makeRelative().toString();
else
return element.getName();
}
}

View file

@ -0,0 +1,129 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.viewsupport;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IPath;
import org.eclipse.swt.graphics.Image;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IFileEditorMapping;
import org.eclipse.ui.PlatformUI;
/**
* Standard label provider for IStorage objects.
* Use this class when you want to present IStorage objects in a viewer.
*/
public class StorageLabelProvider extends LabelProvider {
private IEditorRegistry fEditorRegistry= PlatformUI.getWorkbench().getEditorRegistry();
private Map fJarImageMap= new HashMap(10);
private Image fDefaultImage;
/* (non-Javadoc)
* @see ILabelProvider#getImage
*/
public Image getImage(Object element) {
if (element instanceof IStorage)
return getImageForJarEntry((IStorage)element);
return super.getImage(element);
}
/* (non-Javadoc)
* @see ILabelProvider#getText
*/
public String getText(Object element) {
if (element instanceof IStorage)
return ((IStorage)element).getName();
return super.getText(element);
}
/* (non-Javadoc)
*
* @see IBaseLabelProvider#dispose
*/
public void dispose() {
if (fJarImageMap != null) {
Iterator each= fJarImageMap.values().iterator();
while (each.hasNext()) {
Image image= (Image)each.next();
image.dispose();
}
fJarImageMap= null;
}
if (fDefaultImage != null)
fDefaultImage.dispose();
fDefaultImage= null;
}
/*
* Gets and caches an image for a JarEntryFile.
* The image for a JarEntryFile is retrieved from the EditorRegistry.
*/
private Image getImageForJarEntry(IStorage element) {
if (fJarImageMap == null)
return getDefaultImage();
if (element == null || element.getName() == null)
return getDefaultImage();
// Try to find icon for full name
String name= element.getName();
Image image= (Image)fJarImageMap.get(name);
if (image != null)
return image;
IFileEditorMapping[] mappings= fEditorRegistry.getFileEditorMappings();
int i= 0;
while (i < mappings.length) {
if (mappings[i].getLabel().equals(name))
break;
i++;
}
String key= name;
if (i == mappings.length) {
// Try to find icon for extension
IPath path= element.getFullPath();
if (path == null)
return getDefaultImage();
key= path.getFileExtension();
if (key == null)
return getDefaultImage();
image= (Image)fJarImageMap.get(key);
if (image != null)
return image;
}
// Get the image from the editor registry
ImageDescriptor desc= fEditorRegistry.getImageDescriptor(name);
image= desc.createImage();
fJarImageMap.put(key, image);
return image;
}
private Image getDefaultImage() {
if (fDefaultImage == null)
fDefaultImage= fEditorRegistry.getImageDescriptor((String)null).createImage();
return fDefaultImage;
}
}