Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  public static void addTreeItemToNode(TreeItem item, DataObject note) {
    List<TreeItem> items = (List<TreeItem>) note.get("__treeItems__");
    if (items == null) {
      items = new ArrayList<TreeItem>();
      note.put("__treeItems__", items);
    }

    items.add(item);
  }
Ejemplo n.º 2
0
  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);
    }
  }
Ejemplo n.º 3
0
 @SuppressWarnings("unchecked")
 public static void removeNote(DataObject note, ActionContext actionContext) {
   List<TreeItem> items = (List<TreeItem>) note.get("__treeItems__");
   if (items != null) {
     for (TreeItem item : items) {
       disposeItem(item);
     }
   }
 }
Ejemplo n.º 4
0
  /**
   * 获取数据对象缓存。
   *
   * @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;
    }
  }
Ejemplo n.º 5
0
  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;
    }
  }
Ejemplo n.º 6
0
  /**
   * 在树上显示或替换节点。
   *
   * @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--;
        }
      }
    }
  }
Ejemplo n.º 7
0
  @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);
      }
    }
  }