From 629cbdc6434a9985cf80f2c578bdc9cbb142d7ae Mon Sep 17 00:00:00 2001 From: Johan Compagner Date: Thu, 26 Oct 2023 18:03:22 +0200 Subject: [PATCH] Support names for Updates repositories in product definition #345 --- .../core/iproduct/IRepositoryInfo.java | 4 ++ .../core/isite/IRepositoryReference.java | 4 ++ .../internal/core/product/RepositoryInfo.java | 22 +++++++++- .../core/site/RepositoryReference.java | 17 ++++++++ .../pde/internal/ui/PDEUIMessages.java | 3 ++ .../internal/ui/dialogs/RepositoryDialog.java | 27 ++++++++---- .../category/RepositoryReferenceSection.java | 41 +++++++++++-------- .../ui/editor/product/UpdatesSection.java | 41 +++++++++++-------- .../pde/internal/ui/pderesources.properties | 2 + 9 files changed, 120 insertions(+), 41 deletions(-) diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/iproduct/IRepositoryInfo.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/iproduct/IRepositoryInfo.java index e5716fa6f32..8287157b838 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/iproduct/IRepositoryInfo.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/iproduct/IRepositoryInfo.java @@ -23,4 +23,8 @@ public interface IRepositoryInfo extends IProductObject { void setURL(String url); + String getName(); + + void setName(String name); + } diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/isite/IRepositoryReference.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/isite/IRepositoryReference.java index 1de160d79fb..d9509b7b107 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/isite/IRepositoryReference.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/isite/IRepositoryReference.java @@ -25,4 +25,8 @@ public interface IRepositoryReference extends ISiteObject { void setURL(String url) throws CoreException; + String getName(); + + void setName(String name) throws CoreException; + } diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/product/RepositoryInfo.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/product/RepositoryInfo.java index 9df8e8ba148..f51fe5a8978 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/product/RepositoryInfo.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/product/RepositoryInfo.java @@ -25,16 +25,32 @@ public class RepositoryInfo extends ProductObject implements IRepositoryInfo { private static final long serialVersionUID = 1L; + public static final String P_NAME = "name"; //$NON-NLS-1$ public static final String P_LOCATION = "location"; //$NON-NLS-1$ public static final String P_ENABLED = "enabled"; //$NON-NLS-1$ private String fURL; + private String fName; private boolean fEnabled = true; // enabled unless specified otherwise public RepositoryInfo(IProductModel model) { super(model); } + @Override + public void setName(String name) { + String old = fName; + fName = name; + if (isEditable()) { + firePropertyChanged(P_NAME, old, fName); + } + } + + @Override + public String getName() { + return fName; + } + @Override public void setURL(String url) { String old = fURL; @@ -58,7 +74,7 @@ public boolean getEnabled() { public void setEnabled(boolean enabled) { boolean old = fEnabled; fEnabled = enabled; - if (isEditable()) { + if (isEditable() && old != fEnabled) { firePropertyChanged(P_ENABLED, old, fEnabled); } } @@ -68,6 +84,7 @@ public void parse(Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; fURL = element.getAttribute("location"); //$NON-NLS-1$ + fName = element.getAttribute("name"); //$NON-NLS-1$ fEnabled = Boolean.parseBoolean(element.getAttribute(P_ENABLED)); } } @@ -77,6 +94,7 @@ public void parse(Node node) { public void write(String indent, PrintWriter writer) { if (isURLDefined()) { writer.print(indent + ""); //$NON-NLS-1$ } @@ -99,7 +117,7 @@ public boolean equals(Object obj) { if (!(obj instanceof RepositoryInfo other)) { return false; } - return Objects.equals(fURL, other.fURL); + return Objects.equals(fURL, other.fURL) && Objects.equals(fName, other.fName); } } diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/site/RepositoryReference.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/site/RepositoryReference.java index 66101e485ac..ef038bc2c6c 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/site/RepositoryReference.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/site/RepositoryReference.java @@ -24,9 +24,11 @@ public class RepositoryReference extends SiteObject implements IRepositoryRefere private static final long serialVersionUID = 1L; + public static final String P_NAME = "name"; //$NON-NLS-1$ public static final String P_LOCATION = "location"; //$NON-NLS-1$ public static final String P_ENABLED = "enabled"; //$NON-NLS-1$ + private String fName; private String fURL; private boolean fEnabled = true; // enabled unless specified otherwise @@ -34,6 +36,19 @@ public RepositoryReference() { super(); } + @Override + public String getName() { + return fName; + } + + @Override + public void setName(String name) throws CoreException { + String old = fName; + fName = name; + ensureModelEditable(); + firePropertyChanged(P_NAME, old, fName); + } + @Override public void setURL(String url) throws CoreException { String old = fURL; @@ -65,6 +80,7 @@ public void parse(Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; fURL = element.getAttribute("location"); //$NON-NLS-1$ + fName = element.getAttribute("name"); //$NON-NLS-1$ fEnabled = Boolean.parseBoolean(element.getAttribute(P_ENABLED)); } } @@ -73,6 +89,7 @@ public void parse(Node node) { public void write(String indent, PrintWriter writer) { if (isURLDefined()) { writer.print(indent + ""); //$NON-NLS-1$ } 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 40f3c7d6d9d..04299c53830 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 @@ -3071,6 +3071,7 @@ public class PDEUIMessages extends NLS { public static String UpdatesSection_description; public static String UpdatesSection_RepositoryDialogTitle; public static String UpdatesSection_Location; + public static String UpdatesSection_Name; public static String UpdatesSection_ErrorLocationNoName; public static String UpdatesSection_ErrorInvalidURL; public static String UpdatesSection_LocationColumn; @@ -3078,6 +3079,8 @@ public class PDEUIMessages extends NLS { public static String UpdatesSection_LocationMessage; public static String UpdatesSection_EnabledColumn; + public static String UpdatesSection_NameColumn; + public static String CustomizationPage_title; public static String PreferencesSection_title; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/RepositoryDialog.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/RepositoryDialog.java index 955adef1fd1..d45c525714c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/RepositoryDialog.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/RepositoryDialog.java @@ -44,8 +44,10 @@ */ public class RepositoryDialog extends StatusDialog { private Text fLocation; + private Text fName; private final String fRepoURL; - private String fLocationStr; + private final String fNameStr; + private RepositoryResult result; /** * @param shell @@ -53,35 +55,43 @@ public class RepositoryDialog extends StatusDialog { * @param repoURL * The initial value of the URL, which may be null */ - public RepositoryDialog(Shell shell, String repoURL) { + public RepositoryDialog(Shell shell, String repoURL, String name) { super(shell); fRepoURL = repoURL; + fNameStr = name; } @Override protected Control createDialogArea(Composite parent) { Composite comp = (Composite) super.createDialogArea(parent); ((GridLayout) comp.getLayout()).numColumns = 2; + WidgetFactory.label(SWT.NONE).text(PDEUIMessages.UpdatesSection_Name).create(comp); + fName = WidgetFactory.text(SWT.BORDER).create(comp); WidgetFactory.label(SWT.NONE).text(PDEUIMessages.UpdatesSection_Location).create(comp); fLocation = WidgetFactory.text(SWT.BORDER).create(comp); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); fLocation.setLayoutData(data); + fName.setLayoutData(data); DropTarget target = new DropTarget(fLocation, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK); target.setTransfer(new Transfer[] { URLTransfer.getInstance(), FileTransfer.getInstance() }); target.addDropListener(new TextURLDropAdapter(fLocation, true)); fLocation.addModifyListener(e -> validate()); + fName.addModifyListener(e -> validate()); if (fRepoURL != null) { fLocation.setText(fRepoURL); } + if (fNameStr != null) { + fName.setText(fNameStr); + } validate(); return comp; } protected void validate() { - fLocationStr = fLocation.getText().trim(); - updateStatus(isValidURL(fLocationStr)); + result = new RepositoryResult(fName.getText().trim(), fLocation.getText().trim()); + updateStatus(isValidURL(result.url())); } private IStatus isValidURL(String location) { @@ -116,8 +126,11 @@ protected Control createHelpControl(Composite parent) { * * @return the repository URL */ - public String getResult() { - return fLocationStr; + public RepositoryResult getResult() { + return result; + } + + public record RepositoryResult(String name, String url) { } -} \ No newline at end of file +} diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/RepositoryReferenceSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/RepositoryReferenceSection.java index 66bd154de95..d2b65193ab4 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/RepositoryReferenceSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/RepositoryReferenceSection.java @@ -35,6 +35,7 @@ import org.eclipse.pde.internal.ui.PDEPluginImages; import org.eclipse.pde.internal.ui.PDEUIMessages; import org.eclipse.pde.internal.ui.dialogs.RepositoryDialog; +import org.eclipse.pde.internal.ui.dialogs.RepositoryDialog.RepositoryResult; import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; import org.eclipse.pde.internal.ui.editor.PDEFormPage; import org.eclipse.pde.internal.ui.editor.TableSection; @@ -76,7 +77,7 @@ public Object[] getElements(Object inputElement) { private class LabelProvider extends PDELabelProvider { @Override public Image getColumnImage(Object obj, int index) { - if (index == 0) + if (index == 1) return get(PDEPluginImages.DESC_REPOSITORY_OBJ); return null; } @@ -85,8 +86,9 @@ public Image getColumnImage(Object obj, int index) { public String getColumnText(Object obj, int index) { IRepositoryReference repo = (IRepositoryReference) obj; return switch (index) { - case 0 -> repo.getURL(); - case 1 -> Boolean.toString(repo.getEnabled()); + case 0 -> repo.getName(); + case 1 -> repo.getURL(); + case 2 -> Boolean.toString(repo.getEnabled()); default -> null; }; } @@ -129,13 +131,17 @@ protected void createClient(Section section, FormToolkit toolkit) { final Table table = fRepositoryTable.getTable(); + final TableColumn nameColumn = new TableColumn(table, SWT.LEFT); + nameColumn.setText(PDEUIMessages.UpdatesSection_NameColumn); + nameColumn.setWidth(120); + final TableColumn locationColumn = new TableColumn(table, SWT.LEFT); locationColumn.setText(PDEUIMessages.UpdatesSection_LocationColumn); - locationColumn.setWidth(240); + locationColumn.setWidth(200); final TableColumn enabledColumn = new TableColumn(table, SWT.LEFT); enabledColumn.setText(PDEUIMessages.UpdatesSection_EnabledColumn); - enabledColumn.setWidth(120); + enabledColumn.setWidth(80); GridData data = (GridData) tablePart.getControl().getLayoutData(); data.minimumWidth = 200; @@ -155,8 +161,9 @@ public void controlMoved(ControlEvent e) { @Override public void controlResized(ControlEvent e) { int size = table.getSize().x; - locationColumn.setWidth(size / 6 * 5); - enabledColumn.setWidth(size / 6 * 1); + locationColumn.setWidth(size / 7 * 4); + enabledColumn.setWidth(size / 7 * 1); + nameColumn.setWidth(size / 7 * 2); } }); @@ -215,28 +222,30 @@ private void handleEdit(IStructuredSelection selection) { clearEditors(); if (!selection.isEmpty()) { IRepositoryReference repo = (IRepositoryReference) selection.toArray()[0]; - RepositoryDialog dialog = getRepositoryDialog(repo.getURL()); + RepositoryDialog dialog = getRepositoryDialog(repo.getName(), repo.getURL()); if (dialog.open() == Window.OK) { updateModel(repo, dialog.getResult()); } } } - private RepositoryDialog getRepositoryDialog(String repoURL) { - RepositoryDialog dialog = new RepositoryDialog(PDEPlugin.getActiveWorkbenchShell(), repoURL); + private RepositoryDialog getRepositoryDialog(String name, String repoURL) { + RepositoryDialog dialog = new RepositoryDialog(PDEPlugin.getActiveWorkbenchShell(), repoURL, name); dialog.setTitle(PDEUIMessages.RepositorySection_title); return dialog; } - private void updateModel(IRepositoryReference repo, String repoURL) { + private void updateModel(IRepositoryReference repo, RepositoryResult result) { try { if (repo != null) { getSite().removeRepositoryReferences(new IRepositoryReference[] { repo }); } ISiteModelFactory factory = getModel().getFactory(); IRepositoryReference newRepo = factory.createRepositoryReference(); - newRepo.setURL(repoURL.trim()); + newRepo.setURL(result.url().trim()); newRepo.setEnabled(true); + if (result.name() != null) + newRepo.setName(result.name().trim()); getSite().addRepositoryReferences(new IRepositoryReference[] { newRepo }); fRepositoryTable.refresh(); fRepositoryTable.setSelection(new StructuredSelection(newRepo)); @@ -276,7 +285,7 @@ private void handleRemoveAll() { private void handleAdd() { clearEditors(); - RepositoryDialog dialog = getRepositoryDialog(null); + RepositoryDialog dialog = getRepositoryDialog(null, null); if (dialog.open() == Window.OK) { updateModel(null, dialog.getResult()); } @@ -358,17 +367,17 @@ private void showControls() { final IRepositoryReference repo = (IRepositoryReference) selection.getFirstElement(); final CCombo combo = new CCombo(table, SWT.BORDER | SWT.READ_ONLY); combo.setItems(new String[] {Boolean.toString(true), Boolean.toString(false)}); - combo.setText(item.getText(1)); + combo.setText(item.getText(2)); combo.pack(); combo.addSelectionListener(widgetSelectedAdapter(e -> { - item.setText(1, combo.getText()); + item.setText(2, combo.getText()); try { repo.setEnabled(Boolean.parseBoolean(combo.getText())); } catch (CoreException ex) { PDEPlugin.log(ex); } })); - fEnabledColumnEditor.setEditor(combo, item, 1); + fEnabledColumnEditor.setEditor(combo, item, 2); } } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/UpdatesSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/UpdatesSection.java index a2ba60a8642..73a1c174192 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/UpdatesSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/UpdatesSection.java @@ -35,6 +35,7 @@ import org.eclipse.pde.internal.ui.PDEPluginImages; import org.eclipse.pde.internal.ui.PDEUIMessages; import org.eclipse.pde.internal.ui.dialogs.RepositoryDialog; +import org.eclipse.pde.internal.ui.dialogs.RepositoryDialog.RepositoryResult; import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; import org.eclipse.pde.internal.ui.editor.PDEFormPage; import org.eclipse.pde.internal.ui.editor.TableSection; @@ -75,7 +76,7 @@ public Object[] getElements(Object inputElement) { private class LabelProvider extends PDELabelProvider { @Override public Image getColumnImage(Object obj, int index) { - if (index == 0) + if (index == 1) return get(PDEPluginImages.DESC_REPOSITORY_OBJ); return null; } @@ -85,8 +86,9 @@ public String getColumnText(Object obj, int index) { IRepositoryInfo repo = (IRepositoryInfo) obj; return switch (index) { - case 0 -> repo.getURL(); - case 1 -> Boolean.toString(repo.getEnabled()); + case 0 -> repo.getName(); + case 1 -> repo.getURL(); + case 2 -> Boolean.toString(repo.getEnabled()); default -> null; }; } @@ -126,13 +128,17 @@ protected void createClient(Section section, FormToolkit toolkit) { final Table table = fRepositoryTable.getTable(); + final TableColumn nameColumn = new TableColumn(table, SWT.LEFT); + nameColumn.setText(PDEUIMessages.UpdatesSection_NameColumn); + nameColumn.setWidth(120); + final TableColumn locationColumn = new TableColumn(table, SWT.LEFT); locationColumn.setText(PDEUIMessages.UpdatesSection_LocationColumn); - locationColumn.setWidth(240); + locationColumn.setWidth(200); final TableColumn enabledColumn = new TableColumn(table, SWT.LEFT); enabledColumn.setText(PDEUIMessages.UpdatesSection_EnabledColumn); - enabledColumn.setWidth(120); + enabledColumn.setWidth(80); GridData data = (GridData) tablePart.getControl().getLayoutData(); data.minimumWidth = 200; @@ -152,8 +158,9 @@ public void controlMoved(ControlEvent e) { @Override public void controlResized(ControlEvent e) { int size = table.getSize().x; - locationColumn.setWidth(size / 6 * 5); - enabledColumn.setWidth(size / 6 * 1); + locationColumn.setWidth(size / 7 * 4); + enabledColumn.setWidth(size / 7 * 1); + nameColumn.setWidth(size / 7 * 2); } }); @@ -209,26 +216,28 @@ private void handleEdit(IStructuredSelection selection) { clearEditors(); if (!selection.isEmpty()) { IRepositoryInfo repoInfo = (IRepositoryInfo) selection.toArray()[0]; - RepositoryDialog dialog = getRepositoryDialog(repoInfo.getURL()); + RepositoryDialog dialog = getRepositoryDialog(repoInfo.getURL(), repoInfo.getName()); if (dialog.open() == Window.OK) { updateModel(repoInfo, dialog.getResult()); } } } - private RepositoryDialog getRepositoryDialog(String repoURL) { - RepositoryDialog dialog = new RepositoryDialog(PDEPlugin.getActiveWorkbenchShell(), repoURL); + private RepositoryDialog getRepositoryDialog(String repoURL, String name) { + RepositoryDialog dialog = new RepositoryDialog(PDEPlugin.getActiveWorkbenchShell(), repoURL, name); dialog.setTitle(PDEUIMessages.UpdatesSection_RepositoryDialogTitle); return dialog; } - private void updateModel(IRepositoryInfo pRepositoryInfo, String pURL) { + private void updateModel(IRepositoryInfo pRepositoryInfo, RepositoryResult result) { if (pRepositoryInfo != null) { getProduct().removeRepositories(new IRepositoryInfo[] { pRepositoryInfo }); } IProductModelFactory factory = getModel().getFactory(); IRepositoryInfo repo = factory.createRepositoryInfo(); - repo.setURL(pURL.trim()); + if (result.name() != null) + repo.setName(result.name().trim()); + repo.setURL(result.url().trim()); repo.setEnabled(true); getProduct().addRepositories(new IRepositoryInfo[] { repo }); fRepositoryTable.refresh(); @@ -258,7 +267,7 @@ private void handleRemoveAll() { private void handleAdd() { clearEditors(); - RepositoryDialog dialog = getRepositoryDialog(null); + RepositoryDialog dialog = getRepositoryDialog(null, null); if (dialog.open() == Window.OK) { updateModel(null, dialog.getResult()); } @@ -348,13 +357,13 @@ private void showControls() { final IRepositoryInfo repo = (IRepositoryInfo) selection.getFirstElement(); final CCombo combo = new CCombo(table, SWT.BORDER | SWT.READ_ONLY); combo.setItems(new String[] { Boolean.toString(true), Boolean.toString(false) }); - combo.setText(item.getText(1)); + combo.setText(item.getText(2)); combo.pack(); combo.addSelectionListener(widgetSelectedAdapter(e -> { - item.setText(1, combo.getText()); + item.setText(2, combo.getText()); repo.setEnabled(Boolean.parseBoolean(combo.getText())); })); - fEnabledColumnEditor.setEditor(combo, item, 1); + fEnabledColumnEditor.setEditor(combo, item, 2); } } } 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 adce7fc4005..cf7c3f47dc8 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 @@ -2568,11 +2568,13 @@ UpdatesSection_description=Specify the repository locations for product updates. Enabled repositories are always contacted for updates. Disabled repositories are added to the preference list but must be explicitly enabled by the user in order to be contacted. UpdatesSection_RepositoryDialogTitle=Repository Location UpdatesSection_Location=Enter a URL: +UpdatesSection_Name=Enter a name: UpdatesSection_ErrorLocationNoName=You must specify a URL for the repository location. UpdatesSection_ErrorInvalidURL=The location specified for the repository is not a valid URL. UpdatesSection_LocationColumn=Location UpdatesSection_LocationMessage=A valid http://, https://, or file:/ URL UpdatesSection_EnabledColumn=Enabled +UpdatesSection_NameColumn=Name CustomizationPage_title=Customization PreferencesSection_title=Default Preferences