Compare commits
2 Commits
patch/7.3.
...
ggu/TUP-17
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8dc804b72a | ||
|
|
fb9e2638b6 |
@@ -21,8 +21,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.jface.util.LocalSelectionTransfer;
|
||||
import org.eclipse.jface.viewers.IBaseLabelProvider;
|
||||
@@ -46,6 +44,7 @@ import org.osgi.framework.ServiceRegistration;
|
||||
import org.osgi.service.event.Event;
|
||||
import org.osgi.service.event.EventConstants;
|
||||
import org.osgi.service.event.EventHandler;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.core.model.properties.Property;
|
||||
import org.talend.core.model.repository.IRepositoryViewObject;
|
||||
import org.talend.core.repository.CoreRepositoryPlugin;
|
||||
@@ -58,6 +57,7 @@ import org.talend.repository.model.IRepositoryNode;
|
||||
import org.talend.repository.model.RepositoryNode;
|
||||
import org.talend.repository.view.sorter.IRepositoryNodeSorter;
|
||||
import org.talend.repository.view.sorter.RepositoryNodeSorterRegister;
|
||||
import org.talend.repository.view.util.RepoViewRefreshHelper;
|
||||
import org.talend.repository.viewer.content.listener.IRefreshNodePerspectiveListener;
|
||||
import org.talend.repository.viewer.ui.provider.INavigatorContentServiceProvider;
|
||||
|
||||
@@ -414,13 +414,21 @@ public class RepoViewCommonViewer extends CommonViewer implements INavigatorCont
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
RepoViewRefreshHelper helper = new RepoViewRefreshHelper();
|
||||
for (String fileUpdated : fileList) {
|
||||
XmiResourceManager xrm = new XmiResourceManager();
|
||||
if (xrm.isPropertyFile(fileUpdated)) {
|
||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileUpdated));
|
||||
if (file != null && file.isAccessible()) {
|
||||
Property property = xrm.loadProperty(file);
|
||||
refreshNodeFromProperty(property);
|
||||
IFile file = helper.getValidResourceFile(fileUpdated);
|
||||
if (file != null) {
|
||||
try {
|
||||
Property property = xrm.loadProperty(file);
|
||||
if (property != null) {
|
||||
refreshNodeFromProperty(property);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// if have error still, just log it
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2016 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.repository.view.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.talend.core.model.repository.ERepositoryObjectType;
|
||||
|
||||
/**
|
||||
* DOC ggu class global comment. Detailled comment
|
||||
*/
|
||||
public class RepoViewRefreshHelper {
|
||||
|
||||
protected List<String> resourceFolderList = new ArrayList<String>();
|
||||
|
||||
public RepoViewRefreshHelper() {
|
||||
for (ERepositoryObjectType type : (ERepositoryObjectType[]) ERepositoryObjectType.values(ERepositoryObjectType.class)) {
|
||||
// must be resource folder
|
||||
if (type.isResouce() && type.hasFolder()) {
|
||||
resourceFolderList.add(type.getFolder());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IFile getValidResourceFile(String filePath) {
|
||||
if (StringUtils.isBlank(filePath)) {
|
||||
return null;
|
||||
}
|
||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath.trim()));
|
||||
if (file != null && file.isAccessible()) {
|
||||
final IPath projectLocation = file.getProject().getLocation();
|
||||
final IPath fileLocation = file.getLocation();
|
||||
final IPath projectRelativePath = fileLocation.makeRelativeTo(projectLocation);
|
||||
if (!projectRelativePath.isEmpty() && resourceFolderList.contains(projectRelativePath.segment(0))) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2016 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.repository.view.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.eclipse.core.internal.resources.Resource;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.talend.commons.exception.PersistenceException;
|
||||
import org.talend.commons.utils.workbench.resources.ResourceUtils;
|
||||
import org.talend.core.model.repository.ERepositoryObjectType;
|
||||
import org.talend.repository.ProjectManager;
|
||||
|
||||
/**
|
||||
* DOC ggu class global comment. Detailled comment
|
||||
*/
|
||||
public class RepoViewRefreshHelperTest {
|
||||
|
||||
static RepoViewRefreshHelper helper;
|
||||
|
||||
@BeforeClass
|
||||
public static void prepare() {
|
||||
helper = new RepoViewRefreshHelper();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup() {
|
||||
helper = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getValidResourceFile_blankPath() {
|
||||
IFile file = helper.getValidResourceFile(null);
|
||||
Assert.assertNull(file);
|
||||
|
||||
file = helper.getValidResourceFile("");
|
||||
Assert.assertNull(file);
|
||||
|
||||
file = helper.getValidResourceFile(" ");
|
||||
Assert.assertNull(file);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getValidResourceFile_nonExistedPath() {
|
||||
IFile file = helper.getValidResourceFile("mytest");
|
||||
Assert.assertNull(file);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getValidResourceFile_jobPath() throws PersistenceException, CoreException {
|
||||
IProgressMonitor monitor = new NullProgressMonitor();
|
||||
|
||||
final IProject project = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
|
||||
final IFolder jobFolder = project.getFolder(ERepositoryObjectType.PROCESS.getFolder());
|
||||
Assert.assertTrue("The folder should be existed: " + jobFolder, jobFolder.exists());
|
||||
|
||||
final IFile abcFile = jobFolder.getFile("abc.txt");
|
||||
if (!abcFile.exists()) {
|
||||
abcFile.setContents(new ByteArrayInputStream("abc".getBytes()), Resource.FORCE, monitor);
|
||||
}
|
||||
try {
|
||||
IPath filePath = abcFile.getLocation().makeRelativeTo(ResourcesPlugin.getWorkspace().getRoot().getLocation());
|
||||
|
||||
IFile file = helper.getValidResourceFile(filePath.toString());
|
||||
Assert.assertNotNull("It should be valid:" + filePath, file);
|
||||
} finally {
|
||||
if (abcFile.exists()) {
|
||||
abcFile.delete(true, monitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getValidResourceFile_componentsPath() throws PersistenceException, CoreException {
|
||||
IProgressMonitor monitor = new NullProgressMonitor();
|
||||
|
||||
final IProject project = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
|
||||
final IFolder compFolder = project.getFolder(ERepositoryObjectType.COMPONENTS.getFolder());
|
||||
Assert.assertTrue("The folder should be existed: " + compFolder, compFolder.exists());
|
||||
|
||||
final IFile abcFile = compFolder.getFile("abc.txt");
|
||||
if (!abcFile.exists()) {
|
||||
abcFile.setContents(new ByteArrayInputStream("abc".getBytes()), Resource.FORCE, monitor);
|
||||
}
|
||||
try {
|
||||
IPath filePath = abcFile.getLocation().makeRelativeTo(ResourcesPlugin.getWorkspace().getRoot().getLocation());
|
||||
|
||||
IFile file = helper.getValidResourceFile(filePath.toString());
|
||||
Assert.assertNull("should be invalid:" + filePath, file);
|
||||
} finally {
|
||||
if (abcFile.exists()) {
|
||||
abcFile.delete(true, monitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getValidResourceFile_tempPath() throws PersistenceException, CoreException {
|
||||
IProgressMonitor monitor = new NullProgressMonitor();
|
||||
|
||||
final IProject project = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
|
||||
final IFolder tempFolder = project.getFolder("temp");
|
||||
Assert.assertTrue("The folder should be existed: " + tempFolder, tempFolder.exists());
|
||||
|
||||
final IFile abcFile = tempFolder.getFile("abc.txt");
|
||||
if (!abcFile.exists()) {
|
||||
abcFile.setContents(new ByteArrayInputStream("abc".getBytes()), Resource.FORCE, monitor);
|
||||
}
|
||||
try {
|
||||
IPath filePath = abcFile.getLocation().makeRelativeTo(ResourcesPlugin.getWorkspace().getRoot().getLocation());
|
||||
|
||||
IFile file = helper.getValidResourceFile(filePath.toString());
|
||||
Assert.assertNull("should be invalid:" + filePath, file);
|
||||
} finally {
|
||||
if (abcFile.exists()) {
|
||||
abcFile.delete(true, monitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user