use of org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider in project knime-core by knime.
the class WorkflowImportElementFromArchive method isWorkflowGroup.
/**
* {@inheritDoc}
*/
@Override
public boolean isWorkflowGroup() {
ILeveledImportStructureProvider provider = getProvider();
Object zipEntry = getEntry();
if (provider.isFolder(zipEntry)) {
List children = provider.getChildren(zipEntry);
if (children == null) {
return false;
}
for (Object o : children) {
String elementLabel = provider.getLabel(o);
if (elementLabel.equals(WorkflowPersistor.METAINFO_FILE)) {
return true;
}
}
}
return false;
}
use of org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider in project knime-core by knime.
the class WorkflowImportOperation method handleCopyProject.
private ILeveledImportStructureProvider handleCopyProject(final IWorkflowImportElement importElement, final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
IPath destination = m_targetPath.append(importElement.getRenamedPath());
ImportOperation operation = null;
ILeveledImportStructureProvider provider = null;
if (importElement instanceof WorkflowImportElementFromFile) {
operation = createWorkflowFromFile((WorkflowImportElementFromFile) importElement, destination, new SubProgressMonitor(monitor, 1));
} else if (importElement instanceof WorkflowImportElementFromArchive) {
WorkflowImportElementFromArchive zip = (WorkflowImportElementFromArchive) importElement;
provider = zip.getProvider();
operation = createWorkflowFromArchive(zip, destination, new SubProgressMonitor(monitor, 1));
}
if (operation != null) {
operation.setContext(m_shell);
operation.setOverwriteResources(true);
operation.setCreateContainerStructure(false);
operation.run(monitor);
// if we created a project -> set the correct nature
if (Path.ROOT.equals(m_targetPath)) {
setProjectNature(importElement);
}
IResource newProject = ResourcesPlugin.getWorkspace().getRoot().findMember(destination);
if (newProject != null) {
newProject.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
monitor.worked(1);
}
return provider;
}
use of org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider in project knime-core by knime.
the class WorkflowImportOperation method execute.
/**
* {@inheritDoc}
*/
@Override
protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
ILeveledImportStructureProvider provider = null;
try {
monitor.beginTask("", m_workflows.size());
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
for (IWorkflowImportElement wf : m_workflows) {
if (!m_copy) {
handleLinkedProject(wf, monitor);
} else {
provider = handleCopyProject(wf, monitor);
}
}
if (!m_missingMetaInfoLocations.isEmpty()) {
createMetaInfo();
}
// clean up afterwards
m_missingMetaInfoLocations.clear();
ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
final IResource result = ResourcesPlugin.getWorkspace().getRoot().findMember(m_targetPath);
if (result != null) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
KnimeResourceUtil.revealInNavigator(result);
}
});
}
} catch (CoreException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (InvocationTargetException ex) {
throw ex;
} catch (Exception ex) {
throw new InvocationTargetException(ex);
} finally {
if (provider != null) {
ArchiveFileManipulations.closeStructureProvider(provider, m_shell);
}
monitor.done();
}
}
use of org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider 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);
}
}
use of org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider in project knime-core by knime.
the class WorkflowImportElementFromArchive method isWorkflow.
/**
* {@inheritDoc}
*/
@Override
public boolean isWorkflow() {
ILeveledImportStructureProvider provider = getProvider();
Object zipEntry = getEntry();
if (provider.isFolder(zipEntry)) {
List children = provider.getChildren(zipEntry);
if (children == null) {
return false;
}
for (Object o : children) {
String elementLabel = provider.getLabel(o);
if (elementLabel.equals(WorkflowPersistor.WORKFLOW_FILE)) {
return true;
}
}
}
return false;
}
Aggregations