Пример #1
0
  @Override
  public Thing getThing(String thingName) {
    // 需要先从缓存中读取,否则当遍历iterator时每次都会读取新的,是否和World中的缓存重复呢?
    Thing thing = ThingCache.get(thingName);
    if (thing != null) {
      if (thing.getMetadata().isRemoved()) {
        // 如事物的文件被外部改动或事物已给标记为删除,需要重新读取
        thing = null;
      } else {
        return thing;
      }
    }

    thing = doLoadThing(thingName);
    if (thing != null) {
      for (ThingManagerListener listener : listeners) {
        listener.loaded(this, thing);
      }

      for (ThingManagerListener listener :
          World.getInstance().getThingManagerListeners(getName())) {
        listener.loaded(this, thing);
      }
    }

    return thing;
  }
Пример #2
0
  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);
  }
Пример #3
0
  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;
  }
Пример #4
0
  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);
  }
Пример #5
0
  @Override
  public boolean save(Thing thing) {
    boolean removed = doSaveThing(thing);
    if (thing != null) {
      for (ThingManagerListener listener : listeners) {
        listener.saved(this, thing);
      }

      for (ThingManagerListener listener :
          World.getInstance().getThingManagerListeners(getName())) {
        listener.saved(this, thing);
      }
    }

    return removed;
  }
Пример #6
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);
  }
Пример #7
0
  private void openTablItem() {
    // IDE动作
    final ActionContainer actions = Designer.getExplorerActions();
    if (actions == null) {
      log.info("designer exlplorer actions is null");
      return;
    }

    // 要打开的事物
    String thingPath = "xworker.ui.function.FunctionRequestRunningShell/@dialogMainComposite";
    final String compositeId = "functionRequest_" + String.valueOf(functionRequest.hashCode());
    final String title = functionRequest.getThing().getMetadata().getLabel();
    final Thing thing = World.getInstance().getThing(thingPath);

    if (thing == null) {
      log.info("thing not exists, thingPath=" + thingPath);
      return;
    }

    Display display = Designer.getExplorerDisplay();
    final FunctionRequestUI ui = this;
    Runnable runnable =
        new Runnable() {
          public void run() {
            ActionContext ac = actions.getActionContext();
            Shell shell = (Shell) ac.get("shell");
            if (shell != null) {
              shell.forceActive();
            }

            // 创建UI
            CTabItem citem =
                (CTabItem)
                    actions.doAction(
                        "openCompoisteAtTab",
                        UtilMap.toMap(
                            new Object[] {
                              "compositeThing", thing, "title", title, "path", compositeId
                            }));
            if (citem != tabItem) {
              tabItem = citem;

              // 第一次初始化
              ActionContext actionContext = (ActionContext) tabItem.getData("actionContext");
              tabItem.addDisposeListener(
                  new DisposeListener() {
                    @Override
                    public void widgetDisposed(DisposeEvent arg0) {
                      FunctionRequestUIFactory.removeUI(functionRequest);
                    }
                  });

              // 注册Handler
              ActionContainer actions = (ActionContainer) actionContext.get("dialogActions");
              actions.doAction(
                  "initFunctionRequest",
                  actionContext,
                  UtilMap.toMap(new Object[] {"functionRequestUI", ui}));
            }
          }
        };

    display.syncExec(runnable);
  }