Search in sources :

Example 6 with EResourceConstant

use of org.talend.resource.EResourceConstant in project tdq-studio-se by Talend.

the class FileTreeLabelProvider method getImage.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
     */
@Override
public Image getImage(Object element) {
    Image image = null;
    if (element instanceof ItemRecord) {
        ItemRecord record = (ItemRecord) element;
        File file = record.getFile();
        String fileName = file.getName();
        if (file.isDirectory()) {
            image = ImageLib.getImage(ImageLib.FOLDERNODE_IMAGE);
            EResourceConstant constant = resolveResourceConstant(fileName);
            if (constant != null) {
                switch(constant) {
                    case DATA_PROFILING:
                        image = ImageLib.getImage(ImageLib.DATA_PROFILING);
                        break;
                    case METADATA:
                        image = ImageLib.getImage(ImageLib.METADATA);
                        break;
                    case LIBRARIES:
                        image = ImageLib.getImage(ImageLib.LIBRARIES);
                        break;
                    case ANALYSIS:
                        break;
                    case REPORTS:
                        break;
                    case EXCHANGE:
                        image = ImageLib.getImage(ImageLib.EXCHANGE);
                        break;
                    case DB_CONNECTIONS:
                        image = ImageLib.getImage(ImageLib.CONNECTION);
                        break;
                    case FILEDELIMITED:
                        image = ImageLib.getImage(ImageLib.FILE_DELIMITED);
                        break;
                    case HADOOP_CLUSTER:
                        image = ImageLib.getImage(ImageLib.HADOOP_CLUSTER);
                        break;
                    case CONTEXT:
                        image = ImageLib.getImage(ImageLib.CONTEXT);
                        break;
                    default:
                        break;
                }
            }
        } else {
            if (fileName.endsWith(FactoriesUtil.ANA)) {
                image = ImageLib.getImage(ImageLib.ANALYSIS_OBJECT);
            } else if (fileName.endsWith(FactoriesUtil.REP)) {
                image = ImageLib.getImage(ImageLib.REPORT_OBJECT);
            } else if (fileName.endsWith(FactoriesUtil.PATTERN)) {
                image = ImageLib.getImage(ImageLib.PATTERN_REG);
            } else if (fileName.endsWith(FactoriesUtil.DQRULE)) {
                if (record.getElement() instanceof MatchRuleDefinition) {
                    image = ImageLib.getImage(ImageLib.MATCH_RULE_ICON);
                } else {
                    image = ImageLib.getImage(ImageLib.DQ_RULE);
                }
            } else if (fileName.endsWith(FactoriesUtil.ITEM_EXTENSION)) {
                if (record.getElement() instanceof DelimitedFileConnection) {
                    image = ImageLib.getImage(ImageLib.FILE_DELIMITED);
                } else if (record.getElement() instanceof DatabaseConnection) {
                    image = ImageLib.getImage(ImageLib.TD_DATAPROVIDER);
                } else {
                    image = ImageLib.getImage(ImageLib.CONTEXT);
                }
            } else if (fileName.endsWith(FactoriesUtil.DEFINITION)) {
                image = ImageLib.getImage(ImageLib.IND_DEFINITION);
            } else if (fileName.endsWith(FactoriesUtil.SQL)) {
                image = ImageLib.getImage(ImageLib.SOURCE_FILE);
            } else if (fileName.endsWith(FactoriesUtil.JAR)) {
                image = ImageLib.getImage(ImageLib.JAR_FILE);
            } else if (fileName.endsWith(FactoriesUtil.JRXML)) {
                image = ImageLib.getImage(ImageLib.JRXML_ICON);
            }
        }
    }
    return image != null ? image : super.getImage(element);
}
Also used : EResourceConstant(org.talend.resource.EResourceConstant) ItemRecord(org.talend.dataprofiler.core.ui.imex.model.ItemRecord) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Image(org.eclipse.swt.graphics.Image) File(java.io.File)

Example 7 with EResourceConstant

