24
24
import org .eclipse .core .resources .IWorkspaceRoot ;
25
25
import org .eclipse .core .resources .ResourcesPlugin ;
26
26
import org .eclipse .core .runtime .CoreException ;
27
+ import org .eclipse .core .runtime .IPath ;
27
28
import org .eclipse .core .runtime .Path ;
28
29
import org .eclipse .jface .action .Action ;
29
30
import org .eclipse .jface .action .IToolBarManager ;
53
54
import com .espressif .idf .core .logging .Logger ;
54
55
import com .espressif .idf .core .util .GcovUtility ;
55
56
import com .espressif .idf .core .util .IDFUtil ;
57
+ import com .espressif .idf .core .util .StringUtil ;
56
58
57
59
/**
58
60
* Gcov file view that can be opened by right clicking on the project. It is used to show the gcno/gcda files as one
@@ -121,6 +123,14 @@ public void run()
121
123
refreshList ();
122
124
}
123
125
};
126
+ Action selectProjectAction = new Action ("Select Project" )
127
+ {
128
+ public void run ()
129
+ {
130
+ openProjectSelectionDialog ();
131
+ refreshList ();
132
+ }
133
+ };
124
134
mgr .add (refreshAction );
125
135
126
136
// Initial population of the list
@@ -139,14 +149,55 @@ public void selectionChanged(IWorkbenchPart part, ISelection selection)
139
149
setSelectedProject ((IProject ) obj );
140
150
}
141
151
}
142
-
143
- private void refreshList ()
152
+
153
+ private void openProjectSelectionDialog ()
144
154
{
145
- for (TableItem item : table .getItems ())
155
+ IWorkspaceRoot root = ResourcesPlugin .getWorkspace ().getRoot ();
156
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog (
157
+ PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getShell (),
158
+ new org .eclipse .ui .model .WorkbenchLabelProvider ());
159
+ dialog .setElements (root .getProjects ());
160
+ dialog .setTitle (Messages .Dialog_SelectProject_Title );
161
+
162
+ // only continue if the user pressed "OK"
163
+ if (dialog .open () != Window .OK )
146
164
{
147
- item . dispose () ;
165
+ return ;
148
166
}
149
167
168
+ setSelectedProject ((IProject ) dialog .getFirstResult ());
169
+ }
170
+
171
+ private void createTableItem (Image image , String fileName , String filePath , String gcnoDate , String gcdaDate , String gcnoSize , String gcdaSize , Object data )
172
+ {
173
+ int index = 0 ;
174
+ TableItem item = new TableItem (table , SWT .NONE );
175
+ item .setImage (index , image );
176
+ item .setText (index ++, fileName );
177
+ item .setText (index ++, filePath );
178
+ item .setText (index ++, gcnoDate );
179
+ item .setText (index ++, gcdaDate );
180
+ item .setText (index ++, gcnoSize );
181
+ item .setText (index ++, gcdaSize );
182
+
183
+ item .setData (data );
184
+ }
185
+
186
+ private String getFileSize (java .nio .file .Path path )
187
+ {
188
+ try
189
+ {
190
+ long size = Files .size (path );
191
+ return String .valueOf (size ) + " bytes" ; //$NON-NLS-1$
192
+ }
193
+ catch (Exception e )
194
+ {
195
+ return Messages .Table_Unknown ;
196
+ }
197
+ }
198
+
199
+ private void verifyProjectSelection ()
200
+ {
150
201
if (getSelectedProject () == null )
151
202
{
152
203
// Get the current selection
@@ -173,22 +224,19 @@ private void refreshList()
173
224
// If no project is selected, ask the user to choose one
174
225
if (getSelectedProject () == null )
175
226
{
176
- IWorkspaceRoot root = ResourcesPlugin .getWorkspace ().getRoot ();
177
- ElementListSelectionDialog dialog = new ElementListSelectionDialog (
178
- PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getShell (),
179
- new org .eclipse .ui .model .WorkbenchLabelProvider ());
180
- dialog .setElements (root .getProjects ());
181
- dialog .setTitle (Messages .Dialog_SelectProject_Title );
182
-
183
- // only continue if the user pressed "OK"
184
- if (dialog .open () != Window .OK )
185
- {
186
- return ;
187
- }
188
-
189
- setSelectedProject ((IProject ) dialog .getFirstResult ());
227
+ openProjectSelectionDialog ();
190
228
}
191
229
}
230
+ }
231
+
232
+ private void refreshList ()
233
+ {
234
+ for (TableItem item : table .getItems ())
235
+ {
236
+ item .dispose ();
237
+ }
238
+
239
+ verifyProjectSelection ();
192
240
193
241
IProject project = getSelectedProject ();
194
242
@@ -210,47 +258,23 @@ public boolean visit(IResource resource)
210
258
+ file .getName ().substring (0 , file .getName ().indexOf (".gcno" )) + ".gcda" ; //$NON-NLS-1$ //$NON-NLS-2$
211
259
if (Files .exists (Paths .get (partnerFile )))
212
260
{
213
- TableItem item = new TableItem (table , SWT .NONE );
214
261
Image image = PlatformUI .getWorkbench ().getEditorRegistry ()
215
262
.getImageDescriptor (file .getName ()).createImage ();
216
- item .setImage (0 , image );
217
- item .setText (0 , file .getName ().substring (0 , file .getName ().indexOf (".gcno" ))); //$NON-NLS-1$
218
- item .setText (1 , file .getParent ().getFullPath ().toString ());
219
-
220
263
// gcno
221
264
IFileInfo fileInfo = EFS .getLocalFileSystem ().getStore (file .getLocationURI ())
222
265
.fetchInfo ();
223
- String date = DateFormat .getDateTimeInstance ().format (new Date (fileInfo .getLastModified ()));
224
- item .setText (2 , date );
225
-
266
+ String dateGcno = DateFormat .getDateTimeInstance ()
267
+ .format (new Date (fileInfo .getLastModified ()));
226
268
// gcda
227
269
fileInfo = EFS .getLocalFileSystem ().getStore (Path .fromOSString (partnerFile ))
228
270
.fetchInfo ();
229
- item .setText (3 , DateFormat .getDateTimeInstance ().format (new Date (fileInfo .getLastModified ())));
230
-
231
- java .nio .file .Path path = Paths .get (file .getRawLocationURI ());
232
- try
233
- {
234
- long size = Files .size (path );
235
- item .setText (4 , String .valueOf (size ) + " bytes" ); //$NON-NLS-1$
236
- }
237
- catch (Exception e )
238
- {
239
- item .setText (4 , Messages .Table_Unknown );
240
- }
241
-
242
- path = Paths .get (partnerFile );
243
- try
244
- {
245
- long size = Files .size (path );
246
- item .setText (5 , String .valueOf (size ) + " bytes" ); //$NON-NLS-1$
247
- }
248
- catch (Exception e )
249
- {
250
- item .setText (5 , Messages .Table_Unknown );
251
- }
252
-
253
- item .setData (file );
271
+ String dateGcda = DateFormat .getDateTimeInstance ()
272
+ .format (new Date (fileInfo .getLastModified ()));
273
+
274
+ String gcnoSize = getFileSize (Paths .get (file .getRawLocationURI ()));
275
+ String gcdaSize = getFileSize (Paths .get (partnerFile ));
276
+
277
+ createTableItem (image , file .getName ().substring (0 , file .getName ().indexOf (".gcno" )), file .getParent ().getFullPath ().toString (), dateGcno , dateGcda , gcnoSize , gcdaSize , file );
254
278
}
255
279
}
256
280
}
@@ -347,6 +371,18 @@ public int compare(TableItem item1, TableItem item2)
347
371
});
348
372
349
373
// Copy existing item data
374
+ List <TableRowData > copiedData = createTableDataCopy (items );
375
+
376
+ // Remove all items (dispose of TableItem objects)
377
+ table .removeAll ();
378
+
379
+ // Repopulate the table
380
+ populateTable (copiedData );
381
+ }
382
+
383
+
384
+ private List <TableRowData > createTableDataCopy (TableItem [] items )
385
+ {
350
386
List <TableRowData > copiedData = new ArrayList <>();
351
387
for (TableItem item : items )
352
388
{
@@ -360,12 +396,13 @@ public int compare(TableItem item1, TableItem item2)
360
396
rowData .itemData = item .getData ();
361
397
copiedData .add (rowData );
362
398
}
363
-
364
- // Remove all items (dispose of TableItem objects)
365
- table .removeAll ();
366
-
367
- // Repopulate the table
368
- for (TableRowData rowData : copiedData )
399
+
400
+ return copiedData ;
401
+ }
402
+
403
+ private void populateTable (List <TableRowData > tableRowData )
404
+ {
405
+ for (TableRowData rowData : tableRowData )
369
406
{
370
407
TableItem newItem = new TableItem (table , SWT .NONE );
371
408
for (int j = 0 ; j < table .getColumnCount (); j ++)
0 commit comments