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 boolean showConsole = WikiEditorPlugin.getDefault().getPreferenceStore().getBoolean(WikiEditorPlugin.CONSOLE_OUTPUT);
42 for (int i = 0; i < files.length; i++) {
44 wikiTitle = wikiTitles[i];
46 IContainer parent = file.getParent();
47 if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
48 Util.createFolder((IFolder) parent, monitor);
52 monitor.subTask("Create File: "+file.getLocation().toString());
53 file.create(source, true, monitor);
54 Page page = new Page("", wikiTitle, "");
55 page.createXMLFile(file, false);
57 console.println("Title: "+wikiTitle+" =>File: " + file.getLocation().toString() + "created\n");
60 String message = "File: " + file.getLocation().toString() + "\n==>file already exists!";
61 monitor.subTask(message);
62 console.println(message);
64 } catch (CoreException e) {
66 console.println("File: " + file.getLocation().toString() + "\n==>CoreException: "+e.getMessage());
69 if (monitor.isCanceled()) {
70 return Status.CANCEL_STATUS;
77 // The progress dialog is still open show the message
78 console.reportError();
80 setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
81 // setProperty(IProgressConstants.ACTION_PROPERTY, getWikisCompletedAction());
83 return Status.OK_STATUS;
84 // } catch(CoreException e) {
85 // return e.getStatus();
89 // return Status.OK_STATUS;
92 public boolean isModal(Job job) {
93 Boolean isModal = (Boolean) job.getProperty(IProgressConstants.PROPERTY_IN_DIALOG);
94 if (isModal == null) {
97 return isModal.booleanValue();