Skip to content

Commit

Permalink
#4672 Add context menus to table cells to copy values
Browse files Browse the repository at this point in the history
  • Loading branch information
stroomdev66 committed Dec 19, 2024
1 parent b0eb21e commit 62a212c
Show file tree
Hide file tree
Showing 50 changed files with 661 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
import stroom.dispatch.client.RestFactory;
import stroom.docref.DocRef;
import stroom.docstore.shared.DocRefUtil;
import stroom.document.client.ClientDocumentType;
import stroom.document.client.ClientDocumentTypeRegistry;
import stroom.document.client.DocumentPlugin;
import stroom.document.client.DocumentPluginEventManager;
import stroom.entity.client.presenter.DocumentEditPresenter;
import stroom.explorer.shared.DocumentTypeGroup;
import stroom.security.client.api.ClientSecurityContext;
import stroom.svg.shared.SvgImage;
import stroom.task.client.TaskMonitorFactory;

import com.google.gwt.core.client.GWT;
Expand All @@ -43,6 +47,11 @@
public class AnalyticsPlugin extends DocumentPlugin<AnalyticRuleDoc> {

private static final AnalyticRuleResource ANALYTIC_RULE_RESOURCE = GWT.create(AnalyticRuleResource.class);
public static final ClientDocumentType DOCUMENT_TYPE = new ClientDocumentType(
DocumentTypeGroup.SEARCH,
AnalyticRuleDoc.DOCUMENT_TYPE,
"Analytic Rule",
SvgImage.DOCUMENT_ANALYTIC_RULE);

private final Provider<AnalyticRulePresenter> editorProvider;
private final RestFactory restFactory;
Expand All @@ -57,6 +66,8 @@ public AnalyticsPlugin(final EventBus eventBus,
super(eventBus, contentManager, entityPluginEventManager, securityContext);
this.editorProvider = editorProvider;
this.restFactory = restFactory;

ClientDocumentTypeRegistry.put(DOCUMENT_TYPE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public LinkedEventPresenter(final EventBus eventBus,
view.setDataView(dataPresenter.getView());

dataGrid.addAutoResizableColumn(
DataGridUtil.copyTextColumnBuilder(EventId::toString)
DataGridUtil.copyTextColumnBuilder(EventId::toString, getEventBus())
.build(),
"Id",
ColumnSizeConstants.MEDIUM_COL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
import stroom.dispatch.client.RestFactory;
import stroom.docref.DocRef;
import stroom.docstore.shared.DocRefUtil;
import stroom.document.client.ClientDocumentType;
import stroom.document.client.ClientDocumentTypeRegistry;
import stroom.document.client.DocumentPlugin;
import stroom.document.client.DocumentPluginEventManager;
import stroom.entity.client.presenter.DocumentEditPresenter;
import stroom.explorer.shared.DocumentTypeGroup;
import stroom.security.client.api.ClientSecurityContext;
import stroom.svg.shared.SvgImage;
import stroom.task.client.TaskMonitorFactory;

import com.google.gwt.core.client.GWT;
Expand All @@ -43,6 +47,11 @@
public class S3ConfigPlugin extends DocumentPlugin<S3ConfigDoc> {

private static final S3ConfigResource S3_CONFIG_RESOURCE = GWT.create(S3ConfigResource.class);
public static final ClientDocumentType DOCUMENT_TYPE = new ClientDocumentType(
DocumentTypeGroup.CONFIGURATION,
S3ConfigDoc.DOCUMENT_TYPE,
"S3 Configuration",
SvgImage.DOCUMENT_S3);
private final Provider<S3ConfigPresenter> editorProvider;

private final RestFactory restFactory;
Expand All @@ -57,6 +66,8 @@ public S3ConfigPlugin(final EventBus eventBus,
super(eventBus, contentManager, entityPluginEventManager, securityContext);
this.editorProvider = editorProvider;
this.restFactory = restFactory;

ClientDocumentTypeRegistry.put(DOCUMENT_TYPE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@
import stroom.dispatch.client.RestFactory;
import stroom.docref.DocRef;
import stroom.docstore.shared.DocRefUtil;
import stroom.document.client.ClientDocumentType;
import stroom.document.client.ClientDocumentTypeRegistry;
import stroom.document.client.DocumentPlugin;
import stroom.document.client.DocumentPluginEventManager;
import stroom.document.client.event.OpenDocumentEvent.CommonDocLinkTab;
import stroom.entity.client.presenter.DocumentEditPresenter;
import stroom.explorer.shared.DocumentTypeGroup;
import stroom.hyperlink.client.ShowDashboardEvent;
import stroom.query.api.v2.ResultStoreInfo;
import stroom.query.api.v2.SearchRequestSource;
import stroom.query.api.v2.SearchRequestSource.SourceType;
import stroom.security.client.api.ClientSecurityContext;
import stroom.svg.shared.SvgImage;
import stroom.task.client.DefaultTaskMonitorFactory;
import stroom.task.client.TaskMonitorFactory;

Expand All @@ -56,6 +60,11 @@
public class DashboardPlugin extends DocumentPlugin<DashboardDoc> {

private static final DashboardResource DASHBOARD_RESOURCE = GWT.create(DashboardResource.class);
public static final ClientDocumentType DOCUMENT_TYPE = new ClientDocumentType(
DocumentTypeGroup.SEARCH,
DashboardDoc.DOCUMENT_TYPE,
DashboardDoc.DOCUMENT_TYPE,
SvgImage.DOCUMENT_DASHBOARD);

private final Provider<DashboardSuperPresenter> dashboardSuperPresenterProvider;
private final RestFactory restFactory;
Expand All @@ -72,6 +81,8 @@ public DashboardPlugin(final EventBus eventBus,
this.dashboardSuperPresenterProvider = dashboardSuperPresenterProvider;
this.restFactory = restFactory;

ClientDocumentTypeRegistry.put(DOCUMENT_TYPE);

registerHandler(eventBus.addHandler(ShowDashboardEvent.getType(),
event -> openParameterisedDashboard(event.getHref())));
registerHandler(eventBus.addHandler(ReopenResultStoreEvent.getType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ protected ResultPage<MetaRow> onProcessData(final ResultPage<MetaRow> data) {
return data;
}

protected abstract void addColumns(boolean allowSelectAll);
protected abstract void addColumns(final boolean allowSelectAll);

private void setMatchAll(final boolean select) {
selection.clear();
Expand Down Expand Up @@ -341,7 +341,8 @@ void addInfoColumn() {
void addCreatedColumn() {
dataGrid.addResizableColumn(
DataGridUtil.copyTextColumnBuilder((MetaRow metaRow) ->
dateTimeFormatter.format(metaRow.getMeta().getCreateMs()))
dateTimeFormatter.format(metaRow.getMeta().getCreateMs()),
getEventBus())
.withSorting(MetaFields.CREATE_TIME)
.build(),
"Created",
Expand Down Expand Up @@ -387,11 +388,8 @@ private DocRef getFeed(final MetaRow metaRow) {

private DocRef getPipeline(final MetaRow metaRow) {
if (metaRow.getMeta().getProcessorUuid() != null) {
if (metaRow.getPipelineName() != null) {
return new DocRef(
PipelineDoc.DOCUMENT_TYPE,
metaRow.getMeta().getPipelineUuid(),
metaRow.getPipelineName());
if (metaRow.getPipeline() != null) {
return metaRow.getPipeline();
} else {
return new DocRef(null, null, null);
}
Expand All @@ -405,7 +403,8 @@ void addPipelineColumn() {
Optional.ofNullable(metaRow)
.map(this::getPipeline)
.orElse(null),
getEventBus(), false)
getEventBus(),
false)
.withSorting(MetaFields.PIPELINE_NAME)
.build(),
"Pipeline",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
package stroom.data.client.presenter;

import stroom.data.grid.client.EventCell;
import stroom.svg.shared.SvgImage;
import stroom.util.client.ClipboardUtil;
import stroom.util.shared.GwtNullSafe;
import stroom.widget.menu.client.presenter.IconMenuItem;
import stroom.widget.menu.client.presenter.Item;
import stroom.widget.menu.client.presenter.ShowMenuEvent;
import stroom.widget.popup.client.presenter.PopupPosition;
import stroom.widget.util.client.ElementUtil;
import stroom.widget.util.client.MouseUtil;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HasHandlers;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.view.client.CellPreviewEvent;
import com.google.web.bindery.event.shared.EventBus;

import java.util.ArrayList;
import java.util.List;

import static com.google.gwt.dom.client.BrowserEvents.MOUSEDOWN;

public class CopyTextCell extends AbstractCell<String> implements EventCell {
public class CopyTextCell extends AbstractCell<String> implements HasHandlers, EventCell {

private final EventBus eventBus;

public CopyTextCell() {
public CopyTextCell(final EventBus eventBus) {
super(MOUSEDOWN);
this.eventBus = eventBus;
}

@Override
Expand All @@ -38,11 +52,31 @@ public void onBrowserEvent(final Context context,
final NativeEvent event,
final ValueUpdater<String> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);
if (MOUSEDOWN.equals(event.getType()) && MouseUtil.isPrimary(event)) {
onEnterKeyDown(context, parent, value, event, valueUpdater);
if (MOUSEDOWN.equals(event.getType())) {
if (MouseUtil.isPrimary(event)) {
onEnterKeyDown(context, parent, value, event, valueUpdater);
} else if (GwtNullSafe.isNonBlankString(value)) {
final List<Item> menuItems = new ArrayList<>();
menuItems.add(new IconMenuItem.Builder()
.priority(1)
.icon(SvgImage.COPY)
.text("Copy")
.command(() -> ClipboardUtil.copy(value))
.build());
ShowMenuEvent
.builder()
.items(menuItems)
.popupPosition(new PopupPosition(event.getClientX(), event.getClientY()))
.fire(this);
}
}
}

@Override
public void fireEvent(final GwtEvent<?> gwtEvent) {
eventBus.fireEvent(gwtEvent);
}

@Override
protected void onEnterKeyDown(final Context context,
final Element parent,
Expand Down
Loading

0 comments on commit 62a212c

Please sign in to comment.