Search in sources :

Example 96 with ClickEvent

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

the class AddPublicationsTabItem method loadCreateScreen.

/**
	 * Draw tab content for CREATE state.
	 */
private void loadCreateScreen() {
    // MAIN PANEL
    final VerticalPanel mainPanel = new VerticalPanel();
    mainPanel.setSize("100%", "100%");
    // MAIN MENU
    FlexTable header = new FlexTable();
    header.setStyleName("wizardHeader");
    mainPanel.add(header);
    // splitter
    HTML splitter = new HTML("<hr size=\"1\" width=\"100%\" />");
    mainPanel.add(splitter);
    int column = 0;
    header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.bookEditIcon()));
    column++;
    Label headerTitle = new Label();
    headerTitle.getElement().setAttribute("style", "font-size: 1.35em;");
    header.setWidget(0, column, headerTitle);
    column++;
    headerTitle.setText("Create publication");
    // Widgets
    final CustomButton backButton = TabMenu.getPredefinedButton(ButtonType.BACK, "Go back to start page - !! ALL UNSAVED CHANGES WILL BE LOST !!", new ClickHandler() {

        public void onClick(ClickEvent event) {
            importedPublications.clear();
            hadError = false;
            // go back to original state
            state = State.START;
            session.getTabManager().reloadTab(tab);
        }
    });
    header.setWidget(0, column, backButton);
    column++;
    final ExtendedTextBox title = new ExtendedTextBox();
    title.getTextBox().setMaxLength(1024);
    final TextBox isbn = new TextBox();
    isbn.setMaxLength(32);
    final TextBox doi = new TextBox();
    doi.setMaxLength(256);
    final ExtendedTextArea cite = new ExtendedTextArea();
    cite.getTextArea().setSize("380px", "75px");
    cite.getTextArea().getElement().setAttribute("maxlength", "4000");
    final ListBox year = new ListBox();
    final CheckBox addAsAuthor = new CheckBox("Add me as author");
    addAsAuthor.setValue(true);
    addAsAuthor.setTitle("When checked, you will be automatically added as author of created publication");
    final ExtendedTextBox.TextBoxValidator titleValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (title.getTextBox().getText().trim().isEmpty()) {
                title.setError("Publication title can't be empty.");
                return false;
            } else {
                title.setOk();
                return true;
            }
        }
    };
    title.setValidator(titleValidator);
    final ExtendedTextArea.TextAreaValidator citeValidator = new ExtendedTextArea.TextAreaValidator() {

        @Override
        public boolean validateTextArea() {
            if (cite.getTextArea().getText().trim().isEmpty()) {
                cite.setError("Publication citation can't be empty.");
                return false;
            } else {
                cite.setOk();
                return true;
            }
        }
    };
    cite.setValidator(citeValidator);
    final CustomButton finishButton = TabMenu.getPredefinedButton(ButtonType.CREATE, "Create publication in Perun");
    // enable only after search for similar publications
    finishButton.setEnabled(false);
    finishButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // check
            if (titleValidator.validateTextBox() && citeValidator.validateTextArea()) {
                // create
                CreatePublication request = new CreatePublication(JsonCallbackEvents.disableButtonEvents(finishButton, new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        Publication pub = jso.cast();
                        importedPublications.add(pub);
                        counter--;
                        if (addAsAuthor.getValue()) {
                            CreateAuthorship request = new CreateAuthorship();
                            request.createAuthorship(pub.getId(), userId);
                            previousState = State.CREATE;
                            state = State.REVIEW;
                            session.getTabManager().reloadTab(tab);
                        }
                    }

                    @Override
                    public void onError(PerunError error) {
                        hadError = true;
                        counter--;
                    }
                }));
                request.createPublication(title.getTextBox().getText().trim(), categoryId, Integer.parseInt(year.getValue(year.getSelectedIndex())), isbn.getText().trim(), doi.getText().trim(), cite.getTextArea().getText().trim());
                counter++;
            }
        }
    });
    // checking
    final Map<String, Object> ids = new HashMap<String, Object>();
    ids.put("userId", session.getUser().getId());
    ids.put("authors", 1);
    final FindSimilarPublications filterCall = new FindSimilarPublications(ids);
    filterCall.setCheckable(false);
    CellTable<Publication> table = filterCall.getEmptyTable(new FieldUpdater<Publication, String>() {

        public void update(int index, Publication object, String value) {
            session.getTabManager().addTab(new PublicationDetailTabItem(object, true));
        }
    });
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel();
    sp.add(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    table.setWidth("100%");
    table.removeColumn(0);
    table.removeColumn(5);
    table.removeColumn(4);
    table.removeColumn(3);
    // check layout
    final FlexTable checkLayout = new FlexTable();
    checkLayout.setSize("100%", "100%");
    // form layout
    final FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    layout.setWidth("600px");
    final CustomButton checkButton = new CustomButton("Check", "Check if same publication exist in Perun", SmallIcons.INSTANCE.booksIcon());
    filterCall.setEvents(JsonCallbackEvents.disableButtonEvents(checkButton, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            finishButton.setEnabled(true);
            ArrayList<Publication> pubs = JsonUtils.jsoAsList(jso);
            if (pubs == null || pubs.isEmpty()) {
                UiElements.generateInfo("No similar publications", "No similar publications were found. You can continue reporting new publication.");
            } else {
                backButton.setEnabled(false);
                checkButton.setEnabled(false);
                mainPanel.remove(layout);
                mainPanel.add(checkLayout);
            }
        }

        @Override
        public void onError(PerunError error) {
            finishButton.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
        }
    }));
    checkButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (titleValidator.validateTextBox() && citeValidator.validateTextArea()) {
                ids.clear();
                ids.put("authors", 1);
                if (!title.getTextBox().getText().trim().equals("")) {
                    ids.put("title", title.getTextBox().getText().trim());
                }
                if (!isbn.getText().trim().equals("")) {
                    ids.put("isbn", isbn.getText().trim());
                }
                if (!doi.getText().equals("")) {
                    ids.put("doi", doi.getText());
                }
                filterCall.clearTable();
                filterCall.retrieveData();
            }
        }
    });
    final ListBoxWithObjects<Category> category = new ListBoxWithObjects<Category>();
    GetCategories request = new GetCategories(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            category.clear();
            categories = JsonUtils.<Category>jsoAsList(jso);
            if (categories != null && !categories.isEmpty()) {
                for (Category c : categories) {
                    category.addItem(c);
                    if (c.getName().equalsIgnoreCase("Ke kontrole")) {
                        // set default
                        defaultCategoryId = c.getId();
                        categoryId = c.getId();
                        category.setSelected(c, true);
                    }
                }
                checkButton.setEnabled(true);
            } else {
                category.addItem("No category available");
            }
        }

        @Override
        public void onError(PerunError error) {
            category.clear();
            category.addItem("Error while loading");
            // categories must be loaded !!
            checkButton.setEnabled(false);
            finishButton.setEnabled(false);
        }

        @Override
        public void onLoadingStart() {
            category.clear();
            category.addItem("Loading...");
        }
    });
    request.retrieveData();
    category.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            // put new publication in right category
            categoryId = category.getSelectedObject().getId();
        }
    });
    // set year
    for (int i = 2004; i <= JsonUtils.getCurrentYear(); i++) {
        year.addItem(String.valueOf(i));
    }
    year.setSelectedIndex(year.getItemCount() - 1);
    // form
    layout.setHTML(0, 0, "Title:");
    layout.setWidget(0, 1, title);
    layout.setHTML(1, 0, "Year:");
    layout.setWidget(1, 1, year);
    layout.setHTML(2, 0, "ISBN&nbsp;/&nbsp;ISSN:");
    layout.setWidget(2, 1, isbn);
    layout.setHTML(3, 0, "DOI:");
    layout.setWidget(3, 1, doi);
    layout.setHTML(4, 0, "Category:");
    layout.setWidget(4, 1, category);
    layout.setHTML(5, 0, "Full&nbsp;cite:");
    layout.setWidget(5, 1, cite);
    layout.setHTML(6, 1, "Citation as close as possible to ČSN ISO 690 or ČSN ISO 690-2.");
    layout.getFlexCellFormatter().setStyleName(6, 1, "inputFormInlineComment");
    for (int i = 0; i < layout.getRowCount(); i++) {
        layout.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    header.setWidget(0, column, checkButton);
    column++;
    header.setWidget(0, column, finishButton);
    column++;
    header.setWidget(0, column, addAsAuthor);
    column++;
    checkLayout.setWidget(0, 0, new CustomButton("Back to input form", "Back to Create publication form.", SmallIcons.INSTANCE.arrowLeftIcon(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            mainPanel.add(layout);
            mainPanel.remove(checkLayout);
            backButton.setEnabled(true);
            checkButton.setEnabled(true);
        }
    }));
    checkLayout.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
    checkLayout.getFlexCellFormatter().setWidth(0, 0, "180px");
    checkLayout.setHTML(0, 1, "<span class=\"input-status-error\">Please check if your publication is not already listed below.</span><ul><li>If NO, continue with Create button above.</br>&nbsp;</li><li>If YES, click on it to see details and add yourself between authors. If desired publication is locked for changes, notify administrators (meta@cesnet.cz) about your request.</li></ul>");
    checkLayout.setWidget(1, 0, sp);
    checkLayout.getFlexCellFormatter().setColSpan(1, 0, 2);
    mainPanel.add(layout);
    mainPanel.setCellHeight(layout, "100%");
    this.contentWidget.setWidget(mainPanel);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 97 with ClickEvent

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

