Package org.springframework.ide.eclipse.beans.ui.namespaces

Source Code of org.springframework.ide.eclipse.beans.ui.namespaces.DefaultNamespaceLabelProvider

/*******************************************************************************
* Copyright (c) 2007, 2011 Spring IDE Developers
* 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:
*     Spring IDE Developers - initial API and implementation
*******************************************************************************/
package org.springframework.ide.eclipse.beans.ui.namespaces;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITreePathLabelProvider;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.ViewerLabel;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.navigator.IDescriptionProvider;
import org.springframework.ide.eclipse.beans.core.BeansCorePlugin;
import org.springframework.ide.eclipse.beans.core.internal.model.BeansModelUtils;
import org.springframework.ide.eclipse.beans.core.model.IBean;
import org.springframework.ide.eclipse.beans.core.model.IBeansComponent;
import org.springframework.ide.eclipse.beans.core.model.IProfileAwareBeansComponent;
import org.springframework.ide.eclipse.beans.ui.BeansUIImages;
import org.springframework.ide.eclipse.beans.ui.BeansUILabels;
import org.springframework.ide.eclipse.beans.ui.model.BeansModelImages;
import org.springframework.ide.eclipse.core.model.IModelElement;
import org.springframework.ide.eclipse.core.model.ISourceModelElement;

/**
* This class is a label provider which knows about the beans core model's {@link ISourceModelElement source elements}which belong to a namespace.
* @author Torsten Juergeleit
* @author Christian Dupuis
*/
public class DefaultNamespaceLabelProvider implements INamespaceLabelProvider, ITreePathLabelProvider,
    IDescriptionProvider {

  public Image getImage(ISourceModelElement element, IModelElement context, boolean isDecorating) {
    String namespaceUri = NamespaceUtils.getNameSpaceURI(element);

    if (element instanceof IBean && !NamespaceUtils.DEFAULT_NAMESPACE_URI.equals(namespaceUri)
        && !BeansModelUtils.isInnerBean((IBean) element)) {
      Image image = null;

      org.springframework.ide.eclipse.beans.core.model.INamespaceDefinition namespaceDefinition = BeansCorePlugin
          .getNamespaceDefinitionResolver(BeansModelUtils.getProject(element).getProject())
          .resolveNamespaceDefinition(namespaceUri);
      if (namespaceDefinition != null && namespaceDefinition.getIconPath() != null) {
        image = NamespaceUtils.getImage(namespaceDefinition);
      }
      else {
        image = BeansUIImages.getImage(BeansUIImages.IMG_OBJS_NAMESPACE_BEAN);
      }
      if (isDecorating) {
        image = BeansModelImages.getDecoratedImage(image, element, context);
      }
      return image;
    }
    else if (element instanceof IProfileAwareBeansComponent) {
      Image image = BeansUIImages.getImage(BeansUIImages.IMG_OBJS_CONFIG);
      if (isDecorating) {
        image = BeansModelImages.getDecoratedImage(image, element, context);
      }
      return image;
    }
    else if (element instanceof IBeansComponent) {
      Image image = null;

      org.springframework.ide.eclipse.beans.core.model.INamespaceDefinition namespaceDefinition = BeansCorePlugin
          .getNamespaceDefinitionResolver(BeansModelUtils.getProject(element).getProject())
          .resolveNamespaceDefinition(namespaceUri);
      if (namespaceDefinition != null && namespaceDefinition.getIconPath() != null) {
        image = NamespaceUtils.getImage(namespaceDefinition);
      }
      else {
        image = BeansUIImages.getImage(BeansUIImages.IMG_OBJS_NAMESPACE_COMPONENT);
      }
      if (isDecorating) {
        image = BeansModelImages.getDecoratedImage(image, element, context);
      }
      return image;
    }
    return BeansModelImages.getImage(element, context, isDecorating);
  }

  public String getText(ISourceModelElement element, IModelElement context, boolean isDecorating) {
    return getElementLabel(element, 0);
  }

  public void addListener(ILabelProviderListener listener) {
  }

  public void removeListener(ILabelProviderListener listener) {
  }

  public void dispose() {
  }

  public boolean isLabelProperty(Object element, String property) {
    return true;
  }

  public void updateLabel(ViewerLabel label, TreePath elementPath) {
    Object element = elementPath.getLastSegment();
    if (element instanceof ISourceModelElement && elementPath.getSegmentCount() > 1) {
      Object parent = elementPath.getParentPath().getLastSegment();
      IModelElement context = (parent instanceof IModelElement ? (IModelElement) parent : null);
      // TODO CD revise
      label.setImage(getImage((ISourceModelElement) element, context, false));
      label.setText(getText((ISourceModelElement) element, context, false));
    }
  }

  public String getDescription(Object element) {
    if (element instanceof ISourceModelElement) {
      return getElementLabel((ISourceModelElement) element, BeansUILabels.APPEND_PATH | BeansUILabels.DESCRIPTION);
    }
    return null;
  }

  protected String getElementLabel(ISourceModelElement element, int flags) {
    return DefaultNamespaceLabels.getElementLabel(element, flags);
  }
}
TOP

Related Classes of org.springframework.ide.eclipse.beans.ui.namespaces.DefaultNamespaceLabelProvider

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.