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;
}
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);
}
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;
}
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;
}
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);
}
}
}
}
}
Aggregations