the class AddPublicationsTabItem method loadStartScreen.

/**
	 * Draw tab content for START state - selection of create / import
	 */
private void loadStartScreen() {
    HorizontalPanel vp = new HorizontalPanel();
    vp.setHeight("500px");
    vp.setWidth("100%");
    // IMPORT LAYOUT
    DecoratorPanel dp = new DecoratorPanel();
    FlexTable importLayout = new FlexTable();
    importLayout.setCellSpacing(10);
    dp.add(importLayout);
    // button
    CustomButton importButton = new CustomButton("Import publication…", SmallIcons.INSTANCE.addIcon());
    // layout
    importLayout.setHTML(0, 0, "<span class=\"subsection-heading\">Import publication</span>");
    importLayout.setHTML(1, 0, "<span class=\"inputFormInlineComment\">Are you from MU, ZCU? You can import publications you have already reported in university publication systems.</span>");
    importLayout.setWidget(2, 0, importButton);
    // CREATE LAYOUT
    DecoratorPanel dp2 = new DecoratorPanel();
    FlexTable createLayout = new FlexTable();
    createLayout.setCellSpacing(10);
    dp2.add(createLayout);
    // button
    CustomButton createButton = new CustomButton("Create publication…", SmallIcons.INSTANCE.addIcon());
    // layout
    createLayout.setHTML(0, 0, "<span class=\"subsection-heading\">Create publication</span>");
    createLayout.setHTML(1, 0, "<span class=\"inputFormInlineComment\">Use when you want to add custom publication or report publication created by other user.</span>");
    createLayout.setWidget(2, 0, createButton);
    // ADD CONTENT
    vp.add(dp);
    dp.setWidth("400px");
    vp.add(dp2);
    dp2.setWidth("400px");
    vp.setCellWidth(dp, "50%");
    vp.setCellWidth(dp2, "50%");
    vp.setCellVerticalAlignment(dp, HasVerticalAlignment.ALIGN_MIDDLE);
    vp.setCellVerticalAlignment(dp2, HasVerticalAlignment.ALIGN_MIDDLE);
    vp.setCellHorizontalAlignment(dp, HasHorizontalAlignment.ALIGN_CENTER);
    vp.setCellHorizontalAlignment(dp2, HasHorizontalAlignment.ALIGN_CENTER);
    // CLICK HANDLERS
    importButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            state = State.IMPORT;
            session.getTabManager().reloadTab(tab);
        }
    });
    createButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            state = State.CREATE;
            session.getTabManager().reloadTab(tab);
        }
    });
    this.contentWidget.setWidget(vp);
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ClickEvent(com.google.gwt.event.dom.client.ClickEvent)

