Example usage for com.google.gwt.user.client.ui Grid getColumnCount

List of usage examples for com.google.gwt.user.client.ui Grid getColumnCount

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Grid getColumnCount.

Prototype

public int getColumnCount() 

Source Link

Document

Gets the number of columns in this grid.

Usage

From source file:asquare.gwt.tests.memoryleak.client.Demo.java

License:Apache License

public void onModuleLoad() {
    m_button.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (m_popupPanel == null) {
                m_popupPanel = new NonModalPopup();
                Grid grid = new Grid(10, 10);
                for (int row = 0; row < grid.getRowCount(); row++) {
                    for (int col = 0; col < grid.getColumnCount(); col++) {
                        grid.setHTML(row, col, "<img height='20' width='20' src='JohannesElison.jpg'/>");
                    }//from   ww w. j  a v  a  2  s.c  om
                }
                m_popupPanel.add(grid);
                m_popupPanel.show();
                m_button.setText("Remove Popup");
            } else {
                m_popupPanel.hide();
                m_popupPanel = null;
                m_button.setText("Add Popup");
            }
        }
    });
    RootPanel.get().add(m_button);
}

From source file:co.fxl.gui.gwt.GWTGridPanel.java

License:Open Source License

private void resize() {
    Grid grid = (Grid) container.widget;
    if (gridCell.column >= grid.getColumnCount()) {
        grid.resizeColumns(gridCell.column + 1);
    }//from  w  w w  .j a va  2 s  . com
    if (gridCell.row >= grid.getRowCount()) {
        grid.resizeRows(gridCell.row + 1);
    }
}

From source file:co.fxl.gui.gwt.GWTGridPanel.java

License:Open Source License

@Override
public int columns() {
    Grid grid = (Grid) container.widget;
    return grid.getColumnCount();
}

From source file:com.example.texture_mapping.client.Texture_mapping.java

License:Apache License

public void onModuleLoad() {
    // HTML ben/*from   w  ww. j ava  2  s .  co  m*/
    Grid grid = new Grid(3, 3);
    grid.setBorderWidth(1);

    int numRows = grid.getRowCount();
    int numColumns = grid.getColumnCount();
    for (int row = 0; row < numRows; row++) {
        for (int col = 0; col < numColumns; col++) {
            grid.setWidget(row, col, new Image(PlaceholderImages.INSTANCE.myImage()));
        }
    }

    RootPanel.get().add(grid);

    // WebGL
    final Canvas webGLCanvas = Canvas.createIfSupported();
    webGLCanvas.setCoordinateSpaceHeight(500); // ToDo: AutoSize
    webGLCanvas.setCoordinateSpaceWidth(500);
    glContext = (WebGLRenderingContext) webGLCanvas.getContext("experimental-webgl");
    if (glContext == null) {
        glContext = (WebGLRenderingContext) webGLCanvas.getContext("experimental-webgl");
    }

    if (glContext == null) {
        Window.alert("Sorry, Your Browser doesn't support WebGL!");
    }

    glContext.viewport(0, 0, 500, 500);

    RootPanel.get("gwtGL").add(webGLCanvas);
    start();
}

From source file:com.google.gwt.sample.showcase.client.content.tables.CwGrid.java

License:Apache License

/**
 * Initialize this example./* w  w w.ja  v  a 2 s  . c  o m*/
 */
@ShowcaseSource
@Override
public Widget onInitialize() {
    // Create a grid
    Grid grid = new Grid(4, 4);

    // Add images to the grid
    int numRows = grid.getRowCount();
    int numColumns = grid.getColumnCount();
    for (int row = 0; row < numRows; row++) {
        for (int col = 0; col < numColumns; col++) {
            grid.setWidget(row, col, new Image(Showcase.images.gwtLogo()));
        }
    }

    // Return the panel
    grid.ensureDebugId("cwGrid");
    return grid;
}

From source file:com.nanosim.client.content.tables.CwGrid.java

License:Apache License

/**
 * Initialize this example.//  w w w  .  j a va 2 s . c o m
 */
@NanosimSource
@Override
public Widget onInitialize() {
    // Create a grid
    Grid grid = new Grid(4, 4);

    // Add images to the grid
    int numRows = grid.getRowCount();
    int numColumns = grid.getColumnCount();
    for (int row = 0; row < numRows; row++) {
        for (int col = 0; col < numColumns; col++) {
            grid.setWidget(row, col, Nanosim.images.logo().createImage());
        }
    }

    // Return the panel
    grid.ensureDebugId("cwGrid");
    return grid;
}

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

