Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i want to retrieve value in my Ui class to dispaly using array list ..but only single value is appearing
Java
public class UiClass {
    public Composite method() {
        final Composite container = (Composite) super.createContents(parent);

        container.setLayout(new GridLayout(3, true));
        container.setLayoutData(new GridData(GridData.FILL_BOTH));
        
       // String[] lblsInGroup1 = {"CMM Upload Data", "DTS Data Import","KTDRS data Import","High speed pickImport","Pre post TestPhoto", };
        //String[] lblsInGroup2 = {"Diadem: Create Graphs","Pre post TestPhoto","post Data Mesurement","Diadem:upload Process Data"};
        //String[] lblsInGroup3 = {"Final test report upload","Test Label Data"};
    //    XmlTest xmlTestObj = new XmlTest(); 
        
        ArrayList<String> lblsInGroup1 = new ArrayList<String>();
        ArrayList<String> lblsInGroup2 = new ArrayList<String>();
        ArrayList<String> lblsInGroup3 = new ArrayList<String>();
        ArrayList<String> lblsInGroup4 = new ArrayList<String>();
        
        SAXBuilder builder = new SAXBuilder();	
        File xmlFile = new File("GroupElement.xml");
        ArrayList<String> listOfTitles = new ArrayList<String>();
        ArrayList<String> listOfValues = new ArrayList<String>();

        try {    	
            Document document = (Document) builder.build(xmlFile);
            Element rootNode = document.getRootElement();
            List list = rootNode.getChildren("GroupElement");
            System.err.println(list.size());
            for (int i = 0;
                    i < list.size();
                    i++) {			    	
                Element groupNode = (Element) list.get(i);
                
                ArrayList<String> tempArray = new ArrayList<String>();			    	
                tempArray.add(groupNode.getAttribute("Title").getValue());
                
                List itemList = groupNode.getChildren();
                Iterator listIter = itemList.iterator();

                while (listIter.hasNext()){
                    Element childNode = (Element) listIter.next();
                    //System.out.println("Item : " +groupNode.getAttribute("GroupElement").getValue());
                    System.out.println("Item : " + childNode.getAttribute("plugin").getValue());
                   // System.out.println("Item : " + childNode.getAttributeValue("plugin"));
                   //   listOfValues.add(getStringFromMap(childNode.getAttributeValue("plugin")));
                }
                System.err.println(itemList.size());
                for (int j = 0; j < itemList.size(); j++) {
                    tempArray.add(groupNode.getChildText("Item"));
                }
                tempArray.add(groupNode.getChildText("Item"));
                if (i==0) {
                    lblsInGroup1 = tempArray;
                } else if (i==1) {
                    lblsInGroup2 = tempArray;
                } else if (i==2) {
                    lblsInGroup3 = tempArray;
                } else if (i==3) {
                    lblsInGroup4 = tempArray;
                }
                
            }
                   
        } catch (IOException io) {
            System.out.println(io.getMessage());
        } catch (JDOMException jdomex) {
            System.out.println(jdomex.getMessage());
        }			    

        if (lblsInGroup1.size()>0) {
            Label  myLabelheading= new Label(container,SWT.FILL);
            GridData gridData11 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1,1);
            gridData11.horizontalAlignment = GridData.FILL;
            gridData11.horizontalSpan= 3;
            myLabelheading.setText(lblsInGroup1.get(0));
            FontData[] _font =  myLabelheading.getFont().getFontData();
            _font[0].setHeight(11);
            _font[0].setStyle(SWT.BOLD);
            myLabelheading.setFont( new Font(null,_font[0]));
            myLabelheading.setLayoutData(gridData11);

            //for (String currStr : lblsInGroup1)
            for (int _ind = 1;
                    _ind < lblsInGroup1.size();
                    ++_ind) {
                String currStr = lblsInGroup1.get(_ind);
                Label _lbl= new Label(container,SWT.FILL);
                GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1,1);
                _lbl.setText(currStr); 
                _lbl.setLayoutData(gridData);

                Button _btn = new Button(container,SWT.PUSH);
                gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1,1);
                _btn.setText("START"); 
                _btn.setLayoutData(gridData);

