Search in sources :

Example 31 with ImageResource

use of com.google.gwt.resources.client.ImageResource in project perun by CESNET.

the class WhetherEnabledCell method render.

@Override
public void render(com.google.gwt.cell.client.Cell.Context context, Boolean enabled, SafeHtmlBuilder sb) {
    // selects the image according to the status
    ImageResource ir = null;
    if (enabled) {
        ir = ENABLED;
    } else {
        ir = DISABLED;
    }
    // if status not available
    if (ir == null) {
        return;
    }
    // append the image
    Element imageElement = new Image(ir).getElement();
    imageElement.setTitle(String.valueOf(enabled));
    SafeHtml image = SafeHtmlUtils.fromSafeConstant((imageElement.getString()));
    sb.append(image);
}
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 32 with ImageResource

use of com.google.gwt.resources.client.ImageResource in project perun by CESNET.

the class FindPublicationsByGUIFilter method getEmptyTable.

/**
	 * Returns table of users publications
	 * @return
	 */
public CellTable<Publication> getEmptyTable() {
    // Table data provider.
    dataProvider = new ListDataProvider<Publication>(list);
    // Cell table
    table = new PerunTable<Publication>(list);
    // display row-count for perun admin only
    if (!session.isPerunAdmin()) {
        table.removeRowCountChangeHandler();
    }
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<Publication> columnSortHandler = new ListHandler<Publication>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Publication>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("No publications found. Try to change filtering options.");
    // show checkbox column
    if (this.checkable) {
        table.addCheckBoxColumn();
    }
    // ID COLUMN
    table.addIdColumn("Publication ID", tableFieldUpdater, 60);
    Column<Publication, ImageResource> lockedColumn = new Column<Publication, ImageResource>(new CustomImageResourceCell("click")) {

        public ImageResource getValue(Publication object) {
            if (object.getLocked() == true) {
                return SmallIcons.INSTANCE.lockIcon();
            } else {
                return SmallIcons.INSTANCE.lockOpenIcon();
            }
        }

        public void onBrowserEvent(final Context context, final Element elem, final Publication object, NativeEvent event) {
            // on click and for perun admin
            if ("click".equals(event.getType()) && session.isPerunAdmin()) {
                final ImageResource value;
                if (object.getLocked() == true) {
                    value = SmallIcons.INSTANCE.lockOpenIcon();
                    object.setLocked(false);
                } else {
                    value = SmallIcons.INSTANCE.lockIcon();
                    object.setLocked(true);
                }
                LockUnlockPublications request = new LockUnlockPublications(new JsonCallbackEvents() {

                    @Override
                    public void onLoadingStart() {
                        getCell().setValue(context, elem, SmallIcons.INSTANCE.updateIcon());
                    }

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // change picture (object already changed)
                        getCell().setValue(context, elem, value);
                    }

                    @Override
                    public void onError(PerunError error) {
                        // on error switch object back
                        if (object.getLocked() == true) {
                            object.setLocked(false);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockOpenIcon());
                        } else {
                            object.setLocked(true);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockIcon());
                        }
                    }
                });
                // send request
                ArrayList<Publication> list = new ArrayList<Publication>();
                list.add(object);
                request.lockUnlockPublications(object.getLocked(), list);
            }
        }
    };
    table.addColumn(lockedColumn, "Lock");
    // TITLE COLUMN
    Column<Publication, String> titleColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getTitle();
        }
    }, this.tableFieldUpdater);
    titleColumn.setSortable(true);
    columnSortHandler.setComparator(titleColumn, new PublicationComparator(PublicationComparator.Column.TITLE));
    table.addColumn(titleColumn, "Title");
    // if display authors
    if (ids.containsKey("authors")) {
        if ((Integer) ids.get("authors") == 1) {
            // AUTHORS COLUMN
            Column<Publication, String> authorColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

                public String getValue(Publication object) {
                    return object.getAuthorsFormatted();
                }
            }, this.tableFieldUpdater);
            authorColumn.setSortable(true);
            columnSortHandler.setComparator(authorColumn, new PublicationComparator(PublicationComparator.Column.AUTHORS));
            table.addColumn(authorColumn, "Reported by");
        }
    }
    // YEAR COLUMN
    Column<Publication, String> yearColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return String.valueOf(object.getYear());
        }
    }, this.tableFieldUpdater);
    yearColumn.setSortable(true);
    columnSortHandler.setComparator(yearColumn, new PublicationComparator(PublicationComparator.Column.YEAR));
    table.addColumn(yearColumn, "Year");
    // CATEGORY COLUMN
    Column<Publication, String> categoryColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getCategoryName();
        }
    }, this.tableFieldUpdater);
    categoryColumn.setSortable(true);
    columnSortHandler.setComparator(categoryColumn, new PublicationComparator(PublicationComparator.Column.CATEGORY));
    table.addColumn(categoryColumn, "Category");
    // THANKS COLUMN
    Column<Publication, String> thanksColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            String result = "";
            JsArray<Thanks> thks = object.getThanks();
            for (int i = 0; i < thks.length(); i++) {
                result += thks.get(i).getOwnerName() + ", ";
            }
            if (result.length() >= 2) {
                result = result.substring(0, result.length() - 2);
            }
            return result;
        }
    }, this.tableFieldUpdater);
    thanksColumn.setSortable(true);
    columnSortHandler.setComparator(thanksColumn, new PublicationComparator(PublicationComparator.Column.THANKS));
    table.addColumn(thanksColumn, "Thanked to");
    /*
		 * HIDE ISBN COLUMN FOR NOW
		// ISBN COLUMN
		Column<Publication, String> isbnColumn = JsonUtils.addColumn(
		new CustomClickableTextCell(), "",
		new JsonUtils.GetValue<Publication, String>() {
		public String getValue(Publication object) {
		return object.getIsbn();
		}
		}, this.tableFieldUpdater);

		isbnColumn.setSortable(true);
		columnSortHandler.setComparator(isbnColumn, new PublicationComparator(PublicationComparator.Column.ISBN));
		table.addColumn(isbnColumn, "ISBN");
		*/
    // CITE COLUMN
    Column<Publication, String> citaceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return "Cite";
        }
    }, new FieldUpdater<Publication, String>() {

        public void update(int index, Publication object, String value) {
            SimplePanel sp = new SimplePanel();
            sp.add(new HTML(object.getMain()));
            Confirm cf = new Confirm("Cite publication", sp, true);
            cf.show();
        }

        ;
    });
    table.addColumn(citaceColumn, "Cite");
    return table;
}
Also used : PublicationComparator(cz.metacentrum.perun.webgui.json.comparators.PublicationComparator) Element(com.google.gwt.dom.client.Element) ArrayList(java.util.ArrayList) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) ImageResource(com.google.gwt.resources.client.ImageResource) Column(com.google.gwt.user.cellview.client.Column) Context(com.google.gwt.cell.client.Cell.Context) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) CustomImageResourceCell(cz.metacentrum.perun.webgui.widgets.cells.CustomImageResourceCell) JsArray(com.google.gwt.core.client.JsArray) Publication(cz.metacentrum.perun.webgui.model.Publication) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 33 with ImageResource

