Added list selection box for file creation from wiki links
authoraxelcl <axelcl>
Thu, 3 Feb 2005 18:22:14 +0000 (18:22 +0000)
committeraxelcl <axelcl>
Thu, 3 Feb 2005 18:22:14 +0000 (18:22 +0000)
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/CreateFilesFromLinksEditorAction.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/CreateFilesJob.java

index 0fa5c0d..32a6ae0 100644 (file)
@@ -1,15 +1,48 @@
 package net.sourceforge.phpeclipse.wiki.actions;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 
+import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.window.Window;
 import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.eclipse.ui.internal.dialogs.ListContentProvider;
 
 public final class CreateFilesFromLinksEditorAction extends OpenWikiLinkEditorAction {
 
+  class WikiFile implements Comparable {
+    IFile file;
+
+    String wikiTitle;
+
+    public WikiFile(IFile f, String title) {
+      file = f;
+      wikiTitle = title;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+      return wikiTitle + " - " + file.getProjectRelativePath().toString();
+    }
+    /* (non-Javadoc)
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
+    public int compareTo(Object o) {
+      return wikiTitle.compareTo(((WikiFile)o).wikiTitle);
+    }
+  }
+
   public void openWikiLinkOnSelection() {
     IDocument doc = getDocument();
     ArrayList startPositionList = getLinksStartingPosition(doc);
@@ -28,24 +61,36 @@ public final class CreateFilesFromLinksEditorAction extends OpenWikiLinkEditorAc
       if (wikiTitle != null && !wikiTitle.equals("")) {
         if (!wikiNames.contains(wikiTitle)) {
           IFile file = getWikiFile(currentFile, wikiTitle);
-          filesList.add(file);
-          wikiList.add(wikiTitle);
+          filesList.add(new WikiFile(file, wikiTitle));
+//          wikiList.add(wikiTitle);
           wikiNames.add(wikiTitle);
         }
       }
     }
 
     if (filesList.size() > 0) {
-      IFile[] files = new IFile[filesList.size()];
-      String[] wikiTitles = new String[filesList.size()];
-      filesList.toArray(files);
-      wikiList.toArray(wikiTitles);
-
-      Job job = new CreateFilesJob(files, wikiTitles);
-      //        job.setRule(createRule(files));
-      job.setRule(null);
-      job.setUser(true);
-      job.schedule();
+      Collections.sort(filesList);
+      ListSelectionDialog listSelectionDialog = new ListSelectionDialog(WikiEditorPlugin.getDefault().getWorkbench()
+          .getActiveWorkbenchWindow().getShell(), filesList, new ListContentProvider(), new LabelProvider(),
+          "Select the links for file creation:");
+      listSelectionDialog.setTitle("Links found in this article");
+      if (listSelectionDialog.open() == Window.OK) {
+        Object[] locations = listSelectionDialog.getResult();
+        if (locations.length > 0) {
+          IFile[] files = new IFile[locations.length];
+          String[] wikiTitles = new String[locations.length];
+          for (int i = 0; i < files.length; i++) {
+            files[i] = ((WikiFile) locations[i]).file;
+            wikiTitles[i] = ((WikiFile) locations[i]).wikiTitle;
+          }
+          
+          Job job = new CreateFilesJob(files, wikiTitles);
+          //        job.setRule(createRule(files));
+          job.setRule(null);
+          job.setUser(true);
+          job.schedule();
+        }
+      }
 
     }
   }
index 095f77e..7b3cad2 100644 (file)
@@ -75,7 +75,6 @@ public class CreateFilesJob extends WorkspaceJob {
 
       if (isModal(this)) {
         // The progress dialog is still open show the message
-        console.reportError();
       } else {
         setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
         //            setProperty(IProgressConstants.ACTION_PROPERTY, getWikisCompletedAction());