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.dynamic.views;
11:
12: import org.eclipse.core.runtime.Assert;
13: import org.eclipse.jface.viewers.IStructuredSelection;
14: import org.eclipse.jface.viewers.StructuredSelection;
15: import org.eclipse.jface.viewers.TreeNode;
16: import org.eclipse.swt.graphics.Image;
17: import org.eclipse.ui.tests.views.properties.tabbed.dynamic.model.DynamicTestsElement;
18:
19: /**
20: * Label provider for the title bar for the tabbed property view.
21: *
22: * @author Anthony Hunter
23: */
24: public class DynamicTestsTitleBarLabelProvider extends
25: org.eclipse.jface.viewers.LabelProvider {
26:
27: public Image getImage(Object obj) {
28: Assert.isTrue(obj instanceof IStructuredSelection);
29: IStructuredSelection structuredSelection = (IStructuredSelection) obj;
30: if (structuredSelection.equals(StructuredSelection.EMPTY)
31: || structuredSelection.size() > 1) {
32: return null;
33: }
34: DynamicTestsElement dynamicTestsElement = (DynamicTestsElement) ((DynamicTestsTreeNode) structuredSelection
35: .getFirstElement()).getValue();
36: return dynamicTestsElement.getImage();
37: }
38:
39: public String getText(Object obj) {
40: Assert.isTrue(obj instanceof IStructuredSelection);
41: IStructuredSelection structuredSelection = (IStructuredSelection) obj;
42: if (structuredSelection.equals(StructuredSelection.EMPTY)) {
43: return null;
44: }
45: if (structuredSelection.size() > 1) {
46: return structuredSelection.size() + " items selected";//$NON-NLS-1$
47: }
48: DynamicTestsElement dynamicTestsElement = (DynamicTestsElement) ((TreeNode) structuredSelection
49: .getFirstElement()).getValue();
50: return dynamicTestsElement.getName();
51: }
52: }
|