use of com.google.gwt.resources.client.ImageResource in project perun by CESNET.

the class TabManager method addTabWhenPrepared.

/**
	 * Adding a tab
	 * With this method, the authorization must be already granted
	 *
	 * @param tab
	 * @param open
	 * @return
	 */
private boolean addTabWhenPrepared(TabItem tab, boolean open) {
    // store place
    final Widget widget;
    ImageResource tabIcon;
    // overlay tab
    final SimplePanel overlayTab = new SimplePanel();
    overlayTab.addStyleName("tab-overlay");
    final AbsolutePanel overlayShield = new AbsolutePanel();
    overlayShield.addStyleName("tab-overlay-shield");
    overlayShield.add(overlayTab);
    overlayTab.getElement().getStyle().setLeft(5, Unit.PCT);
    // authorization when not already opened
    if (tab.isAuthorized() == true) {
        // widget itself
        widget = tab.getWidget();
        tabIcon = tab.getIcon();
        // load page content
        tab.draw();
    } else {
        widget = new NotAuthorizedWidget();
        tabIcon = SmallIcons.INSTANCE.errorIcon();
    }
    // panel with overlay and widget contents
    final AbsolutePanel ap = new AbsolutePanel();
    ap.add(widget, 5, 5);
    ap.add(overlayShield, 0, -2000);
    //overlayShield.getElement().getStyle().setLeft(5, Unit.PCT);
    // set sizes
    ap.setSize("100%", "100%");
    widget.setWidth("100%");
    // update overlay position
    UiElements.addResizeCommand(new Command() {

        @Override
        public void execute() {
            // empty
            if (overlayTab.getWidget() == null) {
                return;
            }
            int clientWidth = (Window.getClientWidth() > WebGui.MIN_CLIENT_WIDTH) ? Window.getClientWidth() : WebGui.MIN_CLIENT_WIDTH;
            // if small, then fixed size in the center
            if (!overlayTab.getStyleName().contains("tab-overlay-large")) {
                int overlayWidth = overlayTab.getElement().getOffsetWidth();
                // main menu width
                int left = (clientWidth - MainMenu.MENU_WIDTH - overlayWidth) / 2;
                overlayShield.setWidgetPosition(overlayTab, left, overlayShield.getWidgetTop(overlayTab));
                return;
            }
        }
    }, tab);
    // has a help widget?
    if (tab instanceof TabItemWithHelp) {
        helpCounter++;
        final String helpWrapperId = "helpWidgetWrapper-" + helpCounter;
        TabItemWithHelp tabWithHelp = (TabItemWithHelp) tab;
        final AbsolutePanel helpWidgetWrapper = new AbsolutePanel();
        ap.add(helpWidgetWrapper, 100000, 0);
        helpWidgetWrapper.addStyleName("helpWidgetWrapper");
        helpWidgetWrapper.addStyleName(helpWrapperId);
        // help widget
        //FlexTable helpWidget = new FlexTable();
        VerticalPanel helpWidget = new VerticalPanel();
        helpWidget.setWidth("100%");
        final ScrollPanel sp = new ScrollPanel(helpWidget);
        // header
        //Image img = new Image(LargeIcons.INSTANCE.helpIcon());
        //helpWidget.setWidget(0, 0, img);
        //helpWidget.getCellFormatter().setWidth(0, 0, "40px");
        HTML helpHeader = new HTML("<h3>Quick help</h3>");
        helpWidget.add(helpHeader);
        helpWidget.setCellHeight(helpHeader, "45px");
        // content
        //helpWidget.getFlexCellFormatter().setColSpan(1, 0, 2);
        //helpWidget.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP);
        helpWidget.add(tabWithHelp.getHelpWidget());
        final SimplePanel helpWidgetInnerWrapper = new SimplePanel(sp);
        helpWidgetInnerWrapper.setStyleName("helpWidget");
        helpWidgetWrapper.add(helpWidgetInnerWrapper, 0, 0);
        /*helpWidgetInnerWrapper.setSize("100%", "100%");*/
        // open help widget button
        PushButton helpWidgetButton = new PushButton(new Image(HELP_WIDGET_BUTTON_IMAGE));
        final SimplePanel helpWidgetButtonWrapper = new SimplePanel(helpWidgetButton);
        helpWidgetButton.setStyleName("helpWidgetButton");
        helpWidgetButton.setTitle("Open / close Quick help");
        helpWidgetWrapper.add(helpWidgetButtonWrapper, -30, 0);
        helpWidgetButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                toggleHelp(helpWrapperId);
            }
        });
        UiElements.addResizeCommand(new Command() {

            public void execute() {
                int helpWidgetWidth = 400;
                int clientWidth = (Window.getClientWidth() > WebGui.MIN_CLIENT_WIDTH) ? Window.getClientWidth() : WebGui.MIN_CLIENT_WIDTH;
                //int clientHeight = (Window.getClientHeight() > WebGui.MIN_CLIENT_HEIGHT) ?  Window.getClientHeight() : WebGui.MIN_CLIENT_HEIGHT;
                clientWidth -= MainMenu.MENU_WIDTH;
                int newLeft = clientWidth;
                if (isHelpOpened(helpWrapperId)) {
                    newLeft -= helpWidgetWidth;
                }
                // update widget position
                ap.setWidgetPosition(helpWidgetWrapper, newLeft, 0);
                session.getUiElements().resizeSmallTabPanel(sp, 200);
            // update button top position
            //helpWidgetWrapper.setWidgetPosition(helpWidgetButtonWrapper, helpWidgetWrapper.getWidgetLeft(helpWidgetButtonWrapper), (clientHeight - 200) / 2);
            }
        });
    }
    // add
    int tabId = session.getUiElements().contentAddTab(ap, tab.getTitle(), open, tabIcon);
    // add to current map
    this.tabs.put(tab, tabId);
    if (open) {
        activeTab = tab;
        // call the event
        if (tab.isAuthorized()) {
            tab.open();
        }
    // DO NOT CHANGE MENU, IT'S HANDLED BY TAB
    // ON IT'S OWN VIA tab.open()
    //session.getUiElements().getMenu().updateLinks();
    }
    tabOverlays.put(tabId, overlayShield);
    // refresh URL
    refreshUrl();
    return true;
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) NotAuthorizedWidget(cz.metacentrum.perun.webgui.widgets.NotAuthorizedWidget) NotAuthorizedWidget(cz.metacentrum.perun.webgui.widgets.NotAuthorizedWidget) ImageResource(com.google.gwt.resources.client.ImageResource) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Command(com.google.gwt.user.client.Command)

