mail[Wesnoth-commits] r43826 - in /trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin: utils/ wizards/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by timotei_cluj on July 01, 2010 - 23:48:
Author: timotei
Date: Thu Jul  1 23:48:54 2010
New Revision: 43826

URL: http://svn.gna.org/viewcvs/wesnoth?rev=43826&view=rev
Log:
eclipse plugin: part 2 of creating project files/directories based on text 
files

Added:
    trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/Pair.java
Modified:
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/CampaignNewWizard.java
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/ScenarioNewWizard.java
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/TemplateProvider.java

Added: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/Pair.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/Pair.java?rev=43826&view=auto
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/Pair.java 
(added)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/Pair.java 
Thu Jul  1 23:48:54 2010
@@ -1,0 +1,16 @@
+/**
+ * @author Timotei Dolean
+ *
+ */
+package wesnoth_eclipse_plugin.utils;
+
+public class Pair<T, K>
+{
+       public T        First;
+       public K        Second;
+
+       public Pair(T first, K second) {
+               First = first;
+               Second = second;
+       }
+}

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/CampaignNewWizard.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/CampaignNewWizard.java?rev=43826&r1=43825&r2=43826&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/CampaignNewWizard.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/CampaignNewWizard.java
 Thu Jul  1 23:48:54 2010
@@ -2,6 +2,7 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
+import java.util.List;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IProjectDescription;
@@ -16,8 +17,8 @@
 import org.eclipse.ui.IWorkbench;
 
 import wesnoth_eclipse_plugin.builder.WesnothProjectNature;
+import wesnoth_eclipse_plugin.utils.Pair;
 import wesnoth_eclipse_plugin.utils.ResourceUtils;
-import wesnoth_eclipse_plugin.utils.StringUtils;
 
 public class CampaignNewWizard extends Wizard implements INewWizard
 {
@@ -98,25 +99,20 @@
                        if (campaignStructure == null)
                                return;
 
-                       for (String line : 
StringUtils.getLines(campaignStructure))
+                       List<Pair<String, String>> files;
+                       List<String> dirs;
+                       Pair<List<Pair<String, String>>, List<String>> tmp = 
TemplateProvider.getInstance().getFilesDirectories(campaignStructure);
+                       files = tmp.First;
+                       dirs = tmp.Second;
+
+                       for (Pair<String, String> file : files)
                        {
-                               if (StringUtils.startsWith(line, "#"))
-                                       continue;
-
-                               if (line.contains(":")) // file with template
-                               {
-                                       String[] tmpLine = line.split(":");
-
-                                       // oops. error
-                                       if (tmpLine.length != 2)
-                                               continue;
-
-                                       
ResourceUtils.createFile(currentProject, tmpLine[0].trim(), 
prepareTemplate(tmpLine[1].trim()));
-                               }
-                               else
-                               {
-                                       
ResourceUtils.createFolder(currentProject, line.trim());
-                               }
+                               ResourceUtils.createFile(currentProject, 
file.First, prepareTemplate(file.Second));
+                               monitor.worked(1);
+                       }
+                       for (String dir : dirs)
+                       {
+                               ResourceUtils.createFolder(currentProject, 
dir);
                                monitor.worked(1);
                        }
 
@@ -151,7 +147,7 @@
                params.add(new ReplaceableParameter("$$project_name", 
page0_.getProjectName()));
                params.add(new ReplaceableParameter("$$type", 
page1_.isMultiplayer() ? "campaign_mp" : "campaign"));
 
-               return TemplateProvider.getProcessedTemplate(templateName, 
params);
+               return 
TemplateProvider.getInstance().getProcessedTemplate(templateName, params);
        }
 
        @Override

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/ScenarioNewWizard.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/ScenarioNewWizard.java?rev=43826&r1=43825&r2=43826&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/ScenarioNewWizard.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/ScenarioNewWizard.java
 Thu Jul  1 23:48:54 2010
