diff options
author | Thomas Wolf | 2018-10-23 09:13:14 +0000 |
---|---|---|
committer | Thomas Wolf | 2018-10-23 09:13:14 +0000 |
commit | a93f27754122f0a1fd32b9a8e5aaf940df88e460 (patch) | |
tree | 3d47c40a93460b7a49de80d7ede6ec37898d3fd4 /org.eclipse.egit.ui | |
parent | 16364e86235a5c7ba1d58c2cb0120d6a21a71b2e (diff) | |
download | egit-a93f27754122f0a1fd32b9a8e5aaf940df88e460.tar.gz egit-a93f27754122f0a1fd32b9a8e5aaf940df88e460.tar.xz egit-a93f27754122f0a1fd32b9a8e5aaf940df88e460.zip |
Fetch from Gerrit: handle double-click in repo selection dialog
The GitSelectRepositoryPage already would move on to the next page
in the wizard on a double-click on a repository. Expand that to
finish the dialog if there is no next page (and the wizard _can_
be finished).
Also re-order the control creation such that the setup of the viewer
is all in one place. (Except setting its input, which happens later).
Change-Id: I1ac5eaaf4a093d62eb2d55e00931c003c177cdd9
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui')
4 files changed, 86 insertions, 20 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitSelectRepositoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitSelectRepositoryPage.java index 753ca033fe..3e65d5b7ba 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitSelectRepositoryPage.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitSelectRepositoryPage.java @@ -28,6 +28,7 @@ import org.eclipse.egit.core.RepositoryUtil; import org.eclipse.egit.core.internal.gerrit.GerritUtil; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.internal.UIText; +import org.eclipse.egit.ui.internal.dialogs.FinishableWizardDialog; import org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider; import org.eclipse.egit.ui.internal.repository.RepositorySearchWizard; import org.eclipse.egit.ui.internal.repository.RepositoryTreeNodeLabelProvider; @@ -46,6 +47,8 @@ import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.IWizardContainer; +import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.jgit.lib.Repository; @@ -177,21 +180,6 @@ public class GitSelectRepositoryPage extends WizardPage { } }); tv.setLabelProvider(new RepositoryTreeNodeLabelProvider()); - - - if (!allowBare) { - bareMsg = new Composite(main, SWT.NONE); - bareMsg.setLayout(new RowLayout()); - bareMsg.setLayoutData( - GridDataFactory.fillDefaults().grab(true, false).create()); - Label imageLabel = new Label(bareMsg, SWT.NONE); - imageLabel.setImage( - JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO)); - Label textLabel = new Label(bareMsg, SWT.WRAP); - textLabel.setText( - UIText.GitSelectRepositoryPage_BareRepositoriesHidden); - bareMsg.setVisible(false); - } tv.addSelectionChangedListener(new ISelectionChangedListener() { @Override @@ -205,13 +193,33 @@ public class GitSelectRepositoryPage extends WizardPage { @Override public void doubleClick(DoubleClickEvent event) { checkPage(); - if (isPageComplete()) - getContainer().showPage(getNextPage()); + if (isPageComplete()) { + IWizardContainer container = getContainer(); + IWizardPage next = getNextPage(); + if (next != null) { + container.showPage(next); + } else if (container instanceof FinishableWizardDialog) { + ((FinishableWizardDialog) container).finish(); + } + } } }); - if (allowAdd) { + if (!allowBare) { + bareMsg = new Composite(main, SWT.NONE); + bareMsg.setLayout(new RowLayout()); + bareMsg.setLayoutData( + GridDataFactory.fillDefaults().grab(true, false).create()); + Label imageLabel = new Label(bareMsg, SWT.NONE); + imageLabel.setImage( + JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO)); + Label textLabel = new Label(bareMsg, SWT.WRAP); + textLabel.setText( + UIText.GitSelectRepositoryPage_BareRepositoriesHidden); + bareMsg.setVisible(false); + } + if (allowAdd) { Composite tb = new Composite(main, SWT.NONE); GridLayoutFactory.fillDefaults().numColumns(1).applyTo(tb); GridDataFactory.fillDefaults().grab(false, true).applyTo(tb); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/FetchChangeFromGerritCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/FetchChangeFromGerritCommand.java index 025ee5a539..9ab06a513d 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/FetchChangeFromGerritCommand.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/FetchChangeFromGerritCommand.java @@ -15,6 +15,7 @@ package org.eclipse.egit.ui.internal.commands.shared; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.egit.ui.internal.UIText; +import org.eclipse.egit.ui.internal.dialogs.MinimumSizeWizardDialog; import org.eclipse.egit.ui.internal.dialogs.NonBlockingWizardDialog; import org.eclipse.egit.ui.internal.fetch.FetchGerritChangeWizard; import org.eclipse.egit.ui.internal.gerrit.GerritSelectRepositoryPage; @@ -54,7 +55,8 @@ public class FetchChangeFromGerritCommand extends AbstractSharedCommandHandler { }; wizard.addPage(page); wizard.setWindowTitle(UIText.GerritSelectRepositoryPage_PageTitle); - WizardDialog wizardDialog = new WizardDialog(shell, wizard) { + WizardDialog wizardDialog = new MinimumSizeWizardDialog(shell, + wizard) { @Override protected Button createButton(Composite parent, int id, String label, boolean defaultButton) { diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/FinishableWizardDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/FinishableWizardDialog.java new file mode 100644 index 0000000000..314ea7ca88 --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/FinishableWizardDialog.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.egit.ui.internal.dialogs; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Shell; + +/** + * A {@link WizardDialog} that can be programmatically finished. + */ +public class FinishableWizardDialog extends WizardDialog { + + /** + * Creates a new wizard dialog for the given wizard. + * + * @param parentShell + * the parent shell + * @param newWizard + * the wizard this dialog is working on + */ + public FinishableWizardDialog(Shell parentShell, IWizard newWizard) { + super(parentShell, newWizard); + } + + /** + * Tries to finish the wizard dialog as if the "Finish" button had been + * clicked. Does nothing if the "Finish" button is not enabled or the wizard + * cannot finish. + * + * @return whether the dialog was closed + */ + public boolean finish() { + Button finishButton = getButton(IDialogConstants.FINISH_ID); + if (finishButton.isEnabled() && getWizard().canFinish()) { + // Probably checking both the button and the wizard is a bit + // paranoid, especially since finishPressed only does something if + // wizard.performFinish() == true, but yes, let's be paranoid and + // not rely on implementation details. The javadoc of finishPressed + // makes no promises. + finishPressed(); + return getShell() == null || getShell().isDisposed(); + } + return false; + } +} diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MinimumSizeWizardDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MinimumSizeWizardDialog.java index 37edb878c7..befc19654d 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MinimumSizeWizardDialog.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MinimumSizeWizardDialog.java @@ -20,7 +20,7 @@ import org.eclipse.swt.widgets.Shell; * A {@link WizardDialog} that can prevent making the dialog smaller than the * size needed to show the starting page. */ -public class MinimumSizeWizardDialog extends WizardDialog { +public class MinimumSizeWizardDialog extends FinishableWizardDialog { private final boolean restrictResize; |