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);
}
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;
}
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);
}
}
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());
}
}
}
}
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;
}
Aggregations