Example 98 with ClickEvent

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

the class AllCategoriesTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    final GetCategories callback = new GetCategories();
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(callback);
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Add new category", new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CreateCategoryTabItem());
        }
    }));
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, "Delete selected categories");
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<Category> delete = callback.getTableSelectedList();
            String text = "Following categories will be deleted";
            UiElements.showDeleteConfirm(delete, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                    for (int i = 0; i < delete.size(); i++) {
                        if (i == delete.size() - 1) {
                            DeleteCategory request = new DeleteCategory(JsonCallbackEvents.disableButtonEvents(removeButton, events));
                            request.deleteCategory(delete.get(i).getId());
                        } else {
                            DeleteCategory request = new DeleteCategory(JsonCallbackEvents.disableButtonEvents(removeButton));
                            request.deleteCategory(delete.get(i).getId());
                        }
                    }
                }
            });
        }
    });
    menu.addWidget(removeButton);
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in category ranks");
    saveButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<Category> list = callback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                for (int i = 0; i < list.size(); i++) {
                    if (i == list.size() - 1) {
                        UpdateCategory request = new UpdateCategory(JsonCallbackEvents.disableButtonEvents(saveButton, events));
                        request.updateCategory(list.get(i));
                    } else {
                        UpdateCategory request = new UpdateCategory(JsonCallbackEvents.disableButtonEvents(saveButton));
                        request.updateCategory(list.get(i));
                    }
                }
            }
        }
    });
    menu.addWidget(saveButton);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    CellTable<Category> table = callback.getTable();
    removeButton.setEnabled(false);
    saveButton.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, removeButton);
    JsonUtils.addTableManagedButton(callback, table, saveButton);
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel();
    sp.add(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    // resize perun table to correct size on screen
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) UpdateCategory(cz.metacentrum.perun.webgui.json.cabinetManager.UpdateCategory) DeleteCategory(cz.metacentrum.perun.webgui.json.cabinetManager.DeleteCategory) UpdateCategory(cz.metacentrum.perun.webgui.json.cabinetManager.UpdateCategory) Category(cz.metacentrum.perun.webgui.model.Category) DeleteCategory(cz.metacentrum.perun.webgui.json.cabinetManager.DeleteCategory) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) GetCategories(cz.metacentrum.perun.webgui.json.cabinetManager.GetCategories) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 99 with ClickEvent

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

