Search in sources :

Example 1 with ExecService

use of cz.metacentrum.perun.webgui.model.ExecService 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)

Example 2 with ExecService

use of cz.metacentrum.perun.webgui.model.ExecService in project perun by CESNET.

the class EditExecServiceTabItem method draw.

public Widget draw() {
    titleWidget = new Label("Edit ExecService");
    VerticalPanel vp = new VerticalPanel();
    final CheckBox enabled = new CheckBox();
    enabled.setText("Enabled / Disabled");
    enabled.setValue(execService.isEnabled());
    final ExtendedTextBox delay = new ExtendedTextBox();
    delay.getTextBox().setText("" + execService.getDefaultDelay());
    final ExtendedTextBox.TextBoxValidator delayValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!JsonUtils.checkParseInt(delay.getTextBox().getText().trim())) {
                delay.setError("Delay must be a number (time in minutes) !");
                return false;
            } else {
                delay.setOk();
                return true;
            }
        }
    };
    delay.setValidator(delayValidator);
    final ExtendedTextBox scriptPath = new ExtendedTextBox();
    scriptPath.getTextBox().setValue(execService.getScriptPath());
    final ExtendedTextBox.TextBoxValidator scriptValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (scriptPath.getTextBox().getText().trim().isEmpty()) {
                scriptPath.setError("Script path can't be empty !");
                return false;
            } else {
                scriptPath.setOk();
                return true;
            }
        }
    };
    scriptPath.setValidator(scriptValidator);
    // prepares layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // close tab events
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    // send button
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes of ExecService");
    saveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (!scriptValidator.validateTextBox() && !delayValidator.validateTextBox())
                return;
            ExecService es = JsonUtils.clone(execService).cast();
            es.setEnabled(enabled.getValue());
            es.setDefaultDelay(Integer.parseInt(delay.getTextBox().getValue().trim()));
            es.setScriptPath(scriptPath.getTextBox().getValue().trim());
            UpdateExecService request = new UpdateExecService(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, events));
            request.updateExecService(es);
        }
    });
    // cancel button
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    });
    // Add some standard form options
    layout.setHTML(0, 0, "Enabled:");
    layout.setWidget(0, 1, enabled);
    layout.setHTML(1, 0, "Script path:");
    layout.setWidget(1, 1, scriptPath);
    layout.setHTML(2, 0, "Delay:");
    layout.setWidget(2, 1, delay);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    menu.addWidget(saveButton);
    menu.addWidget(cancelButton);
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : UpdateExecService(cz.metacentrum.perun.webgui.json.generalServiceManager.UpdateExecService) ExecService(cz.metacentrum.perun.webgui.model.ExecService) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) UpdateExecService(cz.metacentrum.perun.webgui.json.generalServiceManager.UpdateExecService) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 3 with ExecService

use of cz.metacentrum.perun.webgui.model.ExecService in project perun by CESNET.

the class ServiceExecServicesTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(service.getName()) + ": exec services");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    final ListExecServices callback = new ListExecServices(serviceId);
    CellTable<ExecService> table = callback.getTable(new FieldUpdater<ExecService, String>() {

        public void update(int index, ExecService object, String value) {
            // manage details of exec services (dependency, status, update values?)
            session.getTabManager().addTab(new ViewExecServiceTabItem(object));
        }
    });
    // refresh event after deletion
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(callback);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createExecService(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().addTabToCurrentTab(new AddExecServiceTabItem(service));
        }
    }));
    final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.deleteSelectedExecServices());
    menu.addWidget(deleteButton);
    deleteButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<ExecService> execToRemove = callback.getTableSelectedList();
            UiElements.showDeleteConfirm(execToRemove, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                    for (int i = 0; i < execToRemove.size(); i++) {
                        if (i == execToRemove.size() - 1) {
                            DeleteExecService request = new DeleteExecService(JsonCallbackEvents.disableButtonEvents(deleteButton, events));
                            request.deleteExecService(execToRemove.get(i).getId());
                        } else {
                            DeleteExecService request = new DeleteExecService(JsonCallbackEvents.disableButtonEvents(deleteButton));
                            request.deleteExecService(execToRemove.get(i).getId());
                        }
                    }
                }
            });
        }
    });
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    final CustomButton enable = TabMenu.getPredefinedButton(ButtonType.ENABLE, "Enable selected exec service(s)");
    final CustomButton disable = TabMenu.getPredefinedButton(ButtonType.DISABLE, "Disable selected exec service(s)");
    menu.addWidget(enable);
    menu.addWidget(disable);
    enable.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            ArrayList<ExecService> list = callback.getTableSelectedList();
            for (int i = 0; i < list.size(); i++) {
                ExecService e = list.get(i);
                if (i < list.size() - 1) {
                    // any call
                    if (!e.isEnabled()) {
                        UpdateExecService request = new UpdateExecService(JsonCallbackEvents.disableButtonEvents(enable));
                        e.setEnabled(true);
                        request.updateExecService(e);
                    }
                } else {
                    // last call
                    if (!e.isEnabled()) {
                        UpdateExecService request = new UpdateExecService(JsonCallbackEvents.disableButtonEvents(enable, events));
                        e.setEnabled(true);
                        request.updateExecService(e);
                    }
                }
            }
        }
    });
    disable.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            ArrayList<ExecService> list = callback.getTableSelectedList();
            for (int i = 0; i < list.size(); i++) {
                ExecService e = list.get(i);
                if (i < list.size() - 1) {
                    // any call
                    if (e.isEnabled()) {
                        UpdateExecService request = new UpdateExecService(JsonCallbackEvents.disableButtonEvents(disable));
                        e.setEnabled(false);
                        request.updateExecService(e);
                    }
                } else {
                    // last call
                    if (e.isEnabled()) {
                        UpdateExecService request = new UpdateExecService(JsonCallbackEvents.disableButtonEvents(disable, events));
                        e.setEnabled(false);
                        request.updateExecService(e);
                    }
                }
            }
        }
    });
    deleteButton.setEnabled(false);
    enable.setEnabled(false);
    disable.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, deleteButton);
    JsonUtils.addTableManagedButton(callback, table, enable);
    JsonUtils.addTableManagedButton(callback, table, disable);
    vp.add(sp);
    vp.setCellHeight(sp, "100%");
    // add tabs to the main panel
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) DeleteExecService(cz.metacentrum.perun.webgui.json.generalServiceManager.DeleteExecService) UpdateExecService(cz.metacentrum.perun.webgui.json.generalServiceManager.UpdateExecService) ExecService(cz.metacentrum.perun.webgui.model.ExecService) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) DeleteExecService(cz.metacentrum.perun.webgui.json.generalServiceManager.DeleteExecService) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ListExecServices(cz.metacentrum.perun.webgui.json.generalServiceManager.ListExecServices) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) UpdateExecService(cz.metacentrum.perun.webgui.json.generalServiceManager.UpdateExecService) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 4 with ExecService

