Example usage for com.google.gwt.event.logical.shared ValueChangeEvent getValue

List of usage examples for com.google.gwt.event.logical.shared ValueChangeEvent getValue

Introduction

In this page you can find the example usage for com.google.gwt.event.logical.shared ValueChangeEvent getValue.

Prototype

public T getValue() 

Source Link

Document

Gets the value.

Usage

From source file:gov.nist.spectrumbrowser.admin.AddNewSensor.java

License:Open Source License

public void draw() {
    try {//from   w  w w  .j a  va  2 s.  c  om
        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.AddOutboundPeer.java

License:Open Source License

public void draw() {
    verticalPanel.clear();//from   w w  w. ja va 2s  .  co  m
    HTML html = new HTML("<H2>Add peer for outbound registration</H2>");
    verticalPanel.add(html);
    Grid grid = new Grid(3, 2);
    grid.setText(0, 0, "Host");
    verticalPanel.add(grid);

    final TextBox nameTextBox = new TextBox();
    grid.setWidget(0, 1, nameTextBox);
    nameTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String ip = event.getValue();
            if (!validateHost(ip)) {
                Window.alert("Please enter a valid IP address");
                nameTextBox.setText("");
            }
        }
    });

    grid.setText(1, 0, "Port");
    final TextBox portTextBox = new TextBox();
    portTextBox.setText("443");
    portTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String portStr = event.getValue();
            if (!validatePort(portStr)) {
                Window.alert("Please enter valid port");
                portTextBox.setText("443");
            }

        }
    });
    grid.setWidget(1, 1, portTextBox);

    grid.setText(2, 0, "Protocol");
    final TextBox protocolTextBox = new TextBox();
    protocolTextBox.setText("https");
    protocolTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String protocol = event.getValue();
            if (!protocol.equals("http") && !protocol.equals("http")) {
                Window.alert("please enter http or https");
                protocolTextBox.setText("https");
            }
        }
    });
    grid.setWidget(2, 1, protocolTextBox);

    HorizontalPanel horizontalPanel = new HorizontalPanel();

    Button applyButton = new Button("Add");
    applyButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            String host = nameTextBox.getValue();
            if (!validateHost(host)) {
                Window.alert("Please enter valid host name");
                return;
            }
            int port = Integer.parseInt(portTextBox.getText());
            if (!validatePort(portTextBox.getText())) {
                Window.alert("please enter valid port");
                return;
            }
            String protocol = protocolTextBox.getText();
            Admin.getAdminService().addPeer(host, port, protocol, peers);
        }
    });
    horizontalPanel.add(applyButton);

    Button cancelButton = new Button("Cancel");
    horizontalPanel.add(cancelButton);
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            peers.draw();
        }
    });

    Button logoffButton = new Button("Log Off");
    horizontalPanel.add(logoffButton);
    logoffButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            admin.logoff();
            return;
        }
    });

    verticalPanel.add(horizontalPanel);

}

From source file:gov.nist.spectrumbrowser.admin.AddSweptFrequencySensorBand.java

License:Open Source License

