|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2026 IBM Corporation and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * IBM Corporation - initial API and implementation |
| 13 | + *******************************************************************************/ |
| 14 | +package org.eclipse.pde.internal.ui.launcher; |
| 15 | + |
| 16 | + |
| 17 | +import java.util.Map; |
| 18 | +import java.util.StringJoiner; |
| 19 | + |
| 20 | +import org.eclipse.jface.dialogs.Dialog; |
| 21 | +import org.eclipse.jface.dialogs.IDialogConstants; |
| 22 | +import org.eclipse.osgi.service.resolver.BundleDescription; |
| 23 | +import org.eclipse.pde.core.plugin.IPluginModelBase; |
| 24 | +import org.eclipse.pde.internal.ui.PDEUIMessages; |
| 25 | +import org.eclipse.swt.SWT; |
| 26 | +import org.eclipse.swt.dnd.Clipboard; |
| 27 | +import org.eclipse.swt.dnd.TextTransfer; |
| 28 | +import org.eclipse.swt.dnd.Transfer; |
| 29 | +import org.eclipse.swt.graphics.Rectangle; |
| 30 | +import org.eclipse.swt.layout.GridData; |
| 31 | +import org.eclipse.swt.widgets.Composite; |
| 32 | +import org.eclipse.swt.widgets.Control; |
| 33 | +import org.eclipse.swt.widgets.Label; |
| 34 | +import org.eclipse.swt.widgets.Shell; |
| 35 | +import org.eclipse.swt.widgets.Text; |
| 36 | + |
| 37 | + |
| 38 | +public class ShowBundlesDialog extends Dialog { |
| 39 | + private Text fModuleArgumentsText; |
| 40 | + private final Map<IPluginModelBase, String> fModelsWithStartLevels; |
| 41 | + |
| 42 | + |
| 43 | + protected ShowBundlesDialog(Shell parentShell, Map<IPluginModelBase, String> modelsWithLevels) { |
| 44 | + super(parentShell); |
| 45 | + fModelsWithStartLevels = modelsWithLevels; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + protected void configureShell(Shell newShell) { |
| 50 | + super.configureShell(newShell); |
| 51 | + newShell.setText(PDEUIMessages.ShowBundlesDialog_LaunchBundles); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected void createButtonsForButtonBar(Composite parent) { |
| 56 | + createButton(parent, IDialogConstants.OK_ID, |
| 57 | + PDEUIMessages.ShowBundlesDialog_Copy, true); |
| 58 | + createButton(parent, IDialogConstants.CANCEL_ID, |
| 59 | + PDEUIMessages.ShowBundlesDialog_Close, false); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + protected Rectangle getConstrainedShellBounds(Rectangle preferredSize) { |
| 64 | + Rectangle result = super.getConstrainedShellBounds(preferredSize); |
| 65 | + int heightLimit = convertHeightInCharsToPixels(40); |
| 66 | + int widthLimit = convertWidthInCharsToPixels(150); |
| 67 | + if (result.height > heightLimit) { |
| 68 | + result.y += (result.height - heightLimit) / 2; |
| 69 | + result.height = heightLimit; |
| 70 | + } |
| 71 | + if (result.width > widthLimit) { |
| 72 | + result.x += (result.width - widthLimit) / 2; |
| 73 | + result.width = widthLimit; |
| 74 | + } |
| 75 | + return result; |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + protected boolean isResizable() { |
| 80 | + return true; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + protected Control createDialogArea(Composite parent) { |
| 85 | + Composite comp = (Composite) super.createDialogArea(parent); |
| 86 | + Label explanation = new Label(comp, SWT.NONE); |
| 87 | + explanation.setText("List of all bundles contained in this launch using the schema:\n" //$NON-NLS-1$ |
| 88 | + + "<Symbolic Name>, <Version>, <Start level>, <File Path>"); //$NON-NLS-1$ |
| 89 | + explanation.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 90 | + fModuleArgumentsText = new Text(comp, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); |
| 91 | + fModuleArgumentsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 92 | + StringJoiner lines = new StringJoiner("\n"); //$NON-NLS-1$ |
| 93 | + fModelsWithStartLevels.forEach((model, value) -> { |
| 94 | + BundleDescription bundle = model.getBundleDescription(); |
| 95 | + String startLevel = value.substring(0, value.indexOf(':')); |
| 96 | + lines.add(bundle.getSymbolicName() + ", " + bundle.getVersion() + ", " + startLevel + ", " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 97 | + + model.getInstallLocation()); |
| 98 | + }); |
| 99 | + fModuleArgumentsText.setText(lines.toString()); |
| 100 | + fModuleArgumentsText.setEditable(false); |
| 101 | + |
| 102 | + return comp; |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + protected void buttonPressed(int buttonId) { |
| 107 | + if (buttonId == OK) { |
| 108 | + Clipboard clipboard = new Clipboard(null); |
| 109 | + try { |
| 110 | + Transfer[] transfers = { TextTransfer.getInstance() }; |
| 111 | + Object[] data = { fModuleArgumentsText.getText() }; |
| 112 | + clipboard.setContents(data, transfers); |
| 113 | + } finally { |
| 114 | + clipboard.dispose(); |
| 115 | + } |
| 116 | + } |
| 117 | + super.buttonPressed(buttonId); |
| 118 | + } |
| 119 | + |
| 120 | +} |
0 commit comments