| 1 |
/** |
| 2 |
* Copyright (c) 2013 Obeo and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v2.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v20.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Obeo - initial API and implementation |
| 10 |
*/ |
| 11 |
package org.eclipse.emf.edit.ui.provider; |
| 12 |
|
| 13 |
import org.eclipse.jface.viewers.IColorProvider; |
| 14 |
import org.eclipse.jface.viewers.IFontProvider; |
| 15 |
import org.eclipse.jface.viewers.ILabelProvider; |
| 16 |
import org.eclipse.jface.viewers.ITableColorProvider; |
| 17 |
import org.eclipse.jface.viewers.ITableFontProvider; |
| 18 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
| 19 |
import org.eclipse.swt.graphics.Color; |
| 20 |
import org.eclipse.swt.graphics.Font; |
| 21 |
import org.eclipse.swt.graphics.Image; |
| 22 |
|
| 23 |
/** |
| 24 |
* An extended {@link org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider DelegatingStyledCellLabelProvider} that can |
| 25 |
* be used as a {@link ILabelProvider standard label provider} and {@link ITableLabelProvider table label provider} by |
| 26 |
* delegating to the wrapped {@link IStyledLabelProvider}. The methods of these interfaces will return null if the wrapped |
| 27 |
* {@link IStyledLabelProvider} does not implement itself the proper interfaces. |
| 28 |
* |
| 29 |
* @author <a href="mailto:[email protected]">Mikael Barbero</a> |
| 30 |
* @since 2.10 |
| 31 |
*/ |
| 32 |
public class DelegatingStyledCellLabelProvider extends org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider implements |
| 33 |
ILabelProvider, ITableLabelProvider |
| 34 |
{ |
| 35 |
|
| 36 |
/** |
| 37 |
* An extended version of the delegating styled cell label provider that also provides for fonts if the wrapped |
| 38 |
* {@link org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider} itself provides for fonts. |
| 39 |
*/ |
| 40 |
public static class FontProvider extends DelegatingStyledCellLabelProvider implements IFontProvider, ITableFontProvider |
| 41 |
{ |
| 42 |
/** |
| 43 |
* Construct an instance that wraps the given styled label provider. The constructed instance will |
| 44 |
* return null when asked to provide for {@link ILabelProvider label} and for {@link ITableLabelProvider table label} |
| 45 |
* if the given {@code styledLabelProvider} does not implement itself the proper interfaces. |
| 46 |
* @param styledLabelProvider the styled label provider to be wrapped |
| 47 |
*/ |
| 48 |
public FontProvider(IStyledLabelProvider styledLabelProvider) |
| 49 |
{ |
| 50 |
super(styledLabelProvider); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* An extended version of the delegating styled cell label provider that also provides for colors if the wrapped |
| 56 |
* {@link org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider} itself provides for colors. |
| 57 |
*/ |
| 58 |
public static class ColorProvider extends DelegatingStyledCellLabelProvider implements IColorProvider, ITableColorProvider |
| 59 |
{ |
| 60 |
/** |
| 61 |
* Construct an instance that wraps the given styled label provider. The constructed instance will |
| 62 |
* return null when asked to provide for {@link ILabelProvider label} and for {@link ITableLabelProvider table label} |
| 63 |
* if the given {@code styledLabelProvider} does not implement itself the proper interfaces. |
| 64 |
* @param styledLabelProvider the styled label provider to be wrapped |
| 65 |
*/ |
| 66 |
public ColorProvider(IStyledLabelProvider styledLabelProvider) |
| 67 |
{ |
| 68 |
super(styledLabelProvider); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* An extended version of the delegating styled cell label provider that also provides for fonts and colors if the wrapped |
| 74 |
* {@link org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider} itself provides for fonts and colors. |
| 75 |
*/ |
| 76 |
public static class FontAndColorProvider extends DelegatingStyledCellLabelProvider implements IFontProvider, ITableFontProvider, IColorProvider, ITableColorProvider |
| 77 |
{ |
| 78 |
/** |
| 79 |
* Construct an instance that wraps the given styled label provider. The constructed instance will |
| 80 |
* return null when asked to provide for {@link ILabelProvider label} and for {@link ITableLabelProvider table label} |
| 81 |
* if the given {@code styledLabelProvider} does not implement itself the proper interfaces. |
| 82 |
* @param styledLabelProvider the styled label provider to be wrapped |
| 83 |
*/ |
| 84 |
public FontAndColorProvider(IStyledLabelProvider styledLabelProvider) |
| 85 |
{ |
| 86 |
super(styledLabelProvider); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Construct an instance that wraps the given styled label provider. The constructed instance will |
| 92 |
* return null when asked to provide for {@link ILabelProvider label} and for {@link ITableLabelProvider table label} |
| 93 |
* if the given {@code styledLabelProvider} does not implement itself the proper interfaces. |
| 94 |
* @param styledLabelProvider the styled label provider to be wrapped |
| 95 |
*/ |
| 96 |
public DelegatingStyledCellLabelProvider(IStyledLabelProvider styledLabelProvider) |
| 97 |
{ |
| 98 |
super(styledLabelProvider); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* This implements {@link ILabelProvider#getText(Object)} by forwarding it to the wrapped styled label provider if |
| 103 |
* it implements {@link ILabelProvider}. Returns null otherwise. |
| 104 |
*/ |
| 105 |
public String getText(Object element) |
| 106 |
{ |
| 107 |
if (getStyledStringProvider() instanceof ILabelProvider) |
| 108 |
{ |
| 109 |
return ((ILabelProvider) getStyledStringProvider()).getText(element); |
| 110 |
} |
| 111 |
return null; |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* This implements {@link ITableFontProvider#getFont(Object, int)} by forwarding it to the wrapped styled label provider if |
| 116 |
* it implements {@link ITableFontProvider}. Returns null otherwise. |
| 117 |
*/ |
| 118 |
public Font getFont(Object element, int columnIndex) |
| 119 |
{ |
| 120 |
if (getStyledStringProvider() instanceof ITableFontProvider) |
| 121 |
{ |
| 122 |
return ((ITableFontProvider) getStyledStringProvider()).getFont(element, columnIndex); |
| 123 |
} |
| 124 |
return null; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* This implements {@link ITableColorProvider#getForeground(Object, int)} by forwarding it to the wrapped styled label provider if |
| 129 |
* it implements {@link ITableColorProvider}. Returns null otherwise. |
| 130 |
*/ |
| 131 |
public Color getForeground(Object element, int columnIndex) |
| 132 |
{ |
| 133 |
if (getStyledStringProvider() instanceof ITableColorProvider) |
| 134 |
{ |
| 135 |
return ((ITableColorProvider) getStyledStringProvider()).getForeground(element, columnIndex); |
| 136 |
} |
| 137 |
return null; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* This implements {@link ITableColorProvider#getBackground(Object, int)} by forwarding it to the wrapped styled label provider if |
| 142 |
* it implements {@link ITableColorProvider}. Returns null otherwise. |
| 143 |
*/ |
| 144 |
public Color getBackground(Object element, int columnIndex) |
| 145 |
{ |
| 146 |
if (getStyledStringProvider() instanceof ITableColorProvider) |
| 147 |
{ |
| 148 |
return ((ITableColorProvider) getStyledStringProvider()).getBackground(element, columnIndex); |
| 149 |
} |
| 150 |
return null; |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* This implements {@link ITableLabelProvider#getColumnImage(Object, int)} by forwarding it to the wrapped styled label provider if |
| 155 |
* it implements {@link ITableLabelProvider}. Returns null otherwise. |
| 156 |
*/ |
| 157 |
public Image getColumnImage(Object element, int columnIndex) |
| 158 |
{ |
| 159 |
if (getStyledStringProvider() instanceof ITableLabelProvider) |
| 160 |
{ |
| 161 |
return ((ITableLabelProvider) getStyledStringProvider()).getColumnImage(element, columnIndex); |
| 162 |
} |
| 163 |
return null; |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* This implements {@link ITableLabelProvider#getColumnText(Object, int)} by forwarding it to the wrapped styled label provider if |
| 168 |
* it implements {@link ITableLabelProvider}. Returns null otherwise. |
| 169 |
*/ |
| 170 |
public String getColumnText(Object element, int columnIndex) |
| 171 |
{ |
| 172 |
if (getStyledStringProvider() instanceof ITableLabelProvider) |
| 173 |
{ |
| 174 |
return ((ITableLabelProvider) getStyledStringProvider()).getColumnText(element, columnIndex); |
| 175 |
} |
| 176 |
return null; |
| 177 |
} |
| 178 |
} |