@Override
 public void finalizeInitOperations() {
   super.finalizeInitOperations();
   super.selectButton.setText(
       LayerModuleConstants.INSTANCE.GPProjectSearchPanel_selectButtonText());
   super.search.setFieldLabel(
       LayerModuleConstants.INSTANCE.GPProjectSearchPanel_searchlabelText());
   GPProjectAction action = new GPProjectAction(GPTrustedLevel.HIGH, this);
   GPSecureButton addProjectButton =
       new GPSecureButton(
           ButtonsConstants.INSTANCE.addText(),
           AbstractImagePrototype.create(LayerResources.ICONS.projectAdd()),
           action);
   super.addButton(1, addProjectButton);
   addProjectButton.disable();
   this.editButton =
       new GPSecureButton(
           ButtonsConstants.INSTANCE.editText(),
           AbstractImagePrototype.create(BasicWidgetResources.ICONS.edit()),
           action);
   this.editButton.disable();
   super.addButton(2, this.editButton);
   this.deleteButton =
       new GPSecureButton(
           ButtonsConstants.INSTANCE.deleteText(),
           AbstractImagePrototype.create(LayerResources.ICONS.projectDelete()),
           new DeleteProjectAction(GPTrustedLevel.FULL, this));
   this.deleteButton.disable();
   super.addButton(3, this.deleteButton);
   ShareProjectAction shareProjectAction = new ShareProjectAction(GPTrustedLevel.HIGH, this);
   this.shareButton =
       new GPSecureButton(
           ButtonsConstants.INSTANCE.shareText(),
           AbstractImagePrototype.create(LayerResources.ICONS.arrowRefresh()),
           shareProjectAction);
   this.shareButton.disable();
   super.addButton(4, this.shareButton);
 }
Exemplo n.º 2
0
  private void createUploadComponent(String uploadAction, final GPExtensions... extensions) {
    uploaderProgressBar = new UploaderProgressBar();
    formPanel.setAction(GWT.getModuleBaseURL() + uploadAction);
    formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    formPanel.setMethod(FormPanel.METHOD_POST);

    this.verticalPanel = new VerticalPanel();

    this.queryParameter = new Hidden();

    this.verticalPanel.add(queryParameter);

    formPanel.setWidget(verticalPanel);

    fileUpload = new FileUpload();
    fileUpload.setName("uploadFormElement");
    verticalPanel.add(fileUpload);

    buttonSubmit =
        new Button(
            ButtonsConstants.INSTANCE.submitText(),
            new SelectionListener<ButtonEvent>() {

              @Override
              public void componentSelected(ButtonEvent ce) {
                uploaderProgressBar.show("Uploading...");
                formPanel.submit();
                if ((fileUpload.getFilename() != null)
                    && isValidExtensions(fileUpload.getFilename(), extensions)) {
                  LayoutManager.getInstance()
                      .getStatusMap()
                      .setBusy(BasicWidgetConstants.INSTANCE.GPFileUploader_uploadInProgressText());
                }
              }
            });
    verticalPanel.add(buttonSubmit);

    // Add an event handler to the form.
    formPanel.addSubmitHandler(
        new FormPanel.SubmitHandler() {

          @Override
          public void onSubmit(SubmitEvent event) {
            // This event is fired just before the form is submitted. We can
            // take this opportunity to perform validation
            if (!isValidExtensions(fileUpload.getFilename(), extensions)) {
              uploaderProgressBar.hide();
              LayoutManager.getInstance()
                  .getStatusMap()
                  .setStatus(
                      BasicWidgetConstants.INSTANCE.GPFileUploader_failedStatusText(),
                      EnumSearchStatus.STATUS_NO_SEARCH.toString());
              GeoPlatformMessage.errorMessage(
                  BasicWidgetConstants.INSTANCE.GPFileUploader_failedErrorMessageTitleText(),
                  BasicWidgetConstants.INSTANCE.GPFileUploader_failedErrorKindFileBodyText());
              event.cancel();
              formPanel.reset();
            }
          }
        });

    formPanel.addSubmitCompleteHandler(
        new FormPanel.SubmitCompleteHandler() {

          @Override
          public void onSubmitComplete(SubmitCompleteEvent event) {
            // When the form submission is successfully completed,
            // this event is fired. Assuming the service returned a
            // response of type text/html, we can get the result text here
            // (see the FormPanel documentation for further explanation)
            htmlResult = event.getResults();
            System.out.println("HTML Result: " + htmlResult);
            // Execute this code only if the session is still alive
            if (htmlResult.contains("Session Timeout")) {
              GPHandlerManager.fireEvent(new GPLoginEvent(null));
            } else if (!htmlResult.contains("HTTP ERROR")) {
              formPanel.reset();
              htmlResult = htmlResult.replaceAll("<pre>", "");
              htmlResult = htmlResult.replaceAll("</pre>", "");
              htmlResult =
                  htmlResult.replaceAll(
                      "<pre style=\"word-wrap: break-word; white-space: pre-wrap;\">", "");
              if (GPSharedUtils.isNotEmpty(htmlResult)) {
                //                                logger.info("HTMLResult: " + htmlResult);
                uploadEvent.setResult(htmlResult);
                GPHandlerManager.fireEvent(uploadEvent);
                // done.enable();
                // mapPreviewWidget.drawAoiOnMap(wkt);
                LayoutManager.getInstance()
                    .getStatusMap()
                    .setStatus(
                        BasicWidgetConstants.INSTANCE.GPFileUploader_successStatusText(),
                        EnumSearchStatus.STATUS_SEARCH.toString());
              } else {
                LayoutManager.getInstance()
                    .getStatusMap()
                    .setStatus(
                        BasicWidgetConstants.INSTANCE.GPFileUploader_failedStatusText(),
                        EnumSearchStatus.STATUS_NO_SEARCH.toString());
              }
            } else {
              GeoPlatformMessage.errorMessage(
                  BasicWidgetConstants.INSTANCE.GPFileUploader_failedErrorMessageTitleText(),
                  BasicWidgetConstants.INSTANCE.GPFileUploader_failedErrorGenericBodyText());
              LayoutManager.getInstance()
                  .getStatusMap()
                  .setStatus(
                      BasicWidgetConstants.INSTANCE.GPFileUploader_failedStatusText(),
                      EnumSearchStatus.STATUS_NO_SEARCH.toString());
            }
            uploaderProgressBar.hide();
          }
        });
  }
