
<?xml version="1.0" encoding="utf-8"?>
<Shell name="shell" descriptors="xworker.swt.widgets.Shell" text="CodeEditor"
RESIZE="true" width="640" height="480" label="CodeEditor">
<FillLayout name="shellFillLayout"></FillLayout>
<Group name="group" text="CodeEditor" label="CodeEditor">
<FillLayout name="groupFillLayout"></FillLayout>
<CodeEditor name="codeEditor" codeName="java" codeType="java">
<code><![CDATA[/*******************************************************************
* Copyright 2007-2013 See AUTHORS file.
*
* 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 xworker.swt.xworker;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import org.xmeta.World;
import xworker.swt.design.Designer;
import xworker.swt.events.SwtListener;
import xworker.swt.form.TextEditor;
public class CodeEditorCreator {
public static Object create(ActionContext actionContext){
World world = World.getInstance();
Thing self = (Thing) actionContext.get("self");
Composite parent = (Composite) actionContext.get("parent");
ActionContext newContext = new ActionContext();
newContext.put("parent", parent);
newContext.put("codeName", self.getString("codeName"));
newContext.put("codeType", self.getString("codeType"));
newContext.put("parentContext", actionContext);
Thing codeEditor = world.getThing("xworker.swt.xworker.CodeEditor/@editorViewForm");
codeEditor.doAction("create", newContext);
StyledText textEditor = (StyledText) newContext.get("editInput");
if("true".equals(self.getString("WRAP"))){
textEditor.setWordWrap(true);
}
actionContext.getScope(0).put(self.getString("name"), textEditor);
try{
//代码着色
Colorer.attach(textEditor, self.getString("codeName"), self.getString("codeType"));
}catch(Throwable t){
}
if(self.getStringBlankAsNull("code") != null){
textEditor.setText(self.getString("code"));
}
//设置redoundo和其他
TextEditor.attach(textEditor);
textEditor.setData("lineLabel", newContext.get("editorLineLabel"));
//创建子节点
actionContext.peek().put("parent", newContext.get("editorViewForm"));
for(Thing child : self.getAllChilds()){
child.doAction("create", actionContext);
}
actionContext.peek().remove("parent");
//log.info("newContext.editorViewForm=" + newContext.editorViewForm.getLayoutData());
Designer.attach(textEditor, self.getMetadata().getPath(), actionContext);
return textEditor;
}
public static void textKeyDown(ActionContext actionContext){
Event event = (Event) actionContext.get("event");
StyledText text = (StyledText) event.widget;
int line = text.getLineAtOffset(text.getCaretOffset()) + 1;
int carOffset = text.getCaretOffset();
int lineOffset = text.getOffsetAtLine(line - 1);
((Label) text.getData("lineLabel")).setText("" + line + ":" + (carOffset - lineOffset + 1));
((Label) text.getData("lineLabel")).update();
if(event.keyCode == 's' && event.stateMask == SWT.CTRL){
SwtListener okButtonSelection = (SwtListener) actionContext.get("okButtonSelection");
if(okButtonSelection != null){
okButtonSelection.handleEvent(null);
}
}
}
public static void textMouseUp(ActionContext actionContext){
}
public static void toolItemSelecitonScript(ActionContext actionContext){
World world = World.getInstance();
//取ViewForm数据对象的定义,要编辑的数据对象放置在ViewForm的数据对象中
StyledText textEditor = (StyledText) actionContext.get("editInput");
ActionContext newContext = new ActionContext();
newContext.put("parent", textEditor.getShell());
newContext.put("fileType", textEditor.getData("fileType"));
newContext.put("parentText", textEditor);
newContext.put("saveButtonSelection", actionContext.get("okButtonSelection"));
Thing shellObject = world.getThing("xworker.swt.xworker.CodeEditorPop/@shell");
shellObject.doAction("create", newContext);
StyledText newtextEditor = (StyledText) newContext.get("textEditor");
if(textEditor.getWordWrap()){
newtextEditor.setWordWrap(true);
}
newtextEditor.setText(textEditor.getText());
newtextEditor.setData("oldText", textEditor);
newtextEditor.setTopIndex(textEditor.getTopIndex());
newtextEditor.setCaretOffset(textEditor.getCaretOffset());
//CodeEditorSyncer.attach(textEditor, newContext.textEditor);
//CodeEditorSyncer.attach(newContext.textEditor, textEditor);
((Shell) newContext.get("shell")).open();
}
public static void contentTextKeyDown(ActionContext actionContext){
Event event = (Event) actionContext.get("event");
StyledText text = (StyledText) event.widget;
int line = text.getLineAtOffset(text.getCaretOffset()) + 1;
int carOffset = text.getCaretOffset();
int lineOffset = text.getOffsetAtLine(line - 1);
((Label) text.getData("lineLabel")).setText("" + line + ":" + (carOffset - lineOffset + 1));
((Label) text.getData("lineLabel")).update();
if(event.keyCode == 's' && event.stateMask == SWT.CTRL){
SwtListener okButtonSelection = (SwtListener) actionContext.get("okButtonSelection");
if(okButtonSelection != null){
okButtonSelection.handleEvent(null);
}
}
}
}]]></code>
</CodeEditor>
</Group>
</Shell>
Copyright © 2007-2014 XWorker.org 版权所有