Search in sources :

Example 41 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project gwt-cs by iSergio.

the class Labels method buildPanel.

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();
    addLabel();
    ListBox labelsLBox = new ListBox();
    labelsLBox.addItem("Add label", "0");
    labelsLBox.addItem("Set font", "1");
    labelsLBox.addItem("Set properties", "2");
    labelsLBox.addItem("Offset label by distance", "3");
    labelsLBox.addItem("Fade label by distance", "4");
    labelsLBox.addItem("Scale label by distance", "5");
    labelsLBox.addItem("Set label with right-to-left language", "6");
    labelsLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            ListBox source = (ListBox) event.getSource();
            reset();
            switch(source.getSelectedValue()) {
                case "0":
                    addLabel();
                    break;
                case "1":
                    setFont();
                    break;
                case "2":
                    setProperties();
                    break;
                case "3":
                    offsetByDistance();
                    break;
                case "4":
                    fadeByDistance();
                    break;
                case "5":
                    scaleByDistance();
                    break;
                case "6":
                    setRightToLeft();
                    break;
                default:
                    break;
            }
        }
    });
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(labelsLBox, 20, 20);
    contentPanel.add(new HTML("<p>Create Labels</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
}
Also used : ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) AbsolutePanel(com.google.gwt.user.client.ui.AbsolutePanel) HTML(com.google.gwt.user.client.ui.HTML) ListBox(com.google.gwt.user.client.ui.ListBox)

Example 42 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project gwt-cs by iSergio.

the class Models3DColoring method buildPanel.