public void draw() {
    verticalPanel.clear();/*  w  ww  .  j a v  a 2s  . co m*/
    HTML title = new HTML("<h2>Add a new band for sensor " + sensor.getSensorId() + "</h2>");
    verticalPanel.add(title);
    Grid grid = new Grid(5, 2);
    grid.setCellPadding(2);
    grid.setCellSpacing(2);
    grid.setBorderWidth(2);
    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);
        }
    }
    int row = 0;
    grid.setText(row, 0, "System To Detect");
    TextBox sysToDetectTextBox = new TextBox();
    sysToDetectTextBox.setValue(threshold.getSystemToDetect());
    sysToDetectTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String value = event.getValue();
            try {
                threshold.setSystemToDetect(value);
            } catch (IllegalArgumentException ex) {
                Window.alert(ex.getMessage());
            }

        }
    });
    grid.setWidget(row, 1, sysToDetectTextBox);

    row++;

    grid.setText(row, 0, "Min Freq. (Hz)");
    TextBox minFreqHzTextBox = new TextBox();
    minFreqHzTextBox.setEnabled(true);

    minFreqHzTextBox.setText(Long.toString(threshold.getMinFreqHz()));
    minFreqHzTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String val = event.getValue();
            try {
                long newVal = Long.parseLong(val);
                threshold.setMinFreqHz(newVal);
            } catch (NumberFormatException ex) {
                Window.alert("Please enter a valid number");
            } catch (IllegalArgumentException ex) {
                Window.alert(ex.getMessage());
            }
        }
    });
    grid.setWidget(row, 1, minFreqHzTextBox);

    row++;

    grid.setText(row, 0, "Max Freq. (Hz)");
    TextBox maxFreqHzTextBox = new TextBox();
    maxFreqHzTextBox.setEnabled(true);
    maxFreqHzTextBox.setText(Long.toString(threshold.getMaxFreqHz()));
    maxFreqHzTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String val = event.getValue();
            try {
                long newVal = Long.parseLong(val);
                threshold.setMaxFreqHz(newVal);
            } catch (NumberFormatException ex) {
                Window.alert("Please enter a valid number");
            } catch (IllegalArgumentException ex) {
                Window.alert(ex.getMessage());
            }
        }
    });
    grid.setWidget(row, 1, maxFreqHzTextBox);

    row++;

    grid.setText(row, 0, "Channel Count");
    TextBox channelCountTextBox = new TextBox();
    channelCountTextBox.setText(Long.toString(threshold.getChannelCount()));
    channelCountTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String val = event.getValue();
            try {
                long newVal = Long.parseLong(val);
                threshold.setChannelCount(newVal);
            } catch (NumberFormatException ex) {
                Window.alert("Please enter a valid number");
            } catch (IllegalArgumentException ex) {
                Window.alert(ex.getMessage());
            }
        }
    });
    grid.setWidget(row, 1, channelCountTextBox);

    row++;

    grid.setText(row, 0, "Occupancy Threshold (dBm/Hz)");
    TextBox thresholdTextBox = new TextBox();
    thresholdTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String val = event.getValue();
            try {
                double newValue = Double.parseDouble(val);
                threshold.setThresholdDbmPerHz(newValue);
            } catch (NumberFormatException ex) {
                Window.alert("Please enter a valid number");
            } catch (IllegalArgumentException ex) {
                Window.alert(ex.getMessage());
            }
        }
    });
    grid.setWidget(row, 1, thresholdTextBox);

    verticalPanel.add(grid);
    HorizontalPanel horizontalPanel = new HorizontalPanel();
    Button applyButton = new Button("Apply");
    horizontalPanel.add(applyButton);
    applyButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (!threshold.validate()) {
                Window.alert("Error in one or more entries");
            } else {
                sensor.addNewThreshold(AddSweptFrequencySensorBand.this.threshold.getSystemToDetect(),
                        threshold.getThreshold());
                Admin.getAdminService().updateSensor(sensor.toString(), sensorConfig);

                sensorThresholds.draw();
            }

        }
    });

    Button cancelButton = new Button("Cancel");
    horizontalPanel.add(cancelButton);
    cancelButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            sensorThresholds.draw();
        }
    });

    Button logoffButton = new Button("Log Off");
    horizontalPanel.add(logoffButton);
    logoffButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            admin.logoff();
        }
    });

    verticalPanel.add(horizontalPanel);

    for (int i = 0; i < grid.getRowCount(); i++) {
        grid.getCellFormatter().setStyleName(i, 0, "textLabelStyle");
    }

}

From source file:gov.nist.spectrumbrowser.admin.DebugConfiguration.java

License:Open Source License

