Search in sources :

Example 1 with Resource

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

the class ResourceDetailTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()));
    // main widget panel
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    AbsolutePanel dp = new AbsolutePanel();
    // dp.setStyleName("decoration");
    final FlexTable menu = new FlexTable();
    menu.setCellSpacing(5);
    // MAIN INFO PANEL
    // resource info
    menu.setWidget(0, 0, new Image(LargeIcons.INSTANCE.serverGroupIcon()));
    Label resourceName = new Label();
    resourceName.setText(Utils.getStrippedStringWithEllipsis(resource.getName(), 40));
    resourceName.setStyleName("now-managing");
    resourceName.setTitle(resource.getName());
    menu.setWidget(0, 1, resourceName);
    menu.setHTML(0, 2, " ");
    menu.getFlexCellFormatter().setWidth(0, 2, "25px");
    int column = 3;
    final JsonCallbackEvents events = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            new GetEntityById(PerunEntity.RICH_RESOURCE, resourceId, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    resource = jso.cast();
                    open();
                    draw();
                }
            }).retrieveData();
        }
    };
    CustomButton change = new CustomButton("", ButtonTranslation.INSTANCE.editResourceDetails(), SmallIcons.INSTANCE.applicationFormEditIcon());
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        change.setEnabled(false);
    change.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // prepare confirm content
            Resource r = resource.cast();
            session.getTabManager().addTabToCurrentTab(new EditResourceDetailsTabItem(r, events));
        }
    });
    menu.setWidget(0, column, change);
    column++;
    menu.setHTML(0, column, " ");
    menu.getFlexCellFormatter().setWidth(0, column, "25px");
    column++;
    if (JsonUtils.isExtendedInfoVisible()) {
        menu.setHTML(0, column, "<strong>ID:</strong><br/><span class=\"inputFormInlineComment\">" + resource.getId() + "</span>");
        column++;
        menu.setHTML(0, column, "&nbsp;");
        menu.getFlexCellFormatter().setWidth(0, column, "25px");
        column++;
    }
    if (facilityId > 0) {
        // facility admin view
        menu.setHTML(0, column, "<strong>VO:</strong><br/><span class=\"inputFormInlineComment\">" + resource.getVoId() + " / " + SafeHtmlUtils.fromString(resource.getVo().getShortName()).asString() + "</span>");
        column++;
        menu.setHTML(0, column, "&nbsp;");
        menu.getFlexCellFormatter().setWidth(0, column, "25px");
        column++;
    }
    menu.setHTML(0, column, "<strong>Description:</strong><br/><span class=\"inputFormInlineComment\">" + SafeHtmlUtils.fromString((resource.getDescription() != null) ? resource.getDescription() : "").asString() + "&nbsp;</span>");
    if (session.isFacilityAdmin(resource.getFacilityId())) {
        column++;
        menu.setHTML(0, column, "&nbsp;");
        menu.getFlexCellFormatter().setWidth(0, column, "25px");
        column++;
        Anchor a = new Anchor("View facility details >>");
        a.setStyleName("pointer");
        a.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                session.getTabManager().addTab(new FacilityDetailTabItem(resource.getFacility()));
            }
        });
        menu.setWidget(0, column, a);
    }
    dp.add(menu);
    vp.add(dp);
    vp.setCellHeight(dp, "30px");
    // TAB PANEL WITH INNER TABS
    tabPanel.clear();
    Resource r = resource.cast();
    tabPanel.add(new ResourceAssignedGroupsTabItem(r), "Assigned groups");
    tabPanel.add(new ResourceAssignedServicesTabItem(r), "Assigned services");
    tabPanel.add(new ResourceSettingsTabItem(r, null), "Service settings");
    tabPanel.add(new ResourceGroupSettingsTabItem(r), "Group settings");
    tabPanel.add(new ResourceMemberSettingsTabItem(resource), "Member settings");
    if (session.isVoAdmin(r.getVoId()) || session.isVoObserver(r.getVoId())) {
        tabPanel.add(new ResourceTagsTabItem(r), "Tags");
    }
    // Resize must be called after page fully displays
    Scheduler.get().scheduleDeferred(new Command() {

        @Override
        public void execute() {
            tabPanel.finishAdding();
        }
    });
    vp.add(tabPanel);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ImageResource(com.google.gwt.resources.client.ImageResource) Resource(cz.metacentrum.perun.webgui.model.Resource) RichResource(cz.metacentrum.perun.webgui.model.RichResource) FacilityDetailTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.FacilityDetailTabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) Command(com.google.gwt.user.client.Command) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById)

