@Override public void run() { for (int i = 0; i < tasks.size(); i++) { synchronized (tasks) { if (i >= tasks.size()) { break; } Thing task = tasks.get(i); try { // 显示标签 if (label != null && !label.isDisposed()) { String text = (String) task.doAction("getLabel", actionContext); if (text == null) { text = ""; } setLabel(text); } // 先从列表中移除任务 tasks.remove(i); i--; // 执行任务 task.doAction("run", actionContext); } catch (Throwable t) { logger.error("Runn tasks error, task=" + task, t); } finally { if (label != null && !label.isDisposed()) { String text = (String) task.doAction("getLabel", actionContext); if (text == null) { text = ""; } setLabel(text + " task finished"); } addRunnedTaskCount(); // 设置进度条的值 setProgressBarSelection(i == tasks.size() - 1); } } } finished = true; String finishLabel = (String) thing.doAction("getFinishLabel", actionContext); if (finishLabel != null) { setLabel(finishLabel); } thing.doAction("onFinished", actionContext); }
@SuppressWarnings("unchecked") public static Object toCode(ActionContext actionContext) { Thing self = (Thing) actionContext.get("self"); String ident = (String) actionContext.get("ident"); if (ident == null) { ident = ""; } String scriptCode = ""; for (Thing html : (List<Thing>) self.get("html@")) { String code = html.getString("code"); if (code != null && !"".equals(code)) { scriptCode = scriptCode + ",\n" + ident + " " + code; } } Thing config = self.getThing("Config@0"); if (config != null) { String configStr = (String) config.doAction( "toJavaScriptCode", actionContext, UtilMap.toMap(new Object[] {"ident", ident + " "})); if (configStr != null) { if (scriptCode != "") { scriptCode = scriptCode + ",\n" + ident + " " + configStr; } } } if (scriptCode != "") { scriptCode = scriptCode.substring(2, scriptCode.length()); } return scriptCode; }
public static void createItem( DataObject note, String label, String agroup, ActionContext actionContext) { CTabFolder tab = (CTabFolder) actionContext.get("tabFolder"); for (CTabItem tabItem : tab.getItems()) { String l = (String) tabItem.getText(); if (l != null && l.equals(label)) { createItemAtTab(note, agroup, tabItem, actionContext); return; } } ActionContext ac = new ActionContext(); ac.put("parent", tab); ac.put("parentContext", actionContext); Thing tabItemThing = World.getInstance() .getThing( "xworker.app.assistor.note.swt.Note/@composite/@tabFolder/@PreparedWidgets/@defaultTabItem"); CTabItem tabItem = (CTabItem) tabItemThing.doAction("create", ac); if (label != null && !"".equals(label)) { tabItem.setText(label); } Image image = (Image) actionContext.get("tabImage"); if (image != null) { tabItem.setImage(image); } tabItem.setData("actionContext", ac); createItemAtTab(note, agroup, tabItem, actionContext); }
public static JInternalFrame create(ActionContext actionContext) { // 变量 Thing self = (Thing) actionContext.get("self"); Container parent = (Container) actionContext.get("parent"); // 创建 JInternalFrame comp = new JInternalFrame(); if (parent != null) { parent.add(comp); } // 初始化 init(comp, self, parent, actionContext); // 创建子节点 try { actionContext.push().put("parent", comp); for (Thing child : self.getChilds()) { child.doAction("create", actionContext); } } finally { actionContext.pop(); } // 放置和返回变量 actionContext.getScope(0).put(self.getMetadata().getName(), comp); return comp; }
public static void viewHtmlCode(ActionContext actionContext) { World world = World.getInstance(); Thing currentThing = (Thing) actionContext.get("currentThing"); if (actionContext.get("explorerContext") == null) { // log.warn("Must run in explorer menu"); System.out.println(currentThing.doAction("toHtml")); return; } Thing editorThing = world.getThing("xworker.ide.worldExplorer.swt.dialogs.HtmlCodeViewer/@shell"); ActionContext context = new ActionContext(); context.put("parent", ((ActionContext) actionContext.get("explorerContext")).get("shell")); String html = (String) currentThing.doAction("toHtml"); context.put("html", html == null ? "no html generated" : html); editorThing.doAction("run", context); }
public static Object create(ActionContext actionContext) { Thing self = (Thing) actionContext.get("self"); int style = SWT.NONE; String selfStyle = self.getString("style"); if ("HORIZONTAL".equals(selfStyle)) { style |= SWT.HORIZONTAL; } else if ("VERTICAL".equals(selfStyle)) { style |= SWT.VERTICAL; } if (self.getBoolean("SMOOTH")) style |= SWT.SMOOTH; if (self.getBoolean("BORDER")) style |= SWT.BORDER; if (self.getBoolean("INDETERMINATE")) style |= SWT.INDETERMINATE; Composite parent = (Composite) actionContext.get("parent"); ProgressBar bar = new ProgressBar(parent, style); // 父类的初始化方法 Bindings bindings = actionContext.push(null); bindings.put("control", bar); try { self.doAction("super.init", actionContext); } finally { actionContext.pop(); } bar.setMaximum(self.getInt("maximum", 100)); bar.setMinimum(self.getInt("minimum", 0)); bar.setSelection(self.getInt("selection", 0)); // 保存变量和创建子事物 actionContext.getScope(0).put(self.getString("name"), bar); actionContext.peek().put("parent", bar); for (Thing child : self.getAllChilds()) { child.doAction("create", actionContext); } actionContext.peek().remove("parent"); Designer.attach(bar, self.getMetadata().getPath(), actionContext); return bar; }
public static void createInternalFrameListeners(ActionContext actionContext) { Thing self = (Thing) actionContext.get("self"); JInternalFrame parent = (JInternalFrame) actionContext.get("parent"); for (Thing child : self.getChilds()) { InternalFrameListener c = (InternalFrameListener) child.doAction("create", actionContext); if (c != null) { parent.addInternalFrameListener(c); } } }
public static Object run(ActionContext actionContext) throws OgnlException { Thing self = (Thing) actionContext.get("self"); Shell shell = (Shell) self.doAction("getShell", actionContext); DirectoryDialog dialog = new DirectoryDialog(shell, SWT.NONE); String filterPath = (String) self.doAction("getFilterPath", actionContext); if (filterPath != null && !"".equals(filterPath)) { dialog.setFilterPath(UtilString.getString(filterPath, actionContext)); } String message = self.getString("message"); if (message != null && !"".equals(message)) { dialog.setMessage(UtilString.getString(message, actionContext)); } String dir = dialog.open(); self.doAction("open", actionContext, UtilMap.toMap("fileName", dir)); return dir; }
public static void createAction(ActionContext actionContext) { Thing self = (Thing) actionContext.get("self"); JToolBar parent = (JToolBar) actionContext.get("parent"); for (Thing child : self.getChilds()) { Action obj = (Action) child.doAction("create", actionContext); if (obj != null) { parent.add(obj); } } }
public static void createChangeListeners(ActionContext actionContext) { Thing self = (Thing) actionContext.get("self"); JTabbedPane parent = (JTabbedPane) actionContext.get("parent"); for (Thing child : self.getChilds()) { ChangeListener l = (ChangeListener) child.doAction("create", actionContext); if (l != null) { parent.addChangeListener(l); } } }
public static void iteratorLines(ActionContext actionContext) throws IOException { Thing self = (Thing) actionContext.get("self"); File file = (File) self.doAction("getFile", actionContext); if (file == null) { throw new ActionException( "IteratorLines: file is null, path=" + self.getMetadata().getPath()); } FileInputStream fin = new FileInputStream(file); try { BufferedReader br = new BufferedReader(new InputStreamReader(fin)); String line = null; boolean trim = self.getBoolean("trim"); boolean continueOnBlank = self.getBoolean("continueOnBlank"); Bindings bindings = actionContext.push(); bindings.isVarScopeFlag = true; try { bindings.put("file", file); while ((line = br.readLine()) != null) { if (trim) { line = line.trim(); } if (continueOnBlank && "".equals(line)) { continue; } bindings.put("line", line); self.doAction("handleLine", actionContext); } } finally { actionContext.pop(); } br.close(); } finally { fin.close(); } }
public static void createContentPane(ActionContext actionContext) { Thing self = (Thing) actionContext.get("self"); JInternalFrame parent = (JInternalFrame) actionContext.get("parent"); for (Thing child : self.getChilds()) { Container c = (Container) child.doAction("create", actionContext); if (c != null) { parent.setContentPane(c); break; } } }
@SuppressWarnings("unchecked") public static void onReconfig(ActionContext actionContext) { Thing self = (Thing) actionContext.get("self"); Table table = (Table) self.get("table"); // 删除所有数据 table.removeAll(); // 删除所有列 for (TableColumn column : table.getColumns()) { column.dispose(); } // 重新组建表格的列 Thing store = (Thing) actionContext.get("store"); Thing dataObject = (Thing) store.get("dataObject"); if (dataObject == null) { return; } List<Thing> columns = new ArrayList<Thing>(); for (Thing attr : (List<Thing>) dataObject.get("attribute@")) { if (attr.getBoolean("viewField") && attr.getBoolean("showInTable") && attr.getBoolean("gridEditor")) { int style = SWT.NONE; String gridAlign = attr.getString("gridAlign"); if ("left".equals(gridAlign)) { style = style | SWT.LEFT; } else if ("right".equals(gridAlign)) { style = style | SWT.RIGHT; } else if ("center".equals(gridAlign)) { style = style | SWT.CENTER; } TableColumn column = new TableColumn(table, style); column.setText(attr.getMetadata().getLabel()); int width = attr.getInt("gridWidth"); if (width > 0) { column.setWidth(width); } column.setResizable(attr.getBoolean("gridResizable")); column.setMoveable(true); columns.add(attr); } } self.set("columns", columns); // 初始化数据,如果存在 self.doAction("onLoaded", actionContext); }
public static Object toJavaScriptCode(ActionContext actionContext) { Thing self = (Thing) actionContext.get("self"); String varref = self.getString("varref"); if (varref != null && !"".equals(varref)) { return varref; } else { String scriptCode = (String) self.doAction("toCode", actionContext); if (scriptCode != "") { return "new Ext.Template(\n" + scriptCode + "\n" + actionContext.get("ident") + ")"; } else { return null; } } }
public static Object create(ActionContext actionContext) { World world = World.getInstance(); Thing self = (Thing) actionContext.get("self"); Action styleAction = world.getAction("xworker.swt.widgets.Composite/@scripts/@getStyles"); int style = (Integer) styleAction.run(actionContext); Composite parent = (Composite) actionContext.get("parent"); Spinner spinner = new Spinner(parent, style); // 父类的初始化方法 Bindings bindings = actionContext.push(null); bindings.put("control", spinner); bindings.put("self", self); try { Action initAction = world.getAction("xworker.swt.widgets.Control/@actions/@init"); initAction.run(actionContext); } finally { actionContext.pop(); } spinner.setDigits(self.getInt("digits", 0)); spinner.setIncrement(self.getInt("increment", 1)); String maximum = self.getString("maximum"); if (maximum != null && !"".equals(maximum)) spinner.setMaximum(self.getInt("maximum", 1000000)); String minimun = self.getString("minimun"); if (minimun != null && !"".equals(minimun)) spinner.setMinimum(self.getInt("maximum", -100000)); String pageIncrement = self.getString("pageIncrement"); if (pageIncrement != null && !"".equals(pageIncrement)) spinner.setPageIncrement(self.getInt("pageIncrement", 10)); String selection = self.getString("selection"); if (selection != null && !"".equals(selection)) spinner.setSelection(self.getInt("selection", 1)); // 保存变量和创建子事物 actionContext.getScope(0).put(self.getString("name"), spinner); actionContext.peek().put("parent", spinner); for (Thing child : self.getAllChilds()) { child.doAction("create", actionContext); } actionContext.peek().remove("parent"); Designer.attach(spinner, self.getMetadata().getPath(), actionContext); return spinner; }
public static void createTabItem(ActionContext actionContext) { Thing self = (Thing) actionContext.get("self"); JTabbedPane parent = (JTabbedPane) actionContext.get("parent"); Thing thing = self.getThing("Component@0"); if (thing != null) { try { Bindings bindings = actionContext.push(); bindings.put("parent", null); for (Thing child : thing.getChilds()) { Component c = (Component) child.doAction("create", actionContext); if (c != null) { int index = parent.getTabCount(); parent.setComponentAt(index, c); Color background = AwtCreator.createColor(thing, "background", actionContext); if (background != null) { parent.setBackgroundAt(index, background); } Icon disabledIcon = SwingCreator.createIcon(thing, "disabledIcon", actionContext); if (disabledIcon != null) { parent.setDisabledIconAt(index, disabledIcon); } Integer displayedMnemonicIndex = JavaCreator.createInteger(thing, "displayedMnemonicIndex"); if (displayedMnemonicIndex != null) { parent.setDisplayedMnemonicIndexAt(index, displayedMnemonicIndex); } Boolean enabled = JavaCreator.createBoolean(thing, "enabled"); if (enabled != null) { parent.setEnabledAt(index, enabled); } Color foreground = AwtCreator.createColor(thing, "foreground", actionContext); if (foreground != null) { parent.setForeground(foreground); } Icon icon = SwingCreator.createIcon(thing, "icon", actionContext); if (icon != null) { parent.setIconAt(index, icon); } Integer mnemonic = AwtCreator.createMnemonic(thing, "mnemonic"); if (mnemonic != null) { parent.setMnemonicAt(index, mnemonic); } Boolean selected = JavaCreator.createBoolean(thing, "selected"); if (selected != null && selected) { parent.setSelectedIndex(index); } String title = JavaCreator.createText(thing, "title", actionContext); if (title != null) { parent.setTitleAt(index, title); } String toolTipText = JavaCreator.createText(thing, "toolTipText", actionContext); if (toolTipText != null) { parent.setToolTipTextAt(index, toolTipText); } break; } } } finally { actionContext.pop(); } } }
public static Object toHtml(ActionContext actionContext) { // HTML分为head、body和bottom三个部分 // head是HTML头,body是主内容,bottom是页面最后的部分,比如yahoo ui的初始化脚本在最后 // 初始化heads、bottoms和bottomThings,使个元素可以添加heads和bottoms // 添加head和bottom可以通过view的addHead和addBottom方法 List<Map<String, String>> heads = new ArrayList<Map<String, String>>(); List<Map<String, String>> bottoms = new ArrayList<Map<String, String>>(); List<Thing> bottomThings = new ArrayList<Thing>(); Thing self = (Thing) actionContext.get("self"); String bodyAttributes = self.getString("bodyAttributes"); if (bodyAttributes == null) bodyAttributes = ""; ActionContext newContext = new ActionContext(actionContext); newContext.put("heads", heads); newContext.put("bottoms", bottoms); newContext.put("bottomThings", bottomThings); newContext.put("bodyAttributes", bodyAttributes); Thing javaScriptThing = new Thing("xworker.html.base.scripts.JavaScript"); javaScriptThing.put("useChildsCode", "true"); newContext.put(HtmlConstants.HTML_BOTTOM_JAVASCRIPT_THING, javaScriptThing); // 循环递归生成子事物的界面,每个子事物都应实现toHtml方法,toHtml方法返回的是body部分的代码 // 在toHtml方法里,子事物可以把头部的代码和底部的代码加入到heads和bottoms变量中 String bodyContent = ""; for (Thing child : self.getAllChilds()) { String content = (String) child.doAction("toHtml", newContext); if (content != null) { bodyContent = bodyContent + content; } } // -------------生成HTML头-------------------------- String html = ""; if ("true".equals(self.getString("belongToHtml"))) { html = "<html>\n<head>"; if (self.get("title") != null) { html = html + "<title>" + self.get("title") + "</title>\n"; } } if (self.getBoolean("belongToHtml") || self.getBoolean("hasHead")) { if (self.get("otherHeads") != null) { html = html + self.get("otherHeads") + "\n"; } for (Map<String, String> head : heads) { html = html + head.get("value"); } } // --------------生成HTML的body部分------------------------- if (self.getBoolean("belongToHtml")) { // log.info(newContext.get("bodyAttributes")); html = html + "</head>\n<body " + newContext.get("bodyAttributes") + ">\n"; } if (bodyContent != null) { html = html + bodyContent; } // html = html+ "<div id=\"loadingDiv\">"; // html = html + "</div>"; // --------------生成HTML的底部部分-------------------------- if (self.getBoolean("belongToHtml") || self.getBoolean("hasBottom")) { for (Map<String, String> bottom : bottoms) { html = html + bottom.get("value"); } for (Thing bottomThing : bottomThings) { html = html + bottomThing.doAction("toHtml", newContext); } if (javaScriptThing.getChilds().size() > 0) { html = html + javaScriptThing.doAction("toHtml", newContext); } } if (self.getBoolean("belongToHtml")) { html = html + "\n" + " </body>\n" + "</html>"; } return html; }