Ignore:
Timestamp:
02/28/12 13:43:20 (13 years ago)
Author:
wschamai
Message:

Improvements for loading Modelica files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modelicaml/org.openmodelica.modelicaml.common/src/org/openmodelica/modelicaml/common/services/ModelicaMLServices.java

    r1272 r1367  
    11package org.openmodelica.modelicaml.common.services;
    22
     3import java.io.File;
     4import java.net.URI;
    35import java.util.ArrayList;
    46import java.util.Collections;
     
    79import java.util.List;
    810
     11import org.eclipse.core.filesystem.EFS;
     12import org.eclipse.core.filesystem.IFileStore;
     13import org.eclipse.core.filesystem.IFileSystem;
     14import org.eclipse.core.runtime.CoreException;
    915import org.eclipse.core.runtime.IAdaptable;
    1016import org.eclipse.emf.common.util.EList;
     
    151157    }
    152158   
     159   
     160    public static List<String> getFilesToLoad(String folderAbsolutePath){
     161       
     162        // list of files to be loaded
     163        List<String> list = new ArrayList<String>();
     164
     165        // add "/" at the end if there is none
     166        if (!folderAbsolutePath.trim().endsWith("/")) {
     167            folderAbsolutePath = folderAbsolutePath + "/";
     168        }
     169       
     170        File folder = new File(folderAbsolutePath);
     171        if (folder.isDirectory()) {
     172            /*
     173             * - get all .mo files add these to the list
     174             * - get all sub.folders and add sub-folder-name/package.mo to the list
     175             */
     176            IFileSystem fileSystem = EFS.getLocalFileSystem();
     177            IFileStore folderStore = fileSystem.getStore(URI.create(folderAbsolutePath));
     178           
     179            String[] children;
     180            try {
     181                children = folderStore.childNames(EFS.NONE, null);
     182                for (int i = 0; i < children.length; i++) {
     183                    String child = children[i];
     184                   
     185                    File checkChild = new File(folderAbsolutePath + child);
     186                   
     187                    if (child.endsWith(".mo")) { // if it is a .mo file
     188                        list.add(folderAbsolutePath + child);
     189                    }
     190                    else if (checkChild.isDirectory()) { // if it is a folder
     191                        list.add(folderAbsolutePath + child + "/package.mo");
     192                    }
     193                    else { // any other files
     194                       
     195                    }
     196                }
     197            } catch (CoreException e) {
     198                // TODO Auto-generated catch block
     199                e.printStackTrace();
     200            }
     201        }
     202        return list;
     203    }
     204   
    153205}
Note: See TracChangeset for help on using the changeset viewer.