| /******************************************************************************* |
| * Copyright (c) 2012 SAP AG. |
| * 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: |
| * Georgi Konstantinov - initial API and implementation. |
| *******************************************************************************/ |
| package org.eclipse.wst.sse.sieditor.search.ui; |
| |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.core.runtime.Path; |
| import org.eclipse.wst.sse.sieditor.model.api.IModelObject; |
| import org.eclipse.wst.sse.sieditor.model.api.IQNamedObject; |
| import org.eclipse.wst.sse.sieditor.search.ui.tree.FileNode; |
| import org.eclipse.wst.sse.sieditor.ui.v2.common.AbstractEditorLabelProvider; |
| import org.eclipse.wst.sse.sieditor.ui.v2.nodes.ITreeNode; |
| |
| public class SearchResultLableProvider extends AbstractEditorLabelProvider { |
| @Override |
| public String getText(Object element) { |
| if (element instanceof FileNode) { |
| return ((FileNode) element).getTreeDisplayText(); |
| } |
| |
| return super.getText(element); |
| } |
| |
| @Override |
| public String getToolTipText(Object element) { |
| if (!(element instanceof ITreeNode)) { |
| return null; |
| } |
| |
| ITreeNode treeNode = (ITreeNode) element; |
| IModelObject modelObject = treeNode.getModelObject(); |
| if (modelObject == null) { |
| return null; |
| } |
| |
| if (!(modelObject instanceof IQNamedObject)) { |
| return null; |
| } |
| |
| IQNamedObject namedObject = (IQNamedObject) modelObject; |
| String result = "Namespace: " + namedObject.getNamespace(); //$NON-NLS-1$ |
| |
| result += "\nFile: " + getFilePath(namedObject); //$NON-NLS-1$ |
| |
| String documentation = modelObject.getDocumentation(); |
| if (documentation != null && !documentation.isEmpty()) { |
| result += "\nDocumentation: " + documentation.trim(); //$NON-NLS-1$ |
| } |
| |
| return result; |
| } |
| |
| protected String getFilePath(IQNamedObject namedObject) { |
| String strFile = namedObject.getComponent().eResource().getURI().toFileString(); |
| IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(strFile)); |
| return iFile.getFullPath().toString(); |
| } |
| } |