Skip to content

Switch branch Action #286

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
Binary file added org.abapgit.adt.ui/icons/etool/branches_obj.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.abapgit.adt.ui/icons/etool/switchToTree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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_switch_branch;
public static String AbapGitDialogPageObjLog_default_filename;
public static String AbapGitView_action_clone;
public static String AbapGitView_action_refresh;
Expand Down Expand Up @@ -138,6 +139,11 @@ public class Messages extends NLS {
public static String AbapGitDialogPageObjLog_pull_title;
public static String AbapGitDialogPageObjLog_push_description;
public static String AbapGitDialogPageObjLog_push_title;
public static String AbapGitWizardPageSwitch_branch_selection_title;
public static String AbapGitWizardPageSwitch_branch_credentials_title;
public static String AbapGitWizardPageSwitch_select_branch_description;
public static String AbapGitWizardPageSwitch_credentials_description;
public static String AbapGitWizardSwitch_branch_wizard_title;

//ABAPGIT STAGING MESSAGES
public static String AbapGitStaging_no_repository_selected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ 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_switch_branch=Switch Branch...
AbapGitWizardSwitch_branch_wizard_title=Switch Branch
AbapGitWizardPageSwitch_branch_selection_title=Branch Selection
AbapGitWizardPageSwitch_branch_credentials_title=User Authentication
AbapGitWizardPageSwitch_select_branch_description=Select the branch.
AbapGitWizardPageSwitch_credentials_description=Specify credentials for git repository.
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,
actionSwitchBranch;
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.actionSwitchBranch);
//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.actionSwitchBranch = 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,53 @@
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.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_switch_branch);
setToolTipText(Messages.AbapGitView_action_switch_branch);

setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(AbapGitUIPlugin.PLUGIN_ID, "/icons/etool/branches_obj.png")); //$NON-NLS-1$
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,160 @@
package org.abapgit.adt.ui.internal.wizards;

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.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 final 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();
this.abapGitService = AbapGitUIServiceFactory.createAbapGitService();
getPackageAndRepoType();

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

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) {
((WizardPage) getContainer().getCurrentPage()).setMessage(e.getMessage(), DialogPage.ERROR);
}
return true;
}

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;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public class AbapGitWizardPageBranchAndPackage extends WizardPage {
private final CloneData cloneData;
private final String pullBranch;

private Button checkbox_lnp;
protected Button checkbox_lnp;
private Boolean chboxLinkAndPull;
private TextViewer txtPackage;
private ComboViewer comboBranches;
protected ComboViewer comboBranches;

private final Boolean pullAction;
private boolean backButtonEnabled = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.abapgit.adt.ui.internal.wizards;

import org.abapgit.adt.ui.internal.i18n.Messages;
import org.abapgit.adt.ui.internal.wizards.AbapGitWizard.CloneData;
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);
setTitle(Messages.AbapGitWizardPageSwitch_branch_selection_title);
setDescription(Messages.AbapGitWizardPageSwitch_select_branch_description);
}

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

if (visible) {
this.comboBranches.getCombo().setEnabled(true);
// hiding the pull after link checkbox
this.checkbox_lnp.setVisible(false);
}
}

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

}
Loading