@Override
public void draw() {
    verticalPanel.clear();//from w w w  .  j  ava  2  s.  c  o 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();// w ww .j  a v a2 s  . c om
    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.ManageStorage.java

License:Open Source License

public void draw() {
    verticalPanel.clear();/*from w  ww  .  j av  a2s .  co m*/

    HTML title = new HTML("<h3>Sensor Storage Management </h3>");
    verticalPanel.add(title);

    Grid grid = new Grid(2, 2);
    grid.setText(0, 0, "Data Retention Duration (months)");
    final TextBox dataRetentionTextBox = new TextBox();
    dataRetentionTextBox.setWidth("30px");
    dataRetentionTextBox.setValue(Integer.toString(sensor.getDataRetentionDurationMonths()));
    dataRetentionTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            try {
                int newRetention = Integer.parseInt(event.getValue());
                if (!sensor.setDataRetentionDurationMonths(newRetention)) {
                    Window.alert("Please enter a valid integer >= 0");
                    dataRetentionTextBox.setText(Integer.toString(sensor.getDataRetentionDurationMonths()));
                    return;
                }
                Admin.getAdminService().updateSensor(sensor.toString(), ManageStorage.this);
            } catch (Exception ex) {
                Window.alert("Please enter a valid integer >= 0");
            }
        }
    });
    grid.setWidget(0, 1, dataRetentionTextBox);

    Button cleanupButton = new Button("Garbage Collect");
    cleanupButton.setTitle("Removes timed out data");
    cleanupButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {

            if (sensor.getSensorStatus().equals("ENABLED")) {
                Window.alert("Please toggle sensor status");
                return;
            }
            boolean yes = Window
                    .confirm("This can take a while. Please ensure there are no active user sessions. "
                            + "Deleted records can't be reclaimed.");

            if (yes) {
                verticalPanel.add(progress);
                ManageStorage.this.updateFlag = true;
                Admin.getAdminService().garbageCollect(sensor.getSensorId(), ManageStorage.this);
            }
        }
    });

    verticalPanel.add(grid);

    HorizontalPanel hpanel = new HorizontalPanel();
    hpanel.add(cleanupButton);

    Button done = new Button("Done");
    done.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Window.alert("Please re-enable sensor on sensor management page");
            sensorConfig.draw();

        }
    });

    hpanel.add(done);

    Button logoffButton = new Button("Log out");
    logoffButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            admin.logoff();

        }
    });
    hpanel.add(logoffButton);
    verticalPanel.add(hpanel);

}

From source file:gov.nist.spectrumbrowser.admin.ScreenConfig.java

License:Open Source License

