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 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
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.
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,12 @@ 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;
public static String AbapGitWizardSwitch_branch_package_ref_not_found_error;

//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 Expand Up @@ -132,6 +138,7 @@ AbapGitWizardPageRepositoryAndCredentials_title=Link abapGit Repository
AbapGitWizardPageRepositoryAndCredentials_validate_password_error=Specify password or personal access token
AbapGitWizardPageRepositoryAndCredentials_validate_url_error=Enter a valid Git URL
AbapGitWizardPageRepositoryAndCredentials_validate_user_error=Specify user
AbapGitWizardSwitch_branch_package_ref_not_found_error=Could not find package ref for {0}

AbapGitStaging_no_repository_selected=No Repository Selected
AbapGitStaging_check_job_title=Repository checks
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.AbapGitWizardSwitchBranch;
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 AbapGitView;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can keep this view variable typed to AbapGitView itself i.e. private final AbapGitView 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.AbapGitView = 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.AbapGitView.getViewSite().getShell(),
new AbapGitWizardSwitchBranch(this.project, this.selRepo, destination));
dialog.open();
}

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

}

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

private IProject getProject() {
return ((IAbapGitRepositoriesView) this.AbapGitView).getProject();
}
}
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
Expand Up @@ -44,7 +44,7 @@ public class AbapGitWizardPageRepositoryAndCredentials extends WizardPage {
private final CloneData cloneData;

private Text txtURL;
private Text txtUser;
protected Text txtUser;
private Text txtPwd;
private Label lblUser;
private Label lblPwd;
Expand Down Expand Up @@ -189,7 +189,7 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte

}

private boolean validateClientOnly() {
protected boolean validateClientOnly() {
setMessage(null);
setPageComplete(true);

Expand Down Expand Up @@ -279,7 +279,7 @@ public boolean validateAll() {
return true;
}

private void fetchRepositories() {
protected void fetchRepositories() {
try {
getContainer().run(true, true, new IRunnableWithProgress() {

Expand All @@ -300,7 +300,7 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
}
}

private boolean fetchExternalRepoInfo() {
protected boolean fetchExternalRepoInfo() {
try {
getContainer().run(true, true, new IRunnableWithProgress() {

Expand Down Expand Up @@ -337,7 +337,7 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
}
}

private void setUserAndPassControlsVisible(boolean visible) {
protected void setUserAndPassControlsVisible(boolean visible) {
this.txtUser.setVisible(visible);
this.txtPwd.setVisible(visible);
this.lblUser.setVisible(visible);
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 AbapGitWizardPageSwitchBranchAndPackage extends AbapGitWizardPageBranchAndPackage {

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

Choose a reason for hiding this comment

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

Like in case of credentials page, here as well the pullAction will be false always.
We can remove the parameter pullAction in the constructor and set pullAction as false for the super constructor.

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;
}

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

import org.abapgit.adt.backend.model.abapgitexternalrepo.AccessMode;
import org.abapgit.adt.ui.internal.i18n.Messages;
import org.abapgit.adt.ui.internal.wizards.AbapGitWizard.CloneData;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.dialogs.DialogPage;

public class AbapGitWizardPageSwitchBranchCredentials extends AbapGitWizardPageRepositoryAndCredentials {

private final CloneData cloneData;

public AbapGitWizardPageSwitchBranchCredentials(IProject project, String destination, CloneData cloneData) {
super(project, destination, cloneData, false);
this.cloneData = cloneData;
setTitle(Messages.AbapGitWizardPageSwitch_branch_credentials_title);
setDescription(Messages.AbapGitWizardPageSwitch_credentials_description);
}

@Override
public void setVisible(boolean visible) {
//Navigate to branch selection page if repo is public
if (this.cloneData.externalRepoInfo != null && this.cloneData.externalRepoInfo.getAccessMode() == AccessMode.PUBLIC) {
getContainer().showPage(getNextPage());
getContainer().getCurrentPage().setVisible(visible);
getContainer().getCurrentPage().setPreviousPage(getContainer().getCurrentPage());
return;
}

super.setVisible(visible);
}

@Override
public boolean validateAll() {
if (!validateClientOnly()) {
return false;
}

fetchRepositories();
if (this.cloneData.repositories == null) {
return false;
}

if (this.cloneData.externalRepoInfo == null) {
fetchExternalRepoInfo();
if (this.cloneData.externalRepoInfo == null) {
return false;
}
}
if (this.cloneData.externalRepoInfo.getAccessMode() == AccessMode.PRIVATE) {
if (!this.txtUser.isVisible()) {
setUserAndPassControlsVisible(true);
this.txtUser.setFocus();
setPageComplete(false);
setMessage(Messages.AbapGitWizardPageRepositoryAndCredentials_repo_is_private, DialogPage.INFORMATION);
return false;
} else {
// update the info, now that we have proper user/password
if (!fetchExternalRepoInfo()) {
return false;
}
}
}

return true;
}

}
Loading