@Override
public void buildPanel() {
    ViewerOptions csViewerOptions = new ViewerOptions();
    csViewerOptions.infoBox = false;
    csViewerOptions.selectionIndicator = false;
    csViewerOptions.shadows = false;
    csVPanel = new ViewerPanel(csViewerOptions);
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb");
    modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(128);
    modelGraphicsOptions.maximumScale = new ConstantProperty<>(20000);
    modelGraphicsOptions.color = new ConstantProperty<>(getColor("red", alpha));
    modelGraphicsOptions.colorBlendMode = new ConstantProperty<>(ColorBlendMode.HIGHLIGHT());
    modelGraphicsOptions.colorBlendAmount = new ConstantProperty<>(colorBlendAmount);
    modelGraphicsOptions.silhouetteColor = new ConstantProperty<>(getColor("red", alpha));
    modelGraphicsOptions.silhouetteSize = new ConstantProperty<>(silhouetteSize);
    ModelGraphics modelGraphics = new ModelGraphics(modelGraphicsOptions);
    Cartesian3 position = Cartesian3.fromDegrees(-123.0744619, 44.0503706, 5000.0);
    double heading = Math.toRadians(135);
    double pitch = 0;
    double roll = 0;
    org.cesiumjs.cs.core.HeadingPitchRoll hpr = new org.cesiumjs.cs.core.HeadingPitchRoll(heading, pitch, roll);
    Quaternion orientation = Transforms.headingPitchRollQuaternion(position, hpr);
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.name = GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb";
    entityOptions.position = new ConstantPositionProperty(position);
    entityOptions.orientation = new ConstantProperty<>(orientation);
    entityOptions.model = modelGraphics;
    csVPanel.getViewer().trackedEntity = csVPanel.getViewer().entities().add(entityOptions);
    ListBox modeLBox = new ListBox();
    modeLBox.addItem("Hightlight", "0");
    modeLBox.addItem("Replace", "1");
    modeLBox.addItem("Mix", "2");
    modeLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            ListBox source = (ListBox) event.getSource();
            mixSlider.setVisible(false);
            mixTBox.setVisible(false);
            if (source.getSelectedValue().equalsIgnoreCase("0")) {
                colorBlendMode = ColorBlendMode.HIGHLIGHT();
            } else if (source.getSelectedValue().equalsIgnoreCase("1")) {
                colorBlendMode = ColorBlendMode.REPLACE();
            } else if (source.getSelectedValue().equalsIgnoreCase("2")) {
                colorBlendMode = ColorBlendMode.MIX();
                mixSlider.setVisible(true);
                mixTBox.setVisible(true);
            }
            csVPanel.getViewer().trackedEntity.model.colorBlendMode = new ConstantProperty<>(colorBlendMode);
        }
    });
    ListBox colorLBox = new ListBox();
    colorLBox.addItem("White", "White");
    colorLBox.addItem("Red", "Red");
    colorLBox.addItem("Green", "Green");
    colorLBox.addItem("Blue", "Blue");
    colorLBox.addItem("Yellow", "Yellow");
    colorLBox.addItem("Gray", "Gray");
    colorLBox.setSelectedIndex(1);
    colorLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            ListBox source = (ListBox) event.getSource();
            colorStr = source.getSelectedValue();
            csVPanel.getViewer().trackedEntity.model.color = new ConstantProperty<>(getColor(source.getSelectedValue(), alpha));
        }
    });
    alphaSlider = new Slider("Alpha", 0, 100, 100);
    alphaSlider.setWidth("100px");
    alphaSlider.setStep(1);
    alphaSlider.addListener(new MSliderListener());
    alphaTBox = new TextBox();
    alphaTBox.setSize("30px", "12px");
    alphaTBox.setValue("" + 1);
    alphaTBox.addChangeHandler(new MChangeHandler());
    mixSlider = new Slider("Mix", 0, 100, 50);
    mixSlider.setStep(1);
    mixSlider.setVisible(false);
    mixSlider.addListener(new MSliderListener());
    mixTBox = new TextBox();
    mixTBox.setSize("30px", "12px");
    mixTBox.setValue("0.5");
    mixTBox.setVisible(false);
    mixTBox.addChangeHandler(new MChangeHandler());
    ListBox silhouetteColorLBox = new ListBox();
    silhouetteColorLBox.addItem("Red", "Red");
    silhouetteColorLBox.addItem("Green", "Green");
    silhouetteColorLBox.addItem("Blue", "Blue");
    silhouetteColorLBox.addItem("Yellow", "Yellow");
    silhouetteColorLBox.addItem("Gray", "Gray");
    silhouetteColorLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            ListBox source = (ListBox) event.getSource();
            silhouetteColorStr = source.getSelectedValue();
            silhouetteColor = getColor(source.getSelectedValue(), alpha);
            csVPanel.getViewer().trackedEntity.model.silhouetteColor = new ConstantProperty<>(getColor(silhouetteColorStr, silhouetteAlpha));
        }
    });
    silhouetteAlphaSlider = new Slider("SilhouetteAlpha", 0, 100, 100);
    silhouetteAlphaSlider.setStep(1);
    silhouetteAlphaSlider.addListener(new MSliderListener());
    silhouetteAlphaTBox = new TextBox();
    silhouetteAlphaTBox.setSize("30px", "12px");
    silhouetteAlphaTBox.setValue("" + 1);
    silhouetteAlphaTBox.addChangeHandler(new MChangeHandler());
    silhouetteSizeSlider = new Slider("SizeAlpha", 0, 1000, 20);
    silhouetteSizeSlider.setStep(1);
    silhouetteSizeSlider.addListener(new MSliderListener());
    silhouetteSizeTBox = new TextBox();
    silhouetteSizeTBox.setSize("30px", "12px");
    silhouetteSizeTBox.setValue("" + 2);
    silhouetteSizeTBox.addChangeHandler(new MChangeHandler());
    final ListBox modelsLBox = new ListBox();
    modelsLBox.addItem("Aircraft", "0");
    modelsLBox.addItem("Ground vehicle", "1");
    modelsLBox.addItem("Hot Air Balloon", "2");
    modelsLBox.addItem("Milk truck", "3");
    modelsLBox.addItem("Skinned character", "4");
    modelsLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            csVPanel.getViewer().entities().removeAll();
            switch(modelsLBox.getSelectedValue()) {
                case "0":
                    createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb", 5000.0);
                    break;
                case "1":
                    createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumGround/Cesium_Ground.glb", 0);
                    break;
                case "2":
                    createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumBalloon/CesiumBalloon.glb", 1000.0);
                    break;
                case "3":
                    createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumMilkTruck/CesiumMilkTruck-kmc.glb", 0);
                    break;
                case "4":
                    createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumMan/Cesium_Man.glb", 0);
                    break;
                default:
                    break;
            }
        }
    });
    CheckBox shadowsCBox = new CheckBox("Shadows");
    shadowsCBox.getElement().getStyle().setColor("white");
    shadowsCBox.setWidth("100px");
    shadowsCBox.setValue(true);
    shadowsCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            csVPanel.getViewer().shadows = event.getValue();
        }
    });
    FlexTable flexTable = new FlexTable();
    flexTable.setHTML(1, 0, "<font color=\"white\">Model Color</font>");
    flexTable.setHTML(2, 0, "<font color=\"white\">Mode</font>");
    flexTable.setWidget(2, 1, modeLBox);
    flexTable.setHTML(3, 0, "<font color=\"white\">Color</font>");
    flexTable.setWidget(3, 1, colorLBox);
    flexTable.setHTML(4, 0, "<font color=\"white\">Alpha</font>");
    flexTable.setWidget(4, 1, alphaSlider);
    flexTable.setWidget(4, 2, alphaTBox);
    flexTable.setHTML(5, 0, "<font color=\"white\">Mix</font>");
    flexTable.setWidget(5, 1, mixSlider);
    flexTable.setWidget(5, 2, mixTBox);
    flexTable.setHTML(6, 0, "<font color=\"white\">Model Silhouette</font>");
    flexTable.setHTML(7, 0, "<font color=\"white\">Color</font>");
    flexTable.setWidget(7, 1, silhouetteColorLBox);
    flexTable.setHTML(8, 0, "<font color=\"white\">Alpha</font>");
    flexTable.setWidget(8, 1, silhouetteAlphaSlider);
    flexTable.setWidget(8, 2, silhouetteAlphaTBox);
    flexTable.setHTML(9, 0, "<font color=\"white\">Size</font>");
    flexTable.setWidget(9, 1, silhouetteSizeSlider);
    flexTable.setWidget(9, 2, silhouetteSizeTBox);
    flexTable.setWidget(10, 0, modelsLBox);
    flexTable.setWidget(10, 1, shadowsCBox);
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(flexTable, 20, 20);
    contentPanel.add(new HTML("<p>Create 3D coloring models.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
}
Also used : Slider(org.cleanlogic.showcase.client.examples.slider.Slider) ViewerOptions(org.cesiumjs.cs.widgets.options.ViewerOptions) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) ConstantProperty(org.cesiumjs.cs.datasources.properties.ConstantProperty) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) org.cesiumjs.cs.core(org.cesiumjs.cs.core) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent)