@Override
public void draw() {
    verticalPanel.clear();/* www  . j av  a2  s  .  c  o  m*/
    HTML title;
    title = new HTML("<h3>Specify screen configuration parameters.</h3>");

    titlePanel = new HorizontalPanel();
    titlePanel.add(title);
    verticalPanel.add(titlePanel);

    grid = new Grid(7, 2);
    grid.setCellSpacing(4);
    grid.setBorderWidth(2);
    verticalPanel.add(grid);

    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 index = 0;

    TextBox mapWidth = new TextBox();
    mapWidth.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String str = event.getValue();
            try {
                int newVal = Integer.parseInt(str);

                if (newVal < 400)
                    newVal = 400;
                else if (newVal > 1600)
                    newVal = 1600;

                jsonObject.put(Defines.MAP_WIDTH, new JSONNumber(newVal));
            } catch (NumberFormatException nfe) {
                Window.alert("Please enter a valid integer between 400 and 1600");
            }
        }
    });
    setInteger(index++, Defines.MAP_WIDTH, "Map Width (pixels)", mapWidth);

    TextBox mapHeight = new TextBox();
    mapHeight.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String str = event.getValue();
            try {
                int newVal = Integer.parseInt(str);

                if (newVal < 400)
                    newVal = 400;
                else if (newVal > 1600)
                    newVal = 1600;

                jsonObject.put(Defines.MAP_HEIGHT, new JSONNumber(newVal));
            } catch (NumberFormatException nfe) {
                Window.alert("Please enter a valid integer between 400 and 1600");
            }
        }
    });
    setInteger(index++, Defines.MAP_HEIGHT, "Map Height (pixels)", mapHeight);

    TextBox specWidth = new TextBox();
    specWidth.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String str = event.getValue();
            try {
                int newVal = Integer.parseInt(str);

                if (newVal < 400)
                    newVal = 400;
                else if (newVal > 1600)
                    newVal = 1600;

                jsonObject.put(Defines.SPEC_WIDTH, new JSONNumber(newVal));
            } catch (NumberFormatException nfe) {
                Window.alert("Please enter a valid integer between 400 and 1600");
            }
        }
    });
    setInteger(index++, Defines.SPEC_WIDTH, "Chart Width (pixels) for client side charts", specWidth);

    TextBox specHeight = new TextBox();
    specHeight.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String str = event.getValue();
            try {
                int newVal = Integer.parseInt(str);

                if (newVal < 400)
                    newVal = 400;
                else if (newVal > 1600)
                    newVal = 1600;

                jsonObject.put(Defines.SPEC_HEIGHT, new JSONNumber(newVal));
            } catch (NumberFormatException nfe) {
                Window.alert("Please enter a valid integer between 400 and 1600");
            }
        }
    });
    setInteger(index++, Defines.SPEC_HEIGHT, "Chart Height (pixels) for client side charts", specHeight);

    TextBox chartWidth = new TextBox();
    chartWidth.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String str = event.getValue();
            try {
                int newVal = Integer.parseInt(str);

                if (newVal < 1)
                    newVal = 1;
                else if (newVal > 10)
                    newVal = 10;

                jsonObject.put(Defines.CHART_WIDTH, new JSONNumber(newVal));
            } catch (NumberFormatException nfe) {
                Window.alert("Please enter a valid integer between 1 and 10");
            }
        }
    });
    setInteger(index++, Defines.CHART_WIDTH, "Aspect ratio (width) for server generated charts", chartWidth);

    TextBox chartHeight = new TextBox();
    chartHeight.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String str = event.getValue();
            try {
                int newVal = Integer.parseInt(str);

                if (newVal < 1)
                    newVal = 1;
                else if (newVal > 10)
                    newVal = 10;

                jsonObject.put(Defines.CHART_HEIGHT, new JSONNumber(newVal));
            } catch (NumberFormatException nfe) {
                Window.alert("Please enter a valid integer between 1 and 10");
            }
        }
    });
    setInteger(index++, Defines.CHART_HEIGHT, "Aspect ratio (height) for server generated charts", chartHeight);

    TextBox warningText = new TextBox();
    warningText.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            jsonObject.put(Defines.WARNING_TEXT, new JSONString(event.getValue()));

        }
    });

    warningText.setTitle(
            "Absolute server path to file containing HTML to be displayed on user access to the system. Blank if no warning");
    setText(index++, Defines.WARNING_TEXT, "Path to Warning Text displayed on first access to system",
            warningText);

    for (int i = 0; i < grid.getRowCount(); i++) {
        grid.getCellFormatter().setStyleName(i, 0, "textLabelStyle");
    }

    applyButton = new Button("Apply Changes");
    cancelButton = new Button("Cancel Changes");
    logoutButton = new Button("Log Out");

    applyButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {

            Admin.getAdminService().setScreenConfig(jsonObject.toString(),
                    new SpectrumBrowserCallback<String>() {

                        @Override
                        public void onSuccess(String result) {
                            JSONObject jsonObj = JSONParser.parseLenient(result).isObject();
                            if (jsonObj.get("status").isString().stringValue().equals("OK")) {
                                Window.alert("Configuration successfully updated");
                            } else {
                                String errorMessage = jsonObj.get("ErrorMessage").isString().stringValue();
                                Window.alert("Error in updating config - please re-enter. Error Message : "
                                        + errorMessage);
                            }
                        }

                        @Override
                        public void onFailure(Throwable throwable) {
                            Window.alert("Error communicating with server");
                            admin.logoff();
                        }
                    });
        }
    });

    cancelButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            redraw = true;
            Admin.getAdminService().getScreenConfig(ScreenConfig.this);
        }
    });

    logoutButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            admin.logoff();
        }
    });

    HorizontalPanel buttonPanel = new HorizontalPanel();
    buttonPanel.add(applyButton);
    buttonPanel.add(cancelButton);
    buttonPanel.add(logoutButton);
    verticalPanel.add(buttonPanel);

}