Example 34 with ImageResource

use of com.google.gwt.resources.client.ImageResource in project playn by threerings.

the class HtmlAssets method getImage.

protected HtmlImage getImage(String path, Scale scale) {
    String url = pathPrefix + path;
    AutoClientBundleWithLookup clientBundle = getBundle(path);
    if (clientBundle != null) {
        String key = getKey(path);
        ImageResource resource = (ImageResource) getResource(key, clientBundle);
        if (resource != null) {
            url = resource.getSafeUri().asString();
        }
    }
    return adaptImage(url, scale);
}
Also used : ImageResource(com.google.gwt.resources.client.ImageResource) AutoClientBundleWithLookup(playn.core.AutoClientBundleWithLookup)

Aggregations

ImageResource (com.google.gwt.resources.client.ImageResource)34 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)9 Element (com.google.gwt.dom.client.Element)6 Image (com.google.gwt.user.client.ui.Image)6 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)5 Column (com.google.gwt.user.cellview.client.Column)5 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 Test (org.junit.Test)4 ImageResourceCell (com.google.gwt.cell.client.ImageResourceCell)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 GwtTestTest (com.googlecode.gwt.test.GwtTestTest)3 ArrayList (java.util.ArrayList)3 Context (com.google.gwt.cell.client.Cell.Context)2 JsArray (com.google.gwt.core.client.JsArray)2 JsArrayString (com.google.gwt.core.client.JsArrayString)2 NativeEvent (com.google.gwt.dom.client.NativeEvent)2 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)2 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)2 HTML (com.google.gwt.user.client.ui.HTML)2