Search in sources :

Example 11 with JsArray

use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.

the class JsArrayUtil method deepCopy.

@SuppressWarnings("unchecked")
public static final <T extends JavaScriptObject> JsArray<T> deepCopy(JsArray<T> array) {
    JsObject original = (JsObject) array.cast();
    JsObject clone = original.clone();
    JsArray<T> cloneArray = (JsArray<T>) clone.cast();
    return cloneArray;
}
Also used : JsObject(org.rstudio.core.client.js.JsObject) JsArray(com.google.gwt.core.client.JsArray)

Example 12 with JsArray

use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.

the class GeneralPreferencesPane method initialize.

@Override
protected void initialize(RPrefs rPrefs) {
    // general prefs
    final GeneralPrefs generalPrefs = rPrefs.getGeneralPrefs();
    showServerHomePage_.setEnabled(true);
    reuseSessionsForProjectLinks_.setEnabled(true);
    saveWorkspace_.setEnabled(true);
    loadRData_.setEnabled(true);
    dirChooser_.setEnabled(true);
    showServerHomePage_.setValue(generalPrefs.getShowUserHomePage());
    reuseSessionsForProjectLinks_.setValue(generalPrefs.getReuseSessionsForProjectLinks());
    int saveWorkspaceIndex;
    switch(generalPrefs.getSaveAction()) {
        case SaveAction.NOSAVE:
            saveWorkspaceIndex = 1;
            break;
        case SaveAction.SAVE:
            saveWorkspaceIndex = 0;
            break;
        case SaveAction.SAVEASK:
        default:
            saveWorkspaceIndex = 2;
            break;
    }
    saveWorkspace_.getListBox().setSelectedIndex(saveWorkspaceIndex);
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            server_.getTerminalShells(new ServerRequestCallback<JsArray<TerminalShellInfo>>() {

                @Override
                public void onResponseReceived(JsArray<TerminalShellInfo> shells) {
                    int currentShell = generalPrefs.getDefaultTerminalShellValue();
                    int currentShellIndex = 0;
                    GeneralPreferencesPane.this.terminalShell_.getListBox().clear();
                    for (int i = 0; i < shells.length(); i++) {
                        TerminalShellInfo info = shells.get(i);
                        GeneralPreferencesPane.this.terminalShell_.addChoice(info.getShellName(), Integer.toString(info.getShellType()));
                        if (info.getShellType() == currentShell)
                            currentShellIndex = i;
                    }
                    if (GeneralPreferencesPane.this.terminalShell_.getListBox().getItemCount() > 0) {
                        GeneralPreferencesPane.this.terminalShell_.setEnabled((true));
                        GeneralPreferencesPane.this.terminalShell_.getListBox().setSelectedIndex(currentShellIndex);
                    }
                }

                @Override
                public void onError(ServerError error) {
                }
            });
        }
    });
    loadRData_.setValue(generalPrefs.getLoadRData());
    dirChooser_.setText(generalPrefs.getInitialWorkingDirectory());
    // history prefs
    HistoryPrefs historyPrefs = rPrefs.getHistoryPrefs();
    alwaysSaveHistory_.setEnabled(true);
    removeHistoryDuplicates_.setEnabled(true);
    alwaysSaveHistory_.setValue(historyPrefs.getAlwaysSave());
    removeHistoryDuplicates_.setValue(historyPrefs.getRemoveDuplicates());
    rProfileOnResume_.setValue(generalPrefs.getRprofileOnResume());
    rProfileOnResume_.setEnabled(true);
    showLastDotValue_.setValue(generalPrefs.getShowLastDotValue());
    showLastDotValue_.setEnabled(true);
    if (rServerRVersion_ != null)
        rServerRVersion_.setRVersion(generalPrefs.getDefaultRVersion());
    if (rememberRVersionForProjects_ != null) {
        rememberRVersionForProjects_.setValue(generalPrefs.getRestoreProjectRVersion());
    }
    // projects prefs
    ProjectsPrefs projectsPrefs = rPrefs.getProjectsPrefs();
    restoreLastProject_.setEnabled(true);
    restoreLastProject_.setValue(projectsPrefs.getRestoreLastProject());
}
Also used : GeneralPrefs(org.rstudio.studio.client.workbench.prefs.model.GeneralPrefs) TerminalShellInfo(org.rstudio.studio.client.workbench.views.terminal.TerminalShellInfo) JsArray(com.google.gwt.core.client.JsArray) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ServerError(org.rstudio.studio.client.server.ServerError) ProjectsPrefs(org.rstudio.studio.client.workbench.prefs.model.ProjectsPrefs) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) HistoryPrefs(org.rstudio.studio.client.workbench.prefs.model.HistoryPrefs)

Example 13 with JsArray

