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


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

Header


Content

Posted by timotei_cluj on July 09, 2010 - 12:34:
Author: timotei
Date: Fri Jul  9 12:34:41 2010
New Revision: 44037

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44037&view=rev
Log:
eclipse plugin: schema-based wizards - step 7 implement constratints checkers
and added comboboxes for "enum" value types

Modified:
    trunk/data/schema.cfg
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/SchemaParser.java
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/Tag.java
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/TagKey.java
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/WizardGeneratorPageKey.java

Modified: trunk/data/schema.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/schema.cfg?rev=44037&r1=44036&r2=44037&view=diff
==============================================================================
--- trunk/data/schema.cfg (original)
+++ trunk/data/schema.cfg Fri Jul  9 12:34:41 2010
@@ -2,6 +2,11 @@
 [schema]
     identifier="re ^[a-zA-Z0-9_ ]+$"
     identifierlist="re ^([a-zA-Z0-9_ ]+,)*[a-zA-Z0-9_ ]+$"
+       string="re ^"[\d\w\s]*"$"
+       tstring="re ^_"[\d\w\s]*"$"
+       integer="re ^\d+$"
+       float="re ^\d+.\d+$"
+       boolean="enum true,false"
     # slash-separated filenames
     path="re 
^([a-zA-Z0-9_\-.+]+/)*[a-zA-Z0-9_\-.+]+(~(TC|RC|PAL|FL|GS|CS|CROP|SCALE|BL|O|R|G|B|NOP|RIGHT)\(.*\))*$"
     #TODO: imagepath, remove imagepathfunctions from path

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/SchemaParser.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/SchemaParser.java?rev=44037&r1=44036&r2=44037&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/SchemaParser.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/SchemaParser.java
 Fri Jul  9 12:34:41 2010
@@ -8,6 +8,7 @@
 import java.util.HashMap;
 import java.util.Stack;
 
+import wesnoth_eclipse_plugin.Logger;
 import wesnoth_eclipse_plugin.preferences.PreferenceConstants;
 import wesnoth_eclipse_plugin.preferences.PreferenceInitializer;
 import wesnoth_eclipse_plugin.utils.ResourceUtils;
@@ -34,15 +35,19 @@
                if (parsingDone_ && !force)
                        return;
 
+               parsingDone_ = false;
+               if (force)
+               {
+                       primitives_.clear();
+                       tags_.clear();
+               }
+
+               Logger.print("parsing schema " + (force == true ? "forced" : 
""));
                File schemaFile = new File(PreferenceInitializer.getString(
                                                
PreferenceConstants.P_WESNOTH_WORKING_DIR) + "/data/schema.cfg");
                String res = ResourceUtils.getFileContents(schemaFile);
                String[] lines = StringUtils.getLines(res);
                Stack<String> tagStack = new Stack<String>();
-
-               // temporarly add 'string' and 'tstring' primitives
-               primitives_.put("string", "\"[\\d\\w\\s]\"");
-               primitives_.put("tstring", "_\"[\\d\\w\\s]\"");
 
                Tag currentTag = null;
                for (int index = 0; index < lines.length; index++)
@@ -144,7 +149,7 @@
                                                continue; //return;
                                        }
 
-                                       if (currentTag != 
null)//tags.containsKey(tagStack.peek()))
+                                       if (currentTag != null)
                                        {
                                                if 
(tokens[0].startsWith("_")) // reference to another tag
                                                {
@@ -166,7 +171,9 @@
                                                {
                                                        if 
(!(primitives_.containsKey(value[1])))
                                                                
currentTag.NeedsExpanding = true;
-                                                       
currentTag.addKey(tokens[0], value[1], getCardinality(value[0]));
+                                                       if 
(primitives_.get(value[1]) == null)
+                                                               
System.err.println("Undefined primitive type in schema.cfg for: " + value[1]);
+                                                       
currentTag.addKey(tokens[0], primitives_.get(value[1]), 
getCardinality(value[0]));
                                                }
                                        }
                                        else
@@ -214,7 +221,7 @@
                String res = indent + "[" + tag.Name + "]\n";
                for (TagKey key : tag.KeyChildren)
                {
-                       res += (indent + "\t" + key.Name + "=" + key.Regex + 
"\n");
+                       res += (indent + "\t" + key.Name + "=" + 
key.ValueType + "\n");
                }
                for (Tag tmpTag : tag.TagChildren)
                {

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/Tag.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/Tag.java?rev=44037&r1=44036&r2=44037&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/Tag.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/Tag.java
 Fri Jul  9 12:34:41 2010
@@ -49,8 +49,8 @@
                KeyChildren.add(key);
        }
 
-       public void addKey(String name, String regex, char cardinality)
+       public void addKey(String name, String valueType, char cardinality)
        {
-               addKey(new TagKey(name, cardinality, regex));
+               addKey(new TagKey(name, cardinality, valueType));
        }
 }

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/TagKey.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/TagKey.java?rev=44037&r1=44036&r2=44037&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/TagKey.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/TagKey.java
 Fri Jul  9 12:34:41 2010
