01: package org.drools.brms.client.ruleeditor;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.drools.brms.client.common.DirtyableComposite;
20: import org.drools.brms.client.rpc.RuleAsset;
21: import org.drools.brms.client.rpc.RuleContentText;
22:
23: import com.google.gwt.user.client.ui.ChangeListener;
24: import com.google.gwt.user.client.ui.KeyboardListenerAdapter;
25: import com.google.gwt.user.client.ui.TextArea;
26: import com.google.gwt.user.client.ui.Widget;
27:
28: /**
29: * This is the default rule editor widget (just text editor based) - more to come later.
30: * @author michael neale
31: */
32: public class DefaultRuleContentWidget extends DirtyableComposite {
33:
34: private TextArea text;
35: final private RuleContentText data;
36:
37: final private RuleAsset asset;
38:
39: public DefaultRuleContentWidget(RuleAsset a) {
40: asset = a;
41: data = (RuleContentText) asset.content;
42:
43: text = new TextArea();
44: text.setWidth("100%");
45: text.setHeight("100%");
46: text.setVisibleLines(10);
47: text.setText(data.content);
48:
49: text.setStyleName("default-text-Area");
50:
51: text.addChangeListener(new ChangeListener() {
52: public void onChange(Widget w) {
53: data.content = text.getText();
54: makeDirty();
55: }
56: });
57:
58: text.addKeyboardListener(new KeyboardListenerAdapter() {
59: public void onKeyDown(Widget arg0, char arg1, int arg2) {
60:
61: if (arg1 == KEY_TAB) {
62: insertText("\t");
63: text.setCursorPos(text.getCursorPos() + 1);
64: text.cancelKey();
65: }
66: }
67: });
68:
69: initWidget(text);
70: }
71:
72: void insertText(String ins) {
73: int i = text.getCursorPos();
74: String left = text.getText().substring(0, i);
75: String right = text.getText().substring(i,
76: text.getText().length());
77: text.setText(left + ins + right);
78: this.data.content = text.getText();
79: }
80:
81: }
|