use of org.eclipse.core.resources.IContainer in project knime-core by knime.
the class NewProjectWizardPage method dialogChanged.
/**
* Ensures that the text field is set properly.
*/
private void dialogChanged() {
// check if a name was entered
String projectName = m_projectName.getText().trim();
if (projectName.length() == 0) {
updateStatus(m_elementName + " name must be specified");
return;
}
IStatus validName = ResourcesPlugin.getWorkspace().validateName(projectName, IResource.PROJECT);
if (!validName.isOK()) {
updateStatus(m_elementName + " name is not valid!");
return;
}
// check whether this container already exists
IPath path = getWorkflowPath();
IContainer container = (IContainer) ResourcesPlugin.getWorkspace().getRoot().findMember(path);
if (container != null) {
updateStatus(m_elementName + " name already exists.");
return;
}
updateStatus(null);
}
use of org.eclipse.core.resources.IContainer in project knime-core by knime.
the class NewProjectWizardPage method handleBrowseButton.
private void handleBrowseButton() {
WorkflowGroupSelectionDialog dialog = new WorkflowGroupSelectionDialog(getShell());
dialog.setInitialSelection(new Path(m_destinationUI.getText()));
if (dialog.open() == IDialogConstants.OK_ID) {
IContainer c = dialog.getSelectedWorkflowGroup();
m_destinationUI.setText(c.getFullPath().toString());
}
dialogChanged();
}
use of org.eclipse.core.resources.IContainer in project knime-core by knime.
the class WorkflowImportSelectionPage method handleWorkflowGroupBrowseButtonPressed.
private void handleWorkflowGroupBrowseButtonPressed() {
// get the value from the text field
String wfGroupPath = m_targetTextUI.getText();
IPath initialPath = ResourcesPlugin.getWorkspace().getRoot().getFullPath();
// if not yet set take workflow root
if (wfGroupPath != null && !wfGroupPath.trim().isEmpty()) {
initialPath = new Path(wfGroupPath);
}
WorkflowGroupSelectionDialog dialog = new WorkflowGroupSelectionDialog(getShell());
dialog.setInitialSelection(initialPath);
int returnCode = dialog.open();
if (returnCode == IDialogConstants.OK_ID) {
// set the newly selected workflow group as destination
IContainer target = dialog.getSelectedWorkflowGroup();
if (target != null && !target.equals(ResourcesPlugin.getWorkspace().getRoot())) {
m_targetTextUI.setText(target.getFullPath().toString());
} else {
m_targetTextUI.setText(Path.ROOT.toString());
}
}
validateWorkflows();
}
use of org.eclipse.core.resources.IContainer in project knime-core by knime.
the class NewProjectWizard method doFinish.
/**
* Worker method, creates the project using the given options.
*
* @param workflowPath path of the workflow to create in workspace
* @param monitor Progress monitor
* @throws CoreException if error while creating the project
*/
public static void doFinish(final IPath workflowPath, final IProgressMonitor monitor) throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(workflowPath);
if (resource != null) {
throwCoreException("Resource \"" + workflowPath.toString() + "\" does already exist.", null);
}
// check if there is a folder with the same name on the file system
// see bug (http://bimbug.inf.uni-konstanz.de/show_bug.cgi?id=1912)
IPath rootLocation = root.getLocation();
if (rootLocation != null) {
IPath absolutePath = rootLocation.append(workflowPath);
if (absolutePath.toFile().exists()) {
throwCoreException("Resource " + workflowPath + " already exists!", null);
}
}
ContainerGenerator generator = new ContainerGenerator(workflowPath);
IContainer containerResult = generator.generateContainer(monitor);
if (containerResult instanceof IProject) {
IProject project = (IProject) containerResult;
// open the project
project.open(monitor);
// Create project description, set the nature IDs and build-commands
try {
// set the nature id of the project is enough
// the name is already set by IProject#create()
IProjectDescription description = project.getDescription();
description.setNatureIds(new String[] { KNIMEProjectNature.ID });
project.setDescription(description, monitor);
} catch (CoreException ce) {
throwCoreException("Error while creating project description for " + project.getName(), ce);
}
}
//
// 2. Create the optional files, if wanted
//
final IFile defaultFile = containerResult.getFile(new Path(WorkflowPersistor.WORKFLOW_FILE));
InputStream is = new ByteArrayInputStream(new byte[0]);
defaultFile.create(is, true, monitor);
// open the default file, if it was created
// open the model file in the editor
monitor.setTaskName("Opening file for editing...");
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
IDE.openEditor(page, defaultFile, true);
} catch (PartInitException e) {
// ignore it
}
}
});
}
use of org.eclipse.core.resources.IContainer in project knime-core by knime.
the class WorkflowGroupSelectionDialog method pathToTreeSelection.
/**
* @param path the path of a resource
* @return the selection to be passed to a tree in order to select the
* resource denoted by the given path
*/
public static IStructuredSelection pathToTreeSelection(final IPath path) {
if (path != null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource r = root.findMember(path);
if (r != null && !r.equals(root)) {
IContainer c = r.getParent();
if (r instanceof IContainer) {
c = (IContainer) r;
}
String[] segments = c.getFullPath().segments();
Object[] treePathSegments = new Object[segments.length];
// find all parents in order to create the path segments
int i = 1;
while (c.getParent() != null) {
treePathSegments[treePathSegments.length - i] = c;
c = c.getParent();
i++;
}
TreePath treePath = new TreePath(treePathSegments);
return new TreeSelection(treePath);
}
}
// default: return empty selection
return new TreeSelection();
}
Aggregations