use of org.talend.resource.EResourceConstant in project tdq-studio-se by Talend.

the class ItemRecord method isValidDirectory.

/**
 * DOC bZhou Comment method "isTOPFile".
 *
 * @param f
 * @return
 */
private boolean isValidDirectory(File f) {
    // filter the bin folder
    if (!f.getName().startsWith(".") && !f.getName().equals("bin")) {
        // $NON-NLS-1$ //$NON-NLS-2$
        IPath filePath = new Path(f.getAbsolutePath());
        String pathStr = filePath.toPortableString();
        for (EResourceConstant constant : EResourceConstant.getTdqConstants()) {
            if (filePath.toString().indexOf(constant.getPath()) > 0) {
                String lastSeg = filePath.lastSegment();
                if (constant == EResourceConstant.METADATA) {
                    return lastSeg.equals(constant.getName()) || pathStr.contains(EResourceConstant.DB_CONNECTIONS.getPath()) || pathStr.contains(EResourceConstant.FILEDELIMITED.getPath());
                }
                return true;
            }
        }
    }
    return false;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) EResourceConstant(org.talend.resource.EResourceConstant) IPath(org.eclipse.core.runtime.IPath)

Example 8 with EResourceConstant

use of org.talend.resource.EResourceConstant in project tdq-studio-se by Talend.

the class DependenciesHandler method findClientAndRemoveDependencyInLocalProject.

private static void findClientAndRemoveDependencyInLocalProject(ModelElement modelElement, ModelElement analysis) {
    URI uri = EObjectHelper.getURI(modelElement).trimFileExtension().appendFileExtension(FactoriesUtil.PROPERTIES_EXTENSION);
    // get file from filename
    String fileName = uri.lastSegment();
    File foundFile = null;
    EResourceConstant[] topConstants = EResourceConstant.getTopConstants();
    for (EResourceConstant resource : topConstants) {
        File reportFolder = ResourceManager.getRootProject().getLocation().append(resource.getPath()).toFile();
        List<File> fileList = FileUtils.getFilesByExtension(reportFolder, FactoriesUtil.PROPERTIES_EXTENSION);
        for (File file : fileList) {
            if (file.getName().equals(fileName)) {
                foundFile = file;
                break;
            }
        }
        if (foundFile != null) {
            break;
        }
    }
    // from file to get model and change it
    if (foundFile != null) {
        Property property = PropertyHelper.getProperty(foundFile);
        // change the cache content also
        Item item = property.getItem();
        Resource itemResource = ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().getItemResource(item);
        List<EObject> toRemoveObjList = new ArrayList<EObject>();
        for (EObject obj : itemResource.getContents()) {
            if (obj != null && obj instanceof Dependency) {
                EList<ModelElement> clients = ((Dependency) obj).getClient();
                for (ModelElement model : clients) {
                    if (model.getName() == null) {
                        toRemoveObjList.add(obj);
                    } else {
                        if (StringUtils.equals(model.getName(), analysis.getName())) {
                            toRemoveObjList.add(obj);
                            break;
                        }
                    }
                }
                EList<ModelElement> supplier = ((Dependency) obj).getSupplier();
                for (ModelElement model : supplier) {
                    if (model.getName() == null) {
                        toRemoveObjList.add(obj);
                    } else {
                        if (StringUtils.equals(model.getName(), item.getProperty().getLabel())) {
                            toRemoveObjList.add(obj);
                            break;
                        }
                    }
                }
            } else {
                // modify where rule
                EList<Dependency> supplierDependency = ((ModelElement) obj).getSupplierDependency();
                Iterator<Dependency> iterator = supplierDependency.iterator();
                while (iterator.hasNext()) {
                    Dependency model = iterator.next();
                    EList<ModelElement> clients = model.getClient();
                    for (ModelElement client : clients) {
                        if (StringUtils.equals(client.getName(), analysis.getName())) {
                            iterator.remove();
                            break;
                        }
                    }
                }
            }
        }
        for (EObject removeObj : toRemoveObjList) {
            if (removeObj != null) {
                itemResource.getContents().remove(removeObj);
            }
        }
        // save the node
        AElementPersistance writer = ElementWriterFactory.getInstance().create(item);
        writer.save(item, true);
    }
}
Also used : EResourceConstant(org.talend.resource.EResourceConstant) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) Dependency(orgomg.cwm.objectmodel.core.Dependency) URI(org.eclipse.emf.common.util.URI) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Item(org.talend.core.model.properties.Item) TDQSourceFileItem(org.talend.dataquality.properties.TDQSourceFileItem) TDQFileItem(org.talend.dataquality.properties.TDQFileItem) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EObject(org.eclipse.emf.ecore.EObject) AElementPersistance(org.talend.dq.writer.AElementPersistance) File(java.io.File) Property(org.talend.core.model.properties.Property)