Example 43 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project gwt-cs by iSergio.

the class ImageryLayersManipulation method buildPanel.

@Override
public void buildPanel() {
    ViewerOptions viewerOptions = new ViewerOptions();
    viewerOptions.baseLayerPicker = false;
    ViewerPanel csVPanel = new ViewerPanel(viewerOptions);
    imageryLayers = csVPanel.getViewer().imageryLayers();
    setupLayers();
    updateLayerList();
    _callback.onSuccess(null);
    HorizontalPanel baseLayersHPanel = new HorizontalPanel();
    baseLayersHPanel.setSpacing(5);
    baseLayersHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    baseLayersHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    final ListBox baseLayersLBox = new ListBox();
    baseLayersHPanel.add(baseLayersLBox);
    Slider baseLayersSlider = new Slider("baseLayersAlpha", 0, 100, 100);
    baseLayersSlider.setWidth("200px");
    baseLayersSlider.addListener(new MSliderListener());
    baseLayersHPanel.add(baseLayersSlider);
    baseLayersLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            ListBox source = (ListBox) changeEvent.getSource();
            ImageryLayer baseLayer = baseLayers.get(source.getSelectedValue());
            int activeLayerIndex = 0;
            int numLayers = layers.size();
            for (int i = 0; i < numLayers; ++i) {
                if (baseLayers.containsValue(layers.get(i))) {
                    activeLayerIndex = i;
                }
            }
            ImageryLayer activeLayer = layers.get(activeLayerIndex);
            float alpha = activeLayer.alpha;
            boolean show = activeLayer.show;
            imageryLayers.remove(activeLayer, false);
            imageryLayers.add(baseLayer, numLayers - activeLayerIndex - 1);
            baseLayer.show = show;
            baseLayer.alpha = alpha;
            updateLayerList();
            selectedLayer = baseLayer;
        }
    });
    Callback<Void, Void> cesiumCreated = new Callback<Void, Void>() {

        @Override
        public void onFailure(Void aVoid) {
        // 
        }

        @Override
        public void onSuccess(Void aVoid) {
            for (Map.Entry<String, ImageryLayer> entry : baseLayers.entrySet()) {
                baseLayersLBox.addItem(entry.getKey(), entry.getKey());
            }
        }
    };
    addCallback(cesiumCreated);
    contentPanel.add(new HTML("<p>Layer imagery from multiple sources, including WMS servers, Bing Maps, ArcGIS Online, OpenStreetMaps, and more, and adjust the alpha of each independently.</p>"));
    contentPanel.add(baseLayersHPanel);
    contentPanel.add(csVPanel);
    initWidget(contentPanel);
}
Also used : ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) Slider(org.cleanlogic.showcase.client.examples.slider.Slider) ViewerOptions(org.cesiumjs.cs.widgets.options.ViewerOptions) Callback(com.google.gwt.core.client.Callback) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ImageryLayer(org.cesiumjs.cs.scene.ImageryLayer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 44 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project perun by CESNET.

the class ResourceSettingsTabItem method draw.

public Widget draw() {
    if (service != null) {
        titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": " + service.getName() + " configuration");
    } else {
        titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": service configuration");
    }
    vp.setSize("100%", "100%");
    vp.clear();
    // menu
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    // callback
    final GetRequiredAttributesV2 resAttrs = new GetRequiredAttributesV2();
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("resource", resourceId);
    resAttrs.setIds(ids);
    final GetAttributesV2 attrs = new GetAttributesV2();
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        resAttrs.setCheckable(false);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        attrs.setCheckable(false);
    // puts first table
    final CellTable<Attribute> table = resAttrs.getEmptyTable();
    final CellTable<Attribute> table2 = attrs.getEmptyTable();
    // if for one service only modify empty table message
    if (service != null) {
        AjaxLoaderImage empty = (AjaxLoaderImage) table.getEmptyTableWidget();
        empty.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
        AjaxLoaderImage empty2 = (AjaxLoaderImage) table2.getEmptyTableWidget();
        empty2.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
    }
    final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
    sp.setWidget(table);
    sp2.setWidget(table2);
    // switch between assigned and all
    final CheckBox chb = new CheckBox();
    chb.setText(WidgetTranslation.INSTANCE.offerAvailableServicesOnly());
    chb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
    // default true
    chb.setValue(lastOfferAvailableOnly);
    // event which fills the listbox and call getRequiredAttributes
    JsonCallbackEvents event = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // clear services list
            servList.clear();
            // process services
            ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
            srv = new TableSorter<Service>().sortByName(srv);
            for (int i = 0; i < srv.size(); i++) {
                // fill listbox
                servList.addItem(srv.get(i));
            }
            if (servList.isEmpty()) {
                servList.addNotSelectedOption();
                lastSelectedService = 0;
                indexInList = 0;
                attrs.retrieveData();
                setTable(false);
                return;
            }
            if (lastSelectedService == 0 && chb.getValue() == true) {
                servList.addNotSelectedOption();
                servList.addAllOption();
                if (indexInList == 0) {
                    servList.setSelectedIndex(0);
                    attrs.retrieveData();
                    setTable(false);
                    return;
                } else if (indexInList == 1) {
                    servList.setSelectedIndex(1);
                }
            } else if (lastSelectedService == 0 && chb.getValue() == false) {
                servList.addNotSelectedOption();
                servList.setSelectedIndex(0);
                attrs.retrieveData();
                setTable(false);
                return;
            } else if (lastSelectedService != 0) {
                if (chb.getValue() == true) {
                    servList.addNotSelectedOption();
                    servList.addAllOption();
                } else {
                    servList.addNotSelectedOption();
                }
                // remove last service, we can't be sure it was loaded again
                ids.remove("service");
                // either all or specific service
                servList.setSelectedIndex(1);
                for (Service s : servList.getAllObjects()) {
                    if (s.getId() == lastSelectedService) {
                        // service selected last time was found in a list
                        servList.setSelected(s, true);
                        ids.put("service", s.getId());
                        break;
                    }
                }
            }
            // make call
            resAttrs.clearTable();
            resAttrs.setIds(ids);
            resAttrs.retrieveData();
            setTable(true);
        }

        @Override
        public void onError(PerunError error) {
            servList.clear();
            servList.addItem("Error while loading");
            if (required) {
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
            } else {
                ((AjaxLoaderImage) table2.getEmptyTableWidget()).loadingError(error);
            }
        }

        @Override
        public void onLoadingStart() {
            servList.removeAllOption();
            servList.removeNotSelectedOption();
            servList.clear();
            servList.addItem("Loading...");
        }
    };
    final GetAssignedServices services = new GetAssignedServices(resourceId, event);
    final GetServices allServices = new GetServices(event);
    // offer services selection
    if (serviceId == 0) {
        // services listbox
        servList.setTitle("Services");
        attrs.setIds(ids);
        // on change of service update table
        servList.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                // if service selected
                if (servList.getSelectedIndex() == 0) {
                    attrs.retrieveData();
                    setTable(false);
                    lastSelectedService = 0;
                    indexInList = 0;
                    return;
                } else if (chb.getValue() == true && servList.getSelectedIndex() == 1) {
                    ids.remove("service");
                    lastSelectedService = 0;
                    indexInList = 1;
                } else if ((chb.getValue() == true && servList.getSelectedIndex() > 1) || (chb.getValue() == false && servList.getSelectedIndex() > 0)) {
                    ids.put("service", servList.getSelectedObject().getId());
                    lastSelectedService = servList.getSelectedObject().getId();
                }
                lastOfferAvailableOnly = chb.getValue();
                resAttrs.clearTable();
                resAttrs.setIds(ids);
                resAttrs.retrieveData();
                setTable(true);
            }
        });
        if (chb.getValue() == false) {
            allServices.retrieveData();
        } else {
            services.retrieveData();
        }
    } else {
        // retrieve data for selected service only
        lastSelectedService = serviceId;
        lastOfferAvailableOnly = chb.getValue();
        ids.put("service", serviceId);
        resAttrs.setIds(ids);
        resAttrs.retrieveData();
        setTable(true);
    }
    // refresh table event - refresh only on finished / on error keep selected
    final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(resAttrs);
    final JsonCallbackEvents refreshTable2 = JsonCallbackEvents.refreshTableEvents(attrs);
    // add save changes to menu
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    menu.addWidget(saveChangesButton);
    // set button disable event
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable);
    final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable2);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        saveChangesButton.setEnabled(false);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getTableSelectedList();
            } else {
                list = attrs.getTableSelectedList();
            }
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
                request.setAttributes(ids, list);
            }
        }
    });
    // add set new to menu
    CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getList();
            } else {
                list = attrs.getList();
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("resource", resourceId);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, list), true);
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        setNewAttributeButton.setEnabled(false);
    if (service == null) {
        menu.addWidget(setNewAttributeButton);
    }
    // fill button
    final CustomButton fillDefaultButton = TabMenu.getPredefinedButton(ButtonType.FILL, ButtonTranslation.INSTANCE.fillResourceAttributes());
    menu.addWidget(fillDefaultButton);
    // remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    // remove button event
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
    final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable2);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        removeButton.setEnabled(false);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getTableSelectedList();
            } else {
                list = attrs.getTableSelectedList();
            }
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(removeButton);
    // add service selection to menu and switcher
    if (serviceId == 0) {
        menu.addWidget(new HTML("<strong>Selected&nbsp;service: </strong>"));
        menu.addWidget(servList);
        menu.addWidget(chb);
    }
    // checkbox switcher on click
    chb.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (chb.getValue() == false) {
                lastOfferAvailableOnly = false;
                allServices.retrieveData();
            } else {
                lastOfferAvailableOnly = true;
                services.retrieveData();
            }
        }
    });
    fillDefaultButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // automatically try to fill all attributes
            ArrayList<Attribute> prepareList = new ArrayList<Attribute>();
            if (required) {
                prepareList = resAttrs.getTableSelectedList();
            } else {
                prepareList = attrs.getTableSelectedList();
            }
            final ArrayList<Attribute> list = prepareList;
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                FillAttributes request = new FillAttributes(JsonCallbackEvents.disableButtonEvents(fillDefaultButton, new JsonCallbackEvents() {

                    boolean wasRequiredTable = required;

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // remove attribute from original table and put new ones
                        ArrayList<Attribute> newList = JsonUtils.jsoAsList(jso);
                        for (Attribute a : newList) {
                            for (Attribute oldA : list) {
                                // deselect old
                                if (a.getId() == oldA.getId()) {
                                    if (wasRequiredTable) {
                                        resAttrs.getSelectionModel().setSelected(oldA, false);
                                        resAttrs.removeFromTable(oldA);
                                    } else {
                                        attrs.getSelectionModel().setSelected(oldA, false);
                                        attrs.removeFromTable(oldA);
                                    }
                                }
                            }
                            if (wasRequiredTable) {
                                // add new
                                resAttrs.addToTable(a);
                                // select returned
                                resAttrs.getSelectionModel().setSelected(a, true);
                            } else {
                                // add new
                                attrs.addToTable(a);
                                // select returned
                                attrs.getSelectionModel().setSelected(a, true);
                            }
                        }
                        if (wasRequiredTable) {
                            resAttrs.sortTable();
                        } else {
                            attrs.sortTable();
                        }
                    }
                }));
                request.fillAttributes(ids, list);
            }
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        fillDefaultButton.setEnabled(false);
    /* TODO - not implemented

			 Button checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon());
			 menu.addWidget(checkValuesButton);
			 checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");


			 checkValuesButton.addClickHandler(new ClickHandler(){
			 public void onClick(ClickEvent event) {
			 Window.alert("not yet implemented");
			 }
			 });

*/
    table.addStyleName("perun-table");
    table.setWidth("100%");
    table2.addStyleName("perun-table");
    table2.setWidth("100%");
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    sp2.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp2, 350, this);
    // default is required attributes
    setTable(true);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) Service(cz.metacentrum.perun.webgui.model.Service) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) HashMap(java.util.HashMap) Map(java.util.Map)

