/v3.2/nimbits-tds/src/com/nimbits/client/panels/PointPanel.java

http://nimbits-server.googlecode.com/ · Java · 887 lines · 619 code · 203 blank · 65 comment · 51 complexity · d977ac93d8c452fbda1b62f8e728b2df MD5 · raw file

  1. /*
  2. * Copyright (c) 2010 Tonic Solutions LLC.
  3. *
  4. * http://www.nimbits.com
  5. *
  6. *
  7. * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * http://www.gnu.org/licenses/gpl.html
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  12. */
  13. package com.nimbits.client.panels;
  14. import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
  15. import com.extjs.gxt.ui.client.Style.Orientation;
  16. import com.extjs.gxt.ui.client.Style.Scroll;
  17. import com.extjs.gxt.ui.client.event.*;
  18. import com.extjs.gxt.ui.client.widget.*;
  19. import com.extjs.gxt.ui.client.widget.button.Button;
  20. import com.extjs.gxt.ui.client.widget.form.*;
  21. import com.extjs.gxt.ui.client.widget.layout.FillLayout;
  22. import com.extjs.gxt.ui.client.widget.layout.FormData;
  23. import com.extjs.gxt.ui.client.widget.layout.TableData;
  24. import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
  25. import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
  26. import com.google.gwt.core.client.GWT;
  27. import com.google.gwt.user.client.Window;
  28. import com.google.gwt.user.client.rpc.AsyncCallback;
  29. import com.google.gwt.user.client.ui.AbstractImagePrototype;
  30. import com.google.gwt.user.client.ui.Hyperlink;
  31. import com.google.gwt.user.client.ui.Image;
  32. import com.google.gwt.user.client.ui.Label;
  33. import com.nimbits.client.controls.PointCombo;
  34. import com.nimbits.client.exception.NimbitsException;
  35. import com.nimbits.client.exceptions.CalculationFailedException;
  36. import com.nimbits.client.icons.Icons;
  37. import com.nimbits.client.model.Const;
  38. import com.nimbits.client.model.GxtPointModel;
  39. import com.nimbits.client.model.point.Point;
  40. import com.nimbits.client.model.point.PointModel;
  41. import com.nimbits.client.service.datapoints.PointService;
  42. import com.nimbits.client.service.datapoints.PointServiceAsync;
  43. import com.nimbits.client.service.recordedvalues.RecordedValueService;
  44. import com.nimbits.client.service.recordedvalues.RecordedValueServiceAsync;
  45. import java.util.ArrayList;
  46. import java.util.List;
  47. class PointPanel extends LayoutContainer {
  48. private final Button btnHelp = new Button("Help");
  49. private final Button btnTestCalc = new Button("Test Calc");
  50. private final Button buttonDelete = new Button("Delete Point");
  51. private final CheckBox check2 = new CheckBox();
  52. private final CheckBox checkFB = new CheckBox();
  53. private final CheckBox checkIM = new CheckBox();
  54. private final CheckBox checkTwitter = new CheckBox();
  55. private final CheckBox alertToFacebookCheckbox = new CheckBox();
  56. private final CheckBox alertToEmailCheckbox = new CheckBox();
  57. private final CheckBox he = new CheckBox();
  58. //idle
  59. private final CheckBox idleOn = new CheckBox();
  60. private final CheckBox ignoreCompressedValues = new CheckBox();
  61. private final CheckBox im = new CheckBox();
  62. private final CheckBox le = new CheckBox();
  63. private final CheckBox tw = new CheckBox();
  64. private final Hyperlink hyperlinkRest = new Hyperlink("New hyperlink", false, "newHistoryToken");
  65. private final Hyperlink uuidLink = new Hyperlink("New hyperlink", false, "newHistoryToken");
  66. private final LabelField lblfldTips = new LabelField("Whenever the <b>Trigger</b> data point records a new value, the formula entered above will be executed. The resulting value will then be stored in the <b>Target</b> data point. Your formula can contain a <b>lowercase</b> x, y, and z variable. The current value of the point assigned to that variable will be used. Supported symbols are: *, +, -, *, /, ^, %, cos, sin, tan, acos, asin, atan, sqrt, sqr, log, min, max, ceil, floor, abs, neg, rndr. ");
  67. private final Label lblQrCodesThe = new Label("QR Codes: The QR Bar code below represents a link to a data screen for this point. Any device capable of reading barcodes can read this, such as a barcode app on your smart phone.");
  68. private final Label lblTheQrBarcode = new Label("The QR Barcode above links to this URL, which you can also use as a universal way to view this point's data:");
  69. private final Label lblYouCanPull = new Label("You can pull this point's data using http post and getInstance commands using the REST API Web service. This example uses this points unique UUID, but there are many ways to access this point's data. See the REST API documents to learn more. ");
  70. private final List<PointDeletedListener> pointDeletedListeners = new ArrayList<PointDeletedListener>();
  71. private final List<PointUpdatedListener> pointUpdatedListeners = new ArrayList<PointUpdatedListener>();
  72. //General Properties
  73. private final NumberField compression = new NumberField();
  74. private final NumberField delay = new NumberField();
  75. private final NumberField expires = new NumberField();
  76. //Alerts
  77. private final NumberField high = new NumberField();
  78. private final NumberField idleMinutes = new NumberField();
  79. private final NumberField lat = new NumberField();
  80. private final NumberField lng = new NumberField();
  81. private final NumberField low = new NumberField();
  82. // private final TextField<String> High = new TextField<String>();
  83. ///private final TextField<String> Low = new TextField<String>();
  84. private final NumberField targetValue = new NumberField();
  85. private PointCombo X;
  86. private PointCombo Y;
  87. private PointCombo Z;
  88. //calcs
  89. private final PointCombo target = new PointCombo();
  90. // private final Icons ICONS = GWT.create(Icons.class);
  91. // private Point point;
  92. // void setPoint(Point aPoint) {
  93. // this.point = aPoint;
  94. // }
  95. private final PointServiceAsync pointService = GWT.create(PointService.class);
  96. private final SeparatorToolItem separatorToolItem = new SeparatorToolItem();
  97. private final static String FORM_HEIGHT = "450";
  98. private final static String MAIN_WIDTH = "450";
  99. private final TextArea description = new TextArea();
  100. private final TextField<String> formula = new TextField<String>();
  101. private final TextField<String> trigger = new TextField<String>();
  102. private final TextField<String> unit = new TextField<String>();
  103. private final Point originalPoint;
  104. private Point point;
  105. public PointPanel(final Point x) throws NimbitsException {
  106. originalPoint = x;
  107. loadForm();
  108. }
  109. private void loadForm() throws NimbitsException {
  110. pointService.getPointByID(originalPoint.getId(), new AsyncCallback<Point>() {
  111. @Override
  112. public void onFailure(Throwable caught) {
  113. GWT.log(caught.getMessage());
  114. }
  115. @Override
  116. public void onSuccess(final Point p) {
  117. buildForm(p);
  118. }
  119. private void buildForm(final Point p) {
  120. point = p;
  121. X = new PointCombo();
  122. Y = new PointCombo();
  123. Z = new PointCombo();
  124. setSize(FORM_HEIGHT, "475");
  125. setLayout(new FillLayout(Orientation.VERTICAL));
  126. //setLayout(new FitLayout());
  127. com.google.gwt.user.client.ui.VerticalPanel verticalPanel = new com.google.gwt.user.client.ui.VerticalPanel();
  128. add(verticalPanel);
  129. verticalPanel.setSize("460", "450");
  130. verticalPanel.setBorderWidth(0);
  131. ToolBar mainToolBar = mainToolBar();
  132. verticalPanel.add(mainToolBar);
  133. TabPanel tabPanel = new TabPanel();
  134. TabItem tabAlerts = new TabItem("Alerts");
  135. TabItem tabGeneral = new TabItem("General");
  136. tabGeneral.setHeight("425");
  137. // TabItem tabRelay = new TabItem("Relay");
  138. TabItem tabCalcs = new TabItem("Calculations");
  139. TabItem tabIdle = new TabItem("Idle Alarm");
  140. TabItem tabLinks = new TabItem("Links");
  141. //tabGeneral.setWidth("450");
  142. verticalPanel.add(tabPanel);
  143. tabPanel.setSize(FORM_HEIGHT, "435");
  144. tabPanel.add(tabGeneral);
  145. tabPanel.add(tabAlerts);
  146. tabPanel.add(tabCalcs);
  147. tabPanel.add(tabIdle);
  148. // tabPanel.add(tabRelay);
  149. tabPanel.add(tabLinks);
  150. tabAlerts.add(alertForm());
  151. tabGeneral.add(generalForm());
  152. tabCalcs.add(calcForm());
  153. // tabRelay.add(relayForm());
  154. tabLinks.add(linkForm());
  155. tabIdle.add(idleForm());
  156. tabPanel.addListener(Events.Select,
  157. new Listener<BaseEvent>() {
  158. public void handleEvent(BaseEvent tpe) {
  159. if (!(point.getTarget() == 0)) {
  160. target.setValue(target.getStore().findModel(Const.PARAM_ID,
  161. point.getTarget()));
  162. }
  163. if (!(point.getX() == 0)) {
  164. X.setValue(X.getStore().findModel(Const.PARAM_ID, point.getX()));
  165. X.repaint();
  166. } else {
  167. GxtPointModel xModel = new GxtPointModel(point);
  168. X.setValue(xModel);
  169. }
  170. if (!(point.getY() == 0)) {
  171. Y.setValue(Y.getStore().findModel(Const.PARAM_ID, point.getY()));
  172. }
  173. if (!(point.getZ() == 0)) {
  174. Z.setValue(Z.getStore().findModel(Const.PARAM_ID, point.getZ()));
  175. }
  176. //Window.alert("d");
  177. }
  178. });
  179. add(verticalPanel);
  180. doLayout();
  181. }
  182. });
  183. }
  184. ToolBar mainToolBar() {
  185. ToolBar toolBar = new ToolBar();
  186. toolBar.setHeight("");
  187. buttonDelete.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.delete()));
  188. final Listener<MessageBoxEvent> deletePointListener = new Listener<MessageBoxEvent>() {
  189. public void handleEvent(MessageBoxEvent ce) {
  190. Button btn = ce.getButtonClicked();
  191. if (btn.getText().equals("Yes")) {
  192. try {
  193. pointService.deletePoint(point, new AsyncCallback<Void>() {
  194. @Override
  195. public void onFailure(Throwable caught) {
  196. }
  197. @Override
  198. public void onSuccess(Void result) {
  199. notifyPointDeletedListener(point);
  200. Window.alert(Const.MESSAGE_POINT_DELETED);
  201. }
  202. });
  203. } catch (NimbitsException e) {
  204. GWT.log(e.getMessage(), e);
  205. }
  206. }
  207. }
  208. };
  209. buttonDelete.addSelectionListener(new SelectionListener<ButtonEvent>() {
  210. public void componentSelected(ButtonEvent ce) {
  211. MessageBox.confirm("Confirm", "Are you sure you want delete this point? Doing so will permanently delete all historical data for this point.", deletePointListener);
  212. }
  213. });
  214. Button buttonSave = new Button("Save");
  215. buttonSave.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.SaveAll()));
  216. buttonSave.addSelectionListener(new SelectionListener<ButtonEvent>() {
  217. public void componentSelected(ButtonEvent ce) {
  218. try {
  219. savePoint();
  220. } catch (NimbitsException e) {
  221. GWT.log(e.getMessage(), e);
  222. }
  223. }
  224. });
  225. toolBar.add(buttonSave);
  226. btnTestCalc.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.Play()));
  227. btnTestCalc.addSelectionListener(new SelectionListener<ButtonEvent>() {
  228. public void componentSelected(ButtonEvent ce) {
  229. try {
  230. runEquation(true);
  231. } catch (CalculationFailedException e) {
  232. Window.alert(e.getMessage());
  233. }
  234. }
  235. });
  236. toolBar.add(btnTestCalc);
  237. toolBar.add(buttonDelete);
  238. buttonDelete.setWidth("90px");
  239. btnHelp.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.Help()));
  240. btnHelp.addSelectionListener(new SelectionListener<ButtonEvent>() {
  241. public void componentSelected(ButtonEvent ce) {
  242. Window.open("https://code.google.com/p/nimbits-server/wiki/NimbitsWiki", "", "");
  243. }
  244. });
  245. toolBar.add(btnHelp);
  246. toolBar.add(separatorToolItem);
  247. separatorToolItem.setWidth("25px");
  248. return toolBar;
  249. }
  250. private void notifyPointDeletedListener(Point p) {
  251. for (PointDeletedListener pointDeletedListener : pointDeletedListeners) {
  252. pointDeletedListener.onPointDeleted(p);
  253. }
  254. }
  255. // private Point point() {
  256. //
  257. // return point;
  258. //
  259. // }
  260. private void savePoint() throws NimbitsException {
  261. final MessageBox box = MessageBox.wait("Progress",
  262. "Saving your data, please wait...", "Saving...");
  263. box.show();
  264. //General
  265. point.setCompression(compression.getValue().doubleValue());
  266. point.setIgnoreIncomingCompressedValues(ignoreCompressedValues.getValue());
  267. point.setExpire(expires.getValue().intValue());
  268. point.setUnit(unit.getValue());
  269. point.setDescription(description.getValue());
  270. point.setPublic(check2.getValue());
  271. point.setSendIM(checkIM.getValue());
  272. point.setSendTweet(checkTwitter.getValue());
  273. point.setPostToFacebook(checkFB.getValue());
  274. point.setTargetValue(targetValue.getValue().doubleValue());
  275. //Alerts
  276. int d = delay.getValue().intValue();
  277. point.setAlarmDelay(d);
  278. point.setHighAlarm(high.getValue().doubleValue());
  279. point.setLowAlarm(low.getValue().doubleValue());
  280. point.setHighAlarmOn(he.getValue());
  281. point.setLowAlarmOn(le.getValue());
  282. point.setAlarmToFacebook(alertToFacebookCheckbox.getValue());
  283. point.setAlarmToEmail(alertToEmailCheckbox.getValue());
  284. point.setSendAlarmIM(im.getValue());
  285. point.setSendAlarmTweet(tw.getValue());
  286. //idlealarm
  287. point.setIdleAlarmOn(idleOn.getValue());
  288. point.setIdleSeconds(idleMinutes.getValue().intValue() * 60);
  289. point.setIdleAlarmSent(false);
  290. if (!(lng.getValue() == null)) {
  291. point.setLng(lng.getValue().doubleValue());
  292. }
  293. if (!(lat.getValue() == null)) {
  294. point.setLat(lat.getValue().doubleValue());
  295. }
  296. //calcs
  297. point.setFormula(formula.getValue());
  298. if (!(target.getValue() == null)) {
  299. point.setTarget(target.getPoint().getId());
  300. } else {
  301. point.setTarget(0);
  302. }
  303. if (!(X.getValue() == null)) {
  304. point.setX(X.getPoint().getId());
  305. } else {
  306. point.setX(0);
  307. }
  308. if (!(Y.getValue() == null)) {
  309. point.setY(Y.getPoint().getId());
  310. } else {
  311. point.setY(0);
  312. }
  313. if (!(Z.getValue() == null)) {
  314. point.setZ(Z.getPoint().getId());
  315. } else {
  316. point.setZ(0);
  317. }
  318. pointService.updatePoint(point, new AsyncCallback<Point>() {
  319. @Override
  320. public void onFailure(Throwable caught) {
  321. MessageBox.alert("Alert", caught.getMessage(), null);
  322. box.close();
  323. }
  324. @Override
  325. public void onSuccess(Point result) {
  326. MessageBox.alert("Message", "Point Updated", null);
  327. notifyPointUpdatedListener(point);
  328. box.close();
  329. }
  330. });
  331. }
  332. private void notifyPointUpdatedListener(Point p) {
  333. for (PointUpdatedListener pointUpdatedListener : pointUpdatedListeners) {
  334. pointUpdatedListener.onPointUpdated(p);
  335. }
  336. }
  337. private boolean runEquation(final boolean showFeedback) throws CalculationFailedException {
  338. final PointModel testPoint = new PointModel();
  339. final RecordedValueServiceAsync dataService;
  340. dataService = GWT.create(RecordedValueService.class);
  341. if (target.getValue() == null) {
  342. if (showFeedback) {
  343. final Dialog d = new Dialog();
  344. d.setHeading("Error");
  345. d.setButtons(Dialog.OK);
  346. d.setBodyStyleName("pad-text");
  347. d.addText("You must select a target that the result of this calculation will be recorded to.");
  348. d.setScrollMode(Scroll.AUTO);
  349. d.setHideOnButtonClick(true);
  350. d.show();
  351. }
  352. return false;
  353. }
  354. if (target.getText().equals(point.getName().getValue())) {
  355. if (showFeedback) {
  356. final Dialog d = new Dialog();
  357. d.setHeading("Error");
  358. d.setButtons(Dialog.OK);
  359. d.setBodyStyleName("pad-text");
  360. d.addText("Infinite Loop Error");
  361. d.setScrollMode(Scroll.AUTO);
  362. d.setHideOnButtonClick(true);
  363. d.show();
  364. }
  365. return false;
  366. }
  367. if (formula.getValue() == null) {
  368. if (showFeedback) {
  369. final Dialog d = new Dialog();
  370. d.setHeading("Error");
  371. d.setButtons(Dialog.OK);
  372. d.setBodyStyleName("pad-text");
  373. d.addText("Please enter an equation.");
  374. d.setScrollMode(Scroll.AUTO);
  375. d.setHideOnButtonClick(true);
  376. d.show();
  377. }
  378. return false;
  379. }
  380. testPoint.setFormula(formula.getValue());
  381. if (X.getValue() != null) {
  382. testPoint.setX(X.getValue().getId());
  383. }
  384. if (Y.getValue() != null) {
  385. testPoint.setY(Y.getValue().getId());
  386. }
  387. if (Z.getValue() != null) {
  388. testPoint.setZ(Z.getValue().getId());
  389. }
  390. try {
  391. dataService.solveEquation(testPoint, new AsyncCallback<Double>() {
  392. @Override
  393. public void onFailure(Throwable caught) {
  394. if (showFeedback) {
  395. final Dialog simple = new Dialog();
  396. simple.setHeading("formula Error");
  397. simple.setButtons(Dialog.OK);
  398. simple.setBodyStyleName("pad-text");
  399. simple.addText(caught.getMessage());
  400. simple.setScrollMode(Scroll.AUTO);
  401. simple.setHideOnButtonClick(true);
  402. simple.show();
  403. }
  404. }
  405. @Override
  406. public void onSuccess(Double result) {
  407. if (showFeedback) {
  408. final Dialog d = new Dialog();
  409. d.setHeading("formula Success");
  410. d.setButtons(Dialog.OK);
  411. d.setBodyStyleName("pad-text");
  412. d.addText("Result: " + result);
  413. d.setScrollMode(Scroll.AUTO);
  414. d.setHideOnButtonClick(true);
  415. d.show();
  416. }
  417. }
  418. });
  419. } catch (NimbitsException e) {
  420. GWT.log(e.getMessage());
  421. }
  422. return true;
  423. }
  424. private FormPanel alertForm() {
  425. FormPanel simple = new FormPanel();
  426. simple.setHeaderVisible(false);
  427. simple.setFrame(false);
  428. simple.setBorders(false);
  429. simple.setBodyBorder(false);
  430. simple.setSize(MAIN_WIDTH, FORM_HEIGHT);
  431. high.setFieldLabel("High Value");
  432. high.setValue(point.getHighAlarm());
  433. high.setAllowBlank(false);
  434. simple.add(high);
  435. he.setBoxLabel("High alert enabled");
  436. he.setLabelSeparator("");
  437. he.setValue(point.isHighAlarmOn());
  438. // he.setFieldLabel("Enabled");
  439. simple.add(he);
  440. low.setFieldLabel("Low Value");
  441. low.setAllowBlank(false);
  442. low.setValue(point.getLowAlarm());
  443. simple.add(low);
  444. le.setBoxLabel("Low alert enabled");
  445. le.setLabelSeparator("");
  446. le.setValue(point.isLowAlarmOn());
  447. simple.add(le, new FormData("0% -395"));
  448. alertToFacebookCheckbox.setBoxLabel("Post alerts to facebook");
  449. alertToFacebookCheckbox.setLabelSeparator("");
  450. alertToFacebookCheckbox.setValue(point.getAlarmToFacebook());
  451. simple.add(alertToFacebookCheckbox);
  452. alertToEmailCheckbox.setBoxLabel("Send alerts to email");
  453. alertToEmailCheckbox.setLabelSeparator("");
  454. alertToEmailCheckbox.setValue(point.isAlarmToEmail());
  455. simple.add(alertToEmailCheckbox);
  456. im.setBoxLabel("Send alerts to IM");
  457. im.setLabelSeparator("");
  458. im.setValue(point.getSendAlarmIM());
  459. simple.add(im);
  460. tw.setBoxLabel("Post alerts to twitter");
  461. tw.setLabelSeparator("");
  462. tw.setValue(point.getSendAlarmTweet());
  463. simple.add(tw);
  464. // final TextField<Integer> delay = new TextField<Integer>();
  465. delay.setAllowBlank(false);
  466. delay.setFieldLabel("Repeat email Delay (Minutes)");
  467. delay.setValue(point.getAlarmDelay());
  468. simple.add(delay);
  469. return simple;
  470. }
  471. //general
  472. private FormPanel generalForm() {
  473. //ContentPanel vp = new ContentPanel();
  474. // vpoint.setHeaderVisible(false);
  475. // vpoint.setFrame(false);
  476. // vpoint.setBorders(false);
  477. // vpoint.setBodyBorder(false);
  478. FormPanel simple = new FormPanel();
  479. simple.setHeaderVisible(false);
  480. simple.setFrame(false);
  481. //simple.setWidth(600);
  482. simple.setBorders(false);
  483. simple.setBodyBorder(false);
  484. simple.setSize("450", "408");
  485. Image i = new Image();
  486. // i.setStyleName("#images-view .thumb img");
  487. i.setUrl("http://chart.apis.google.com/chart?chs=100x100&cht=qr&chl=" + "http://" + point.getHost() + "?uuid="
  488. + point.getUuid() + "&chld=L|1&choe=UTF-8");
  489. //i.setSize("75px", "75px");
  490. HorizontalPanel titlebar = new HorizontalPanel();
  491. // String host;
  492. //
  493. // if (point.getHost().contains("127.0.0.1")) {
  494. // host = point.getHost() + ":8888";
  495. // } else {
  496. // host = point.getHost();
  497. // }
  498. String host = GWT.getModuleBaseURL();
  499. String ht = "<A href = \"http://" + host + "?uuid=" + point.getUuid() + "\" target=\"_blank\"> UUID:" + point.getUuid() + "</A>";
  500. titlebar.add(i);
  501. VerticalPanel verticalPanel = new VerticalPanel();
  502. verticalPanel.setSpacing(10);
  503. verticalPanel.setHeight(80);
  504. Html h = new Html(ht);
  505. verticalPanel.add(h);
  506. TableData tdVerticalPanel = new TableData();
  507. tdVerticalPanel.setHorizontalAlign(HorizontalAlignment.CENTER);
  508. tdVerticalPanel.setMargin(5);
  509. titlebar.add(verticalPanel, tdVerticalPanel);
  510. // vpoint.add(titlebar);
  511. // titlebar.setSize("450", "100");
  512. compression.setFieldLabel("Compression");
  513. compression.setValue(point.getCompression());
  514. compression.setAllowBlank(false);
  515. simple.add(compression);
  516. ignoreCompressedValues.setFieldLabel("Apply compression to incoming data");
  517. ignoreCompressedValues.setValue(point.getIgnoreIncomingCompressedValues());
  518. //simple.add(ignoreCompressedValues);
  519. targetValue.setFieldLabel("Target");
  520. targetValue.setValue(point.getTargetValue());
  521. targetValue.setAllowBlank(false);
  522. simple.add(targetValue);
  523. expires.setFieldLabel("Expires (days)");
  524. expires.setValue(point.getExpire());
  525. expires.setAllowBlank(false);
  526. simple.add(expires);
  527. unit.setFieldLabel("Unit of Measure");
  528. unit.setValue(point.getUnit());
  529. unit.setAllowBlank(true);
  530. simple.add(unit);
  531. check2.setBoxLabel("Public");
  532. check2.setValue(point.isPublic());
  533. checkFB.setBoxLabel("facebook");
  534. checkFB.setValue(point.isPostToFacebook());
  535. checkIM.setBoxLabel("Instant Message");
  536. checkIM.setValue(point.getSendIM());
  537. checkTwitter.setBoxLabel("Twitter");
  538. checkTwitter.setValue(point.getSendTweet());
  539. CheckBoxGroup checkGroup = new CheckBoxGroup();
  540. checkGroup.setFieldLabel("Sharing");
  541. checkGroup.add(check2);
  542. simple.add(checkGroup);
  543. CheckBoxGroup checkGroupFB = new CheckBoxGroup();
  544. checkGroupFB.setFieldLabel("Messaging");
  545. checkGroupFB.add(checkFB);
  546. checkFB.setWidth("108px");
  547. checkGroupFB.add(checkIM);
  548. checkIM.setWidth("132px");
  549. checkGroupFB.add(checkTwitter);
  550. checkTwitter.setWidth("82px");
  551. simple.add(checkGroupFB, new FormData("-115"));
  552. checkGroupFB.setWidth("400");
  553. // simple.add(checkIM, formData);
  554. lat.setFieldLabel("Source latitude");
  555. if (point.getLat() != 0) {
  556. lat.setValue(point.getLat());
  557. }
  558. lat.setAllowBlank(true);
  559. simple.add(lat);
  560. lng.setFieldLabel("Source longitude");
  561. if (point.getLng() != 0) {
  562. lng.setValue(point.getLng());
  563. }
  564. lng.setAllowBlank(true);
  565. simple.add(lng);
  566. description.setPreventScrollbars(true);
  567. description.setValue(point.getDescription());
  568. description.setFieldLabel("Description");
  569. simple.add(description, new FormData("-20"));
  570. description.setSize("400", "100");
  571. return simple;
  572. }
  573. private FormPanel calcForm() {
  574. FormPanel simple = new FormPanel();
  575. simple.setHeaderVisible(false);
  576. simple.setFrame(false);
  577. simple.setBorders(false);
  578. simple.setBodyBorder(false);
  579. simple.setSize(MAIN_WIDTH, FORM_HEIGHT);
  580. trigger.setReadOnly(true);
  581. trigger.setValue(point.getName().getValue());
  582. trigger.setFieldLabel("Trigger:");
  583. simple.add(trigger);
  584. formula.setFieldLabel("formula");
  585. formula.setAllowBlank(false);
  586. formula.setValue(point.getFormula());
  587. simple.add(formula);
  588. target.setEditable(true);
  589. target.setAllowBlank(true);
  590. target.setFieldLabel("Target:");
  591. target.setForceSelection(true);
  592. target.setReadOnly(false);
  593. // target.setValue(point.getTarget()));
  594. // if (point.getTarget() > 0)
  595. // {
  596. // for (Point p : target.getItemSelector().)
  597. // }
  598. X.setEditable(true);
  599. X.setFieldLabel("x");
  600. X.setAllowBlank(true);
  601. Y.setAllowBlank(true);
  602. Y.setEditable(true);
  603. Y.setFieldLabel("y");
  604. Z.setEditable(true);
  605. Z.setAllowBlank(true);
  606. Z.setFieldLabel("z");
  607. simple.add(target);
  608. simple.add(X);
  609. simple.add(Y);
  610. simple.add(Z);
  611. lblfldTips.setFieldLabel("Tips:");
  612. simple.add(lblfldTips, new FormData("100%"));
  613. return simple;
  614. }
  615. private VerticalPanel linkForm() {
  616. VerticalPanel simple = new VerticalPanel();
  617. String u = Window.Location.getHost();
  618. String infoURL = "http://" + u + "?" +
  619. "uuid=" + point.getUuid();
  620. String bcURL;
  621. bcURL = "http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=" +
  622. infoURL +
  623. "&chld=L|1&choe=UTF-8";
  624. final Image image = new Image(bcURL);
  625. simple.add(lblQrCodesThe);
  626. simple.add(image);
  627. image.setSize("100", "100");
  628. image.setUrl(bcURL);
  629. simple.add(lblTheQrBarcode);
  630. uuidLink.setHeight("44px");
  631. uuidLink.setHTML("UUID Link");
  632. uuidLink.setText(infoURL);
  633. simple.add(uuidLink);
  634. simple.add(lblYouCanPull);
  635. hyperlinkRest.setText("http://" + u + "/service/currentvalue?uuid=" + point.getUuid());
  636. simple.add(hyperlinkRest);
  637. return simple;
  638. }
  639. private FormPanel idleForm() {
  640. FormPanel simple = new FormPanel();
  641. simple.setHeaderVisible(false);
  642. simple.setFrame(false);
  643. simple.setBorders(false);
  644. simple.setBodyBorder(false);
  645. simple.setSize(MAIN_WIDTH, FORM_HEIGHT);
  646. idleOn.setBoxLabel("Alarm On");
  647. idleOn.setLabelSeparator("");
  648. idleOn.setValue(point.isIdleAlarmOn());
  649. idleMinutes.setFieldLabel("Idle Minutes");
  650. idleMinutes.setValue(point.getIdleSeconds() / 60);
  651. Html h = new Html();
  652. h.setHtml("<P>Enter the number of minutes needed to elapse for a point to be considered idle if it does not recieve a value. </P>" +
  653. "<BR><P>If a point does not record a value in the elapsed number of minutes, an email alert will be sent to you. </P>" +
  654. "<BR><P>Please note: Regardless of the idle setting, you may not got an alert for 1 to 30 minutes after the elapsed time passes, depending on system load.</P><BR><BR>");
  655. simple.add(h);
  656. simple.add(idleMinutes);
  657. simple.add(idleOn);
  658. if (point.isIdleAlarmOn()) {
  659. Html h2 = new Html();
  660. String s = "<P>Based on the current settings, this point is currently ";
  661. if (point.getIdleAlarmSent()) {
  662. s += "idle.";
  663. } else {
  664. s += "not idle.";
  665. }
  666. s += " Last recorded timestamp was: " + point.getLastRecordedTimestamp() + "</p>";
  667. h2.setHtml(s);
  668. simple.add(h2);
  669. }
  670. return simple;
  671. }
  672. public interface PointDeletedListener {
  673. void onPointDeleted(Point p);
  674. }
  675. public void addPointDeletedListeners(PointDeletedListener listener) {
  676. pointDeletedListeners.add(listener);
  677. }
  678. public interface PointUpdatedListener {
  679. void onPointUpdated(Point p);
  680. }
  681. public void addPointUpdatedListeners(PointUpdatedListener listener) {
  682. pointUpdatedListeners.add(listener);
  683. }
  684. }