Search in sources :

Example 11 with Image

use of com.google.gwt.user.client.ui.Image in project gwt-test-utils by gwt-test-utils.

the class ImageTest method constructor.

@Test
public void constructor() {
    // Given
    ImageResource imageRessource = MyClientBundle.INSTANCE.imageResource();
    // When
    Image i = new Image(imageRessource);
    // Then
    assertThat(i.getUrl()).isEqualTo("http://127.0.0.1:8888/gwt_test_utils_module/imageResource.gif");
    assertThat(i.getOriginLeft()).isEqualTo(0);
    assertThat(i.getOriginTop()).isEqualTo(0);
    assertThat(i.getWidth()).isEqualTo(0);
    assertThat(i.getHeight()).isEqualTo(0);
}
Also used : ImageResource(com.google.gwt.resources.client.ImageResource) Image(com.google.gwt.user.client.ui.Image) Test(org.junit.Test)

Example 12 with Image

use of com.google.gwt.user.client.ui.Image in project perun by CESNET.

the class GetAllRichSubGroups method getTable.

/**
	 * Returns the table with subgroups.
	 * @return
	 */
public CellTable<RichGroup> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<RichGroup>(list);
    // Cell table
    table = new PerunTable<RichGroup>(list);
    table.setHyperlinksAllowed(false);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<RichGroup> columnSortHandler = new ListHandler<RichGroup>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<RichGroup>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("Group has no sub-groups.");
    // checkbox column column
    table.addCheckBoxColumn();
    table.addIdColumn("Group ID", tableFieldUpdater);
    // Add a synchronization clicable icon column.
    Column<RichGroup, RichGroup> syncColumn = new Column<RichGroup, RichGroup>(new CustomClickableInfoCellWithImageResource("click")) {

        @Override
        public RichGroup getValue(RichGroup object) {
            return object;
        }

        @Override
        public String getCellStyleNames(Cell.Context context, RichGroup object) {
            if (tableFieldUpdater != null) {
                return super.getCellStyleNames(context, object) + " pointer image-hover";
            } else {
                return super.getCellStyleNames(context, object);
            }
        }
    };
    syncColumn.setFieldUpdater(new FieldUpdater<RichGroup, RichGroup>() {

        @Override
        public void update(int index, final RichGroup object, RichGroup value) {
            GetEntityById get = new GetEntityById(PerunEntity.RICH_GROUP, object.getId(), new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    final RichGroup object = jso.cast();
                    String name, syncEnabled, syncInterval, syncTimestamp, syncSuccessTimestamp, syncState, authGroup;
                    name = object.getName();
                    if (object.isSyncEnabled()) {
                        syncEnabled = "enabled";
                    } else {
                        syncEnabled = "disabled";
                    }
                    if (object.getSynchronizationInterval() == null) {
                        syncInterval = "N/A";
                    } else {
                        if (JsonUtils.checkParseInt(object.getSynchronizationInterval())) {
                            int time = Integer.parseInt(object.getSynchronizationInterval()) * 5 / 60;
                            if (time == 0) {
                                time = Integer.parseInt(object.getSynchronizationInterval()) * 5;
                                syncInterval = time + " minute(s)";
                            } else {
                                syncInterval = time + " hour(s)";
                            }
                        } else {
                            syncInterval = object.getSynchronizationInterval();
                        }
                    }
                    if (object.getLastSynchronizationState() == null) {
                        if (object.getLastSuccessSynchronizationTimestamp() != null) {
                            syncState = "OK";
                        } else {
                            syncState = "Not synced yet";
                        }
                    } else {
                        if (session.isPerunAdmin()) {
                            syncState = object.getLastSynchronizationState();
                        } else {
                            syncState = "Internal Error";
                        }
                    }
                    if (object.getLastSynchronizationTimestamp() == null) {
                        syncTimestamp = "N/A";
                    } else {
                        syncTimestamp = object.getLastSynchronizationTimestamp().split("\\.")[0];
                    }
                    if (object.getLastSuccessSynchronizationTimestamp() == null) {
                        syncSuccessTimestamp = "N/A";
                    } else {
                        syncSuccessTimestamp = object.getLastSuccessSynchronizationTimestamp().split("\\.")[0];
                    }
                    if (object.getAuthoritativeGroup() != null && object.getAuthoritativeGroup().equals("1")) {
                        authGroup = "Yes";
                    } else {
                        authGroup = "No";
                    }
                    String html = "Group name: <b>" + name + "</b><br>";
                    html += "Synchronization: <b>" + syncEnabled + "</b><br>";
                    if (object.isSyncEnabled()) {
                        html += "Last sync. state: <b>" + syncState + "</b><br>";
                        html += "Last sync. timestamp: <b>" + syncTimestamp + "</b><br>";
                        html += "Last successful sync. timestamp: <b>" + syncSuccessTimestamp + "</b><br>";
                        html += "Sync. Interval: <b>" + syncInterval + "</b><br>";
                        html += "Authoritative group: <b>" + authGroup + "</b><br>";
                    }
                    FlexTable layout = new FlexTable();
                    layout.setWidget(0, 0, new HTML("<p>" + new Image(LargeIcons.INSTANCE.informationIcon())));
                    layout.setHTML(0, 1, "<p style=\"line-height: 1.2;\">" + html);
                    layout.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                    layout.getFlexCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                    layout.getFlexCellFormatter().setStyleName(0, 0, "alert-box-image");
                    final CustomButton okButton = new CustomButton("Force synchronization", SmallIcons.INSTANCE.arrowRefreshIcon());
                    okButton.addClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            ForceGroupSynchronization call = new ForceGroupSynchronization(JsonCallbackEvents.disableButtonEvents(okButton));
                            call.synchronizeGroup(object.getId());
                        }
                    });
                    if (!session.isVoAdmin(object.getVoId()) && !session.isGroupAdmin(object.getId()))
                        okButton.setEnabled(false);
                    okButton.setVisible(object.isSyncEnabled());
                    final Confirm c = new Confirm("Group synchronization info", layout, okButton, null, true);
                    c.setHideOnButtonClick(false);
                    c.setCancelIcon(SmallIcons.INSTANCE.acceptIcon());
                    c.setCancelButtonText("OK");
                    c.setCancelClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            c.hide();
                        }
                    });
                    c.show();
                }
            });
            get.retrieveData();
        }

        ;
    });
    syncColumn.setSortable(true);
    columnSortHandler.setComparator(syncColumn, new Comparator<RichGroup>() {

        @Override
        public int compare(RichGroup o1, RichGroup o2) {
            if (o1 != null && o2 != null) {
                int o1val = 0;
                int o2val = 0;
                if (o1.isSyncEnabled())
                    o1val = 5;
                if (o2.isSyncEnabled())
                    o2val = 5;
                if (o1.getAuthoritativeGroup() != null && o1.getAuthoritativeGroup().equalsIgnoreCase("1"))
                    o1val = o1val + 3;
                if (o2.getAuthoritativeGroup() != null && o2.getAuthoritativeGroup().equalsIgnoreCase("1"))
                    o2val = o2val + 3;
                return o1val - o2val;
            }
            return 0;
        }
    });
    table.addColumn(syncColumn, "Sync");
    table.setColumnWidth(syncColumn, "70px");
    table.addNameColumn(tableFieldUpdater);
    table.addDescriptionColumn(tableFieldUpdater);
    return table;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) RichGroup(cz.metacentrum.perun.webgui.model.RichGroup) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) Image(com.google.gwt.user.client.ui.Image) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) Column(com.google.gwt.user.cellview.client.Column) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) FlexTable(com.google.gwt.user.client.ui.FlexTable) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomClickableInfoCellWithImageResource(cz.metacentrum.perun.webgui.widgets.cells.CustomClickableInfoCellWithImageResource)

