001: /*
002: * ValidationNotifier.java
003: *
004: * Created on February 13, 2007, 7:04 PM
005: */
006:
007: package org.netbeans.modules.mobility.jsr172.wizard;
008:
009: import java.awt.BorderLayout;
010: import java.awt.Component;
011: import java.util.List;
012: import javax.swing.Icon;
013: import javax.swing.ImageIcon;
014: import javax.swing.JLabel;
015: import javax.swing.JList;
016: import javax.swing.JPanel;
017: import javax.swing.ListCellRenderer;
018: import javax.swing.ListModel;
019: import javax.swing.event.ListDataListener;
020: import org.netbeans.modules.e2e.api.wsdl.wsdl2java.WSDL2Java;
021: import org.netbeans.modules.e2e.api.wsdl.wsdl2java.WSDL2Java.ValidationResult.ErrorLevel;
022: import org.openide.util.NbBundle;
023: import org.openide.util.Utilities;
024:
025: /**
026: *
027: * @author Michal Skvor
028: */
029: public class ValidationNotifier extends javax.swing.JPanel {
030:
031: List<WSDL2Java.ValidationResult> validationResults;
032:
033: /** Creates new form ValidationNotifier */
034: public ValidationNotifier(
035: List<WSDL2Java.ValidationResult> validationResults) {
036: this .validationResults = validationResults;
037:
038: initComponents();
039:
040: initData();
041:
042: initAccessibility();
043: }
044:
045: private void initData() {
046: validationList.setModel(new IconListModel(validationResults));
047: validationList.setCellRenderer(new IconListRenderer());
048: }
049:
050: private void initAccessibility() {
051: getAccessibleContext().setAccessibleDescription(
052: NbBundle.getMessage(ClientInfo.class,
053: "ACSD_Validation_Results"));
054:
055: validationList.getAccessibleContext().setAccessibleDescription(
056: NbBundle.getMessage(ValidationNotifier.class,
057: "ACSD_Validation_List"));
058: }
059:
060: /** This method is called from within the constructor to
061: * initialize the form.
062: * WARNING: Do NOT modify this code. The content of this method is
063: * always regenerated by the Form Editor.
064: */
065: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
066: private void initComponents() {
067:
068: jLabel1 = new javax.swing.JLabel();
069: jScrollPane1 = new javax.swing.JScrollPane();
070: validationList = new javax.swing.JList();
071:
072: jLabel1.setText(org.openide.util.NbBundle.getMessage(
073: ValidationNotifier.class, "LBL_Validation_Results")); // NOI18N
074:
075: jScrollPane1.setViewportView(validationList);
076:
077: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
078: this );
079: this .setLayout(layout);
080: layout
081: .setHorizontalGroup(layout
082: .createParallelGroup(
083: org.jdesktop.layout.GroupLayout.LEADING)
084: .add(
085: layout
086: .createSequentialGroup()
087: .addContainerGap()
088: .add(
089: layout
090: .createParallelGroup(
091: org.jdesktop.layout.GroupLayout.LEADING)
092: .add(
093: jScrollPane1,
094: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
095: 437,
096: Short.MAX_VALUE)
097: .add(jLabel1))
098: .addContainerGap()));
099: layout.setVerticalGroup(layout.createParallelGroup(
100: org.jdesktop.layout.GroupLayout.LEADING).add(
101: layout.createSequentialGroup().addContainerGap().add(
102: jLabel1).addPreferredGap(
103: org.jdesktop.layout.LayoutStyle.RELATED).add(
104: jScrollPane1,
105: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
106: 236, Short.MAX_VALUE).addContainerGap()));
107: }// </editor-fold>//GEN-END:initComponents
108:
109: // Variables declaration - do not modify//GEN-BEGIN:variables
110: private javax.swing.JLabel jLabel1;
111: private javax.swing.JScrollPane jScrollPane1;
112: private javax.swing.JList validationList;
113:
114: // End of variables declaration//GEN-END:variables
115:
116: private static final class IconListModel implements ListModel {
117:
118: private List<WSDL2Java.ValidationResult> validationResults;
119:
120: public IconListModel(
121: List<WSDL2Java.ValidationResult> validationResults) {
122: this .validationResults = validationResults;
123: }
124:
125: public int getSize() {
126: return validationResults.size();
127: }
128:
129: public Object getElementAt(int index) {
130: return validationResults.get(index);
131: }
132:
133: public void addListDataListener(ListDataListener arg0) {
134: }
135:
136: public void removeListDataListener(ListDataListener arg0) {
137: }
138: }
139:
140: private static final Icon ICON_WARNING = new ImageIcon(
141: Utilities
142: .loadImage("org/netbeans/modules/mobility/jsr172/resources/warning.png"));
143: private static final Icon ICON_ERROR = new ImageIcon(
144: Utilities
145: .loadImage("org/netbeans/modules/mobility/jsr172/resources/error.png"));
146:
147: private static final class IconListRenderer implements
148: ListCellRenderer {
149:
150: public Component getListCellRendererComponent(JList arg0,
151: Object data, int arg2, boolean arg3, boolean arg4) {
152: WSDL2Java.ValidationResult rowData = (WSDL2Java.ValidationResult) data;
153: JLabel row = new JLabel();
154: row.setText(rowData.getMessage());
155:
156: if (ErrorLevel.FATAL.equals(rowData.getErrorLevel())) {
157: row.setIcon(ICON_ERROR);
158: } else if (ErrorLevel.WARNING.equals(rowData
159: .getErrorLevel())) {
160: row.setIcon(ICON_WARNING);
161: }
162:
163: return row;
164: }
165: }
166:
167: }
|