Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support names for Updates repositories in product definition #824

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ public interface IRepositoryInfo extends IProductObject {

void setURL(String url);

String getName();

void setName(String name);

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ public interface IRepositoryReference extends ISiteObject {

void setURL(String url) throws CoreException;

String getName();

void setName(String name) throws CoreException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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);
}
}
Expand All @@ -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 + "<repository location=\"" + fURL + "\""); //$NON-NLS-1$ //$NON-NLS-2$
if (fName != null) {
writer.print(" name=\"" + fName + "\""); //$NON-NLS-1$//$NON-NLS-2$
}
writer.print(" enabled=\"" + fEnabled + "\""); //$NON-NLS-1$//$NON-NLS-2$
writer.println(" />"); //$NON-NLS-1$
}
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
Expand All @@ -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));
}
}
Expand All @@ -73,6 +89,9 @@ public void parse(Node node) {
public void write(String indent, PrintWriter writer) {
if (isURLDefined()) {
writer.print(indent + "<repository-reference location=\"" + fURL + "\""); //$NON-NLS-1$ //$NON-NLS-2$
if (fName != null) {
writer.print(" name=\"" + fName + "\""); //$NON-NLS-1$//$NON-NLS-2$
}
writer.print(" enabled=\"" + fEnabled + "\""); //$NON-NLS-1$//$NON-NLS-2$
writer.println(" />"); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3071,13 +3071,16 @@ 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;

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,44 +44,54 @@
*/
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
* the shell to use for the dialog which may not be null
* @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) {
Expand Down Expand Up @@ -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();
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,17 +77,19 @@ 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) {
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;
};
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading
Loading