Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to make a zebra striped table in Java SWT?

Hi,
I am working on creating a GUI using Java SWT and in this GUI I am putting some data to a table continuously as the worker thread generates it.

I make one line with dark background and one line with light background line zebra.

However, this does not work correctly every time. Sometimes, more than one consecutive lines has the same light or dark background.

Can you please help me to figure out why this happens and how to solve it?

This is the other method that calls the populateResultsTable method (LINE  26):

SOME CODE THAT RUNS THE PERL CODE IN THE WORKER THREAD

            exitLoop = false;
            boolean newRun = true;
            boolean evenRow = true;
            
            // String fileName = null;
            int value = 1;
            while(true && exitLoop == false) {
                
            HashMap<String, Future> tempFutures = futures;   
            ArrayList<String> keyList = new ArrayList<String>();
            
            
            for (Entry<String, Future> entry  : tempFutures.entrySet()) {
            	
            	//This is to stop the process
            	if (exitLoop) break;
                Future<List<CheckDetail>> f = entry.getValue();
                    try {
                        checkDetails = f.get(1, TimeUnit.MILLISECONDS);
                        
                        if (checkDetails != null) {
                            keyList.add(entry.getKey());
                            checkDetailsAll.addAll(checkDetails); 
                            evenRow = Gui.populateResultsTable(checkDetails,shell,table,titles, newRun, evenRow, groupResults, value, fileData.length);
                            newRun = false;                            
                        }
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (TimeoutException e) {
                       ;
                    }
            }    

            if (!futures.isEmpty()){             
                for (String key : keyList) {
                    futures.remove(key);
                    value++;
                }                        
            }
            
            if (futures.isEmpty())
               exitLoop = true;
            }

SOME OTHER CODE

Open in new window


This is the code that populates the results on the table with the  zebra pattern: (LINE 35)

public static boolean populateResultsTable(final List<CheckDetail> checkDetails, final Shell shell, final Table table, final String[] titles, final boolean newRun, final boolean evenRow, final Group groupResults_new, final int value, final int numFiles){        
 
    	
    	
    	
    	
        evenRowFine = evenRow;
        display.asyncExec(new Runnable() {
            public void run() {

        if (newRun){
            table.removeAll();
        }else{
            //do not clean table            
        }
        
        
        //upDateProgressBar(5, 10);
        
        for(Iterator<CheckDetail> i = checkDetails.iterator();i.hasNext();) {
            CheckDetail checkDetail = i.next();

                TableItem item = new TableItem(table, SWT.NULL);
                item.setText(0, checkDetail.getStatus()); //Status
                item.setText(1, checkDetail.getName()); //Check
                item.setText(2, checkDetail.getFileName()); //Filename
                item.setText(3, checkDetail.getExistingLineNumbers()); //Existing Line Numbers
                item.setText(4, checkDetail.getNewLineNumbers()); //New Line Numbers
                
                //if this is true then, we do let the user to save 
                //the results table to a file or a geck
                tableHasData = true;
                //This is to make shadow for every other line
                if (evenRowFine){
                    item.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
                    evenRowFine = false;        
                    i.remove(); // clear
                } else{
                    evenRowFine = true;
                }
            //}
                upDateProgressBar(value, numFiles);
        }
         
         for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) {
              table.getColumn(loopIndex).pack();
         }
        table.setRedraw(true);
        
      //This is to sort the columns in the table
        Listener sortListener = new Listener() {
            int prevSortIndex = -1;
            int prevSortDirection = 1;
            int prevSortDir;
            
            public void handleEvent(Event e) {
                TableItem[] items = table.getItems();
                Collator collator = Collator.getInstance(Locale.getDefault());
                TableColumn column = (TableColumn) e.widget;
                int index = column == table.getColumn(0) ? 0 : 1;
                if (prevSortIndex == index) {
                    prevSortDir *= -1;
                } else {
                    prevSortDir = 1;
                    prevSortIndex = index;
                }
                for (int i = 1; i < items.length; i++) {
                    String value1 = items[i].getText(index);
                    for (int j = 0; j < i; j++) {
                        String value2 = items[j].getText(index);
                        if ((collator.compare(value1, value2) * prevSortDir) < 0) {
                            String[] values = { items[i].getText(0),
                                    items[i].getText(1), items[i].getText(2),
                                    items[i].getText(3) };
                            items[i].dispose();
                            TableItem item = new TableItem(table, SWT.NONE, j);
                            item.setText(values);
                            items = table.getItems();
                            break;
                        }
                    }
                }
                table.setSortColumn(column);
            }
        };
        
        table.getColumn(0).addListener(SWT.Selection, sortListener);
        table.getColumn(1).addListener(SWT.Selection, sortListener);
        table.setSortColumn(table.getColumn(0));
        table.setSortDirection(SWT.TOP);
        
        table.setRedraw(true);
    }
  });
            
     return evenRowFine;
    }

Open in new window

Avatar of mccarl
mccarl
Flag of Australia image

Can you post the full code for the class containing that populateResultsTable method? From what you have posted, something doesn't look quite right, it lokos like it wouldn't compile. "evenRowFine" is defined outside the "Runnable" inner class and is used inside it too, so it would have needed to be declared final BUT the value of it is also modified in a couple of places so final would cause a problem.

In your editing of the code, to post in this question, you must have removed/changed something that matters quite a bit to this issue.

