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 e5716fa6f3..8287157b83 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 1de160d79f..d9509b7b10 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 9df8e8ba14..f98e45c507 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 @@ -26,9 +26,11 @@ public class RepositoryInfo extends ProductObject implements IRepositoryInfo { private static final long serialVersionUID = 1L; public static final String P_LOCATION = "location"; //$NON-NLS-1$ + public static final String P_NAME = "name"; //$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) { @@ -49,6 +51,20 @@ public String getURL() { return fURL; } + @Override + public String getName() { + return fName; + } + + @Override + public void setName(String name) { + String old = fName; + fName = name; + if (isEditable()) { + firePropertyChanged(P_NAME, old, fName); + } + } + @Override public boolean getEnabled() { return fEnabled; @@ -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,15 +84,18 @@ 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)); } } - @Override public void write(String indent, PrintWriter writer) { if (isURLDefined()) { writer.print(indent + ""); //$NON-NLS-1$ } @@ -99,7 +118,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 66101e485a..b017e65461 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 @@ -25,9 +25,11 @@ public class RepositoryReference extends SiteObject implements IRepositoryRefere private static final long serialVersionUID = 1L; public static final String P_LOCATION = "location"; //$NON-NLS-1$ + public static final String P_NAME = "name"; //$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 RepositoryReference() { @@ -47,6 +49,19 @@ public String getURL() { return fURL; } + @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 boolean getEnabled() { return fEnabled; @@ -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,9 @@ 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 40f3c7d6d9..04299c5383 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 955adef1fd..2a57c3d113 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(), fLocation.getText()); + updateStatus(isValidURL(result.url())); } private IStatus isValidURL(String location) { @@ -116,8 +126,15 @@ 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) { + public RepositoryResult { + name = name == null || name.isBlank() ? null : name.strip(); + url = url.strip(); + } } -} \ 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 66bd154de9..a33951cf9a 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,8 +77,9 @@ 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 +87,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 +132,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 +162,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); + nameColumn.setWidth(size / 7 * 2); + locationColumn.setWidth(size / 7 * 4); + enabledColumn.setWidth(size / 7 * 1); } }); @@ -215,27 +223,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()); + if (result.name() != null) { + newRepo.setName(result.name()); + } + newRepo.setURL(result.url()); newRepo.setEnabled(true); getSite().addRepositoryReferences(new IRepositoryReference[] { newRepo }); fRepositoryTable.refresh(); @@ -276,7 +287,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 +369,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 a2ba60a864..a6a34cec89 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,20 +76,21 @@ 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; } @Override public String getColumnText(Object obj, int index) { IRepositoryInfo repo = (IRepositoryInfo) obj; - return switch (index) - { - case 0 -> repo.getURL(); - case 1 -> Boolean.toString(repo.getEnabled()); + return switch (index) { + 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); + nameColumn.setWidth(size / 7 * 2); + locationColumn.setWidth(size / 7 * 4); + enabledColumn.setWidth(size / 7 * 1); } }); @@ -209,26 +216,29 @@ 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()); + } + repo.setURL(result.url()); repo.setEnabled(true); getProduct().addRepositories(new IRepositoryInfo[] { repo }); fRepositoryTable.refresh(); @@ -258,7 +268,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 +358,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 adce7fc400..cf7c3f47dc 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