Exemple #1
0
  /**
   * 创建。
   *
   * @param actionContext
   * @return
   */
  public static Thing create(ActionContext actionContext) {
    Thing self = (Thing) actionContext.get("self");

    // 任务列表
    List<Thing> tasks = new ArrayList<Thing>();
    Thing tasksThing = self.getThing("Tasks@0");
    if (tasksThing != null) {
      tasks.addAll(tasksThing.getChilds());
    }

    // 进度条和标签
    String progressBarVarName = self.getStringBlankAsNull("progressBarVarName");
    ProgressBar progressBar = null;
    if (progressBarVarName != null) {
      progressBar = (ProgressBar) actionContext.get(progressBarVarName);
    }
    String labelVarName = self.getStringBlankAsNull("labelVarName");
    Label label = null;
    if (labelVarName != null) {
      label = (Label) actionContext.get(labelVarName);
    }

    // 创建新的事物
    Thing thing = new Thing();
    thing.put("descriptors", self.getMetadata().getPath()); // 设置原来的事物为描述者,用于继承行为

    // 创建实例
    TaskMonitor monitor = new TaskMonitor(self, tasks, progressBar, label, actionContext);
    thing.setData(TaskMonitor.monitor_name, monitor);

    // 保存变量
    actionContext.getScope(0).put(self.getMetadata().getName(), thing);

    return thing;
  }
Exemple #2
0
  public static void init(ActionContext actionContext) {
    World world = World.getInstance();
    // import xworker.util.ThingOgnlAccessor;

    // 初始化Ognl读Thing的类
    // ThingOgnlAccessor.init();

    System.out.println("init world=" + world);

    // 重新设置元事物,Java代码中定义的元事物是最简单的,有更多功能的更好一些
    Thing metaThing = world.getThing("xworker.lang.MetaThing").detach();
    // 保留元事物的路径
    metaThing.getMetadata().setPath("xworker.lang.MetaThing");
    metaThing.initChildPath();
    world.metaThing = metaThing;

    // 检查全局配置是否存在
    Thing globalConfig = world.getThing("_local.xworker.config.GlobalConfig");
    if (globalConfig == null) {
      globalConfig = new Thing("xworker.ide.config.decriptors.GlobalConfig");
      globalConfig.put("name", "GlobalConfig");
      globalConfig.copyTo("_local", "_local.xworker.config");
    }

    // 注册事物
    ThingRegistor.regist(
        "_xworker_thing_attribute_editor_config", "xworker.lang.attributeEditors.EditorConfig");
    ThingRegistor.regist(
        "_xworker_thing_attribute_editor_CodeEditor", "xworker.swt.xworker.CodeEditor");
    ThingRegistor.regist("_xworker_thing_attribute_editor_GridData", "xworker.swt.layout.GridData");
    ThingRegistor.regist(
        "_xworker_thing_attribute_editor_CodeEditor", "xworker.swt.xworker.CodeEditor");
    ThingRegistor.regist(
        "_xworker_thing_attribute_editor_HtmlEditor", "xworker.swt.xworker.HtmlEditor");
    ThingRegistor.regist(
        "_xworker_thing_attribute_editor_openDataListener",
        "xworker.ide.worldExplorer.swt.shareScript.ThingEditor/@scripts/@openDataListener");

    ThingRegistor.regist("_xworker.swt_model", "xworker.swt.model.Model");
    ThingRegistor.regist("_xworker_globalConfig", "_local.xworker.config.GlobalConfig");
    // log.info("ThingRegister regiseted all");
    // log.info("ThingRegister class=" + ThingRegistor.getThings());

    // 执行其他项目的初始化
    World.getInstance().runActionAsync("xworker.ide.config.Project/@actions/@initBackground", null);
  }
Exemple #3
0
  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;
  }