use of org.eclipse.jface.operation.IRunnableWithProgress in project knime-core by knime.
the class NodeContainerEditPart method openNodeDialog.
/**
* Opens the node's dialog (also metanode dialogs).
*
* @since 2.6
*/
public void openNodeDialog() {
final NodeContainerUI container = (NodeContainerUI) getModel();
// if this node does not have a dialog
if (!container.hasDialog()) {
LOGGER.debug("No dialog for " + container.getNameWithID());
return;
}
final Shell shell = Display.getCurrent().getActiveShell();
shell.setEnabled(false);
try {
if (container.hasDataAwareDialogPane() && !container.isAllInputDataAvailable() && container.canExecuteUpToHere()) {
IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
String prefPrompt = store.getString(PreferenceConstants.P_EXEC_NODES_DATA_AWARE_DIALOGS);
boolean isExecuteUpstreamNodes;
if (MessageDialogWithToggle.PROMPT.equals(prefPrompt)) {
int returnCode = MessageDialogWithToggle.openYesNoCancelQuestion(shell, "Execute upstream nodes", "The " + container.getName() + " node can be configured using the full input data.\n\n" + "Execute upstream nodes?", "Remember my decision", false, store, PreferenceConstants.P_EXEC_NODES_DATA_AWARE_DIALOGS).getReturnCode();
if (returnCode == Window.CANCEL) {
return;
} else if (returnCode == IDialogConstants.YES_ID) {
isExecuteUpstreamNodes = true;
} else {
isExecuteUpstreamNodes = false;
}
} else if (MessageDialogWithToggle.ALWAYS.equals(prefPrompt)) {
isExecuteUpstreamNodes = true;
} else {
isExecuteUpstreamNodes = false;
}
if (isExecuteUpstreamNodes) {
try {
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Future<Void> submit = DATA_AWARE_DIALOG_EXECUTOR.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
container.getParent().executePredecessorsAndWait(container.getID());
return null;
}
});
while (!submit.isDone()) {
if (monitor.isCanceled()) {
submit.cancel(true);
throw new InterruptedException();
}
try {
submit.get(300, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
LOGGER.error("Error while waiting for execution to finish", e);
} catch (InterruptedException e) {
submit.cancel(true);
throw e;
} catch (TimeoutException e) {
// do another round
}
}
}
});
} catch (InvocationTargetException e) {
String error = "Exception while waiting for completion of execution";
LOGGER.warn(error, e);
ErrorDialog.openError(shell, "Failed opening dialog", error, new Status(IStatus.ERROR, KNIMEEditorPlugin.PLUGIN_ID, error, e));
} catch (InterruptedException e) {
return;
}
}
}
//
try {
if (Wrapper.wraps(container, NodeContainer.class)) {
WrappedNodeDialog dlg = new WrappedNodeDialog(shell, Wrapper.unwrapNC(container));
dlg.open();
}
} catch (NotConfigurableException ex) {
MessageBox mb = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
mb.setText("Dialog cannot be opened");
mb.setMessage("The dialog cannot be opened for the following" + " reason:\n" + ex.getMessage());
mb.open();
} catch (Throwable t) {
LOGGER.error("The dialog pane for node '" + container.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an implementation error.", t);
}
} finally {
shell.setEnabled(true);
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project knime-core by knime.
the class KnimeResourceUtil method importWorkflowIntoWorkspace.
/**
* Stores the flow in the archive in the local workspace.
*
* @param destination the name of the new workflow. Must denote a flow (if
* it exists it is overwritten).
* @param zippedWorkflow
* @throws IOException
* @throws ZipException
* @throws InterruptedException
* @throws InvocationTargetException
*/
private static void importWorkflowIntoWorkspace(final IPath destination, final File zippedWorkflow) throws ZipException, IOException, InvocationTargetException, InterruptedException {
ZipFile zFile = new ZipFile(zippedWorkflow);
ZipLeveledStructProvider importStructureProvider = new ZipLeveledStructProvider(zFile);
importStructureProvider.setStrip(1);
ZipEntry root = (ZipEntry) importStructureProvider.getRoot();
List<ZipEntry> rootChild = importStructureProvider.getChildren(root);
if (rootChild.size() == 1) {
// the zipped workflow normally contains only one dir
root = rootChild.get(0);
}
LOGGER.debug("Importing workflow. Destination:" + destination.toString());
try {
final ImportOperation iOper = new ImportOperation(destination, root, importStructureProvider, new IOverwriteQuery() {
@Override
public String queryOverwrite(final String pathString) {
return IOverwriteQuery.YES;
}
});
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
iOper.run(monitor);
}
});
} finally {
importStructureProvider.closeArchive();
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project knime-core by knime.
the class WorkflowImportSelectionPage method collectWorkflowsFromDir.
/**
* @param selectedDir the directory to collect the contained workflows from
*/
public void collectWorkflowsFromDir(final String selectedDir) {
clear();
initialDirLocation = selectedDir;
m_fromDirTextUI.setText(selectedDir);
File dir = new File(selectedDir);
IWorkflowImportElement root = null;
// the name only is considered when the resource is created
if (WorkflowImportElementFromFile.isWorkflow(dir)) {
// if the user selected a workflow we set the parent and the
// child to this workflow - otherwise it would not be displayed
root = new WorkflowImportElementFromFile(dir, true);
root.addChild(new WorkflowImportElementFromFile(dir));
} else {
root = new WorkflowImportElementFromFile(dir);
}
m_importRoot = root;
try {
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Looking for workflows in ", IProgressMonitor.UNKNOWN);
collectWorkflowsFromDir((WorkflowImportElementFromFile) m_importRoot, monitor);
monitor.done();
}
});
} catch (Exception e) {
String message = "Error while trying to import workflows from " + selectedDir;
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.jface.operation.IRunnableWithProgress 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.jface.operation.IRunnableWithProgress in project knime-core by knime.
the class NewProjectWizard method performFinish.
/**
* Perform finish - queries the page and creates the project / file.
*
* {@inheritDoc}
*/
@Override
public boolean performFinish() {
final IPath workflowPath = m_page.getWorkflowPath();
// Create new runnable
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(final IProgressMonitor monitor) throws InvocationTargetException {
try {
// call the worker method
doFinish(workflowPath, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
};
try {
getContainer().run(true, false, op);
IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(workflowPath);
KnimeResourceUtil.revealInNavigator(r);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException e) {
// get the exception that issued this async exception
Throwable realException = e.getTargetException();
MessageDialog.openError(getShell(), "Error", realException.getMessage());
return false;
}
return true;
}
Aggregations