use of org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider in project translationstudio8 by heartsome.
the class ImportProjectWizardPage method updateProjectsList.
/**
* Update the list of projects based on path. Method declared public only
* for test suite.
*
* @param path
*/
public void updateProjectsList(final String path) {
// on an empty path empty selectedProjects
if (path == null || path.length() == 0) {
setMessage(Messages.getString("wizard.ImportProjectWizardPage.desc"));
selectedProjects = new ProjectRecord[0];
projectsList.refresh(true);
projectsList.setCheckedElements(selectedProjects);
setPageComplete(projectsList.getCheckedElements().length > 0);
lastPath = path;
return;
}
final File directory = new File(path);
long modified = directory.lastModified();
if (path.equals(lastPath) && lastModified == modified && lastCopyFiles == copyFiles) {
// change, no refreshing is required
return;
}
lastPath = path;
lastModified = modified;
lastCopyFiles = copyFiles;
// We can't access the radio button from the inner class so get the
// status beforehand
final boolean dirSelected = false;
try {
getContainer().run(true, true, new IRunnableWithProgress() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.operation.IRunnableWithProgress#run(org
* .eclipse.core.runtime.IProgressMonitor)
*/
@SuppressWarnings("rawtypes")
public void run(IProgressMonitor monitor) {
monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_SearchingMessage, 100);
selectedProjects = new ProjectRecord[0];
Collection files = new ArrayList();
monitor.worked(10);
if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
if (sourceTarFile == null) {
return;
}
structureProvider = new TarLeveledStructureProvider(sourceTarFile);
Object child = structureProvider.getRoot();
if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
return;
}
Iterator filesIterator = files.iterator();
selectedProjects = new ProjectRecord[files.size()];
int index = 0;
monitor.worked(50);
monitor.subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
while (filesIterator.hasNext()) {
selectedProjects[index++] = (ProjectRecord) filesIterator.next();
}
} else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
ZipFile sourceFile = getSpecifiedZipSourceFile(path);
if (sourceFile == null) {
return;
}
structureProvider = new ZipLeveledStructureProvider(sourceFile);
Object child = structureProvider.getRoot();
if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
return;
}
Iterator filesIterator = files.iterator();
selectedProjects = new ProjectRecord[files.size()];
int index = 0;
monitor.worked(50);
monitor.subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
while (filesIterator.hasNext()) {
selectedProjects[index++] = (ProjectRecord) filesIterator.next();
}
} else {
monitor.worked(60);
}
monitor.done();
}
});
} catch (InvocationTargetException e) {
IDEWorkbenchPlugin.log(e.getMessage(), e);
} catch (InterruptedException e) {
// Nothing to do if the user interrupts.
}
projectsList.refresh(true);
ProjectRecord[] projects = getProjectRecords();
boolean displayWarning = false;
for (int i = 0; i < projects.length; i++) {
if (projects[i].hasConflicts) {
displayWarning = true;
projectsList.setGrayed(projects[i], true);
} else {
projectsList.setChecked(projects[i], true);
}
}
if (displayWarning) {
setMessage(DataTransferMessages.WizardProjectsImportPage_projectsInWorkspace, WARNING);
} else {
setMessage("");
}
setPageComplete(projectsList.getCheckedElements().length > 0);
if (selectedProjects.length == 0) {
setMessage(DataTransferMessages.WizardProjectsImportPage_noProjectsToImport, WARNING);
}
}
use of org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider 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