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

Switch branch Action #286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -4,6 +4,7 @@

public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.abapgit.adt.ui.internal.i18n.messages"; //$NON-NLS-1$
public static String AbapGitView_action_select_branch;
public static String AbapGitDialogPageObjLog_default_filename;
public static String AbapGitView_action_clone;
public static String AbapGitView_action_refresh;
Expand Down Expand Up @@ -202,6 +203,7 @@ public class Messages extends NLS {
public static String AbapGitStagingView_TransportWBKey;
public static String AbapGitStagingView_PackageRel;
public static String AbapGitStagingView_TransportRel;
public static String AbapGitWizardPageRepositoryAndCredentials_select_branch_title;

static {
// initialize resource bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ AbapGitView_action_open_repo=Open Repository in Browser
AbapGitView_action_open_repo_tooltip=Open Repository in Browser
AbapGitView_action_open_repo_error_dialog_title=Error while opening repository in browser
AbapGitView_action_open_xtol=Open Linked Package
AbapGitView_action_select_branch=Switch Branch
AbapGitWizardPageRepositoryAndCredentials_select_branch_title=Select Branch
AbapGitView_column_branch=Branch
AbapGitView_column_firstcommitat=Last Changed (UTC)
AbapGitView_column_folder_logic=Folder Logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.abapgit.adt.ui.internal.dialogs.AbapGitDialogObjLog;
import org.abapgit.adt.ui.internal.i18n.Messages;
import org.abapgit.adt.ui.internal.repositories.actions.OpenRepositoryAction;
import org.abapgit.adt.ui.internal.repositories.actions.SwitchbranchAction;
import org.abapgit.adt.ui.internal.staging.AbapGitStagingView;
import org.abapgit.adt.ui.internal.staging.IAbapGitStagingView;
import org.abapgit.adt.ui.internal.util.AbapGitUIServiceFactory;
Expand Down Expand Up @@ -101,7 +102,8 @@ public class AbapGitView extends ViewPart implements IAbapGitRepositoriesView {
public static final String ID = "org.abapgit.adt.ui.views.AbapGitView"; //$NON-NLS-1$

protected TableViewer viewer;
protected Action actionRefresh, actionWizard, actionCopy, actionOpen, actionShowMyRepos, actionPullWizard, actionOpenRepository;
protected Action actionRefresh, actionWizard, actionCopy, actionOpen, actionShowMyRepos, actionPullWizard, actionOpenRepository,
actionSwitch;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to actionSwitchBranch to avoid ambiguity with other possible actions like switching folder logic.

private ISelection lastSelection;
protected IProject lastProject;
private ViewerFilter searchFilter;
Expand All @@ -113,6 +115,10 @@ public class AbapGitView extends ViewPart implements IAbapGitRepositoriesView {
//key binding for copy text
private static final KeyStroke KEY_STROKE_COPY = KeyStroke.getInstance(SWT.MOD1, 'C' | 'c');

public void refresh() {
updateView(true);
}

private final ISelectionListener selectionListener = new ISelectionListener() {
private boolean isUpdatingSelection = false;
@Override
Expand Down Expand Up @@ -403,6 +409,10 @@ public void menuAboutToShow(IMenuManager manager) {
}
//separator
manager.add(new Separator());
//switch Branch Action
manager.add(AbapGitView.this.actionSwitch);
//separator
manager.add(new Separator());
//copy to clip-board action
manager.add(AbapGitView.this.actionCopy);
//unlink action
Expand Down Expand Up @@ -564,6 +574,9 @@ public void run() {

//Open repository in external browser
this.actionOpenRepository = new OpenRepositoryAction(this);

//Switch Branches
this.actionSwitch = new SwitchbranchAction(this);
}

private List<IRepository> getRepositories(String destinationId, Boolean byCurrUser) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.abapgit.adt.ui.internal.repositories.actions;

import org.abapgit.adt.backend.model.abapgitrepositories.IRepository;
import org.abapgit.adt.ui.AbapGitUIPlugin;
import org.abapgit.adt.ui.internal.i18n.Messages;
import org.abapgit.adt.ui.internal.repositories.AbapGitView;
import org.abapgit.adt.ui.internal.repositories.IAbapGitRepositoriesView;
import org.abapgit.adt.ui.internal.repositories.wizards.AbapGitWizardBranchSelection;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import com.sap.adt.tools.core.project.AdtProjectServiceFactory;

public class SwitchbranchAction extends Action {

private IRepository selRepo;
private final IViewPart view;
private IProject project;

public SwitchbranchAction(IViewPart view) {
super(Messages.AbapGitView_action_select_branch);
setToolTipText(Messages.AbapGitView_action_select_branch);
setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(AbapGitUIPlugin.PLUGIN_ID, "icons/etool/compare_view.png")); //$NON-NLS-1$
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check availability of any other icon.

this.view = view;
}

@Override
public void run() {
this.project = getProject();
this.selRepo = getRepository();
if (this.selRepo != null) {
String destination = AdtProjectServiceFactory.createProjectService().getDestinationId(this.project);
WizardDialog dialog = new WizardDialog(this.view.getViewSite().getShell(),
new AbapGitWizardBranchSelection(this.project, this.selRepo, destination));
dialog.open();
}

((AbapGitView) this.view).refresh();

}

private IRepository getRepository() {
return ((IAbapGitRepositoriesView) this.view).getRepositorySelection();
}

private IProject getProject() {
return ((IAbapGitRepositoriesView) this.view).getProject();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package org.abapgit.adt.ui.internal.repositories.wizards;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the classes to the package org.abapgit.adt.ui.internal.wizards.
Technically it's right to have repositories in the package name, but presently all wizards & related pages are only related to repositories view.

In future in case we have wizards also for staging view, in that case we can have this new package.


import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.abapgit.adt.backend.IExternalRepositoryInfoService;
import org.abapgit.adt.backend.IRepositoryService;
import org.abapgit.adt.backend.RepositoryServiceFactory;
import org.abapgit.adt.backend.model.abapgitrepositories.IRepository;
import org.abapgit.adt.ui.AbapGitUIPlugin;
import org.abapgit.adt.ui.internal.i18n.Messages;
import org.abapgit.adt.ui.internal.util.AbapGitUIServiceFactory;
import org.abapgit.adt.ui.internal.util.IAbapGitService;
import org.abapgit.adt.ui.internal.wizards.AbapGitWizard.CloneData;
import org.abapgit.adt.ui.internal.wizards.AbapGitWizardPageRepositoryAndCredentials;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.dialogs.IPageChangingListener;
import org.eclipse.jface.dialogs.PageChangingEvent;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import com.sap.adt.tools.core.model.adtcore.IAdtObjectReference;
import com.sap.adt.tools.core.ui.packages.AdtPackageServiceUIFactory;
import com.sap.adt.tools.core.ui.packages.IAdtPackageServiceUI;

public class AbapGitWizardBranchSelection extends Wizard {

private final IProject project;
final CloneData cloneData;
public IRepository selRepoData;
private final String destination;
private IAbapGitService abapGitService;
private PageChangeListener pageChangeListener;
AbapGitWizardPageRepositoryAndCredentials pageCredentials;
AbapGitWizardPageBranchSelection pageBranchAndPackage;

public AbapGitWizardBranchSelection(IProject project, IRepository selRepo, String destination) {
this.project = project;
this.cloneData = new CloneData();
this.destination = destination;
this.selRepoData = selRepo;
this.cloneData.url = selRepo.getUrl();
this.cloneData.branch = selRepo.getBranchName();
if (this.abapGitService == null) {
this.abapGitService = AbapGitUIServiceFactory.createAbapGitService();
}
Comment on lines +52 to +54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the object is created, abapGitService will always be null right?
So, is this check required ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true that's not required, will remove it.

getPackageAndRepoType();

setWindowTitle(Messages.AbapGitView_action_select_branch);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message variable can be renamed to AbapGitView_action_switch_branch.

setNeedsProgressMonitor(true);
setDefaultPageImageDescriptor(
AbstractUIPlugin.imageDescriptorFromPlugin(AbapGitUIPlugin.PLUGIN_ID, "icons/wizban/abapGit_import_wizban.png")); //$NON-NLS-1$
}

public Object getProject() {
return this.project;
}

public Object getSelectedRepository() {
return this.selRepoData;
}
Comment on lines +63 to +69
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these methods needed and used anywhere? I don't see its usage.


public boolean getPackageAndRepoType() {

try {
String packageName = AbapGitWizardBranchSelection.this.selRepoData.getPackage();
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {

@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.AbapGitWizardPageBranchAndPackage_task_package_validation_message, IProgressMonitor.UNKNOWN);

//Get repository type (public / private)
IExternalRepositoryInfoService externalRepoInfoService = RepositoryServiceFactory
.createExternalRepositoryInfoService(AbapGitWizardBranchSelection.this.destination, null);
AbapGitWizardBranchSelection.this.cloneData.externalRepoInfo = externalRepoInfoService
.getExternalRepositoryInfo(AbapGitWizardBranchSelection.this.selRepoData.getUrl(), "", "", null); //$NON-NLS-1$ //$NON-NLS-2$

IAdtPackageServiceUI packageServiceUI = AdtPackageServiceUIFactory.getOrCreateAdtPackageServiceUI();
if (packageServiceUI.packageExists(AbapGitWizardBranchSelection.this.destination, packageName, monitor)) {
List<IAdtObjectReference> packageRefs = packageServiceUI.find(AbapGitWizardBranchSelection.this.destination,
packageName, monitor);
AbapGitWizardBranchSelection.this.cloneData.packageRef = packageRefs.stream().findFirst().orElse(null);
}

}
});
return true;
} catch (InvocationTargetException e) {
return false;
} catch (InterruptedException e) {
((WizardPage) getContainer().getCurrentPage()).setPageComplete(false);
((WizardPage) getContainer().getCurrentPage()).setMessage(e.getMessage(), DialogPage.ERROR);
return false;
}

}

@Override
public void setContainer(IWizardContainer wizardContainer) {
super.setContainer(wizardContainer);

if (this.pageChangeListener == null && wizardContainer != null) {
Assert.isLegal(wizardContainer instanceof WizardDialog, "Wizard container must be of type WizardDialog"); //$NON-NLS-1$

this.pageChangeListener = new PageChangeListener();
((WizardDialog) wizardContainer).addPageChangingListener(this.pageChangeListener);

}
}

@Override
public void addPages() {
this.pageCredentials = new AbapGitWizardPageBranchSelectionCredentials(this.project, this.destination, this.cloneData);
this.pageBranchAndPackage = new AbapGitWizardPageBranchSelection(this.project, this.destination, this.cloneData, false);
addPage(this.pageCredentials);
addPage(this.pageBranchAndPackage);
}

@Override
public boolean performFinish() {
try {
getContainer().run(true, true, new IRunnableWithProgress() {

@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// Unlink
RepositoryServiceFactory
.createRepositoryService(AbapGitWizardBranchSelection.this.abapGitService
.getDestination(AbapGitWizardBranchSelection.this.project), monitor)
.unlinkRepository(AbapGitWizardBranchSelection.this.selRepoData.getKey(), monitor);
// Relink
IRepositoryService repoService = RepositoryServiceFactory
.createRepositoryService(AbapGitWizardBranchSelection.this.destination, monitor);
repoService.cloneRepository(AbapGitWizardBranchSelection.this.selRepoData.getUrl(),
AbapGitWizardBranchSelection.this.cloneData.branch, AbapGitWizardBranchSelection.this.selRepoData.getPackage(),
AbapGitWizardBranchSelection.this.selRepoData.getFolderLogic(),
AbapGitWizardBranchSelection.this.selRepoData.getTransportRequest(),
AbapGitWizardBranchSelection.this.cloneData.user, AbapGitWizardBranchSelection.this.cloneData.pass, monitor)
.getAbapObjects();
//
}
});
} catch (InvocationTargetException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
Comment on lines +152 to +156
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show the error message on the page if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

}

final class PageChangeListener implements IPageChangingListener {
@Override
public void handlePageChanging(final PageChangingEvent event) {
//-> Credentials page -> Branch & Package page
if (event.getCurrentPage() == AbapGitWizardBranchSelection.this.pageCredentials
&& event.getTargetPage() == AbapGitWizardBranchSelection.this.pageBranchAndPackage) {
if (!AbapGitWizardBranchSelection.this.pageCredentials.validateAll()) {
event.doit = false;
return;
}

}

//-> Branch & Package page -> Credentials page
if (event.getCurrentPage() == AbapGitWizardBranchSelection.this.pageBranchAndPackage
&& event.getTargetPage() == AbapGitWizardBranchSelection.this.pageCredentials) {
if (AbapGitWizardBranchSelection.this.pageBranchAndPackage.validateAll()) {
event.doit = false;
return;
}
}
Comment on lines +173 to +179
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation of content of current is not needed while going back in the wizard. This logic can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah true as we won't be navigating it back can remove this.

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.abapgit.adt.ui.internal.repositories.wizards;

import org.abapgit.adt.ui.internal.wizards.AbapGitWizard.CloneData;
import org.abapgit.adt.ui.internal.wizards.AbapGitWizardPageBranchAndPackage;
import org.eclipse.core.resources.IProject;

public class AbapGitWizardPageBranchSelection extends AbapGitWizardPageBranchAndPackage {

public AbapGitWizardPageBranchSelection(IProject project, String destination, CloneData cloneData, Boolean pullAction) {
super(project, destination, cloneData, pullAction);
}
Comment on lines +9 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also set a new title & description for the page. The parent page sets the title "Branch and Package Selection", but the branch selection wizard does not allow to select package.
Hence a new title & description should be set here.

Suggestion.
Title: Select Branch (Same as the credentials page)
Description: Select branch to switch from the dropdown


@Override
public void setVisible(boolean visible) {
super.setVisible(visible);

if (visible) {
this.comboBranches.getCombo().setEnabled(true);
}
}
Comment on lines +17 to +20
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's hide the pull after link checkbox.
Presently, the pull operation need not be combined with the switch branch operation.
We can enable it in future based on demand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.


@Override
public boolean canFlipToNextPage() {
return false;
}

}
Loading