Also, you are calling display.asyncExec() which executes the code within as *SOME* point in the future and then "return evenRowFine" straight away, so it possibly wouldn't have even had a chance to be updated by the code with that alternates that variable before returning.



So, I have an idea of what you've done that would cause your problem, but post the full code so that I can see the "big picture".
Avatar of Tolgar
Tolgar

ASKER

Here is the full class that has PopulateResultsTable in it:

import java.sql.SQLException;
import java.text.Collator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;


public class Gui {

    static Display display;

    static ToolItem item_selectFilesDirectories;
    static ToolItem item_selectChangelist;
    static ToolItem item_selectFileList;
    static ToolItem item_clearList;
    static ToolItem item_SaveFileList;
    static ToolItem item_SpecifyChecks;
    static ToolItem item_help;
    static ToolItem item_RunChecks;
    static CTabFolder folder;
    static ToolItem item_LoadSavedCheckList;
    static ToolItem item_UnselectAll;
    static ToolItem item_SaveSelections;
    static ToolItem item_StopChecks;
    static ToolItem item_RerunFailed;
    static ToolItem item_SaveResults;
    static ToolItem item_SaveToGeck;
    static ToolItem item_StartOver;
    static ToolItem item_Quit;
    static ToolItem item_selectAllChecks;
    static Text txt;
    static Label helpLabel;
    static boolean tableHasData = false;
    static Group groupResults; 
    static boolean evenRowFine;
    private static Composite compRESULTS_toolbar;
    static CSFilteringCheckBoxes csFilteringCheckBoxes;
    
    private static ToolBarListener toolBarListener = new ToolBarListener();
    private static RunPerl runPerl = new RunPerl();
    private static RunCheckProgressBar runCheckProgressBar = new RunCheckProgressBar();
    static RWFile rwFile = new RWFile();
    static FileTree fileTree = new FileTree();
    static StringBuilder buffer; 
    
    
    public static void swichTabChecks() {
        folder.setSelection(1);
    }
    
    public static void swichTabResults() {
        folder.setSelection(2);
    }
    
    public static void swichTabFiles() {
        folder.setSelection(0);
    } 
    
    public static void readTxt(String fileListFile, String fileListPath) {
        buffer = new StringBuilder();
        if (txt.getText().isEmpty()){
            buffer.append(txt.getText() + rwFile.readFromFile(fileListFile, fileListPath));
        } else{
            buffer.append(txt.getText() + "\r\n" + rwFile.readFromFile(fileListFile, fileListPath));
        }
        String fileList = buffer.toString();
        
        txt.setText(fileList);
    }    
    
    public static void writeTxt(String file) {
        String content = txt.getText();
        
       
        //Remove all empty lines in the files text box
        content = content.replaceAll("(?m)^[ \t]*\r?\n", "");
        
        //Replace everything until product except -d
        content = content.replaceAll("(?m)^(-d\\s)?.*?(?=product)", "$1");
        //write the result to a file
        rwFile.writeToFile(content, file);
    }    
    
    public static void clearTxt() {
        txt.setText("");
    } 
    
//    TO DO: This may replace the built-in dialog box.     
//    public static void selectFilesFolders() {
//        fileTree.createFileDirDialog(null);
//        buffer = new StringBuilder();
//        
//        buffer.append(txt.getText() + fileTree.getFileFolders());
//        fileTree.clearModel();
//        //System.out.println("FILES:" + fileTree.getFileFolders());
//        String fileList = buffer.toString();
//        txt.setText(fileList);
//    }  
    
    public static void selectFiles(FileDialog dlg){    	
    	String lineSeparator;
    	
    	buffer = new StringBuilder();
    	String firstFile = dlg.open();
    	
        if (firstFile != null) {
        	String path = dlg.getFilterPath();
            String[] selectedFiles = dlg.getFileNames();
            for (int ii = 0; ii < selectedFiles.length; ii++ ) {
            	lineSeparator = System.getProperty("line.separator");                
            	buffer.append("-f"+ " " + path + System.getProperty("file.separator") + selectedFiles[ii] + lineSeparator);
            }
      }
    	 	
    	String fileList = buffer.toString();
    	
    	// This will clear the buffer
    	buffer.delete(0, buffer.length());

    	//This will copy the content to the text field
        txt.setText(txt.getText() + fileList);    	
    }
   
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        display = new Display();
        

        
        Image image_favicon = new Image(display, "assets/favicon.png");        
        final Shell shell = new Shell(display);
        shell.setLocation(300,100);   
        shell.setImage(image_favicon);
        
        int frameX = shell.getSize().x - shell.getClientArea().width;
        int frameY = shell.getSize().y - shell.getClientArea().height;
        shell.setSize(1200 + frameX, 750 + frameY);
                
        toolBarListener.setShell(shell,display);                  
        shell.setText("Code Analysis Tool");
        shell.setLayout(new GridLayout());      
        
        
        //This is the title bar
        //Composite compositeBanner = new Composite(shell, SWT.NONE); 
        
        GridData gridDataBanner = new GridData(SWT.FILL, SWT.FILL, true, false);

        
        CLabel banner = new CLabel(shell, SWT.CENTER);
        banner.setBackground(new Color[] { display.getSystemColor(SWT.COLOR_DARK_BLUE), display.getSystemColor(SWT.COLOR_BLUE) }, new int[] { 100 }, true); 
        