Example 45 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project perun by CESNET.

the class CreateMailTabItem method basicInformationTab.

/**
 * Returns flex table with basic information
 *
 * @return
 */
private Widget basicInformationTab() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("500px", "350px");
    vp.setSpacing(10);
    // layout
    FlexTable ft = new FlexTable();
    ft.setStyleName("inputFormFlexTable");
    FlexCellFormatter ftf = ft.getFlexCellFormatter();
    vp.add(ft);
    vp.add(new HTML("&nbsp;"));
    // inputs - filling
    mailTypeListbox.clear();
    for (ApplicationMail.MailType type : ApplicationMail.MailType.values()) {
        if (group == null && type.equals(ApplicationMail.MailType.APPROVABLE_GROUP_APP_USER)) {
            // This notification is relevant only for the groups, so skip it from the offering
            continue;
        }
        mailTypeListbox.addItem(ApplicationMail.getTranslatedMailType(type.toString()), type.toString());
    }
    int initialIndex = 0;
    applicationTypeListbox.clear();
    for (Application.ApplicationType type : Application.ApplicationType.values()) {
        applicationTypeListbox.addItem(Application.getTranslatedType(type.toString()), type.toString());
        if (type.equals(Application.ApplicationType.INITIAL)) {
            initialIndex = applicationTypeListbox.getItemCount() - 1;
        }
    }
    final int initIndex = initialIndex;
    mailTypeListbox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (mailTypeListbox.getValue(mailTypeListbox.getSelectedIndex()).equals("USER_INVITE")) {
                applicationTypeListbox.setEnabled(false);
                applicationTypeListbox.setSelectedIndex(initIndex);
            } else {
                applicationTypeListbox.setEnabled(true);
            }
        }
    });
    // basic info
    int row = 0;
    ft.setHTML(row, 0, "E-mail type:");
    ft.setWidget(row, 1, mailTypeListbox);
    ftf.setStyleName(row, 0, "itemName");
    row++;
    ft.setHTML(row, 1, "Selected type of notification (action which trigger sending and who is notified).");
    ftf.setStyleName(row, 1, "inputFormInlineComment");
    row++;
    ft.setHTML(row, 0, "Application type: ");
    ft.setWidget(row, 1, applicationTypeListbox);
    ftf.setStyleName(row, 0, "itemName");
    ftf.setWidth(row, 0, "120px");
    row++;
    ft.setHTML(row, 1, "Select which application type will trigger sending.");
    ftf.setStyleName(row, 1, "inputFormInlineComment");
    row++;
    sendingEnabledCheckBox.setValue(true);
    ft.setHTML(row, 0, "Sending enabled:");
    ft.setWidget(row, 1, sendingEnabledCheckBox);
    ftf.setStyleName(row, 0, "itemName");
    row++;
    ft.setHTML(row, 1, "If checked, notification will be sent. Un-check it to temporary disable sending.");
    ftf.setStyleName(row, 1, "inputFormInlineComment");
    return vp;
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) AddApplicationMail(cz.metacentrum.perun.webgui.json.registrarManager.AddApplicationMail)

Aggregations

ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)123 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)123 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)48 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)48 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)34 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)31 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)31 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)31 ListBox (org.gwtbootstrap3.client.ui.ListBox)31 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)29 ArrayList (java.util.ArrayList)26 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)21 PerunError (cz.metacentrum.perun.webgui.model.PerunError)17 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)16 HTML (com.google.gwt.user.client.ui.HTML)14 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)14 HashMap (java.util.HashMap)13 ListBox (com.google.gwt.user.client.ui.ListBox)12 FormStylePopup (org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup)12 Map (java.util.Map)11