View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.argeo.cms.ui.jcr;
17  
18  import javax.jcr.Node;
19  import javax.jcr.RepositoryException;
20  import javax.jcr.version.Version;
21  
22  import org.argeo.eclipse.ui.EclipseUiException;
23  import org.eclipse.jface.viewers.ColumnLabelProvider;
24  
25  /**
26   * Simple wrapping of the ColumnLabelProvider class to provide text display in
27   * order to build a tree for version. The getText() method does not assume that
28   * {@link Version} extends {@link Node} class to respect JCR 2.0 specification
29   * 
30   */
31  public class VersionLabelProvider extends ColumnLabelProvider {
32  	private static final long serialVersionUID = 5270739851193688238L;
33  
34  	public String getText(Object element) {
35  		try {
36  			if (element instanceof Version) {
37  				Version version = (Version) element;
38  				return version.getName();
39  			} else if (element instanceof Node) {
40  				return ((Node) element).getName();
41  			}
42  		} catch (RepositoryException re) {
43  			throw new EclipseUiException(
44  					"Unexpected error while getting element name", re);
45  		}
46  		return super.getText(element);
47  	}
48  }