Search in sources :

Example 1 with ConnectionAction

use of org.rstudio.studio.client.workbench.views.connections.model.ConnectionAction in project rstudio by rstudio.

the class ConnectionsPane method installConnectionExplorerToolbar.

private void installConnectionExplorerToolbar(final Connection connection) {
    toolbar_.removeAllWidgets();
    toolbar_.addLeftWidget(backToConnectionsButton_);
    toolbar_.addLeftSeparator();
    toolbar_.addLeftWidget(connectMenuButton_);
    toolbar_.addLeftSeparator();
    if (isConnected(connection.getId()) && connection.getActions() != null) {
        // if we have any actions, create a toolbar button for each one
        for (int i = 0; i < connection.getActions().length(); i++) {
            final ConnectionAction action = connection.getActions().get(i);
            // use the supplied base64 icon data if it was provided
            Image icon = StringUtil.isNullOrEmpty(action.getIconData()) ? null : new Image(action.getIconData());
            // force to 20x18
            if (icon != null) {
                icon.setWidth("20px");
                icon.setHeight("18px");
            }
            ToolbarButton button = new ToolbarButton(action.getName(), // left image
            icon, // right image
            null, // invoke the action when the button is clicked
            new ClickHandler() {

                @Override
                public void onClick(ClickEvent arg0) {
                    fireEvent(new ExecuteConnectionActionEvent(connection.getId(), action.getName()));
                }
            });
            // none was supplied
            if (StringUtil.isNullOrEmpty(action.getIconData()))
                button.getElement().getStyle().setMarginTop(-5, Unit.PX);
            toolbar_.addLeftWidget(button);
            toolbar_.addLeftSeparator();
        }
    }
    toolbar_.addLeftWidget(commands_.disconnectConnection().createToolbarButton());
    toolbar_.addRightWidget(commands_.removeConnection().createToolbarButton());
    toolbar_.addRightWidget(commands_.refreshConnection().createToolbarButton());
    connectionName_.setText(connection.getDisplayName());
    setSecondaryToolbarVisible(true);
}
Also used : ToolbarButton(org.rstudio.core.client.widget.ToolbarButton) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExecuteConnectionActionEvent(org.rstudio.studio.client.workbench.views.connections.events.ExecuteConnectionActionEvent) ConnectionAction(org.rstudio.studio.client.workbench.views.connections.model.ConnectionAction) Image(com.google.gwt.user.client.ui.Image)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Image (com.google.gwt.user.client.ui.Image)1 ToolbarButton (org.rstudio.core.client.widget.ToolbarButton)1 ExecuteConnectionActionEvent (org.rstudio.studio.client.workbench.views.connections.events.ExecuteConnectionActionEvent)1 ConnectionAction (org.rstudio.studio.client.workbench.views.connections.model.ConnectionAction)1