License:Open Source License

public void draw() {
    verticalPanel.clear();//  ww  w.  j  av a2s.co  m
    HTML title = new HTML("<h2>Add a new band for sensor " + sensor.getSensorId() + "</h2>");
    verticalPanel.add(title);
    final Grid grid = new Grid(8, 3);
    grid.setCellPadding(2);
    grid.setCellSpacing(2);
    grid.setBorderWidth(2);
    grid.setText(0, 0, "Setting");
    grid.setText(0, 1, "Value");
    grid.setText(0, 2, "Info");
    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 = 1;
    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();
            verified = false;
            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();
            verified = false;
            try {
                long newVal = (long) Double.parseDouble(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); //2

    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();
            verified = false;
            try {
                long newVal = (long) Double.parseDouble(val);
                threshold.setMaxFreqHz(newVal);
                if (threshold.getMinFreqHz() >= 0 && threshold.getMaxFreqHz() > 0) {
                    channelCountTextBox.setEnabled(true);
                }
            } catch (NumberFormatException ex) {
                Window.alert("Please enter a valid number");
            } catch (IllegalArgumentException ex) {
                Window.alert(ex.getMessage());
            }
        }
    });
    grid.setWidget(row, 1, maxFreqHzTextBox);//3

    row++;

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

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String val = event.getValue();
            verified = false;
            try {
                long newVal = Long.parseLong(val);
                threshold.setChannelCount(newVal);

                thresholdTextBox.setEnabled(true);
            } catch (NumberFormatException ex) {
                Window.alert("Please enter a valid number");
            } catch (IllegalArgumentException ex) {
                Window.alert(ex.getMessage());
            }
        }
    });
    grid.setWidget(row, 1, channelCountTextBox);//4

    row++;

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

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String val = event.getValue();
            verified = false;
            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); //5
    row++;

    grid.setText(row, 0, "Sampling Rate (Samples/S) ");
    TextBox samplingRateTextBox = new TextBox();
    samplingRateTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String val = event.getValue();
            verified = false;
            try {
                long newVal = (long) Double.parseDouble(val);
                threshold.setSamplingRate(newVal);
            } catch (NumberFormatException ex) {
                Window.alert("Please enter a valid number");
            } catch (IllegalArgumentException ex) {
                Window.alert(ex.getMessage());
            }
        }
    });

    grid.setWidget(row, 1, samplingRateTextBox);//6
    row++;

    grid.setText(row, 0, "FFT Size");
    TextBox fftSizeTextBox = new TextBox();
    fftSizeTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String val = event.getValue();
            verified = false;
            try {
                long newVal = Long.parseLong(val);
                threshold.setFftSize(newVal);
            } catch (NumberFormatException ex) {
                Window.alert("Please enter a valid number");
            } catch (IllegalArgumentException ex) {
                Window.alert(ex.getMessage());
            }
        }
    });

    grid.setWidget(row, 1, fftSizeTextBox);
    row++;

    verticalPanel.add(grid);
    HorizontalPanel horizontalPanel = new HorizontalPanel();
    final Button okButton = new Button("Check Entries");
    okButton.setTitle("Check entered values and print additional information");
    final Button applyButton = new Button("Apply");
    applyButton.setTitle("Please Chek Entries and Apply to update server entries");
    applyButton.setEnabled(false);
    horizontalPanel.add(okButton);
    okButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // TODO Auto-generated method stub
            if (!threshold.validate()) {
                Window.alert("Error in one or more entries");
            } else {
                long channelCount = threshold.getChannelCount();
                grid.setText(4, 2, "Resolution BW = "
                        + ((threshold.getMaxFreqHz() - threshold.getMinFreqHz()) / (1000 * channelCount)) + " "
                        + " KHz");
                double thresholdDbmPerHz = threshold.getThresholdDbmPerHz();
                double resolutionBw = (threshold.getMaxFreqHz() - threshold.getMinFreqHz()) / channelCount;
                grid.setText(5, 2, "Threshold (dBm) = " + (thresholdDbmPerHz + 10 * Math.log10(resolutionBw)));
                verified = true;
                applyButton.setEnabled(true);
            }
        }

    });

    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(AddFftPowerSensorBand.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);

}

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

