01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.tests.views.properties.tabbed.text;
11:
12: import java.util.StringTokenizer;
13:
14: import org.eclipse.jface.text.ITextSelection;
15: import org.eclipse.jface.viewers.LabelProvider;
16: import org.eclipse.swt.graphics.Image;
17: import org.eclipse.ui.ISharedImages;
18: import org.eclipse.ui.PlatformUI;
19:
20: /**
21: * Label provider for the title bar for the tabbed property view.
22: *
23: * @author Anthony Hunter
24: */
25: public class TextTestsLabelProvider extends LabelProvider {
26:
27: /**
28: * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
29: */
30: public Image getImage(Object obj) {
31: return PlatformUI.getWorkbench().getSharedImages().getImage(
32: ISharedImages.IMG_OBJ_FILE);
33: }
34:
35: /**
36: * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
37: */
38: public String getText(Object obj) {
39: if (obj instanceof ITextSelection) {
40: ITextSelection textSelection = (ITextSelection) obj;
41: if (textSelection.getLength() != 0) {
42: StringTokenizer tokenizer = new StringTokenizer(
43: textSelection.getText());
44: int size = 0;
45: while (tokenizer.hasMoreTokens()) {
46: size++;
47: tokenizer.nextToken();
48: }
49: if (size == 1) {
50: return textSelection.getText();
51: }
52: return size + " words selected";//$NON-NLS-1$
53: }
54: }
55: return null;
56: }
57: }
|