Package de.innovationgate.eclipse.editors.helpers

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

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

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;

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

public class ContainerFileReferenceLookup 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") && region.hasAttribute("doc") && !region.isDynamicAttributeValue("doc")) {
          String containername = region.getAttributeValue("doc");
          //final IFolder fContainer = new WGADesignStructureHelper(activeFile).getFileContainer(containername);

          final IFolder fContainer = WGADesignStructureHelper.findReferencedFileContainer(activeFile, containername);
         
          if (fContainer != null) {
            final Set<String> fReferences = references;
            try {
              fContainer.accept(new IResourceVisitor() {

                public boolean visit(IResource resource) throws CoreException {
                  if (resource instanceof IFile) {
                    fReferences.add(resource.getName().toLowerCase());
                    return true;
                  } else if (resource.equals(fContainer)) {
                    return true;
                  } else {
                    return false;
                  }
                }

              });
            } catch (CoreException e) {
              Plugin.getDefault().logError("Unable to lookup container file references of filecontainer '" + fContainer.getLocation() + "'.", e);
            }
          }
        }
      }
     
      if (tagName.equals("image") || tagName.equals("img")) {
       
        if (region.hasAttribute("doc") && !region.isDynamicAttributeValue("doc") && !region.hasAttribute("db")) {
          String containername = region.getAttributeValue("doc");
          //final IFolder fContainer = new WGADesignStructureHelper(activeFile).getFileContainer(containername);
          final IFolder fContainer = WGADesignStructureHelper.findReferencedFileContainer(activeFile, containername);
          if (fContainer != null) {
            final Set<String> fReferences = references;
            try {
              fContainer.accept(new IResourceVisitor() {

                public boolean visit(IResource resource) throws CoreException {
                  if (resource instanceof IFile) {
                    fReferences.add(resource.getName().toLowerCase());
                    return true;
                  } else if (resource.equals(fContainer)) {
                    return true;
                  } else {
                    return false;
                  }
                }

              });
            } catch (CoreException e) {
              Plugin.getDefault().logError("Unable to lookup container file references of filecontainer '" + fContainer.getLocation() + "'.", e);
            }
          }
        }
      }
     
     
     
     
     
     
    }
    return references;
  }

}
TOP

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

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.