Example 2 with Resource

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

the class CreateFacilityResourceTabItem method draw.

public Widget draw() {
    titleWidget.setText("Create resource");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // form inputs
    final ExtendedTextBox nameTextBox = new ExtendedTextBox();
    final TextBox descriptionTextBox = new TextBox();
    final ListBoxWithObjects<VirtualOrganization> vosDropDown = new ListBoxWithObjects<VirtualOrganization>();
    // send button
    final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createResource());
    // local events fills the listbox of Vos and Slds
    JsonCallbackEvents event = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // fill VOs listbox
            vosDropDown.clear();
            ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
            vos = new TableSorter<VirtualOrganization>().sortByName(vos);
            for (VirtualOrganization vo : vos) {
                vosDropDown.addItem(vo);
            }
            if (!vos.isEmpty())
                createButton.setEnabled(true);
        }

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

        @Override
        public void onError(PerunError error) {
            vosDropDown.clear();
            vosDropDown.addItem("Error while loading");
            createButton.setEnabled(false);
        }
    };
    // load available VOs
    final GetVos vos = new GetVos(event);
    vos.setForceAll(true);
    vos.retrieveData();
    // layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // Add some standard form options
    layout.setHTML(0, 0, "On facility:");
    layout.setHTML(0, 1, SafeHtmlUtils.fromString((facility.getName() != null) ? facility.getName() : "").asString());
    layout.setHTML(1, 0, "For VO:");
    layout.setWidget(1, 1, vosDropDown);
    layout.setHTML(2, 0, "Name:");
    layout.setWidget(2, 1, nameTextBox);
    layout.setHTML(3, 0, "Description:");
    layout.setWidget(3, 1, descriptionTextBox);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    layout.setWidth("350px");
    TabMenu menu = new TabMenu();
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (nameTextBox.getTextBox().getText().trim().isEmpty()) {
                nameTextBox.setError("Name can't be empty.");
                return false;
            }
            nameTextBox.setOk();
            return true;
        }
    };
    nameTextBox.setValidator(validator);
    createButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // loads new tab when creating successful, also disable button
            JsonCallbackEvents localEvents = new JsonCallbackEvents() {

                public void onLoadingStart() {
                    (JsonCallbackEvents.disableButtonEvents(createButton)).onLoadingStart();
                }

                public void onFinished(JavaScriptObject jso) {
                    (JsonCallbackEvents.disableButtonEvents(createButton)).onFinished(jso);
                    Resource res = (Resource) jso;
                    session.getTabManager().addTabToCurrentTab(new CreateFacilityResourceManageServicesTabItem(facility, res), true);
                }

                public void onError(PerunError error) {
                    (JsonCallbackEvents.disableButtonEvents(createButton)).onError(error);
                }
            };
            if (validator.validateTextBox()) {
                // request
                CreateResource request = new CreateResource(localEvents);
                request.createResource(nameTextBox.getTextBox().getText().trim(), descriptionTextBox.getText().trim(), facility.getId(), vosDropDown.getSelectedObject().getId());
            }
        }
    });
    menu.addWidget(createButton);
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    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) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) CreateResource(cz.metacentrum.perun.webgui.json.resourcesManager.CreateResource) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ImageResource(com.google.gwt.resources.client.ImageResource) Resource(cz.metacentrum.perun.webgui.model.Resource) CreateResource(cz.metacentrum.perun.webgui.json.resourcesManager.CreateResource) GetVos(cz.metacentrum.perun.webgui.json.vosManager.GetVos) 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) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 3 with Resource

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

the class GetResources method retrieveData.

/**
 * Retrieves data from RPC
 */
