Beispiel #1
0
  public TabItem getTab(Portlet portlet) {
    //	Search using the internal list, in case it's already been removed from the tabPanel by GXT
    for (List<TabItem> tabs : portletTabs) {
      for (TabItem tab : tabs) {
        for (Component component : tab.getItems()) {
          if (component.hashCode() == portlet.hashCode())
            if (component.getClass().getName().equals(portlet.getClass().getName())) {
              return tab;
            }
        }
      }
    }

    return null;
  }
Beispiel #2
0
 public String getTabLabel(Portlet portlet, int index, int column) {
   String label = null;
   if (portlet instanceof AppPortlet) label = ((AppPortlet) portlet).getShortPortletName();
   else label = portlet.getHeading();
   if (label != null && label.length() > 0) return label;
   return index + "-" + column + " : ";
 }
Beispiel #3
0
  @Override
  public void close(Portlet portlet) {
    TabItem tab = getTab(portlet);
    if (tab != null) {
      if (tab.getTabPanel() != null) tab.close();

      //	Take the tab out of the list of tabs
      for (List<TabItem> column : portletTabs) {
        for (TabItem targetTab : column) {
          if (tab.hashCode() == targetTab.hashCode()) {
            column.remove(targetTab);
            break;
          }
        }
      }
    }

    //	Make sure the portlet is out of the tab itself
    if (portlet.getParent() != null) portlet.removeFromParent();

    //	Update the portlet as "closed" in the user cache
    if (portlet instanceof AppPortlet) ((AppPortlet) portlet).updateUserPortlet();
  }
  @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);
  }