Skip to content

Commit

Permalink
Add support for Eclipse-BundleShape in Manifest-Editor
Browse files Browse the repository at this point in the history
Three modes are supported: jar, dir and default.
First two are self-explanatory, third option removes the header
which is the default behaviour.
Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>

Fixes: eclipse-pde#864
  • Loading branch information
alshamams authored and HannesWell committed Dec 22, 2023
1 parent d00aa72 commit c99e249
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,18 @@ public class PDEUIMessages extends NLS {
public static String ProductFileWizadPage_basic;
public static String Product_overview_exporting;
public static String GeneralInfoSection_desc;

public static String GeneralInfoSection_EclipseBundleShape_defaultGeneralInfoSection_EclipseBundleShape_default;

public static String GeneralInfoSection_EclipseBundleShape_dirGeneralInfoSection_EclipseBundleShape_dir;

public static String GeneralInfoSection_EclipseBundleShape_jarGeneralInfoSection_EclipseBundleShape_jar;

public static String GeneralInfoSection_EclipseBundleShape_label_defaultGeneralInfoSection_EclipseBundleShape_label_default;

public static String GeneralInfoSection_EclipseBundleShape_label_dirGeneralInfoSection_EclipseBundleShape_label_dir;

public static String GeneralInfoSection_EclipseBundleShape_label_jarGeneralInfoSection_EclipseBundleShape_label_jar;
public static String ProductInfoSection_desc;
public static String ProductInfoSection_id;
public static String ProductInfoSection_product;
Expand Down Expand Up @@ -2563,6 +2575,8 @@ public class PDEUIMessages extends NLS {

public static String PluginGeneralInfoSection_singleton;

public static String PluginGeneralInfoSection_bundleshape;

public static String FragmentGeneralInfoSection_singleton;

public static String ClassSearchParticipant_taskMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;

import java.util.stream.Stream;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.layout.RowLayoutFactory;
import org.eclipse.pde.core.IBaseModel;
import org.eclipse.pde.core.IModelChangeProvider;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.internal.core.ICoreConstants;
import org.eclipse.pde.internal.core.ibundle.IBundle;
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
Expand All @@ -41,6 +45,8 @@
import org.eclipse.pde.internal.ui.parts.FormEntry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
Expand All @@ -55,7 +61,7 @@
* Provides the first section of the manifest editor describing the bundle id/name/version/etc.
*/
public abstract class GeneralInfoSection extends PDESection {
private static String PLATFORM_FILTER = "Eclipse-PlatformFilter"; //$NON-NLS-1$
private static final String PLATFORM_FILTER = "Eclipse-PlatformFilter"; //$NON-NLS-1$

private FormEntry fIdEntry;
private FormEntry fVersionEntry;
Expand All @@ -77,6 +83,10 @@ public abstract class GeneralInfoSection extends PDESection {

protected Button fSingleton;

private Button fBundleShapeDefault;
private Button fBundleShapeJar;
private Button fBundleShapeDir;

public GeneralInfoSection(PDEFormPage page, Composite parent) {
super(page, parent, Section.DESCRIPTION);
createClient(getSection(), page.getEditor().getToolkit());
Expand All @@ -102,6 +112,7 @@ protected void createClient(Section section, FormToolkit toolkit) {
if (isBundle() && ((ManifestEditor) getPage().getEditor()).isEquinox())
createPlatformFilterEntry(client, toolkit, actionBars);
createSpecificControls(client, toolkit, actionBars);
createBundleShape(client, toolkit, PDEUIMessages.PluginGeneralInfoSection_bundleshape);
toolkit.paintBordersFor(client);

addListeners();
Expand Down Expand Up @@ -340,6 +351,24 @@ public void refresh() {
IManifestHeader header = getSingletonHeader();
fSingleton.setSelection(header instanceof BundleSymbolicNameHeader && ((BundleSymbolicNameHeader) header).isSingleton());
}
// Select the corresponding 'Bundle-Shape' radio button (eventually)
Stream.of(fBundleShapeDefault, fBundleShapeJar, fBundleShapeDir).forEach(b -> b.setSelection(false));
Button selectedBundleShape = fBundleShapeDefault;
IManifestHeader header = getBundle().getManifestHeader(ICoreConstants.ECLIPSE_BUNDLE_SHAPE);
if (header != null) {
String value = header.getValue();
if (value != null) {
selectedBundleShape = switch (value) {
case ICoreConstants.SHAPE_JAR -> fBundleShapeJar;
case ICoreConstants.SHAPE_DIR -> fBundleShapeDir;
default -> null; // unsupported value
};
}
}
if (selectedBundleShape != null) {
selectedBundleShape.setSelection(true);
}

super.refresh();
}

Expand Down Expand Up @@ -400,4 +429,46 @@ protected void createSingleton(Composite parent, FormToolkit toolkit, IActionBar
}));
}

protected void createBundleShape(Composite parent, FormToolkit toolkit, String label) {
Composite c = new Composite(parent, SWT.NONE);
TableWrapData td = new TableWrapData();
td.colspan = 3;
c.setLayoutData(td);
RowLayoutFactory.fillDefaults().spacing(5).applyTo(c);
toolkit.createLabel(c, label, SWT.NONE);
fBundleShapeDefault = toolkit.createButton(c,
PDEUIMessages.GeneralInfoSection_EclipseBundleShape_label_defaultGeneralInfoSection_EclipseBundleShape_label_default,
SWT.RADIO);
fBundleShapeJar = toolkit.createButton(c,
PDEUIMessages.GeneralInfoSection_EclipseBundleShape_label_jarGeneralInfoSection_EclipseBundleShape_label_jar,
SWT.RADIO);
fBundleShapeDir = toolkit.createButton(c,
PDEUIMessages.GeneralInfoSection_EclipseBundleShape_label_dirGeneralInfoSection_EclipseBundleShape_label_dir,
SWT.RADIO);
fBundleShapeDir.setToolTipText(PDEUIMessages.GeneralInfoSection_EclipseBundleShape_dirGeneralInfoSection_EclipseBundleShape_dir);
fBundleShapeJar.setToolTipText(
PDEUIMessages.GeneralInfoSection_EclipseBundleShape_jarGeneralInfoSection_EclipseBundleShape_jar);
fBundleShapeDefault.setToolTipText(
PDEUIMessages.GeneralInfoSection_EclipseBundleShape_defaultGeneralInfoSection_EclipseBundleShape_default);
fBundleShapeDefault.setSelection(true);
fBundleShapeJar.addSelectionListener(SelectionListener
.widgetSelectedAdapter(event -> setBundleShapeHeader(event, ICoreConstants.SHAPE_JAR)));
fBundleShapeDir.addSelectionListener(SelectionListener
.widgetSelectedAdapter(event -> setBundleShapeHeader(event, ICoreConstants.SHAPE_DIR)));
fBundleShapeDefault.addSelectionListener(
SelectionListener.widgetSelectedAdapter(event -> setBundleShapeHeader(event, null)));
}

private void setBundleShapeHeader(SelectionEvent event, String shape) {
if (((Button) event.widget).getSelection()) {
IBundle bundle = getBundle();
if (shape != null) {
bundle.setHeader(ICoreConstants.ECLIPSE_BUNDLE_SHAPE, shape);
} else {
// Setting the header's value to null removes it (setting the
// header to null is not sufficient)
bundle.getManifestHeader(ICoreConstants.ECLIPSE_BUNDLE_SHAPE).setValue(null);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,7 @@ PluginWorkingSet_deselectAll_label=Dese&lect All
PluginDevelopmentPage_presentation=Plug-in Manifest Editor Presentation
PluginGeneralInfoSection_lazyStart=Activate this plug-in when one of its classes is loaded
PluginGeneralInfoSection_singleton=This plug-in is a singleton
PluginGeneralInfoSection_bundleshape=Shape after P2 installation:
FragmentGeneralInfoSection_singleton=This fragment is a singleton
PluginWorkingSet_deselectAll_toolTip=Unselect all of these plug-ins for this working set.
PluginListPage_initializeFromPlugins=&Initialize from the plug-ins list:
Expand Down Expand Up @@ -2110,6 +2111,12 @@ Product_overview_exporting = <form>\
<p>Use the <a href="action.export">Eclipse Product export wizard</a> to package and export the product defined in this configuration.</p>\
</form>
GeneralInfoSection_desc=This section describes general information about the product.
GeneralInfoSection_EclipseBundleShape_defaultGeneralInfoSection_EclipseBundleShape_default=Set Eclipse_BundleShape to default
GeneralInfoSection_EclipseBundleShape_dirGeneralInfoSection_EclipseBundleShape_dir=Set Eclipse_BundleShape to dir
GeneralInfoSection_EclipseBundleShape_jarGeneralInfoSection_EclipseBundleShape_jar=Set Eclipse_BundleShape to jar
GeneralInfoSection_EclipseBundleShape_label_defaultGeneralInfoSection_EclipseBundleShape_label_default=default
GeneralInfoSection_EclipseBundleShape_label_dirGeneralInfoSection_EclipseBundleShape_label_dir=directory
GeneralInfoSection_EclipseBundleShape_label_jarGeneralInfoSection_EclipseBundleShape_label_jar=jar
ProductInfoSection_desc=This section describes the launching product extension identifier and application.
ProductInfoSection_id=ID:
ProductInfoSection_product=Product:
Expand Down

0 comments on commit c99e249

Please sign in to comment.