Created
May 7, 2012 09:29
-
-
Save Rikkola/2626902 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * This is the default rule editor widget (just text editor based) - more to come later. | |
| */ | |
| public class DefaultRuleContentWidget extends DirtyableComposite | |
| implements | |
| EditorWidget { | |
| private TextArea text; | |
| final private RuleContentText data; | |
| public DefaultRuleContentWidget(Asset a, | |
| RuleViewer v, | |
| ClientFactory clientFactory, | |
| EventBus eventBus) { | |
| this(a); | |
| } | |
| public DefaultRuleContentWidget(Asset a) { | |
| this(a, | |
| -1); | |
| } | |
| public DefaultRuleContentWidget(Asset a, | |
| int visibleLines) { | |
| data = (RuleContentText) a.getContent(); | |
| if (data.content == null) { | |
| data.content = ""; | |
| } | |
| text = new TextArea(); | |
| text.setWidth("100%"); | |
| text.setVisibleLines((visibleLines == -1) ? 16 : visibleLines); | |
| text.setText(data.content); | |
| text.getElement().setAttribute("spellcheck", | |
| "false"); //NON-NLS | |
| text.setStyleName("default-text-Area"); //NON-NLS | |
| text.addChangeHandler(new ChangeHandler() { | |
| public void onChange(ChangeEvent event) { | |
| data.content = text.getText(); | |
| makeDirty(); | |
| } | |
| }); | |
| text.addKeyDownHandler(new KeyDownHandler() { | |
| public void onKeyDown(KeyDownEvent event) { | |
| if (event.getNativeKeyCode() == KeyCodes.KEY_TAB) { | |
| int pos = text.getCursorPos(); | |
| insertText("\t"); | |
| text.setCursorPos(pos + 1); | |
| text.cancelKey(); | |
| text.setFocus(true); | |
| } | |
| } | |
| }); | |
| initWidget(text); | |
| } | |
| public void insertText(String ins) { | |
| int i = text.getCursorPos(); | |
| String left = text.getText().substring(0, | |
| i); | |
| String right = text.getText().substring(i, | |
| text.getText().length()); | |
| text.setText(left + ins + right); | |
| this.data.content = text.getText(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment