[jboss-svn-commits] JBL Code SVN: r12323 - labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jun 4 16:54:09 EDT 2007


Author: arhan
Date: 2007-06-04 16:54:09 -0400 (Mon, 04 Jun 2007)
New Revision: 12323

Modified:
   labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/DSLSentenceWidget.java
Log:
layout complete

Modified: labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/DSLSentenceWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/DSLSentenceWidget.java	2007-06-04 20:12:05 UTC (rev 12322)
+++ labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/DSLSentenceWidget.java	2007-06-04 20:54:09 UTC (rev 12323)
@@ -1,13 +1,20 @@
 package org.drools.eclipse.rulebuilder.ui;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 import org.drools.brms.client.modeldriven.brxml.DSLSentence;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 
+
 /**
  * This displays a widget to edit a DSL sentence.
  * 
@@ -18,57 +25,75 @@
 public class DSLSentenceWidget extends Widget {
 
     private final DSLSentence sentence;
-
+    
+    private List widgets = new ArrayList();
+    
     public DSLSentenceWidget(FormToolkit toolkit,
                              Composite parent,
                              DSLSentence sentence, RuleModeller modeller, int index) {
         super(parent,toolkit,modeller,index);
         
         this.sentence = sentence;
-        init();
-    }
-
-    private void init() {
+        
         GridLayout l = new GridLayout();
-        l.numColumns = sentence.sentence.length();//sentence.elements.length;
+        l.numColumns = sentence.sentence.length();
         l.verticalSpacing = 0;
         l.marginTop = 0;
         l.marginHeight = 2;
         l.marginBottom = 0;
         parent.setLayout( l );
+        
+        makeWidget(sentence.sentence);
+    }
 
-        toolkit.createLabel( parent,
-                             sentence.toString() );
-
-        final Text box = toolkit.createText( parent,
-                                             sentence.toString() );
-        box.setTabs( sentence.toString().length() );
-
-        box.addModifyListener( new ModifyListener() {
-            public void modifyText(ModifyEvent e) {
-                sentence.sentence = box.getText();
-                getModeller().setDirty( true );
+    private void makeWidget(String dslLine) {
+    	char[] chars = dslLine.toCharArray();
+        Text currentBox = null;
+        Label currentLabel = null;
+        for ( int i = 0; i < chars.length; i++ ) {
+            char c = chars[i];
+            if (c == '{') {
+                currentLabel = null;
+                currentBox = toolkit.createText(parent, ""); 
+                
+                currentBox.addModifyListener(new ModifyListener(){
+					public void modifyText(ModifyEvent e) {
+						updateSentence();
+					}
+                });
+                
+                widgets.add(currentBox);
+                
+            } else if (c == '}') {
+            	currentBox = null;
+            } else {
+                if (currentBox == null && currentLabel == null) {
+                    currentLabel = toolkit.createLabel(parent, "");
+                    widgets.add(currentLabel);
+                }
+                if (currentLabel != null) {
+                    currentLabel.setText( currentLabel.getText() + c );
+                } else if (currentBox != null) {
+                    currentBox.setText( currentBox.getText() + c );
+                }
             }
-        } );
-
-        /*for (int i = 0; i < sentence.length; i++) {
-         //final DSLSentenceFragment el = sentence.elements[i];
-         
-         if (!el.isEditableField) {
-         toolkit.createLabel(parent, sentence.toString());
-         } else {
-         final Text box = toolkit.createText(parent, el.value);
-         box.setTabs(el.value.length());
-
-         box.addModifyListener(new ModifyListener() {
-         public void modifyText(ModifyEvent e) {
-         el.value = box.getText();
-         }
-         });
-
-         }
-         }*/
+        }
+        
         toolkit.paintBordersFor( parent );
-    }
+	}
+    
+    protected void updateSentence() {
+        String newSentence = "";
+        for ( Iterator iter = widgets.iterator(); iter.hasNext(); ) {
+            Control wid = (Control) iter.next();
+            if (wid instanceof Label) {
+                newSentence = newSentence + ((Label) wid).getText();
+            } else if (wid instanceof Text) {
+                newSentence = newSentence + " {" + ((Text) wid).getText() + "} ";
+            }
+        }
+        this.sentence.sentence = newSentence.trim();
+    }    
+    
 
 }




More information about the jboss-svn-commits mailing list