public void retrieveData() {
    // empty
    if (this.attributesToSearchBy.size() == 0) {
        session.getUiElements().setLogText("No keywords.");
        return;
    }
    // ok, start
    loaderImage.loadingStart();
    // build request
    JSONObject attributesWithSearchingValues = new JSONObject();
    for (Map.Entry<String, String> entry : attributesToSearchBy.entrySet()) {
        String name = entry.getKey();
        String value = entry.getValue();
        attributesWithSearchingValues.put(name, new JSONString(value));
    }
    JSONObject req = new JSONObject();
    req.put("attributesWithSearchingValues", attributesWithSearchingValues);
    // send request
    JsonPostClient js = new JsonPostClient(new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Error while loading resources.");
            loaderImage.loadingError(error);
            events.onError(error);
        }

        public void onLoadingStart() {
            loaderImage.loadingStart();
            session.getUiElements().setLogText("Loading resources started.");
            events.onLoadingStart();
        }

        public void onFinished(JavaScriptObject jso) {
            loaderImage.loadingFinished();
            setList(JsonUtils.<Resource>jsoAsList(jso));
            sortTable();
            session.getUiElements().setLogText("Resources loaded: " + list.size());
            events.onFinished(jso);
        }
    });
    js.sendData(JSON_URL, req);
    return;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) Resource(cz.metacentrum.perun.webgui.model.Resource) JSONString(com.google.gwt.json.client.JSONString) PerunError(cz.metacentrum.perun.webgui.model.PerunError) HashMap(java.util.HashMap) Map(java.util.Map) JSONString(com.google.gwt.json.client.JSONString)

Example 4 with Resource

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

the class GetResources method removeFromTable.

/**
 * Removes object as row from table
 *
 * @param object Resource to be removed as row
 */
public void removeFromTable(Resource object) {
    Resource toRem = null;
    for (Resource r : getList()) {
        if (r.getId() == object.getId()) {
            toRem = r;
            break;
        }
    }
    list.remove(toRem);
    selectionModel.getSelectedSet().remove(toRem);
    dataProvider.flush();
    dataProvider.refresh();
}
Also used : Resource(cz.metacentrum.perun.webgui.model.Resource)

Example 5 with Resource

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

the class EditResourceDetailsTabItem method draw.

public Widget draw() {
    titleWidget = new Label("Edit resource");
    VerticalPanel vp = new VerticalPanel();
    // textboxes which set the class data when updated
    final ExtendedTextBox nameTextBox = new ExtendedTextBox();
    nameTextBox.getTextBox().setText(resource.getName());
    final TextBox descriptionTextBox = new TextBox();
    descriptionTextBox.setText(resource.getDescription());
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (nameTextBox.getTextBox().getText().trim().isEmpty()) {
                nameTextBox.setError("Name can't be empty.");
                return false;
            } else {
                nameTextBox.setOk();
                return true;
            }
        }
    };
    nameTextBox.setValidator(validator);
    // 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, buttonTranslation.saveResourceDetails());
    saveButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (!validator.validateTextBox())
                return;
            Resource r = JsonUtils.clone(resource).cast();
            r.setName(nameTextBox.getTextBox().getText().trim());
            r.setDescription(descriptionTextBox.getText().trim());
            UpdateResource request = new UpdateResource(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, true, events));
            request.updateResource(r);
        }
    });
    // cancel button
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    });
    // Add some standard form options
    layout.setHTML(0, 0, "Name:");
    layout.setWidget(0, 1, nameTextBox);
    layout.setHTML(1, 0, "Description:");
    layout.setWidget(1, 1, descriptionTextBox);
    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 : FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) UpdateResource(cz.metacentrum.perun.webgui.json.resourcesManager.UpdateResource) ImageResource(com.google.gwt.resources.client.ImageResource) Resource(cz.metacentrum.perun.webgui.model.Resource) UpdateResource(cz.metacentrum.perun.webgui.json.resourcesManager.UpdateResource) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) 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) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Aggregations

Resource (cz.metacentrum.perun.webgui.model.Resource)8 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)5 ImageResource (com.google.gwt.resources.client.ImageResource)5 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)5 PerunError (cz.metacentrum.perun.webgui.model.PerunError)4 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 JSONObject (com.google.gwt.json.client.JSONObject)2 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)2 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)2 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)2 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSONString (com.google.gwt.json.client.JSONString)1 Command (com.google.gwt.user.client.Command)1 GetEntityById (cz.metacentrum.perun.webgui.json.GetEntityById)1 CreateResource (cz.metacentrum.perun.webgui.json.resourcesManager.CreateResource)1