@@ -64,13 +64,13 @@
        @Override
        public void addPages()
        {
-               this.page0_ = new ScenarioPage0(this.selection);
-               addPage(this.page0_);
-
-               this.page1_ = new ScenarioPage1();
+               page0_ = new ScenarioPage0(selection);
+               addPage(page0_);
+
+               page1_ = new ScenarioPage1();
                // addPage(page1_);
 
-               this.lastPageHashCode_ = getPages()[getPageCount() - 
1].hashCode();
+               lastPageHashCode_ = getPages()[getPageCount() - 1].hashCode();
        }
 
        /*
@@ -81,7 +81,7 @@
        public boolean canFinish()
        {
                IWizardPage page = getContainer().getCurrentPage();
-               return super.canFinish() && page.hashCode() == 
this.lastPageHashCode_ && page.isPageComplete();
+               return super.canFinish() && page.hashCode() == 
lastPageHashCode_ && page.isPageComplete();
        }
 
        /**
@@ -91,8 +91,8 @@
        @Override
        public boolean performFinish()
        {
-               final String containerName = this.page0_.getProjectName();
-               final String fileName = this.page0_.getFileName();
+               final String containerName = page0_.getProjectName();
+               final String fileName = page0_.getFileName();
                IRunnableWithProgress op = new IRunnableWithProgress() {
                        @Override
                        public void run(IProgressMonitor monitor) throws 
InvocationTargetException
@@ -135,10 +135,12 @@
                monitor.beginTask("Creating " + fileName, 2);
                IWorkspaceRoot root = 
ResourcesPlugin.getWorkspace().getRoot();
                IResource resource = root.findMember(new Path(containerName));
+
                if (!resource.exists() || !(resource instanceof IContainer))
                {
                        throwCoreException("Container \"" + containerName + 
"\" does not exist.");
                }
+
                IContainer container = (IContainer) resource;
                final IFile file = container.getFile(new Path(fileName));
 
@@ -147,22 +149,23 @@
                        InputStream stream = getScenarioStream();
 
                        if (stream == null)
-                       {
                                return;
-                       }
 
                        if (file.exists())
                        {
                                file.setContents(stream, true, true, monitor);
-                       } else
+                       }
+                       else
                        {
                                file.create(stream, true, monitor);
                        }
+
                        stream.close();
                } catch (IOException e)
                {
                        e.printStackTrace();
                }
+
                monitor.worked(1);
                monitor.setTaskName("Opening file for editing...");
                getShell().getDisplay().asyncExec(new Runnable() {
@@ -188,14 +191,14 @@
        {
                ArrayList<ReplaceableParameter> params = new 
ArrayList<ReplaceableParameter>();
 
-               params.add(new ReplaceableParameter("$$scenario_id", 
this.page0_.getScenarioId()));
-               params.add(new ReplaceableParameter("$$next_scenario_id", 
this.page0_.getNextScenarioId()));
-               params.add(new ReplaceableParameter("$$scenario_name", 
this.page0_.getScenarioName()));
-               params.add(new ReplaceableParameter("$$map_data", 
this.page0_.getMapData()));
-
-               params.add(new ReplaceableParameter("$$turns_number", 
String.valueOf(this.page0_.getTurnsNumber())));
-
-               String template = 
TemplateProvider.getProcessedTemplate("scenario", params);
+               params.add(new ReplaceableParameter("$$scenario_id", 
page0_.getScenarioId()));
+               params.add(new ReplaceableParameter("$$next_scenario_id", 
page0_.getNextScenarioId()));
+               params.add(new ReplaceableParameter("$$scenario_name", 
page0_.getScenarioName()));
+               params.add(new ReplaceableParameter("$$map_data", 
page0_.getMapData()));
+
+               params.add(new ReplaceableParameter("$$turns_number", 
String.valueOf(page0_.getTurnsNumber())));
+
+               String template = 
TemplateProvider.getInstance().getProcessedTemplate("scenario", params);
 
                if (template == null)
                {

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/TemplateProvider.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/TemplateProvider.java?rev=43826&r1=43825&r2=43826&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/TemplateProvider.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/TemplateProvider.java
 Thu Jul  1 23:48:54 2010
@@ -8,8 +8,10 @@
 import java.io.FileReader;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 
 import wesnoth_eclipse_plugin.Logger;
+import wesnoth_eclipse_plugin.utils.Pair;
 import wesnoth_eclipse_plugin.utils.StringUtils;
 
 public class TemplateProvider
@@ -83,7 +85,7 @@
                }
        }
 
-       public static String getProcessedTemplate(String templateName, 
ArrayList<ReplaceableParameter> parameters)
+       public String getProcessedTemplate(String templateName, 
ArrayList<ReplaceableParameter> parameters)
        {
                String tmpTemplate = 
TemplateProvider.getInstance().getTemplate(templateName);
                if (tmpTemplate == null)
@@ -125,4 +127,41 @@
                        return "";
                return templates_.get(name);
        }
+
+       /**
+        * Gets the lists of the specified structure template. The first 
return
+        * value is a list of <String, String> that consist of <Filename, 
Template
+        * used for file contents> and the second return value is a list of 
String
+        * with directories names
+        * @param structureTemplate the template
+        * @return
+        */
+       public Pair<List<Pair<String, String>>, List<String>> 
getFilesDirectories(String structureTemplate)
+       {
+               List<Pair<String, String>> files = new ArrayList<Pair<String, 
String>>();
+               List<String> dirs = new ArrayList<String>();
+
+               for (String line : StringUtils.getLines(structureTemplate))
+               {
+                       if (StringUtils.startsWith(line, "#"))
+                               continue;
+
+                       if (line.contains(":")) // file with template
+                       {
+                               String[] tmpLine = line.split(":");
+
+                               // oops. error
+                               if (tmpLine.length != 2)
+                                       continue;
+
+                               files.add(new Pair<String, 
String>(tmpLine[0].trim(), tmpLine[1].trim()));
+                       }
+                       else
+                       {
+                               dirs.add(line.trim());
+                       }
+               }
+
+               return new Pair<List<Pair<String, String>>, 
List<String>>(files, dirs);
+       }
 }




Related Messages


Powered by MHonArc, Updated Fri Jul 02 01:40:05 2010