From d325b4e58a63154e074062326a79fdb58668fbf1 Mon Sep 17 00:00:00 2001 From: Edoardo Luppi Date: Wed, 22 Mar 2023 19:32:20 +0100 Subject: [PATCH] Remove 'Compute' button and sync-checkbox from the Feature editor Fixes https://github.com/eclipse-pde/eclipse.pde/issues/37 Co-authored-by: Hannes Wellmann --- .../pde/internal/core/feature/Feature.java | 162 ------------------ .../pde/internal/core/ifeature/IFeature.java | 2 - .../pde/internal/ui/PDEUIMessages.java | 2 - .../ui/editor/feature/RequiresSection.java | 89 ++-------- .../pde/internal/ui/pderesources.properties | 14 +- 5 files changed, 22 insertions(+), 247 deletions(-) diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/feature/Feature.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/feature/Feature.java index bd364473f3..67d23784c8 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/feature/Feature.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/feature/Feature.java @@ -15,23 +15,13 @@ package org.eclipse.pde.internal.core.feature; import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; import java.util.Locale; import java.util.Vector; import org.eclipse.core.runtime.CoreException; -import org.eclipse.osgi.service.resolver.BundleDescription; -import org.eclipse.osgi.service.resolver.HostSpecification; -import org.eclipse.osgi.service.resolver.VersionRange; import org.eclipse.pde.core.IModelChangedEvent; -import org.eclipse.pde.core.plugin.IMatchRules; -import org.eclipse.pde.core.plugin.IPluginBase; -import org.eclipse.pde.core.plugin.IPluginImport; import org.eclipse.pde.core.plugin.IPluginModelBase; -import org.eclipse.pde.core.plugin.ModelEntry; import org.eclipse.pde.core.plugin.PluginRegistry; -import org.eclipse.pde.internal.core.ICoreConstants; import org.eclipse.pde.internal.core.ifeature.IFeature; import org.eclipse.pde.internal.core.ifeature.IFeatureChild; import org.eclipse.pde.internal.core.ifeature.IFeatureData; @@ -40,8 +30,6 @@ import org.eclipse.pde.internal.core.ifeature.IFeatureInstallHandler; import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin; import org.eclipse.pde.internal.core.ifeature.IFeatureURL; -import org.eclipse.pde.internal.core.plugin.PluginBase; -import org.eclipse.pde.internal.core.util.VersionUtil; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -314,156 +302,6 @@ private void parseRequires(Node node) { } } - @Override - public void computeImports() throws CoreException { - // some existing imports may valid and can be preserved - Vector preservedImports = new Vector<>(fImports.size()); - // new imports - ArrayList newImports = new ArrayList<>(); - IPluginModelBase model = null; - for (int i = 0; i < fPlugins.size(); i++) { - IFeaturePlugin fp = fPlugins.get(i); - ModelEntry entry = PluginRegistry.findEntry(fp.getId()); - if (entry == null) { - continue; - } - IPluginModelBase[] models = entry.getActiveModels(); - for (IPluginModelBase m : models) { - if (fp.getVersion().equals(m.getPluginBase().getVersion()) || fp.getVersion().equals(ICoreConstants.DEFAULT_VERSION)) { - model = m; - } - } - if (model != null) { - addPluginImports(preservedImports, newImports, model.getPluginBase()); - if (model.isFragmentModel()) { - BundleDescription desc = model.getBundleDescription(); - if (desc == null) { - continue; - } - HostSpecification hostSpec = desc.getHost(); - String id = hostSpec.getName(); - String version = null; - int match = IMatchRules.NONE; - VersionRange versionRange = hostSpec.getVersionRange(); - if (!(versionRange == null || VersionRange.emptyRange.equals(versionRange))) { - version = versionRange.getMinimum() != null ? versionRange.getMinimum().toString() : null; - match = PluginBase.getMatchRule(versionRange); - } - addNewDependency(id, version, match, preservedImports, newImports); - } - } - } - // preserve imports of features - for (int i = 0; i < fImports.size(); i++) { - IFeatureImport iimport = fImports.get(i); - if (iimport.getType() == IFeatureImport.FEATURE) { - preservedImports.add(iimport); - } - } - // removed = old - preserved - @SuppressWarnings("unchecked") - Vector removedImports = ((Vector) fImports.clone()); - removedImports.removeAll(preservedImports); - // perform remove - fImports = preservedImports; - if (!removedImports.isEmpty()) { - fireStructureChanged(removedImports.toArray(new IFeatureImport[removedImports.size()]), IModelChangedEvent.REMOVE); - } - // perform add - if (!newImports.isEmpty()) { - fImports.addAll(newImports); - fireStructureChanged(newImports.toArray(new IFeatureImport[newImports.size()]), IModelChangedEvent.INSERT); - } - } - - /** - * Creates IFeatureImports based on IPluginImports. Ensures no duplicates in - * preservedImports + newImports - * - * @param preservedImports - * out for valid existing imports - * @param newImports - * out for new imports - * @param plugin - * @throws CoreException - */ - private void addPluginImports(List preservedImports, List newImports, IPluginBase plugin) throws CoreException { - IPluginImport[] pluginImports = plugin.getImports(); - for (IPluginImport pluginImport : pluginImports) { - if (pluginImport.isOptional()) { - continue; - } - String id = pluginImport.getId(); - String version = pluginImport.getVersion(); - int match = pluginImport.getMatch(); - addNewDependency(id, version, match, preservedImports, newImports); - } - } - - private void addNewDependency(String id, String version, int match, List preservedImports, List newImports) throws CoreException { - if (findFeaturePlugin(id, version, match) != null) { - // don't add imports to local plug-ins - return; - } - if (findImport(preservedImports, id, version, match) != null) { - // already seen - return; - } - if (findImport(newImports, id, version, match) != null) { - // already seen - return; - } - IFeatureImport iimport = findImport(fImports, id, version, match); - if (iimport != null) { - // import still valid - preservedImports.add(iimport); - return; - } - // a new one is needed - iimport = getModel().getFactory().createImport(); - iimport.setId(id); - iimport.setVersion(version); - iimport.setMatch(match); - ((FeatureImport) iimport).setInTheModel(true); - newImports.add(iimport); - } - - /** - * Finds a given import in the list - * @param imports list of imports - * @param id - * @param version - * @param match - * @return IFeatureImport or null - */ - private IFeatureImport findImport(List imports, String id, String version, int match) { - for (int i = 0; i < imports.size(); i++) { - IFeatureImport iimport = imports.get(i); - if (iimport.getId().equals(id)) { - if (version == null) { - return iimport; - } - if (version.equals(iimport.getVersion()) && match == iimport.getMatch()) { - return iimport; - } - } - } - return null; - } - - private IFeaturePlugin findFeaturePlugin(String id, String version, int match) { - - for (int i = 0; i < fPlugins.size(); i++) { - IFeaturePlugin fp = fPlugins.get(i); - String pid = fp.getId(); - String pversion = fp.getVersion(); - if (VersionUtil.compare(pid, pversion, id, version, match)) { - return fp; - } - } - return null; - } - @Override public void removePlugins(IFeaturePlugin[] removed) throws CoreException { ensureModelEditable(); diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ifeature/IFeature.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ifeature/IFeature.java index 7869a5f512..1209b34ed7 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ifeature/IFeature.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ifeature/IFeature.java @@ -231,8 +231,6 @@ public interface IFeature extends IFeatureObject, IVersionable, IEnvironment { */ public void setURL(IFeatureURL url) throws CoreException; - public void computeImports() throws CoreException; - boolean isPrimary(); public String getLicenseFeatureID(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java index c896918c54..6e79663975 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java @@ -862,8 +862,6 @@ public class PDEUIMessages extends NLS { public static String FeatureEditor_RequiresSection_title; public static String FeatureEditor_RequiresSection_desc; - public static String FeatureEditor_RequiresSection_sync; - public static String FeatureEditor_RequiresSection_compute; public static String FeatureEditor_RequiresSection_plugin; public static String FeatureEditor_RequiresSection_feature; public static String FeatureEditor_RequiresSection_sortAlpha; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/RequiresSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/RequiresSection.java index eb3fdcd23e..a89a1af8a1 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/RequiresSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/RequiresSection.java @@ -18,16 +18,11 @@ *******************************************************************************/ package org.eclipse.pde.internal.ui.editor.feature; -import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; - import java.util.ArrayList; import java.util.Iterator; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IMenuManager; @@ -57,7 +52,6 @@ import org.eclipse.pde.internal.core.ifeature.IFeatureImport; import org.eclipse.pde.internal.core.ifeature.IFeatureModel; import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin; -import org.eclipse.pde.internal.ui.IPDEUIConstants; import org.eclipse.pde.internal.ui.PDEPlugin; import org.eclipse.pde.internal.ui.PDEUIMessages; import org.eclipse.pde.internal.ui.dialogs.FeatureSelectionDialog; @@ -74,7 +68,6 @@ import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Table; @@ -85,29 +78,24 @@ import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.Section; -import org.osgi.service.prefs.Preferences; public class RequiresSection extends TableSection implements IPluginModelListener, IFeatureModelListener { - private static final int RECOMPUTE_IMPORT = 3; private static final int REMOVE = 2; private static final int NEW_FEATURE = 1; private static final int NEW_PLUGIN = 0; - private Button fSyncButton; - private TableViewer fPluginViewer; private Action fDeleteAction; - private SortAction fSortAction; private Action fOpenAction; static class ImportContentProvider implements IStructuredContentProvider { @Override public Object[] getElements(Object parent) { - if (parent instanceof IFeature) { - IFeatureImport[] imports = ((IFeature) parent).getImports(); + if (parent instanceof IFeature feature) { + IFeatureImport[] imports = feature.getImports(); ArrayList displayable = new ArrayList<>(); for (IFeatureImport featureImport : imports) { if (featureImport.isPatch()) @@ -122,39 +110,19 @@ public Object[] getElements(Object parent) { } public RequiresSection(FeatureDependenciesPage page, Composite parent) { - super(page, parent, Section.DESCRIPTION, new String[] {PDEUIMessages.FeatureEditor_RequiresSection_plugin, PDEUIMessages.FeatureEditor_RequiresSection_feature, PDEUIMessages.FeatureEditor_RequiresSection_remove, PDEUIMessages.FeatureEditor_RequiresSection_compute}); + super(page, parent, Section.DESCRIPTION, new String[] {PDEUIMessages.FeatureEditor_RequiresSection_plugin, PDEUIMessages.FeatureEditor_RequiresSection_feature, PDEUIMessages.FeatureEditor_RequiresSection_remove}); getSection().setText(PDEUIMessages.FeatureEditor_RequiresSection_title); getSection().setDescription(PDEUIMessages.FeatureEditor_RequiresSection_desc); getTablePart().setEditable(false); } - @Override - public void commit(boolean onSave) { - super.commit(onSave); - } - @Override public void createClient(Section section, FormToolkit toolkit) { - - final IFeatureModel model = (IFeatureModel) getPage().getModel(); section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); GridData data = new GridData(GridData.FILL_BOTH); section.setLayoutData(data); Composite container = createClientContainer(section, 2, toolkit); - - fSyncButton = toolkit.createButton(container, PDEUIMessages.FeatureEditor_RequiresSection_sync, SWT.CHECK); - // syncButton.setSelection(true); - GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - gd.horizontalSpan = 2; - fSyncButton.setLayoutData(gd); - - fSyncButton.addSelectionListener(widgetSelectedAdapter(e -> { - IEclipsePreferences eclipsePrefs = Platform.getPreferencesService().getRootNode(); - Preferences prefs = eclipsePrefs.node(Plugin.PLUGIN_PREFERENCE_SCOPE).node(IPDEUIConstants.PLUGIN_ID); - prefs.putBoolean(model.getFeature().getLabel(), fSyncButton.getSelection()); - })); - createViewerPartControl(container, SWT.MULTI, 2, toolkit); TablePart tablePart = getTablePart(); @@ -180,21 +148,18 @@ public void run() { toolkit.paintBordersFor(container); section.setClient(container); initialize(); - createSectionToolbar(section, toolkit); + createSectionToolbar(section); } - /** - * @param section - * @param toolkit - */ - private void createSectionToolbar(Section section, FormToolkit toolkit) { + private void createSectionToolbar(Section section) { ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); ToolBar toolbar = toolBarManager.createControl(section); final Cursor handCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND); toolbar.setCursor(handCursor); // Add sort action to the tool bar - fSortAction = new SortAction(getStructuredViewerPart().getViewer(), PDEUIMessages.FeatureEditor_RequiresSection_sortAlpha, ListUtil.NAME_COMPARATOR, null, null); + SortAction fSortAction = new SortAction(getStructuredViewerPart().getViewer(), + PDEUIMessages.FeatureEditor_RequiresSection_sortAlpha, ListUtil.NAME_COMPARATOR, null, null); toolBarManager.add(fSortAction); @@ -205,12 +170,12 @@ private void createSectionToolbar(Section section, FormToolkit toolkit) { @Override protected void buttonSelected(int index) { - switch (index) { + switch (index) + { case NEW_PLUGIN -> handleNewPlugin(); case NEW_FEATURE -> handleNewFeature(); case REMOVE -> handleDelete(); - case RECOMPUTE_IMPORT -> recomputeImports(); - }; + } } private void handleNewPlugin() { @@ -282,8 +247,7 @@ private void doAdd(Object[] candidates) throws CoreException { IFeatureImport[] added = new IFeatureImport[candidates.length]; for (int i = 0; i < candidates.length; i++) { FeatureImport fimport = (FeatureImport) model.getFactory().createImport(); - if (candidates[i] instanceof IFeatureModel) { - IFeatureModel candidate = (IFeatureModel) candidates[i]; + if (candidates[i] instanceof IFeatureModel candidate) { fimport.loadFrom(candidate.getFeature()); } else { // instanceof IPluginModelBase IPluginModelBase candidate = (IPluginModelBase) candidates[i]; @@ -346,8 +310,7 @@ private void handleOpen() { IStructuredSelection sel = fPluginViewer.getStructuredSelection(); Object obj = sel.getFirstElement(); - if (obj instanceof FeatureImport) { - FeatureImport featureImport = (FeatureImport) obj; + if (obj instanceof FeatureImport featureImport) { if (featureImport.getType() == IFeatureImport.PLUGIN) { IPlugin plugin = featureImport.getPlugin(); if (plugin == null) { @@ -356,8 +319,7 @@ private void handleOpen() { } ManifestEditor.open(plugin, false); - } - else if (featureImport.getType() == IFeatureImport.FEATURE) { + } else if (featureImport.getType() == IFeatureImport.FEATURE) { IFeature feature = featureImport.getFeature(); if (feature == null) { logNullFeatureImport(obj); @@ -444,23 +406,18 @@ private void updateButtons() { Table table = tablePart.getTableViewer().getTable(); TableItem[] tableSelection = table.getSelection(); boolean hasSelection = tableSelection.length > 0; - //delete + // delete tablePart.setButtonEnabled(REMOVE, isEditable() && hasSelection); } public void initialize() { IFeatureModel model = (IFeatureModel) getPage().getModel(); refresh(); - if (model.isEditable() == false) { + if (!model.isEditable()) { getTablePart().setButtonEnabled(NEW_PLUGIN, false); getTablePart().setButtonEnabled(NEW_FEATURE, false); getTablePart().setButtonEnabled(REMOVE, false); - getTablePart().setButtonEnabled(RECOMPUTE_IMPORT, false); - fSyncButton.setEnabled(false); } - IEclipsePreferences eclipsePrefs = Platform.getPreferencesService().getRootNode(); - Preferences prefs = eclipsePrefs.node(Plugin.PLUGIN_PREFERENCE_SCOPE).node(IPDEUIConstants.PLUGIN_ID); - fSyncButton.setSelection(prefs.getBoolean(model.getFeature().getLabel(), false)); model.addModelChangedListener(this); PDECore.getDefault().getModelManager().addPluginModelListener(this); PDECore.getDefault().getFeatureModelManager().addFeatureModelListener(this); @@ -470,7 +427,6 @@ public void initialize() { public void modelChanged(IModelChangedEvent e) { if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { markStale(); - return; } else if (e.getChangeType() == IModelChangedEvent.CHANGE) { Object obj = e.getChangedObjects()[0]; if (obj instanceof IFeatureImport) { @@ -484,26 +440,13 @@ public void modelChanged(IModelChangedEvent e) { if (e.getChangedObjects().length > 0) { fPluginViewer.setSelection(new StructuredSelection(e.getChangedObjects()[0])); } - } else + } else { fPluginViewer.remove(e.getChangedObjects()); - } else if (obj instanceof IFeaturePlugin) { - if (fSyncButton.getSelection()) { - recomputeImports(); } } } } - private void recomputeImports() { - IFeatureModel model = (IFeatureModel) getPage().getModel(); - IFeature feature = model.getFeature(); - try { - feature.computeImports(); - } catch (CoreException e) { - PDEPlugin.logException(e); - } - } - @Override public void modelsChanged(final PluginModelDelta delta) { getSection().getDisplay().asyncExec(() -> { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties index 401e5f437e..1f53d02708 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties @@ -242,9 +242,7 @@ Leave blank if the archive does not contain platform-specific code. FeatureExportJob_name=Export Features FeatureEditor_RequiresSection_title = Required Features/Plug-ins -FeatureEditor_RequiresSection_desc = Compute plug-ins that will need to be present before installing this feature. -FeatureEditor_RequiresSection_sync = Recompute when feature plug-ins change -FeatureEditor_RequiresSection_compute = Compute +FeatureEditor_RequiresSection_desc = List Plug-ins and Features that will need to be present before installing this feature. FeatureEditor_RequiresSection_plugin = Add Plug-in... FeatureEditor_RequiresSection_feature = Add Feature... FeatureEditor_RequiresSection_remove = Remove @@ -601,7 +599,7 @@ TracingTab_AttributeLabel_TracingOptions=Tracing options TracingTab_AttributeLabel_TracingChecked=Tracing select all TracingTab_AttributeLabel_TracingNone=Tracing select none -TracingBlock_restore_default=Restore &All to Defaults +TracingBlock_restore_default=Restore &All to Defaults TracingBlock_restore_default_selected=Restore &Selected to Defaults TracingLauncherTab_name = Trac&ing TracingLauncherTab_tracing =&Enable tracing @@ -1147,7 +1145,7 @@ ImageBrowserView_Show=Show: ImageBrowserView_Source=Source: ImageBrowserView_Width=Width: ImportActionGroup_binaryWithLinkedContent=Binary Project with &Linked Content -ImportActionGroup_cannot_import=The selected plug-ins cannot be imported from a repository. The plug-ins do not have an Eclipse-SourceReferences manifest header that can be processed. +ImportActionGroup_cannot_import=The selected plug-ins cannot be imported from a repository. The plug-ins do not have an Eclipse-SourceReferences manifest header that can be processed. ImportActionGroup_importContributingPlugin=&Import Contributing Plug-in as ImportActionGroup_Repository_project=P&roject from a Repository... @@ -1716,7 +1714,7 @@ RepositorySection_remove=Remove RepositorySection_removeAll=Remove All StatsSection_title=Download Statistics -StatsSection_description=Specify a URL for the server that tracks download statistics. List the features and plug-ins to be tracked by the server. +StatsSection_description=Specify a URL for the server that tracks download statistics. List the features and plug-ins to be tracked by the server. StatsSection_url=URL: StatsSection_addFeature = Add Feature... StatsSection_addBundle = Add Plug-in... @@ -2575,7 +2573,7 @@ UpdatesSection_EnabledColumn=Enabled CustomizationPage_title=Customization PreferencesSection_title=Default Preferences -PreferencesSection_description=Use an Eclipse preferences (.epf) file to set the product's default preferences. +PreferencesSection_description=Use an Eclipse preferences (.epf) file to set the product's default preferences. PreferencesSection_errorReading=Error reading file {0}. Could not generate preferences. PreferencesSection_errorNoDefiningPlugin=The product's defining plug-in project could not be found. Cannot generate a plugin_customization.ini file. PreferencesSection_errorNoDefiningPluginTitle=Plug-in {0} Not Found @@ -2665,7 +2663,7 @@ ExtensionAttributeRow_AttrReq={0} (required) ExtensionAttributeRow_AttrReqDepr={0} (required) (deprecated) ExtensionAttributeRow_AttrFilter=Press {0} within text to filter for this attribute value. # In extension page of plug-in editor we list attributes with symbols after to indicate deprecation/required -ExtensionAttributeRow_AttrLabel={0}: +ExtensionAttributeRow_AttrLabel={0}: ExtensionAttributeRow_AttrLabelDepr={0}(!): ExtensionAttributeRow_AttrLabelReq={0}*: ExtensionAttributeRow_AttrLabelReqDepr={0}(!)*: