Package de.innovationgate.eclipse.wgadesigner.classpath

Source Code of de.innovationgate.eclipse.wgadesigner.classpath.WGALibrarySetContainer

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

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IAccessRule;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;

import de.innovationgate.eclipse.utils.BeanMapPreferencesStore;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;

/**
* a classpath container which provides libraries from a WGA library set
*
* the containerpath includes ID/<librarySetID>
*
*
*
*/
public class WGALibrarySetContainer implements IClasspathContainer {
 
  public static final String ID = "de.innovationgate.eclipse.ids.classpath.WGALibrarySet";
 
  private IPath _path;

  private LibrarySet _librarySet;

  public WGALibrarySetContainer(IPath path) {
    _path = path;
    // extract the libraryset id from path
    String librarySetId = _path.lastSegment();
   
    // retrieve library set
    _librarySet = WGADesignerPlugin.getDefault().getLibrarySets().get(librarySetId);
  }

  public IClasspathEntry[] getClasspathEntries() {
    List<IClasspathEntry> entryList = new ArrayList<IClasspathEntry>()
    BeanMapPreferencesStore<IPath, LibraryClasspathEntryInformation> store = WGADesignerPlugin.getDefault().getLibraryClasspathEntryInformationStore();
    store.load();
    Map<IPath, LibraryClasspathEntryInformation> infos = store.getBeans();   
    IClasspathEntry[] entries =  _librarySet.getClasspathEntries();
    for (IClasspathEntry entry : entries) {
      // check if we have additional infos for this entry
      LibraryClasspathEntryInformation info = infos.get(entry.getPath());
      if (info != null) {
        IPath srcPath = info.getSourcePath();
        IPath srcRoot = new Path("/");
        if (srcPath == null) {
          srcPath = new Path("");
          srcRoot = null;
        }
       
        entryList.add(JavaCore.newLibraryEntry(entry.getPath(), srcPath, srcRoot, new IAccessRule[0], info.getAttributes(), false));
      } else {
        entryList.add(JavaCore.newLibraryEntry(entry.getPath(), new Path(""), null));
      }
    }
    return entryList.toArray(new IClasspathEntry[0]);
  }

  public String getDescription() {
    return "WGA Library Set (" + _librarySet.getName() + ")";
  }

  public int getKind() {
    return IClasspathContainer.K_APPLICATION;
  }

  public IPath getPath() {
    return _path;
  }

  public boolean isValid() {
    return _librarySet != null;
  }

}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.classpath.WGALibrarySetContainer

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.