Package de.innovationgate.eclipse.wgadesigner.team

Source Code of de.innovationgate.eclipse.wgadesigner.team.WGAFSDesignResourceSyncInfo

/*******************************************************************************
* 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.team;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Path;
import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.variants.IResourceVariant;
import org.eclipse.team.core.variants.IResourceVariantComparator;

import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.eclipse.wgadesigner.models.WGARemoteServer;
import de.innovationgate.eclipse.wgadesigner.natures.WGARuntime;
import de.innovationgate.wgaservices.types.FSDesignResourceState;

public class WGAFSDesignResourceSyncInfo extends SyncInfo {

  private WGARuntime _runtime;
  private WGARemoteServer _server;
  private LocalFSDesignResourceState _localState;

  public WGAFSDesignResourceSyncInfo(WGARuntime runtime, WGARemoteServer server, IResource local, LocalFSDesignResourceState localState, IResourceVariant base, IResourceVariant remote, IResourceVariantComparator comparator) {   
    super(local, base, remote, comparator);
    _server = server;
    _runtime = runtime;
    _localState = localState;
  }

  public WGARemoteServer getServer() {
    return _server;
  }

  public void setServer(WGARemoteServer server) {
    _server = server;
  }

  public WGARuntime getRuntime() {
    return _runtime;
  }

  public void setRuntime(WGARuntime runtime) {
    _runtime = runtime;
  }

  @Override
  public int getKind() {
    if (getLocal() instanceof IProject) {
      return IN_SYNC;
    } else if (getLocal().equals(_runtime.getDesignRoot())) {
      return IN_SYNC;
    }else if (getLocal().exists() && !WGADesignStructureHelper.isWGADesignResource(getLocal())) {
      return IN_SYNC; 
   
    return super.getKind();
  }
 
  /**
   * determines if the underlying resource is located within the runtime designroot or linked external
   * @return
   */
  public boolean isExternal() {
    return !getRuntime().getDesignRoot().getFullPath().isPrefixOf(getLocal().getFullPath());
  }
 
  /**
   *
   * @return the path ono the remote server rooted at wga design root for this resource
   */
  public String getRemotePath() {
    if (!isExternal()) {
      int matchingSegments = getRuntime().getDesignRoot().getFullPath().matchingFirstSegments(getLocal().getFullPath());     
      return getLocal().getFullPath().removeFirstSegments(matchingSegments).makeRelative().toString();
    } else {
      if (_localState != null && _localState.isDirLink()) {
        String linkName = _localState.getDirLinkName();
        IContainer linkTarget = _localState.getDirLinkTarget();
        int matchingSegments = linkTarget.getFullPath().matchingFirstSegments(getLocal().getFullPath());     
        return new Path(linkName).append(getLocal().getFullPath().removeFirstSegments(matchingSegments)).makeRelative().toString();       
      } else if (getRemote() != null) {
        FSDesignResourceState remoteState = ((WGAFSDesignResourceVariant)getRemote()).getState();
        if (remoteState != null) {
          return remoteState.getPath();
        }
      }
    }
    return null;
  }

}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.team.WGAFSDesignResourceSyncInfo

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.