Example 9 with EResourceConstant

use of org.talend.resource.EResourceConstant in project tdq-studio-se by Talend.

the class AddPackageFilterForDBTask method updateConnectionFile.

private void updateConnectionFile() {
    File rawDir = getWorkspacePath().append(EResourceConstant.METADATA.getPath()).toFile();
    ArrayList<File> fileList = new ArrayList<File>();
    if (rawDir.exists()) {
        getAllFilesFromFolder(rawDir, fileList, new FilenameFilter() {

            public boolean accept(File dir, String name) {
                return name.endsWith(FactoriesUtil.ITEM_EXTENSION);
            }
        });
    }
    for (File file : fileList) {
        IFile iFile = WorkspaceUtils.fileToIFile(file);
        Property property = PropertyHelper.getProperty(iFile);
        if (property != null) {
            Item item = property.getItem();
            EResourceConstant type = EResourceConstant.getTypedConstant(item);
            if (type == EResourceConstant.DB_CONNECTIONS) {
                DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
                DatabaseConnection connection = (DatabaseConnection) dbItem.getConnection();
                // set package filter to old connection file
                // $NON-NLS-1$
                ConnectionHelper.setPackageFilter(connection, "");
                EMFSharedResources.getInstance().saveResource(connection.eResource());
            }
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EResourceConstant(org.talend.resource.EResourceConstant) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) File(java.io.File) IFile(org.eclipse.core.resources.IFile) Property(org.talend.core.model.properties.Property) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 10 with EResourceConstant

use of org.talend.resource.EResourceConstant in project tdq-studio-se by Talend.

the class ModelElementDuplicateHandle method extractFolder.

/**
 * DOC msjian Comment method "extractFolder".
 *
 * @param oldItem
 * @param oldObject
 * @return
 */
protected IFolder extractFolder(Item oldItem, ModelElement oldObject) {
    Resource resource = oldObject.eResource();
    IPath path = new Path(resource.getURI().toPlatformString(false));
    IFile oldFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    boolean inCurrentMainProject = ProjectManager.getInstance().isInCurrentMainProject(oldItem);
    IFolder parent = (IFolder) oldFile.getParent();
    if (inCurrentMainProject) {
        return parent;
    } else {
        // for the reference project node, we get its folder in current project.
        EResourceConstant typedConstant = EResourceConstant.getTypedConstant(oldObject);
        if (typedConstant != null) {
            return ResourceManager.getOneFolder(typedConstant);
        }
    }
    return parent;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) EResourceConstant(org.talend.resource.EResourceConstant) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Resource(org.eclipse.emf.ecore.resource.Resource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

EResourceConstant (org.talend.resource.EResourceConstant)11 ArrayList (java.util.ArrayList)5 File (java.io.File)4 IFile (org.eclipse.core.resources.IFile)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 Item (org.talend.core.model.properties.Item)3 Property (org.talend.core.model.properties.Property)3 FilenameFilter (java.io.FilenameFilter)2 IFolder (org.eclipse.core.resources.IFolder)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)2 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)2 IOException (java.io.IOException)1 CoreException (org.eclipse.core.runtime.CoreException)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 ISelection (org.eclipse.jface.viewers.ISelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1