Example 13 with Image

use of com.google.gwt.user.client.ui.Image in project perun by CESNET.

the class PerunStatusCell method render.

@Override
public void render(com.google.gwt.cell.client.Cell.Context context, String status, SafeHtmlBuilder sb) {
    // selects the image according to the status
    ImageResource ir = null;
    if (status.equalsIgnoreCase("VALID")) {
        ir = VALID;
    } else if (status.equalsIgnoreCase("INVALID")) {
        ir = INVALID;
    } else if (status.equalsIgnoreCase("SUSPENDED")) {
        ir = SUSPENDED;
    } else if (status.equalsIgnoreCase("EXPIRED")) {
        ir = EXPIRED;
    } else if (status.equalsIgnoreCase("DISABLED")) {
        ir = DISABLED;
    }
    // if status not available
    if (ir == null) {
        return;
    }
    // append the image
    Element imageElement = new Image(ir).getElement();
    imageElement.setTitle(status);
    SafeHtml image = SafeHtmlUtils.fromSafeConstant((imageElement.getString()));
    sb.appendHtmlConstant("<div class=\"" + "customClickableTextCell" + "\">");
    sb.append(image);
    sb.appendHtmlConstant("</div>");
}
Also used : ImageResource(com.google.gwt.resources.client.ImageResource) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Element(com.google.gwt.dom.client.Element) Image(com.google.gwt.user.client.ui.Image)