        FontData fontData = banner.getFont().getFontData()[0];
        Font fontBanner = new Font(shell.getDisplay(), new FontData(fontData.getName(), 10, SWT.BOLD));
        banner.setFont(fontBanner);
        banner.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
        
//        Image image_Help = new Image(display, "assets/help.png");
//        banner.setImage(image_Help);
        banner.setText("\nCODE ANALYSIS TOOL \n ");
        banner.setLayoutData(gridDataBanner);
        
        
        GridData gridDataBanner2 = new GridData(GridData.HORIZONTAL_ALIGN_END);
        CLabel banner2 = new CLabel(shell, SWT.CENTER);
        Color MWGreen = new Color (shell.getDisplay(), 240,240,240);
        banner2.setBackground(MWGreen); 
        
        FontData fontData2 = banner2.getFont().getFontData()[0];
        Font fontBanner2 = new Font(shell.getDisplay(), new FontData(fontData2.getName(),8, SWT.NORMAL));
        banner2.setFont(fontBanner2);
        banner2.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
        
//        Image image_Help = new Image(display, "assets/help.png");
//        banner.setImage(image_Help);
        banner2.setText("Help");
        banner2.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_BLUE));
        banner2.setLayoutData(gridDataBanner2);
        
    
        //This creates the Tabs
        folder = new CTabFolder(shell, SWT.TOP);
        folder.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, true, 3, 3));
        
        //This is to format folder
        //folder.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_YELLOW), display.getSystemColor(SWT.COLOR_RED)}, new int[]{100}, true);
        //folder.setSelectionBackground(new Color[]{display.getSystemColor(SWT.COLOR_WHITE), display.getSystemColor(SWT.COLOR_BLUE)}, new int[]{100}, true);
        //Color lightgray = new Color (display, 240, 240, 240);
        Color lightgray = new Color (display, 220, 220, 220);
        Color sepatator_color = new Color (display, 245, 245, 245);
        folder.setSelectionBackground(new Color[]{new Color(display, new RGB(157, 167, 195)), new Color(display, new RGB(240, 240, 240))}, new int[]{100}, true);
        Font font = new Font(display,"Arial",9, SWT.BOLD);
        folder.setFont(font);
        
        
        CTabItem cTabItem_Files = new CTabItem(folder, SWT.NONE);
        cTabItem_Files.setText("FILES");
        CTabItem cTabItem_Checks = new CTabItem(folder, SWT.NONE);
        cTabItem_Checks.setText("STANDARDS");
        CTabItem cTabItem_Results = new CTabItem(folder, SWT.NONE);
        cTabItem_Results.setText("RESULTS");
       
     // -----------here starts FILES TAB -------------------- 
        Image image_FileInFolder = new Image(display, "assets/folder_document.png");
        //Image image_Help = new Image(display, "assets/help.png");
        Image image_shape_triangle = new Image(display, "assets/shape_triangle.png");
        Image image_document = new Image(display, "assets/document.png");
        Image image_delete = new Image(display, "assets/delete.png");
        Image image_floppy_disk = new Image(display, "assets/floppy_disk.png");
        Image image_navigate_right = new Image(display, "assets/navigate_right.png");
       
        Composite compFilesTab = new Composite(folder, SWT.NULL);
        GridLayout gridLayout_FilesTab = new GridLayout(3, false);
        compFilesTab.setLayout(gridLayout_FilesTab);
        
        Composite compFILES = new Composite(compFilesTab, SWT.NULL);
        GridLayout gridLayout_Files = new GridLayout(8, false);
        gridLayout_Files.marginLeft = 0; gridLayout_Files.marginRight = 0; gridLayout_Files.horizontalSpacing = 0;
        compFILES.setLayout(gridLayout_Files);
        GridData sepGridData_Files = new GridData(GridData.FILL_HORIZONTAL); sepGridData_Files.horizontalSpan = 3; 
        compFILES.setLayoutData(sepGridData_Files);
        //compFILES.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_GRAY));
        compFILES.setBackground(lightgray);
        
                       
        //1st group
        CustomToolbar custToolbar_Files = new CustomToolbar(compFILES, SWT.FLAT, "Files");
        
        item_selectFilesDirectories = new ToolItem(custToolbar_Files.getToolBar(), SWT.NONE);
        item_selectFilesDirectories.setImage(image_FileInFolder); item_selectFilesDirectories.setText("Select Files"); item_selectFilesDirectories.setToolTipText("Select the files or the directory you want to analyze");
        item_selectFilesDirectories.addListener(SWT.Selection, toolBarListener);
        
        item_selectChangelist = new ToolItem(custToolbar_Files.getToolBar(), SWT.PUSH);
        item_selectChangelist.setImage(image_shape_triangle); item_selectChangelist.setText("Select Changelist"); item_selectChangelist.setToolTipText("Select the files in the changelist");
        item_selectChangelist.addListener(SWT.Selection, toolBarListener);
                
