/v3.2/nimbits-tds/src/com/nimbits/client/panels/PointPanel.java
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 14package com.nimbits.client.panels; 15 16import com.extjs.gxt.ui.client.Style.HorizontalAlignment; 17import com.extjs.gxt.ui.client.Style.Orientation; 18import com.extjs.gxt.ui.client.Style.Scroll; 19import com.extjs.gxt.ui.client.event.*; 20import com.extjs.gxt.ui.client.widget.*; 21import com.extjs.gxt.ui.client.widget.button.Button; 22import com.extjs.gxt.ui.client.widget.form.*; 23import com.extjs.gxt.ui.client.widget.layout.FillLayout; 24import com.extjs.gxt.ui.client.widget.layout.FormData; 25import com.extjs.gxt.ui.client.widget.layout.TableData; 26import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem; 27import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; 28import com.google.gwt.core.client.GWT; 29import com.google.gwt.user.client.Window; 30import com.google.gwt.user.client.rpc.AsyncCallback; 31import com.google.gwt.user.client.ui.AbstractImagePrototype; 32import com.google.gwt.user.client.ui.Hyperlink; 33import com.google.gwt.user.client.ui.Image; 34import com.google.gwt.user.client.ui.Label; 35import com.nimbits.client.controls.PointCombo; 36import com.nimbits.client.exception.NimbitsException; 37import com.nimbits.client.exceptions.CalculationFailedException; 38import com.nimbits.client.icons.Icons; 39import com.nimbits.client.model.Const; 40import com.nimbits.client.model.GxtPointModel; 41import com.nimbits.client.model.point.Point; 42import com.nimbits.client.model.point.PointModel; 43import com.nimbits.client.service.datapoints.PointService; 44import com.nimbits.client.service.datapoints.PointServiceAsync; 45import com.nimbits.client.service.recordedvalues.RecordedValueService; 46import com.nimbits.client.service.recordedvalues.RecordedValueServiceAsync; 47 48import java.util.ArrayList; 49import java.util.List; 50 51class PointPanel extends LayoutContainer { 52 private final Button btnHelp = new Button("Help"); 53 private final Button btnTestCalc = new Button("Test Calc"); 54 private final Button buttonDelete = new Button("Delete Point"); 55 private final CheckBox check2 = new CheckBox(); 56 private final CheckBox checkFB = new CheckBox(); 57 private final CheckBox checkIM = new CheckBox(); 58 private final CheckBox checkTwitter = new CheckBox(); 59 private final CheckBox alertToFacebookCheckbox = new CheckBox(); 60 private final CheckBox alertToEmailCheckbox = new CheckBox(); 61 private final CheckBox he = new CheckBox(); 62 63 64 //idle 65 private final CheckBox idleOn = new CheckBox(); 66 private final CheckBox ignoreCompressedValues = new CheckBox(); 67 private final CheckBox im = new CheckBox(); 68 private final CheckBox le = new CheckBox(); 69 private final CheckBox tw = new CheckBox(); 70 private final Hyperlink hyperlinkRest = new Hyperlink("New hyperlink", false, "newHistoryToken"); 71 private final Hyperlink uuidLink = new Hyperlink("New hyperlink", false, "newHistoryToken"); 72 73 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. "); 74 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."); 75 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:"); 76 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. "); 77 78 private final List<PointDeletedListener> pointDeletedListeners = new ArrayList<PointDeletedListener>(); 79 private final List<PointUpdatedListener> pointUpdatedListeners = new ArrayList<PointUpdatedListener>(); 80 81 //General Properties 82 private final NumberField compression = new NumberField(); 83 private final NumberField delay = new NumberField(); 84 private final NumberField expires = new NumberField(); 85 86 //Alerts 87 private final NumberField high = new NumberField(); 88 private final NumberField idleMinutes = new NumberField(); 89 private final NumberField lat = new NumberField(); 90 private final NumberField lng = new NumberField(); 91 private final NumberField low = new NumberField(); 92 // private final TextField<String> High = new TextField<String>(); 93 ///private final TextField<String> Low = new TextField<String>(); 94 private final NumberField targetValue = new NumberField(); 95 private PointCombo X; 96 private PointCombo Y; 97 private PointCombo Z; 98 99 //calcs 100 private final PointCombo target = new PointCombo(); 101 102// private final Icons ICONS = GWT.create(Icons.class); 103 104 105 // private Point point; 106 107// void setPoint(Point aPoint) { 108// this.point = aPoint; 109// } 110 111 112 private final PointServiceAsync pointService = GWT.create(PointService.class); 113 114 private final SeparatorToolItem separatorToolItem = new SeparatorToolItem(); 115 116 private final static String FORM_HEIGHT = "450"; 117 118 private final static String MAIN_WIDTH = "450"; 119 private final TextArea description = new TextArea(); 120 private final TextField<String> formula = new TextField<String>(); 121 122 private final TextField<String> trigger = new TextField<String>(); 123 private final TextField<String> unit = new TextField<String>(); 124 125 126 private final Point originalPoint; 127 private Point point; 128 129 130 public PointPanel(final Point x) throws NimbitsException { 131 originalPoint = x; 132 loadForm(); 133 } 134 135 private void loadForm() throws NimbitsException { 136 pointService.getPointByID(originalPoint.getId(), new AsyncCallback<Point>() { 137 @Override 138 public void onFailure(Throwable caught) { 139 GWT.log(caught.getMessage()); 140 } 141 142 @Override 143 public void onSuccess(final Point p) { 144 buildForm(p); 145 } 146 147 private void buildForm(final Point p) { 148 point = p; 149 X = new PointCombo(); 150 Y = new PointCombo(); 151 Z = new PointCombo(); 152 153 154 setSize(FORM_HEIGHT, "475"); 155 setLayout(new FillLayout(Orientation.VERTICAL)); 156 //setLayout(new FitLayout()); 157 158 com.google.gwt.user.client.ui.VerticalPanel verticalPanel = new com.google.gwt.user.client.ui.VerticalPanel(); 159 add(verticalPanel); 160 verticalPanel.setSize("460", "450"); 161 verticalPanel.setBorderWidth(0); 162 ToolBar mainToolBar = mainToolBar(); 163 verticalPanel.add(mainToolBar); 164 165 TabPanel tabPanel = new TabPanel(); 166 TabItem tabAlerts = new TabItem("Alerts"); 167 TabItem tabGeneral = new TabItem("General"); 168 tabGeneral.setHeight("425"); 169 // TabItem tabRelay = new TabItem("Relay"); 170 TabItem tabCalcs = new TabItem("Calculations"); 171 TabItem tabIdle = new TabItem("Idle Alarm"); 172 TabItem tabLinks = new TabItem("Links"); 173 //tabGeneral.setWidth("450"); 174 175 176 verticalPanel.add(tabPanel); 177 tabPanel.setSize(FORM_HEIGHT, "435"); 178 179 tabPanel.add(tabGeneral); 180 tabPanel.add(tabAlerts); 181 tabPanel.add(tabCalcs); 182 tabPanel.add(tabIdle); 183 // tabPanel.add(tabRelay); 184 tabPanel.add(tabLinks); 185 186 tabAlerts.add(alertForm()); 187 tabGeneral.add(generalForm()); 188 tabCalcs.add(calcForm()); 189 // tabRelay.add(relayForm()); 190 tabLinks.add(linkForm()); 191 tabIdle.add(idleForm()); 192 tabPanel.addListener(Events.Select, 193 new Listener<BaseEvent>() { 194 public void handleEvent(BaseEvent tpe) { 195 if (!(point.getTarget() == 0)) { 196 target.setValue(target.getStore().findModel(Const.PARAM_ID, 197 point.getTarget())); 198 } 199 if (!(point.getX() == 0)) { 200 X.setValue(X.getStore().findModel(Const.PARAM_ID, point.getX())); 201 X.repaint(); 202 } else { 203 GxtPointModel xModel = new GxtPointModel(point); 204 X.setValue(xModel); 205 } 206 207 if (!(point.getY() == 0)) { 208 Y.setValue(Y.getStore().findModel(Const.PARAM_ID, point.getY())); 209 } 210 211 if (!(point.getZ() == 0)) { 212 Z.setValue(Z.getStore().findModel(Const.PARAM_ID, point.getZ())); 213 } 214 //Window.alert("d"); 215 } 216 }); 217 add(verticalPanel); 218 doLayout(); 219 } 220 }); 221 } 222 223 ToolBar mainToolBar() { 224 ToolBar toolBar = new ToolBar(); 225 toolBar.setHeight(""); 226 227 228 buttonDelete.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.delete())); 229 230 231 final Listener<MessageBoxEvent> deletePointListener = new Listener<MessageBoxEvent>() { 232 public void handleEvent(MessageBoxEvent ce) { 233 Button btn = ce.getButtonClicked(); 234 235 if (btn.getText().equals("Yes")) { 236 try { 237 pointService.deletePoint(point, new AsyncCallback<Void>() { 238 @Override 239 public void onFailure(Throwable caught) { 240 241 242 } 243 244 @Override 245 public void onSuccess(Void result) { 246 notifyPointDeletedListener(point); 247 Window.alert(Const.MESSAGE_POINT_DELETED); 248 } 249 }); 250 } catch (NimbitsException e) { 251 GWT.log(e.getMessage(), e); 252 } 253 } 254 } 255 }; 256 buttonDelete.addSelectionListener(new SelectionListener<ButtonEvent>() { 257 public void componentSelected(ButtonEvent ce) { 258 MessageBox.confirm("Confirm", "Are you sure you want delete this point? Doing so will permanently delete all historical data for this point.", deletePointListener); 259 } 260 }); 261 262 Button buttonSave = new Button("Save"); 263 buttonSave.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.SaveAll())); 264 buttonSave.addSelectionListener(new SelectionListener<ButtonEvent>() { 265 public void componentSelected(ButtonEvent ce) { 266 try { 267 savePoint(); 268 } catch (NimbitsException e) { 269 GWT.log(e.getMessage(), e); 270 } 271 } 272 }); 273 274 275 toolBar.add(buttonSave); 276 277 278 btnTestCalc.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.Play())); 279 280 btnTestCalc.addSelectionListener(new SelectionListener<ButtonEvent>() { 281 public void componentSelected(ButtonEvent ce) { 282 try { 283 runEquation(true); 284 } catch (CalculationFailedException e) { 285 Window.alert(e.getMessage()); 286 } 287 } 288 }); 289 290 toolBar.add(btnTestCalc); 291 292 293 toolBar.add(buttonDelete); 294 buttonDelete.setWidth("90px"); 295 btnHelp.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.Help())); 296 btnHelp.addSelectionListener(new SelectionListener<ButtonEvent>() { 297 public void componentSelected(ButtonEvent ce) { 298 Window.open("https://code.google.com/p/nimbits-server/wiki/NimbitsWiki", "", ""); 299 } 300 }); 301 302 toolBar.add(btnHelp); 303 304 toolBar.add(separatorToolItem); 305 separatorToolItem.setWidth("25px"); 306 return toolBar; 307 } 308 309 private void notifyPointDeletedListener(Point p) { 310 for (PointDeletedListener pointDeletedListener : pointDeletedListeners) { 311 pointDeletedListener.onPointDeleted(p); 312 } 313 } 314 315// private Point point() { 316// 317// return point; 318// 319// } 320 321 private void savePoint() throws NimbitsException { 322 final MessageBox box = MessageBox.wait("Progress", 323 "Saving your data, please wait...", "Saving..."); 324 box.show(); 325 326 327 //General 328 point.setCompression(compression.getValue().doubleValue()); 329 point.setIgnoreIncomingCompressedValues(ignoreCompressedValues.getValue()); 330 point.setExpire(expires.getValue().intValue()); 331 point.setUnit(unit.getValue()); 332 point.setDescription(description.getValue()); 333 point.setPublic(check2.getValue()); 334 point.setSendIM(checkIM.getValue()); 335 point.setSendTweet(checkTwitter.getValue()); 336 point.setPostToFacebook(checkFB.getValue()); 337 point.setTargetValue(targetValue.getValue().doubleValue()); 338 339 //Alerts 340 int d = delay.getValue().intValue(); 341 point.setAlarmDelay(d); 342 point.setHighAlarm(high.getValue().doubleValue()); 343 point.setLowAlarm(low.getValue().doubleValue()); 344 point.setHighAlarmOn(he.getValue()); 345 point.setLowAlarmOn(le.getValue()); 346 point.setAlarmToFacebook(alertToFacebookCheckbox.getValue()); 347 point.setAlarmToEmail(alertToEmailCheckbox.getValue()); 348 point.setSendAlarmIM(im.getValue()); 349 point.setSendAlarmTweet(tw.getValue()); 350 351 //idlealarm 352 point.setIdleAlarmOn(idleOn.getValue()); 353 point.setIdleSeconds(idleMinutes.getValue().intValue() * 60); 354 point.setIdleAlarmSent(false); 355 356 if (!(lng.getValue() == null)) { 357 point.setLng(lng.getValue().doubleValue()); 358 } 359 360 361 if (!(lat.getValue() == null)) { 362 point.setLat(lat.getValue().doubleValue()); 363 } 364 365 366 //calcs 367 point.setFormula(formula.getValue()); 368 if (!(target.getValue() == null)) { 369 point.setTarget(target.getPoint().getId()); 370 } else { 371 point.setTarget(0); 372 } 373 374 if (!(X.getValue() == null)) { 375 point.setX(X.getPoint().getId()); 376 } else { 377 point.setX(0); 378 } 379 380 if (!(Y.getValue() == null)) { 381 point.setY(Y.getPoint().getId()); 382 } else { 383 point.setY(0); 384 } 385 if (!(Z.getValue() == null)) { 386 point.setZ(Z.getPoint().getId()); 387 } else { 388 point.setZ(0); 389 } 390 391 392 pointService.updatePoint(point, new AsyncCallback<Point>() { 393 @Override 394 public void onFailure(Throwable caught) { 395 MessageBox.alert("Alert", caught.getMessage(), null); 396 box.close(); 397 } 398 399 @Override 400 public void onSuccess(Point result) { 401 MessageBox.alert("Message", "Point Updated", null); 402 notifyPointUpdatedListener(point); 403 box.close(); 404 } 405 }); 406 } 407 408 private void notifyPointUpdatedListener(Point p) { 409 for (PointUpdatedListener pointUpdatedListener : pointUpdatedListeners) { 410 pointUpdatedListener.onPointUpdated(p); 411 } 412 } 413 414 private boolean runEquation(final boolean showFeedback) throws CalculationFailedException { 415 final PointModel testPoint = new PointModel(); 416 final RecordedValueServiceAsync dataService; 417 dataService = GWT.create(RecordedValueService.class); 418 419 if (target.getValue() == null) { 420 if (showFeedback) { 421 final Dialog d = new Dialog(); 422 d.setHeading("Error"); 423 d.setButtons(Dialog.OK); 424 d.setBodyStyleName("pad-text"); 425 d.addText("You must select a target that the result of this calculation will be recorded to."); 426 d.setScrollMode(Scroll.AUTO); 427 d.setHideOnButtonClick(true); 428 d.show(); 429 } 430 return false; 431 } 432 433 if (target.getText().equals(point.getName().getValue())) { 434 if (showFeedback) { 435 final Dialog d = new Dialog(); 436 d.setHeading("Error"); 437 d.setButtons(Dialog.OK); 438 d.setBodyStyleName("pad-text"); 439 d.addText("Infinite Loop Error"); 440 d.setScrollMode(Scroll.AUTO); 441 d.setHideOnButtonClick(true); 442 d.show(); 443 } 444 return false; 445 } 446 447 448 if (formula.getValue() == null) { 449 if (showFeedback) { 450 final Dialog d = new Dialog(); 451 d.setHeading("Error"); 452 d.setButtons(Dialog.OK); 453 d.setBodyStyleName("pad-text"); 454 d.addText("Please enter an equation."); 455 d.setScrollMode(Scroll.AUTO); 456 d.setHideOnButtonClick(true); 457 d.show(); 458 } 459 return false; 460 } 461 testPoint.setFormula(formula.getValue()); 462 463 if (X.getValue() != null) { 464 testPoint.setX(X.getValue().getId()); 465 } 466 467 if (Y.getValue() != null) { 468 testPoint.setY(Y.getValue().getId()); 469 } 470 471 if (Z.getValue() != null) { 472 testPoint.setZ(Z.getValue().getId()); 473 } 474 475 try { 476 dataService.solveEquation(testPoint, new AsyncCallback<Double>() { 477 @Override 478 public void onFailure(Throwable caught) { 479 if (showFeedback) { 480 final Dialog simple = new Dialog(); 481 simple.setHeading("formula Error"); 482 simple.setButtons(Dialog.OK); 483 simple.setBodyStyleName("pad-text"); 484 simple.addText(caught.getMessage()); 485 simple.setScrollMode(Scroll.AUTO); 486 simple.setHideOnButtonClick(true); 487 simple.show(); 488 } 489 } 490 491 @Override 492 public void onSuccess(Double result) { 493 if (showFeedback) { 494 final Dialog d = new Dialog(); 495 d.setHeading("formula Success"); 496 d.setButtons(Dialog.OK); 497 d.setBodyStyleName("pad-text"); 498 d.addText("Result: " + result); 499 d.setScrollMode(Scroll.AUTO); 500 d.setHideOnButtonClick(true); 501 d.show(); 502 } 503 } 504 }); 505 } catch (NimbitsException e) { 506 GWT.log(e.getMessage()); 507 } 508 return true; 509 } 510 511 private FormPanel alertForm() { 512 FormPanel simple = new FormPanel(); 513 514 515 simple.setHeaderVisible(false); 516 517 simple.setFrame(false); 518 simple.setBorders(false); 519 simple.setBodyBorder(false); 520 simple.setSize(MAIN_WIDTH, FORM_HEIGHT); 521 522 523 high.setFieldLabel("High Value"); 524 high.setValue(point.getHighAlarm()); 525 high.setAllowBlank(false); 526 simple.add(high); 527 528 529 he.setBoxLabel("High alert enabled"); 530 he.setLabelSeparator(""); 531 he.setValue(point.isHighAlarmOn()); 532 // he.setFieldLabel("Enabled"); 533 simple.add(he); 534 535 536 low.setFieldLabel("Low Value"); 537 low.setAllowBlank(false); 538 low.setValue(point.getLowAlarm()); 539 simple.add(low); 540 541 542 le.setBoxLabel("Low alert enabled"); 543 le.setLabelSeparator(""); 544 le.setValue(point.isLowAlarmOn()); 545 simple.add(le, new FormData("0% -395")); 546 547 548 alertToFacebookCheckbox.setBoxLabel("Post alerts to facebook"); 549 alertToFacebookCheckbox.setLabelSeparator(""); 550 alertToFacebookCheckbox.setValue(point.getAlarmToFacebook()); 551 simple.add(alertToFacebookCheckbox); 552 553 554 alertToEmailCheckbox.setBoxLabel("Send alerts to email"); 555 alertToEmailCheckbox.setLabelSeparator(""); 556 alertToEmailCheckbox.setValue(point.isAlarmToEmail()); 557 simple.add(alertToEmailCheckbox); 558 559 im.setBoxLabel("Send alerts to IM"); 560 im.setLabelSeparator(""); 561 im.setValue(point.getSendAlarmIM()); 562 simple.add(im); 563 564 565 tw.setBoxLabel("Post alerts to twitter"); 566 tw.setLabelSeparator(""); 567 tw.setValue(point.getSendAlarmTweet()); 568 simple.add(tw); 569 570 // final TextField<Integer> delay = new TextField<Integer>(); 571 572 573 delay.setAllowBlank(false); 574 575 delay.setFieldLabel("Repeat email Delay (Minutes)"); 576 delay.setValue(point.getAlarmDelay()); 577 simple.add(delay); 578 579 580 return simple; 581 } 582 583 //general 584 private FormPanel generalForm() { 585 //ContentPanel vp = new ContentPanel(); 586 587 // vpoint.setHeaderVisible(false); 588 // vpoint.setFrame(false); 589 // vpoint.setBorders(false); 590 // vpoint.setBodyBorder(false); 591 592 FormPanel simple = new FormPanel(); 593 simple.setHeaderVisible(false); 594 595 simple.setFrame(false); 596 //simple.setWidth(600); 597 simple.setBorders(false); 598 simple.setBodyBorder(false); 599 simple.setSize("450", "408"); 600 Image i = new Image(); 601 // i.setStyleName("#images-view .thumb img"); 602 i.setUrl("http://chart.apis.google.com/chart?chs=100x100&cht=qr&chl=" + "http://" + point.getHost() + "?uuid=" 603 + point.getUuid() + "&chld=L|1&choe=UTF-8"); 604 //i.setSize("75px", "75px"); 605 606 607 HorizontalPanel titlebar = new HorizontalPanel(); 608// String host; 609// 610// if (point.getHost().contains("127.0.0.1")) { 611// host = point.getHost() + ":8888"; 612// } else { 613// host = point.getHost(); 614// } 615 String host = GWT.getModuleBaseURL(); 616 617 String ht = "<A href = \"http://" + host + "?uuid=" + point.getUuid() + "\" target=\"_blank\"> UUID:" + point.getUuid() + "</A>"; 618 619 620 titlebar.add(i); 621 622 VerticalPanel verticalPanel = new VerticalPanel(); 623 verticalPanel.setSpacing(10); 624 verticalPanel.setHeight(80); 625 626 627 Html h = new Html(ht); 628 verticalPanel.add(h); 629 TableData tdVerticalPanel = new TableData(); 630 tdVerticalPanel.setHorizontalAlign(HorizontalAlignment.CENTER); 631 tdVerticalPanel.setMargin(5); 632 titlebar.add(verticalPanel, tdVerticalPanel); 633 634 635 // vpoint.add(titlebar); 636 // titlebar.setSize("450", "100"); 637 638 639 compression.setFieldLabel("Compression"); 640 compression.setValue(point.getCompression()); 641 compression.setAllowBlank(false); 642 simple.add(compression); 643 644 ignoreCompressedValues.setFieldLabel("Apply compression to incoming data"); 645 ignoreCompressedValues.setValue(point.getIgnoreIncomingCompressedValues()); 646 //simple.add(ignoreCompressedValues); 647 648 649 targetValue.setFieldLabel("Target"); 650 targetValue.setValue(point.getTargetValue()); 651 targetValue.setAllowBlank(false); 652 simple.add(targetValue); 653 654 655 expires.setFieldLabel("Expires (days)"); 656 expires.setValue(point.getExpire()); 657 expires.setAllowBlank(false); 658 simple.add(expires); 659 660 661 unit.setFieldLabel("Unit of Measure"); 662 unit.setValue(point.getUnit()); 663 unit.setAllowBlank(true); 664 simple.add(unit); 665 666 667 check2.setBoxLabel("Public"); 668 check2.setValue(point.isPublic()); 669 670 671 checkFB.setBoxLabel("facebook"); 672 checkFB.setValue(point.isPostToFacebook()); 673 674 675 checkIM.setBoxLabel("Instant Message"); 676 checkIM.setValue(point.getSendIM()); 677 678 679 checkTwitter.setBoxLabel("Twitter"); 680 checkTwitter.setValue(point.getSendTweet()); 681 682 CheckBoxGroup checkGroup = new CheckBoxGroup(); 683 checkGroup.setFieldLabel("Sharing"); 684 685 checkGroup.add(check2); 686 simple.add(checkGroup); 687 688 CheckBoxGroup checkGroupFB = new CheckBoxGroup(); 689 checkGroupFB.setFieldLabel("Messaging"); 690 checkGroupFB.add(checkFB); 691 checkFB.setWidth("108px"); 692 693 checkGroupFB.add(checkIM); 694 checkIM.setWidth("132px"); 695 checkGroupFB.add(checkTwitter); 696 checkTwitter.setWidth("82px"); 697 simple.add(checkGroupFB, new FormData("-115")); 698 checkGroupFB.setWidth("400"); 699 // simple.add(checkIM, formData); 700 701 702 lat.setFieldLabel("Source latitude"); 703 if (point.getLat() != 0) { 704 lat.setValue(point.getLat()); 705 } 706 707 lat.setAllowBlank(true); 708 simple.add(lat); 709 710 711 lng.setFieldLabel("Source longitude"); 712 if (point.getLng() != 0) { 713 lng.setValue(point.getLng()); 714 } 715 716 lng.setAllowBlank(true); 717 simple.add(lng); 718 719 720 description.setPreventScrollbars(true); 721 description.setValue(point.getDescription()); 722 description.setFieldLabel("Description"); 723 simple.add(description, new FormData("-20")); 724 description.setSize("400", "100"); 725 726 727 return simple; 728 } 729 730 private FormPanel calcForm() { 731 FormPanel simple = new FormPanel(); 732 simple.setHeaderVisible(false); 733 simple.setFrame(false); 734 simple.setBorders(false); 735 simple.setBodyBorder(false); 736 simple.setSize(MAIN_WIDTH, FORM_HEIGHT); 737 trigger.setReadOnly(true); 738 trigger.setValue(point.getName().getValue()); 739 trigger.setFieldLabel("Trigger:"); 740 simple.add(trigger); 741 742 formula.setFieldLabel("formula"); 743 744 formula.setAllowBlank(false); 745 formula.setValue(point.getFormula()); 746 747 simple.add(formula); 748 target.setEditable(true); 749 target.setAllowBlank(true); 750 751 target.setFieldLabel("Target:"); 752 target.setForceSelection(true); 753 target.setReadOnly(false); 754 755 // target.setValue(point.getTarget())); 756 // if (point.getTarget() > 0) 757 // { 758 // for (Point p : target.getItemSelector().) 759 // } 760 761 762 X.setEditable(true); 763 X.setFieldLabel("x"); 764 X.setAllowBlank(true); 765 766 Y.setAllowBlank(true); 767 Y.setEditable(true); 768 Y.setFieldLabel("y"); 769 770 Z.setEditable(true); 771 Z.setAllowBlank(true); 772 Z.setFieldLabel("z"); 773 774 simple.add(target); 775 simple.add(X); 776 simple.add(Y); 777 simple.add(Z); 778 779 lblfldTips.setFieldLabel("Tips:"); 780 781 simple.add(lblfldTips, new FormData("100%")); 782 783 return simple; 784 } 785 786 787 private VerticalPanel linkForm() { 788 VerticalPanel simple = new VerticalPanel(); 789 String u = Window.Location.getHost(); 790 791 String infoURL = "http://" + u + "?" + 792 "uuid=" + point.getUuid(); 793 794 795 String bcURL; 796 797 bcURL = "http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=" + 798 infoURL + 799 "&chld=L|1&choe=UTF-8"; 800 801 final Image image = new Image(bcURL); 802 803 simple.add(lblQrCodesThe); 804 simple.add(image); 805 image.setSize("100", "100"); 806 807 image.setUrl(bcURL); 808 809 simple.add(lblTheQrBarcode); 810 uuidLink.setHeight("44px"); 811 uuidLink.setHTML("UUID Link"); 812 uuidLink.setText(infoURL); 813 814 simple.add(uuidLink); 815 816 simple.add(lblYouCanPull); 817 818 819 hyperlinkRest.setText("http://" + u + "/service/currentvalue?uuid=" + point.getUuid()); 820 821 simple.add(hyperlinkRest); 822 823 return simple; 824 } 825 826 private FormPanel idleForm() { 827 FormPanel simple = new FormPanel(); 828 simple.setHeaderVisible(false); 829 simple.setFrame(false); 830 simple.setBorders(false); 831 simple.setBodyBorder(false); 832 simple.setSize(MAIN_WIDTH, FORM_HEIGHT); 833 834 idleOn.setBoxLabel("Alarm On"); 835 idleOn.setLabelSeparator(""); 836 837 idleOn.setValue(point.isIdleAlarmOn()); 838 idleMinutes.setFieldLabel("Idle Minutes"); 839 idleMinutes.setValue(point.getIdleSeconds() / 60); 840 841 Html h = new Html(); 842 843 844 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>" + 845 "<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>" + 846 "<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>"); 847 848 849 simple.add(h); 850 851 simple.add(idleMinutes); 852 simple.add(idleOn); 853 if (point.isIdleAlarmOn()) { 854 Html h2 = new Html(); 855 856 String s = "<P>Based on the current settings, this point is currently "; 857 if (point.getIdleAlarmSent()) { 858 s += "idle."; 859 } else { 860 s += "not idle."; 861 } 862 s += " Last recorded timestamp was: " + point.getLastRecordedTimestamp() + "</p>"; 863 h2.setHtml(s); 864 865 simple.add(h2); 866 } 867 868 869 return simple; 870 } 871 872 public interface PointDeletedListener { 873 void onPointDeleted(Point p); 874 } 875 876 public void addPointDeletedListeners(PointDeletedListener listener) { 877 pointDeletedListeners.add(listener); 878 } 879 880 public interface PointUpdatedListener { 881 void onPointUpdated(Point p); 882 } 883 884 public void addPointUpdatedListeners(PointUpdatedListener listener) { 885 pointUpdatedListeners.add(listener); 886 } 887}