Example #1
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;
  }
Example #2
0
  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;
  }
Example #3
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);
  }