1 package net.sourceforge.phpeclipse.wiki.actions;
3 import java.util.ArrayList;
4 import java.util.HashSet;
6 import org.eclipse.core.resources.IFile;
7 import org.eclipse.core.runtime.jobs.Job;
8 import org.eclipse.jface.text.IDocument;
9 import org.eclipse.ui.IFileEditorInput;
11 public final class CreateFilesFromLinksEditorAction extends OpenWikiLinkEditorAction {
13 public void openWikiLinkOnSelection() {
14 IDocument doc = getDocument();
15 ArrayList startPositionList = getLinksStartingPosition(doc);
17 HashSet wikiNames = new HashSet();
18 ArrayList filesList = new ArrayList();
19 ArrayList wikiList = new ArrayList();
22 IFile currentFile = ((IFileEditorInput) editor.getEditorInput()).getFile();
24 for (int i = 0; i < startPositionList.size(); i++) {
25 posInteger = (Integer) startPositionList.get(i);
26 wikiTitle = getWikiTitle(editor, doc, posInteger.intValue());
28 if (wikiTitle != null && !wikiTitle.equals("")) {
29 if (!wikiNames.contains(wikiTitle)) {
30 IFile file = getWikiFile(currentFile, wikiTitle);
32 wikiList.add(wikiTitle);
33 wikiNames.add(wikiTitle);
38 if (filesList.size() > 0) {
39 IFile[] files = new IFile[filesList.size()];
40 String[] wikiTitles = new String[filesList.size()];
41 filesList.toArray(files);
42 wikiList.toArray(wikiTitles);
44 Job job = new CreateFilesJob(files, wikiTitles);
45 // job.setRule(createRule(files));
57 private ArrayList getLinksStartingPosition(IDocument doc) {
58 ArrayList startPositionList = new ArrayList();
59 char[] text = doc.get().toCharArray();
75 if (ch == ']' && startPos != (-1)) {
76 startPositionList.add(new Integer(startPos));
86 } catch (IndexOutOfBoundsException e) {
89 return startPositionList;