/**
 * @author Nazzareno Sileno - CNR IMAA geoSDI Group
 * @email [email protected]
 */
public class LayerTimeFilterWidget extends GeoPlatformWindow {

  public static final String LAYER_TIME_DELIMITER = " - [";
  private static final short WIDGET_HEIGHT = 250;
  private static final short WIDGET_WIDTH = 400;
  private final TimeFilterLayerMapEvent timeFilterLayerMapEvent = new TimeFilterLayerMapEvent();
  private final GPTreeLabelEvent labelEvent = new TreeChangeLabelEvent();
  private NumberField startFilterNumberField;
  private NumberField endFilterNumberField;
  private ComboBox<DimensionData> startDimensionComboBox;
  private ComboBox<DimensionData> endDimensionComboBox;
  private ListStore<DimensionData> startStore;
  private ListStore<DimensionData> endStore;
  private GPTreePanel<GPBeanTreeModel> treePanel;
  private Label dimensionSizeLabel;
  private final Radio fixedDimensionRadio = new Radio();
  private final Radio variableDimensionRadio = new Radio();
  private final LayoutContainer fixedDimensionContainer = new LayoutContainer(new FormLayout());
  private final LayoutContainer variableDimensionContainer;
  private RadioGroup dimensionRadioGroup;
  private SelectionListener<ButtonEvent> applyFilterSelectionListener;
  private Label endTimeLabel;
  private Label startTimeLabel;
  private Timer animationTimer;
  private SelectionListener<ButtonEvent> playSelectioListener;
  private ToggleButton playButton =
      new ToggleButton(
          ButtonsConstants.INSTANCE.playText(),
          AbstractImagePrototype.create(LayerResources.ICONS.playTime()));
  private Slider slider;
  private CheckBox rangeCheckBox;

  public LayerTimeFilterWidget(boolean lazy, GPTreePanel<GPBeanTreeModel> treePanel) {
    super(lazy);
    this.variableDimensionContainer =
        new LayoutContainer(new FormLayout()) {
          @Override
          protected void onAttach() {
            super.onAttach();
            playButton.enable();
          }

          @Override
          protected void onHide() {
            super.onHide();
            stopPlayer();
            playButton.disable();
          }

          @Override
          protected void onShow() {
            super.onShow();
            playButton.enable();
          }

          @Override
          protected void onDetach() {
            super.onDetach();
            stopPlayer();
            playButton.disable();
          }
        };
    this.treePanel = treePanel;
  }