//        item_selectFileList = new ToolItem(custToolbar_Files.getToolBar(), SWT.PUSH);
//        item_selectFileList.setImage(image_document); item_selectFileList.setText("Load File List"); item_selectFileList.setToolTipText("Select the file list");
//        item_selectFileList.addListener(SWT.Selection, toolBarListener);
        
        item_clearList = new ToolItem(custToolbar_Files.getToolBar(), SWT.PUSH);
        item_clearList.setImage(image_delete); item_clearList.setText("Clear List"); item_clearList.setToolTipText("Delete the list of all files below");
        item_clearList.addListener(SWT.Selection, toolBarListener);
        item_clearList.setEnabled(false);
        
        //This is the separator
        //Color lightgray = new Color (display, 240, 255, 240);
        Label verticalSepartor_Files_Configuration = new Label(compFILES, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
        verticalSepartor_Files_Configuration.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_Files_Configuration.setBackground(sepatator_color);
        
        //2nd group
//        CustomToolbar custToolbar_FileConfiguration = new CustomToolbar(compFILES, SWT.FLAT, "Configuration");
//        
//        item_SaveFileList = new ToolItem(custToolbar_FileConfiguration.getToolBar(), SWT.NONE);
//        item_SaveFileList.setImage(image_floppy_disk); item_SaveFileList.setText("Save File List"); item_SaveFileList.setToolTipText("Save the list of files below to text file for future reference");
//        item_SaveFileList.addListener(SWT.Selection, toolBarListener);    
//        
//        
//        //This is the separator
//        Label verticalSepartor_Configuration_FileNextActions = new Label(compFILES, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
//        verticalSepartor_Configuration_FileNextActions.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_Configuration_FileNextActions.setBackground(lightgray);
       
        //3rd group
        CustomToolbar custToolbar_FileNextActions = new CustomToolbar(compFILES, SWT.FLAT, "Next Actions");
        
        item_SpecifyChecks = new ToolItem(custToolbar_FileNextActions.getToolBar(), SWT.NONE);
        item_SpecifyChecks.setImage(image_navigate_right); item_SpecifyChecks.setText("Specify Checks"); item_SpecifyChecks.setToolTipText("Move to the next tab to select the list of checks. This icon will be enabled once you have information in the below text box with no path issues.");
        item_SpecifyChecks.addListener(SWT.Selection, toolBarListener);
        item_SpecifyChecks.setEnabled(false);
  
        //This is the separator
        Label verticalSepartor_FileNextActions_Help = new Label(compFILES, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
        verticalSepartor_FileNextActions_Help.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_FileNextActions_Help.setBackground(sepatator_color);
        
//        //4th group
//        CustomToolbar custToolbar_Help = new CustomToolbar(compFILES, SWT.FLAT, "Help");
//        
//        item_help = new ToolItem(custToolbar_Help.getToolBar(), SWT.NONE);
//        item_help.setImage(image_Help); item_help.setText(" "); item_help.setToolTipText("Help page for the GUI");
//        item_help.addListener(SWT.Selection, toolBarListener);
//            
//        //This is the separator
//        Label verticalSepartor_Help_END = new Label(compFILES, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
//        verticalSepartor_Help_END.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_Help_END.setBackground(sepatator_color);
        
        //This is the separator between the toolbar and the text box.
        Label horSepartor_ToolBar_TextBox = new Label(compFilesTab, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.HORIZONTAL);
        GridData sepGridDataFilesTab = new GridData(GridData.FILL_HORIZONTAL); sepGridDataFilesTab.horizontalSpan = 3; 
        horSepartor_ToolBar_TextBox.setLayoutData(sepGridDataFilesTab);horSepartor_ToolBar_TextBox.setBackground(sepatator_color);
               
        Composite compFilesButtons = new Composite(compFilesTab, SWT.NULL);
        FillLayout fillLayout_Files = new FillLayout();
        fillLayout_Files.type = SWT.HORIZONTAL;                  
        compFilesButtons.setLayout(fillLayout_Files);
       
        cTabItem_Files.setControl(compFilesTab);
        
       
// -----------here starts CHECKS TAB --------------------              
        Image image_folder_document = new Image(display, "assets/folder_document.png");
        Image image_selection_delete_2 = new Image(display, "assets/selection_delete_2.png");
        //Image image_selectAllChecks = new Image(display, "selectAllChecks.png");

        Composite compChecksTab = new Composite(folder, SWT.NULL);
        GridLayout gridLayout_ChecksTab = new GridLayout(2, false);
        compChecksTab.setLayout(gridLayout_ChecksTab);
        
        Composite compCHECKS = new Composite(compChecksTab, SWT.NULL);
        GridLayout gridLayout_Checks = new GridLayout(6, false);
        gridLayout_Checks.marginLeft = 0; gridLayout_Checks.marginRight = 0; gridLayout_Checks.horizontalSpacing = 0;
        compCHECKS.setLayout(gridLayout_Checks);
        GridData sepGridData_Checks = new GridData(GridData.FILL_HORIZONTAL); sepGridData_Checks.horizontalSpan = 2; 
        compCHECKS.setLayoutData(sepGridData_Checks);
        //compCHECKS.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_GRAY));
        compCHECKS.setBackground(lightgray);
        
        
        //1st group
        CustomToolbar custToolbar_CheckConfiguration = new CustomToolbar(compCHECKS, SWT.FLAT, "Configuration");  
     
        item_LoadSavedCheckList = new ToolItem(custToolbar_CheckConfiguration.getToolBar(), SWT.PUSH);
        item_LoadSavedCheckList.setImage(image_folder_document); item_LoadSavedCheckList.setText("Load saved checks"); item_LoadSavedCheckList.setToolTipText("Load the saved list of checks if you saved from previous runs");      
        item_LoadSavedCheckList.addListener(SWT.Selection, toolBarListener);
        
//        item_UnselectAll = new ToolItem(custToolbar_CheckConfiguration.getToolBar(), SWT.PUSH);
//        item_UnselectAll.setImage(image_selection_delete_2); item_UnselectAll.setText("Unselect all"); item_UnselectAll.setToolTipText("Unselec all checks below");
//        item_UnselectAll.addListener(SWT.Selection, toolBarListener);
        
        item_SaveSelections = new ToolItem(custToolbar_CheckConfiguration.getToolBar(), SWT.PUSH);
        item_SaveSelections.setImage(image_floppy_disk); item_SaveSelections.setText("Save selected checks"); item_SaveSelections.setToolTipText("Save the list of checks to a XML file for future reference");
        item_SaveSelections.addListener(SWT.Selection, toolBarListener);
        item_SaveSelections.setEnabled(false);
        
        //This is the separator
        Label verticalSepartor_CheckConfiguration_CheckNextActions = new Label(compCHECKS, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
        verticalSepartor_CheckConfiguration_CheckNextActions.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_CheckConfiguration_CheckNextActions.setBackground(sepatator_color);
                
        //2nd group
        CustomToolbar custToolbar_CheckNextActions = new CustomToolbar(compCHECKS, SWT.FLAT, "Next Actions");
                
        item_RunChecks = new ToolItem(custToolbar_CheckNextActions.getToolBar(), SWT.PUSH);
        item_RunChecks.setImage(image_navigate_right); item_RunChecks.setText("Run checks"); item_RunChecks.setToolTipText("Run the checks against the files you selected");
        item_RunChecks.addListener(SWT.Selection, toolBarListener); 
        item_RunChecks.setEnabled(false);             
        
        //This is the separator
        Label verticalSepartor_CheckNextActions_END = new Label(compCHECKS, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
        verticalSepartor_CheckNextActions_END.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_CheckNextActions_END.setBackground(sepatator_color);
        
        
//        //3rd group
//        CustomToolbar custToolbar_HelpChecks = new CustomToolbar(compCHECKS, SWT.FLAT, "Help");
//        
//        item_help = new ToolItem(custToolbar_HelpChecks.getToolBar(), SWT.NONE);
//        item_help.setImage(image_Help); item_help.setText(" "); item_help.setToolTipText("Help page for the GUI");
//        item_help.addListener(SWT.Selection, toolBarListener);
//            
//        //This is the separator
//        Label verticalSepartor_Help_END_Checks = new Label(compCHECKS, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
//        verticalSepartor_Help_END_Checks.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_Help_END_Checks.setBackground(sepatator_color);
        
        
        //This is the separator between the toolbar and the checks tree.
        Label horSepartor_ToolBar_CheckList = new Label(compChecksTab, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.HORIZONTAL);
        GridData sepGridDataChecksTab = new GridData(GridData.FILL_HORIZONTAL); sepGridDataChecksTab.horizontalSpan = 3; 
        horSepartor_ToolBar_CheckList.setLayoutData(sepGridDataChecksTab);horSepartor_ToolBar_CheckList.setBackground(sepatator_color);
               
        Composite compChecksButtons = new Composite(compChecksTab, SWT.NULL);
        FillLayout fillLayout_Checks = new FillLayout();
        fillLayout_Checks.type = SWT.HORIZONTAL;                  
        compChecksButtons.setLayout(fillLayout_Checks);
       
        cTabItem_Checks.setControl(compChecksTab);
     // -----------here starts RESULTS TAB --------------------      
        Image image_breakpoint = new Image(display, "assets/breakpoint.png");
        Image image_redo = new Image(display, "assets/redo.png");
        Image image_gecko = new Image(display, "assets/gecko.png");
        Image image_navigate_left2 = new Image(display, "assets/navigate_left2_orange.png");
        Image image_exit = new Image(display, "assets/exit.png");
        
        Composite compResultsTab = new Composite(folder, SWT.NULL);
        GridLayout gridLayout_ResultsTab = new GridLayout(4, false);
        compResultsTab.setLayout(gridLayout_ResultsTab);
        
        Composite compRESULTS = new Composite(compResultsTab, SWT.NULL);
        
        GridLayout gridLayout_Results = new GridLayout(10, false);
        gridLayout_Results.marginLeft = 0; gridLayout_Results.marginRight = 0; gridLayout_Results.horizontalSpacing = 0;
        compRESULTS.setLayout(gridLayout_Results);
        GridData sepGridData_Results = new GridData(GridData.FILL_HORIZONTAL); sepGridData_Results.horizontalSpan = 5; 
        compRESULTS.setLayoutData(sepGridData_Results);
        //compRESULTS.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_GRAY));
        compRESULTS.setBackground(lightgray);

                      
        //1st group
        CustomToolbar custToolbar_ResultsProcess = new CustomToolbar(compRESULTS, SWT.FLAT, "Process");             
        
        item_StopChecks = new ToolItem(custToolbar_ResultsProcess.getToolBar(), SWT.PUSH);
        item_StopChecks.setImage(image_breakpoint); item_StopChecks.setText("Stop checks"); //item_StopChecks.setToolTipText("Stop running the checks");
        item_StopChecks.setToolTipText("This feature has not been implemented yet");
        item_StopChecks.addListener(SWT.Selection, toolBarListener);
        item_StopChecks.setEnabled(false);
        
        item_RerunFailed = new ToolItem(custToolbar_ResultsProcess.getToolBar(), SWT.PUSH);
        item_RerunFailed.setImage(image_redo); item_RerunFailed.setText("Rerun failed"); //item_RerunFailed.setToolTipText("Rerun failed checks");
        item_RerunFailed.setToolTipText("This feature has not been implemented yet");
        item_RerunFailed.addListener(SWT.Selection, toolBarListener);
        item_RerunFailed.setEnabled(false);

        //This is the separator
        Label verticalSepartor_Process_Filtering = new Label(compRESULTS, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
        verticalSepartor_Process_Filtering.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_Process_Filtering.setBackground(sepatator_color);
       
        
        //2nd group       
        csFilteringCheckBoxes = new CSFilteringCheckBoxes(compRESULTS, SWT.FLAT);
        //csFilteringCheckBoxes.setEnabled(false);
        csFilteringCheckBoxes.getError().setEnabled(false);
        csFilteringCheckBoxes.getFailed().setEnabled(false);
        csFilteringCheckBoxes.getPassed().setEnabled(false);
        
        
        //This is the separator
        Label verticalSepartor_Filtering_Results = new Label(compRESULTS, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
        verticalSepartor_Filtering_Results.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_Filtering_Results.setBackground(sepatator_color);
        
        
        //3rd group
        CustomToolbar custToolbar_Results = new CustomToolbar(compRESULTS, SWT.FLAT, "Results");
        
        item_SaveResults = new ToolItem(custToolbar_Results.getToolBar(), SWT.PUSH);
        item_SaveResults.setImage(image_floppy_disk); item_SaveResults.setText("Save results"); item_SaveResults.setToolTipText("Save the results to HTML or XML file");
        item_SaveResults.addListener(SWT.Selection, toolBarListener);  
        item_SaveResults.setEnabled(false);
        
        item_SaveToGeck = new ToolItem(custToolbar_Results.getToolBar(), SWT.PUSH);
        item_SaveToGeck.setImage(image_gecko); item_SaveToGeck.setText("Save to geck"); //item_SaveToGeck.setToolTipText("Save the results to a geck. Geck number will be asked when you click this button");
        item_SaveToGeck.setToolTipText("This feature has not been implemented yet");
        item_SaveToGeck.addListener(SWT.Selection, toolBarListener);
        item_SaveToGeck.setEnabled(false);
        
      
        //This is the separator
        Label verticalSepartor_Results_ResultNextActions = new Label(compRESULTS, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
        verticalSepartor_Results_ResultNextActions.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_Results_ResultNextActions.setBackground(sepatator_color);
        
               
        //5th group
        CustomToolbar custToolbar_ResultsNextActions = new CustomToolbar(compRESULTS, SWT.FLAT, "Next Actions");      
    
        item_StartOver = new ToolItem(custToolbar_ResultsNextActions.getToolBar(), SWT.PUSH);
        item_StartOver.setImage(image_navigate_left2); item_StartOver.setText("Start over"); item_StartOver.setToolTipText("Go back to the first tab to start over");
        item_StartOver.addListener(SWT.Selection, toolBarListener);
        
//        item_Quit = new ToolItem(custToolbar_ResultsNextActions.getToolBar(), SWT.PUSH);
//        item_Quit.setImage(image_exit); item_Quit.setText("Quit"); item_Quit.setToolTipText("Quit the tool");
//        item_Quit.addListener(SWT.Selection, toolBarListener);
        
        //This is the separator
        Label verticalSepartor_ResultNextActions_END = new Label(compRESULTS, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
        verticalSepartor_ResultNextActions_END.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_ResultNextActions_END.setBackground(sepatator_color);
                                 

//        //6th group
//        CustomToolbar custToolbar_HelpResults = new CustomToolbar(compRESULTS, SWT.FLAT, "Help");
//        
//        item_help = new ToolItem(custToolbar_HelpResults.getToolBar(), SWT.NONE);
//        item_help.setImage(image_Help); item_help.setText(" "); item_help.setToolTipText("Help page for the GUI");
//        item_help.addListener(SWT.Selection, toolBarListener);
//            
//        //This is the separator
//        Label verticalSepartor_Help_END_Results = new Label(compRESULTS, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.VERTICAL);
//        verticalSepartor_Help_END_Results.setLayoutData(new GridData(GridData.FILL_VERTICAL)); verticalSepartor_Help_END_Results.setBackground(sepatator_color);
        
        
        //This is the separator between the toolbar and the results table.
        Label horSepartor_ToolBar_ResultTable = new Label(compResultsTab, SWT.SEPARATOR | SWT.SHADOW_NONE | SWT.HORIZONTAL);
        GridData sepGridDataResultsTab = new GridData(GridData.FILL_HORIZONTAL); sepGridDataResultsTab.horizontalSpan = 5; 
        horSepartor_ToolBar_ResultTable.setLayoutData(sepGridDataResultsTab);horSepartor_ToolBar_ResultTable.setBackground(sepatator_color);
        
        
        Composite compResultsButtons = new Composite(compResultsTab, SWT.NULL);
        FillLayout fillLayout_Results = new FillLayout();
        fillLayout_Results.type = SWT.HORIZONTAL;                  
        compResultsButtons.setLayout(fillLayout_Results);
       
        cTabItem_Results.setControl(compResultsTab);
        
        // -----------here ends ALL TAB MENUS -------------------- 
        
        //TAB1 CONTENT
        //This is the text box   
        GridLayout groupLayout = new GridLayout();
        Group groupText = new Group(compFilesTab, SWT.NONE);
        groupText.setLayout(groupLayout);
        groupText.setLayoutData(new GridData(GridData.FILL_BOTH));
        groupText.setText("File List (Use the buttons above to select files or changelists. Or you can type the full path to the files)");
        txt = new Text(groupText, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        TxtFocusListener txtFL = new TxtFocusListener(compFilesTab);
        txt.setLayoutData(new GridData(GridData.FILL_BOTH));
        txt.addFocusListener(txtFL);
        txt.setText(TxtFocusListener.introText); txt.setForeground(compFilesTab.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        new Label(compFilesTab, SWT.NONE);
        //new Label(compFilesTab, SWT.NONE);
                      
        txt.addModifyListener(new ModifyListener(){
			@Override
			public void modifyText(ModifyEvent arg0) {
	            Map<Integer, TreeItem> checkListMap = new HashMap<Integer, TreeItem>();
	            final Map<Integer, String> checkNameMap= new HashMap<Integer, String>();
                //This is to disable the button if a checkbox is not selected
                final Map<Integer, String> checkedList = CheckListTree.getInstance().getCheckedStandards(checkListMap, checkNameMap);
                //If there is a file and check then enable the related buttons 
                if (Gui.txt.getText().trim().length() > 0 && checkedList.size() > 0){
					item_SpecifyChecks.setEnabled(true);
					item_clearList.setEnabled(true);
					item_RunChecks.setEnabled(true);
                } else if (Gui.txt.getText().trim().length() > 0){
                	//Gui.item_SaveSelections.setEnabled(true);               	
					item_SpecifyChecks.setEnabled(true);
					item_clearList.setEnabled(true);
                } else{
                	//Gui.item_SaveSelections.setEnabled(false);
                	item_RunChecks.setEnabled(false);
					item_SpecifyChecks.setEnabled(false);
					item_clearList.setEnabled(false);
                }
//				if (txt.getText().length() > 0){
//					item_SpecifyChecks.setEnabled(true);
//					item_clearList.setEnabled(true);
//				}else{
//					item_SpecifyChecks.setEnabled(false);
//					item_clearList.setEnabled(false);
//				}
			}});
//#########################################################################################################################        
        
        //TAB2 CONTENT
        //This is the checks check box tree 
        GridLayout groupLayoutChecks = new GridLayout();
        groupLayoutChecks.numColumns = 2;
        Group groupChecks = new Group(compChecksTab, SWT.NONE);       
        groupChecks.setLayout(groupLayoutChecks);
        groupChecks.setLayoutData(new GridData(GridData.FILL_BOTH));
        
        GridData checksGridData = new GridData(GridData.FILL_VERTICAL);
        checksGridData.widthHint = 400;
        QueryDatabase qrydb = new QueryDatabase();
        List<CheckDBDetail> checkList = qrydb.getFullCheckList();
        //System.out.println(checkList);
        CheckListTree clt = CheckListTree.getInstance();
        clt.createCheckListTree(groupChecks, checksGridData, checkList);
 
        
        //This creates a label on the right side of the 
        //window to provide information  about each check
        helpLabel = new Label(groupChecks, SWT.BORDER); 
        GridData checkLabelGridData = new GridData(GridData.FILL_BOTH);
        checkLabelGridData.widthHint = 700;
        helpLabel.setSize(300,300);
        helpLabel.setLocation(0, 0);
        helpLabel.setLayoutData(checkLabelGridData);  
        helpLabel.setText("Please expand the tree on the left and click on a check to view the check details.");
        
        Map<Integer, TreeItem> checkListMap = new HashMap<Integer, TreeItem>();
        Map<Integer, String> checkNameMap= new HashMap<Integer, String>();
        checkNameMap = CheckListTree.getInstance().getCheckedStandards(checkListMap, checkNameMap);
 
//#########################################################################################################################
        
        //TAB3 CONTENT
        GridLayout groupLayoutResults = new GridLayout();
        groupResults = new Group(compResultsTab, SWT.NONE);       
        groupResults.setLayout(groupLayoutResults);
        GridData tableGridData = new GridData(GridData.FILL_BOTH);
        groupResults.setLayoutData(tableGridData);
        groupResults.setText(" ");
        
     
       //progress is created in here      
            runCheckProgressBar.setBar(groupResults);
            ProgressBar bar = runCheckProgressBar.getBar();
            runCheckProgressBar.setGroup(groupResults);
        
      //This is the progress bar
      GridLayout progressBarGridLayout = new GridLayout();
      progressBarGridLayout.numColumns = 1;
      //GridData progressBarGridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
      RunCheckProgressBar progressBar = new RunCheckProgressBar();
      int value = 0;
      int numFiles = 0;

      //ProgressBar bar = new ProgressBar (compResultsTab, SWT.SMOOTH);
      progressBar.createAndUpdateProgressBar(groupResults, bar, value, numFiles);
        
        //This is the results table
        Table table = new Table(groupResults, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP | SWT.MULTI);
        table.setHeaderVisible(true);
        table.getVerticalBar().setVisible(true);
        //String[] titles = { "Override", "Rerun", "Status", "Check", "Filename", "Existing Line Numbers", "New Line Numbers" };
        String[] titles = { "Status", "Check", "Filename", "Existing Line Numbers", "New Line Numbers" };
        
        for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) {
            TableColumn column = new TableColumn(table, SWT.NULL);
            column.setText(titles[loopIndex]);
            //column.setWidth(80);
        }
        
        runPerl.setTable(table, titles);
        runPerl.setShell(shell, display);
        runPerl.setGroupResults(groupResults);
        toolBarListener.setTable(table,titles);
        CSFilteringCheckBoxes.setTable(table, titles);
        CSFilteringCheckBoxes.setShell(shell, display);
        CSFilteringCheckBoxes.setGroupResults(groupResults);
        
        
         int frameShell = shell.getSize().x;
         tableGridData.widthHint = frameShell;
         table.setLayoutData(tableGridData);
         
         for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) {
             table.getColumn(loopIndex).pack();
        }
       table.setRedraw(true);
             
//#########################################################################################################################
     
        shell.addShellListener(new ShellListener() {

            public void shellIconified(ShellEvent e) {
            }
            public void shellDeiconified(ShellEvent e) {
            }
            public void shellDeactivated(ShellEvent e) {
            }
            public void shellClosed(ShellEvent e) {
            }
            public void shellActivated(ShellEvent e) {
            }
        });
        
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
    
    public static String getFileList(){      
        return txt.getText();
    }
    
    
    public static boolean populateResultsTable(final List<CheckDetail> checkDetails, final Shell shell, final Table table, final String[] titles, final boolean newRun, final boolean evenRow, final Group groupResults_new, final int value, final int numFiles){        
 	
        evenRowFine = evenRow;
        display.asyncExec(new Runnable() {
            public void run() {

        if (newRun){
            table.removeAll();
        }else{
            //do not clean table            
        }
        
        
        //upDateProgressBar(5, 10);
        
        for(Iterator<CheckDetail> i = checkDetails.iterator();i.hasNext();) {
            CheckDetail checkDetail = i.next();
            
            //update progress bar
            upDateProgressBar(value, numFiles);
            
           //Showing only the failed results requires a change in CSFilteringCheckBoxes class. 
           //This features will be added in the next release
           //if (!checkDetail.getStatus().equalsIgnoreCase("PASSED")){
                TableItem item = new TableItem(table, SWT.NULL);
                item.setText(0, checkDetail.getStatus()); //Status
                item.setText(1, checkDetail.getName()); //Check
                item.setText(2, checkDetail.getFileName()); //Filename
                item.setText(3, checkDetail.getExistingLineNumbers()); //Existing Line Numbers
                item.setText(4, checkDetail.getNewLineNumbers()); //New Line Numbers
                
                //if this is true then, we do let the user to save 
                //the results table to a file or a geck
                tableHasData = true;
                //This is to make shadow for every other line
                if (evenRowFine){
                    //item.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
                    evenRowFine = false;        
                    i.remove(); // clear
                } else{
                    evenRowFine = true;
                }
            //}
                
        }
         
         for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) {
              table.getColumn(loopIndex).pack();
         }
        table.setRedraw(true);
        
      //This is to sort the columns in the table
        Listener sortListener = new Listener() {
            int prevSortIndex = -1;
            int prevSortDirection = 1;
            int prevSortDir;
            
            public void handleEvent(Event e) {
                TableItem[] items = table.getItems();
                Collator collator = Collator.getInstance(Locale.getDefault());
                TableColumn column = (TableColumn) e.widget;
                int index = column == table.getColumn(0) ? 0 : 1;
                if (prevSortIndex == index) {
                    prevSortDir *= -1;
                } else {
                    prevSortDir = 1;
                    prevSortIndex = index;
                }
                for (int i = 1; i < items.length; i++) {
                    String value1 = items[i].getText(index);
                    for (int j = 0; j < i; j++) {
                        String value2 = items[j].getText(index);
                        if ((collator.compare(value1, value2) * prevSortDir) < 0) {
                            String[] values = { items[i].getText(0),
                                    items[i].getText(1), items[i].getText(2),
                                    items[i].getText(3) };
                            items[i].dispose();
                            TableItem item = new TableItem(table, SWT.NONE, j);
                            item.setText(values);
                            items = table.getItems();
                            break;
                        }
                    }
                }
                table.setSortColumn(column);
            }
        };
        
        table.getColumn(0).addListener(SWT.Selection, sortListener);
        table.getColumn(1).addListener(SWT.Selection, sortListener);
        table.setSortColumn(table.getColumn(0));
        table.setSortDirection(SWT.TOP);
        
        table.setRedraw(true);
    }
  });
            
     return evenRowFine;
    }
    
    
    public static void upDateProgressBar(int value, int numFiles){
    	RunCheckProgressBar progressBar= new RunCheckProgressBar();
    	ProgressBar bar = progressBar.getBar();
    	progressBar.createAndUpdateProgressBar(groupResults, bar, value, numFiles);
    }
    
    public static void reenableItem23(){
        display.asyncExec(new Runnable() {
            public void run() {
                item_RunChecks.setEnabled(true);
            }
        });
    }
    
    public static boolean getTableInfo(){        
        return tableHasData;
    }
        
    
    public static  void setcompRESULTS(Composite compRESULTS){       
        compRESULTS_toolbar = compRESULTS;
    }
     
    public static Composite getcompRESULTS(){
        return compRESULTS_toolbar;
    }
    
}

Open in new window


Thanks,
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tolgar,

Just questioning the B grading? You haven't left any comments to explain. What was not right or not complete about my answer?

Cheers
Avatar of Tolgar

ASKER

You are right. This should have been marked as A. My bad.

I would be happy to re-enter my rating if you can reopen the question.

Sorry,
Thanks for that! ;)