                Button _chkbtn= new Button(container,SWT.CHECK);
                gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1,1);
                _chkbtn.setText("STATUS");
                _chkbtn.setSelection(false);
                _chkbtn.setLayoutData(gridData);
            }
        }
                
        if (lblsInGroup2.size() > 0) {
            Label _lbl= new Label(container,SWT.FILL);
            GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1,1);
            gridData.horizontalAlignment = GridData.FILL;
            gridData.horizontalSpan = 3;
            _lbl.setText(lblsInGroup2.get(0));
            FontData[] fontData =  _lbl.getFont().getFontData();
            fontData[0].setHeight(11);
            fontData[0].setStyle(SWT.BOLD);
            _lbl.setFont( new Font(null,fontData[0]));
            _lbl.setLayoutData(gridData);	      

            for (int _ind = 1;
                    _ind < lblsInGroup2.size();
                    ++_ind) {	
                String currStr = lblsInGroup2.get(_ind);
                _lbl= new Label( container,SWT.FILL);
                gridData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1,1);		    	  	        
                _lbl.setText(currStr);
                _lbl.setLayoutData(gridData);

                Button _btn = new Button( container,SWT.PUSH);
                gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1,1);
                _btn.setText("START");
                _btn.setLayoutData(gridData);

                Button _chkbtn= new Button( container,SWT.CHECK);
                gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1,1);
                _chkbtn.setText("STATUS");
                _chkbtn.setLayoutData(gridData);
            }
        }

        if (lblsInGroup3.size() > 0) {
            Label _lbl= new Label(container,SWT.FILL);
            GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1,1);
            gridData.horizontalAlignment = GridData.FILL;
            gridData.horizontalSpan = 3;
            FontData[] fData =  _lbl.getFont().getFontData();
            fData[0].setHeight(11);
            fData[0].setStyle(SWT.BOLD);
            _lbl.setText(lblsInGroup3.get(0));
            _lbl.setFont( new Font(null,fData[0]));
            _lbl.setLayoutData(gridData);

            for (int _ind = 1;
                    _ind < lblsInGroup3.size();
                    ++_ind) {	
                String currStr = lblsInGroup3.get(_ind);
                Label _lblline= new Label(container,SWT.FILL);
                GridData gridDataline = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1,1);		    
                _lblline.setText(currStr);
                _lblline.setLayoutData(gridDataline);

                Button _btn = new Button( container,SWT.PUSH);
                gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1,1);
                _btn.setText("START");
                _btn.setLayoutData(gridData);

                Button _chkbtn= new Button( container,SWT.CHECK);
                gridData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1,1);
                _chkbtn.setText("STATUS");
                _chkbtn.setLayoutData(gridData);
            }
        }
        return container;
    }

        
    private Display getDisplay() {
        // TODO Auto-generated method stub
        return null;
    }	  
}
Posted
Updated 11-Jan-12 0:56am
v3
Comments
Nagy Vilmos 11-Jan-12 6:57am    
Shortened title and re-formatted code.
Nagy Vilmos 11-Jan-12 6:59am    
What are the outputs from the debug print statements to the standard output?

1 solution

Java
for (int _ind = 1;_ind < lblsInGroup3.size(); ++_ind){
  // fancy GUI code
}


I guess only humans are stating counting from 1. I'm pretty sure not even animals are doing it.
You need to start at 0.

And there is another thingy - you are counting _ind up before you use it. Doesn't really matter at this point, but you should be aware that it's a significant difference whether the value is counted up before or after use.

How much values are supposed to be in the ArrayList? Debug and figure out if the ArrayList has more than one value.

EDIT: Do me and yourself a favor:
Pull the XML-Code out of there.
Set up a second class "XMLParser" and let that one do the XML stuff.
Then you would only have to call a GET-method(s) to get the ArrayLists.

Benefit is a much better to read GUI Code and a clear defined XML Parser. It would make things much easier.
 
Share this answer
 
v3
Comments
Nagy Vilmos 11-Jan-12 14:10pm    
Sensible!
I didn't even read the code, I just formatted it to make some sense.
TorstenH. 12-Jan-12 3:07am    
Well, that is what I saw. There might be more in there or a complete other problem. We don't know what is hidden in that XML-file.

The user doesn't reply any more.
vicky patole 12-Jan-12 6:08am    
Torsten...i did it using XmlParser file...thanks for your help..and and for your kind information at int_ind=0...this is rootGroup is ,,we dont want that to b display on Ui,so its better to start from _ind=1....GOT IT

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900