From source file:gov.nist.spectrumbrowser.admin.SensorIdentity.java

License:Open Source License

public void draw() {
    verticalPanel.clear();// w  w  w.j  a  va2 s  .  c  om
    HTML html = new HTML("<h3>Sensor Identity</h3>");
    verticalPanel.add(html);
    this.grid = new Grid(5, 2);

    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);

    verticalPanel.add(grid);
    int row = 0;
    grid.setText(row, 0, "Sensor Name:");
    grid.setText(row, 1, sensor.getSensorId()); // 0

    row++;

    grid.setText(row, 0, "Sensor Key:");
    final TextBox sensorKeyTextBox = new TextBox();

    grid.setWidget(row, 1, sensorKeyTextBox);
    sensorKeyTextBox.setText(sensor.getSensorKey());
    sensorKeyTextBox.setWidth("120px");
    sensorKeyTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String newKey = event.getValue();
            if (!sensor.setSensorKey(newKey)) {
                Window.alert("Please enter a key at least 4 characters long");
                sensorKeyTextBox.setText(sensor.getSensorKey());
                return;
            }
            Admin.getAdminService().updateSensor(sensor.toString(), sensorConfig);
        }
    });

    row++;

    grid.setText(row, 0, "Measurement Type:");
    grid.setText(row, 1, sensor.getMeasurementType());
    row++;

    grid.setText(row, 0, "Sensor Admin Email:");
    final TextBox adminEmailTextBox = new TextBox();
    adminEmailTextBox.setText(sensor.getSensorAdminEmail());
    adminEmailTextBox.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,})$")) {
                sensor.setSensorAdminEmail(email);
            } else {
                Window.alert("please enter a valid email address");
                adminEmailTextBox.setText(sensor.getSensorAdminEmail());
            }
            Admin.getAdminService().updateSensor(sensor.toString(), sensorConfig);
        }
    });
    grid.setWidget(row, 1, adminEmailTextBox);
    row++;

    boolean isStreamingEnabled = sensor.isStreamingEnabled();
    final CheckBox checkBox = new CheckBox();
    checkBox.setValue(isStreamingEnabled);
    grid.setText(row, 0, "isStreamingEnabled");
    grid.setWidget(row, 1, checkBox);
    checkBox.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            boolean currentState = sensor.isStreamingEnabled();
            boolean newState = !currentState;
            checkBox.setValue(newState);
            sensor.setStreamingEnabled(newState);
            Admin.getAdminService().updateSensor(sensor.toString(), sensorConfig);
        }
    });

    HorizontalPanel buttonPanel = new HorizontalPanel();

    Button okButton = new Button("Done");
    buttonPanel.add(okButton);
    okButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            sensorConfig.draw();
        }
    });
    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.SetStreamingParams.java

License:Open Source License

