use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore in project knime-core by knime.
the class SaveAsMetaNodeTemplateAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
if (nodes.length < 1) {
return;
}
WorkflowManager wm = Wrapper.unwrapWFM(nodes[0].getNodeContainer());
List<String> validMountPointList = new ArrayList<String>();
// Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().findView(ID)
for (Map.Entry<String, AbstractContentProvider> entry : ExplorerMountTable.getMountedContent().entrySet()) {
AbstractContentProvider contentProvider = entry.getValue();
if (contentProvider.isWritable() && contentProvider.canHostMetaNodeTemplates()) {
validMountPointList.add(entry.getKey());
}
}
if (validMountPointList.isEmpty()) {
throw new IllegalStateException("No valid mount points found - " + "this is inconsistent with calculateEnabled()");
}
String[] validMountPoints = validMountPointList.toArray(new String[0]);
final Shell shell = Display.getCurrent().getActiveShell();
ContentObject defSel = getDefaultSaveLocation(wm);
SpaceResourceSelectionDialog dialog = new SpaceResourceSelectionDialog(shell, validMountPoints, defSel);
dialog.setTitle("Save As Metanode Template");
dialog.setHeader("Select destination workflow group for metanode template");
dialog.setValidator(new Validator() {
@Override
public String validateSelectionValue(final AbstractExplorerFileStore selection, final String name) {
final AbstractExplorerFileInfo info = selection.fetchInfo();
if (info.isWorkflowGroup()) {
return null;
}
return "Only workflow groups can be selected as target.";
}
});
if (dialog.open() != Window.OK) {
return;
}
AbstractExplorerFileStore target = dialog.getSelection();
AbstractContentProvider contentProvider = target.getContentProvider();
contentProvider.saveMetaNodeTemplate(wm, target);
}
use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore in project knime-core by knime.
the class SaveAsSubNodeTemplateAction method getDefaultSaveLocation.
private ContentObject getDefaultSaveLocation(final WorkflowManager arg) {
final NodeID id = arg.getID();
URI uri = DisconnectSubNodeLinkCommand.RECENTLY_USED_URIS.get(id);
if (uri == null || !ExplorerFileSystem.SCHEME.equals(uri.getScheme())) {
return null;
}
final AbstractExplorerFileStore oldTemplateFileStore = ExplorerFileSystem.INSTANCE.getStore(uri);
final AbstractExplorerFileStore parent = oldTemplateFileStore == null ? null : oldTemplateFileStore.getParent();
if (parent != null) {
return ContentObject.forFile(parent);
}
return null;
}
use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore in project knime-core by knime.
the class SaveAsSubNodeTemplateAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
if (nodes.length < 1) {
return;
}
SubNodeContainer snc = unwrap(nodes[0].getNodeContainer(), SubNodeContainer.class);
WorkflowManager wm = snc.getWorkflowManager();
List<String> validMountPointList = new ArrayList<String>();
for (Map.Entry<String, AbstractContentProvider> entry : ExplorerMountTable.getMountedContent().entrySet()) {
AbstractContentProvider contentProvider = entry.getValue();
if (contentProvider.isWritable() && contentProvider.canHostMetaNodeTemplates()) {
validMountPointList.add(entry.getKey());
}
}
if (validMountPointList.isEmpty()) {
throw new IllegalStateException("No valid mount points found - " + "this is inconsistent with calculateEnabled()");
}
String[] validMountPoints = validMountPointList.toArray(new String[0]);
final Shell shell = Display.getCurrent().getActiveShell();
ContentObject defSel = getDefaultSaveLocation(wm);
SpaceResourceSelectionDialog dialog = new SpaceResourceSelectionDialog(shell, validMountPoints, defSel);
dialog.setTitle("Save As Wrapped Metanode Template");
dialog.setHeader("Select destination workflow group for Wrapped Metanode template");
dialog.setValidator(new Validator() {
@Override
public String validateSelectionValue(final AbstractExplorerFileStore selection, final String name) {
final AbstractExplorerFileInfo info = selection.fetchInfo();
if (info.isWorkflowGroup()) {
return null;
}
return "Only workflow groups can be selected as target.";
}
});
if (dialog.open() != Window.OK) {
return;
}
AbstractExplorerFileStore target = dialog.getSelection();
AbstractContentProvider contentProvider = target.getContentProvider();
contentProvider.saveSubNodeTemplate(snc, target);
}
use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore in project knime-core by knime.
the class IntroPage method newWorkflow.
private void newWorkflow() {
ExplorerView explorerView = null;
for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
for (IWorkbenchPage page : window.getPages()) {
for (IViewReference ref : page.getViewReferences()) {
if (ExplorerView.ID.equals(ref.getId())) {
explorerView = (ExplorerView) ref.getPart(true);
break;
}
}
}
}
Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
NewWorkflowWizard newWiz = new NewWorkflowWizard();
newWiz.init(PlatformUI.getWorkbench(), null);
WizardDialog dialog = new WizardDialog(shell, newWiz);
dialog.create();
dialog.getShell().setText("Create new workflow");
dialog.getShell().setSize(Math.max(470, dialog.getShell().getSize().x), 350);
int ok = dialog.open();
if ((ok == Window.OK) && (explorerView != null)) {
// update the tree
IWizardPage currentPage = dialog.getCurrentPage();
if (currentPage instanceof NewWorkflowWizardPage) {
NewWorkflowWizardPage nwwp = (NewWorkflowWizardPage) currentPage;
AbstractExplorerFileStore file = nwwp.getNewFile();
Object p = ContentDelegator.getTreeObjectFor(file.getParent());
explorerView.setNextSelection(file);
explorerView.getViewer().refresh(p);
}
}
}
use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore in project knime-core by knime.
the class WorkflowEditor method dispose.
/**
* Deregisters all listeners when the editor is disposed.
*
* @see org.eclipse.ui.IWorkbenchPart#dispose()
*/
@Override
public void dispose() {
NodeLogger.getLogger(WorkflowEditor.class).debug("Disposing editor...");
if (m_zoomWheelListener != null) {
m_zoomWheelListener.dispose();
}
if (m_fileResource != null && m_manager != null) {
// disposed is also called when workflow load fails or is canceled
ProjectWorkflowMap.unregisterClientFrom(m_fileResource, this);
// removes the workflow from memory
ProjectWorkflowMap.remove(m_fileResource);
if (isTempRemoteWorkflowEditor()) {
// after the workflow is deleted we can delete the temp location
final AbstractExplorerFileStore flowLoc = getFileStore(m_fileResource);
if (flowLoc != null) {
new Thread(() -> {
try {
m_workflowCanBeDeleted.acquire();
File d = flowLoc.toLocalFile();
if (d != null && d.exists()) {
FileUtils.deleteDirectory(d.getParentFile());
}
} catch (CoreException | IOException | InterruptedException e) {
LOGGER.warn("Error during deletion of temporary workflow location: " + e.getMessage(), e);
}
}, "Delete temporary copy of " + m_origRemoteLocation).start();
}
}
}
final ReferencedFile autoSaveDirectory;
if (m_manager != null && m_parentEditor == null && m_fileResource != null) {
autoSaveDirectory = Wrapper.unwrapWFMOptional(m_manager).map(wfm -> wfm.getAutoSaveDirectory()).orElse(null);
} else {
autoSaveDirectory = null;
}
// remember that this editor has been closed
m_closed = true;
for (IEditorPart child : getSubEditors()) {
child.getEditorSite().getPage().closeEditor(child, false);
}
NodeProvider.INSTANCE.removeListener(this);
getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(this);
if (m_parentEditor != null && m_manager != null) {
// Store the editor settings with the metanode
if (getWorkflowManagerUI().isDirty()) {
// doesn't persist settings to disk
saveEditorSettingsToWorkflowManager();
}
// bug fix 2051: Possible memory leak related to sub-flow editor.
// metanode editors were still referenced by the EditorHistory
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench instanceof Workbench) {
EditorHistory hist = ((Workbench) workbench).getEditorHistory();
WorkflowManagerInput wfmInput = new WorkflowManagerInput(m_manager, m_parentEditor);
hist.remove(wfmInput);
}
}
if (m_autoSaveJob != null) {
m_autoSaveJob.cancel();
m_autoSaveJob = null;
}
// unregisters wfm listeners
setWorkflowManager(null);
if (autoSaveDirectory != null) {
KNIMEConstants.GLOBAL_THREAD_POOL.enqueue(new Runnable() {
@Override
public void run() {
LOGGER.debugWithFormat("Deleting auto-saved copy (\"%s\")...", autoSaveDirectory);
try {
FileUtils.deleteDirectory(autoSaveDirectory.getFile());
} catch (IOException e) {
LOGGER.error(String.format("Failed to delete auto-saved copy of workflow (folder \"%s\"): %s", autoSaveDirectory, e.getMessage()), e);
}
}
});
}
getCommandStack().removeCommandStackListener(this);
IPreferenceStore prefStore = KNIMEUIPlugin.getDefault().getPreferenceStore();
prefStore.removePropertyChangeListener(this);
super.dispose();
}
Aggregations