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;
6 import net.sourceforge.phpeclipse.wiki.xml.Page;
8 import org.eclipse.core.resources.IContainer;
9 import org.eclipse.core.resources.IFile;
10 import org.eclipse.core.resources.IFolder;
11 import org.eclipse.core.resources.WorkspaceJob;
12 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.core.runtime.jobs.Job;
17 import org.eclipse.ui.progress.IProgressConstants;
19 public class CreateFilesJob extends WorkspaceJob {
23 public CreateFilesJob(IFile[] files, String[] wikiTitles) {
24 super("Create Wiki Files Job");
26 this.wikiTitles = wikiTitles;
29 public IStatus runInWorkspace(IProgressMonitor monitor) {
31 monitor.beginTask("Create Wiki Files", 100);
34 int partOfWork = 100 / files.length;
36 String newText = WikiEditorPlugin.AUTOMATICALLY_CREATED;
37 byte[] buffer = newText.getBytes();
38 ByteArrayInputStream source = new ByteArrayInputStream(buffer);
39 ProblemConsole console = new ProblemConsole();
40 for (int i = 0; i < files.length; i++) {
42 wikiTitle = wikiTitles[i];
44 IContainer parent = file.getParent();
45 if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
46 Util.createFolder((IFolder) parent, monitor);
50 monitor.subTask("Create File: "+file.getLocation().toString());
51 file.create(source, true, monitor);
52 Page page = new Page("", wikiTitle, "");
53 page.createXMLFile(file, false);
55 String message = "File: " + file.getLocation().toString() + "\n==>file already exists!";
56 monitor.subTask(message);
57 console.println(message);
59 } catch (CoreException e) {
61 console.println("File: " + file.getLocation().toString() + "\n==>CoreException: "+e.getMessage());
64 if (monitor.isCanceled()) {
65 return Status.CANCEL_STATUS;
72 // The progress dialog is still open show the message
73 console.reportError();
75 setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
76 // setProperty(IProgressConstants.ACTION_PROPERTY, getWikisCompletedAction());
78 return Status.OK_STATUS;
79 // } catch(CoreException e) {
80 // return e.getStatus();
84 // return Status.OK_STATUS;
87 public boolean isModal(Job job) {
88 Boolean isModal = (Boolean) job.getProperty(IProgressConstants.PROPERTY_IN_DIALOG);
89 if (isModal == null) {
92 return isModal.booleanValue();