use of org.eclipse.ui.dialogs.ContainerGenerator in project che by eclipse.
the class ImportOperation method execute.
/* (non-Javadoc)
* Method declared on WorkbenchModifyOperation.
* Imports the specified file system objects from the file system.
*/
protected void execute(IProgressMonitor progressMonitor) {
monitor = progressMonitor;
try {
if (selectedFiles == null) {
//Set the amount to 1000 as we have no idea of how long this will take
monitor.beginTask("Importing:", 1000);
ContainerGenerator generator = new ContainerGenerator(destinationPath);
monitor.worked(30);
validateFiles(Arrays.asList(new Object[] { source }));
monitor.worked(50);
destinationContainer = generator.generateContainer(new SubProgressMonitor(monitor, 50));
importRecursivelyFrom(source, POLICY_DEFAULT);
//Be sure it finishes
monitor.worked(90);
} else {
// Choose twice the selected files size to take folders into account
int creationCount = selectedFiles.size();
monitor.beginTask("Importing:", creationCount + 100);
ContainerGenerator generator = new ContainerGenerator(destinationPath);
monitor.worked(30);
validateFiles(selectedFiles);
monitor.worked(50);
destinationContainer = generator.generateContainer(new SubProgressMonitor(monitor, 50));
importFileSystemObjects(selectedFiles);
monitor.done();
}
} catch (CoreException e) {
errorTable.add(e.getStatus());
} finally {
monitor.done();
}
}
use of org.eclipse.ui.dialogs.ContainerGenerator in project knime-core by knime.
the class WorkflowGroupCreationOperation method execute.
/**
* {@inheritDoc}
*/
@Override
protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
ContainerGenerator generator = new ContainerGenerator(m_targetPath);
m_resultContainer = generator.generateContainer(monitor);
if (m_resultContainer instanceof IProject) {
// get project description
// set nature
// set description
final IProject project = (IProject) m_resultContainer;
IProjectDescription desc = project.getDescription();
desc.setNatureIds(new String[] { KNIMEWorkflowSetProjectNature.ID });
project.setDescription(desc, monitor);
// only one workflow group can be created at a time
// -> thus, only necessary to create this meta info file
}
// this has to be done in any case!
MetaInfoFile.createMetaInfoFile(new File(m_resultContainer.getLocationURI()), false);
m_resultContainer.refreshLocal(IResource.DEPTH_ONE, monitor);
}
use of org.eclipse.ui.dialogs.ContainerGenerator 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.ui.dialogs.ContainerGenerator in project knime-core by knime.
the class WorkflowImportOperation method createMetaInfo.
private void createMetaInfo() throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
for (IPath p : m_missingMetaInfoLocations) {
// to be sure that target location indeed exists -> create it
ContainerGenerator generator = new ContainerGenerator(p);
generator.generateContainer(new NullProgressMonitor());
p = root.getLocation().append(p);
File parent = p.toFile();
MetaInfoFile.createMetaInfoFile(parent, false);
}
}
use of org.eclipse.ui.dialogs.ContainerGenerator in project knime-core by knime.
the class KnimeResourceUtil method createContainer.
/**
* Creates a container with the specified path (resource must not exist!).
* Return true if the container exists at the end, false if not. Creates
* meta info and projects files as required by KNIME.
*
* @param dest
* @return
*/
private static boolean createContainer(final IPath dest) {
int newLevel = 0;
IPath p = dest.removeLastSegments(1);
while (!ResourcesPlugin.getWorkspace().getRoot().exists(p)) {
newLevel++;
p = dest.removeLastSegments(newLevel + 1);
}
final ContainerGenerator cg = new ContainerGenerator(dest);
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
cg.generateContainer(monitor);
} catch (CoreException ce) {
// we check later
}
}
});
} catch (InvocationTargetException e) {
// we check later
} catch (InterruptedException e) {
// we check later
}
while (newLevel > 0) {
// we created a new directory, create metainfo files in all levels
IResource newRes = ResourcesPlugin.getWorkspace().getRoot().findMember(dest.removeLastSegments(newLevel));
URI rawLoc = newRes.getLocationURI();
if (rawLoc != null) {
File projLoc = new File(rawLoc);
MetaInfoFile.createMetaInfoFile(projLoc, dest.segmentCount() == 1);
}
newLevel--;
}
try {
ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (CoreException e) {
// don't refresh then
}
return true;
}
Aggregations