use of com.google.gwt.core.client.JsArray in project opennms by OpenNMS.

the class MarqueeSelectHandler method selectVertices.

private void selectVertices() {
    // We use the svgIconOverlay to determine the selection and ignore the status border, the label
    // and possible invisible elements, such as status badge, navigate to target etc, as the vertex is
    // slightly greater than the svgIconOverlay and the user probably uses the icon itself to make the selection.
    D3 iconOverlay = m_svgTopologyMap.selectAllVertexElements().select(".svgIconOverlay");
    JsArray<JsArray<SVGElement>> selection = iconOverlay.cast();
    final JsArray<SVGElement> elemArray = selection.get(0);
    iconOverlay.each(new Handler<GWTVertex>() {

        @Override
        public void call(GWTVertex vertex, int index) {
            SVGElement elem = elemArray.get(index).cast();
            boolean selected = inSelection(elem);
            vertex.setSelected(selected);
        }
    });
}
Also used : JsArray(com.google.gwt.core.client.JsArray) SVGElement(org.opennms.features.topology.app.internal.gwt.client.svg.SVGElement) GWTVertex(org.opennms.features.topology.app.internal.gwt.client.GWTVertex) D3(org.opennms.features.topology.app.internal.gwt.client.d3.D3)

Example 14 with JsArray

use of com.google.gwt.core.client.JsArray in project perun by CESNET.

the class AssignServiceTabItem method draw.

public Widget draw() {
    titleWidget.setText("Assign service");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    final GetServices services = new GetServices();
    final CellTable<Service> table = services.getEmptyTable(new FieldUpdater<Service, String>() {

        public void update(int index, Service object, String value) {
            session.getTabManager().addTab(new ResourceSettingsTabItem(resource, object));
        }
    });
    // remove already assigned services from offering
    JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            // second callback
            final GetAssignedServices alreadyAssigned = new GetAssignedServices(resourceId, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    JsArray<Service> srvToRemove = JsonUtils.jsoAsArray(jso);
                    for (int i = 0; i < srvToRemove.length(); i++) {
                        services.removeFromTable(srvToRemove.get(i));
                    }
                    if (services.getList().size() == 1) {
                        table.getSelectionModel().setSelected(services.getList().get(0), true);
                    }
                }
            });
            alreadyAssigned.retrieveData();
        }
    };
    services.setEvents(localEvents);
    final TabItem tab = this;
    // button
    final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.assignSelectedServicesToResource());
    assignButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Service> servicesToAssign = services.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(servicesToAssign)) {
                for (int i = 0; i < servicesToAssign.size(); i++) {
                    if (i != servicesToAssign.size() - 1) {
                        // call json normaly
                        AssignService request = new AssignService(JsonCallbackEvents.disableButtonEvents(assignButton));
                        request.assignService(servicesToAssign.get(i).getId(), resourceId);
                    } else {
                        // last change - call json with update
                        AssignService request = new AssignService(JsonCallbackEvents.closeTabDisableButtonEvents(assignButton, tab));
                        request.assignService(servicesToAssign.get(i).getId(), resourceId);
                    }
                }
            }
        }
    });
    menu.addWidget(assignButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    menu.addFilterWidget(new ExtendedSuggestBox(services.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            services.filterTable(text);
            if (services.getList().size() == 1) {
                table.getSelectionModel().setSelected(services.getList().get(0), true);
            }
        }
    }, "Filter services by name");
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    services.retrieveData();
    assignButton.setEnabled(false);
    JsonUtils.addTableManagedButton(services, table, assignButton);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JsArray(com.google.gwt.core.client.JsArray) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.webgui.model.Service) AssignService(cz.metacentrum.perun.webgui.json.resourcesManager.AssignService) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) 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) AssignService(cz.metacentrum.perun.webgui.json.resourcesManager.AssignService) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)

Example 15 with JsArray

use of com.google.gwt.core.client.JsArray in project perun by CESNET.

the class FindSimilarPublications method getEmptyTable.

/**
	 * Returns table of users publications
	 * @return table
	 */
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 similar publications found.");
    // show checkbox column
    if (this.checkable) {
        // checkbox column column
        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");
    // 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)

Aggregations

JsArray (com.google.gwt.core.client.JsArray)39 ArrayList (java.util.ArrayList)14 ServerError (org.rstudio.studio.client.server.ServerError)12 JsArrayString (com.google.gwt.core.client.JsArrayString)7 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)6 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)6 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)6 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)5 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)4 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)4 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)4 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)4 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)4 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)4 HTML (com.google.gwt.user.client.ui.HTML)3 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)3 CommentInfo (com.google.gerrit.client.changes.CommentInfo)2 CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)2 NativeString (com.google.gerrit.client.rpc.NativeString)2 Context (com.google.gwt.cell.client.Cell.Context)2