License:Open Source License

public void draw() {
    verticalPanel.clear();//  w  w w  . j  a v  a  2s.  c o  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.FftPowerSensorBands.java

License:Open Source License

public void draw() {

    verticalPanel.clear();/*  w  w  w  . j a  v  a 2s  .  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.SessionManagement.java

License:Open Source License

@Override
public void draw() {
    try {//from w w w.j  ava 2  s . c om
        verticalPanel.clear();
        HTML title = new HTML("<h2>Active Sessions </h2>");
        verticalPanel.add(title);
        if (frozen) {
            HTML subtitle = new HTML("<h3>New session creation is temporarily suspended by " + freezeRequester
                    + ". Users cannot use the system.</h3>");
            verticalPanel.add(subtitle);
        }

        int nrows = userSessions.size() + adminSessions.size();
        Grid grid = new Grid(nrows + 1, 5);
        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);
            }
        }

        for (int i = 0; i < grid.getColumnCount(); i++) {
            grid.getCellFormatter().setStyleName(0, i, "textLabelStyle");
        }
        grid.setBorderWidth(2);
        grid.setCellSpacing(2);
        grid.setCellPadding(2);
        grid.setText(0, 0, "Email Address");
        grid.setText(0, 1, "Remote IP Address");
        grid.setText(0, 2, "Session Start Time");
        grid.setText(0, 3, "Session End Time");
        grid.setText(0, 4, "User Privilege");

        for (int i = 0; i < userSessions.size(); i++) {
            JSONObject jsonObj = userSessions.get(i).isObject();
            String userName = jsonObj.get(Defines.USER_NAME).isString().stringValue();
            int row = i + 1;
            grid.setText(row, 0, userName);
            String ipAddr = jsonObj.get(Defines.REMOTE_ADDRESS).isString().stringValue();
            grid.setText(row, 1, ipAddr);
            String startTime = jsonObj.get(Defines.SESSION_LOGIN_TIME).isString().stringValue();
            grid.setText(row, 2, startTime);
            String expiryTime = jsonObj.get(Defines.EXPIRE_TIME).isString().stringValue();
            grid.setText(row, 3, expiryTime);
            grid.setText(row, 4, "user");

        }
        for (int i = 0; i < adminSessions.size(); i++) {
            JSONObject jsonObj = adminSessions.get(i).isObject();
            int row = i + userSessions.size() + 1;
            String userName = jsonObj.get(Defines.USER_NAME).isString().stringValue();
            grid.setText(row, 0, userName);
            String ipAddr = jsonObj.get(Defines.REMOTE_ADDRESS).isString().stringValue();
            grid.setText(row, 1, ipAddr);
            String startTime = jsonObj.get(Defines.SESSION_LOGIN_TIME).isString().stringValue();
            grid.setText(row, 2, startTime);
            String expiryTime = jsonObj.get(Defines.EXPIRE_TIME).isString().stringValue();
            grid.setText(row, 3, expiryTime);
            grid.setText(row, 4, "admin");
        }
        verticalPanel.add(grid);

        HorizontalPanel hpanel = new HorizontalPanel();

        Button freezeButton = new Button("Freeze Sessions");
        hpanel.add(freezeButton);
        freezeButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                boolean yesno = Window.confirm("Warning! No new sessions will be allowed.\n "
                        + "Email will be sent to the administrator when all active sessions are terminated.\n Proceed?");
                if (yesno) {
                    SessionManagement.this.redraw = true;
                    Admin.getAdminService().freezeSessions(SessionManagement.this);
                }
            }
        });

        Button unfreezeButton = new Button("Cancel Freeze");

        hpanel.add(unfreezeButton);
        unfreezeButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                SessionManagement.this.redraw = true;
                Admin.getAdminService().unfreezeSessions(SessionManagement.this);

            }
        });

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

            @Override
            public void onClick(ClickEvent event) {
                timer.cancel();
                admin.logoff();
            }
        });
        verticalPanel.add(hpanel);
        timer = new Timer() {
            @Override
            public void run() {
                if (Admin.getSessionToken() != null) {
                    SessionManagement.this.redraw = true;
                    Admin.getAdminService().getSessions(SessionManagement.this);
                }
            }

        };

        timer.schedule(5 * 1000);
    } catch (Throwable th) {
        logger.log(Level.SEVERE, "Error drawing", th);
        admin.logoff();
    }

}