Search in sources :

Example 1 with CreateDependency

use of cz.metacentrum.perun.webgui.json.generalServiceManager.CreateDependency in project perun by CESNET.

the class AddDependencyTabItem method draw.

public Widget draw() {
    // TITLE
    titleWidget.setText("Add dependency");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // prepares layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // close tab events
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    final ListBoxWithObjects<ExecService> listBox = new ListBoxWithObjects<ExecService>();
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDependantExecService());
    // fill listbox after callback finishes
    final JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            listBox.clear();
            ArrayList<ExecService> execs = JsonUtils.jsoAsList(jso);
            if (execs != null && !execs.isEmpty()) {
                execs = new TableSorter<ExecService>().sortByService(execs);
                for (int i = 0; i < execs.size(); i++) {
                    listBox.addItem(execs.get(i));
                    if (execService.getService().getName().equals(execs.get(i).getService().getName()) && !execService.getType().equals(execs.get(i).getType())) {
                        // preselect different type of exec service from same service
                        listBox.setSelected(execs.get(i), true);
                    }
                }
                addButton.setEnabled(true);
            } else {
                listBox.addItem("No exec service available");
            }
        }

        @Override
        public void onLoadingStart() {
            listBox.clear();
            listBox.addItem("Loading...");
            addButton.setEnabled(false);
        }

        @Override
        public void onError(PerunError error) {
            listBox.addItem("Error while loading");
            addButton.setEnabled(false);
        }
    };
    // callback for all services
    ListExecServices callback = new ListExecServices(0, localEvents);
    callback.retrieveData();
    // layout
    layout.setHTML(0, 0, "ExecService:");
    layout.setHTML(1, 0, "Depend On:");
    layout.setHTML(0, 1, execService.getService().getName() + " " + execService.getType());
    layout.setWidget(1, 1, listBox);
    final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab);
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            CreateDependency request = new CreateDependency(closeTabEvents);
            request.createDependancy(execServiceId, listBox.getSelectedObject().getId());
        }
    });
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    });
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    menu.addWidget(addButton);
    menu.addWidget(cancelButton);
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ExecService(cz.metacentrum.perun.webgui.model.ExecService) CreateDependency(cz.metacentrum.perun.webgui.json.generalServiceManager.CreateDependency) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ListExecServices(cz.metacentrum.perun.webgui.json.generalServiceManager.ListExecServices) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) 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)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 CreateDependency (cz.metacentrum.perun.webgui.json.generalServiceManager.CreateDependency)1 ListExecServices (cz.metacentrum.perun.webgui.json.generalServiceManager.ListExecServices)1 ExecService (cz.metacentrum.perun.webgui.model.ExecService)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1