/** * 获取数据对象缓存。 * * @param dataObjectDescriptor * @param keyName * @param key * @return */ public DataObject getDataObject(Thing dataObjectDescriptor, String keyName, Object key) { if (dataObjectDescriptor.getBoolean("cacheRelationReadnone")) { DataObject dataObject = new DataObject(dataObjectDescriptor.getMetadata().getPath()); dataObject.put(keyName, key); dataObject.setInited(false); return dataObject; } else { String descriptorPath = dataObjectDescriptor.getMetadata().getPath(); Map<Object, DataObjectCacheEntry> dataObjectCache = caches.get(descriptorPath); if (dataObjectCache == null) { dataObjectCache = new HashMap<Object, DataObjectCacheEntry>(); caches.put(descriptorPath, dataObjectCache); } DataObjectCacheEntry entry = dataObjectCache.get(key); if (entry != null) { return entry.dataObject; } // 重置缓存 DataObject dataObject = new DataObject(descriptorPath); dataObject.put(keyName, key); dataObject.setInited(false); // 保存缓存 if (dataObjectDescriptor.getInt("cacheRelationMaxSize") <= 0 || dataObjectCache.size() < dataObjectDescriptor.getInt("cacheRelationMaxSize")) { entry = new DataObjectCacheEntry(); entry.dataObject = dataObject; dataObjectCache.put(key, entry); } return dataObject; } }
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; }
@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 init(ActionContext actionContext) throws PropertyVetoException { Thing self = (Thing) actionContext.get("self"); // 配置文件 Thing thing = self; try { thing = UtilData.createPropertiesThing(self, self.getString("configPropertiesFile")); } catch (Exception e) { logger.error("Reader datasource properties file error", e); } // 创建c3p0DataSource BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(thing.getString("driver_class")); dataSource.setUrl(thing.getString("url")); dataSource.setUsername(thing.getString("userName")); dataSource.setPassword(thing.getString("password")); dataSource.setInitialSize(thing.getInt("initPoolSize", 3)); dataSource.setMaxActive(thing.getInt("maxPoolSize", 15)); dataSource.setMinIdle(thing.getInt("minPoolSize", 3)); dataSource.setMaxWait(thing.getInt("maxIdleTime", 0)); dataSource.setTimeBetweenEvictionRunsMillis(thing.getInt("idleConnectionTestPeriod", 0)); dataSource.setTestOnBorrow(thing.getBoolean("testOnCheckOut")); dataSource.setTestOnReturn(thing.getBoolean("testOnCheckIn")); dataSource.setTestWhileIdle(thing.getBoolean("testWhileIdle")); // dataSource.set(thing.getInt("acquireIncrement", 3)); // dataSource.setAcquireRetryAttempts(thing.getInt("acquireRetryAttempts", 30)); // dataSource.setAcquireRetryDelay(thing.getInt("acquireRetryDelay", 1000)); // dataSource.setBreakAfterAcquireFailure(thing.getBoolean("breakAfterAcquireFailure", false)); // dataSource.setDebugUnreturnedConnectionStackTraces(thing.getBoolean("debugUnreturnedConnectionStackTraces", false)); String testSql = thing.getString("testSql"); if (testSql != null && !"".equals(testSql)) { dataSource.setValidationQuery(testSql); } return dataSource; }
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; }