Example 14 with Image

use of com.google.gwt.user.client.ui.Image in project perun by CESNET.

the class HandleApplication method approveApplication.

/**
	 * Approve application
	 *
	 * @param app
	 */
public void approveApplication(final Application app) {
    this.appId = app.getId();
    // test arguments
    if (!this.testApplication()) {
        return;
    }
    // new events
    final JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        @Override
        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Approving application failed.");
            events.onError(error);
        }

        @Override
        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Application approved.");
            events.onFinished(jso);
        }

        @Override
        public void onLoadingStart() {
            events.onLoadingStart();
        }
    };
    final JSONObject appIdObj = new JSONObject();
    appIdObj.put("appId", new JSONNumber(appId));
    final JSONObject idObj = new JSONObject();
    idObj.put("id", new JSONNumber(appId));
    // check if can be approved
    JsonPostClient jspc = new JsonPostClient(new JsonCallbackEvents() {

        @Override
        public void onError(final PerunError error) {
            session.getUiElements().setLogErrorText("Checking approval failed.");
            events.onError(error);
            if (error == null) {
                PerunError e = (PerunError) JsonUtils.parseJson("{\"errorId\":\"0\",\"name\":\"Cross-site request\",\"type\":\"" + WidgetTranslation.INSTANCE.jsonClientAlertBoxErrorCrossSiteType() + "\",\"message\":\"" + WidgetTranslation.INSTANCE.jsonClientAlertBoxErrorCrossSiteText() + "\"}").cast();
                JsonErrorHandler.alertBox(e);
            } else if (!error.getName().equals("CantBeApprovedException")) {
                JsonErrorHandler.alertBox(error);
            } else {
                FlexTable layout = new FlexTable();
                layout.setWidget(0, 0, new HTML("<p>" + new Image(LargeIcons.INSTANCE.errorIcon())));
                if ("NOT_ACADEMIC".equals(error.getReason())) {
                    layout.setHTML(0, 1, "<p>User is not active academia member and application shouldn't be approved.<p><b>LoA:</b> " + app.getExtSourceLoa() + "</br><b>IdP category:</b> " + (!(error.getCategory().equals("")) ? error.getCategory() : "N/A") + "</br><b>Affiliation:</b> " + (!(error.getAffiliation().equals("")) ? error.getAffiliation().replace(";", ", ") : "N/A") + ((error.isSoft()) ? "<p>You can try to override above restriction by clicking 'Approve anyway' button." : ""));
                } else {
                    layout.setHTML(0, 1, "<p>" + error.getErrorInfo() + ((error.isSoft()) ? "<p>You can try to override above restriction by clicking 'Approve anyway' button." : ""));
                }
                layout.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                layout.getFlexCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                layout.getFlexCellFormatter().setStyleName(0, 0, "alert-box-image");
                if (error.isSoft()) {
                    Confirm c = new Confirm("Application shouldn't be approved", layout, new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            // ok approve sending data
                            JsonPostClient jspc = new JsonPostClient(newEvents);
                            jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
                        }
                    }, new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            events.onFinished(null);
                        }
                    }, true);
                    c.setOkButtonText("Approve anyway");
                    c.setNonScrollable(true);
                    c.show();
                } else {
                    Confirm c = new Confirm("Application can't be approved", layout, true);
                    c.setNonScrollable(true);
                    c.show();
                }
            }
        }

        @Override
        public void onFinished(JavaScriptObject jso) {
            if (app.getUser() != null) {
                // ok approve sending data
                JsonPostClient jspc2 = new JsonPostClient(newEvents);
                jspc2.sendData(JSON_URL_APPROVE, prepareJSONObject());
            } else {
                JsonPostClient checkJspc = new JsonPostClient(new JsonCallbackEvents() {

                    @Override
                    public void onError(PerunError error) {
                        session.getUiElements().setLogErrorText("Approving application failed.");
                        events.onError(error);
                    }

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        ArrayList<Identity> users = JsonUtils.jsoAsList(jso);
                        if (users != null && !users.isEmpty()) {
                            FlexTable ft = new FlexTable();
                            ft.setWidth("600px");
                            ft.setHTML(0, 0, "<p><strong>Following similar user(s) were found in system:");
                            ft.getFlexCellFormatter().setColSpan(0, 0, 3);
                            ft.setHTML(1, 0, "<strong>" + ApplicationMessages.INSTANCE.name() + "</strong>");
                            ft.setHTML(1, 1, "<strong>" + ApplicationMessages.INSTANCE.email() + "</strong>");
                            ft.setHTML(1, 2, "<strong>" + ApplicationMessages.INSTANCE.organization() + "</strong>");
                            int i = 2;
                            for (Identity user : users) {
                                ft.setHTML(i, 0, user.getName());
                                if (user.getEmail() != null && !user.getEmail().isEmpty()) {
                                    ft.setHTML(i, 1, user.getEmail());
                                } else {
                                    ft.setHTML(i, 1, "N/A");
                                }
                                if (user.getOrganization() != null && !user.getOrganization().isEmpty()) {
                                    ft.setHTML(i, 2, user.getOrganization());
                                } else {
                                    ft.setHTML(i, 2, "N/A");
                                }
                                i++;
                            }
                            String type = "";
                            if (app.getExtSourceType().equals("cz.metacentrum.perun.core.impl.ExtSourceX509")) {
                                type = "cert";
                            } else if (app.getExtSourceType().equals("cz.metacentrum.perun.core.impl.ExtSourceIdp")) {
                                type = "fed";
                            }
                            ft.setHTML(i, 0, "<p>Please contact new applicant with question, if he/she isn't already member of any other VO." + "<ul><li>If YES, ask him/her to join identities at <a href=\"" + Utils.getIdentityConsolidatorLink(type, false) + "\" target=\"_blank\">identity consolidator</a> before approving this application." + "</li><li>If NO, you can approve this application anyway. " + "</li><li>If UNSURE, contact <a href=\"mailto:" + Utils.perunReportEmailAddress() + "\">support</a> to help you.</li></ul>");
                            ft.getFlexCellFormatter().setColSpan(i, 0, 3);
                            i++;
                            ft.setHTML(i, 0, "<strong>Do you wish to approve this application anyway ?</strong>");
                            ft.getFlexCellFormatter().setColSpan(i, 0, 3);
                            Confirm c = new Confirm("Similar users found!", ft, new ClickHandler() {

                                @Override
                                public void onClick(ClickEvent clickEvent) {
                                    // ok approve sending data
                                    JsonPostClient jspc = new JsonPostClient(newEvents);
                                    jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
                                }
                            }, new ClickHandler() {

                                @Override
                                public void onClick(ClickEvent clickEvent) {
                                    events.onFinished(null);
                                }
                            }, true);
                            c.setOkButtonText("Approve");
                            c.setNonScrollable(true);
                            c.show();
                        } else {
                            // ok approve sending data
                            JsonPostClient jspc = new JsonPostClient(newEvents);
                            jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
                        }
                    }

                    @Override
                    public void onLoadingStart() {
                        events.onLoadingStart();
                    }
                });
                checkJspc.sendData("registrarManager/checkForSimilarUsers", appIdObj);
            }
        }

        @Override
        public void onLoadingStart() {
            events.onLoadingStart();
        }
    });
    // we have own error handling
    jspc.setHidden(true);
    jspc.sendData(JSON_URL_CHECK, idObj);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FlexTable(com.google.gwt.user.client.ui.FlexTable) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) JSONString(com.google.gwt.json.client.JSONString) Image(com.google.gwt.user.client.ui.Image) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JSONNumber(com.google.gwt.json.client.JSONNumber) PerunError(cz.metacentrum.perun.webgui.model.PerunError) Identity(cz.metacentrum.perun.webgui.model.Identity)

