@MethodFilter public List<String> getViewComponentIds() { User user = Common.getUser(); List<String> result = new ArrayList<String>(); for (ViewComponent vc : user.getView().getViewComponents()) result.add(vc.getId()); return result; }
private List<ViewComponentState> getViewPointData(User user, View view, boolean edit) { WebContext webContext = WebContextFactory.get(); HttpServletRequest request = webContext.getHttpServletRequest(); List<ViewComponentState> states = new ArrayList<ViewComponentState>(); Map<String, Object> model = new HashMap<String, Object>(); RuntimeManager rtm = Common.ctx.getRuntimeManager(); for (ViewComponent viewComponent : view.getViewComponents()) { if (viewComponent.isCompoundComponent() && (edit || viewComponent.isVisible())) { CompoundComponent compoundComponent = (CompoundComponent) viewComponent; boolean imageChart = compoundComponent instanceof ImageChartComponent; // Add states for each of the children for (CompoundChild child : compoundComponent.getChildComponents()) addPointComponentState( child.getViewComponent(), rtm, model, request, view, user, states, edit, !imageChart); // Add a state for the compound component. ViewComponentState state = new ViewComponentState(); state.setId(compoundComponent.getId()); model.clear(); model.put("compoundComponent", compoundComponent); List<Map<String, Object>> childData = new ArrayList<Map<String, Object>>(); for (CompoundChild child : compoundComponent.getChildComponents()) { if (child.getViewComponent().isPointComponent()) { DataPointVO point = ((PointComponent) child.getViewComponent()).tgetDataPoint(); if (point != null) { Map<String, Object> map = new HashMap<String, Object>(); if (imageChart) map.put("name", point.getName()); else map.put("name", getMessage(child.getDescription())); map.put("point", point); map.put("pointValue", point.lastValue()); childData.add(map); } } } model.put("childData", childData); if (compoundComponent.hasInfo()) state.setInfo(generateContent(request, "compoundInfoContent.jsp", model)); if (imageChart) state.setContent( ((ImageChartComponent) compoundComponent).getImageChartData(getResourceBundle())); else if (!edit) state.setChart(compoundComponent.getImageChartData(getResourceBundle())); states.add(state); } else addPointComponentState(viewComponent, rtm, model, request, view, user, states, edit, true); } return states; }
@MethodFilter public ViewComponent addComponent(String componentName) { ViewComponent viewComponent = ViewComponent.newInstance(componentName); User user = Common.getUser(); View view = user.getView(); view.addViewComponent(viewComponent); viewComponent.validateDataPoint(user, false); return viewComponent; }
// // / // / View editing // / // @MethodFilter public Map<String, Object> editInit() { Map<String, Object> result = new HashMap<String, Object>(); User user = Common.getUser(); // Users with which to share. result.put("shareUsers", getShareUsers(user)); // Users already sharing with. result.put("viewUsers", user.getView().getViewUsers()); // View component types List<KeyValuePair> components = new ArrayList<KeyValuePair>(); for (ImplDefinition impl : ViewComponent.getImplementations()) components.add(new KeyValuePair(impl.getName(), getMessage(impl.getNameKey()))); result.put("componentTypes", components); // Available points List<DataPointVO> allPoints = new DataPointDao().getDataPoints(DataPointExtendedNameComparator.instance, false); List<DataPointBean> availablePoints = new ArrayList<DataPointBean>(); for (DataPointVO dataPoint : allPoints) { if (Permissions.hasDataPointReadPermission(user, dataPoint)) availablePoints.add(new DataPointBean(dataPoint)); } result.put("pointList", availablePoints); return result; }
private void addPointComponentState( ViewComponent viewComponent, RuntimeManager rtm, Map<String, Object> model, HttpServletRequest request, View view, User user, List<ViewComponentState> states, boolean edit, boolean add) { if (viewComponent.isPointComponent() && (edit || viewComponent.isVisible())) { PointComponent pointComponent = (PointComponent) viewComponent; DataPointRT dataPointRT = null; if (pointComponent.tgetDataPoint() != null) dataPointRT = rtm.getDataPoint(pointComponent.tgetDataPoint().getId()); ViewComponentState state = preparePointComponentState(pointComponent, user, dataPointRT, model, request); if (!edit) { if (pointComponent.isSettable()) { int access = view.getUserAccess(user); if (access == ShareUser.ACCESS_OWNER || access == ShareUser.ACCESS_SET) setChange(pointComponent.tgetDataPoint(), state, dataPointRT, request, model); } if (pointComponent.tgetDataPoint() != null) setChart(pointComponent.tgetDataPoint(), state, request, model); } if (add) states.add(state); model.clear(); } }
private ViewComponent getViewComponent(View view, String viewComponentId) { for (ViewComponent viewComponent : view.getViewComponents()) { if (viewComponent.getId().equals(viewComponentId)) return viewComponent; } return null; }