use of org.eclipse.core.resources.IWorkspaceRoot in project knime-core by knime.
the class WorkflowExportPage method handleSingleSelection.
private IContainer handleSingleSelection(final IStructuredSelection selection) {
Object obj = selection.getFirstElement();
IContainer resultContainer = null;
// prepare default export file name
if (obj instanceof IContainer) {
resultContainer = (IContainer) obj;
} else if (obj instanceof IResource) {
resultContainer = ((IResource) obj).getParent();
}
if (obj instanceof NodeContainer) {
resultContainer = getContainerForWorkflow((NodeContainer) obj);
}
if (obj instanceof IContainer) {
IContainer container = (IContainer) obj;
// check whether it is a workflow group -> list all workflows
if (KnimeResourceUtil.isWorkflowGroup(container) || container instanceof IWorkspaceRoot) {
// get all contained containers and list them recursively
m_treeViewer.setInput(container);
m_treeViewer.getTree().setVisible(true);
m_treeViewer.expandAll();
// all
if (selection.size() <= 1) {
/*
* Since the tree is expanded before the deprecated method
* should work. Reason why it is deprecated:
* "this method only checks or unchecks visible items" but
* CheckboxTreeViewer#setSubtreeChecked(Object, boolean)
* does not work.
*/
m_treeViewer.setAllChecked(true);
}
} else if (KnimeResourceUtil.isWorkflow(container)) {
// or a workflow -> list nothing
m_treeViewer.getTree().setVisible(false);
}
}
return resultContainer;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project knime-core by knime.
the class WorkflowExportPage method handleSelection.
private IContainer handleSelection(final IStructuredSelection selection) {
IContainer resultContainer = null;
// reset checked elements
m_treeViewer.expandAll();
m_treeViewer.setAllChecked(false);
if (selection.size() > 1) {
resultContainer = handleMultiSelection(selection);
} else if (selection.size() == 1) {
resultContainer = handleSingleSelection(selection);
}
if (resultContainer != null) {
String containerSelectionText = resultContainer.getFullPath().toString();
if (resultContainer instanceof IWorkspaceRoot) {
containerSelectionText = "/";
}
m_containerText.setText(containerSelectionText);
}
// also update the target file name
updateFileName(resultContainer);
return resultContainer;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project knime-core by knime.
the class WorkflowExportPage method updateFileName.
private void updateFileName(final IContainer container) {
if (container != null) {
String fileName = container.getName() + ".zip";
if (container instanceof IWorkspaceRoot) {
fileName = "knime-export.zip";
}
File f = null;
if (lastSelectedTargetLocation != null) {
// create file in last used directory
File parentFile = new File(lastSelectedTargetLocation);
if (parentFile.exists() && parentFile.isDirectory()) {
f = new File(parentFile, fileName);
}
}
if (f == null) {
// no value for last selected target - or folder does not exists
// anymore -> default case: create file in user.home
f = new File(System.getProperty("user.home"), fileName);
}
m_fileText.setText(f.getAbsolutePath());
}
}
use of org.eclipse.core.resources.IWorkspaceRoot in project knime-core by knime.
the class WorkflowSelectionDialog method createDialogArea.
/**
* {@inheritDoc}
*/
@Override
protected Control createDialogArea(final Composite parent) {
// a tree viewer to select a workflow group or workflow
Group overall = new Group(parent, SWT.SHADOW_ETCHED_IN);
overall.setText("Export selection:");
overall.setLayout(new GridLayout(1, false));
GridData shellLayout = new GridData(GridData.FILL_BOTH);
shellLayout.widthHint = 300;
shellLayout.heightHint = 350;
overall.setLayoutData(shellLayout);
GridData fillBoth = new GridData(GridData.FILL_BOTH);
m_viewer = new TreeViewer(overall, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
m_viewer.getTree().setLayoutData(fillBoth);
m_viewer.setLabelProvider(new KnimeResourceLabelProviderWithRoot());
m_viewer.setContentProvider(new KnimeResourceContentProviderWithRoot());
m_viewer.addFilter(new ViewerFilter() {
@Override
public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
if (element instanceof IWorkspaceRoot) {
return true;
}
IResource resource = null;
if (element instanceof NodeContainer) {
ProjectWorkflowMap.findProjectFor(((NodeContainer) element).getID());
} else if (element instanceof IResource) {
resource = (IResource) element;
}
if (KnimeResourceUtil.isWorkflow(resource)) {
return true;
}
if (KnimeResourceUtil.isWorkflowGroup(resource)) {
return true;
}
return false;
}
});
m_viewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
m_viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
m_selectedObjs = (IStructuredSelection) m_viewer.getSelection();
}
});
if (m_initialSelection != null) {
m_viewer.setSelection(m_initialSelection);
}
m_viewer.expandAll();
return overall;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project knime-core by knime.
the class NewProjectWizardPage method createDestinationSelectionComposite.
private void createDestinationSelectionComposite(final Composite parent) {
Group destGroup = new Group(parent, SWT.SHADOW_ETCHED_IN);
destGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
destGroup.setLayout(new GridLayout(3, false));
// second row: workflow destination
Label destinationLabel = new Label(destGroup, SWT.NONE);
destinationLabel.setText("Workspace destination:");
m_destinationUI = new Text(destGroup, SWT.BORDER | SWT.READ_ONLY);
m_destinationUI.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (m_initiallySelectedResource != null && !(m_initiallySelectedResource instanceof IWorkspaceRoot)) {
m_destinationUI.setText(m_initiallySelectedResource.getFullPath().toString());
} else {
m_destinationUI.setText("/");
}
Button browseBtn = new Button(destGroup, SWT.PUSH);
browseBtn.setText("Browse...");
browseBtn.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(final SelectionEvent e) {
handleBrowseButton();
}
});
}
Aggregations