blob: 404c7993de32d6375f900013b96d0142ebf4c2df [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2001, 2004 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Jens Lukowski/Innoopract - initial renaming/restructuring
*
*******************************************************************************/
package org.eclipse.wst.dtd.ui.internal.views.contentoutline;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.dtd.core.internal.DTDFile;
import org.eclipse.wst.dtd.core.internal.DTDNode;
import org.eclipse.wst.dtd.core.internal.NodeList;
/*
* Based on DTDLabelProvider
*/
public class DTDLabelProvider extends LabelProvider {
public DTDLabelProvider() {
super();
}
/**
* Returns the image for the label of the given element.
*
* @param element
* the element for which to provide the label image
* @return the image used to label the element, or <code>null</code> if
* these is no image for the given object
*/
public Image getImage(Object element) {
Image image = null;
if (element instanceof DTDNode) {
image = ((DTDNode) element).getImage();
}
else if (element instanceof NodeList) {
image = ((NodeList) element).getImage();
}
else if (element instanceof IndexedNodeList) {
return ((IndexedNodeList) element).getTarget().getImage();
}
else if (element instanceof DTDFile) {
image = ((DTDFile) element).getImage();
}
else {
image = super.getImage(element);
}
return image;
}
/**
* Returns the text for the label of the given element.
*
* @param element
* the element for which to provide the label text
* @return the text string used to label the element, or <code>null</code>
* if these is no text label for the given object
*/
public String getText(Object element) {
if (element instanceof DTDNode) {
String name = ((DTDNode) element).getName();
// strip leading whitespace (useful for multi-line comments)
int i = 0;
for (i = 0; i < name.length(); i++) {
if (!Character.isWhitespace(name.charAt(i)))
break;
}
if (i > 0 && i < name.length() - 1)
name = name.substring(i);
return name;
}
else if (element instanceof NodeList) {
return ((NodeList) element).getListType();
}
else if (element instanceof IndexedNodeList) {
return ((IndexedNodeList) element).getTarget().getName();
}
else if (element instanceof DTDFile) {
return ((DTDFile) element).getName();
}
return super.getText(element);
}
}