11package io .snyk .eclipse .plugin .views .snyktoolview ;
22
33import java .nio .file .Paths ;
4- import java .util .HashMap ;
5- import java .util .Map ;
64
7- import org .eclipse .core .resources .IProject ;
8- import org .eclipse .core .resources .ResourcesPlugin ;
95import org .eclipse .jface .action .IMenuManager ;
106import org .eclipse .jface .action .MenuManager ;
117import org .eclipse .jface .viewers .ISelectionChangedListener ;
2218import org .eclipse .swt .layout .GridLayout ;
2319import org .eclipse .swt .widgets .Composite ;
2420import org .eclipse .swt .widgets .Display ;
25- import org .eclipse .swt .widgets .Event ;
26- import org .eclipse .swt .widgets .Listener ;
2721import org .eclipse .swt .widgets .Menu ;
2822import org .eclipse .swt .widgets .Tree ;
29- import org .eclipse .swt .widgets .TreeItem ;
3023import org .eclipse .ui .PlatformUI ;
3124import org .eclipse .ui .menus .CommandContributionItem ;
3225import org .eclipse .ui .menus .CommandContributionItemParameter ;
@@ -56,8 +49,7 @@ public class SnykToolView extends ViewPart implements ISnykToolView {
5649 private TreeViewer treeViewer ;
5750 private Browser browser ;
5851 private BrowserHandler browserHandler ;
59- private Map <TreeItem , Listener > itemListeners = new HashMap <>();
60- private FolderConfigs preferenceState = FolderConfigs .getInstance ();
52+ private FolderConfigs folderConfigs = FolderConfigs .getInstance ();
6153
6254 @ Override
6355 public void createPartControl (Composite parent ) {
@@ -107,6 +99,15 @@ public void selectionChanged(SelectionChangedEvent event) {
10799 LSPEclipseUtils .open (fileNode .getPath ().toUri ().toASCIIString (),
108100 issueTreeNode .getIssue ().getLSP4JRange ());
109101 }
102+ boolean deltaEnabled = Preferences .getInstance ()
103+ .getBooleanPref (Preferences .FILTER_DELTA_NEW_ISSUES );
104+ if (node instanceof ContentRootNode && deltaEnabled ) {
105+ ContentRootNode contentNode = (ContentRootNode ) node ;
106+ String projectPath = contentNode .getPath ().toString ();
107+ String [] localBranches = folderConfigs .getLocalBranches (projectPath ).toArray (new String [0 ]);
108+
109+ new BaseBranchDialog ().baseBranchDialog (Display .getDefault (), projectPath , localBranches );
110+ }
110111 });
111112 }
112113 });
@@ -131,7 +132,7 @@ public void setFocus() {
131132 public void setNodeText (BaseTreeNode node , String text ) {
132133 node .setText (text );
133134 Display .getDefault ().asyncExec (() -> {
134- this .treeViewer .refresh (node , true );
135+ this .treeViewer .update (node , null );
135136 });
136137 }
137138
@@ -273,69 +274,44 @@ public void toggleIgnoresButtons() {
273274 * Sets up for doing a Net New Issues scan.
274275 */
275276 public void enableDelta () {
276- clearDeltaNodeListeners ();
277277
278- Display .getDefault ().asyncExec (() -> {
279- if (this .treeViewer != null && !this .treeViewer .getTree ().isDisposed ()) {
278+ if (this .treeViewer != null && !this .treeViewer .getTree ().isDisposed ()) {
279+ BaseTreeNode [] children = (BaseTreeNode []) getRoot ().getChildren ();
280+
281+ for (BaseTreeNode node : children ) {
282+ if (node instanceof ContentRootNode ) {
283+ ContentRootNode contentNode = (ContentRootNode ) node ;
284+ String projectPath = contentNode .getPath ().toString ();
285+ String projectName = ResourceUtils .getProjectByPath (contentNode .getPath ()).getName ();
286+ String baseBranch = folderConfigs .getBaseBranch (projectPath );
287+
288+ setNodeText (contentNode , String .format ("%s - Click here choose base branch [ current: %s ]" ,
289+ projectName , baseBranch ));
280290
281- TreeItem [] rootItems = getTreeViewer ().getTree ().getItems ();
282- for (TreeItem item : rootItems ) {
283- ContentRootNode node = (ContentRootNode ) item .getData ();
284- String projectName = node .getName ();
285- String projectPath = node .getPath ().toString ();
286- IProject project = ResourcesPlugin .getWorkspace ().getRoot ().getProject (projectName );
287- String baseBranch = preferenceState .getBaseBranch (projectPath );
288- String [] localBranches = preferenceState .getLocalBranches (projectPath ).toArray (String []::new );
289-
290- item .setText (String .format ("%s - Click here choose base branch [ current: %s ]" , projectName ,
291- baseBranch ));
292-
293- Listener selectionListener = new Listener () {
294- @ Override
295- public void handleEvent (Event event ) {
296- if (event .item == item ) {
297- new BaseBranchDialog ().baseBranchDialog (event .display , projectPath , project ,
298- localBranches );
299- }
300- }
301- };
302-
303- itemListeners .put (item , selectionListener );
304-
305- item .getParent ().addListener (SWT .Selection , selectionListener );
306291 }
307292 }
308- });
293+ }
309294 }
310295
311296 /*
312297 * Disables Net New Issues scan, and starts a regular scan.
313298 */
314299 public void disableDelta () {
315- clearDeltaNodeListeners ();
300+ if (this .treeViewer != null && !this .treeViewer .getTree ().isDisposed ()) {
301+ BaseTreeNode [] children = (BaseTreeNode []) getRoot ().getChildren ();
316302
317- SnykExtendedLanguageClient .getInstance ().triggerScan (null );
318- }
303+ for (BaseTreeNode node : children ) {
304+ if (node instanceof ContentRootNode ) {
305+ ContentRootNode contentNode = (ContentRootNode ) node ;
319306
320- private void clearDeltaNodeListeners () {
321- Display .getDefault ().asyncExec (() -> {
322- if (this .treeViewer != null && !this .treeViewer .getTree ().isDisposed ()) {
323- for (Map .Entry <TreeItem , Listener > entry : itemListeners .entrySet ()) {
324- TreeItem item = entry .getKey ();
325- Listener listener = entry .getValue ();
326-
327- ContentRootNode node = (ContentRootNode ) item .getData ();
328- String project = node .getName ();
307+ String projectName = ResourceUtils .getProjectByPath (contentNode .getPath ()).getName ();
329308
330- // Revert text to original
331- item .setText (project );
332-
333- item .getParent ().removeListener (SWT .Selection , listener );
309+ setNodeText (contentNode , projectName );
334310 }
335-
336- itemListeners .clear ();
337311 }
338- });
312+ }
313+
314+ SnykExtendedLanguageClient .getInstance ().triggerScan (null );
339315 }
340316
341317 // Helper method to add a command if it's not already present
0 commit comments