コード例 #1
0
ファイル: NoteSwtActions.java プロジェクト: RTM945/xworker
  public static void createItemAtTab(
      DataObject note, String agroup, CTabItem tabItem, ActionContext actionContext) {
    ActionContext ac = (ActionContext) tabItem.getData("actionContext");
    Tree tree = (Tree) ac.get("tree");
    String[] group = agroup.split("[.]");
    for (TreeItem item : tree.getItems()) {
      if (createToTreeItem(item, note, tabItem.getText(), agroup, group, 0, actionContext)) {
        return;
      }
    }

    if (!"".equals(agroup)) {
      TreeItem nodeItem = new TreeItem(tree, SWT.None);
      nodeItem.setData("type", "node");
      nodeItem.setText(group[0]);
      nodeItem.setData("group", agroup);
      nodeItem.setData("label", tabItem.getText());
      setImage(nodeItem, "nodeImage", actionContext);
      createToTreeItem(nodeItem, note, tabItem.getText(), agroup, group, 0, actionContext);
    } else {
      TreeItem newItem = new TreeItem(tree, SWT.None);
      newItem.setData("type", "note");
      newItem.setData(note);
      newItem.setText(note.getString("name"));
      newItem.setData("label", tabItem.getText());
      newItem.setData("group", agroup);
      setImage(newItem, "noteImage", actionContext);
      addTreeItemToNode(newItem, note);
    }
  }
コード例 #2
0
ファイル: RandomData.java プロジェクト: RTM945/xworker
  @SuppressWarnings("unchecked")
  public static void run(ActionContext actionContext) {
    Thing self = (Thing) actionContext.get("self");

    DataObject monitorTask = (DataObject) actionContext.get("monitorTask");
    // DataObject monitorTaskTask = (DataObject) actionContext.get("monitorTaskTask");
    List<DataObject> resources = (List<DataObject>) actionContext.get("resources");
    MonitorContext monitorContext = (MonitorContext) actionContext.get("monitorContext");

    Random random = new Random();
    for (DataObject resource : resources) {
      String dataNames = resource.getString("param1");
      double minValue = resource.getDouble("param2");
      double maxValue = resource.getDouble("param3");
      boolean toInt = resource.getBoolean("param4");

      for (String dataName : dataNames.split("[,]")) {
        double v = random.nextDouble();
        v = (maxValue - minValue) * v + minValue;

        DataObject data = new DataObject("xworker.app.monitor.dataobjects.MonitorData");
        data.put("taskThingPath", self.getMetadata().getPath());
        data.put("resourceId", resource.getString("resId"));
        data.put("dataName", dataName);
        if (toInt) {
          long lv = (long) v;
          data.put("value", String.valueOf(lv));
        } else {
          data.put("value", String.valueOf(v));
        }
        data.put("grabStartTime", monitorContext.getStartTime());
        data.put("grabEndTime", new Date());
        data.put("monitorId", monitorContext.monitor.get("id"));
        data.put("monitorTaskId", monitorTask.get("id"));
        data.put("monitorTaskResId", resource.get("id"));

        MonitorDataSaveTask.addCreateData(data);
      }
    }
  }
コード例 #3
0
ファイル: NoteSwtActions.java プロジェクト: RTM945/xworker
  public static boolean createToTreeItem(
      TreeItem item,
      DataObject note,
      String label,
      String agroup,
      String[] group,
      int groupIndex,
      ActionContext actionContext) {
    if ("node".equals(item.getData("type")) && group[groupIndex].equals(item.getText())) {
      if (groupIndex == group.length - 1) {
        TreeItem newItem = new TreeItem(item, SWT.None);
        newItem.setData("type", "note");
        newItem.setData(note);
        newItem.setText(note.getString("name"));
        newItem.setData("label", label);
        newItem.setData("group", agroup);
        setImage(newItem, "noteImage", actionContext);
        addTreeItemToNode(newItem, note);
        return true;
      } else if (groupIndex < group.length - 1) {
        boolean created = false;
        for (TreeItem childItem : item.getItems()) {
          if (createToTreeItem(
              childItem, note, label, agroup, group, groupIndex + 1, actionContext)) {
            created = true;
            return true;
          }
        }

        if (!created) {
          TreeItem nodeItem = new TreeItem(item, SWT.None);
          nodeItem.setData("type", "node");
          nodeItem.setText(group[groupIndex + 1]);
          setImage(nodeItem, "nodeImage", actionContext);
          nodeItem.setData("group", agroup);
          nodeItem.setData("label", label);
          return createToTreeItem(
              nodeItem, note, label, agroup, group, groupIndex + 1, actionContext);
        }
      }

      return false;
    } else {
      return false;
    }
  }
コード例 #4
0
ファイル: NoteSwtActions.java プロジェクト: RTM945/xworker
  /**
   * 在树上显示或替换节点。
   *
   * @param note
   * @param actionContext
   */
  @SuppressWarnings("unchecked")
  public static void updateItem(DataObject note, ActionContext actionContext) {
    String label = note.getString("label");
    if (label == null || "".equals(label)) {
      label = "默认";
    }

    String agroup = note.getString("agroup");
    if (agroup == null) {
      agroup = "";
    }

    String[] labels = label.split("[,]");
    String[] groups = agroup.split("[,]");

    List<TreeItem> items = (List<TreeItem>) note.get("__treeItems__");
    for (String lb : labels) {
      for (String gr : groups) {
        boolean have = false;

        if (items != null) {
          for (TreeItem item : items) {
            String l = (String) item.getData("label");
            String g = (String) item.getData("group");

            if (lb.equals(l) && g.equals(gr)) {
              have = true;
              item.setText(note.getString("name"));
              break;
            }
          }
        }

        if (!have) {
          createItem(note, lb, gr, actionContext);
        }
      }
    }

    // 移除没有的条目
    if (items != null) {
      for (TreeItem item : items) {
        String l = (String) item.getData("label");
        String g = (String) item.getData("group");

        boolean have = false;
        for (String lb : labels) {
          for (String gr : groups) {
            if (lb.equals(l) && g.equals(gr)) {
              have = true;
              break;
            }
          }

          if (have) {
            break;
          }
        }

        if (!have) {
          disposeItem(item);
        }
      }

      for (int i = 0; i < items.size(); i++) {
        if (items.get(i).isDisposed()) {
          items.remove(i);
          i--;
        }
      }
    }
  }