[jboss-svn-commits] JBL Code SVN: r9560 - in labs/jbossrules/trunk: drools-compiler/src/test/java/org/drools/lang/dsl and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Feb 16 15:07:42 EST 2007
Author: tirelli
Date: 2007-02-16 15:07:42 -0500 (Fri, 16 Feb 2007)
New Revision: 9560
Added:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultDSLMapping.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/MappingError.java
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMapping.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingEntry.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultDSLMappingEntry.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultExpanderResolver.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultDSLMappingEntryTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultExpanderTest.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLContentProvider.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLLabelProvider.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLMappingSorter.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/IMappingListViewer.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/MappingEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/NLGrammarModel.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/DSLAdapter.java
Log:
Fixing IDE build issues
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMapping.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMapping.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMapping.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -18,19 +18,68 @@
import java.util.List;
+import org.drools.lang.dsl.DSLMappingEntry.Section;
/**
- * An interface that represents a DSL Mapping source
+ * An interface that represents a DSL Mapping
*
- * Implementations of this interface are capable of parsing
- * different DSL mapping file layouts.
- *
* @author etirelli
*/
public interface DSLMapping {
+
+ /**
+ * Returns the string identifier for this mapping
+ * @return
+ */
+ public String getIdentifier();
- public String getIdentifier();
+ /**
+ * Sets the identifier for this mapping
+ * @param identifier
+ */
+ public void setIdentifier( String identifier );
+
+ /**
+ * Returns a String description of this mapping
+ * @return
+ */
+ public String getDescription();
+
+ /**
+ * Sets the description for this mapping
+ * @param description
+ */
+ public void setDescription( String description );
+ /**
+ * Returns the list of entries in this mapping
+ * @return
+ */
public List getEntries();
+ /**
+ * Add one entry to the list of the entries
+ * @param entry
+ */
+ public void addEntry(DSLMappingEntry entry);
+
+ /**
+ * Adds all entries in the given list to this DSL Mapping
+ * @param entries
+ */
+ public void addEntries(List entries);
+
+ /**
+ * Removes the given entry from the list of entries
+ * @param entry
+ */
+ public void removeEntry(DSLMappingEntry entry);
+
+ /**
+ * Returns the list of mappings for the given section
+ * @param section
+ * @return
+ */
+ public List getEntries(Section section);
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingEntry.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingEntry.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -16,6 +16,7 @@
package org.drools.lang.dsl;
+import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@@ -30,6 +31,7 @@
public static final Section CONDITION = new ConditionSection();
public static final Section CONSEQUENCE = new ConsequenceSection();
public static final Section ANY = new AnySection();
+ public static final MetaData EMPTY_METADATA = new DefaultDSLEntryMetaData("");
/**
* Returns the section this mapping entry refers to
@@ -37,14 +39,14 @@
* @return
*/
public DSLMappingEntry.Section getSection();
-
+
/**
* Returns the meta data info about this mapping entry
*
* @return
*/
public DSLMappingEntry.MetaData getMetaData();
-
+
/**
* Returns the key of this mapping, i.e., the source
* that needs to be translated
@@ -52,7 +54,7 @@
* @return
*/
public String getMappingKey();
-
+
/**
* Returns the result of the translation
*
@@ -60,7 +62,6 @@
*/
public String getMappingValue();
-
/**
* Returns the compiled pattern based on the given MappingKey
* @return the keyPattern
@@ -78,17 +79,44 @@
* @return the variables
*/
public Map getVariables();
+
+ /**
+ * @param key the key to set
+ */
+ public void setMappingKey(String key);
+
+ /**
+ * @param section the section to set
+ */
+ public void setSection(Section section);
+
+ /**
+ * @param value the value to set
+ */
+ public void setMappingValue(String value);
+
+ /**
+ * @param metadata the metadata to set
+ */
+ public void setMetaData(MetaData metadata);
-
/**
+ * Returns a list of errors found in this mapping
+ * @return
+ */
+ public List getErrors();
+
+ /**
* An inner interface for DSL mapping sections
* @author etirelli
*
*/
- public static interface Section {
+ public static interface Section
+ extends
+ Comparable {
public String getSymbol();
}
-
+
/**
* An inner interface to represent any metadata
* associated with this entry. It is obviously
@@ -97,7 +125,9 @@
* @author etirelli
*
*/
- public static interface MetaData {
+ public static interface MetaData
+ extends
+ Comparable {
public String toString();
public String getMetaData();
@@ -119,7 +149,7 @@
public String getSymbol() {
return symbol;
}
-
+
public String toString() {
return symbol;
}
@@ -141,6 +171,10 @@
} else if ( !symbol.equals( other.getSymbol() ) ) return false;
return true;
}
+
+ public int compareTo(Object arg0) {
+ return this.toString().compareTo( arg0.toString() );
+ }
}
/**
@@ -181,6 +215,10 @@
} else if ( !symbol.equals( other.getSymbol() ) ) return false;
return true;
}
+
+ public int compareTo(Object arg0) {
+ return this.toString().compareTo( arg0.toString() );
+ }
}
/**
@@ -222,6 +260,10 @@
} else if ( !symbol.equals( other.getSymbol() ) ) return false;
return true;
}
+
+ public int compareTo(Object arg0) {
+ return this.toString().compareTo( arg0.toString() );
+ }
}
/**
@@ -263,6 +305,33 @@
} else if ( !symbol.equals( other.getSymbol() ) ) return false;
return true;
}
+
+ public int compareTo(Object arg0) {
+ return this.toString().compareTo( arg0.toString() );
+ }
}
+ public static class DefaultDSLEntryMetaData
+ implements
+ DSLMappingEntry.MetaData {
+
+ private String metadata;
+
+ public DefaultDSLEntryMetaData(String metadata) {
+ this.metadata = metadata;
+ }
+
+ public String getMetaData() {
+ return this.metadata;
+ }
+
+ public String toString() {
+ return (this.metadata == null) ? "" : this.metadata;
+ }
+
+ public int compareTo(Object arg0) {
+ return this.toString().compareTo( arg0.toString() );
+ }
+ }
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -19,25 +19,23 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
-import java.util.ArrayList;
+import java.io.Writer;
import java.util.Collections;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.drools.lang.dsl.DSLMappingEntry;
+import org.drools.lang.dsl.DSLMappingEntry.DefaultDSLEntryMetaData;
/**
- * A class that represents a DSL Mapping file
+ * A helper class that handles a DSL Mapping file
* @author etirelli
- *
*/
-public class DSLMappingFile
- implements
- DSLMapping {
+public class DSLMappingFile {
- // following pattern will be used to parse dsl mapping entries in the DSL file.
+ // the following pattern will be used to parse dsl mapping entries in the DSL file.
// It is capable of parsing entries that follows the pattern:
// [<section>][<metadata>]?<key>=<value>
private static final Pattern pattern = Pattern.compile( "((\\[[^\\[]*\\])\\s*(\\[([^\\[]*)\\])?)?\\s*([^=]*)=(.*)" );
@@ -46,45 +44,28 @@
private static final String CONSEQUENCE = "[then]";
//private static final String ANY = "[*]";
- private String dslFileName;
- private BufferedReader dslFileReader;
- private List entries;
+ private DSLMapping mapping;
private List errors;
- private boolean closed;
- private boolean parsed;
- public DSLMappingFile(String dslFileName,
- Reader dslFileReader) {
- this.dslFileName = dslFileName;
- this.dslFileReader = new BufferedReader( dslFileReader );
- this.closed = false;
- this.parsed = false;
- this.entries = new ArrayList();
- this.errors = new ArrayList();
+ public DSLMappingFile() {
+ this.mapping = new DefaultDSLMapping( );
+ this.errors = Collections.EMPTY_LIST;
}
- public String getIdentifier() {
- return this.dslFileName;
- }
-
/**
- * Returns the name of the DSL Mapping file associated
- * with this object
- *
+ * Returns the DSL mapping loaded from this file
* @return
*/
- public String getDslFileName() {
- return this.dslFileName;
+ public DSLMapping getMapping() {
+ return this.mapping;
}
/**
- * @inheritDoc
+ * Sets the
+ * @param mapping
*/
- public List getEntries() {
- if ( parsed && this.errors.isEmpty() ) {
- return Collections.unmodifiableList( this.entries );
- }
- return null;
+ public void setMapping( DSLMapping mapping ) {
+ this.mapping = mapping;
}
/**
@@ -96,35 +77,19 @@
}
/**
- * Closes the file stream
- * @throws IOException
- */
- public void close() throws IOException {
- this.closed = true;
- this.dslFileReader.close();
- }
-
- /**
- * Returns true if this file is already closed. False otherwise.
- *
- * @return
- */
- public boolean isClosed() {
- return this.closed;
- }
-
- /**
* Parses the file. Throws IOException in case there is any problem
* reading the file;
*
* @return true in case no error was found parsing the file. false
* otherwise. Use getErrors() to check for the actual errors.
*/
- public boolean parseFile() throws IOException {
+ public boolean parseAndLoad( Reader dsl ) throws IOException {
String line = null;
int linecounter = 0;
- this.parsed = true;
- while ( (line = this.dslFileReader.readLine()) != null ) {
+ BufferedReader dslFileReader = new BufferedReader( dsl );
+ this.mapping = new DefaultDSLMapping();
+ this.errors = new LinkedList();
+ while ( (line = dslFileReader.readLine()) != null ) {
linecounter++;
Matcher mat = pattern.matcher( line );
if ( mat.matches() ) {
@@ -140,16 +105,16 @@
section = DSLMappingEntry.CONDITION;
} else if ( CONSEQUENCE.equals( sectionStr ) ) {
section = DSLMappingEntry.CONSEQUENCE;
- }
+ }
- DSLMappingEntry.MetaData metadata = new StandardDSLEntryMetaData( metadataStr );
+ DSLMappingEntry.MetaData metadata = new DefaultDSLEntryMetaData( metadataStr );
DSLMappingEntry entry = new DefaultDSLMappingEntry( section,
metadata,
key,
value );
- this.entries.add( entry );
+ this.mapping.addEntry( entry );
} else if ( !line.trim().startsWith( "#" ) ) { // it is not a comment
String error = "Error parsing mapping entry: " + line;
DSLMappingParseException exception = new DSLMappingParseException( error,
@@ -160,42 +125,43 @@
return this.errors.isEmpty();
}
+ /**
+ * Saves current mapping into a DSL mapping file
+ * @param out
+ * @throws IOException
+ */
+ public void saveMapping( Writer out ) throws IOException {
+ for ( Iterator it = mapping.getEntries().iterator(); it.hasNext(); ) {
+ out.write( it.next().toString() );
+ out.write( "\n" );
+ }
+ }
+
+ /**
+ * Saves the given mapping into a DSL mapping file
+ *
+ * @param out
+ * @param mapping
+ * @throws IOException
+ */
+ public static void saveMapping( Writer out, DSLMapping mapping ) throws IOException {
+ for ( Iterator it = mapping.getEntries().iterator(); it.hasNext(); ) {
+ out.write( it.next().toString() );
+ out.write( "\n" );
+ }
+ }
+
+ /**
+ * Method to return the current mapping as a String object
+ * @return
+ */
public String dumpFile() {
StringBuffer buf = new StringBuffer();
- for ( Iterator it = this.entries.iterator(); it.hasNext(); ) {
+ for ( Iterator it = this.mapping.getEntries().iterator(); it.hasNext(); ) {
buf.append( it.next() );
buf.append( "\n" );
}
return buf.toString();
}
- public String dumpPatternFile() {
- StringBuffer buf = new StringBuffer();
- for ( Iterator it = this.entries.iterator(); it.hasNext(); ) {
- buf.append( ((DefaultDSLMappingEntry)it.next()).toPatternString() );
- buf.append( "\n" );
- }
- return buf.toString();
- }
-
- public static class StandardDSLEntryMetaData
- implements
- DSLMappingEntry.MetaData {
-
- private String metadata;
-
- public StandardDSLEntryMetaData(String metadata) {
- this.metadata = metadata;
- }
-
- public String getMetaData() {
- return this.metadata;
- }
-
- public String toString() {
- return (this.metadata == null) ? "" : this.metadata;
- }
-
- }
-
}
Added: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultDSLMapping.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultDSLMapping.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultDSLMapping.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2006 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.lang.dsl;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.drools.lang.dsl.DSLMappingEntry.Section;
+
+/**
+ * This is a default implementation of the DSL Mapping interface
+ * capable of storing a list of DSLMappingEntries and managing it.
+ *
+ * @author etirelli
+ */
+public class DefaultDSLMapping
+ implements
+ DSLMapping {
+
+ private String identifier;
+ private String description;
+ private List entries;
+
+ public DefaultDSLMapping() {
+ this( "" );
+ }
+
+ public DefaultDSLMapping(String identifier) {
+ this.identifier = identifier;
+ this.entries = new LinkedList();
+ }
+
+ /**
+ * Add one entry to the list of the entries
+ * @param entry
+ */
+ public void addEntry( DSLMappingEntry entry ) {
+ this.entries.add( entry );
+ }
+
+ /**
+ * Adds all entries in the given list to this DSL Mapping
+ * @param entries
+ */
+ public void addEntries( List entries ) {
+ this.entries.addAll( entries );
+ }
+
+ /**
+ * Returns an unmodifiable list of entries
+ */
+ public List getEntries() {
+ return Collections.unmodifiableList( this.entries );
+ }
+
+ /**
+ * Returns the list of mappings for the given section
+ * @param section
+ * @return
+ */
+ public List getEntries( Section section ) {
+ List list = new LinkedList();
+ for( Iterator it = this.entries.iterator(); it.hasNext(); ) {
+ DSLMappingEntry entry = (DSLMappingEntry) it.next();
+ if( entry.getSection().equals( section ) ) {
+ list.add( entry );
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Returns the identifier for this mapping
+ */
+ public String getIdentifier() {
+ return this.identifier;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public void removeEntry(DSLMappingEntry entry) {
+ this.entries.remove( entry );
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public String getDescription() {
+ return this.description;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public void setIdentifier(String identifier) {
+ this.identifier = identifier;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultDSLMapping.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ id author date revision
Name: svn:eol-style
+ native
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultDSLMappingEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultDSLMappingEntry.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultDSLMappingEntry.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -19,6 +19,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -32,16 +33,16 @@
implements
DSLMappingEntry {
- private Section section;
- private MetaData metadata;
- private String key;
- private String value;
-
- private Map variables = Collections.EMPTY_MAP;
-
- private Pattern keyPattern;
- private String valuePattern;
-
+ private Section section;
+ private MetaData metadata;
+ private String key;
+ private String value;
+
+ private Map variables = Collections.EMPTY_MAP;
+
+ private Pattern keyPattern;
+ private String valuePattern;
+
// following pattern is used to extract all variables names and positions from a mapping.
// Example: for the following String:
//
@@ -50,9 +51,14 @@
// it will return variables:
// This, pattern, easy, say
//
- private static final Pattern varFinder = Pattern.compile( "(^|[^\\\\])\\{([(\\\\\\{)|[^\\{]]*?)\\}", Pattern.MULTILINE | Pattern.DOTALL );
+ static final Pattern varFinder = Pattern.compile( "(^|[^\\\\])\\{([(\\\\\\{)|[^\\{]]*?)\\}",
+ Pattern.MULTILINE | Pattern.DOTALL );
public DefaultDSLMappingEntry() {
+ this( DSLMappingEntry.ANY,
+ DSLMappingEntry.EMPTY_METADATA,
+ null,
+ null );
}
public DefaultDSLMappingEntry(Section section,
@@ -98,30 +104,40 @@
*/
public void setMappingKey(String key) {
this.key = key;
-
- // retrieving variables list and creating key pattern
- Matcher m = varFinder.matcher( key.replaceAll("\\$", "\\\\\\$") );
- StringBuffer buf = new StringBuffer();
- int counter = 1;
- while( m.find() ) {
- if( this.variables == Collections.EMPTY_MAP ) {
- this.variables = new HashMap(2);
+
+ if( key != null ) {
+ // retrieving variables list and creating key pattern
+ Matcher m = varFinder.matcher( key.replaceAll( "\\$",
+ "\\\\\\$" ) );
+ StringBuffer buf = new StringBuffer();
+ int counter = 1;
+ while ( m.find() ) {
+ if ( this.variables == Collections.EMPTY_MAP ) {
+ this.variables = new HashMap( 2 );
+ }
+ this.variables.put( m.group( 2 ),
+ new Integer( counter++ ) );
+ m.appendReplacement( buf,
+ m.group( 1 ) + "(.*?)" );
}
- this.variables.put( m.group( 2 ), new Integer( counter++ ) );
- m.appendReplacement( buf, m.group( 1 )+"(.*?)" );
+ m.appendTail( buf );
+ if ( buf.toString().endsWith( "(.*?)" ) ) {
+ buf.append( "$" );
+ }
+
+ // setting the key pattern and making it space insensitive
+ String pat = buf.toString().replaceAll( "\\s+",
+ "\\\\s*" );
+ if ( pat.trim().startsWith( "-" ) && (!pat.trim().startsWith( "-\\s*" )) ) {
+ pat = pat.substring( 0,
+ pat.indexOf( '-' ) + 1 ) + "\\s*" + pat.substring( pat.indexOf( '-' ) + 1 );
+ }
+ this.keyPattern = Pattern.compile( pat,
+ Pattern.DOTALL | Pattern.MULTILINE );
+
+ } else {
+ this.keyPattern = null;
}
- m.appendTail( buf );
- if( buf.toString().endsWith( "(.*?)" ) ) {
- buf.append( "$" );
- }
-
- // setting the key pattern and making it space insensitive
- String pat = buf.toString().replaceAll( "\\s+", "\\\\s*" );
- if( pat.trim().startsWith( "-" ) && (! pat.trim().startsWith( "-\\s*" ) )) {
- pat = pat.substring( 0, pat.indexOf( '-' )+1 ) + "\\s*" + pat.substring( pat.indexOf( '-' )+1 );
- }
- this.keyPattern = Pattern.compile( pat, Pattern.DOTALL | Pattern.MULTILINE );
-
// update value mapping
this.setMappingValue( this.value );
}
@@ -139,14 +155,17 @@
public void setMappingValue(String value) {
this.valuePattern = value;
this.value = value;
- if( value != null ) {
- this.valuePattern = this.valuePattern.replaceAll( "\\\\n", "\n" ).replaceAll( "\\$", "\\\\\\$" );
- for( Iterator it = this.variables.entrySet().iterator(); it.hasNext(); ) {
+ if ( value != null ) {
+ this.valuePattern = this.valuePattern.replaceAll( "\\\\n",
+ "\n" ).replaceAll( "\\$",
+ "\\\\\\$" );
+ for ( Iterator it = this.variables.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String var = (String) entry.getKey();
int pos = ((Integer) entry.getValue()).intValue();
-
- this.valuePattern = valuePattern.replaceAll( "\\{"+var+"\\}", "\\$"+pos );
+
+ this.valuePattern = valuePattern.replaceAll( "\\{" + var + "\\}",
+ "\\$" + pos );
}
}
}
@@ -178,13 +197,13 @@
public Map getVariables() {
return variables;
}
-
+
public String toPatternString() {
- return this.section+"["+this.metadata+"]"+this.keyPattern.pattern()+"="+this.valuePattern;
+ return this.section + "[" + this.metadata + "]" + this.keyPattern.pattern() + "=" + this.valuePattern;
}
-
+
public String toString() {
- return this.section+"["+this.metadata+"]"+this.key+"="+this.value;
+ return this.section + "[" + this.metadata + "]" + this.key + "=" + this.value;
}
/* (non-Javadoc)
@@ -223,4 +242,9 @@
return true;
}
+ public List getErrors() {
+ // TODO Need to implement validation here
+ return Collections.EMPTY_LIST;
+ }
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultExpanderResolver.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultExpanderResolver.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultExpanderResolver.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.drools.RuntimeDroolsException;
import org.drools.lang.Expander;
import org.drools.lang.ExpanderResolver;
@@ -55,13 +56,15 @@
* This is the constructor most people should use.
*/
public DefaultExpanderResolver(final Reader reader) throws IOException {
- DSLMappingFile file = new DSLMappingFile("default", reader);
- file.parseFile();
- file.close();
- final Expander expander = new DefaultExpander();
- expander.addDSLMapping( file );
- this.expanders.put( "*",
- expander );
+ DSLMappingFile file = new DSLMappingFile();
+ if( file.parseAndLoad( reader ) ) {
+ final Expander expander = new DefaultExpander();
+ expander.addDSLMapping( file.getMapping() );
+ this.expanders.put( "*",
+ expander );
+ } else {
+ throw new RuntimeDroolsException("Error parsing and loading DSL file."+file.getErrors());
+ }
}
/**
Added: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/MappingError.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/MappingError.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/MappingError.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.lang.dsl;
+
+import org.drools.compiler.DroolsError;
+
+/**
+ * MappingError
+ * A class to represent errors found in a DSL mapping
+ *
+ * @author <a href="mailto:tirelli at post.com">Edson Tirelli</a>
+ *
+ * Created: 11/04/2006
+ */
+public class MappingError extends DroolsError {
+ public static final int TEMPLATE_UNKNOWN = 0;
+ public static final int TEMPLATE_NATURAL = 1;
+ public static final int TEMPLATE_TARGET = 2;
+
+ public static final int ERROR_UNUSED_TOKEN = 21;
+ public static final int ERROR_UNDECLARED_TOKEN = 22;
+ public static final int ERROR_INVALID_TOKEN = 23;
+ public static final int ERROR_UNMATCHED_BRACES = 24;
+
+ private final int errorCode;
+ private final int template;
+ private final int offset;
+ private final String token;
+ private String templateText;
+
+ public MappingError(final int errorCode,
+ final int template,
+ final int offset,
+ final String token,
+ final String templateText) {
+ this.errorCode = errorCode;
+ this.template = template;
+ this.token = token;
+ this.offset = offset;
+ this.templateText = templateText;
+ }
+
+ /**
+ * Returns this error code
+ * @return
+ */
+ public int getErrorCode() {
+ return this.errorCode;
+ }
+
+ /**
+ * @return the offset
+ */
+ public int getOffset() {
+ return this.offset;
+ }
+
+ /**
+ * @return the template
+ */
+ public int getTemplate() {
+ return this.template;
+ }
+
+ /**
+ * @return the original content.
+ */
+ public String getTemplateText() {
+ return this.templateText;
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @see org.drools.compiler.DroolsError#getMessage()
+ */
+ public String getMessage() {
+ switch ( this.errorCode ) {
+ case ERROR_UNUSED_TOKEN :
+ return "Warning, the token " + this.token + " not used in the mapping.";
+ case ERROR_UNDECLARED_TOKEN :
+ return "Warning, the token " + this.token + " not found in the expression. (May not be a problem).";
+ case ERROR_INVALID_TOKEN :
+ return "Invalid token declaration at offset " + this.offset + ": " + this.token;
+ case ERROR_UNMATCHED_BRACES :
+ return "Unexpected } found at offset " + this.offset;
+ default :
+ return "Unkown error at offset: " + this.offset;
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/MappingError.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ id author date revision
Name: svn:eol-style
+ native
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -11,41 +11,25 @@
private final String filename = "test_metainfo.dsl";
protected void setUp() throws Exception {
- Reader reader = new InputStreamReader( this.getClass().getResourceAsStream( filename ) );
- file = new DSLMappingFile( filename,
- reader );
-
super.setUp();
}
protected void tearDown() throws Exception {
- file.close();
super.tearDown();
}
- public void testGetDslFileName() {
- assertEquals( filename, file.getDslFileName() );
- }
-
- public void testClose() {
- try {
- assertFalse( file.isClosed() );
- file.close();
- assertTrue( file.isClosed() );
- } catch ( IOException e ) {
- e.printStackTrace();
- fail( "Should not raise exception ");
- }
- }
-
public void testParseFile() {
try {
- boolean parsingResult = file.parseFile();
+ Reader reader = new InputStreamReader( this.getClass().getResourceAsStream( filename ) );
+ file = new DSLMappingFile( );
+
+ boolean parsingResult = file.parseAndLoad( reader );
+ reader.close();
assertTrue( file.getErrors().toString(), parsingResult );
assertTrue( file.getErrors().isEmpty() );
- assertEquals( 31, file.getEntries().size() );
+ assertEquals( 31, file.getMapping().getEntries().size() );
} catch ( IOException e ) {
e.printStackTrace();
fail( "Should not raise exception ");
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultDSLMappingEntryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultDSLMappingEntryTest.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultDSLMappingEntryTest.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -4,7 +4,7 @@
public class DefaultDSLMappingEntryTest extends TestCase {
- private DefaultDSLMappingEntry entry;
+ private DSLMappingEntry entry;
protected void setUp() throws Exception {
super.setUp();
@@ -28,7 +28,7 @@
String expectedKeyP = "The\\s*Customer\\s*name\\s*is\\s*(.*?)\\s*and\\s*surname\\s*is\\s*(.*?)\\s*and\\s*it\\s*has\\s*US\\$\\s*50,00\\s*on\\s*his\\s*(.*?)$";
String expectedValP = "Customer( name == \"$1\", surname == \"$2\", money > \\$money )";
- DefaultDSLMappingEntry entry = new DefaultDSLMappingEntry( DSLMappingEntry.CONDITION,
+ DSLMappingEntry entry = new DefaultDSLMappingEntry( DSLMappingEntry.CONDITION,
null,
inputKey,
inputValue );
@@ -51,7 +51,7 @@
String expectedKeyP = "-\\s*name\\s*is\\s*(.*?)$";
String expectedValP = "name == \"$1\"";
- DefaultDSLMappingEntry entry = new DefaultDSLMappingEntry( DSLMappingEntry.CONDITION,
+ DSLMappingEntry entry = new DefaultDSLMappingEntry( DSLMappingEntry.CONDITION,
null,
inputKey,
inputValue );
@@ -74,7 +74,7 @@
String expectedKeyP = "-\\s*name\\s*is\\s*(.*?)$";
String expectedValP = "name == \"$1\"";
- DefaultDSLMappingEntry entry = new DefaultDSLMappingEntry( DSLMappingEntry.CONDITION,
+ DSLMappingEntry entry = new DefaultDSLMappingEntry( DSLMappingEntry.CONDITION,
null,
inputKey,
inputValue );
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultExpanderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultExpanderTest.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultExpanderTest.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -1,6 +1,5 @@
package org.drools.lang.dsl;
-import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -13,9 +12,9 @@
protected void setUp() throws Exception {
String filename = "test_metainfo.dsl";
Reader reader = new InputStreamReader( this.getClass().getResourceAsStream( filename ) );
- file = new DSLMappingFile( filename,
- reader );
- file.parseFile();
+ file = new DSLMappingFile();
+ file.parseAndLoad( reader );
+ reader.close();
expander = new DefaultExpander();
@@ -23,43 +22,17 @@
}
protected void tearDown() throws Exception {
- file.close();
super.tearDown();
}
- public void xxxtestAddDSLMapping() {
- expander.addDSLMapping( file );
+ public void testAddDSLMapping() {
+ expander.addDSLMapping( file.getMapping() );
// should not raise any exception
}
- public void xxxtestExpand() {
- expander.addDSLMapping( file );
- Reader rules = new InputStreamReader( this.getClass().getResourceAsStream( ".drl" ) );
-
- try {
- String out = expander.expand( rules );
- System.out.println( out );
- } catch ( IOException e ) {
- e.printStackTrace();
- fail( "Should not raise exceptions" );
- }
- }
-
public void testRegexp() throws Exception {
-// String input = "regra \"average \\\"bob\\\"\" salience -10";
-//
-// Pattern pat = Pattern.compile( "((\"[(\\\")|[^\"]]*\"\\s*)|([^\\s]+\\s*))" );
-// Matcher mat = pat.matcher( input );
-//
-// while( mat.find()) {
-// System.out.println("Found: ["+mat.group().trim()+"]");
-// }
-
- expander.addDSLMapping( file );
+ expander.addDSLMapping( file.getMapping() );
Reader rules = new InputStreamReader( this.getClass().getResourceAsStream( "test_expansion.drl" ) );
String result = expander.expand( rules );
- System.out.println( result );
-
-
}
}
Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLContentProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLContentProvider.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLContentProvider.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -1,6 +1,6 @@
package org.drools.ide.dsl.editor;
-import org.drools.lang.dsl.template.NLMappingItem;
+import org.drools.lang.dsl.DSLMappingEntry;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
@@ -35,22 +35,22 @@
}
- public void addMapping(NLMappingItem item) {
+ public void addMapping(DSLMappingEntry item) {
viewer.add( item );
}
- public void removeMapping(NLMappingItem item) {
+ public void removeMapping(DSLMappingEntry item) {
viewer.remove( item );
}
- public void updateMapping(NLMappingItem item) {
+ public void updateMapping(DSLMappingEntry item) {
viewer.update( item, null );
}
public Object[] getElements(Object inputElement) {
- return model.getMappings().toArray();
+ return model.getEntries().toArray();
}
}
Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLEditor.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLEditor.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -11,8 +11,10 @@
import org.drools.ide.DroolsIDEPlugin;
import org.drools.ide.builder.IDroolsModelMarker;
-import org.drools.lang.dsl.template.MappingError;
-import org.drools.lang.dsl.template.NLMappingItem;
+import org.drools.lang.dsl.DSLMappingEntry;
+import org.drools.lang.dsl.DSLMappingFile;
+import org.drools.lang.dsl.DefaultDSLMappingEntry;
+import org.drools.lang.dsl.MappingError;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
@@ -50,92 +52,104 @@
*/
public class DSLEditor extends EditorPart {
- private Table table;
- private TableViewer tableViewer;
- private NLGrammarModel model; //this is the model that does all the work (from drools-compiler)
- private boolean dirty = false; //editing or deleting will make it dirty
- private Text exprText; //for language expression
- private Text mappingText; //for target rule expression
- private Text descriptionText; //just a comment field
- private Text objText; // for the object name
- private Combo sortCombo; // for the sort field
-
+ private Table table;
+ private TableViewer tableViewer;
+ private NLGrammarModel model; //this is the model that does all the work (from drools-compiler)
+ private boolean dirty = false; //editing or deleting will make it dirty
+ private Text exprText; //for language expression
+ private Text mappingText; //for target rule expression
+ private Text descriptionText; //just a comment field
+ private Text objText; // for the object name
+ private Combo sortCombo; // for the sort field
+
public void doSave(IProgressMonitor monitor) {
-
+
FileEditorInput input = (FileEditorInput) getEditorInput();
File outputFile = input.getFile().getLocation().toFile();
saveFile( monitor,
- outputFile, input );
-
+ outputFile,
+ input );
+
}
private void saveFile(IProgressMonitor monitor,
- File outputFile, FileEditorInput input) {
+ File outputFile,
+ FileEditorInput input) {
try {
- validate( input );
-
- FileWriter writer = new FileWriter(outputFile);
- model.save( writer );
-
+ validate( input );
+
+ FileWriter writer = new FileWriter( outputFile );
+ DSLMappingFile.saveMapping( writer,
+ model );
+
makeClean();
writer.close();
- input.getFile().getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ input.getFile().getProject().refreshLocal( IResource.DEPTH_INFINITE,
+ monitor );
} catch ( IOException e ) {
- throw new IllegalStateException("Unable to save DSL configuration file. (IOException: " + e.getMessage() + ")");
+ throw new IllegalStateException( "Unable to save DSL configuration file. (IOException: " + e.getMessage() + ")" );
} catch ( CoreException e ) {
- throw new IllegalStateException("Unable to resync workbench after DSL save. (CoreException: " + e.getMessage() + ")");
+ throw new IllegalStateException( "Unable to resync workbench after DSL save. (CoreException: " + e.getMessage() + ")" );
}
}
private void validate(FileEditorInput input) {
removeProblemsFor( input.getFile() );
List errs = new ArrayList();
- for ( Iterator iter = model.getMappings().iterator(); iter.hasNext(); ) {
- NLMappingItem item = (NLMappingItem) iter.next();
- errs.addAll( model.validateMapping( item ) );
+ for ( Iterator iter = model.getEntries().iterator(); iter.hasNext(); ) {
+ DSLMappingEntry item = (DSLMappingEntry) iter.next();
+ errs.addAll( item.getErrors() );
}
- if (errs.size() > 0) {
+ if ( errs.size() > 0 ) {
for ( Iterator iter = errs.iterator(); iter.hasNext(); ) {
MappingError mapEr = (MappingError) iter.next();
- createMarker( input.getFile(), mapEr.getMessage() + " From [" + mapEr.getTemplateText() + "]", -1 );
+ createMarker( input.getFile(),
+ mapEr.getMessage() + " From [" + mapEr.getTemplateText() + "]",
+ -1 );
}
}
}
- private void createMarker(final IResource res, final String message, final int lineNumber) {
+ private void createMarker(final IResource res,
+ final String message,
+ final int lineNumber) {
try {
- IWorkspaceRunnable r= new IWorkspaceRunnable() {
+ IWorkspaceRunnable r = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
- IMarker marker = res
- .createMarker(IDroolsModelMarker.DROOLS_MODEL_PROBLEM_MARKER);
- marker.setAttribute(IMarker.MESSAGE, message);
- marker.setAttribute(IMarker.SEVERITY,
- IMarker.SEVERITY_WARNING);
- marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
+ IMarker marker = res.createMarker( IDroolsModelMarker.DROOLS_MODEL_PROBLEM_MARKER );
+ marker.setAttribute( IMarker.MESSAGE,
+ message );
+ marker.setAttribute( IMarker.SEVERITY,
+ IMarker.SEVERITY_WARNING );
+ marker.setAttribute( IMarker.LINE_NUMBER,
+ lineNumber );
}
};
- res.getWorkspace().run(r, null, IWorkspace.AVOID_UPDATE, null);
- } catch (CoreException e) {
- DroolsIDEPlugin.log(e);
+ res.getWorkspace().run( r,
+ null,
+ IWorkspace.AVOID_UPDATE,
+ null );
+ } catch ( CoreException e ) {
+ DroolsIDEPlugin.log( e );
}
}
-
+
private void removeProblemsFor(IResource resource) {
try {
- if (resource != null && resource.exists()) {
- resource.deleteMarkers(
- IDroolsModelMarker.DROOLS_MODEL_PROBLEM_MARKER, false,
- IResource.DEPTH_INFINITE);
+ if ( resource != null && resource.exists() ) {
+ resource.deleteMarkers( IDroolsModelMarker.DROOLS_MODEL_PROBLEM_MARKER,
+ false,
+ IResource.DEPTH_INFINITE );
}
- } catch (CoreException e) {
- DroolsIDEPlugin.log(e);
+ } catch ( CoreException e ) {
+ DroolsIDEPlugin.log( e );
}
- }
-
+ }
+
void makeClean() {
this.dirty = false;
firePropertyChange( PROP_DIRTY );
-
+
}
public void doSaveAs() {
@@ -144,34 +158,36 @@
public void init(IEditorSite site,
IEditorInput editorInput) throws PartInitException {
- FileEditorInput input = (FileEditorInput)editorInput;
- setSite(site);
- setInput(editorInput);
+ FileEditorInput input = (FileEditorInput) editorInput;
+ setSite( site );
+ setInput( editorInput );
setVisibleName( input );
-
+
try {
InputStream stream = input.getFile().getContents();
model = new NLGrammarModel();
- model.load( new InputStreamReader(stream) );
+ DSLMappingFile file = new DSLMappingFile();
+ file.parseAndLoad( new InputStreamReader( stream ) );
+ model.addEntries( file.getMapping().getEntries() );
stream.close();
-
+
} catch ( CoreException e ) {
- throw new IllegalStateException("Unable to load DSL configuration file. (CoreException: " + e.getMessage() + ")");
+ throw new IllegalStateException( "Unable to load DSL configuration file. (CoreException: " + e.getMessage() + ")" );
} catch ( IOException e ) {
- throw new IllegalStateException("Unabel to close stream fo DSL config file. (IOException: " + e.getMessage() + ")");
+ throw new IllegalStateException( "Unabel to close stream fo DSL config file. (IOException: " + e.getMessage() + ")" );
}
-
+
}
private void setVisibleName(FileEditorInput input) {
setPartName( input.getFile().getName() );
- setContentDescription( "Editing Domain specific language: [" + input.getFile().getFullPath().toString() + "]");
+ setContentDescription( "Editing Domain specific language: [" + input.getFile().getFullPath().toString() + "]" );
}
public boolean isDirty() {
return dirty;
}
-
+
/**
* Sets the dirty flag, and notifies the workbench.
*/
@@ -185,87 +201,89 @@
*
*/
public void sortModel() {
- if (sortCombo.getSelectionIndex() == DSLMappingSorter.EXPRESSION) {
- tableViewer.setSorter(new DSLMappingSorter(DSLMappingSorter.EXPRESSION));
- } else if (sortCombo.getSelectionIndex() == DSLMappingSorter.OBJECT) {
- tableViewer.setSorter(new DSLMappingSorter(DSLMappingSorter.OBJECT));
- } else if (sortCombo.getSelectionIndex() == DSLMappingSorter.SCOPE) {
- tableViewer.setSorter(new DSLMappingSorter(DSLMappingSorter.SCOPE));
- } else if (sortCombo.getSelectionIndex() == DSLMappingSorter.MAPPING) {
- tableViewer.setSorter(new DSLMappingSorter(DSLMappingSorter.MAPPING));
- }
+ if ( sortCombo.getSelectionIndex() == DSLMappingSorter.EXPRESSION ) {
+ tableViewer.setSorter( new DSLMappingSorter( DSLMappingSorter.EXPRESSION ) );
+ } else if ( sortCombo.getSelectionIndex() == DSLMappingSorter.OBJECT ) {
+ tableViewer.setSorter( new DSLMappingSorter( DSLMappingSorter.OBJECT ) );
+ } else if ( sortCombo.getSelectionIndex() == DSLMappingSorter.SCOPE ) {
+ tableViewer.setSorter( new DSLMappingSorter( DSLMappingSorter.SCOPE ) );
+ } else if ( sortCombo.getSelectionIndex() == DSLMappingSorter.MAPPING ) {
+ tableViewer.setSorter( new DSLMappingSorter( DSLMappingSorter.MAPPING ) );
+ }
}
-
+
public boolean isSaveAsAllowed() {
// TODO implement SaveAs
return false;
}
public void createPartControl(Composite parent) {
-
- GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_BOTH);
- parent.setLayoutData (gridData);
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_BOTH );
+ parent.setLayoutData( gridData );
+
// Set numColumns to 3 in the overall grid
- GridLayout layout = new GridLayout(3, false);
+ GridLayout layout = new GridLayout( 3,
+ false );
layout.marginWidth = 4;
- parent.setLayout (layout);
-
+ parent.setLayout( layout );
+
//create the overall desc field (comments).
createDescriptionField( parent );
-
+
// create the table
createTable( parent );
-
+
// Create and setup the TableViewer
- createTableViewer();
-
+ createTableViewer();
+
//set up the table "binding" with the model
- tableViewer.setContentProvider(new DSLContentProvider(tableViewer, model));
- tableViewer.setLabelProvider(new DSLLabelProvider());
+ tableViewer.setContentProvider( new DSLContentProvider( tableViewer,
+ model ) );
+ tableViewer.setLabelProvider( new DSLLabelProvider() );
refreshModel();
-
+
//setup the fields below the table
- createExpressionViewField( parent );
+ createExpressionViewField( parent );
createEditButton( parent );
createMappingViewField( parent );
createDeleteButton( parent );
- createObjectViewField(parent);
+ createObjectViewField( parent );
createAddButton( parent );
- createSortField(parent);
- createSortButton(parent);
- createCopyButton(parent);
-
+ createSortField( parent );
+ createSortButton( parent );
+ createCopyButton( parent );
+
//listeners on the table...
createTableListeners();
-
-
+
}
/**
* Setup table listeners for GUI events.
*/
private void createTableListeners() {
-
+
//setup views into current selected
table.addSelectionListener( new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
populate();
}
- public void widgetDefaultSelected(SelectionEvent e) {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
populate();
}
private void populate() {
- NLMappingItem selected = getCurrentSelected();
- exprText.setText( selected.getNaturalTemplate() );
- mappingText.setText( selected.getTargetTemplate() );
- objText.setText(selected.getObjectName());
+ DSLMappingEntry selected = getCurrentSelected();
+ exprText.setText( selected.getMappingKey() );
+ mappingText.setText( selected.getMappingValue() );
+ objText.setText( selected.getMetaData().getMetaData() );
}
-
- });
-
+
+ } );
+
//double click support
table.addMouseListener( new MouseListener() {
@@ -273,269 +291,285 @@
showEditPopup();
}
- public void mouseDown(MouseEvent e) {}
+ public void mouseDown(MouseEvent e) {
+ }
- public void mouseUp(MouseEvent e) {}
-
- });
-
+ public void mouseUp(MouseEvent e) {
+ }
+
+ } );
+
}
private void createDescriptionField(Composite parent) {
- Label descLbl = new Label(parent, SWT.NONE);
+ Label descLbl = new Label( parent,
+ SWT.NONE );
descLbl.setText( "Description:" );
- GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING);
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
gridData.widthHint = 80;
- descLbl.setLayoutData(gridData);
-
- descriptionText = new Text(parent, SWT.BORDER);
- descriptionText.setLayoutData(new GridData (GridData.FILL_HORIZONTAL));
- descriptionText.setText( "" + model.getDescription() ); //no nulls !
+ descLbl.setLayoutData( gridData );
+
+ descriptionText = new Text( parent,
+ SWT.BORDER );
+ descriptionText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ descriptionText.setText( "" + model.getDescription() ); //no nulls !
descriptionText.addModifyListener( new ModifyListener() {
public void modifyText(ModifyEvent e) {
String text = descriptionText.getText();
- if (!text.equals( model.getDescription() )) {
+ if ( !text.equals( model.getDescription() ) ) {
model.setDescription( text );
makeDirty();
- }
+ }
}
-
- });
+
+ } );
}
-
- private void createMappingViewField(Composite parent) {
- Label mapping = new Label(parent, SWT.NONE);
+
+ private void createMappingViewField(Composite parent) {
+ Label mapping = new Label( parent,
+ SWT.NONE );
mapping.setText( "Mapping:" );
- GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING);
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
gridData.widthHint = 80;
- mapping.setLayoutData(gridData);
-
- mappingText = new Text(parent, SWT.BORDER);
+ mapping.setLayoutData( gridData );
+
+ mappingText = new Text( parent,
+ SWT.BORDER );
mappingText.setEditable( false );
- mappingText.setLayoutData(new GridData (GridData.FILL_HORIZONTAL));
- }
-
+ mappingText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ }
+
private void createExpressionViewField(Composite parent) {
- Label expr = new Label(parent, SWT.NONE);
+ Label expr = new Label( parent,
+ SWT.NONE );
expr.setText( "Expression:" );
- GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING);
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
gridData.widthHint = 80;
- expr.setLayoutData(gridData);
-
- exprText = new Text(parent, SWT.BORDER);
+ expr.setLayoutData( gridData );
+
+ exprText = new Text( parent,
+ SWT.BORDER );
exprText.setEditable( false );
- gridData = new GridData (GridData.FILL_HORIZONTAL);
-
- exprText.setLayoutData(gridData);
+ gridData = new GridData( GridData.FILL_HORIZONTAL );
+ exprText.setLayoutData( gridData );
+
}
private void createObjectViewField(Composite parent) {
- Label obj = new Label(parent, SWT.NONE);
+ Label obj = new Label( parent,
+ SWT.NONE );
obj.setText( "Object:" );
- GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING);
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
gridData.widthHint = 80;
- obj.setLayoutData(gridData);
-
- objText = new Text(parent, SWT.BORDER);
+ obj.setLayoutData( gridData );
+
+ objText = new Text( parent,
+ SWT.BORDER );
objText.setEditable( false );
- gridData = new GridData (GridData.FILL_HORIZONTAL);
-
- objText.setLayoutData(gridData);
+ gridData = new GridData( GridData.FILL_HORIZONTAL );
+ objText.setLayoutData( gridData );
+
}
-
+
private void createSortField(Composite parent) {
- Label sort = new Label(parent, SWT.NONE);
+ Label sort = new Label( parent,
+ SWT.NONE );
sort.setText( "Sort by:" );
- GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING);
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
gridData.widthHint = 80;
- sort.setLayoutData(gridData);
-
- sortCombo = new Combo(parent, SWT.READ_ONLY);
- sortCombo.add("Object", DSLMappingSorter.OBJECT);
- sortCombo.add("Language Expression", DSLMappingSorter.EXPRESSION);
- sortCombo.add("Rule Language Meaning", DSLMappingSorter.MAPPING);
- sortCombo.add("Scope", DSLMappingSorter.SCOPE);
- gridData = new GridData (GridData.FILL_HORIZONTAL);
-
- sortCombo.setLayoutData(gridData);
+ sort.setLayoutData( gridData );
+
+ sortCombo = new Combo( parent,
+ SWT.READ_ONLY );
+ sortCombo.add( "Object",
+ DSLMappingSorter.OBJECT );
+ sortCombo.add( "Language Expression",
+ DSLMappingSorter.EXPRESSION );
+ sortCombo.add( "Rule Language Meaning",
+ DSLMappingSorter.MAPPING );
+ sortCombo.add( "Scope",
+ DSLMappingSorter.SCOPE );
+ gridData = new GridData( GridData.FILL_HORIZONTAL );
+
+ sortCombo.setLayoutData( gridData );
}
/** Refreshes the table do make sure it is up to date with the model. */
private void refreshModel() {
tableViewer.setInput( model );
}
-
+
private void createEditButton(Composite parent) {
// Create and configure the "Add" button
- Button add = new Button(parent, SWT.PUSH | SWT.CENTER);
- add.setText("Edit");
+ Button add = new Button( parent,
+ SWT.PUSH | SWT.CENTER );
+ add.setText( "Edit" );
- GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING);
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
gridData.widthHint = 80;
- add.setLayoutData(gridData);
-
- add.addSelectionListener(new SelectionAdapter() {
-
+ add.setLayoutData( gridData );
+
+ add.addSelectionListener( new SelectionAdapter() {
+
// Add a task to the ExampleTaskList and refresh the view
- public void widgetSelected(SelectionEvent e) {
- showEditPopup();
+ public void widgetSelected(SelectionEvent e) {
+ showEditPopup();
}
+ } );
+ }
- });
- }
-
private void showEditPopup() {
- MappingEditor editor = new MappingEditor(getSite().getShell());
+ MappingEditor editor = new MappingEditor( getSite().getShell() );
editor.create();
- editor.getShell().setText("Edit language mapping");
+ editor.getShell().setText( "Edit language mapping" );
editor.setTitle( "Edit an existing language mapping item." );
editor.setTitleImage( getTitleImage() );
-
+
editor.setNLMappingItem( getCurrentSelected() );
-
+
editor.open();
- if (!editor.isCancelled()) {
+ if ( !editor.isCancelled() ) {
refreshModel();
makeDirty();
}
- }
-
+ }
+
private void createDeleteButton(Composite parent) {
// Create and configure the "Add" button
- Button add = new Button(parent, SWT.PUSH | SWT.CENTER);
- add.setText("Remove");
+ Button add = new Button( parent,
+ SWT.PUSH | SWT.CENTER );
+ add.setText( "Remove" );
- GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING);
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
gridData.widthHint = 80;
- add.setLayoutData(gridData);
- add.addSelectionListener(new SelectionAdapter() {
+ add.setLayoutData( gridData );
+ add.addSelectionListener( new SelectionAdapter() {
// Add a task to the ExampleTaskList and refresh the view
public void widgetSelected(SelectionEvent e) {
- model.removeMapping( getCurrentSelected() );
+ model.removeEntry( getCurrentSelected() );
refreshModel();
makeDirty();
}
+ } );
+ }
- });
- }
-
private void createSortButton(Composite parent) {
// Create and configure the "Add" button
- Button sort = new Button(parent, SWT.PUSH | SWT.CENTER);
- sort.setText("Sort");
+ Button sort = new Button( parent,
+ SWT.PUSH | SWT.CENTER );
+ sort.setText( "Sort" );
- GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING);
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
gridData.widthHint = 80;
- sort.setLayoutData(gridData);
- sort.addSelectionListener(new SelectionAdapter() {
+ sort.setLayoutData( gridData );
+ sort.addSelectionListener( new SelectionAdapter() {
// Add a task to the ExampleTaskList and refresh the view
public void widgetSelected(SelectionEvent e) {
- sortModel();
+ sortModel();
refreshModel();
makeDirty();
}
+ } );
+ }
- });
- }
-
/**
* Return the selected item from the table grid thingy.
*/
- private NLMappingItem getCurrentSelected() {
- return (NLMappingItem) ((IStructuredSelection)
- tableViewer.getSelection()).getFirstElement();
+ private DSLMappingEntry getCurrentSelected() {
+ return (DSLMappingEntry) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement();
}
-
-
+
private void createAddButton(Composite parent) {
// Create and configure the "Add" button
- Button add = new Button(parent, SWT.PUSH | SWT.CENTER);
- add.setText("Add");
+ Button add = new Button( parent,
+ SWT.PUSH | SWT.CENTER );
+ add.setText( "Add" );
- GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING);
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
gridData.widthHint = 80;
- add.setLayoutData(gridData);
-
- add.addSelectionListener(new SelectionAdapter() {
-
+ add.setLayoutData( gridData );
+
+ add.addSelectionListener( new SelectionAdapter() {
+
// Add an item, should pop up the editor
- public void widgetSelected(SelectionEvent e) {
-
- NLMappingItem newItem = new NLMappingItem("", "", "*", "");
-
- MappingEditor editor = new MappingEditor(getSite().getShell());//shell);
+ public void widgetSelected(SelectionEvent e) {
+
+ DSLMappingEntry newItem = new DefaultDSLMappingEntry();
+
+ MappingEditor editor = new MappingEditor( getSite().getShell() );//shell);
editor.create();
- editor.getShell().setText("New language mapping");
+ editor.getShell().setText( "New language mapping" );
editor.setTitle( "Create a new language element mapping." );
editor.setTitleImage( getTitleImage() );
-
+
editor.setNLMappingItem( newItem );
-
+
editor.open();
- if (!editor.isCancelled()) {
- model.addNLItem( newItem );
+ if ( !editor.isCancelled() ) {
+ model.addEntry( newItem );
refreshModel();
makeDirty();
- }
-
+ }
+
}
- });
+ } );
}
-
private void createCopyButton(Composite parent) {
// Create and configure the "Add" button
- Button copy = new Button(parent, SWT.PUSH | SWT.CENTER);
- copy.setText("Copy");
+ Button copy = new Button( parent,
+ SWT.PUSH | SWT.CENTER );
+ copy.setText( "Copy" );
- GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING);
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
gridData.widthHint = 80;
- copy.setLayoutData(gridData);
-
- copy.addSelectionListener(new SelectionAdapter() {
-
+ copy.setLayoutData( gridData );
+
+ copy.addSelectionListener( new SelectionAdapter() {
+
// Add an item, should pop up the editor
- public void widgetSelected(SelectionEvent e) {
-
- NLMappingItem curr = getCurrentSelected();
- NLMappingItem newItem = new NLMappingItem(curr
- .getNaturalTemplate(), curr.getTargetTemplate(), curr
- .getScope(), curr.getObjectName());
-
- MappingEditor editor = new MappingEditor(getSite().getShell());//shell);
+ public void widgetSelected(SelectionEvent e) {
+
+ DSLMappingEntry curr = getCurrentSelected();
+ DSLMappingEntry newItem = new DefaultDSLMappingEntry( curr.getSection(),
+ curr.getMetaData(),
+ curr.getMappingKey(),
+ curr.getMappingValue() );
+
+ MappingEditor editor = new MappingEditor( getSite().getShell() );//shell);
editor.create();
- editor.getShell().setText("New language mapping");
+ editor.getShell().setText( "New language mapping" );
editor.setTitle( "Create a new language element mapping from a copy." );
editor.setTitleImage( getTitleImage() );
-
+
editor.setNLMappingItem( newItem );
-
+
editor.open();
- if (!editor.isCancelled()) {
- model.addNLItem( newItem );
+ if ( !editor.isCancelled() ) {
+ model.addEntry( newItem );
refreshModel();
makeDirty();
- }
-
+ }
+
}
- });
+ } );
}
-
+
/**
* Create the viewer.
*/
private void createTableViewer() {
- tableViewer = new TableViewer(table);
- tableViewer.setUseHashlookup(true);
+ tableViewer = new TableViewer( table );
+ tableViewer.setUseHashlookup( true );
//following is if we want default sorting... my thought is no...
}
@@ -543,74 +577,78 @@
* Create the Table
*/
private void createTable(Composite parent) {
- int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
- SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
+ int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
- table = new Table(parent, style);
-
- GridData gridData = new GridData(GridData.FILL_BOTH);
+ table = new Table( parent,
+ style );
+
+ GridData gridData = new GridData( GridData.FILL_BOTH );
gridData.grabExcessVerticalSpace = true;
gridData.horizontalSpan = 3;
- table.setLayoutData(gridData);
-
- table.setLinesVisible(true);
- table.setHeaderVisible(true);
+ table.setLayoutData( gridData );
+ table.setLinesVisible( true );
+ table.setHeaderVisible( true );
+
TableColumn column;
-
+
//Expression col
- column = new TableColumn(table, SWT.LEFT, 0);
- column.setText("Language Expression");
- column.setWidth(350);
+ column = new TableColumn( table,
+ SWT.LEFT,
+ 0 );
+ column.setText( "Language Expression" );
+ column.setWidth( 350 );
// Add listener to column so sorted when clicked
- column.addSelectionListener(new SelectionAdapter() {
-
+ column.addSelectionListener( new SelectionAdapter() {
+
public void widgetSelected(SelectionEvent e) {
- tableViewer.setSorter(new DSLMappingSorter(DSLMappingSorter.EXPRESSION));
+ tableViewer.setSorter( new DSLMappingSorter( DSLMappingSorter.EXPRESSION ) );
}
- });
-
+ } );
// 3rd column with task Owner
- column = new TableColumn(table, SWT.LEFT, 1);
- column.setText("Rule language mapping");
- column.setWidth(200);
+ column = new TableColumn( table,
+ SWT.LEFT,
+ 1 );
+ column.setText( "Rule language mapping" );
+ column.setWidth( 200 );
// Add listener to column so sorted when clicked
- column.addSelectionListener(new SelectionAdapter() {
-
+ column.addSelectionListener( new SelectionAdapter() {
+
public void widgetSelected(SelectionEvent e) {
- tableViewer.setSorter(new DSLMappingSorter(DSLMappingSorter.MAPPING));
+ tableViewer.setSorter( new DSLMappingSorter( DSLMappingSorter.MAPPING ) );
}
- });
+ } );
// 4th column with task PercentComplete
- column = new TableColumn(table, SWT.LEFT, 2);
- column.setText("Object");
- column.setWidth(80);
-
+ column = new TableColumn( table,
+ SWT.LEFT,
+ 2 );
+ column.setText( "Object" );
+ column.setWidth( 80 );
+
// 5th column with task PercentComplete
- column = new TableColumn(table, SWT.LEFT, 3);
- column.setText("Scope");
- column.setWidth(80);
-
+ column = new TableColumn( table,
+ SWT.LEFT,
+ 3 );
+ column.setText( "Scope" );
+ column.setWidth( 80 );
+
// Add listener to column so tasks are sorted when clicked
- column.addSelectionListener(new SelectionAdapter() {
-
+ column.addSelectionListener( new SelectionAdapter() {
+
public void widgetSelected(SelectionEvent e) {
- tableViewer.setSorter(new DSLMappingSorter(DSLMappingSorter.SCOPE));
+ tableViewer.setSorter( new DSLMappingSorter( DSLMappingSorter.SCOPE ) );
}
- });
-
+ } );
}
-
-
+
public void setFocus() {
}
-
+
public void dispose() {
super.dispose();
}
-
}
Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLLabelProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLLabelProvider.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLLabelProvider.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -1,6 +1,6 @@
package org.drools.ide.dsl.editor;
-import org.drools.lang.dsl.template.NLMappingItem;
+import org.drools.lang.dsl.DSLMappingEntry;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
@@ -23,19 +23,19 @@
public String getColumnText(Object element,
int columnIndex) {
String result = "";
- NLMappingItem item = (NLMappingItem) element;
+ DSLMappingEntry item = (DSLMappingEntry) element;
switch (columnIndex) {
case 0:
- result = item.getNaturalTemplate();
+ result = item.getMappingKey();
break;
case 1 :
- result = item.getTargetTemplate();
+ result = item.getMappingValue();
break;
case 2 :
- result = item.getObjectName();
+ result = item.getMetaData().getMetaData();
break;
case 3 :
- result = item.getScope();
+ result = item.getSection().getSymbol();
break;
default :
break;
Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLMappingSorter.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLMappingSorter.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLMappingSorter.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -1,6 +1,6 @@
package org.drools.ide.dsl.editor;
-import org.drools.lang.dsl.template.NLMappingItem;
+import org.drools.lang.dsl.DSLMappingEntry;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
@@ -34,8 +34,8 @@
*/
public int compare(Viewer viewer, Object o1, Object o2) {
- NLMappingItem item1 = (NLMappingItem) o1;
- NLMappingItem item2 = (NLMappingItem) o2;
+ DSLMappingEntry item1 = (DSLMappingEntry) o1;
+ DSLMappingEntry item2 = (DSLMappingEntry) o2;
switch (criteria) {
case OBJECT:
@@ -53,24 +53,24 @@
- private int compareScope(NLMappingItem item1,
- NLMappingItem item2) {
- return item1.getScope().compareTo( item2.getScope() );
+ private int compareScope(DSLMappingEntry item1,
+ DSLMappingEntry item2) {
+ return item1.getSection().compareTo( item2.getSection() );
}
- private int compareMappings(NLMappingItem item1,
- NLMappingItem item2) {
- return item1.getScope().compareTo( item2.getScope() );
+ private int compareMappings(DSLMappingEntry item1,
+ DSLMappingEntry item2) {
+ return item1.getSection().compareTo( item2.getSection() );
}
- private int compareExpressions(NLMappingItem item1,
- NLMappingItem item2) {
- return item1.getNaturalTemplate().compareTo( item2.getNaturalTemplate() );
+ private int compareExpressions(DSLMappingEntry item1,
+ DSLMappingEntry item2) {
+ return item1.getMappingKey().compareTo( item2.getMappingKey() );
}
- private int compareObject(NLMappingItem item1,
- NLMappingItem item2) {
- return item1.getObjectName().compareTo(item2.getObjectName());
+ private int compareObject(DSLMappingEntry item1,
+ DSLMappingEntry item2) {
+ return item1.getMetaData().compareTo(item2.getMetaData());
}
/**
Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/IMappingListViewer.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/IMappingListViewer.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/IMappingListViewer.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -1,6 +1,6 @@
package org.drools.ide.dsl.editor;
-import org.drools.lang.dsl.template.NLMappingItem;
+import org.drools.lang.dsl.DSLMappingEntry;
/**
* Used to keep the view up to date with changes in mappings.
@@ -9,10 +9,10 @@
*/
public interface IMappingListViewer {
- public void addMapping(NLMappingItem item);
+ public void addMapping(DSLMappingEntry item);
- public void removeMapping(NLMappingItem item);
+ public void removeMapping(DSLMappingEntry item);
- public void updateMapping(NLMappingItem item);
+ public void updateMapping(DSLMappingEntry item);
}
Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/MappingEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/MappingEditor.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/MappingEditor.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -1,6 +1,8 @@
package org.drools.ide.dsl.editor;
-import org.drools.lang.dsl.template.NLMappingItem;
+import org.drools.lang.dsl.DSLMappingEntry;
+import org.drools.lang.dsl.DefaultDSLMappingEntry;
+import org.drools.lang.dsl.DSLMappingEntry.Section;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
@@ -23,64 +25,77 @@
*/
public class MappingEditor extends TitleAreaDialog {
- private static final int SCOPE_WHEN = 0;
- private static final int SCOPE_THEN = 1;
- private static final int SCOPE_ALL = 2;
+ private static final int SCOPE_KEYWORD = 0;
+ private static final int SCOPE_WHEN = 1;
+ private static final int SCOPE_THEN = 2;
+ private static final int SCOPE_ALL = 3;
- private Text exprText;
- private Text mappingText;
- private Text objText;
- private Combo scopeCombo;
- private boolean cancelled;
+ private static final String SCOPE_STR_KEYWORD = "keyword";
+ private static final String SCOPE_STR_WHEN = "when";
+ private static final String SCOPE_STR_THEN = "then";
+ private static final String SCOPE_STR_ALL = "*";
- private NLMappingItem model;
-
+ private Text exprText;
+ private Text mappingText;
+ private Text objText;
+ private Combo scopeCombo;
+ private boolean cancelled;
+
+ private DSLMappingEntry model;
+
protected MappingEditor(Shell parent) {
super( parent );
}
-
+
/**
* Pass in a NLMapping item for display/edits.
* Changes will be applied to this object only if the user clicks OK.
*/
- public void setNLMappingItem(NLMappingItem item) {
+ public void setNLMappingItem(DSLMappingEntry item) {
model = item;
- setScope( model.getScope() );
- exprText.setText( model.getNaturalTemplate() );
- mappingText.setText( model.getTargetTemplate() );
- objText.setText( model.getObjectName() );
+ setSection( model.getSection() );
+ exprText.setText( model.getMappingKey() );
+ mappingText.setText( model.getMappingValue() );
+ objText.setText( model.getMetaData().getMetaData() );
}
-
-
- private void setScope(String scope) {
- if (scope.equals( "when" )) {
+
+ private void setSection(Section section) {
+ if ( section == DSLMappingEntry.CONDITION ) {
scopeCombo.select( SCOPE_WHEN );
- } else if (scope.equals( "then" )) {
+ } else if ( section == DSLMappingEntry.CONSEQUENCE ) {
scopeCombo.select( SCOPE_THEN );
- } else if (scope.equals( "*" )) {
+ } else if ( section == DSLMappingEntry.ANY ) {
scopeCombo.select( SCOPE_ALL );
+ } else if ( section == DSLMappingEntry.KEYWORD ) {
+ scopeCombo.select( SCOPE_KEYWORD );
} else {
- throw new IllegalArgumentException("Unknown scope type: " + scope);
+ throw new IllegalArgumentException( "Unknown scope type: " + section );
}
}
-
-
+
+ private Section getSection(String sectionStr) {
+ DSLMappingEntry.Section section = DSLMappingEntry.ANY;
+ if ( SCOPE_STR_KEYWORD.equals( sectionStr ) ) {
+ section = DSLMappingEntry.KEYWORD;
+ } else if ( SCOPE_STR_WHEN.equals( sectionStr ) ) {
+ section = DSLMappingEntry.CONDITION;
+ } else if ( SCOPE_STR_THEN.equals( sectionStr ) ) {
+ section = DSLMappingEntry.CONSEQUENCE;
+ }
+ return section;
+ }
+
protected void cancelPressed() {
this.cancelled = true;
super.cancelPressed();
}
-
-
protected void okPressed() {
this.cancelled = false;
- this.model.setNaturalTemplate(
- NLGrammarModel.normaliseSpaces(
- this.exprText.getText()
- ));
- this.model.setTargetTemplate( this.mappingText.getText() );
- this.model.setScope( this.scopeCombo.getText() );
- this.model.setObjectName( this.objText.getText() );
+ this.model.setMappingKey( this.exprText.getText() );
+ this.model.setMappingValue( this.mappingText.getText() );
+ this.model.setSection( this.getSection( this.scopeCombo.getText() ) );
+ this.model.setMetaData( new DSLMappingEntry.DefaultDSLEntryMetaData( this.objText.getText() ) );
super.okPressed();
}
@@ -89,9 +104,8 @@
return cancelled;
}
+ protected Control createDialogArea(Composite parent) {
- protected Control createDialogArea(Composite parent) {
-
//set the overall layout
GridLayout gridLayout = new GridLayout();
gridLayout.marginHeight = 10;
@@ -105,7 +119,7 @@
createMappingField( parent );
createObjectField( parent );
createScopeField( parent );
-
+
// create the top level composite wrapper
Composite composite = new Composite( parent,
SWT.NONE );
@@ -114,20 +128,18 @@
layout.marginWidth = 10;
layout.verticalSpacing = 10;
composite.setLayout( layout );
- composite.setLayoutData( new GridData( GridData.FILL_BOTH ));
- composite.setFont( parent.getFont() );
-
+ composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ composite.setFont( parent.getFont() );
+
return composite;
}
-
-
private void createMappingField(Composite parent) {
Label mappingLbl = new Label( parent,
SWT.NONE );
mappingLbl.setText( "Rule mapping:" );
mappingLbl.setFont( parent.getFont() );
- mappingLbl.setLayoutData( new GridData(GridData.HORIZONTAL_ALIGN_END) );
+ mappingLbl.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_END ) );
mappingText = new Text( parent,
SWT.BORDER );
@@ -137,9 +149,8 @@
data.grabExcessHorizontalSpace = true;
mappingText.setLayoutData( data );
- mappingText.setToolTipText( "Enter the rule language mapping that the \nlanguage item will be translated to." +
- " Use the named variables (holes) \nthat you specify in the language expression above." );
-
+ mappingText.setToolTipText( "Enter the rule language mapping that the \nlanguage item will be translated to." + " Use the named variables (holes) \nthat you specify in the language expression above." );
+
}
private void createExpressionField(Composite parent) {
@@ -147,7 +158,7 @@
SWT.NONE );
exprLbl.setText( "Language expression:" );
exprLbl.setFont( parent.getFont() );
- exprLbl.setLayoutData( new GridData(GridData.HORIZONTAL_ALIGN_END) );
+ exprLbl.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_END ) );
exprText = new Text( parent,
SWT.BORDER );
@@ -156,23 +167,19 @@
data.horizontalAlignment = GridData.FILL;
data.grabExcessHorizontalSpace = true;
exprText.setLayoutData( data );
- exprText.setToolTipText( "Enter the language expression that you want to use in a rule.\n" +
- "Use curly brackets to mark 'holes' where the values will be extracted\n" +
- "from in the rule source. " +
- "Such as: Person has a name of {name} \n" +
- "This will then parse the rule source to extract the data out of \n" +
- "the place where {name} would appear." );
+ exprText.setToolTipText( "Enter the language expression that you want to use in a rule.\n" + "Use curly brackets to mark 'holes' where the values will be extracted\n" + "from in the rule source. " + "Such as: Person has a name of {name} \n"
+ + "This will then parse the rule source to extract the data out of \n" + "the place where {name} would appear." );
}
-
+
private void createObjectField(Composite parent) {
Label objectLbl = new Label( parent,
- SWT.NONE );
+ SWT.NONE );
objectLbl.setText( "Object:" );
objectLbl.setFont( parent.getFont() );
- objectLbl.setLayoutData( new GridData(GridData.HORIZONTAL_ALIGN_END) );
+ objectLbl.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_END ) );
objText = new Text( parent,
- SWT.BORDER );
+ SWT.BORDER );
GridData data = new GridData();
data.widthHint = 450;
data.horizontalAlignment = GridData.FILL;
@@ -180,30 +187,36 @@
objText.setLayoutData( data );
objText.setToolTipText( "Enter the name of the object." );
-
+
}
private void createScopeField(Composite parent) {
-
+
//type
- Label scopeLbl = new Label(parent, SWT.NONE);
+ Label scopeLbl = new Label( parent,
+ SWT.NONE );
scopeLbl.setText( "Scope:" );
scopeLbl.setFont( parent.getFont() );
- scopeLbl.setLayoutData( new GridData(GridData.HORIZONTAL_ALIGN_END) );
-
+ scopeLbl.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_END ) );
+
scopeCombo = new Combo( parent,
- SWT.READ_ONLY);
-
- scopeCombo.add( "when", SCOPE_WHEN );
- scopeCombo.add( "then", SCOPE_THEN );
- scopeCombo.add( "*", SCOPE_ALL );
-
+ SWT.READ_ONLY );
+
+ scopeCombo.add( SCOPE_STR_KEYWORD,
+ SCOPE_KEYWORD );
+ scopeCombo.add( SCOPE_STR_WHEN,
+ SCOPE_WHEN );
+ scopeCombo.add( SCOPE_STR_THEN,
+ SCOPE_THEN );
+ scopeCombo.add( SCOPE_STR_ALL,
+ SCOPE_ALL );
+
scopeCombo.select( SCOPE_ALL ); //the default
-
- scopeCombo.setLayoutData( new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING) );
- scopeCombo.setFont( parent.getFont() );
+
+ scopeCombo.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING ) );
+ scopeCombo.setFont( parent.getFont() );
scopeCombo.setToolTipText( "This specifies what part of the rule the expression applies. Indicating '*' means global." );
-
+
}
}
Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/NLGrammarModel.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/NLGrammarModel.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/NLGrammarModel.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -3,7 +3,7 @@
import java.util.HashSet;
import java.util.Set;
-import org.drools.lang.dsl.template.NLGrammar;
+import org.drools.lang.dsl.DefaultDSLMapping;
/**
* This extends the compilers DSL grammar implementation to provide
@@ -12,7 +12,7 @@
* @author Michael Neale
*
*/
-public class NLGrammarModel extends NLGrammar {
+public class NLGrammarModel extends DefaultDSLMapping {
private static final long serialVersionUID = 5449029738300794120L;
@@ -32,23 +32,4 @@
changeListeners.add(viewer);
}
- /** This will normalise all whitespace in a string. */
- public static String normaliseSpaces(String withWhiteSpace) {
- char[] chars = withWhiteSpace.toCharArray();
- StringBuffer normalised = new StringBuffer();
- boolean space = false;
- for ( int i = 0; i < chars.length; i++ ) {
- char c = chars[i];
- if (Character.isWhitespace( c )) {
- if (!space) {
- normalised.append( ' ' );
- space = true;
- }
- } else {
- normalised.append( c );
- space = false;
- }
- }
- return normalised.toString();
- }
}
Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/DSLAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/DSLAdapter.java 2007-02-16 17:04:11 UTC (rev 9559)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/DSLAdapter.java 2007-02-16 20:07:42 UTC (rev 9560)
@@ -10,8 +10,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.drools.lang.dsl.template.NLGrammar;
-import org.drools.lang.dsl.template.NLMappingItem;
+import org.drools.lang.dsl.DSLMapping;
+import org.drools.lang.dsl.DSLMappingEntry;
+import org.drools.lang.dsl.DSLMappingFile;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@@ -98,13 +99,14 @@
}
- /** This will load in the DSL config file, using the NLGrammar from drools-compiler */
+ /** This will load in the DSL config file, using the DSLMapping from drools-compiler */
void readConfig(InputStream stream) throws IOException, CoreException {
- NLGrammar grammar = new NLGrammar();
- grammar.load( new InputStreamReader(stream) );
+ DSLMappingFile file = new DSLMappingFile();
+ file.parseAndLoad( new InputStreamReader(stream) );
- List conditions = grammar.getMappings( "when" );
- List consequences = grammar.getMappings( "then" );
+ DSLMapping grammar = file.getMapping();
+ List conditions = grammar.getEntries( DSLMappingEntry.CONDITION );
+ List consequences = grammar.getEntries( DSLMappingEntry.CONSEQUENCE );
conditionProposals = buildProposals(conditions);
consequenceProposals = buildProposals(consequences);
@@ -114,8 +116,8 @@
List result = new ArrayList(suggestions.size());
Iterator iterator = suggestions.iterator();
while (iterator.hasNext()) {
- NLMappingItem text = (NLMappingItem) iterator.next();
- result.add(text.getNaturalTemplate());
+ DSLMappingEntry text = (DSLMappingEntry) iterator.next();
+ result.add(text.getMappingKey());
}
return result;
}
More information about the jboss-svn-commits
mailing list