the class FacilitiesPropagationsTabItem method draw.

public Widget draw() {
    mainrow = 0;
    okCounter = 0;
    errorCounter = 0;
    notDeterminedCounter = 0;
    procesingCounter = 0;
    VerticalPanel mainTab = new VerticalPanel();
    mainTab.setWidth("100%");
    final TabItem tab = this;
    // MAIN PANEL
    final ScrollPanel firstTabPanel = new ScrollPanel();
    firstTabPanel.setSize("100%", "100%");
    firstTabPanel.setStyleName("perun-tableScrollPanel");
    final FlexTable help = new FlexTable();
    help.setCellPadding(4);
    help.setWidth("100%");
    help.setHTML(0, 0, "<strong>Color&nbsp;notation:</strong>");
    help.getFlexCellFormatter().setWidth(0, 0, "100px");
    help.setHTML(0, 1, "<strong>OK</strong>");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setWidth(0, 1, "50px");
    help.getFlexCellFormatter().setStyleName(0, 1, "green");
    help.setHTML(0, 2, "<strong>Error</strong>");
    help.getFlexCellFormatter().setWidth(0, 2, "50px");
    help.getFlexCellFormatter().setStyleName(0, 2, "red");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
    help.setHTML(0, 3, "<strong>Not&nbsp;determined</strong>");
    help.getFlexCellFormatter().setWidth(0, 3, "50px");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setStyleName(0, 3, "notdetermined");
    /*
			 help.setHTML(0, 4, "<strong>Processing</strong>");
			 help.getFlexCellFormatter().setWidth(0, 4, "50px");
			 help.getFlexCellFormatter().setStyleName(0, 4, "yellow");
			 help.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
			 */
    final CustomButton cb = new CustomButton(ButtonTranslation.INSTANCE.refreshButton(), ButtonTranslation.INSTANCE.refreshPropagationResults(), SmallIcons.INSTANCE.updateIcon(), new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().reloadTab(tab);
        }
    });
    help.setWidget(0, 5, cb);
    help.getFlexCellFormatter().setWidth(0, 5, "200px");
    help.setHTML(0, 6, "&nbsp;");
    help.getFlexCellFormatter().setWidth(0, 6, "50%");
    mainTab.add(help);
    mainTab.add(new HTML("<hr size=\"2\" />"));
    mainTab.add(firstTabPanel);
    final FlexTable content = new FlexTable();
    content.setWidth("100%");
    content.setBorderWidth(0);
    firstTabPanel.add(content);
    content.setStyleName("propagationTable", true);
    final AjaxLoaderImage im = new AjaxLoaderImage();
    content.setWidget(0, 0, im);
    content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    final GetFacilityState callback = new GetFacilityState(0, 0, new JsonCallbackEvents() {

        public void onLoadingStart() {
            im.loadingStart();
            cb.setProcessing(true);
        }

        public void onError(PerunError error) {
            im.loadingError(error);
            cb.setProcessing(false);
        }

        public void onFinished(JavaScriptObject jso) {
            im.loadingFinished();
            cb.setProcessing(false);
            content.clear();
            content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
            ArrayList<FacilityState> list = JsonUtils.jsoAsList(jso);
            if (list != null && !list.isEmpty()) {
                list = new TableSorter<FacilityState>().sortByNumberOfDestinations(list);
                ArrayList<FacilityState> clusters = new ArrayList<FacilityState>();
                ArrayList<FacilityState> hosts = new ArrayList<FacilityState>();
                for (final FacilityState state : list) {
                    if (state.getDestinations().size() > 1) {
                        clusters.add(state);
                    } else {
                        hosts.add(state);
                    }
                }
                clusters = new TableSorter<FacilityState>().sortByFacilityName(clusters);
                hosts = new TableSorter<FacilityState>().sortByFacilityName(hosts);
                for (final FacilityState state : clusters) {
                    content.setHTML(mainrow, 0, "<strong>" + state.getFacility().getName() + "</strong>");
                    final FlowPanel inner = new FlowPanel();
                    content.setWidget(mainrow + 1, 0, inner);
                    content.getFlexCellFormatter().setStyleName(mainrow + 1, 0, "propagationTablePadding");
                    Set<String> destinations = state.getDestinations().keySet();
                    ArrayList<String> destList = new ArrayList<String>();
                    int width = 0;
                    for (String dest : destinations) {
                        destList.add(dest);
                        if (dest.indexOf(".") * 8 > width) {
                            width = dest.indexOf(".") * 8;
                        }
                    }
                    Collections.sort(destList);
                    for (final String dest : destList) {
                        String show = dest.substring(0, dest.indexOf("."));
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + show + "</span>");
                        hyp.addClickHandler(new ClickHandler() {

                            public void onClick(ClickEvent clickEvent) {
                                session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, false));
                            }
                        });
                        inner.add(hyp);
                        // style
                        if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
                            hyp.addStyleName("red");
                            errorCounter++;
                        } else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
                            hyp.addStyleName("green");
                            okCounter++;
                        } else {
                            hyp.addStyleName("notdetermined");
                            notDeterminedCounter++;
                        }
                    }
                    if (destList.isEmpty()) {
                        notDeterminedCounter++;
                    }
                    mainrow++;
                    mainrow++;
                }
                // PROCESS HOSTS (with one or less destination)
                // FIX WIDTH
                int width = 0;
                for (FacilityState state : hosts) {
                    if (state.getDestinations().size() < 2) {
                        if (state.getFacility().getName().length() * 8 > width) {
                            width = state.getFacility().getName().length() * 8;
                        }
                    }
                }
                FlowPanel inner = new FlowPanel();
                for (final FacilityState state : hosts) {
                    Set<String> destinations = state.getDestinations().keySet();
                    ArrayList<String> destList = new ArrayList<String>();
                    for (String dest : destinations) {
                        destList.add(dest);
                    }
                    Collections.sort(destList);
                    for (final String dest : destList) {
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + dest + "</span>");
                        inner.add(hyp);
                        hyp.addClickHandler(new ClickHandler() {

                            public void onClick(ClickEvent clickEvent) {
                                session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, false));
                            }
                        });
                        // style
                        if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
                            hyp.addStyleName("red");
                            errorCounter++;
                        } else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
                            hyp.addStyleName("green");
                            okCounter++;
                        } else {
                            hyp.addStyleName("notdetermined");
                            notDeterminedCounter++;
                        }
                    }
                    if (destList.isEmpty()) {
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + state.getFacility().getName() + "</span>");
                        inner.add(hyp);
                        hyp.addStyleName("notdetermined");
                        notDeterminedCounter++;
                    }
                }
                if (!hosts.isEmpty()) {
                    content.setHTML(mainrow, 0, "<strong>Single hosts</strong>");
                    mainrow++;
                }
                content.setWidget(mainrow, 0, inner);
                content.getFlexCellFormatter().setStyleName(mainrow, 0, "propagationTablePadding");
                mainrow++;
            }
            // set counters
            help.setHTML(0, 1, "<strong>Ok&nbsp;(" + okCounter + ")</strong>");
            help.setHTML(0, 2, "<strong>Error&nbsp;(" + errorCounter + ")</strong>");
            help.setHTML(0, 3, "<strong>Not&nbsp;determined&nbsp;(" + notDeterminedCounter + ")</strong>");
        //help.setHTML(0, 4, "<strong>Processing&nbsp;(" + procesingCounter + ")</strong>");
        }
    });
    // get for all facilities
    callback.retrieveData();
    // resize perun table to correct size on screen
    session.getUiElements().resizePerunTable(firstTabPanel, 400, this);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Set(java.util.Set) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) JSONString(com.google.gwt.json.client.JSONString) GetFacilityState(cz.metacentrum.perun.webgui.json.propagationStatsReader.GetFacilityState) FacilityState(cz.metacentrum.perun.webgui.model.FacilityState) GetFacilityState(cz.metacentrum.perun.webgui.json.propagationStatsReader.GetFacilityState) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) PerunError(cz.metacentrum.perun.webgui.model.PerunError) JSONString(com.google.gwt.json.client.JSONString)

