1 package net.sourceforge.phpeclipse.wiki.actions;
2 import java.io.ByteArrayInputStream;
4 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
5 import net.sourceforge.phpeclipse.wiki.preferences.Util;
7 import org.eclipse.core.resources.IContainer;
8 import org.eclipse.core.resources.IFile;
9 import org.eclipse.core.resources.IFolder;
10 import org.eclipse.core.resources.WorkspaceJob;
11 import org.eclipse.core.runtime.CoreException;
12 import org.eclipse.core.runtime.IProgressMonitor;
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.core.runtime.Status;
15 import org.eclipse.core.runtime.jobs.Job;
16 import org.eclipse.ui.progress.IProgressConstants;
18 public class CreateFilesJob extends WorkspaceJob {
21 public CreateFilesJob(IFile[] files) {
22 super("Create Wiki Files Job");
26 public IStatus runInWorkspace(IProgressMonitor monitor) {
28 monitor.beginTask("Create Wiki Files", 100);
30 int partOfWork = 100 / files.length;
32 String newText = WikiEditorPlugin.AUTOMATICALLY_CREATED;
33 byte[] buffer = newText.getBytes();
34 ByteArrayInputStream source = new ByteArrayInputStream(buffer);
35 ProblemConsole console = new ProblemConsole();
36 for (int i = 0; i < files.length; i++) {
39 IContainer parent = file.getParent();
40 if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
41 Util.createFolder((IFolder) parent, monitor);
45 monitor.subTask("Create File: "+file.getLocation().toString());
46 file.create(source, true, monitor);
48 String message = "File: " + file.getLocation().toString() + "\n==>file already exists!";
49 monitor.subTask(message);
50 console.println(message);
52 } catch (CoreException e) {
54 console.println("File: " + file.getLocation().toString() + "\n==>CoreException: "+e.getMessage());
57 if (monitor.isCanceled()) {
58 return Status.CANCEL_STATUS;
65 // The progress dialog is still open show the message
66 console.reportError();
68 setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
69 // setProperty(IProgressConstants.ACTION_PROPERTY, getWikisCompletedAction());
71 return Status.OK_STATUS;
72 // } catch(CoreException e) {
73 // return e.getStatus();
77 // return Status.OK_STATUS;
80 public boolean isModal(Job job) {
81 Boolean isModal = (Boolean) job.getProperty(IProgressConstants.PROPERTY_IN_DIALOG);
82 if (isModal == null) {
85 return isModal.booleanValue();