@@ -15,11 +15,18 @@
         * - = forbidden
         */
        public char             Cardinality;
-       public String   Regex;
+       public String   ValueType;
+       public boolean  IsEnum;
 
-       public TagKey(String name, char cardinality, String regex) {
+       public TagKey(String name, char cardinality, String valueType) {
                Name = name;
                Cardinality = cardinality;
-               Regex = regex;
+
+               if (valueType == null)
+               {
+                       return;
+               }
+               IsEnum = valueType.substring(1, valueType.indexOf(" 
")).equals("enum");
+               ValueType = valueType.substring(valueType.indexOf(" ") + 1, 
valueType.length() - 1); // remove the " "
        }
 }

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/WizardGeneratorPageKey.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/WizardGeneratorPageKey.java?rev=44037&r1=44036&r2=44037&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/WizardGeneratorPageKey.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/generator/WizardGeneratorPageKey.java
 Fri Jul  9 12:34:41 2010
@@ -8,8 +8,11 @@
 
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
@@ -47,21 +50,81 @@
                for (int i = startIndex_; i <= endIndex_; i++)
                {
                        TagKey key = keys_.get(i);
+
                        Label label = new Label(container_, SWT.NONE);
                        label.setLayoutData(new GridData(SWT.FILL, 
SWT.CENTER, false, false, 1, 1));
                        // add star to required items
                        label.setText(key.Name + (key.Cardinality == '1' ? 
"*" : "") + ":");
 
-                       Text textBox = new Text(container_, SWT.BORDER);
-                       textBox.setLayoutData(new GridData(SWT.FILL, 
SWT.CENTER, true, false, 1, 1));
-                       //textBox.setText(key.Regex);
-                       textBox.setData("name", key.Name);
-                       textBox.setData("regex", key.Regex);
-                       textBox.setData("card", key.Cardinality);
+                       // if the is an enum create a combobox instead of 
textbox
+                       if (key.IsEnum)
+                       {
+                               Combo combo = new Combo(container_, 
SWT.READ_ONLY);
+                               combo.setLayoutData(new GridData(SWT.FILL, 
SWT.CENTER, true, false, 1, 1));
+                               combo.setData("name", key.Name);
+                               String[] items = key.ValueType.split(",");
+                               combo.setItems(items);
+                               combo.select(0);
+                       }
+                       else
+                       {
+                               Text textBox = new Text(container_, 
SWT.BORDER);
+                               textBox.setLayoutData(new GridData(SWT.FILL, 
SWT.CENTER, true, false, 1, 1));
 
-                       //TODO: check for regex/cardinality
+                               textBox.setData("name", key.Name);
+                               textBox.setData("valType", key.ValueType);
+                               textBox.setData("card", key.Cardinality);
+                               if (key.Cardinality == '1')
+                                       textBox.setData("comp", false); // is 
textbox complete
+
+                               textBox.addModifyListener(new 
ModifyListener() {
+                                       @Override
+                                       public void modifyText(ModifyEvent e)
+                               {
+                                       if (!(e.getSource() instanceof Text))
+                                               return;
+
+                                       Text txt = ((Text) e.getSource());
+                                       if (txt.getData("comp") == null)
+                                               return;
+
+                                       if ((txt.getText().isEmpty() && 
(txt.getData("card").toString().equals("1"))) || // cardinality
+                                                       
!txt.getText().matches(txt.getData("valType").toString()) // regex
+                                       )
+                                               txt.setData("comp", false);
+                                       else
+                                               txt.setData("comp", true);
+                                       updatePageIsComplete();
+                               }
+                               });
+                       }
                }
+               updatePageIsComplete();
+       }
+
+       private void updatePageIsComplete()
+       {
+               setPageComplete(false);
+
+               for (Control child : container_.getChildren())
+               {
+                       if (!(child instanceof Text)) // don't check 
comboboxes
+                               continue;
+
+                       if (child.getData("comp") == null)
+                               continue;
+
+                       if (child.getData("comp").toString().equals("false"))
+                       {
+                               setErrorMessage(child.getData("name") +
+                                               " is empty or does not match 
required value\n"
+                                               + child.getData("valType"));
+                               return;
+                       }
+               }
+
                setPageComplete(true);
+               setErrorMessage(null);
        }
 
        public String getContent()
@@ -69,11 +132,15 @@
                StringBuilder result = new StringBuilder();
                for (Control child : container_.getChildren())
                {
-                       if (!(child instanceof Text))
+                       if (!(child instanceof Text || child instanceof 
Combo))
                                continue;
-
+                       String text = "";
+                       if (child instanceof Text)
+                               text = ((Text) child).getText();
+                       else
+                               text = ((Combo) child).getText();
                        result.append(StringUtils.multiples("\t", indent_) +
-                                       child.getData("name") + "=" + ((Text) 
child).getText() + "\n");
+                                       child.getData("name") + "=" + text + 
"\n");
                }
                return result.toString();
        }




Related Messages


Powered by MHonArc, Updated Fri Jul 09 13:40:08 2010