Package tool.builder.resource

Source Code of tool.builder.resource.RepositoryPropertiesManager

package tool.builder.resource;

import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ISynchronizer;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jface.resource.ImageDescriptor;

import tool.ToolBuilderActivator;
import tool.builder.ToolNature;

/**
* @author peter
*
* Utility class to add, modify, get the persistent property of the
* resource.
*
*/
public class RepositoryPropertiesManager

{
  static ISynchronizer syncronizer = ResourcesPlugin.getWorkspace().getSynchronizer();
/**
  * Constructor for DemoResourcePersistentProperty.
  */
  public RepositoryPropertiesManager()
  {
  }
 


 
  /**
   * Generic method to add persistent properties for the resource
   *
   * @param resource IResource object
   * @param localName qualifier name of the persistent property
   * @param value indicate the value of the property
   *
   */ 
  public static void addRepositoryStateProperty (IResource resource,
                                             String value)   
  {
   
    try
    {
      byte[] bytes = value.getBytes();
      syncronizer.setSyncInfo(getSyncQualifiedName(resource), resource, bytes);
    }
    // Catch Exception
    catch(Exception e)
    {
      e.printStackTrace();
      System.out.println(e.getMessage());
    }
  }
 
  /**
   * Add persistent properties for a resource list
   *
   * @param resourceList List of IResource objects
   * @param localName qualifier name of the persistent property
   * @param value  to indicate the value of the property
   *
   */ 
  public static void addRepositoryStateProperty (List<IResource> resourceList,
                                             String value)   
  {
    for (IResource resource : resourceList)
    {
      try
      {
        //resource.setPersistentProperty(ToolNature.repositoryStateQualifiedName, value);
        addRepositoryStateProperty(resource, value);
       
      }
      // Catch Exception
      catch(Exception e)
      {
        e.printStackTrace();
        System.out.println(e.getMessage());
      }
    }
  }
 
 
  /**
   * Find the decorator image for the resource.
   *
   * @param resource IResource Object
   *
   * @return the image decoration as List. For eg: If the file has a read
   * only property set, it returns a list with Lock as the only element
* @throws CoreException
   */
  public static ImageDescriptor findDecorationImageForResource (IResource resource) throws CoreException
 
  {
    String reposState = getRepositoryState(resource);
    if (reposState == null ||reposState.equals(""))
      return null;
    if (reposState.equalsIgnoreCase(RepositoryComponent.READ_ONLY))
    {
      return ToolBuilderActivator.getImageDescriptor("icons/lock.gif");
    }
    else if (reposState.equalsIgnoreCase(RepositoryComponent.CHECKED_OUT))
    {
      return ToolBuilderActivator.getImageDescriptor("icons/checked_out.gif");
    }
    else if (reposState.equalsIgnoreCase(RepositoryComponent.BRANCHED))
    {
      return ToolBuilderActivator.getImageDescriptor("icons/brahched.gif");
    }
    else if (reposState.equalsIgnoreCase(RepositoryComponent.NEW))
    {
      return ToolBuilderActivator.getImageDescriptor("icons/new.gif");
    }
//    else if (reposState.equalsIgnoreCase(RepositoryComponent.NOT_IN_REPOSITORY))
//    {
//      return null;
//    }
    return null;
  }
 
  public static QualifiedName getSyncQualifiedName(IResource resource){
    return new QualifiedName(ToolNature.PROJECT_QUALIFIED_NAME, "Repository:" + resource.getProject().getName());
  }
 
  public static String getRepositoryState(IResource resource) throws CoreException{
    byte[] bytes = null;
    bytes = syncronizer.getSyncInfo(getSyncQualifiedName(resource), resource);
    if (bytes == null)
      return null;
    String reposState = new String(bytes);
    return reposState;
  }
}
TOP

Related Classes of tool.builder.resource.RepositoryPropertiesManager

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.