public void draw() {
    HTML html = new HTML("<h2>Streaming and I/Q capture settings for " + sensor.getSensorId() + "</h2>");
    verticalPanel.clear();/*from w w  w  . j av  a 2 s.  c o m*/
    verticalPanel.add(html);
    Grid grid = new Grid(5, 2);
    grid.setBorderWidth(2);
    grid.setCellPadding(2);
    grid.setCellSpacing(2);

    int row = 0;
    final TextBox streamingCaptureIntervalTextBox = new TextBox();
    streamingCaptureIntervalTextBox
            .setText(Integer.toString(sensorStreamingParams.getStreamingCaptureSamplingIntervalSeconds()));
    streamingCaptureIntervalTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            try {
                int streamingCaptureInterval = Integer.parseInt(event.getValue());
                if (!sensorStreamingParams
                        .setStreamingCaptureSamplingIntervalSeconds(streamingCaptureInterval)) {
                    Window.alert("Please enter a valid integer > 0");
                    streamingCaptureIntervalTextBox.setValue(Integer
                            .toString(sensorStreamingParams.getStreamingCaptureSamplingIntervalSeconds()));
                }
            } catch (Exception ex) {
                Window.alert("Please enter a valid integer >0");
                streamingCaptureIntervalTextBox.setValue(
                        Integer.toString(sensorStreamingParams.getStreamingCaptureSamplingIntervalSeconds()));
            }
        }
    });
    grid.setText(row, 0, "Time per spectrogram capture (s)");
    grid.setWidget(row, 1, streamingCaptureIntervalTextBox);

    row++;

    final CheckBox enableStreamingCapture = new CheckBox();
    enableStreamingCapture.setValue(sensorStreamingParams.getEnableStreamingCapture());
    grid.setText(row, 0, "Enable spectrogram capture");
    enableStreamingCapture.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            boolean newValue = event.getValue();
            sensorStreamingParams.setEnableStreamingCapture(newValue);
        }
    });

    grid.setWidget(row, 1, enableStreamingCapture);

    row++;

    final CheckBox enableIqCapture = new CheckBox();
    enableIqCapture.setValue(sensorStreamingParams.isIqCaptureEnabled());
    grid.setText(row, 0, "Enable I/Q capture");
    enableIqCapture.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            boolean newValue = event.getValue();
            sensorStreamingParams.setIqCaptureEnabled(newValue);
        }
    });
    grid.setWidget(row, 1, enableIqCapture);
    row++;

    final TextBox streamingSecondsPerFrameTextBox = new TextBox();
    streamingSecondsPerFrameTextBox
            .setText(Float.toString(sensorStreamingParams.getStreamingSecondsPerFrame()));
    streamingSecondsPerFrameTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            try {
                float streamingSecondsPerFrame = Float.parseFloat(event.getValue());
                if (!sensorStreamingParams.setStreamingSecondsPerFrame(streamingSecondsPerFrame)) {
                    Window.alert("Please set a float > 0");

                    streamingSecondsPerFrameTextBox
                            .setText(Float.toString(sensorStreamingParams.getStreamingSecondsPerFrame()));
                }

            } catch (Exception ex) {
                Window.alert(ex.getMessage());
                streamingSecondsPerFrameTextBox
                        .setText(Float.toString(sensorStreamingParams.getStreamingSecondsPerFrame()));
            }
        }
    });

    grid.setText(row, 0, "Time between readings (aggregation window) (s)");
    grid.setWidget(row, 1, streamingSecondsPerFrameTextBox);
    streamingSecondsPerFrameTextBox.setTitle("Time between readings sent from the sensor");

    row++;
    final TextBox streamingFilterTextBox = new TextBox();
    streamingFilterTextBox.setText(sensorStreamingParams.getStreamingFilter());
    streamingFilterTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String newFilter = event.getValue();
            if (!sensorStreamingParams.setStreamingFilter(newFilter)) {
                Window.alert("Please specify MAX_HOLD or MEAN");
                streamingFilterTextBox.setText(sensorStreamingParams.getStreamingFilter());
            }
        }
    });
    grid.setText(row, 0, "Aggregation Filter (MAX_HOLD or MEAN)");
    grid.setWidget(row, 1, streamingFilterTextBox);

    verticalPanel.add(grid);
    HorizontalPanel hpanel = new HorizontalPanel();
    Button applyButton = new Button("Apply");
    applyButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (!sensorStreamingParams.verify()) {
                Window.alert(
                        "Please specify all fields correctly. Capture interval must be > sampling interval.");
                return;
            } else {
                sensor.setStreamingEnabled(true);
                sensorConfig.setUpdateFlag(true);
                Admin.getAdminService().updateSensor(sensor.toString(), sensorConfig);
            }
        }
    });
    hpanel.add(applyButton);

    for (int i = 0; i < grid.getRowCount(); i++) {
        grid.getCellFormatter().setStyleName(i, 0, "textLabelStyle");
    }

    Button cancelButton = new Button("Cancel");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            sensorStreamingParams.restore();
            sensorConfig.draw();
        }
    });
    hpanel.add(cancelButton);

    Button clearButton = new Button("Clear");
    clearButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            sensorStreamingParams.clear();
            sensorConfig.setUpdateFlag(true);
            Admin.getAdminService().updateSensor(sensor.toString(), sensorConfig);
        }
    });
    hpanel.add(clearButton);

    Button armButton = new Button("Arm for I/Q Capture (one-shot)");
    armButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (!sensorStreamingParams.isIqCaptureEnabled()) {
                Window.alert("I/Q capture not enabled");
                return;
            }
            Admin.getAdminService().armSensor(sensor.getSensorId(), true,
                    new SpectrumBrowserCallback<String>() {

                        @Override
                        public void onSuccess(String result) {
                            Window.alert("Sensor is armed for one-shot capture");

                        }

                        @Override
                        public void onFailure(Throwable throwable) {
                            Window.alert("Error communicating with server");
                            admin.logoff();

                        }
                    });

        }
    });
    hpanel.add(armButton);

    Button deleteIQCaptureButton = new Button("Delete Capture Events");
    deleteIQCaptureButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Admin.getAdminService().deleteAllCaptureEvents(sensor.getSensorId(),
                    new SpectrumBrowserCallback<String>() {

                        @Override
                        public void onSuccess(String result) {
                            Window.alert("Capture Events Deleted");

                        }

                        @Override
                        public void onFailure(Throwable throwable) {
                            Window.alert("Error communicating with server");
                            admin.logoff();

                        }
                    });

        }
    });
    hpanel.add(deleteIQCaptureButton);

    Button logoffButton = new Button("Log Off");
    logoffButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            admin.logoff();
        }
    });
    hpanel.add(logoffButton);

    verticalPanel.add(hpanel);

}

