Search in sources :

Example 71 with IContainer

use of org.eclipse.core.resources.IContainer in project linuxtools by eclipse.

the class ChangeLogAction method createChangeLog.

protected IFile createChangeLog(IPath changelog) {
    IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
    IWorkbench ws = PlatformUI.getWorkbench();
    final IFile changelog_File = myWorkspaceRoot.getFile(changelog);
    final InputStream initialContents = new ByteArrayInputStream(new byte[0]);
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

        @Override
        public void execute(IProgressMonitor monitor) throws CoreException {
            try {
                // $NON-NLS-1$
                monitor.beginTask(Messages.getString("ChangeLog.AddingChangeLog"), 2000);
                changelog_File.create(initialContents, false, monitor);
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException();
                }
            } finally {
                monitor.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(ws.getActiveWorkbenchWindow().getShell()).run(true, true, operation);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrInterrupted"), e);
        return null;
    } catch (InvocationTargetException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrInvocation"), e);
        return null;
    }
    // FIXME:  we should put this refreshLocal call into a thread (filed as bug #256180)
    try {
        IContainer changelogContainer = myWorkspaceRoot.getContainerForLocation(changelog);
        if (changelogContainer != null)
            changelogContainer.refreshLocal(2, null);
    } catch (CoreException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrRefresh"), e);
        return null;
    }
    return changelog_File;
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IWorkbench(org.eclipse.ui.IWorkbench) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IContainer(org.eclipse.core.resources.IContainer)

Example 72 with IContainer

use of org.eclipse.core.resources.IContainer in project knime-core by knime.

the class KnimeResourceContentProvider method getChildren.

/**
 * {@inheritDoc}
 */
@Override
public Object[] getChildren(final Object element) {
    if (element instanceof IFile) {
        return EMPTY_ARRAY;
    }
    if (isKNIMEWorkflow(element)) {
        IContainer project = (IContainer) element;
        NodeContainerUI workflow = ProjectWorkflowMap.getWorkflowUI(project.getLocationURI());
        if (workflow != null) {
            // the number of contained nodes is returned
            return getSortedNodeContainers(((WorkflowManagerUI) workflow).getNodeContainers());
        }
    } else if (element instanceof WorkflowManager) {
        return getSortedNodeContainers(((WorkflowManagerUI) element).getNodeContainers());
    }
    return getFolders(element);
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) IFile(org.eclipse.core.resources.IFile) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) IContainer(org.eclipse.core.resources.IContainer)

Example 73 with IContainer

use of org.eclipse.core.resources.IContainer in project knime-core by knime.

the class KnimeResourceLabelProvider method getImage.

/**
 * {@inheritDoc}
 */
@Override
public Image getImage(final Object element) {
    Image img = super.getImage(element);
    NodeContainerUI projectNode = null;
    if (element instanceof IContainer) {
        IContainer container = (IContainer) element;
        if (container.exists(WORKFLOW_FILE)) {
            // in any case a knime workflow or meta node (!)
            projectNode = ProjectWorkflowMap.getWorkflowUI(container.getLocationURI());
            if (projectNode == null && !isMetaNode(container)) {
                return CLOSED_WORKFLOW;
            }
        }
        if (projectNode == null) {
            if (isMetaNode(container)) {
                return NODE;
            } else if (container.exists(METAINFO_FILE)) {
                return WORKFLOW_GROUP;
            }
        }
    } else if (element instanceof NodeContainerUI) {
        projectNode = (NodeContainerUI) element;
    }
    if (projectNode != null) {
        if (projectNode instanceof WorkflowManagerUI && // are displayed with state
        ((WorkflowManagerUI) projectNode).getID().hasSamePrefix(WorkflowManager.ROOT.getID())) {
            NodeContainerState state = projectNode.getNodeContainerState();
            if (projectNode.getNodeMessage().getMessageType().equals(NodeMessage.Type.ERROR)) {
                return ERROR;
            }
            if (state.isExecuted()) {
                return EXECUTED;
            } else if (state.isExecutionInProgress()) {
                return EXECUTING;
            } else {
                return CONFIGURED;
            }
        } else {
            return NODE;
        }
    }
    return img;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerState(org.knime.core.node.workflow.NodeContainerState) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) Image(org.eclipse.swt.graphics.Image) IContainer(org.eclipse.core.resources.IContainer)

Example 74 with IContainer

use of org.eclipse.core.resources.IContainer in project knime-core by knime.

the class AbstractWorkflowAction method isEnabled.

/**
 * {@inheritDoc}
 */
@Override
public boolean isEnabled() {
    // does not work to ask for the selection service and get the selection
    // by part id: might be a derived class with different ID
    // get selection
    IStructuredSelection s = (IStructuredSelection) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
    if (s == null) {
        return false;
    }
    Object element = s.getFirstElement();
    // check if is KNIME workflow
    if (element instanceof IContainer) {
        IContainer cont = (IContainer) element;
        if (cont.exists(new Path(WorkflowPersistor.WORKFLOW_FILE))) {
            m_workflow = (WorkflowManager) ProjectWorkflowMap.getWorkflow(cont.getLocationURI());
            if (m_workflow != null) {
                return true;
            }
        }
    }
    return false;
}
Also used : Path(org.eclipse.core.runtime.Path) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IContainer(org.eclipse.core.resources.IContainer)

Example 75 with IContainer

use of org.eclipse.core.resources.IContainer in project knime-core by knime.

the class DeleteAction method closeOpenWorkflows.

private void closeOpenWorkflows(final List<IContainer> allWorkflows) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    for (IContainer wf : allWorkflows) {
        NodeContainer wfm = ProjectWorkflowMap.getWorkflow(wf.getLocationURI());
        if (wfm != null) {
            for (IEditorReference editRef : page.getEditorReferences()) {
                IEditorPart editor = editRef.getEditor(false);
                if (editor == null) {
                    // got closed in the mean time
                    continue;
                }
                WorkflowEditorAdapter wea = (WorkflowEditorAdapter) editor.getAdapter(WorkflowEditorAdapter.class);
                NodeContainer editWFM = null;
                if (wea != null) {
                    editWFM = wea.getWorkflowManager();
                }
                if (wfm == editWFM) {
                    page.closeEditor(editor, false);
                }
            }
        }
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) WorkflowEditorAdapter(org.knime.workbench.ui.navigator.WorkflowEditorAdapter) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NodeContainer(org.knime.core.node.workflow.NodeContainer) IEditorPart(org.eclipse.ui.IEditorPart) IContainer(org.eclipse.core.resources.IContainer)

Aggregations

IContainer (org.eclipse.core.resources.IContainer)199 IResource (org.eclipse.core.resources.IResource)89 IFile (org.eclipse.core.resources.IFile)71 IPath (org.eclipse.core.runtime.IPath)47 CoreException (org.eclipse.core.runtime.CoreException)46 IFolder (org.eclipse.core.resources.IFolder)45 Path (org.eclipse.core.runtime.Path)43 IProject (org.eclipse.core.resources.IProject)28 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)26 ArrayList (java.util.ArrayList)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 Status (org.eclipse.core.runtime.Status)10 PartInitException (org.eclipse.ui.PartInitException)10 InputStream (java.io.InputStream)9