Skip to content

Instantly share code, notes, and snippets.

/GatewayHook Secret

Created Sep 29, 2016
Embed
What would you like to do?
package com.aplikom.testTable.gateway;
import java.sql.SQLException;
import org.apache.log4j.Logger;
import com.inductiveautomation.ignition.common.BundleUtil;
import com.inductiveautomation.ignition.common.licensing.LicenseState;
import com.inductiveautomation.ignition.gateway.model.AbstractGatewayModuleHook;
import com.inductiveautomation.ignition.gateway.model.GatewayContext;
import com.inductiveautomation.ignition.gateway.web.components.LabelConfigMenuNode;
import com.inductiveautomation.ignition.gateway.web.components.LinkConfigMenuNode;
public class GatewayHook extends AbstractGatewayModuleHook {
public static final String[] HCON_MENU_PATH = {"LabAgent Manager"};
public static GatewayContext context;
private final Logger log = Logger.getLogger(getClass());
@Override
public void setup(GatewayContext gatewayContext) {
context = gatewayContext;
BundleUtil.get().addBundle("testTable", getClass(), "testTable"); // this is the file with ressources
BundleUtil.get().addBundle("testTableRecord", getClass(), "testTableRecord");
verifySchema(context);
maybeCreateHCSettings(context);
initMenu();
}
@Override
public void shutdown() {
BundleUtil.get().removeBundle("testTable");
BundleUtil.get().removeBundle("testTableRecord");
context.getConfigMenuModel().removeConfigMenuNode(HCON_MENU_PATH);
}
@Override
public void startup(LicenseState licenseState) {
}
private void initMenu() {
// header is the top-level title in the gateway config page, e.g. System, Configuration, etc
LabelConfigMenuNode header = new LabelConfigMenuNode(HCON_MENU_PATH[0], "testTable.nav.header1");
header.setPosition(801);
context.getConfigMenuModel().addConfigMenuNode(null, header);
// Create the nodes/links that will exist under our parent nav header
//LinkConfigMenuNode tableNode = new LinkConfigMenuNode("Agent", "testTable.nav.table.header", testTableRecord.class);
//register our nodes with the context config menu model
context.getConfigMenuModel().addConfigMenuNode(HCON_MENU_PATH, new LinkConfigMenuNode("Agent", "testTable.nav.table.title", testTableRecordPage.class));
}
private void verifySchema(GatewayContext context) {
try {
//context.getSchemaUpdater().updatePersistentRecords(NotificationExampleTable.META);
context.getSchemaUpdater().updatePersistentRecords(testTableRecord.META);
} catch (SQLException e) {
log.error("Error verifying persistent record schemas for records.", e);
}
}
public void maybeCreateHCSettings(GatewayContext context) {
log.trace("Attempting to create HomeConnect Settings Record");
try {
testTableRecord tableRecord = context.getLocalPersistenceInterface().createNew(testTableRecord.META);
tableRecord.setId(0L);
tableRecord.setEnka("field one");
tableRecord.setDvojka("field two");
tableRecord.setTrojka("field three");
} catch (Exception e) {
log.error("Failed to establish table Record exists", e);
}
log.trace("Table Record Established");
}
}
nav.header1= LabAgent Manager
nav.table.title= Agent
package com.aplikom.testTable.gateway;
import com.inductiveautomation.ignition.gateway.localdb.persistence.Category;
import com.inductiveautomation.ignition.gateway.localdb.persistence.IdentityField;
import com.inductiveautomation.ignition.gateway.localdb.persistence.PersistentRecord;
import com.inductiveautomation.ignition.gateway.localdb.persistence.RecordMeta;
import com.inductiveautomation.ignition.gateway.localdb.persistence.StringField;
import simpleorm.dataset.SFieldFlags;
public class testTableRecord extends PersistentRecord{
public static final RecordMeta<testTableRecord> META =
new RecordMeta<testTableRecord>(testTableRecord.class,
"testTableRecord");
public static final IdentityField Id= new IdentityField(META);
public static final StringField Enka= new StringField(META, "Enka", SFieldFlags.SDESCRIPTIVE);
public static final StringField Dvojka= new StringField(META, "Dvojka", SFieldFlags.SDESCRIPTIVE);
public static final StringField Trojka= new StringField(META, "Trojka", SFieldFlags.SDESCRIPTIVE);
public Long getId() {
return getLong(Id);
}
public void setId(long id) {
setLong(Id, id);
}
public String getEnka() {
return getString(Enka);
}
public void setEnka(String enka) {
setString(Enka, enka);
}
public String getDvojka(){
return getString(Dvojka);
}
public void setDvojka(String dvojka){
setString(Dvojka, dvojka);
}
public String getTrojka(){
return getString(Trojka);
}
public void setTrojka (String trojka){
setString(Trojka, trojka);
}
static final Category Main = new Category("NotificationExampleTable.table.title", 0).include(Enka, Dvojka, Trojka);
@Override
public RecordMeta<?> getMeta() {
// TODO Auto-generated method stub
return META;
}
}
Id.Name= id
Id.Desc= id desc
Enka.Name= one
Enka.Desc= one desc
Dvojka.Name= two
Dvojka.Desc= two desc
Trojka.Name= three
Trojka.Desc= thre desc
package com.aplikom.testTable.gateway;
import com.inductiveautomation.ignition.gateway.localdb.persistence.RecordMeta;
import com.inductiveautomation.ignition.gateway.web.components.RecordActionTable;
import com.inductiveautomation.ignition.gateway.web.pages.IConfigPage;
public class testTableRecordPage extends RecordActionTable<testTableRecord>{
public testTableRecordPage(IConfigPage configPage) {
super(configPage);
// TODO Auto-generated constructor stub
}
public static final String[] PATH = {"LabAgent Manager", "Agent"};
@Override
protected RecordMeta<testTableRecord> getRecordMeta() {
// TODO Auto-generated method stub
return testTableRecord.META;
}
@Override
public String[] getMenuPath() {
// TODO Auto-generated method stub
return PATH;
}
@Override
protected String getNoRowsKey() {
String empty= "empty table";
return empty;
}
@Override
protected String getTitleKey() {
return PATH[1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment