Package de.innovationgate.eclipse.wgadesigner.decorators

Source Code of de.innovationgate.eclipse.wgadesigner.decorators.DesignFolderDecorator

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner.decorators;

import java.io.File;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.team.ui.synchronize.ISynchronizeModelElement;

import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.utils.WGUtils;

/**
* decorator for designs folders
*
*
*/
public class DesignFolderDecorator extends LabelProvider implements ILabelDecorator {

  public Image decorateImage(Image image, Object element) {
    if(element instanceof ISynchronizeModelElement) {
          ISynchronizeModelElement node = (ISynchronizeModelElement)element;
          element = node.getResource();
    }
   
    if (element instanceof IContainer) {
      IContainer container = (IContainer) element;
      if (container.isAccessible() && WGADesignStructureHelper.isDesignFolder(container)) {
        WGADesignStructureHelper helper = new WGADesignStructureHelper(container);
        if (helper.hasPluginConfig()) {
          return WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_WGA_PLUGIN);
        } else {
          return WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_WGA_DESIGN);
        }
      } else if (container.isAccessible()) {
        // we might have to resolve dirlinks
        IFile dirlink = container.getFile(new Path("dirlink.xml"));
        if (dirlink.exists()) {
          File target = WGUtils.resolveDirLink(dirlink.getParent().getLocation().toFile());
          if (WGADesignStructureHelper.isDesignFolder(target)) {
            IContainer targets[] = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocation(new Path(target.getAbsolutePath()));
            if (targets != null && targets.length >= 1) {
              WGADesignStructureHelper helper = new WGADesignStructureHelper(targets[0]);
              if (helper.hasPluginConfig()) {
                return WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_WGA_PLUGIN_LINK);
              } else {
                return WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_WGA_DESIGN_LINK)
              }
            } else {
              return WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_WGA_DESIGN_LINK);
            }
          }
        }
      }
    }
    return image;
  }

  public String decorateText(String text, Object element) {
    return text;
  }

}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.decorators.DesignFolderDecorator

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.