use of org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider in project tdi-studio-se by Talend.
the class TalendWizardProjectsImportPage method getProjectRecords.
@Override
public ProjectRecord[] getProjectRecords() {
if (sourcePath == null || sourcePath.length() == 0) {
return new ProjectRecord[0];
}
ProjectRecord[] selectedProjects = super.getProjectRecords();
Collection files = new ArrayList();
List projects = new ArrayList();
ProjectRecord[] selected = null;
for (ProjectRecord selectedProject : selectedProjects) {
projects.add(selectedProject);
}
final File directory = new File(sourcePath);
if (ArchiveFileManipulations.isTarFile(sourcePath)) {
try {
TarFile sourceTarFile = new TarFile(sourcePath);
if (sourceTarFile == null) {
return new ProjectRecord[0];
}
structureProvider = new TarLeveledStructureProvider(sourceTarFile);
Object child = structureProvider.getRoot();
collectProjectFilesFromProvider(files, child, 0);
selected = new ProjectRecord[files.size()];
Iterator filesIterator = files.iterator();
int j = 0;
while (filesIterator.hasNext()) {
TalendProjectRecord file = (TalendProjectRecord) filesIterator.next();
for (int i = 0; i < projects.size(); i++) {
if (file.getProjectName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
selected[j] = (ProjectRecord) projects.get(i);
j++;
}
}
}
} catch (TarException e) {
// displayErrorDialog(DataTransferMessages.TarImport_badFormat);
//$NON-NLS-1$
displayErrorDialog(Messages.getString("DataTransferMessages.TarImport_badFormat"));
} catch (IOException e) {
// displayErrorDialog(DataTransferMessages.ZipImport_couldNotRead);
//$NON-NLS-1$
displayErrorDialog(Messages.getString("DataTransferMessages.ZipImport_couldNotRead"));
}
} else if (ArchiveFileManipulations.isZipFile(sourcePath)) {
try {
ZipFile sourceFile = new ZipFile(sourcePath);
if (sourceFile == null) {
return new ProjectRecord[0];
}
structureProvider = new ZipLeveledStructureProvider(sourceFile);
Object child = structureProvider.getRoot();
collectProjectFilesFromProvider(files, child, 0);
selected = new ProjectRecord[files.size()];
Iterator filesIterator = files.iterator();
int j = 0;
while (filesIterator.hasNext()) {
TalendProjectRecord file = (TalendProjectRecord) filesIterator.next();
for (int i = 0; i < projects.size(); i++) {
if (file.getProjectName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
selected[j] = (ProjectRecord) projects.get(i);
j++;
}
}
}
} catch (IOException e) {
// displayErrorDialog(DataTransferMessages.ZipImport_badFormat);
//$NON-NLS-1$
displayErrorDialog(Messages.getString("DataTransferMessages.ZipImport_badFormat"));
}
} else if (directory.isDirectory()) {
collectProjectFilesFromDirectory(files, directory, null);
selected = new ProjectRecord[files.size()];
Iterator filesIterator = files.iterator();
int j = 0;
while (filesIterator.hasNext()) {
File file = (File) filesIterator.next();
for (int i = 0; i < projects.size(); i++) {
if (file.getParentFile().getName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
selected[j] = (ProjectRecord) projects.get(i);
j++;
}
}
}
}
return selected;
}
use of org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider in project knime-core by knime.
the class WorkflowImportSelectionPage method collectWorkflowsFromZipFile.
private void collectWorkflowsFromZipFile(final String path) {
ILeveledImportStructureProvider provider = null;
if (ArchiveFileManipulations.isTarFile(path)) {
try {
TarFile sourceTarFile = new TarFile(path);
provider = new TarLeveledStructureProvider(sourceTarFile);
} catch (Exception io) {
// no file -> list stays empty
setErrorMessage("Invalid .tar file: " + path + ". Contains no workflow.");
}
} else if (ArchiveFileManipulations.isZipFile(path)) {
try {
ZipFile sourceFile = new ZipFile(path);
provider = new ZipLeveledStructureProvider(sourceFile);
} catch (Exception e) {
// no file -> list stays empty
setErrorMessage("Invalid .zip file: " + path + ". Contains no workflows");
}
}
// TODO: store only the workflows (dirs are created automatically)
final ILeveledImportStructureProvider finalProvider = provider;
if (provider != null) {
// reset error
setErrorMessage(null);
try {
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Object child = finalProvider.getRoot();
m_importRoot = new WorkflowImportElementFromArchive(finalProvider, child, 0);
monitor.beginTask("Scanning for workflows in ", IProgressMonitor.UNKNOWN);
collectWorkflowsFromProvider((WorkflowImportElementFromArchive) m_importRoot, monitor);
}
});
} catch (Exception e) {
String message = "Error while trying to import workflows from " + path;
IStatus status = new Status(IStatus.ERROR, KNIMEUIPlugin.PLUGIN_ID, message, e);
setErrorMessage(message);
LOGGER.error(message, e);
ErrorDialog.openError(getShell(), "Import Error", null, status);
}
validateWorkflows();
m_workflowListUI.setInput(m_importRoot);
m_workflowListUI.expandAll();
m_workflowListUI.setAllChecked(true);
m_workflowListUI.refresh(true);
}
}
Aggregations