2828import org .eclipse .jface .operation .IRunnableWithProgress ;
2929import org .eclipse .jface .viewers .ArrayContentProvider ;
3030import org .eclipse .jface .viewers .ColumnLabelProvider ;
31+ import org .eclipse .jface .viewers .DoubleClickEvent ;
32+ import org .eclipse .jface .viewers .IDoubleClickListener ;
3133import org .eclipse .jface .viewers .ISelection ;
3234import org .eclipse .jface .viewers .IStructuredSelection ;
3335import org .eclipse .jface .viewers .ITableLabelProvider ;
5557import org .eclipse .ui .statushandlers .StatusManager ;
5658
5759import com .sap .adt .destinations .logon .AdtLogonServiceFactory ;
60+ import com .sap .adt .destinations .model .IDestinationData ;
5861import com .sap .adt .destinations .ui .logon .AdtLogonServiceUIFactory ;
5962import com .sap .adt .project .ui .util .ProjectUtil ;
63+ import com .sap .adt .tools .core .model .adtcore .IAdtObjectReference ;
6064import com .sap .adt .tools .core .project .AdtProjectServiceFactory ;
65+ import com .sap .adt .tools .core .project .IAbapProject ;
66+ import com .sap .adt .tools .core .ui .navigation .AdtNavigationServiceFactory ;
67+ import com .sap .adt .tools .core .ui .packages .AdtPackageServiceUIFactory ;
68+ import com .sap .adt .tools .core .ui .packages .IAdtPackageServiceUI ;
6169
6270public class AbapGitView extends ViewPart {
6371
6472 public static final String ID = "org.abapgit.adt.ui.views.AbapGitView" ; //$NON-NLS-1$
6573
6674 private TableViewer viewer ;
67- private Action actionRefresh , actionWizard , actionCopy ;
75+ private Action actionRefresh , actionWizard , actionCopy , actionShowMyRepos ;
6876 private ISelection lastSelection ;
6977 private IProject lastProject ;
7078
@@ -117,7 +125,7 @@ private void showLastSelectedElement() {
117125 IProject currentProject = ProjectUtil .getActiveAdtCoreProject (this .lastSelection , null , null , null );
118126 if (currentProject != this .lastProject ) {
119127 this .lastProject = currentProject ;
120- updateView (false );
128+ updateView (false , false );
121129 }
122130
123131 this .lastSelection = null ;
@@ -152,7 +160,7 @@ public void createPartControl(Composite parent) {
152160 hookContextMenu ();
153161 contributeToActionBars ();
154162
155- updateView (false );
163+ updateView (false , false );
156164
157165 // add listener for selections
158166 getSite ().getPage ().addPostSelectionListener (this .selectionListener );
@@ -239,13 +247,27 @@ public void menuAboutToShow(IMenuManager manager) {
239247 if (AbapGitView .this .viewer .getStructuredSelection ().size () == 1 ) {
240248 Object firstElement = AbapGitView .this .viewer .getStructuredSelection ().getFirstElement ();
241249 if (firstElement instanceof IRepository ) {
242- if (((IRepository ) firstElement ).getLink (IRepositoryService .RELATION_PULL ) != null ) {
243- manager .add (AbapGitView .this .actionPullWizard );
244- manager .add (new Separator ());
245- }
250+
251+ //Check if repos are created by current user
252+ // String destinationId = getDestination(AbapGitView.this.lastProject);
253+ // IProject currProject = AdtProjectServiceFactory.createProjectService().findProject(destinationId);
254+ // IAbapProject currAbapProject = currProject.getAdapter(IAbapProject.class);
255+ // IDestinationData ProjectDestData = currAbapProject.getDestinationData();
256+
257+ // if ((((IRepository) firstElement).getCreatedBy().equalsIgnoreCase(ProjectDestData.getUser()))) {
258+ //
259+ // if (((IRepository) firstElement).getLink(IRepositoryService.RELATION_PULL) != null) {
260+ // manager.add(AbapGitView.this.actionPullWizard);
261+ // manager.add(new Separator());
262+ // }
263+ //
264+ // }
265+
246266 manager .add (AbapGitView .this .actionCopy );
267+ manager .add (new Separator ());
247268 manager .add (new UnlinkAction (AbapGitView .this .lastProject , (IRepository ) firstElement ));
248269
270+
249271 }
250272 }
251273 }
@@ -257,20 +279,31 @@ public void menuAboutToShow(IMenuManager manager) {
257279 private void contributeToActionBars () {
258280 IToolBarManager toolBarManager = getViewSite ().getActionBars ().getToolBarManager ();
259281 toolBarManager .add (this .actionRefresh );
282+ toolBarManager .add (this .actionShowMyRepos );
260283 toolBarManager .add (this .actionWizard );
261284 }
262285
263286 private void makeActions () {
264287 this .actionRefresh = new Action () {
265288 public void run () {
266- updateView (true );
289+ updateView (true , false );
267290 }
268291 };
269292 this .actionRefresh .setText (Messages .AbapGitView_action_refresh );
270293 this .actionRefresh .setToolTipText (Messages .AbapGitView_action_refresh );
271294 this .actionRefresh
272295 .setImageDescriptor (AbstractUIPlugin .imageDescriptorFromPlugin (AbapGitUIPlugin .PLUGIN_ID , "icons/etool/refresh.png" )); //$NON-NLS-1$
273296
297+ this .actionShowMyRepos = new Action () {
298+ public void run () {
299+ updateView (true , true );
300+ }
301+ };
302+ this .actionShowMyRepos .setText (Messages .AbapGitView_action_showMyRepos );
303+ this .actionShowMyRepos .setToolTipText (Messages .AbapGitView_action_showMyRepos );
304+ this .actionShowMyRepos
305+ .setImageDescriptor (PlatformUI .getWorkbench ().getSharedImages ().getImageDescriptor (ISharedImages .IMG_ETOOL_HOME_NAV ));
306+
274307 this .actionCopy = new Action () {
275308 public void run () {
276309 copy ();
@@ -282,9 +315,6 @@ public void run() {
282315 this .actionCopy .setAccelerator (SWT .ALT | 'C' );
283316 this .actionCopy .setImageDescriptor (PlatformUI .getWorkbench ().getSharedImages ().getImageDescriptor (ISharedImages .IMG_TOOL_COPY ));
284317
285- // this.actionCopy
286- // .setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(AbapGitUIPlugin.PLUGIN_ID, "icons/etool/refresh.png")); //$NON-NLS-1$
287-
288318 this .actionWizard = new Action () {
289319 public void run () {
290320 if (!AdtLogonServiceUIFactory .createLogonServiceUI ().ensureLoggedOn (AbapGitView .this .lastProject ).isOK ()) {
@@ -294,7 +324,7 @@ public void run() {
294324 new AbapGitWizard (AbapGitView .this .lastProject ));
295325
296326 wizardDialog .open ();
297- updateView (true );
327+ updateView (true , false );
298328 }
299329 };
300330 this .actionWizard .setText (Messages .AbapGitView_action_clone );
@@ -322,16 +352,17 @@ public void run() {
322352 wizardDialog .open ();
323353
324354 }
325- updateView (true );
355+ updateView (true , false );
326356 }
327357 };
328358 this .actionPullWizard .setText (Messages .AbapGitView_context_pull );
329359// this.actionPullWizard
330360// .setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_SYNCED));
331361 }
332362
333- private List <IRepository > getRepositories (String destinationId ) {
363+ private List <IRepository > getRepositories (String destinationId , Boolean byCurrUser ) {
334364 List <IRepository > repos = new LinkedList <>();
365+ List <IRepository > myrepos = new LinkedList <>();
335366 boolean [] isSupported = new boolean [1 ];
336367 try {
337368 PlatformUI .getWorkbench ().getProgressService ().busyCursorWhile (new IRunnableWithProgress () {
@@ -344,7 +375,27 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
344375 return ;
345376 }
346377 isSupported [0 ] = true ;
378+
347379 repos .addAll (repoService .getRepositories (monitor ).getRepositories ());
380+
381+ if (byCurrUser ) {
382+ //Check if repos are created by current user
383+ IProject currProject = AdtProjectServiceFactory .createProjectService ().findProject (destinationId );
384+ IAbapProject currAbapProject = currProject .getAdapter (IAbapProject .class );
385+ IDestinationData ProjectDestData = currAbapProject .getDestinationData ();
386+
387+ for (IRepository r : repos ) {
388+ if (r .getCreatedBy ().equalsIgnoreCase (ProjectDestData .getUser ())) {
389+ myrepos .add (r );
390+ }
391+ }
392+ }
393+
394+ if (!myrepos .isEmpty ()) {
395+ repos .clear ();
396+ repos .addAll (myrepos );
397+ }
398+
348399 }
349400 });
350401
@@ -364,7 +415,7 @@ private static String getDestination(IProject project) {
364415 return AdtProjectServiceFactory .createProjectService ().getDestinationId (project );
365416 }
366417
367- private void updateView (boolean ensureLogon ) {
418+ private void updateView (boolean ensureLogon , boolean byCurrUser ) {
368419 if (this .lastProject == null ) {
369420 setContentDescription (Messages .AbapGitView_no_abap_project );
370421 setControlsEnabled (false );
@@ -381,7 +432,11 @@ private void updateView(boolean ensureLogon) {
381432 return ;
382433 }
383434
384- List <IRepository > repos = getRepositories (destinationId );
435+ List <IRepository > repos = getRepositories (destinationId , false );
436+
437+ if (byCurrUser ) {
438+ repos = getRepositories (destinationId , true );
439+ }
385440
386441 if (repos != null ) {
387442 setContentDescription (NLS .bind (Messages .AbapGitView_repos_in_project , this .lastProject .getName ()));
@@ -392,11 +447,79 @@ private void updateView(boolean ensureLogon) {
392447 setControlsEnabled (false );
393448 this .viewer .setInput (null );
394449 }
450+
451+ this .viewer .addDoubleClickListener (new IDoubleClickListener () {
452+
453+ @ Override
454+ public void doubleClick (DoubleClickEvent event ) {
455+
456+ IRepository currRepository ;
457+ // IWorkbenchPage page = getSite().getPage();
458+ // IViewPart view = page.findView(IPageLayout.ID_PROJECT_EXPLORER);
459+ currRepository = null ;
460+
461+ IStructuredSelection selection = (IStructuredSelection ) event .getSelection ();
462+
463+ Object firstElement = selection .getFirstElement ();
464+ if (firstElement instanceof IRepository ) {
465+ currRepository = ((IRepository ) firstElement );
466+ }
467+
468+ if (currRepository != null ) {
469+
470+ IAdtPackageServiceUI packageServiceUI = AdtPackageServiceUIFactory .getOrCreateAdtPackageServiceUI ();
471+ List <IAdtObjectReference > pkgRefs = packageServiceUI .find (destinationId , currRepository .getPackage (), null );
472+ IProject currProject = AbapGitView .this .lastProject ; //AdtProjectServiceFactory.createProjectService().findProject(destinationId);
473+ if (!pkgRefs .isEmpty ()) {
474+ IAdtObjectReference gitPackageRef = pkgRefs .stream ().findFirst ().get ();
475+ if (gitPackageRef != null ) {
476+ AdtNavigationServiceFactory .createNavigationService ().navigate (currProject , gitPackageRef , true );
477+ }
478+ }
479+
480+ // IWorkbenchPart workbenchPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
481+ // IFile file = workbenchPart.getSite().getPage().getActiveEditor().getEditorInput().getAdapter(IFile.class);
482+ // if (file == null) {
483+ // System.out.println("FileNotFoundException");
484+ // }
485+ // expandProjectExlorer(file);
486+
487+ }
488+
489+ }
490+ });
395491 }
396492
493+ // public void expandProjectExlorer(IFile file) {
494+ // if (file == null) {
495+ // return;
496+ // }
497+ // try {
498+ // IWorkbenchPage page = getSite().getWorkbenchWindow().getActivePage();
499+ // IViewPart view = page.showView(IPageLayout.ID_PROJECT_EXPLORER);
500+ // if (view instanceof ISetSelectionTarget) {
501+ //
502+ // AbapGitView.this.viewer.getControl().getShell().getDisplay().asyncExec(new Runnable() {
503+ // @Override
504+ // public void run() {
505+ //
506+ // ISelection selection = new StructuredSelection(file);
507+ //
508+ // System.out.println(selection);
509+ // ((ISetSelectionTarget) view).selectReveal(selection);
510+ // }
511+ // });
512+ //
513+ // }
514+ // } catch (PartInitException e) {
515+ // System.out.println(e.getMessage());
516+ // }
517+ // }
518+
397519 private void setControlsEnabled (boolean enabled ) {
398520 this .viewer .getControl ().setEnabled (enabled );
399521 this .actionRefresh .setEnabled (enabled );
522+ this .actionShowMyRepos .setEnabled (enabled );
400523 this .actionWizard .setEnabled (enabled );
401524 this .actionCopy .setEnabled (enabled );
402525 }
@@ -479,7 +602,7 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
479602 .unlinkRepository (UnlinkAction .this .repository .getKey (), monitor );
480603 }
481604 });
482- updateView (true );
605+ updateView (true , false );
483606 } catch (InvocationTargetException e ) {
484607 StatusManager .getManager ().handle (new Status (IStatus .ERROR , AbapGitUIPlugin .PLUGIN_ID ,
485608 Messages .AbapGitView_context_unlink_error , e .getTargetException ()), StatusManager .SHOW );
0 commit comments