Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Honnen2018-12-18 15:46:49 +0000
committerJulian Honnen2019-01-14 14:03:22 +0000
commit8db6fd7c71ead14224786ad67e51bf872072fedc (patch)
treed419b7e31185ffccc95b77640e3ba6fd08f2028c
parent1506218ec11cb03c801cdea642435ecf59d4797b (diff)
downloadeclipse.platform.ui-8db6fd7c71ead14224786ad67e51bf872072fedc.tar.gz
eclipse.platform.ui-8db6fd7c71ead14224786ad67e51bf872072fedc.tar.xz
eclipse.platform.ui-8db6fd7c71ead14224786ad67e51bf872072fedc.zip
Bug 537944 - Copy to clipboard for InstallationPagesI20190114-1800
Added a copy action for Features & Plug-ins tabs in Installation Details dialog. Change-Id: I8fc56bfd75fefcd559198f279de877c16c1b1e3d Signed-off-by: Julian Honnen <julian.honnen@vector.com>
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/AboutFeaturesPage.java2
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/AboutPluginsPage.java2
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/CopyTableSelectionHandler.java67
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/ProductInfoPage.java52
4 files changed, 123 insertions, 0 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/AboutFeaturesPage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/AboutFeaturesPage.java
index 9639cc38614..23411bc8a86 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/AboutFeaturesPage.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/AboutFeaturesPage.java
@@ -312,6 +312,8 @@ public class AboutFeaturesPage extends ProductInfoPage {
table.setSelection(sel);
table.showSelection();
}
+
+ addCopySupport(table);
}
private void disposeImages() {
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/AboutPluginsPage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/AboutPluginsPage.java
index 540c4a5da14..6136b51759a 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/AboutPluginsPage.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/AboutPluginsPage.java
@@ -421,6 +421,8 @@ public class AboutPluginsPage extends ProductInfoPage {
vendorInfo.setInput(bundleData);
}
}, parent.getDisplay());
+
+ addCopySupport(vendorInfo.getTable());
}
/**
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/CopyTableSelectionHandler.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/CopyTableSelectionHandler.java
new file mode 100644
index 00000000000..6f5a2101c1a
--- /dev/null
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/CopyTableSelectionHandler.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Julian Honnen
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Julian Honnen <julian.honnen@vector.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ui.internal.about;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+class CopyTableSelectionHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) {
+ Object control = HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
+ if (control instanceof Table) {
+ copySelection((Table) control);
+ }
+ return null;
+ }
+
+ public void copySelection(Table table) {
+ String text = selectionToString(table);
+ if (text.isEmpty()) {
+ return;
+ }
+
+ Clipboard clipboard = new Clipboard(table.getDisplay());
+ clipboard.setContents(new Object[] { text }, new Transfer[] { TextTransfer.getInstance() });
+ clipboard.dispose();
+ }
+
+ private static String selectionToString(Table table) {
+ StringBuilder builder = new StringBuilder();
+
+ for (TableItem tableItem : table.getSelection()) {
+ if (builder.length() > 0) {
+ builder.append(System.lineSeparator());
+ }
+
+ for (int column = 0; column < table.getColumnCount(); column++) {
+ if (column > 0) {
+ builder.append('\t');
+ }
+ builder.append(tableItem.getText(column));
+ }
+ }
+
+ return builder.toString();
+ }
+
+}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/ProductInfoPage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/ProductInfoPage.java
index bad07027af7..5f6ab52ebca 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/ProductInfoPage.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/about/ProductInfoPage.java
@@ -13,15 +13,32 @@
*******************************************************************************/
package org.eclipse.ui.internal.about;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.expressions.ExpressionInfo;
+import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.IWorkbenchCommandConstants;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.about.InstallationPage;
+import org.eclipse.ui.handlers.IHandlerActivation;
+import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.internal.WorkbenchMessages;
+import org.eclipse.ui.swt.IFocusService;
/**
* Abstract superclass of about dialog installation pages. The ProductInfoPage
@@ -70,4 +87,39 @@ public abstract class ProductInfoPage extends InstallationPage implements
composite.setLayout(layout);
return composite;
}
+
+ protected final void addCopySupport(Table table) {
+ CopyTableSelectionHandler handler = new CopyTableSelectionHandler();
+ Menu menu = new Menu(table);
+ MenuItem copyItem = new MenuItem(menu, SWT.NONE);
+ copyItem.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> handler.copySelection(table)));
+ copyItem.setText(JFaceResources.getString("copy")); //$NON-NLS-1$
+ copyItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
+
+ table.setMenu(menu);
+
+ IFocusService fs = PlatformUI.getWorkbench().getService(IFocusService.class);
+ IHandlerService hs = PlatformUI.getWorkbench().getService(IHandlerService.class);
+ if (fs != null && hs != null) {
+ fs.addFocusTracker(table, getClass().getName() + ".table"); //$NON-NLS-1$
+ IHandlerActivation handlerActivation = hs.activateHandler(IWorkbenchCommandConstants.EDIT_COPY, handler,
+ controlFocusedExpression(table));
+ table.addDisposeListener(e -> hs.deactivateHandler(handlerActivation));
+ }
+ }
+
+ private static Expression controlFocusedExpression(Control control) {
+ return new Expression() {
+ @Override
+ public EvaluationResult evaluate(IEvaluationContext context) {
+ return context.getVariable(ISources.ACTIVE_FOCUS_CONTROL_NAME) == control ? EvaluationResult.TRUE
+ : EvaluationResult.FALSE;
+ }
+
+ @Override
+ public void collectExpressionInfo(ExpressionInfo info) {
+ info.addVariableNameAccess(ISources.ACTIVE_FOCUS_CONTROL_NAME);
+ }
+ };
+ }
}

Back to the top