  @Override
  public void addComponent() {
    this.dimensionRadioGroup = new RadioGroup();
    this.dimensionRadioGroup.setFieldLabel(
        LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_dimensionRadioLabelText());
    fixedDimensionRadio.setBoxLabel(
        LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_fixedDimensionRadioLabelText());
    fixedDimensionRadio.setHideLabel(Boolean.TRUE);
    this.dimensionRadioGroup.add(fixedDimensionRadio);
    variableDimensionRadio.setBoxLabel(
        LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_variableDimensionRadioLabelText());
    variableDimensionRadio.setHideLabel(Boolean.TRUE);
    this.dimensionRadioGroup.add(variableDimensionRadio);
    this.fixedDimensionContainer.setVisible(Boolean.FALSE);
    this.variableDimensionContainer.setVisible(Boolean.FALSE);
    this.fixedDimensionRadio.addListener(
        Events.Change,
        new Listener<FieldEvent>() {
          @Override
          public void handleEvent(FieldEvent fe) {
            if (fixedDimensionRadio.getValue()) {
              fixedDimensionContainer.setVisible(Boolean.TRUE);
              variableDimensionContainer.setVisible(Boolean.FALSE);
            }
          }
        });
    this.variableDimensionRadio.addListener(
        Events.Change,
        new Listener<FieldEvent>() {
          @Override
          public void handleEvent(FieldEvent fe) {
            if (variableDimensionRadio.getValue()) {
              variableDimensionContainer.setVisible(Boolean.TRUE);
              fixedDimensionContainer.setVisible(Boolean.FALSE);
            }
          }
        });

    this.startStore = new ListStore<DimensionData>();
    this.startDimensionComboBox = new ComboBox<DimensionData>();
    this.startDimensionComboBox.setFieldLabel(
        LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_startDimensionComboLabelText());
    this.startDimensionComboBox.setStore(this.startStore);
    this.startDimensionComboBox.setDisplayField(DimensionData.DIMENSION_KEY);
    this.startDimensionComboBox.setEditable(Boolean.FALSE);
    this.startDimensionComboBox.addSelectionChangedListener(
        new SelectionChangedListener<DimensionData>() {
          @Override
          public void selectionChanged(SelectionChangedEvent<DimensionData> se) {
            if (se.getSelectedItem() != null) {
              endStore.removeAll();
              int indexStart = startStore.getModels().indexOf(se.getSelectedItem()) + 1;
              //                    System.out.println("Sublist start: " + indexStart);
              //                    System.out.println("Sublist end: " +
              // (startStore.getModels().size() - 1));
              if (indexStart < startStore.getModels().size()) {
                endDimensionComboBox.enable();
                endStore.add(
                    startStore
                        .getModels()
                        .subList(
                            startStore.indexOf(se.getSelectedItem()) + 1,
                            startStore.getModels().size()));
              } else {
                endDimensionComboBox.disable();
              }
            }
          }
        });
    this.endStore = new ListStore<DimensionData>();
    this.endDimensionComboBox = new ComboBox<DimensionData>();
    this.endDimensionComboBox.setFieldLabel(
        LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_endDimensionComboLabelText());
    this.endDimensionComboBox.setStore(this.endStore);
    this.endDimensionComboBox.setDisplayField(DimensionData.DIMENSION_KEY);
    this.endDimensionComboBox.disable();
    this.endDimensionComboBox.setEditable(Boolean.FALSE);
    dimensionSizeLabel = new Label();
    dimensionSizeLabel.setStyleAttribute("font-size", "12px");
    this.startFilterNumberField = new NumberField();
    this.startFilterNumberField.setFireChangeEventOnSetValue(Boolean.TRUE);
    this.startFilterNumberField.addListener(
        Events.Change,
        new Listener<BaseEvent>() {
          @Override
          public void handleEvent(BaseEvent be) {
            if (checkStartFieldValue()) {
              int fromFilter = startFilterNumberField.getValue().intValue();
              int position = startStore.getModels().size() - fromFilter - 1;
              String tooltip =
                  (String) startStore.getModels().get(position).get(DimensionData.DIMENSION_KEY);
              //                            startStore.getModels().size() - fromFilter - 1).get(
              startFilterNumberField.setToolTip(tooltip);
              startTimeLabel.setHtml(tooltip);
              slider.setValue(position);
            } else {
              startTimeLabel.setHtml("");
              startFilterNumberField.setToolTip("");
            }
          }
        });
    startTimeLabel = new Label();
    startTimeLabel.setStyleAttribute("font-size", "1.3em");
    this.startFilterNumberField.setSize(50, 30);
    this.endFilterNumberField = new NumberField();
    this.endFilterNumberField.setFireChangeEventOnSetValue(Boolean.TRUE);
    endTimeLabel = new Label();
    endTimeLabel.setStyleAttribute("font-size", "1.3em");
    this.endFilterNumberField.addListener(
        Events.Change,
        new Listener<BaseEvent>() {
          @Override
          public void handleEvent(BaseEvent be) {
            if (checkEndFieldValue()) {
              int endFilter = endFilterNumberField.getValue().intValue();
              String tooltip =
                  (String) startStore.getModels().get(endFilter).get(DimensionData.DIMENSION_KEY);
              //                            startStore.getModels().size() - endFilter - 1).
              endFilterNumberField.setToolTip(tooltip);
              endTimeLabel.setHtml(tooltip);
            } else {
              endTimeLabel.setHtml("");
              endFilterNumberField.setToolTip("");
            }
          }
        });
    this.endFilterNumberField.setSize(50, 30);
    FormPanel panel = new FormPanel();
    panel.setHeaderVisible(Boolean.FALSE);
    panel.setFrame(Boolean.TRUE);
    panel.setBorders(Boolean.FALSE);
    panel.setHeight(WIDGET_HEIGHT - 67);
    panel.add(this.dimensionRadioGroup);
    panel.setStyleAttribute("background-color", "white");
    this.variableDimensionContainer.add(dimensionSizeLabel, new FormData("100%"));

    Portal portal = new Portal(3);
    portal.setBorders(false);
    portal.setColumnWidth(0, .20);
    portal.setColumnWidth(1, .60);
    portal.setColumnWidth(2, .20);

    Portlet portlet = new Portlet();
    portlet.setLayout(new FitLayout());
    portlet.setHeaderVisible(false);
    portlet.setSize(50, 30);
    portlet.add(this.startFilterNumberField);
    portal.add(portlet, 0);
    portlet = new Portlet(new CenterLayout());
    portlet.setHeaderVisible(false);
    portlet.setSize(100, 30);
    this.rangeCheckBox = new CheckBox();
    rangeCheckBox.setValue(true);
    rangeCheckBox.setBoxLabel("range");
    portlet.add(rangeCheckBox);
    portlet.setBorders(false);
    portal.add(portlet, 1);
    portlet = new Portlet();
    portlet.setHeaderVisible(false);
    portlet.setSize(50, 30);
    portlet.add(this.endFilterNumberField);
    portal.add(portlet, 2);

    this.variableDimensionContainer.add(portal, new FormData("99%"));
    //
    this.slider =
        new Slider() {
          @Override
          public void setValue(int value) {
            super.setValue(value);
            super.setMessage("" + (startStore.getModels().size() - value));
          }
        };
    slider.setIncrement(1);
    this.variableDimensionContainer.add(slider, new FormData("98%"));

    this.fixedDimensionContainer.add(this.startDimensionComboBox);
    this.fixedDimensionContainer.add(this.endDimensionComboBox);
    panel.add(this.fixedDimensionContainer, new FormData("100%"));
    panel.add(this.variableDimensionContainer, new FormData("100%"));
    super.add(panel);
    this.playSelectioListener =
        new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            //                System.out.println("Play button status: ");
            if (!playButton.isPressed()) {
              playButton.setText(ButtonsConstants.INSTANCE.playText());
              playButton.setIcon(AbstractImagePrototype.create(LayerResources.ICONS.playTime()));
              animationTimer.cancel();
            } else {
              Number startValueNumber = startFilterNumberField.getValue();
              if (startValueNumber == null) {
                GeoPlatformMessage.alertMessage(
                    LayerModuleConstants.INSTANCE
                        .LayerTimeFilterWidget_timeFilterWarningTitleText(),
                    LayerModuleConstants.INSTANCE
                        .LayerTimeFilterWidget_timeFilterWarningBodyText());
              } else {
                slider.setValue(startStore.getModels().size() - startValueNumber.intValue() - 1);
                playButton.setIcon(AbstractImagePrototype.create(LayerResources.ICONS.pauseTime()));
                playButton.setText(ButtonsConstants.INSTANCE.pauseText());
                playTimeFilter();
              }
            }
          }
        };
    playButton.addSelectionListener(playSelectioListener);
    playButton.setHeight(30);
    super.addButton(playButton);

    Button apply = new Button(ButtonsConstants.INSTANCE.applyText());
    this.applyFilterSelectionListener =
        new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            GPLayerTreeModel layerSelected =
                (GPLayerTreeModel) treePanel.getSelectionModel().getSelectedItem();
            IMementoSave mementoSave =
                MementoModuleInjector.MainInjector.getInstance().getMementoSave();
            AbstractMementoOriginalProperties memento =
                mementoSave.copyOriginalProperties(layerSelected);
            String layerName;
            if (layerSelected.getAlias() != null
                && layerSelected.getAlias().indexOf(LAYER_TIME_DELIMITER) != -1) {
              layerName =
                  layerSelected
                      .getAlias()
                      .substring(0, layerSelected.getAlias().indexOf(LAYER_TIME_DELIMITER));
            } else {
              layerName = layerSelected.getLabel();
            }
            if (fixedDimensionRadio.getValue()) {
              String timeFilter =
                  (String) startDimensionComboBox.getValue().get(DimensionData.DIMENSION_KEY);
              if (endDimensionComboBox.getValue() != null) {
                timeFilter +=
                    "/" + (String) endDimensionComboBox.getValue().get(DimensionData.DIMENSION_KEY);
              }
              layerSelected.setTimeFilter(timeFilter);
              layerSelected.setVariableTimeFilter(null);
              layerSelected.setAlias(
                  layerName + LAYER_TIME_DELIMITER + layerSelected.getTimeFilter() + "]");
              WidgetPropertiesHandlerManager.fireEvent(labelEvent);
            } else {
              if ((rangeCheckBox.getValue() && !checkEndFieldValue()) || !checkStartFieldValue()) {
                GeoPlatformMessage.errorMessage(
                    LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_timeFilterErrorTitleText(),
                    LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_timeFilterErrorBodyText());
                return;
              } else {
                int fromFilter = slider.getValue();
                String timeFilter = "" + (startStore.getModels().size() - fromFilter - 1);
                String variableTimeFilter =
                    (String)
                        startStore.getModels().get(fromFilter).get(DimensionData.DIMENSION_KEY);
                if (rangeCheckBox.getValue() && playButton.isPressed()) {
                  fromFilter =
                      startStore.getModels().size()
                          - startFilterNumberField.getValue().intValue()
                          - 1;
                  timeFilter = "" + startFilterNumberField.getValue().intValue();
                  variableTimeFilter =
                      (String)
                          startStore.getModels().get(fromFilter).get(DimensionData.DIMENSION_KEY);
                  //
                  int toFilter = slider.getValue();
                  timeFilter += "/" + (startStore.getModels().size() - slider.getValue() - 1);
                  variableTimeFilter +=
                      "/"
                          + (String)
                              startStore.getModels().get(toFilter).get(DimensionData.DIMENSION_KEY);
                } // This is usefull when press Apply button to show all the elements in range
                else if (rangeCheckBox.getValue() && endFilterNumberField.getValue() != null) {
                  fromFilter =
                      startStore.getModels().size()
                          - startFilterNumberField.getValue().intValue()
                          - 1;
                  timeFilter = "" + startFilterNumberField.getValue().intValue();
                  variableTimeFilter =
                      (String)
                          startStore.getModels().get(fromFilter).get(DimensionData.DIMENSION_KEY);
                  //
                  int toFilter =
                      startStore.getModels().size()
                          - endFilterNumberField.getValue().intValue()
                          - 1;
                  timeFilter += "/" + endFilterNumberField.getValue().intValue();
                  variableTimeFilter +=
                      "/"
                          + (String)
                              startStore.getModels().get(toFilter).get(DimensionData.DIMENSION_KEY);
                }
                layerSelected.setTimeFilter(timeFilter);
                layerSelected.setVariableTimeFilter(variableTimeFilter);
                layerSelected.setAlias(
                    layerName + LAYER_TIME_DELIMITER + layerSelected.getVariableTimeFilter() + "]");
                WidgetPropertiesHandlerManager.fireEvent(labelEvent);
                slider.setMessage(variableTimeFilter);
                GeoPlatformMessage.infoMessage(
                    LayerModuleConstants.INSTANCE
                        .LayerTimeFilterWidget_timeFilterMessageTitleText(),
                    LayerModuleMessages.INSTANCE.LayerTimeFilterWidget_layerStatusShowedMessage(
                        timeFilter));
              }
            }
            mementoSave.putOriginalPropertiesInCache(memento);
            timeFilterLayerMapEvent.setLayerBean(layerSelected);
            GPHandlerManager.fireEvent(timeFilterLayerMapEvent);
            treePanel.refresh(layerSelected);
          }
        };

    apply.addSelectionListener(applyFilterSelectionListener);

    super.addButton(apply);
    Button close =
        new Button(
            ButtonsConstants.INSTANCE.closeText(),
            new SelectionListener<ButtonEvent>() {
              @Override
              public void componentSelected(ButtonEvent ce) {
                startFilterNumberField.clear();
                startTimeLabel.setHtml("");
                endTimeLabel.setHtml("");
                endFilterNumberField.clear();
                hide();
              }
            });

    super.addButton(close);
  }

  private void playTimeFilter() {
    animationTimer =
        new Timer() {
          @Override
          public void run() {
            //                    int startValue = getFielValueDecrement(startFilterNumberField);
            int startValue = slider.getValue();
            if (startValue != startStore.getModels().size() - 1
                && (endFilterNumberField.getValue() != null
                    && (startStore.getModels().size() - startValue - 1)
                        != (endFilterNumberField.getValue().intValue() - 1))) {
              slider.setValue(++startValue);
              // This call produce the update in map
              applyFilterSelectionListener.componentSelected(null);
            } else {
              stopPlayer();
            }
          }
        };
    animationTimer.scheduleRepeating(5000);
  }

  private void stopPlayer() {
    if (playButton.isPressed()) {
      playButton.toggle(Boolean.FALSE);
      playSelectioListener.componentSelected(null);
      // This call produce the update in map
      applyFilterSelectionListener.componentSelected(null);
    }
  }

  private boolean checkStartFieldValue() {
    boolean condition = false;
    //        System.out.println("Start store size: " + startStore.getModels().size());
    if (startFilterNumberField.getValue() != null) {
      int fromFilter = startFilterNumberField.getValue().intValue();
      //            System.out.println("From filter: " + fromFilter);
      if (fromFilter >= 0 && fromFilter <= startStore.getModels().size() - 1) {
        condition = true;
      }
    }
    return condition;
  }

  private boolean checkEndFieldValue() {
    boolean condition = false;
    if (this.checkStartFieldValue() && endFilterNumberField.getValue() != null) {
      int fromFilter = startFilterNumberField.getValue().intValue();
      int toFilter = endFilterNumberField.getValue().intValue();
      //            System.out.println("To filter: " + toFilter);
      if (toFilter < fromFilter && toFilter >= 0) {
        condition = true;
      }
    }
    return condition;
  }

  private void loadDataToDisplay() {
    final GetLayerDimensionRequest getLayerDimensionRequest =
        GWT.<GetLayerDimensionRequest>create(GetLayerDimensionRequest.class);

    final GPLayerTreeModel layerSelected =
        (GPLayerTreeModel) treePanel.getSelectionModel().getSelectedItem();
    getLayerDimensionRequest.setLayerName(layerSelected.getName());

    ClientCommandDispatcher.getInstance()
        .execute(
            new GPClientCommand<GetLayerDimensionResponse>() {
              private static final long serialVersionUID = 4372276287420606744L;

              {
                super.setCommandRequest(getLayerDimensionRequest);
              }

              @Override
              public void onCommandSuccess(GetLayerDimensionResponse response) {
                List<String> dimensionList =
                    Lists.<String>newArrayList(response.getResult().split(","));
                dimensionSizeLabel.setHtml(
                    LayerModuleMessages.INSTANCE.LayerTimeFilterWidget_dimensionSizeHTMLMessage(
                        dimensionList.size()));
                dimensionSizeLabel.setStyleAttribute("font-size", "1.3em");
                dimensionSizeLabel.setStyleAttribute("text-align", "right");
                startStore.removeAll();
                endStore.removeAll();
                for (String dimension : GPSharedUtils.safeList(dimensionList)) {
                  startStore.add(new DimensionData(dimension));
                }
                if (!dimensionList.isEmpty()) {
                  slider.setMaxValue(dimensionList.size());
                  slider.setMinValue(0);
                  endFilterNumberField.setValue(0);
                  if (layerSelected.getTimeFilter() != null) {
                    String[] timeFilterSplitted = layerSelected.getTimeFilter().split("/");
                    int startDimensionPosition = Integer.parseInt(timeFilterSplitted[0]);
                    slider.setValue(startStore.getModels().size() - startDimensionPosition - 1);
                    startFilterNumberField.setValue(startDimensionPosition);
                    if (timeFilterSplitted.length > 1) {
                      int endDimensionPosition = Integer.parseInt(timeFilterSplitted[1]);
                      endFilterNumberField.setValue(endDimensionPosition);
                    }
                  } else {
                    startFilterNumberField.setValue(dimensionList.size() - 1);
                  }
                }
              }

              @Override
              public void onCommandFailure(Throwable exception) {
                if (exception.getCause() instanceof GPSessionTimeout) {
                  GPHandlerManager.fireEvent(new GPLoginEvent(null));
                } else {
                  GeoPlatformMessage.errorMessage(
                      LayerModuleConstants.INSTANCE
                          .LayerTimeFilterWidget_timeFilterErrorTitleText(),
                      WindowsConstants.INSTANCE.errorMakingConnectionBodyText());
                  LayoutManager.getInstance()
                      .getStatusMap()
                      .setStatus(
                          LayerModuleConstants.INSTANCE
                              .LayerTimeFilterWidget_statusTimeFilterErrorLoadingText(),
                          SearchStatus.EnumSearchStatus.STATUS_NO_SEARCH.toString());
                  System.out.println(
                      "Error Loading Time Filter: "
                          + exception.toString()
                          + " data: "
                          + exception.getMessage());
                }
              }
            });
  }

  @Override
  public void show() {
    super.show();
    this.loadDataToDisplay();
    GPLayerTreeModel layerElement =
        (GPLayerTreeModel) treePanel.getSelectionModel().getSelectedItem();
    String timeFilter = layerElement.getTimeFilter();
    String variableTimeFilter = layerElement.getVariableTimeFilter();
    if (variableTimeFilter != null) {
      try {
        String[] variableTimeFilterSplitted = timeFilter.split("/");
        int integerTimeFilter = Integer.parseInt(variableTimeFilterSplitted[0]);
        this.startFilterNumberField.setValue(integerTimeFilter);
        this.dimensionRadioGroup.setValue(this.variableDimensionRadio);
        if (variableTimeFilterSplitted.length > 1) {
          integerTimeFilter = Integer.parseInt(variableTimeFilterSplitted[1]);
          this.endFilterNumberField.setValue(integerTimeFilter);
        }
      } catch (NumberFormatException nfe) {
      }
    } else if (timeFilter != null) {
      String[] timeFilterSplitted = timeFilter.split("/");
      this.startDimensionComboBox.setValue(new DimensionData(timeFilterSplitted[0]));
      if (timeFilterSplitted.length > 1) {
        this.endDimensionComboBox.enable();
        this.endDimensionComboBox.setValue(new DimensionData(timeFilterSplitted[1]));
      }
      this.dimensionRadioGroup.setValue(this.fixedDimensionRadio);
    }
  }

  @Override
  public void initSize() {
    super.setSize(WIDGET_WIDTH, WIDGET_HEIGHT);
  }

  @Override
  public void setWindowProperties() {
    super.setHeadingHtml(
        LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_timeFilderHeadingText());
    super.setLayout(new FormLayout());
    super.setModal(Boolean.TRUE);
  }
}
  @Override
  public void addComponent() {
    this.dimensionRadioGroup = new RadioGroup();
    this.dimensionRadioGroup.setFieldLabel(
        LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_dimensionRadioLabelText());
    fixedDimensionRadio.setBoxLabel(
        LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_fixedDimensionRadioLabelText());
    fixedDimensionRadio.setHideLabel(Boolean.TRUE);
    this.dimensionRadioGroup.add(fixedDimensionRadio);
    variableDimensionRadio.setBoxLabel(
        LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_variableDimensionRadioLabelText());
    variableDimensionRadio.setHideLabel(Boolean.TRUE);
    this.dimensionRadioGroup.add(variableDimensionRadio);
    this.fixedDimensionContainer.setVisible(Boolean.FALSE);
    this.variableDimensionContainer.setVisible(Boolean.FALSE);
    this.fixedDimensionRadio.addListener(
        Events.Change,
        new Listener<FieldEvent>() {
          @Override
          public void handleEvent(FieldEvent fe) {
            if (fixedDimensionRadio.getValue()) {
              fixedDimensionContainer.setVisible(Boolean.TRUE);
              variableDimensionContainer.setVisible(Boolean.FALSE);
            }
          }
        });
    this.variableDimensionRadio.addListener(
        Events.Change,
        new Listener<FieldEvent>() {
          @Override
          public void handleEvent(FieldEvent fe) {
            if (variableDimensionRadio.getValue()) {
              variableDimensionContainer.setVisible(Boolean.TRUE);
              fixedDimensionContainer.setVisible(Boolean.FALSE);
            }
          }
        });

    this.startStore = new ListStore<DimensionData>();
    this.startDimensionComboBox = new ComboBox<DimensionData>();
    this.startDimensionComboBox.setFieldLabel(
        LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_startDimensionComboLabelText());
    this.startDimensionComboBox.setStore(this.startStore);
    this.startDimensionComboBox.setDisplayField(DimensionData.DIMENSION_KEY);
    this.startDimensionComboBox.setEditable(Boolean.FALSE);
    this.startDimensionComboBox.addSelectionChangedListener(
        new SelectionChangedListener<DimensionData>() {
          @Override
          public void selectionChanged(SelectionChangedEvent<DimensionData> se) {
            if (se.getSelectedItem() != null) {
              endStore.removeAll();
              int indexStart = startStore.getModels().indexOf(se.getSelectedItem()) + 1;
              //                    System.out.println("Sublist start: " + indexStart);
              //                    System.out.println("Sublist end: " +
              // (startStore.getModels().size() - 1));
              if (indexStart < startStore.getModels().size()) {
                endDimensionComboBox.enable();
                endStore.add(
                    startStore
                        .getModels()
                        .subList(
                            startStore.indexOf(se.getSelectedItem()) + 1,
                            startStore.getModels().size()));
              } else {
                endDimensionComboBox.disable();
              }
            }
          }
        });
    this.endStore = new ListStore<DimensionData>();
    this.endDimensionComboBox = new ComboBox<DimensionData>();
    this.endDimensionComboBox.setFieldLabel(
        LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_endDimensionComboLabelText());
    this.endDimensionComboBox.setStore(this.endStore);
    this.endDimensionComboBox.setDisplayField(DimensionData.DIMENSION_KEY);
    this.endDimensionComboBox.disable();
    this.endDimensionComboBox.setEditable(Boolean.FALSE);
    dimensionSizeLabel = new Label();
    dimensionSizeLabel.setStyleAttribute("font-size", "12px");
    this.startFilterNumberField = new NumberField();
    this.startFilterNumberField.setFireChangeEventOnSetValue(Boolean.TRUE);
    this.startFilterNumberField.addListener(
        Events.Change,
        new Listener<BaseEvent>() {
          @Override
          public void handleEvent(BaseEvent be) {
            if (checkStartFieldValue()) {
              int fromFilter = startFilterNumberField.getValue().intValue();
              int position = startStore.getModels().size() - fromFilter - 1;
              String tooltip =
                  (String) startStore.getModels().get(position).get(DimensionData.DIMENSION_KEY);
              //                            startStore.getModels().size() - fromFilter - 1).get(
              startFilterNumberField.setToolTip(tooltip);
              startTimeLabel.setHtml(tooltip);
              slider.setValue(position);
            } else {
              startTimeLabel.setHtml("");
              startFilterNumberField.setToolTip("");
            }
          }
        });
    startTimeLabel = new Label();
    startTimeLabel.setStyleAttribute("font-size", "1.3em");
    this.startFilterNumberField.setSize(50, 30);
    this.endFilterNumberField = new NumberField();
    this.endFilterNumberField.setFireChangeEventOnSetValue(Boolean.TRUE);
    endTimeLabel = new Label();
    endTimeLabel.setStyleAttribute("font-size", "1.3em");
    this.endFilterNumberField.addListener(
        Events.Change,
        new Listener<BaseEvent>() {
          @Override
          public void handleEvent(BaseEvent be) {
            if (checkEndFieldValue()) {
              int endFilter = endFilterNumberField.getValue().intValue();
              String tooltip =
                  (String) startStore.getModels().get(endFilter).get(DimensionData.DIMENSION_KEY);
              //                            startStore.getModels().size() - endFilter - 1).
              endFilterNumberField.setToolTip(tooltip);
              endTimeLabel.setHtml(tooltip);
            } else {
              endTimeLabel.setHtml("");
              endFilterNumberField.setToolTip("");
            }
          }
        });
    this.endFilterNumberField.setSize(50, 30);
    FormPanel panel = new FormPanel();
    panel.setHeaderVisible(Boolean.FALSE);
    panel.setFrame(Boolean.TRUE);
    panel.setBorders(Boolean.FALSE);
    panel.setHeight(WIDGET_HEIGHT - 67);
    panel.add(this.dimensionRadioGroup);
    panel.setStyleAttribute("background-color", "white");
    this.variableDimensionContainer.add(dimensionSizeLabel, new FormData("100%"));

    Portal portal = new Portal(3);
    portal.setBorders(false);
    portal.setColumnWidth(0, .20);
    portal.setColumnWidth(1, .60);
    portal.setColumnWidth(2, .20);

    Portlet portlet = new Portlet();
    portlet.setLayout(new FitLayout());
    portlet.setHeaderVisible(false);
    portlet.setSize(50, 30);
    portlet.add(this.startFilterNumberField);
    portal.add(portlet, 0);
    portlet = new Portlet(new CenterLayout());
    portlet.setHeaderVisible(false);
    portlet.setSize(100, 30);
    this.rangeCheckBox = new CheckBox();
    rangeCheckBox.setValue(true);
    rangeCheckBox.setBoxLabel("range");
    portlet.add(rangeCheckBox);
    portlet.setBorders(false);
    portal.add(portlet, 1);
    portlet = new Portlet();
    portlet.setHeaderVisible(false);
    portlet.setSize(50, 30);
    portlet.add(this.endFilterNumberField);
    portal.add(portlet, 2);

    this.variableDimensionContainer.add(portal, new FormData("99%"));
    //
    this.slider =
        new Slider() {
          @Override
          public void setValue(int value) {
            super.setValue(value);
            super.setMessage("" + (startStore.getModels().size() - value));
          }
        };
    slider.setIncrement(1);
    this.variableDimensionContainer.add(slider, new FormData("98%"));

    this.fixedDimensionContainer.add(this.startDimensionComboBox);
    this.fixedDimensionContainer.add(this.endDimensionComboBox);
    panel.add(this.fixedDimensionContainer, new FormData("100%"));
    panel.add(this.variableDimensionContainer, new FormData("100%"));
    super.add(panel);
    this.playSelectioListener =
        new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            //                System.out.println("Play button status: ");
            if (!playButton.isPressed()) {
              playButton.setText(ButtonsConstants.INSTANCE.playText());
              playButton.setIcon(AbstractImagePrototype.create(LayerResources.ICONS.playTime()));
              animationTimer.cancel();
            } else {
              Number startValueNumber = startFilterNumberField.getValue();
              if (startValueNumber == null) {
                GeoPlatformMessage.alertMessage(
                    LayerModuleConstants.INSTANCE
                        .LayerTimeFilterWidget_timeFilterWarningTitleText(),
                    LayerModuleConstants.INSTANCE
                        .LayerTimeFilterWidget_timeFilterWarningBodyText());
              } else {
                slider.setValue(startStore.getModels().size() - startValueNumber.intValue() - 1);
                playButton.setIcon(AbstractImagePrototype.create(LayerResources.ICONS.pauseTime()));
                playButton.setText(ButtonsConstants.INSTANCE.pauseText());
                playTimeFilter();
              }
            }
          }
        };
    playButton.addSelectionListener(playSelectioListener);
    playButton.setHeight(30);
    super.addButton(playButton);

    Button apply = new Button(ButtonsConstants.INSTANCE.applyText());
    this.applyFilterSelectionListener =
        new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            GPLayerTreeModel layerSelected =
                (GPLayerTreeModel) treePanel.getSelectionModel().getSelectedItem();
            IMementoSave mementoSave =
                MementoModuleInjector.MainInjector.getInstance().getMementoSave();
            AbstractMementoOriginalProperties memento =
                mementoSave.copyOriginalProperties(layerSelected);
            String layerName;
            if (layerSelected.getAlias() != null
                && layerSelected.getAlias().indexOf(LAYER_TIME_DELIMITER) != -1) {
              layerName =
                  layerSelected
                      .getAlias()
                      .substring(0, layerSelected.getAlias().indexOf(LAYER_TIME_DELIMITER));
            } else {
              layerName = layerSelected.getLabel();
            }
            if (fixedDimensionRadio.getValue()) {
              String timeFilter =
                  (String) startDimensionComboBox.getValue().get(DimensionData.DIMENSION_KEY);
              if (endDimensionComboBox.getValue() != null) {
                timeFilter +=
                    "/" + (String) endDimensionComboBox.getValue().get(DimensionData.DIMENSION_KEY);
              }
              layerSelected.setTimeFilter(timeFilter);
              layerSelected.setVariableTimeFilter(null);
              layerSelected.setAlias(
                  layerName + LAYER_TIME_DELIMITER + layerSelected.getTimeFilter() + "]");
              WidgetPropertiesHandlerManager.fireEvent(labelEvent);
            } else {
              if ((rangeCheckBox.getValue() && !checkEndFieldValue()) || !checkStartFieldValue()) {
                GeoPlatformMessage.errorMessage(
                    LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_timeFilterErrorTitleText(),
                    LayerModuleConstants.INSTANCE.LayerTimeFilterWidget_timeFilterErrorBodyText());
                return;
              } else {
                int fromFilter = slider.getValue();
                String timeFilter = "" + (startStore.getModels().size() - fromFilter - 1);
                String variableTimeFilter =
                    (String)
                        startStore.getModels().get(fromFilter).get(DimensionData.DIMENSION_KEY);
                if (rangeCheckBox.getValue() && playButton.isPressed()) {
                  fromFilter =
                      startStore.getModels().size()
                          - startFilterNumberField.getValue().intValue()
                          - 1;
                  timeFilter = "" + startFilterNumberField.getValue().intValue();
                  variableTimeFilter =
                      (String)
                          startStore.getModels().get(fromFilter).get(DimensionData.DIMENSION_KEY);
                  //
                  int toFilter = slider.getValue();
                  timeFilter += "/" + (startStore.getModels().size() - slider.getValue() - 1);
                  variableTimeFilter +=
                      "/"
                          + (String)
                              startStore.getModels().get(toFilter).get(DimensionData.DIMENSION_KEY);
                } // This is usefull when press Apply button to show all the elements in range
                else if (rangeCheckBox.getValue() && endFilterNumberField.getValue() != null) {
                  fromFilter =
                      startStore.getModels().size()
                          - startFilterNumberField.getValue().intValue()
                          - 1;
                  timeFilter = "" + startFilterNumberField.getValue().intValue();
                  variableTimeFilter =
                      (String)
                          startStore.getModels().get(fromFilter).get(DimensionData.DIMENSION_KEY);
                  //
                  int toFilter =
                      startStore.getModels().size()
                          - endFilterNumberField.getValue().intValue()
                          - 1;
                  timeFilter += "/" + endFilterNumberField.getValue().intValue();
                  variableTimeFilter +=
                      "/"
                          + (String)
                              startStore.getModels().get(toFilter).get(DimensionData.DIMENSION_KEY);
                }
                layerSelected.setTimeFilter(timeFilter);
                layerSelected.setVariableTimeFilter(variableTimeFilter);
                layerSelected.setAlias(
                    layerName + LAYER_TIME_DELIMITER + layerSelected.getVariableTimeFilter() + "]");
                WidgetPropertiesHandlerManager.fireEvent(labelEvent);
                slider.setMessage(variableTimeFilter);
                GeoPlatformMessage.infoMessage(
                    LayerModuleConstants.INSTANCE
                        .LayerTimeFilterWidget_timeFilterMessageTitleText(),
                    LayerModuleMessages.INSTANCE.LayerTimeFilterWidget_layerStatusShowedMessage(
                        timeFilter));
              }
            }
            mementoSave.putOriginalPropertiesInCache(memento);
            timeFilterLayerMapEvent.setLayerBean(layerSelected);
            GPHandlerManager.fireEvent(timeFilterLayerMapEvent);
            treePanel.refresh(layerSelected);
          }
        };

    apply.addSelectionListener(applyFilterSelectionListener);

    super.addButton(apply);
    Button close =
        new Button(
            ButtonsConstants.INSTANCE.closeText(),
            new SelectionListener<ButtonEvent>() {
              @Override
              public void componentSelected(ButtonEvent ce) {
                startFilterNumberField.clear();
                startTimeLabel.setHtml("");
                endTimeLabel.setHtml("");
                endFilterNumberField.clear();
                hide();
              }
            });

    super.addButton(close);
  }