-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: master
Are you sure you want to change the base?
Switch branch Action #286
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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$ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the classes to the package org.abapgit.adt.ui.internal.wizards. 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the object is created, abapGitService will always be null right? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Show the error message on the page if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Suggestion. |
||
|
||
@Override | ||
public void setVisible(boolean visible) { | ||
super.setVisible(visible); | ||
|
||
if (visible) { | ||
this.comboBranches.getCombo().setEnabled(true); | ||
} | ||
} | ||
Comment on lines
+17
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's hide the pull after link checkbox. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. |
||
|
||
@Override | ||
public boolean canFlipToNextPage() { | ||
return false; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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.