From source file:gov.nist.spectrumbrowser.admin.SweptFrequencySensorBands.java

License:Open Source License

public void draw() {

    verticalPanel.clear();/*  w  w w. j a  v  a  2s .c  o  m*/
    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, 8);
    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, "Occupancy Threshold (dBm/Hz)");
    grid.setText(0, 5, "Occupancy Threshold (dBm)");
    grid.setText(0, 6, "Enabled?");
    grid.setText(0, 7, "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 SweptFrequencyBand threshold = new SweptFrequencyBand(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 Label thresholdLabel = 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);
                    thresholdLabel.setText(Float.toString(threshold.getThresholdDbm()));
                } catch (Exception ex) {
                    Window.alert(ex.getMessage());
                    thresholdTextBox.setValue(Double.toString(oldThreshold));
                }
            }

        });
        grid.setWidget(row, 4, thresholdTextBox);
        thresholdLabel.setText(Float.toString(threshold.getThresholdDbm()));
        grid.setWidget(row, 5, thresholdLabel);
        CheckBox activeCheckBox = new CheckBox();
        grid.setWidget(row, 6, activeCheckBox);
        activeCheckBox.setValue(threshold.isActive());
        activeCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

            @Override
            public void onValueChange(ValueChangeEvent<Boolean> event) {

                if (event.getValue()) {
                    for (String key : sensor.getThresholds().keySet()) {
                        SweptFrequencyBand th = new SweptFrequencyBand(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, 7, 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 AddSweptFrequencySensorBand(admin, SweptFrequencySensorBands.this, sensorConfig, sensor,
                    verticalPanel).draw();

        }
    });
    horizontalPanel.add(addButton);

    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. Update sensor before proceeding. This can take a long time. Proceed?");
            if (yes) {

                final HTML html = new HTML(
                        "<h3>Recomputing thresholds - this can take a while. Please wait. </h3>");
                verticalPanel.add(html);

                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);

    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 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.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            admin.logoff();
        }
    });

    horizontalPanel.add(logoffButton);

    verticalPanel.add(horizontalPanel);

}