Package tool.navigator.common

Source Code of tool.navigator.common.LabelProvider

package tool.navigator.common;

import org.eclipse.core.resources.IFolder;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.navigator.IDescriptionProvider;

import tool.ToolPlugin;
import tool.ToolProjectSupport;
import tool.model.IClassComponent;
import tool.model.IProjectComponent;
import tool.model.ToolCMember;
import tool.model.ToolComponent;
import tool.model.ToolConstant;
import tool.model.ToolPlan;
import tool.model.ToolServiceObject;
/**
* Provides a label and icon for objects of type {@link TreeData}.
*
* @since 3.2
*
*/
public class LabelProvider extends org.eclipse.jface.viewers.LabelProvider implements
    ILabelProvider, IDescriptionProvider {
 
  private int options = 0;
 

  public static int FULL_PATH = 1;

  public LabelProvider(int options) {
    this();
    this.options = options;
  }
  public LabelProvider() {
    super();
  }

  public Image getImage(Object element) {
    if (element instanceof IProjectComponent){
      IProjectComponent model = (IProjectComponent)element;
      return ToolPlugin.getImage(model.getIconString());
    } else if (element instanceof IClassComponent){
      return ToolPlugin.getImage(((IClassComponent)element).getIconString());
    } else if (element instanceof ToolPlan){
      ToolPlan plan = (ToolPlan)element;
      if (plan.isFortePlan() || plan.isLibrary())
        return ToolPlugin.getImage("icons/library.gif");
      else
        return ToolPlugin.getImage("icons/package.gif");
    } else if (element instanceof IFolder && ToolProjectSupport.isSourceFolder((IFolder)element)){
      return ToolPlugin.getImage("icons/packagefolder.gif");
    }else if (element instanceof ToolCMember){
      return ToolPlugin.getImage("icons/public_attribute.gif");
    }
    return null;
  }

  public String getText(Object element) {
    if (element == null)
      return "Null model element - Check content provider";
    if (element instanceof ToolComponent){
      ToolComponent component = (ToolComponent)element;
      return component.getLabelText(this.options);
    } else if (element instanceof ToolCMember){
      ToolCMember component = (ToolCMember)element;
      return component.getName() + " : " + component.getType();
    }
    return element.toString();
  }

  public String getDescription(Object anElement) {
    if (anElement instanceof ToolConstant) {
      ToolConstant data = (ToolConstant) anElement;
      return "Constant: " + data.getName();
    } else if (anElement instanceof ToolServiceObject) {
      ToolServiceObject data = (ToolServiceObject) anElement;
      return "Service Object: " + data.getToolName();
    } else if (anElement instanceof IClassComponent){
      String name = ((ToolComponent)((IClassComponent)anElement).getParent()).getToolName() + "." + ((IClassComponent)anElement).getLabelText();
      return name;
    }
    return null;
  }

}
TOP

Related Classes of tool.navigator.common.LabelProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.