use of com.serotonin.m2m2.view.chart.TableChartRenderer in project ma-core-public by infiniteautomation.
the class DefaultDataPointPropertiesTemplateFactory method createDefaultBinaryTemplate.
protected DataPointPropertiesTemplateVO createDefaultBinaryTemplate() {
DataPointPropertiesTemplateVO defaultBinaryPointTemplate = new DataPointPropertiesTemplateVO();
defaultBinaryPointTemplate.setXid(BINARY_XID);
defaultBinaryPointTemplate.setName("Binary");
defaultBinaryPointTemplate.setDataTypeId(DataTypes.BINARY);
defaultBinaryPointTemplate.setDefaultTemplate(true);
defaultBinaryPointTemplate.setDefinition(new DataPointPropertiesTemplateDefinition());
defaultBinaryPointTemplate.setChartColour("");
defaultBinaryPointTemplate.setPlotType(PlotTypes.STEP);
defaultBinaryPointTemplate.setLoggingType(LoggingTypes.ON_CHANGE);
defaultBinaryPointTemplate.setDefaultCacheSize(1);
BinaryTextRenderer binaryRenderer = new BinaryTextRenderer();
binaryRenderer.setOneColour("black");
binaryRenderer.setOneLabel("one");
binaryRenderer.setZeroColour("blue");
binaryRenderer.setZeroLabel("zero");
defaultBinaryPointTemplate.setTextRenderer(binaryRenderer);
TableChartRenderer binaryChartRenderer = new TableChartRenderer();
binaryChartRenderer.setLimit(10);
defaultBinaryPointTemplate.setChartRenderer(binaryChartRenderer);
return defaultBinaryPointTemplate;
}
use of com.serotonin.m2m2.view.chart.TableChartRenderer in project ma-core-public by infiniteautomation.
the class DataPointDetailsController method handleRequest.
@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws Exception {
User user = Common.getHttpUser();
int id = -1;
if (user.getEditPoint() != null)
id = user.getEditPoint().getId();
DataPointDao dataPointDao = DataPointDao.instance;
String idStr = request.getParameter("dpid");
DataPointVO point = null;
if (StringUtils.equals(idStr, "exception"))
throw new IOException("testing");
else if (StringUtils.equals(idStr, "permission-exception"))
throw new PermissionException(new TranslatableMessage("common.default", "Testing"), user);
if (StringUtils.isBlank(idStr)) {
// Check for pedid (point event detector id)
String pedStr = request.getParameter("pedid");
if (StringUtils.isBlank(pedStr)) {
// Check if an XID was provided.
String xid = request.getParameter("dpxid");
if (!StringUtils.isBlank(xid)) {
model.put("currentXid", xid);
point = dataPointDao.getDataPoint(xid);
id = point == null ? -2 : point.getId();
}
} else {
int pedid = Integer.parseInt(pedStr);
id = EventDetectorDao.instance.getSourceId(pedid, EventType.EventTypeNames.DATA_POINT);
}
} else
id = Integer.parseInt(idStr);
// Find accessible points for the goto list
List<DataPointSummary> userPoints = ControllerUtils.addPointListDataToModel(user, id, model);
// Get the point.
if (point == null && id != -1)
point = dataPointDao.getDataPoint(id);
if (point == null && id != -2 && /* -2 means an explicit XID was provided but not found */
!userPoints.isEmpty()) {
// Load at least 1 point, there may be many points but some might not actually load if thier data source DNE anymore
for (DataPointSummary userPoint : userPoints) {
point = dataPointDao.getDataPoint(userPoint.getId());
if (point != null)
break;
}
}
if (point != null) {
// Check permissions
Permissions.ensureDataPointReadPermission(user, point);
// Put the point in the model.
model.put("point", point);
// Get the users that have access to this point.
List<User> allUsers = UserDao.instance.getUsers();
List<Map<String, Object>> users = new LinkedList<>();
Map<String, Object> userData;
int accessType;
for (User mangoUser : allUsers) {
accessType = Permissions.getDataPointAccessType(mangoUser, point);
if (accessType != Permissions.DataPointAccessTypes.NONE) {
userData = new HashMap<>();
userData.put("user", mangoUser);
userData.put("accessType", accessType);
users.add(userData);
}
}
model.put("users", users);
// Determine whether the link to edit the point should be displayed
model.put("pointEditor", Permissions.hasDataSourcePermission(user, point.getDataSourceId()));
// Put the events in the model.
model.put("events", EventDao.instance.getEventsForDataPoint(id, user.getId()));
// Put the default history table count into the model. Default to 10.
int historyLimit = 10;
if (point.getChartRenderer() instanceof TableChartRenderer)
historyLimit = ((TableChartRenderer) point.getChartRenderer()).getLimit();
else if (point.getChartRenderer() instanceof ImageFlipbookRenderer)
historyLimit = ((ImageFlipbookRenderer) point.getChartRenderer()).getLimit();
model.put("historyLimit", historyLimit);
// Determine our image chart rendering capabilities.
if (ImageChartRenderer.getDefinition().supports(point.getPointLocator().getDataTypeId())) {
// This point can render an image chart. Carry on...
int periodType = Common.TimePeriods.DAYS;
int periodCount = 1;
if (point.getChartRenderer() instanceof ImageChartRenderer) {
ImageChartRenderer r = (ImageChartRenderer) point.getChartRenderer();
periodType = r.getTimePeriod();
periodCount = r.getNumberOfPeriods();
}
model.put("periodType", periodType);
model.put("periodCount", periodCount);
}
// Determine out flipbook rendering capabilities
if (ImageFlipbookRenderer.getDefinition().supports(point.getPointLocator().getDataTypeId()))
model.put("flipbookLimit", 10);
// Set the point in the session for the dwr.
user.setEditPoint(point);
model.put("currentXid", point.getXid());
model.put("hierPath", CollectionUtils.implode(dataPointDao.getPointHierarchy(true).getPath(id), " » "));
}
return null;
}
use of com.serotonin.m2m2.view.chart.TableChartRenderer in project ma-modules-public by infiniteautomation.
the class ChartRendererFactory method updateDataPoint.
/**
* @param data
* @param renderer
*/
public static void updateDataPoint(DataPointVO vo, BaseChartRendererModel<?> baseRendererModel) {
if (baseRendererModel == null)
// Nothing to do
return;
if (baseRendererModel.getType().equals(ImageChartRenderer.getDefinition().getName())) {
ImageChartRendererModel model = (ImageChartRendererModel) baseRendererModel;
ImageChartRenderer r = new ImageChartRenderer();
r.setNumberOfPeriods(model.getTimePeriod().getPeriods());
r.setTimePeriod(Common.TIME_PERIOD_CODES.getId(model.getTimePeriod().getPeriodType()));
vo.setChartRenderer(r);
} else if (baseRendererModel.getType().equals(ImageFlipbookRenderer.getDefinition().getName())) {
ImageFlipbookChartRendererModel model = (ImageFlipbookChartRendererModel) baseRendererModel;
ImageFlipbookRenderer r = new ImageFlipbookRenderer();
r.setLimit(model.getLimit());
vo.setChartRenderer(r);
} else if (baseRendererModel.getType().equals(StatisticsChartRenderer.getDefinition().getName())) {
StatisticsChartRendererModel model = (StatisticsChartRendererModel) baseRendererModel;
StatisticsChartRenderer r = new StatisticsChartRenderer();
r.setNumberOfPeriods(model.getTimePeriod().getPeriods());
r.setTimePeriod(Common.TIME_PERIOD_CODES.getId(model.getTimePeriod().getPeriodType()));
r.setIncludeSum(model.isIncludeSum());
vo.setChartRenderer(r);
} else if (baseRendererModel.getType().equals(TableChartRenderer.getDefinition().getName())) {
TableChartRendererModel model = (TableChartRendererModel) baseRendererModel;
TableChartRenderer r = new TableChartRenderer();
r.setLimit(model.getLimit());
vo.setChartRenderer(r);
} else {
throw new ShouldNeverHappenException("Unknown Chart Renderer: " + baseRendererModel.getType());
}
}
use of com.serotonin.m2m2.view.chart.TableChartRenderer in project ma-modules-public by infiniteautomation.
the class ChartRendererFactory method createModel.
/**
* @param vo
* @return
*/
public static BaseChartRendererModel<?> createModel(DataPointVO vo) {
ChartRenderer renderer = vo.getChartRenderer();
if (renderer == null)
return null;
if (renderer.getTypeName().equals(ImageChartRenderer.getDefinition().getName())) {
ImageChartRenderer r = (ImageChartRenderer) renderer;
TimePeriodModel tp = new TimePeriodModel(r.getNumberOfPeriods(), r.getTimePeriod());
ImageChartRendererModel model = new ImageChartRendererModel(tp);
return model;
} else if (renderer.getTypeName().equals(ImageFlipbookRenderer.getDefinition().getName())) {
ImageFlipbookRenderer r = (ImageFlipbookRenderer) renderer;
ImageFlipbookChartRendererModel model = new ImageFlipbookChartRendererModel(r.getLimit());
return model;
} else if (renderer.getTypeName().equals(StatisticsChartRenderer.getDefinition().getName())) {
StatisticsChartRenderer r = (StatisticsChartRenderer) renderer;
TimePeriodModel tp = new TimePeriodModel(r.getNumberOfPeriods(), r.getTimePeriod());
StatisticsChartRendererModel model = new StatisticsChartRendererModel(tp, r.isIncludeSum());
return model;
} else if (renderer.getTypeName().equals(TableChartRenderer.getDefinition().getName())) {
TableChartRenderer r = (TableChartRenderer) renderer;
TableChartRendererModel model = new TableChartRendererModel(r.getLimit());
return model;
} else {
throw new ShouldNeverHappenException("Unknown Chart Renderer: " + renderer.getDef().getName());
}
}
use of com.serotonin.m2m2.view.chart.TableChartRenderer in project ma-core-public by infiniteautomation.
the class DefaultDataPointPropertiesTemplateFactory method createDefaultAlphanumericTemplate.
protected DataPointPropertiesTemplateVO createDefaultAlphanumericTemplate() {
DataPointPropertiesTemplateVO defaultAlphanumericPointTemplate = new DataPointPropertiesTemplateVO();
defaultAlphanumericPointTemplate.setXid(ALPHANUMERIC_XID);
defaultAlphanumericPointTemplate.setName("Alphanumeric");
defaultAlphanumericPointTemplate.setDataTypeId(DataTypes.ALPHANUMERIC);
defaultAlphanumericPointTemplate.setDefaultTemplate(true);
defaultAlphanumericPointTemplate.setDefinition(new DataPointPropertiesTemplateDefinition());
defaultAlphanumericPointTemplate.setChartColour("");
defaultAlphanumericPointTemplate.setPlotType(PlotTypes.STEP);
defaultAlphanumericPointTemplate.setLoggingType(LoggingTypes.ON_CHANGE);
defaultAlphanumericPointTemplate.setDefaultCacheSize(1);
defaultAlphanumericPointTemplate.setTextRenderer(new PlainRenderer());
TableChartRenderer alphaChartRenderer = new TableChartRenderer();
alphaChartRenderer.setLimit(10);
defaultAlphanumericPointTemplate.setChartRenderer(alphaChartRenderer);
return defaultAlphanumericPointTemplate;
}
Aggregations