Example 100 with ClickEvent

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

the class FacilitiesSelectTabItem method draw.

public Widget draw() {
    // MAIN PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // TAB MENU
    TabMenu tabMenu = new TabMenu();
    // get RICH facilities request
    final GetFacilities facilities = new GetFacilities(true);
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(facilities);
    // retrieve data (table)
    final CellTable<Facility> table = facilities.getTable(new FieldUpdater<Facility, String>() {

        public void update(int index, Facility object, String value) {
            session.getTabManager().addTab(new FacilityDetailTabItem(object));
        }
    });
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    // add new facility button
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createFacility(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTab(new CreateFacilityTabItem(facilities.getFullBackupList(), events));
        }
    }));
    // add delete facilities button
    final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteFacilities());
    if (session.isPerunAdmin()) {
        tabMenu.addWidget(deleteButton);
    }
    deleteButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<Facility> list = facilities.getTableSelectedList();
            String text = "Following facilities will be deleted.";
            UiElements.showDeleteConfirm(list, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < list.size(); i++) {
                        if (i == list.size() - 1) {
                            DeleteFacility request = new DeleteFacility(JsonCallbackEvents.disableButtonEvents(deleteButton, events));
                            request.deleteFacility(list.get(i).getId());
                        } else {
                            DeleteFacility request = new DeleteFacility(JsonCallbackEvents.disableButtonEvents(deleteButton));
                            request.deleteFacility(list.get(i).getId());
                        }
                    }
                }
            });
        }
    });
    // filter box
    tabMenu.addFilterWidget(new ExtendedSuggestBox(facilities.getOracle()), new PerunSearchEvent() {

        public void searchFor(String text) {
            facilities.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterFacilities());
    tabMenu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
    tabMenu.addWidget(new HTML("<strong>Please select Facility you want to manage.</strong>"));
    deleteButton.setEnabled(false);
    JsonUtils.addTableManagedButton(facilities, table, deleteButton);
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // add menu and the table to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    firstTabPanel.add(sp);
    firstTabPanel.setCellHeight(sp, "100%");
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) DeleteFacility(cz.metacentrum.perun.webgui.json.facilitiesManager.DeleteFacility) GetFacilities(cz.metacentrum.perun.webgui.json.facilitiesManager.GetFacilities) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) DeleteFacility(cz.metacentrum.perun.webgui.json.facilitiesManager.DeleteFacility) Facility(cz.metacentrum.perun.webgui.model.Facility)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)316 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)314 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)161 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)135 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)124 ArrayList (java.util.ArrayList)117 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)105 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)76 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)40 PerunError (cz.metacentrum.perun.webgui.model.PerunError)36 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)32 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)32 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)31 HashMap (java.util.HashMap)31 Button (com.google.gwt.user.client.ui.Button)30 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)25 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)23 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)20 Map (java.util.Map)20 User (cz.metacentrum.perun.webgui.model.User)19