Example 15 with Image

use of com.google.gwt.user.client.ui.Image in project gerrit by GerritCodeReview.

the class ChangeScreen method renderPushCertificate.

private void renderPushCertificate(RevisionInfo revInfo, FlowPanel panel) {
    if (!enableSignedPush()) {
        return;
    }
    Image status = new Image();
    panel.add(status);
    status.setStyleName(style.pushCertStatus());
    if (!revInfo.hasPushCertificate() || revInfo.pushCertificate().key() == null) {
        status.setResource(Gerrit.RESOURCES.question());
        status.setTitle(Util.C.pushCertMissing());
        return;
    }
    PushCertificateInfo certInfo = revInfo.pushCertificate();
    GpgKeyInfo.Status s = certInfo.key().status();
    switch(s) {
        case BAD:
            status.setResource(Gerrit.RESOURCES.redNot());
            status.setTitle(problems(Util.C.pushCertBad(), certInfo));
            break;
        case OK:
            status.setResource(Gerrit.RESOURCES.warning());
            status.setTitle(problems(Util.C.pushCertOk(), certInfo));
            break;
        case TRUSTED:
            status.setResource(Gerrit.RESOURCES.greenCheck());
            status.setTitle(Util.C.pushCertTrusted());
            break;
    }
}
Also used : Image(com.google.gwt.user.client.ui.Image) AvatarImage(com.google.gerrit.client.AvatarImage) PushCertificateInfo(com.google.gerrit.client.info.PushCertificateInfo) GpgKeyInfo(com.google.gerrit.client.info.GpgKeyInfo)

Aggregations

Image (com.google.gwt.user.client.ui.Image)52 Test (org.junit.Test)13 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)9 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)9 Element (com.google.gwt.dom.client.Element)8 Label (com.google.gwt.user.client.ui.Label)8 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)7 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)7 ImageResource (com.google.gwt.resources.client.ImageResource)6 FlexTable (com.google.gwt.user.client.ui.FlexTable)5 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)5 HTML (com.google.gwt.user.client.ui.HTML)5 Style (com.google.gwt.dom.client.Style)4 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)4 Anchor (com.google.gwt.user.client.ui.Anchor)4 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)4 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)3 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)3 HighlightingInlineHyperlink (com.google.gerrit.client.ui.HighlightingInlineHyperlink)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2