|
16 | 16 | import java.util.ArrayList; |
17 | 17 | import java.util.HashSet; |
18 | 18 | import java.util.Set; |
| 19 | +import java.util.function.UnaryOperator; |
19 | 20 |
|
20 | 21 | import org.eclipse.core.runtime.IStatus; |
21 | 22 | import org.eclipse.core.runtime.Status; |
|
39 | 40 | import org.eclipse.pde.internal.ui.util.PDELabelUtility; |
40 | 41 | import org.eclipse.swt.SWT; |
41 | 42 | import org.eclipse.swt.events.ModifyListener; |
| 43 | +import org.eclipse.swt.events.SelectionListener; |
42 | 44 | import org.eclipse.swt.layout.GridData; |
43 | 45 | import org.eclipse.swt.layout.GridLayout; |
44 | 46 | import org.eclipse.swt.widgets.Button; |
@@ -172,7 +174,6 @@ public Object[] getElements(Object inputElement) { |
172 | 174 |
|
173 | 175 | } |
174 | 176 |
|
175 | | - |
176 | 177 | private Text fMinVersionText; |
177 | 178 | private Text fMaxVersionText; |
178 | 179 | private Combo fMinVersionBound; |
@@ -288,6 +289,34 @@ private void createSingleField(Composite parent, boolean createGroup, boolean ed |
288 | 289 | fMinVersionText = new Text(parent, SWT.SINGLE | SWT.BORDER); |
289 | 290 | fMinVersionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
290 | 291 | fMinVersionText.setEnabled(editable); |
| 292 | + |
| 293 | + if (!fRangeAllowed) { |
| 294 | + Label incrLabel = new Label(parent, SWT.NONE); |
| 295 | + incrLabel.setText(PDEUIMessages.PluginVersionPart_incrementTitle); |
| 296 | + incrLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); |
| 297 | + |
| 298 | + Composite btnBar = new Composite(parent, SWT.NONE); |
| 299 | + btnBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 300 | + GridLayout btnBarLayout = new GridLayout(3, true); |
| 301 | + btnBarLayout.marginWidth = 0; |
| 302 | + btnBar.setLayout(btnBarLayout); |
| 303 | + |
| 304 | + // Major Button |
| 305 | + Button majorBtn = createIncrementButton(btnBar, PDEUIMessages.PluginVersionPart_incrementMajor, editable, |
| 306 | + v -> new Version(v.getMajor() + 1, 0, 0)); |
| 307 | + // Minor Button |
| 308 | + Button minorBtn = createIncrementButton(btnBar, PDEUIMessages.PluginVersionPart_incrementMinor, editable, |
| 309 | + v -> new Version(v.getMajor(), v.getMinor() + 1, 0)); |
| 310 | + // Micro Button |
| 311 | + Button microBtn = createIncrementButton(btnBar, PDEUIMessages.PluginVersionPart_incrementMicro, editable, |
| 312 | + v -> new Version(v.getMajor(), v.getMinor(), v.getMicro() + 1)); |
| 313 | + |
| 314 | + if (editable) { |
| 315 | + // Initially disable buttons if editable but no valid version |
| 316 | + updateIncrementButtonsEnabled(majorBtn, minorBtn, microBtn); |
| 317 | + fMinVersionText.addModifyListener(e -> updateIncrementButtonsEnabled(majorBtn, minorBtn, microBtn)); |
| 318 | + } |
| 319 | + } |
291 | 320 | } |
292 | 321 |
|
293 | 322 | public void preloadFields() { |
@@ -454,4 +483,38 @@ public void addListeners(ModifyListener minListener, ModifyListener maxListener) |
454 | 483 | protected String getGroupText() { |
455 | 484 | return PDEUIMessages.DependencyPropertiesDialog_groupText; |
456 | 485 | } |
| 486 | + |
| 487 | + private Button createIncrementButton(Composite btnBar, String label, boolean enabled, |
| 488 | + UnaryOperator<Version> versionModifier) { |
| 489 | + Button btn = new Button(btnBar, SWT.PUSH); |
| 490 | + btn.setText(label); |
| 491 | + btn.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { |
| 492 | + String originalText = getMinVersion(); |
| 493 | + Version originalVersion = new Version(originalText); |
| 494 | + String target = versionModifier.apply(originalVersion).toString(); |
| 495 | + String qualifier = originalVersion.getQualifier(); |
| 496 | + if (!qualifier.isEmpty()) { |
| 497 | + target += "." + qualifier; //$NON-NLS-1$ |
| 498 | + } |
| 499 | + setVersion(target); |
| 500 | + preloadFields(); |
| 501 | + })); |
| 502 | + btn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 503 | + btn.setEnabled(enabled); |
| 504 | + return btn; |
| 505 | + } |
| 506 | + |
| 507 | + private void updateIncrementButtonsEnabled(Button majorBtn, Button minorBtn, Button microBtn) { |
| 508 | + boolean valid = VersionUtil.validateVersion(getMinVersion()).isOK(); |
| 509 | + if (majorBtn != null && !majorBtn.isDisposed()) { |
| 510 | + majorBtn.setEnabled(valid); |
| 511 | + } |
| 512 | + if (minorBtn != null && !minorBtn.isDisposed()) { |
| 513 | + minorBtn.setEnabled(valid); |
| 514 | + } |
| 515 | + if (microBtn != null && !microBtn.isDisposed()) { |
| 516 | + microBtn.setEnabled(valid); |
| 517 | + } |
| 518 | + } |
| 519 | + |
457 | 520 | } |
0 commit comments