001: package org.enhydra.jawe.base.panel.panels;
002:
003: import java.awt.Component;
004: import java.awt.Dimension;
005: import java.util.ArrayList;
006: import java.util.Iterator;
007: import java.util.List;
008:
009: import javax.swing.DefaultListModel;
010: import javax.swing.JList;
011: import javax.swing.JScrollPane;
012: import javax.swing.ListSelectionModel;
013:
014: import org.enhydra.jawe.SearchResult;
015: import org.enhydra.jawe.base.xpdlvalidator.ValidationError;
016: import org.enhydra.shark.xpdl.XMLElement;
017:
018: /**
019: * Creates a references panel.
020: * @author Sasa Bojanic
021: */
022: public class ValidationErrorOrSearchResultListPanel extends
023: XMLBasicPanel {
024:
025: protected static Dimension listDimension = new Dimension(750, 250);
026:
027: protected JList allParam;
028:
029: public ValidationErrorOrSearchResultListPanel(XMLElement checked,
030: List errors, String title, boolean hasBorder,
031: boolean hasEmptyBorder) {
032:
033: super (null, checked, title, true, hasBorder, hasEmptyBorder);
034:
035: allParam = createList();
036: setupList();
037:
038: fillListContent(errors);
039:
040: JScrollPane scrollParam = new JScrollPane();
041: scrollParam.setAlignmentX(Component.LEFT_ALIGNMENT);
042: //scrollParam.setAlignmentY(Component.TOP_ALIGNMENT);
043:
044: scrollParam.setViewportView(allParam);
045: scrollParam.setPreferredSize(new Dimension(listDimension));
046:
047: add(scrollParam);
048: }
049:
050: public JList getList() {
051: return allParam;
052: }
053:
054: protected XMLElement getElementToShow() {
055: XMLElement editElement = null;
056: if (allParam.getModel().getSize() > 0) {
057: try {
058: Object el = allParam.getSelectedValue();
059: if (el instanceof ValidationError) {
060: editElement = ((ValidationError) el).getElement();
061: } else {
062: editElement = ((SearchResult) el).getElement();
063: }
064: } catch (Exception ex) {
065: ex.printStackTrace();
066: }
067: }
068: return editElement;
069: }
070:
071: protected JList createList() {
072: DefaultListModel listModel = new DefaultListModel();
073:
074: JList l = new JList(listModel);
075: return l;
076: }
077:
078: protected void setupList() {
079: allParam.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
080:
081: allParam.setAlignmentX(Component.LEFT_ALIGNMENT);
082: allParam.setAlignmentY(Component.TOP_ALIGNMENT);
083: }
084:
085: protected void fillListContent(List errors) {
086: DefaultListModel listModel = (DefaultListModel) allParam
087: .getModel();
088: Iterator it = errors.iterator();
089: while (it.hasNext()) {
090: listModel.addElement(it.next());
091: }
092: }
093:
094: public void cleanup() {
095: allParam = null;
096: }
097:
098: public List getElements() {
099: List l = new ArrayList();
100: DefaultListModel listModel = (DefaultListModel) allParam
101: .getModel();
102: for (int i = 0; i < listModel.getSize(); i++) {
103: l.add(listModel.getElementAt(i));
104: }
105: return l;
106: }
107:
108: public void removeElement(Object el) {
109: DefaultListModel listModel = (DefaultListModel) allParam
110: .getModel();
111: listModel.removeElement(el);
112: }
113:
114: }
|