Package de.innovationgate.eclipse.editors.helpers

Source Code of de.innovationgate.eclipse.editors.helpers.ContainerReferenceLookup

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

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;

import de.innovationgate.eclipse.editors.tml.TMLRegion;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.wga.model.VersionCompliance;

public class ContainerReferenceLookup implements AttributeValueLookup {

  public Set<String> lookupValues(TMLRegion region, IDocument document, ITextViewer viewer, IFile activeFile) {
    Set<String> references = new HashSet<String>();
    String tagName = region.getTagName();
   
    if (tagName != null) {
      if (tagName.equals("url") && region.hasAttribute("type") && !region.isDynamicAttributeValue("type") && !region.hasAttribute("db")) {
        String type = region.getAttributeValue("type");
        if (type != null && type.equals("file")) {               
            createReferenceValues(activeFile, references);
        }
      }
     
      if ((tagName.equals("image") || tagName.equals("img")) && !region.hasAttribute("db")) {
              createReferenceValues(activeFile, references);
      }
     
     
    }
    return references;
  }

    private void createReferenceValues(IFile activeFile, Set<String> references) {
        WGADesignStructureHelper helper = new WGADesignStructureHelper(activeFile);
        VersionCompliance versionCompliance = WGADesignStructureHelper.getWGAVersionCompliance(activeFile);
        Iterator<IFolder> containers = helper.getFileContainers().iterator();
        while (containers.hasNext()) {
           
            IFolder container = containers.next();
           
            if (versionCompliance != null && versionCompliance.toWGAVersion() != null && versionCompliance.toWGAVersion().isAtLeast(5, 4)) {                               
                IPath refPath = container.getFullPath().makeRelativeTo(helper.getFileContainerRoot().getFullPath());
              references.add(refPath.toString().toLowerCase().replaceAll("\\/",":"));
             
              IPath activeFolderPath = activeFile.getParent().getFullPath().makeRelativeTo(helper.getTmlRoot().getFullPath());
              // remove medium
              activeFolderPath = activeFolderPath.removeFirstSegments(1);
               if (activeFolderPath.segmentCount() > 0 && (refPath.segmentCount() >= activeFolderPath.segmentCount())) {
                    int a = refPath.segmentCount();
                    int b = activeFolderPath.segmentCount();
                    IPath tmp = refPath.removeLastSegments(a - b);
                    if (tmp.equals(activeFolderPath)) {
                        refPath = refPath.removeFirstSegments(tmp.segmentCount());
                        references.add("::" + refPath.toString().replaceAll("\\/", ":"));
                    }
   
                }
            } else {
                references.add(container.getName().toLowerCase());
            }
         
        }
    }

}
TOP

Related Classes of de.innovationgate.eclipse.editors.helpers.ContainerReferenceLookup

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.