[jboss-svn-commits] JBL Code SVN: r12310 - 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
Sun Jun 3 18:44:31 EDT 2007
Author: arhan
Date: 2007-06-03 18:44:31 -0400 (Sun, 03 Jun 2007)
New Revision: 12310
Modified:
labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleAttributeWidget.java
labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleAttributesDialog.java
labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleModeller.java
Log:
added options section
Modified: labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleAttributeWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleAttributeWidget.java 2007-06-03 20:30:14 UTC (rev 12309)
+++ labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleAttributeWidget.java 2007-06-03 22:44:31 UTC (rev 12310)
@@ -1,7 +1,14 @@
package org.drools.eclipse.rulebuilder.ui;
+import java.util.ArrayList;
+import java.util.List;
+
import org.drools.brms.client.modeldriven.brxml.RuleAttribute;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
@@ -20,14 +27,14 @@
super(parent, toolkit, modeller, 0);
GridLayout l = new GridLayout();
- l.numColumns = 4;
- l.marginBottom = 0;
- l.marginHeight = 0;
- l.marginLeft = 0;
- l.marginRight = 0;
- l.marginTop = 0;
- l.marginWidth = 0;
- l.verticalSpacing = 0;
+ l.numColumns = 3;
+ // l.marginBottom = 5;
+ // l.marginHeight = 5;
+ // l.marginLeft = 5;
+ // l.marginRight = 5;
+ // l.marginTop = 10;
+ // l.marginWidth = 10;
+ // l.verticalSpacing = 15;
parent.setLayout(l);
create();
@@ -40,35 +47,91 @@
RuleAttribute at = attrs[i];
addAttribute(at);
}
-
+ toolkit.paintBordersFor(parent);
}
private void addAttribute(RuleAttribute at) {
- toolkit.createLabel(parent, at.attributeName);
-
- if (at.attributeName.equals( "enabled" )
- || at.attributeName.equals( "auto-focus" )
- || at.attributeName.equals( "lock-on-active" )) {
- final Button chekbox = toolkit.createButton(parent, "", SWT.CHECK);
- }else{
- final Text box = toolkit.createText(parent, "");
+ toolkit.createLabel(parent, at.attributeName);
+
+ if (at.attributeName.equals("no-loop")) {
+ toolkit.createLabel(parent, "");
+ } else if (at.attributeName.equals("enabled")
+ || at.attributeName.equals("auto-focus")
+ || at.attributeName.equals("lock-on-active")) {
+ createCheckbox(at);
+ } else {
+ createText(at);
}
+
+ addDeleteLink(at);
+
+ }
+
+ private void createText(final RuleAttribute at) {
+ final Text box = toolkit.createText(parent, "");
+
+ box.setText(at.value);
- addDeleteLink();
+
+ box.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ at.value = box.getText();
+ modeller.setDirty(true);
+ }
+ });
+ if (at.attributeName.equals( "date-effective" ) || at.attributeName.equals( "date-expires" )) {
+ if (at.value == null || "".equals( at.value.trim() )) {
+ box.setText( "dd-MMM-yyyy" );
+ }
+ }
+
}
- private void addDeleteLink() {
+ private void createCheckbox(final RuleAttribute at) {
+ final Button checkbox = toolkit.createButton(parent, "", SWT.CHECK);
+
+ if (at.value == null) {
+ checkbox.setSelection(true);
+ at.value = "true";
+ } else {
+ checkbox.setSelection(at.value.equals("true") ? true : false);
+ }
+
+ checkbox.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ at.value = (checkbox.getSelection()) ? "true" : "false";
+ modeller.setDirty(true);
+ }
+
+ });
+
+ }
+
+ private void addDeleteLink(final RuleAttribute at) {
ImageHyperlink delLink = addImage(parent, "icons/delete_item_small.gif");
delLink.setToolTipText("Remove this fieldconstraint");
delLink.addHyperlinkListener(new IHyperlinkListener() {
public void linkActivated(HyperlinkEvent e) {
MessageBox dialog = new MessageBox(Display.getCurrent()
.getActiveShell(), SWT.YES | SWT.NO | SWT.ICON_WARNING);
- dialog.setMessage("Remove this item?");
- dialog.setText("Remove this item?");
+ dialog.setMessage("Remove this rule option?");
+ dialog.setText("Remove this rule option?");
if (dialog.open() == SWT.YES) {
- //TODO: delete relevant attribute
+ RuleAttribute[] attrs = modeller.getModel().attributes;
+ for (int i = 0; i < attrs.length; i++) {
+ if (attrs[i] == at) {
+ modeller.getModel().removeAttribute(i);
+
+ modeller.setDirty(true);
+ modeller.reloadOptions();
+ }
+ }
}
}
@@ -81,4 +144,29 @@
}
+ /**
+ * Return a listbox of choices for rule attributes.
+ *
+ * @return
+ */
+ public static List getAttributeList() {
+ List list = new ArrayList();
+ list.add("...");
+
+ list.add("salience");
+ list.add("enabled");
+ list.add("date-effective");
+ list.add("date-expires");
+ list.add("no-loop");
+ list.add("agenda-group");
+ list.add("activation-group");
+ list.add("duration");
+ list.add("auto-focus");
+ list.add("lock-on-active");
+ list.add("ruleflow-group");
+ list.add("dialect");
+
+ return list;
+ }
+
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleAttributesDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleAttributesDialog.java 2007-06-03 20:30:14 UTC (rev 12309)
+++ labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleAttributesDialog.java 2007-06-03 22:44:31 UTC (rev 12310)
@@ -1,5 +1,17 @@
package org.drools.eclipse.rulebuilder.ui;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.brms.client.modeldriven.brxml.RuleAttribute;
+import org.eclipse.swt.SWT;
+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.Event;
+import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormToolkit;
@@ -7,14 +19,62 @@
private final FormToolkit toolkit;
- private RuleModeller modeller;
-
- public RuleAttributesDialog(Shell parent, FormToolkit toolkit, RuleModeller modeller) {
- super(parent, "Add new option to the rule", "Pick the value from combo and confirm the selection."); // TODO: set title and hint
-
+ private RuleModeller modeller;
+
+ public RuleAttributesDialog(Shell parent, FormToolkit toolkit,
+ RuleModeller modeller) {
+ super(parent, "Add new option to the rule",
+ "Pick the value from combo and confirm the selection.");
+
this.toolkit = toolkit;
this.modeller = modeller;
}
-
+ protected Control createDialogArea(final Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+
+ GridLayout l = new GridLayout();
+ l.numColumns = 3;
+ l.marginBottom = 0;
+ l.marginHeight = 0;
+ l.marginLeft = 0;
+ l.marginRight = 0;
+ l.marginTop = 0;
+ l.marginWidth = 0;
+ composite.setLayout(l);
+
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+
+ createAtributesSelectionCombo(composite, gd);
+
+ return composite;
+ }
+
+ private void createAtributesSelectionCombo(Composite composite, GridData gd) {
+ toolkit.createLabel(composite, "Attributes");
+ final Combo combo = new Combo(composite, SWT.READ_ONLY);
+ combo.setLayoutData(gd);
+ List attributes = RuleAttributeWidget.getAttributeList();
+ for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
+ String attr = (String) iterator.next();
+ combo.add(attr);
+ }
+ combo.select(0);
+
+ combo.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ if (combo.getSelectionIndex() == 0) {
+ return;
+ }
+ modeller.getModel().addAttribute(
+ new RuleAttribute(combo.getText(), ""));
+ modeller.setDirty(true);
+ modeller.reloadOptions();
+ close();
+ }
+ });
+
+ }
+
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleModeller.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleModeller.java 2007-06-03 20:30:14 UTC (rev 12309)
+++ labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/RuleModeller.java 2007-06-03 22:44:31 UTC (rev 12310)
@@ -181,7 +181,8 @@
}
private void redrawOptions(){
- //TODO
+ Composite comp = toolkit.createComposite( optionsComposite );
+ new RuleAttributeWidget(toolkit, comp, this);
}
More information about the jboss-svn-commits
mailing list