use of cz.metacentrum.perun.webgui.model.ExecService in project perun by CESNET.

the class ViewExecServiceTabItem method getDependencyContent.

public VerticalPanel getDependencyContent() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // MAIN MENU
    TabMenu tabMenu = new TabMenu();
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    // callback
    final ListExecServicesThisExecServiceDependsOn callback = new ListExecServicesThisExecServiceDependsOn(execServiceId);
    // refresh event
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(callback);
    // add button
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDependantExecService(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().addTabToCurrentTab(new AddDependencyTabItem(execService));
        }
    }));
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedDependantExecServices());
    tabMenu.addWidget(removeButton);
    removeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ExecService> dependencyForDeletion = callback.getTableSelectedList();
            UiElements.showDeleteConfirm(dependencyForDeletion, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                    for (int i = 0; i < dependencyForDeletion.size(); i++) {
                        if (i == dependencyForDeletion.size() - 1) {
                            RemoveDependency request = new RemoveDependency(JsonCallbackEvents.disableButtonEvents(removeButton, events));
                            request.removeDependency(execServiceId, dependencyForDeletion.get(i).getId());
                        } else {
                            RemoveDependency request = new RemoveDependency(JsonCallbackEvents.disableButtonEvents(removeButton));
                            request.removeDependency(execServiceId, dependencyForDeletion.get(i).getId());
                        }
                    }
                }
            });
        }
    });
    vp.add(tabMenu);
    vp.setCellHeight(tabMenu, "30px");
    // get table
    CellTable<ExecService> table = callback.getTable();
    // create scroll panel for table
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    sp.setWidth("100%");
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, removeButton);
    vp.add(sp);
    vp.setCellHeight(sp, "100%");
    session.getUiElements().resizePerunTable(sp, 250, this);
    return vp;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ExecService(cz.metacentrum.perun.webgui.model.ExecService) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) RemoveDependency(cz.metacentrum.perun.webgui.json.generalServiceManager.RemoveDependency) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ListExecServicesThisExecServiceDependsOn(cz.metacentrum.perun.webgui.json.generalServiceManager.ListExecServicesThisExecServiceDependsOn) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 5 with ExecService

use of cz.metacentrum.perun.webgui.model.ExecService in project perun by CESNET.

the class ListDenialsForFacility method onFinished.

/**
	 * Called when loading successfully finishes.
	 */
public void onFinished(JavaScriptObject jso) {
    for (ExecService e : JsonUtils.<ExecService>jsoAsList(jso)) {
        e.setLocalEnabled("Disabled");
        addToTable(e);
    }
    sortTable();
    loaderImage.loadingFinished();
    session.getUiElements().setLogText("ExecServices loaded: " + list.size());
    events.onFinished(jso);
}
Also used : ExecService(cz.metacentrum.perun.webgui.model.ExecService)

Aggregations

ExecService (cz.metacentrum.perun.webgui.model.ExecService)5 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)4 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)4 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)3 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)2 ListExecServices (cz.metacentrum.perun.webgui.json.generalServiceManager.ListExecServices)2 UpdateExecService (cz.metacentrum.perun.webgui.json.generalServiceManager.UpdateExecService)2 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)2 ArrayList (java.util.ArrayList)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 CreateDependency (cz.metacentrum.perun.webgui.json.generalServiceManager.CreateDependency)1 DeleteExecService (cz.metacentrum.perun.webgui.json.generalServiceManager.DeleteExecService)1 ListExecServicesThisExecServiceDependsOn (cz.metacentrum.perun.webgui.json.generalServiceManager.ListExecServicesThisExecServiceDependsOn)1 RemoveDependency (cz.metacentrum.perun.webgui.json.generalServiceManager.RemoveDependency)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)1 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)1