List of usage examples for com.google.gwt.user.client.ui CheckBox CheckBox
public CheckBox()
From source file:eu.riscoss.client.entities.RDCConfigurationPage.java
License:Apache License
protected void loadRDCs(JSONObject rdcMap) { if (grid != null) grid.removeFromParent();//w w w . java2s . com // dock.remove( grid.asWidget() ); grid = new Grid(); dock.add(grid, DockPanel.EAST); int num = 0; for (String key : rdcMap.keySet()) { JSONObject o = rdcMap.get(key).isObject(); JSONArray jpn = o.get("params").isArray(); grid.resize(grid.getRowCount() + jpn.size() + 1, 3); CheckBox chk = new CheckBox(); if (enabledMap.isEnabled(key)) chk.setValue(true); chk.addClickHandler(new ClickWrapper<String>(key) { @Override public void onClick(ClickEvent event) { enabledMap.enableRDC(getValue(), ((CheckBox) event.getSource()).getValue()); changedData = true; } }); grid.setWidget(num, 1, chk); Label lbl = new Label(key); lbl.setStyleName("rdcTitle"); grid.setWidget(num, 0, lbl); for (int p = 0; p < jpn.size(); p++) { num++; JSONObject par = jpn.get(p).isObject(); grid.setWidget(num, 0, new Label(par.get("name").isString().stringValue())); TextBox txt = new TextBox(); txt.setName("txt:" + key + ":" + par.get("name").isString().stringValue()); txt.getElement().setId("txt:" + key + ":" + par.get("name").isString().stringValue()); txt.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { changedData = true; } }); if (enabledMap.isEnabled(key)) txt.setText(enabledMap.get(key, par.get("name").isString().stringValue(), "")); else { if (par.get("def").isString() != null) txt.setText(par.get("def").isString().stringValue()); } grid.setWidget(num, 1, txt); if ((par.get("desc").isString() != null) & (par.get("ex").isString() != null)) { grid.setWidget(num, 2, new HTML(par.get("desc").isString().stringValue() + "<br>" + "Example: " + par.get("ex").isString().stringValue())); } } num++; } dock.setVisible(true); // RootPanel.get().add( hpanel ); // RootPanel.get().add( grid ); }
From source file:fr.aliasource.webmail.client.addressbook.ContactList.java
License:GNU General Public License
public void updateGrid(final UiContact[] contacts) { Arrays.sort(contacts, new ContactComp()); clear();/*from w w w. j a v a 2 s . c o m*/ int limit = getNbDisplayItems(); if (limit > contacts.length || isDisplayAllContact()) { limit = contacts.length; setDisplayAllContact(true); } resizeRows(limit + 1); // Header setWidget(0, 0, new Label(I18N.strings.contactName())); getRowFormatter().setStyleName(0, "addressBookHeader"); for (int i = 0; i < limit; i++) { final CheckBox cb = new CheckBox(); final UiContact co = contacts[i]; final int row = i + 1; Label l = new Label(contacts[i].getDisplayName(), true); l.addClickHandler(createLabelClickListener(cb, co, row)); cb.addClickHandler(createCbClickListener(cb, row, co)); setWidget(row, 0, cb); setWidget(row, 1, l); getRowFormatter().setStyleName(row, "addressBookItem"); } if (!isDisplayAllContact()) { int pos = limit + 1; resizeRows(pos + 1); Anchor hl = new Anchor(I18N.strings.displayAllXContacts(Integer.toString(contacts.length))); hl.addClickHandler(new ClickHandler() { public void onClick(ClickEvent sender) { // TODO Auto-generated method stub setDisplayAllContact(!isDisplayAllContact()); clear(); updateGrid(contacts); getRowFormatter().removeStyleName(getNbDisplayItems(), "contentInfo"); webmail.getAddressBook().getContactDisplay().reset(); } }); setWidget(pos, 1, hl); getRowFormatter().setStyleName(pos, "contentInfo"); setHeight("100%"); // "Display all" link on grid bottom } else { setHeight(""); } }
From source file:fr.aliasource.webmail.client.AdvancedSearchForms.java
License:GNU General Public License
private VerticalPanel createForm() { FlexTable ft = new FlexTable(); content = new VerticalPanel(); fromQuery = new TextBox(); fromQuery.addKeyPressHandler(addTextBoxKeyboardListener()); toQuery = new TextBox(); toQuery.addKeyPressHandler(addTextBoxKeyboardListener()); subjectQuery = new TextBox(); subjectQuery.addKeyPressHandler(addTextBoxKeyboardListener()); folderQuery = new ListBox(); hasWordsQuery = new TextBox(); hasWordsQuery.addKeyPressHandler(addTextBoxKeyboardListener()); doNotHaveQuery = new TextBox(); doNotHaveQuery.addKeyPressHandler(addTextBoxKeyboardListener()); attachements = new CheckBox(); attachements.setText(I18N.strings.hasAttachments()); dateWithinQuery = new ListBox(); String[] dateWithinLabel = { ONE_DAY, THREE_DAYS, ONE_WEEK, TWO_WEEKS, ONE_MONTH, TWO_MONTHS, SIX_MONTHS, ONE_YEAR };// w ww.j av a 2 s . c om for (String d : dateWithinLabel) { dateWithinQuery.addItem(d); } dateOfQuery = new TextBox(); dateOfQuery.addKeyPressHandler(addTextBoxKeyboardListener()); HorizontalPanel hpDate = new HorizontalPanel(); hpDate.add(dateWithinQuery); Label of = new Label(" " + I18N.strings.of() + " "); hpDate.add(of); hpDate.setCellVerticalAlignment(of, HorizontalPanel.ALIGN_MIDDLE); hpDate.add(dateOfQuery); Label dateLegend = new Label(I18N.strings.dateLegend()); dateLegend.setStyleName("advancedSearchFormLegend"); ft.setWidget(0, 0, new Label(I18N.strings.from() + ":")); ft.setWidget(0, 1, fromQuery); ft.setWidget(1, 0, new Label(I18N.strings.to() + ":")); ft.setWidget(1, 1, toQuery); ft.setWidget(2, 0, new Label(I18N.strings.subject() + ":")); ft.setWidget(2, 1, subjectQuery); ft.setWidget(3, 0, new Label(I18N.strings.search() + ":")); ft.setWidget(3, 1, folderQuery); ft.setWidget(0, 2, new Label(I18N.strings.hasTheWords() + ":")); ft.setWidget(0, 3, hasWordsQuery); ft.setWidget(1, 2, new Label(I18N.strings.doNotHave() + ":")); ft.setWidget(1, 3, doNotHaveQuery); ft.setWidget(2, 3, attachements); ft.setWidget(3, 2, new Label(I18N.strings.dateWithin() + ":")); ft.setWidget(3, 3, hpDate); ft.setWidget(4, 3, dateLegend); content.setStyleName("advancedSearchForm"); content.setWidth("100%"); content.add(ft); content.add(createButtons()); return content; }
From source file:fr.aliasource.webmail.client.conversations.DataGrid.java
License:GNU General Public License
private void fillRow(DateFormatter dtf, Conversation data, int i) { int col = 0;/*from ww w .j av a2 s. c o m*/ setWidget(i, col++, new GripImage(data)); CheckBox selector = new CheckBox(); if (selectedIds.contains(data.getId())) { selector.setValue(true); } regs.add(selector.addClickHandler(getCheckListener(data.getId(), selector))); setWidget(i, col++, selector); setWidget(i, col++, new StarWidget(data.isStarred(), data.getId())); if (data.isAnswered()) { setWidget(i, col++, new AnsweredWidget()); } else { setWidget(i, col++, new HTML(" ")); } ClickHandler cl = newShowConversationListener(data, i); ParticipantsWidget pw = new ParticipantsWidget(ui, data, cl); regs.add(pw.getRegistration()); setWidget(i, col++, pw); HTML count = null; if (data.getMessageCount() > 1) { count = new HTML("(" + data.getMessageCount() + ")"); } else { count = new HTML(" "); } regs.add(count.addClickHandler(cl)); setWidget(i, col++, count); Widget convWidget = null; try { convWidget = getConversationWidget(data, cl); } catch (Throwable t) { GWT.log("crash on email", t); HTML h = new HTML("[" + data.getTitle() + "]"); regs.add(h.addClickHandler(cl)); convWidget = h; } setWidget(i, col++, convWidget); if (data.hasInvitation()) { setWidget(i, col++, new Image("minig/images/invitation.gif")); } else { if (data.hasAttachements()) { setWidget(i, col++, new Image("minig/images/paperclip.gif")); } else if (data.getSourceFolder().equals("#chat")) { setWidget(i, col++, new Image("minig/images/chat.gif")); } else { setHTML(i, col++, " "); } } Label dlbl = new Label(dateAsText(dtf, data.getDate()), false); DateFormatter df = new DateFormatter(new Date(data.getDate())); dlbl.setTitle(df.formatDetails(new Date(data.getDate()))); if (data.isUnread()) { dlbl.addStyleName("bold"); } setWidget(i, col++, dlbl); }
From source file:geogebra.web.gui.view.algebra.RadioButtonTreeItem.java
License:Open Source License
/** * Creates a new RadioButtonTreeItem for displaying/editing an existing * GeoElement// w ww .ja va 2 s . c om * * @param ge * the existing GeoElement to display/edit * @param showUrl * the marble to be shown when the GeoElement is visible * @param hiddenUrl * the marble to be shown when the GeoElement is invisible */ public RadioButtonTreeItem(GeoElement ge, SafeUri showUrl, SafeUri hiddenUrl) { super(); getElement().setDraggable(Element.DRAGGABLE_TRUE); geo = ge; kernel = geo.getKernel(); app = (AppW) kernel.getApplication(); av = app.getAlgebraView(); selection = app.getSelectionManager(); addStyleName("elem"); addStyleName("panelRow"); // setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); // setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); radio = new Marble(showUrl, hiddenUrl, this); radio.setStyleName("marble"); radio.setEnabled(ge.isEuclidianShowable()); radio.setChecked(ge.isEuclidianVisible()); marblePanel = new FlowPanel(); marblePanel.add(radio); add(marblePanel); // Sliders if (showSliderOrTextBox && app.isPrerelease() && geo instanceof GeoNumeric && ((GeoNumeric) geo).isShowingExtendedAV()) { if (!geo.isEuclidianVisible()) { // number inserted via input bar // -> initialize min/max etc. geo.setEuclidianVisible(true); geo.setEuclidianVisible(false); } slider = new SliderW(((GeoNumeric) geo).getIntervalMin(), (int) ((GeoNumeric) geo).getIntervalMax()); slider.setValue(((GeoNumeric) geo).getValue()); slider.setMinorTickSpacing(geo.getAnimationStep()); slider.addValueChangeHandler(new ValueChangeHandler<Double>() { public void onValueChange(ValueChangeEvent<Double> event) { ((GeoNumeric) geo).setValue(event.getValue()); geo.updateCascade(); // updates other views (e.g. Euclidian) kernel.notifyRepaint(); } }); sliderPanel = new FlowPanel(); add(sliderPanel); if (geo.isAnimatable()) { ImageResource imageresource = geo.isAnimating() ? AppResources.INSTANCE.nav_pause() : AppResources.INSTANCE.nav_play(); playButton = new Image(imageresource); playButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { boolean newValue = !(geo.isAnimating() && app.getKernel().getAnimatonManager().isRunning()); geo.setAnimating(newValue); playButton.setResource( newValue ? AppResources.INSTANCE.nav_pause() : AppResources.INSTANCE.nav_play()); geo.updateRepaint(); if (geo.isAnimating()) { geo.getKernel().getAnimatonManager().startAnimation(); } } }); marblePanel.add(playButton); } } SpanElement se = DOM.createSpan().cast(); updateNewStatic(se); updateColor(se); ihtml = new InlineHTML(); ihtml.addDoubleClickHandler(this); ihtml.addClickHandler(this); ihtml.addMouseMoveHandler(this); ihtml.addMouseDownHandler(this); ihtml.addMouseOverHandler(this); ihtml.addMouseOutHandler(this); ihtml.addTouchStartHandler(this); ihtml.addTouchMoveHandler(this); ihtml.addTouchEndHandler(this); addSpecial(ihtml); ihtml.getElement().appendChild(se); SpanElement se2 = DOM.createSpan().cast(); se2.appendChild(Document.get().createTextNode("\u00A0\u00A0\u00A0\u00A0")); ihtml.getElement().appendChild(se2); // String text = ""; if (showSliderOrTextBox && app.isPrerelease() && geo instanceof GeoBoolean) { // CheckBoxes checkBox = new CheckBox(); checkBox.setValue(((GeoBoolean) geo).getBoolean()); add(checkBox); checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() { public void onValueChange(ValueChangeEvent<Boolean> event) { ((GeoBoolean) geo).setValue(event.getValue()); geo.updateCascade(); // updates other views (e.g. Euclidian) kernel.notifyRepaint(); } }); // use only the name of the GeoBoolean getBuilder(se).append(geo.getLabel(StringTemplate.defaultTemplate)); } else if (geo.isIndependent()) { geo.getAlgebraDescriptionTextOrHTMLDefault(getBuilder(se)); } else { switch (kernel.getAlgebraStyle()) { case Kernel.ALGEBRA_STYLE_VALUE: geo.getAlgebraDescriptionTextOrHTMLDefault(getBuilder(se)); break; case Kernel.ALGEBRA_STYLE_DEFINITION: geo.addLabelTextOrHTML(geo.getDefinitionDescription(StringTemplate.defaultTemplate), getBuilder(se)); break; case Kernel.ALGEBRA_STYLE_COMMAND: geo.addLabelTextOrHTML(geo.getCommandDescription(StringTemplate.defaultTemplate), getBuilder(se)); break; } } // if enabled, render with LaTeX if (av.isRenderLaTeX() && kernel.getAlgebraStyle() == Kernel.ALGEBRA_STYLE_VALUE) { String latexStr = geo.getLaTeXAlgebraDescription(true, StringTemplate.latexTemplateMQ); seNoLatex = se; if ((latexStr != null) && geo.isLaTeXDrawableGeo() && (geo.isGeoList() ? !((GeoList) geo).isMatrix() : true)) { this.needsUpdate = true; av.repaintView(); } } else { seNoLatex = se; } // FIXME: geo.getLongDescription() doesn't work // geo.getKernel().getApplication().setTooltipFlag(); // se.setTitle(geo.getLongDescription()); // geo.getKernel().getApplication().clearTooltipFlag(); longTouchManager = LongTouchManager.getInstance(); setDraggable(); }
From source file:gov.nist.spectrumbrowser.admin.AccountManagement.java
License:Open Source License
@Override public void draw() { verticalPanel.clear();/*from w w w . ja v a2 s .com*/ HTML html = new HTML("<h3>User Accounts</h3>"); int rows = userAccounts.size(); verticalPanel.add(html); HTML helpText = new HTML("<p>Add button to add new accounts.</p> " + "<p>Admin accounts are always authenticated. For User account, ensure authentication is enbled on System Config page.</p>"); grid = new Grid(rows + 1, 11); grid.setText(0, 0, "Email Adddress"); grid.setText(0, 1, "First Name"); grid.setText(0, 2, "Last Name"); grid.setText(0, 3, "Admin Privilege"); grid.setText(0, 4, "Failed Login Attempts"); grid.setText(0, 5, "Account Locked?"); grid.setText(0, 6, "Unlock Account"); grid.setText(0, 7, "Password Expiry Date"); grid.setText(0, 8, "Reset Expiration"); grid.setText(0, 9, "Creation Date"); grid.setText(0, 10, "Delete Account"); // TODO: add session information like currently logged in, time logged in, time session expires // & ability to delete a session object grid.setBorderWidth(2); grid.setCellPadding(2); for (int i = 1; i < rows + 1; i++) { JSONObject account = userAccounts.get(i - 1).isObject(); grid.setText(i, 0, account.get(Defines.ACCOUNT_EMAIL_ADDRESS).isString().stringValue()); grid.setText(i, 1, account.get(Defines.ACCOUNT_FIRST_NAME).isString().stringValue()); grid.setText(i, 2, account.get(Defines.ACCOUNT_LAST_NAME).isString().stringValue()); String priv = account.get(Defines.ACCOUNT_PRIVILEGE).isString().stringValue(); CheckBox togglePrivilege = new CheckBox(); togglePrivilege.setValue(priv.equals("admin")); togglePrivilege.addValueChangeHandler(new TogglePrivilegeValueChangeHandler( account.get(Defines.ACCOUNT_EMAIL_ADDRESS).isString().stringValue())); grid.setWidget(i, 3, togglePrivilege); grid.setText(i, 4, Integer .toString((int) account.get(Defines.ACCOUNT_NUM_FAILED_LOGINS).isNumber().doubleValue())); grid.setText(i, 5, Boolean.toString(account.get(Defines.ACCOUNT_LOCKED).isBoolean().booleanValue())); Button unlock = new Button("Unlock"); unlock.addClickHandler( new UnlockClickHandler(account.get(Defines.ACCOUNT_EMAIL_ADDRESS).isString().stringValue())); grid.setWidget(i, 6, unlock); //JEK: note: the 'datePasswordExpires' and 'dateAccountCreated' are not in accounts database since we store time in seconds. // These date fields are just for display here so we do not need to define constants for JSON strings. grid.setText(i, 7, account.get("datePasswordExpires").isString().stringValue()); Button reset = new Button("Reset Expiration"); reset.addClickHandler(new ResetExpirationClickHandler( account.get(Defines.ACCOUNT_EMAIL_ADDRESS).isString().stringValue())); grid.setWidget(i, 8, reset); grid.setText(i, 9, account.get("dateAccountCreated").isString().stringValue()); Button delete = new Button("Delete"); delete.addClickHandler( new DeleteClickHandler(account.get(Defines.ACCOUNT_EMAIL_ADDRESS).isString().stringValue())); grid.setWidget(i, 10, delete); } for (int i = 0; i < grid.getColumnCount(); i++) { grid.getCellFormatter().setStyleName(0, i, "textLabelStyle"); } for (int i = 0; i < grid.getRowCount(); i++) { for (int j = 0; j < grid.getColumnCount(); j++) { grid.getCellFormatter().setHorizontalAlignment(i, j, HasHorizontalAlignment.ALIGN_CENTER); grid.getCellFormatter().setVerticalAlignment(i, j, HasVerticalAlignment.ALIGN_MIDDLE); } } verticalPanel.add(grid); HorizontalPanel buttonPanel = new HorizontalPanel(); Button addAccountButton = new Button("Add"); addAccountButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { //JEK: I commented out this line because we not want to go back to account management if add account failed //redraw = true; new AddAccount(admin, AccountManagement.this, verticalPanel).draw(); } }); buttonPanel.add(addAccountButton); Button refreshButton = new Button("Refresh"); refreshButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { redraw = true; Admin.getAdminService().getUserAccounts(AccountManagement.this); } }); buttonPanel.add(refreshButton); Button logoffButton = new Button("Log Off"); logoffButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { admin.logoff(); } }); buttonPanel.add(logoffButton); verticalPanel.add(buttonPanel); }
From source file:gov.nist.spectrumbrowser.admin.AddNewSensor.java
License:Open Source License
public void draw() { try {/* w w w . j a v a 2 s .c o m*/ logger.finer("AddNewSensor: draw()"); HTML html = new HTML("<h2>Add New Sensor</h2>"); verticalPanel.clear(); verticalPanel.add(html); Grid grid = new Grid(7, 2); grid.setCellPadding(2); grid.setCellSpacing(2); grid.setBorderWidth(2); int row = 0; grid.setText(row, 0, "Sensor ID"); final TextBox sensorIdTextBox = new TextBox(); sensorIdTextBox.setText(sensor.getSensorId()); sensorIdTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { String sensorId = event.getValue(); if (sensorId == null || sensorId.equals("") || sensorId.equals("UNKNOWN")) { Window.alert("Please enter a valid sensor ID"); return; } ArrayList<Sensor> sensors = sensorConfig.getSensors(); for (Sensor sensor : sensors) { if (sensorId.equals(sensor.getSensorId())) { Window.alert("Please enter a unique sensor ID"); return; } } sensor.setSensorId(sensorId); } }); grid.setWidget(row, 1, sensorIdTextBox); row++; grid.setText(row, 0, "Sensor Key"); final TextBox sensorKeyTextBox = new TextBox(); sensorKeyTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { String key = event.getValue(); if (key == null || (passwordCheckingEnabled && !key.matches("((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&+=])).{12,}$"))) { Window.alert("Please enter a key : " + "\n1) at least 12 characters, " + "\n2) a digit, " + "\n3) an upper case letter, " + "\n4) a lower case letter, and " + "\n5) a special character(!@#$%^&+=)."); return; } sensor.setSensorKey(key); } }); sensorKeyTextBox.setText(sensor.getSensorKey()); grid.setWidget(row, 1, sensorKeyTextBox); row++; grid.setText(row, 0, "Measurement Type"); final TextBox measurementTypeTextBox = new TextBox(); measurementTypeTextBox.setTitle("Enter Swept-frequency or FFT-Power"); measurementTypeTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { String mtype = event.getValue(); if (mtype.equals(Defines.FFT_POWER) || mtype.equals(Defines.SWEPT_FREQUENCY)) { sensor.setMeasurementType(mtype); } else { Window.alert("Please enter FFT-Power or Swept-frequency (Case sensitive)"); } } }); grid.setWidget(row, 1, measurementTypeTextBox); row++; grid.setText(row, 0, "Is Streaming Enabled?"); final CheckBox streamingEnabled = new CheckBox(); streamingEnabled.setValue(false); streamingEnabled.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { boolean value = event.getValue(); sensor.setStreamingEnabled(value); } }); grid.setWidget(row, 1, streamingEnabled); row++; grid.setText(row, 0, "Data Retention(months)"); final TextBox dataRetentionTextBox = new TextBox(); dataRetentionTextBox.setText(Integer.toString(sensor.getDataRetentionDurationMonths())); dataRetentionTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { try { String valueStr = event.getValue(); if (valueStr == null) { Window.alert("Please enter integer >= 0"); return; } int value = Integer.parseInt(valueStr); if (value < 0) { Window.alert("Please enter integer >= 0"); return; } sensor.setDataRetentionDurationMonths(value); } catch (NumberFormatException ex) { Window.alert("Please enter positive integer"); return; } } }); grid.setWidget(row, 1, dataRetentionTextBox); row++; grid.setText(row, 0, "Sensor Admin Email"); final TextBox sensorAdminEmailTextBox = new TextBox(); sensorAdminEmailTextBox.setText(sensor.getSensorAdminEmail()); sensorAdminEmailTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { String email = event.getValue(); if (!email.matches( "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$")) { Window.alert("Please enter valid email address"); return; } sensor.setSensorAdminEmail(email); } }); grid.setWidget(row, 1, sensorAdminEmailTextBox); row++; grid.setText(row, 0, "Sensor Command Line Startup Params"); final TextBox startupParamsTextBox = new TextBox(); startupParamsTextBox.setWidth("200px"); startupParamsTextBox.setText(sensor.getStartupParams()); startupParamsTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { sensor.setStartupParams(event.getValue()); } }); Button submitButton = new Button("Apply"); submitButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (!sensor.validate()) { Window.alert("Error in entry - please enter all fields."); } else { logger.log(Level.FINER, "Adding Sensor " + sensor.getSensorId()); sensorConfig.setUpdateFlag(true); Admin.getAdminService().addSensor(sensor.toString(), sensorConfig); } } }); grid.setWidget(row, 1, startupParamsTextBox); verticalPanel.add(grid); HorizontalPanel hpanel = new HorizontalPanel(); hpanel.add(submitButton); Button cancelButton = new Button("Cancel"); cancelButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { sensorConfig.redraw(); } }); hpanel.add(cancelButton); Button logoffButton = new Button("Log Off"); logoffButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { admin.logoff(); } }); hpanel.add(logoffButton); verticalPanel.add(hpanel); } catch (Throwable th) { logger.log(Level.SEVERE, "Problem drawing screen", th); } }
From source file:gov.nist.spectrumbrowser.admin.DebugConfiguration.java
License:Open Source License
@Override public void draw() { verticalPanel.clear();/*from www. ja v a 2s . co m*/ HTML title = new HTML("<h3>Debug flags</h3>"); HTML helpText = new HTML("<p>Note: Debug flags return to default values on server restart.</p>"); verticalPanel.add(title); verticalPanel.add(helpText); grid = new Grid(jsonObject.keySet().size() + 1, 2); grid.setBorderWidth(2); grid.setCellPadding(2); grid.setCellPadding(2); grid.setText(0, 0, "Name"); grid.setText(0, 1, "Value"); int i = 1; for (final String key : jsonObject.keySet()) { grid.setWidget(i, 0, new Label(key)); final CheckBox checkBox = new CheckBox(); boolean value = jsonObject.get(key).isBoolean().booleanValue(); checkBox.setValue(value); checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { boolean value = event.getValue(); jsonObject.put(key, JSONBoolean.getInstance(value)); Admin.getAdminService().setDebugFlags(jsonObject.toString(), new SpectrumBrowserCallback<String>() { @Override public void onSuccess(String result) { try { JSONObject retval = JSONParser.parseLenient(result).isObject(); String status = retval.get("status").isString().stringValue(); if (!status.equals("OK")) { Window.alert("Unexpected response code"); admin.logoff(); } } catch (Throwable th) { Window.alert("error parsing response"); logger.log(Level.SEVERE, "Error parsing response", th); admin.logoff(); } } @Override public void onFailure(Throwable throwable) { Window.alert("error communicating with server"); logger.log(Level.SEVERE, "Error communicating with server", throwable); admin.logoff(); } }); } }); grid.setWidget(i, 1, checkBox); i++; } for (i = 0; i < grid.getColumnCount(); i++) { grid.getCellFormatter().setStyleName(0, i, "textLabelStyle"); } for (i = 0; i < grid.getRowCount(); i++) { for (int j = 0; j < grid.getColumnCount(); j++) { grid.getCellFormatter().setHorizontalAlignment(i, j, HasHorizontalAlignment.ALIGN_CENTER); grid.getCellFormatter().setVerticalAlignment(i, j, HasVerticalAlignment.ALIGN_MIDDLE); } } verticalPanel.add(grid); final HorizontalPanel urlPanel = new HorizontalPanel(); urlPanel.add(new Label("Click on logs button to fetch server logs")); Button getDebugLog = new Button("Logs"); getDebugLog.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Admin.getAdminService().getLogs(new SpectrumBrowserCallback<String>() { @Override public void onSuccess(String result) { try { JSONObject debugLogs = JSONParser.parseLenient(result).isObject(); String url = debugLogs.get("url").isString().stringValue(); urlPanel.clear(); Label label = new Label(url); urlPanel.add(label); } catch (Throwable throwable) { logger.log(Level.SEVERE, "Error Parsing response ", throwable); admin.logoff(); } } @Override public void onFailure(Throwable throwable) { logger.log(Level.SEVERE, "Error contacting server ", throwable); Window.alert("Error Parsing response"); admin.logoff(); } }); } }); verticalPanel.add(urlPanel); Button logoff = new Button("Log off"); logoff.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { admin.logoff(); } }); Button getTestCases = new Button("Get Test Cases"); getTestCases.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Window.alert("Not yet implemented"); } }); Button clearLogs = new Button("Clear logs"); clearLogs.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Window.alert("Not yet implemented"); /*boolean yesno = Window.confirm("This will restart services after clearing logs and log you off. Proceed?"); if (yesno) { Admin.getAdminService().clearLogs(new SpectrumBrowserCallback<String>() { @Override public void onSuccess(String result) { } @Override public void onFailure(Throwable throwable) { Window.alert("Error in processing request"); }} ); admin.logoff(); }*/ } }); HorizontalPanel buttonPanel = new HorizontalPanel(); buttonPanel.add(getDebugLog); buttonPanel.add(getTestCases); buttonPanel.add(clearLogs); buttonPanel.add(logoff); verticalPanel.add(buttonPanel); }
From source file:gov.nist.spectrumbrowser.admin.FftPowerSensorBands.java
License:Open Source License
public void draw() { verticalPanel.clear();/*ww w . java2s. com*/ HTML html = new HTML("<H2>Bands for sensor : " + sensor.getSensorId() + "</H2>"); verticalPanel.add(html); JSONObject sensorThresholds = sensor.getThresholds(); Grid grid = new Grid(sensorThresholds.keySet().size() + 1, 10); grid.setBorderWidth(2); grid.setCellPadding(2); grid.setCellSpacing(2); grid.setText(0, 0, "System To Detect"); grid.setText(0, 1, "Min Freq (Hz)"); grid.setText(0, 2, "Max Freq (Hz)"); grid.setText(0, 3, "Channel Count"); grid.setText(0, 4, "Sampling Rate"); grid.setText(0, 5, "FFT-Size"); grid.setText(0, 6, "Occupancy Threshold (dBm/Hz)"); grid.setText(0, 7, "Occupancy Threshold (dBm)"); grid.setText(0, 8, "Enabled?"); grid.setText(0, 9, "Delete Band"); grid.setBorderWidth(2); grid.setCellPadding(2); grid.setCellSpacing(2); CellFormatter formatter = grid.getCellFormatter(); for (int i = 0; i < grid.getRowCount(); i++) { for (int j = 0; j < grid.getColumnCount(); j++) { formatter.setHorizontalAlignment(i, j, HasHorizontalAlignment.ALIGN_CENTER); formatter.setVerticalAlignment(i, j, HasVerticalAlignment.ALIGN_MIDDLE); } } for (int i = 0; i < grid.getColumnCount(); i++) { grid.getCellFormatter().setStyleName(0, i, "textLabelStyle"); } int row = 1; for (String key : sensorThresholds.keySet()) { final FftPowerBand threshold = new FftPowerBand(sensorThresholds.get(key).isObject()); grid.setText(row, 0, threshold.getSystemToDetect()); grid.setText(row, 1, Long.toString(threshold.getMinFreqHz())); grid.setText(row, 2, Long.toString(threshold.getMaxFreqHz())); final TextBox channelCountTextBox = new TextBox(); channelCountTextBox.setText(Long.toString(threshold.getChannelCount())); channelCountTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { Long oldValue = Long.parseLong(channelCountTextBox.getValue()); try { long newValue = Long.parseLong(event.getValue()); threshold.setChannelCount((long) newValue); } catch (Exception ex) { Window.alert(ex.getMessage()); channelCountTextBox.setValue(Double.toString(oldValue)); } } }); grid.setWidget(row, 3, channelCountTextBox); final TextBox samplingRateTextBox = new TextBox(); samplingRateTextBox.setText(Long.toString(threshold.getSamplingRate())); samplingRateTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { Long oldValue = Long.parseLong(samplingRateTextBox.getValue()); try { long newValue = Long.parseLong(event.getValue()); threshold.setSamplingRate((long) newValue); } catch (Exception ex) { Window.alert(ex.getMessage()); samplingRateTextBox.setValue(Double.toString(oldValue)); } } }); grid.setWidget(row, 4, samplingRateTextBox); final TextBox fftSizeTextBox = new TextBox(); fftSizeTextBox.setText(Long.toString(threshold.getFftSize())); fftSizeTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { Long oldValue = Long.parseLong(fftSizeTextBox.getValue()); try { long newValue = Long.parseLong(event.getValue()); threshold.setFftSize((long) newValue); } catch (Exception ex) { Window.alert(ex.getMessage()); fftSizeTextBox.setValue(Double.toString(oldValue)); } } }); grid.setWidget(row, 5, fftSizeTextBox); final Label thresholdDbmLabel = new Label(); final TextBox thresholdTextBox = new TextBox(); thresholdTextBox.setText(Double.toString(threshold.getThresholdDbmPerHz())); thresholdTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { Double oldThreshold = Double.parseDouble(thresholdTextBox.getValue()); try { double newThreshold = Double.parseDouble(event.getValue()); threshold.setThresholdDbmPerHz(newThreshold); thresholdDbmLabel.setText(Float.toString(threshold.getThresholdDbm())); } catch (Exception ex) { Window.alert(ex.getMessage()); thresholdTextBox.setValue(Double.toString(oldThreshold)); } } }); grid.setWidget(row, 6, thresholdTextBox); thresholdDbmLabel.setText(Float.toString(threshold.getThresholdDbm())); grid.setWidget(row, 7, thresholdDbmLabel); CheckBox activeCheckBox = new CheckBox(); grid.setWidget(row, 8, activeCheckBox); if (!sensor.isStreamingEnabled()) { activeCheckBox.setValue(true); activeCheckBox.setEnabled(false); } else { activeCheckBox.setValue(threshold.isActive()); } activeCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { if (sensor.isStreamingEnabled()) { if (event.getValue()) { for (String key : sensor.getThresholds().keySet()) { FftPowerBand th = new FftPowerBand(sensor.getThreshold(key)); th.setActive(false); } } threshold.setActive(event.getValue()); draw(); } } }); Button deleteButton = new Button("Delete Band"); deleteButton.addClickHandler(new DeleteThresholdClickHandler(threshold)); grid.setWidget(row, 9, deleteButton); row++; } verticalPanel.add(grid); HorizontalPanel horizontalPanel = new HorizontalPanel(); Button addButton = new Button("Add Band"); addButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { new AddFftPowerSensorBand(admin, FftPowerSensorBands.this, sensorConfig, sensor, verticalPanel) .draw(); } }); horizontalPanel.add(addButton); Button doneButton = new Button("Done"); doneButton.setTitle("Return to Sensors screen"); doneButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { sensorConfig.redraw(); } }); horizontalPanel.add(doneButton); Button updateButton = new Button("Update"); updateButton.setTitle("Update sensor on the server"); updateButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Admin.getAdminService().updateSensor(sensor.toString(), sensorConfig); } }); horizontalPanel.add(updateButton); Button logoffButton = new Button("Log Off"); logoffButton.setTitle("Log off from admin"); logoffButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { admin.logoff(); } }); Button recomputeButton = new Button("Recompute Occupancies"); recomputeButton.setTitle("Recomputes per message summary occupancies."); recomputeButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { boolean yes = Window.confirm( "Ensure no users are using the system. This can take a long time. Sensor will be disabled. Proceed?"); if (yes) { final HTML html = new HTML( "<h3>Recomputing occupancies - this can take a while. Sensor will be disabled. Please wait. </h3>"); verticalPanel.add(html); Admin.getAdminService().updateSensor(sensor.toString(), sensorConfig); Admin.getAdminService().recomputeOccupancies(sensor.getSensorId(), new SpectrumBrowserCallback<String>() { @Override public void onSuccess(String result) { verticalPanel.remove(html); } @Override public void onFailure(Throwable throwable) { Window.alert("Error communicating with server"); admin.logoff(); } }); } } }); horizontalPanel.add(recomputeButton); horizontalPanel.add(logoffButton); verticalPanel.add(horizontalPanel); }
From source file:gov.nist.spectrumbrowser.admin.SensorConfig.java
License:Open Source License
@Override public void draw() { verticalPanel.clear();/*from ww w .j a v a 2 s . co m*/ HTML title = new HTML("<h3>Configured sensors. </h3>"); titlePanel = new HorizontalPanel(); titlePanel.add(title); HTML subtitle = new HTML("<p>Select Add button to add a new sensor. " + "Buttons on each sensor row allow you to reconfigure the sensor.</p>"); verticalPanel.add(titlePanel); verticalPanel.add(subtitle); ; grid = new Grid(sensors.size() + 1, 13); for (int i = 0; i < grid.getColumnCount(); i++) { grid.getCellFormatter().setStyleName(0, i, "textLabelStyle"); } for (int i = 0; i < grid.getRowCount(); i++) { for (int j = 0; j < grid.getColumnCount(); j++) { grid.getCellFormatter().setHorizontalAlignment(i, j, HasHorizontalAlignment.ALIGN_CENTER); grid.getCellFormatter().setVerticalAlignment(i, j, HasVerticalAlignment.ALIGN_MIDDLE); } } grid.setCellPadding(2); grid.setCellSpacing(2); grid.setBorderWidth(2); int col = 0; // Column headings. grid.setText(0, col++, "Sensor Identity"); //1 grid.setText(0, col++, "Storage Management");//2 grid.setText(0, col++, "Frequency Bands");//3 grid.setText(0, col++, "Show Activity");//4 grid.setText(0, col++, "Enabled?");//5 grid.setText(0, col++, "Get System Messages");//6 grid.setText(0, col++, "Measurement Params");//7 grid.setText(0, col++, "Startup Params");//8 grid.setText(0, col++, "Duplicate Settings");//9 grid.setText(0, col++, "Purge Data");//10 grid.setText(0, col++, "Remove Sensor");//11 grid.setText(0, col++, "Configuration Status"); //12 grid.setText(0, col++, "Run Status"); //13 int row = 1; for (final Sensor sensor : sensors) { col = 0; Button sensorIdentityButton = new Button(sensor.getSensorId()); sensorIdentityButton.setWidth("100%"); grid.setWidget(row, col++, sensorIdentityButton); sensorIdentityButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { new SensorIdentity(admin, SensorConfig.this, sensor, verticalPanel).draw(); } }); final Button manageStorage = new Button("Manage Storage"); manageStorage.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (sensor.getSensorStatus().equals("ENABLED")) { Window.alert("Please disable sensor first (click on check box)."); } else { new ManageStorage(admin, verticalPanel, sensors, sensor, SensorConfig.this).draw(); } } }); grid.setWidget(row, col++, manageStorage); int thresholdCount = sensor.getThresholds().keySet().size(); Button thresholdButton; if (thresholdCount == 0) thresholdButton = new Button("Add"); else thresholdButton = new Button("Change/Add"); thresholdButton.setTitle("Define Band Occupancy Threshold."); if (thresholdCount == 0) { thresholdButton.setStyleName("dangerous"); } thresholdButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (sensor.getMeasurementType().equals(Defines.SWEPT_FREQUENCY)) { new SweptFrequencySensorBands(admin, SensorConfig.this, sensor, verticalPanel).draw(); } else { new FftPowerSensorBands(admin, SensorConfig.this, sensor, verticalPanel).draw(); } } }); grid.setWidget(row, col++, thresholdButton); Button getMessageDates = new Button("Show"); getMessageDates.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { new ShowMessageDates(admin, SensorConfig.this, sensor, verticalPanel).draw(); } }); grid.setWidget(row, col++, getMessageDates); CheckBox statusCheckBox = new CheckBox(); statusCheckBox.setValue(sensor.getSensorStatus().equals("ENABLED")); statusCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { SensorConfig.this.updateFlag = true; Admin.getAdminService().toggleSensorStatus(sensor.getSensorId(), SensorConfig.this); } }); grid.setWidget(row, col++, statusCheckBox); Button downloadSysMessages = new Button("Get"); grid.setWidget(row, col++, downloadSysMessages); downloadSysMessages.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Admin.getAdminService().getSystemMessages(sensor.getSensorId(), new SpectrumBrowserCallback<String>() { @Override public void onSuccess(String result) { JSONObject jsonObj = JSONParser.parseLenient(result).isObject(); String status = jsonObj.get("status").isString().stringValue(); if (status.equals("OK")) { Window.alert("Please check your email in 10 minutes for notification"); } else { Window.alert(jsonObj.get("ErrorMessage").isString().stringValue()); } } @Override public void onFailure(Throwable throwable) { // TODO Auto-generated method stub } }); } }); Button streamingButton = new Button(); if (!sensor.isStreamingEnabled()) { streamingButton.setText("Measurement Params"); if (!sensor.isMeasurementConfigured()) { streamingButton.setStyleName("dangerous"); } streamingButton.setTitle("Configure sensor measurement parameters"); } else { streamingButton.setText("Streaming Params"); streamingButton.setTitle("Streaming Params"); if (!sensor.isStreamingConfigured()) { streamingButton.setStyleName("dangerous"); } } grid.setWidget(row, col++, streamingButton); // 9 streamingButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (sensor.isStreamingEnabled()) { new SetStreamingParams(admin, verticalPanel, sensor, SensorConfig.this).draw(); } else { new SetMeasurementParams(admin, verticalPanel, sensor, SensorConfig.this).draw(); } } }); TextBox startupParamsTextBox = new TextBox(); startupParamsTextBox.setWidth("120px"); grid.setWidget(row, col++, startupParamsTextBox); startupParamsTextBox.setTitle("Startup parameters (read by sensor on startup)"); startupParamsTextBox.setText(sensor.getStartupParams()); startupParamsTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { sensor.setStartupParams(event.getValue()); Admin.getAdminService().updateSensor(sensor.toString(), SensorConfig.this); } }); Button dupButton = new Button("Dup"); dupButton.setTitle("Creates a new sensor with the same settings"); dupButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { new AddNewSensor(admin, verticalPanel, sensor, SensorConfig.this).draw(); } }); grid.setWidget(row, col++, dupButton); Button purgeButton = new Button("Purge Data"); purgeButton.setTitle("WARNING: Removes Sensor and all data associated with it"); purgeButton.setStyleName("dangerous"); purgeButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (sensor.getSensorStatus().equals("ENABLED")) { Window.alert("Please toggle state of sensor"); return; } boolean yes = Window.confirm( "Remove the all associated data? Cannot be undone! Ensure no active sessions."); if (yes) { titlePanel.clear(); HTML html = new HTML( "<h3>Purging sensor " + sensor.getSensorId() + ". This can take a while! </h3>"); titlePanel.add(html); SensorConfig.this.updateFlag = true; Admin.getAdminService().purgeSensor(sensor.getSensorId(), SensorConfig.this); } } }); grid.setWidget(row, col++, purgeButton); Button removeButton = new Button("Remove Sensor"); removeButton.setTitle("WARNING: Removes Sensor and all data associated with it"); removeButton.setStyleName("dangerous"); removeButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (sensor.getSensorStatus().equals("ENABLED")) { Window.alert("Please toggle state of sensor"); return; } boolean yes = Window.confirm("Remove Sensor?"); if (yes) { titlePanel.clear(); HTML html = new HTML( "<h3>Removing " + sensor.getSensorId() + ". This can take a while! </h3>"); titlePanel.add(html); SensorConfig.this.updateFlag = true; Admin.getAdminService().deleteSensor(sensor.getSensorId(), SensorConfig.this); } } }); grid.setWidget(row, col++, removeButton); boolean isConfigured = true; if (sensor.getThresholdCount() == 0) { isConfigured = false; } else if (sensor.isStreamingEnabled()) { if (!new StreamingParams(sensor.getStreamingConfig()).verify()) { isConfigured = false; } } else if (!new MeasurementParams(sensor.getMeasurementParams()).verify()) { isConfigured = false; } grid.setText(row, col++, isConfigured ? "Configured" : "Incomplete"); grid.setText(row, col++, sensor.getSensorStatus()); row++; } verticalPanel.add(grid); HorizontalPanel buttonPanel = new HorizontalPanel(); Button addNewSensorButton = new Button("Add new sensor"); addNewSensorButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { new AddNewSensor(admin, verticalPanel, SensorConfig.this).draw(); } }); buttonPanel.add(addNewSensorButton); Button refreshButton = new Button("Refresh"); refreshButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { SensorConfig.this.redraw(); } }); buttonPanel.add(refreshButton); Button logoffButton = new Button("Log Off"); logoffButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { admin.logoff(); } }); buttonPanel.add(logoffButton); verticalPanel.add(buttonPanel); }