Search in sources :

Example 1 with Workbench

use of org.eclipse.ui.internal.Workbench in project translationstudio8 by heartsome.

the class CommonFunction method refreshHistoryWhenDelete.

/**
	 * 当删除一个文件时,刷新历史记录	--robert	2012-11-20
	 */
@SuppressWarnings("restriction")
public static void refreshHistoryWhenDelete(IEditorInput input) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench instanceof Workbench) {
        EditorHistory history = ((Workbench) workbench).getEditorHistory();
        for (EditorHistoryItem item : history.getItems()) {
            if (item.matches(input)) {
                history.remove(item);
            }
        }
        history.refresh();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) EditorHistory(org.eclipse.ui.internal.EditorHistory) EditorHistoryItem(org.eclipse.ui.internal.EditorHistoryItem) Workbench(org.eclipse.ui.internal.Workbench) IWorkbench(org.eclipse.ui.IWorkbench)

Example 2 with Workbench

use of org.eclipse.ui.internal.Workbench 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();
}
Also used : Workbench(org.eclipse.ui.internal.Workbench) IWorkbench(org.eclipse.ui.IWorkbench) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) ReferencedFile(org.knime.core.internal.ReferencedFile) IWorkbench(org.eclipse.ui.IWorkbench) EditorHistory(org.eclipse.ui.internal.EditorHistory) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Aggregations

IWorkbench (org.eclipse.ui.IWorkbench)2 EditorHistory (org.eclipse.ui.internal.EditorHistory)2 Workbench (org.eclipse.ui.internal.Workbench)2 File (java.io.File)1 IOException (java.io.IOException)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 IEditorPart (org.eclipse.ui.IEditorPart)1 EditorHistoryItem (org.eclipse.ui.internal.EditorHistoryItem)1 ReferencedFile (org.knime.core.internal.ReferencedFile)1 AbstractExplorerFileStore (org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore)1