001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.faces.dt_1_1.component.html;
042:
043: import java.awt.Color;
044: import java.awt.Component;
045: import java.awt.Dimension;
046: import java.awt.GridBagConstraints;
047: import java.awt.GridBagLayout;
048: import java.awt.Insets;
049: import java.awt.SystemColor;
050: import java.awt.event.ActionEvent;
051: import java.awt.event.ActionListener;
052: import java.awt.event.MouseAdapter;
053: import java.awt.event.MouseEvent;
054: import java.awt.event.MouseListener;
055: import java.sql.ResultSet;
056: import java.util.ArrayList;
057: import java.util.HashMap;
058: import java.util.Iterator;
059: import javax.faces.component.html.HtmlCommandButton;
060: import javax.faces.component.html.HtmlCommandLink;
061: import javax.faces.component.html.HtmlGraphicImage;
062: import javax.faces.component.html.HtmlInputSecret;
063: import javax.faces.component.html.HtmlInputText;
064: import javax.faces.component.html.HtmlInputTextarea;
065: import javax.faces.component.html.HtmlMessage;
066: import javax.faces.component.html.HtmlOutputText;
067: import javax.faces.component.html.HtmlPanelGrid;
068: import javax.faces.component.html.HtmlPanelGroup;
069: import javax.faces.component.html.HtmlSelectBooleanCheckbox;
070: import javax.faces.component.html.HtmlSelectOneMenu;
071: import javax.faces.component.html.HtmlSelectOneRadio;
072: import javax.swing.AbstractListModel;
073: import javax.swing.BorderFactory;
074: import javax.swing.ComboBoxModel;
075: import javax.swing.DefaultComboBoxModel;
076: import javax.swing.DefaultListCellRenderer;
077: import javax.swing.JButton;
078: import javax.swing.JComboBox;
079: import javax.swing.JLabel;
080: import javax.swing.JList;
081: import javax.swing.JPanel;
082: import javax.swing.JScrollPane;
083: import javax.swing.JTabbedPane;
084: import javax.swing.JTextField;
085: import javax.swing.ListSelectionModel;
086: import javax.swing.border.TitledBorder;
087: import javax.swing.event.DocumentEvent;
088: import javax.swing.event.DocumentListener;
089: import javax.swing.event.ListSelectionEvent;
090: import javax.swing.event.ListSelectionListener;
091: import javax.swing.text.BadLocationException;
092: import javax.swing.text.Document;
093:
094: import org.netbeans.modules.visualweb.faces.dt.util.ComponentBundle;
095: import com.sun.rave.designtime.Constants;
096: import com.sun.rave.designtime.DesignBean;
097: import com.sun.rave.designtime.DesignContext;
098: import com.sun.rave.designtime.Result;
099: import com.sun.rave.designtime.ResultMessage;
100:
101: public class HtmlDataTableCustomizerColumnsPanel extends JPanel {
102:
103: private static final ComponentBundle bundle = ComponentBundle
104: .getBundle(HtmlDataTableCustomizerColumnsPanel.class);
105:
106: private JLabel lblAvailable = new JLabel();
107: private JLabel lblDisplayed = new JLabel();
108: private JScrollPane scrollAvailable = new JScrollPane();
109: private JScrollPane scrollDisplayed = new JScrollPane();
110: private JList listAvailable = new JList();
111: private JList listDisplayed = new JList();
112: private ResultSetColumnListModel modelAvailable = new ResultSetColumnListModel();
113: private DisplayColumnListModel modelDisplayed = new DisplayColumnListModel();
114: private CompTypeComboModel modelCompType = new CompTypeComboModel();
115: private JButton btnAdd = new JButton();
116: private JButton btnRemoveOne = new JButton();
117: private JButton btnUp = new JButton();
118: private JButton btnDown = new JButton();
119: private JButton btnNew = new JButton();
120: private JButton btnRemoveAll = new JButton();
121: private JPanel panColProps = new JPanel();
122: private TitledBorder titledBorder1;
123: private GridBagLayout gridBagLayout1 = new GridBagLayout();
124: private JLabel lblHeaderText = new JLabel();
125: private JLabel lblFooterText = new JLabel();
126: private JLabel lblCompType = new JLabel();
127: private JLabel lblValue = new JLabel();
128: private JTextField tfHeaderText = new JTextField();
129: private JComboBox comboCompType = new JComboBox();
130: private GridBagLayout gridBagLayout2 = new GridBagLayout();
131: private JPanel jPanel2 = new JPanel();
132: private JTextField tfFooterText = new JTextField();
133: private JTextField tfValue = new JTextField();
134: private HtmlDataTableState table;
135: private DesignContext context;
136: private JComboBox sourceCombo = new JComboBox();
137: private DefaultComboBoxModel sourceComboModel = new DefaultComboBoxModel();
138: private JLabel sourceLabel = new JLabel();
139:
140: HtmlDataTableCustomizerColumnsPanel() {
141: try {
142: jbInit();
143: } catch (Exception ex) {
144: ex.printStackTrace();
145: }
146: }
147:
148: void setTable(HtmlDataTableState table) {
149: this .table = table;
150: }
151:
152: void setContext(DesignContext context) {
153: updating = true;
154: this .context = context;
155: populateSourceComboModel();
156: sourceCombo.setModel(sourceComboModel);
157: updating = false;
158: initState();
159: }
160:
161: private void populateSourceComboModel() {
162: sourceComboModel.removeAllElements();
163: sourceComboModel.addElement(null);
164:
165: java.util.List sortedContexts = new ArrayList();
166: sortedContexts.add(this .context);
167: java.util.List sessionContexts = new ArrayList();
168: java.util.List applicationContexts = new ArrayList();
169: DesignContext[] contexts = context.getProject()
170: .getDesignContexts();
171: for (int i = 0; i < contexts.length; i++) {
172: if (contexts[i] == this .context) {
173: continue;
174: }
175: Object scope = contexts[i]
176: .getContextData(Constants.ContextData.SCOPE);
177: if ("session".equals(scope)) { //NOI18N
178: sessionContexts.add(contexts[i]);
179: } else if ("application".equals(scope)) { //NOI18N
180: applicationContexts.add(contexts[i]);
181: }
182: }
183: sortedContexts.addAll(sessionContexts);
184: sortedContexts.addAll(applicationContexts);
185:
186: for (Iterator iter = sortedContexts.iterator(); iter.hasNext();) {
187: DesignContext aContext = (DesignContext) iter.next();
188: DesignBean root = aContext.getRootContainer();
189: fillCombo(root.getChildBeans());
190: }
191: }
192:
193: private void fillCombo(DesignBean[] beans) {
194: for (int i = 0; i < beans.length; i++) {
195: Object inst = beans[i].getInstance();
196: if (inst instanceof javax.faces.model.DataModel
197: || inst instanceof java.util.List
198: || inst instanceof Object[]
199: || inst instanceof ResultSet) {
200: if (!(inst instanceof com.sun.rave.faces.data.RowSetDataModel)
201: && //do not put in RowSetDataModels
202: !(inst instanceof com.sun.rave.faces.data.CachedRowSetDataModel)) { //do not put in CachedRowSetDataModels
203: sourceComboModel.addElement(beans[i]);
204: }
205: }
206: }
207: }
208:
209: private void columnsPanel_actionPerformed(ActionEvent e) {
210: Object s = e.getSource();
211: if (s == sourceCombo) {
212: sourceCombo_actionPerformed(e);
213: } else if (s == btnAdd) {
214: btnAdd_actionPerformed(e);
215: } else if (s == btnRemoveOne) {
216: btnRemoveOne_actionPerformed(e);
217: } else if (s == btnUp) {
218: btnUp_actionPerformed(e);
219: } else if (s == btnDown) {
220: btnDown_actionPerformed(e);
221: } else if (s == btnNew) {
222: btnNew_actionPerformed(e);
223: } else if (s == btnRemoveAll) {
224: btnRemoveAll_actionPerformed(e);
225: } else if (s == comboCompType) {
226: comboCompType_actionPerformed(e);
227: }
228: }
229:
230: private void tf_changed(DocumentEvent e) {
231: Object s = e.getDocument();
232: if (s == tfHeaderText.getDocument()) {
233: tfHeaderText_changed(e);
234: } else if (s == tfFooterText.getDocument()) {
235: tfFooterText_changed(e);
236: } else if (s == tfValue.getDocument()) {
237: tfValue_changed(e);
238: }
239: }
240:
241: private void list_valueChanged(ListSelectionEvent e) {
242: Object s = e.getSource();
243: if (s == listAvailable.getSelectionModel()) {
244: listAvailable_valueChanged(e);
245: } else if (s == listDisplayed.getSelectionModel()) {
246: listDisplayed_valueChanged(e);
247: }
248: }
249:
250: private void columnsPanel_mouseClicked(MouseEvent e) {
251: Object s = e.getSource();
252: if (s == listAvailable) {
253: if (e.getClickCount() == 2) {
254: btnAdd_actionPerformed(null);
255: }
256: }
257: }
258:
259: private void listDisplayed_mouseClicked(MouseEvent e) {
260: Object s = e.getSource();
261: if (s == listDisplayed) {
262: if (e.getClickCount() == 2) {
263: btnRemoveOne_actionPerformed(null);
264: }
265: }
266: }
267:
268: private void jbInit() throws Exception {
269: updating = true;
270:
271: ActionListener actionListener = new ActionListener() {
272: public void actionPerformed(ActionEvent e) {
273: columnsPanel_actionPerformed(e);
274: }
275: };
276: DocumentListener documentListener = new DocumentListener() {
277: public void insertUpdate(DocumentEvent e) {
278: tf_changed(e);
279: }
280:
281: public void removeUpdate(DocumentEvent e) {
282: tf_changed(e);
283: }
284:
285: public void changedUpdate(DocumentEvent e) {
286: tf_changed(e);
287: }
288: };
289: ListSelectionListener listSelectionListener = new ListSelectionListener() {
290: public void valueChanged(ListSelectionEvent e) {
291: list_valueChanged(e);
292: }
293: };
294:
295: MouseListener mouseListener = new MouseAdapter() {
296: public void mouseClicked(MouseEvent e) {
297: columnsPanel_mouseClicked(e);
298: }
299: };
300:
301: MouseListener listDisplayedMouseListener = new MouseAdapter() {
302: public void mouseClicked(MouseEvent e) {
303: listDisplayed_mouseClicked(e);
304: }
305: };
306:
307: sourceLabel.setText(bundle.getMessage("tableCustDataSource")); //NOI18N
308: sourceCombo.setRenderer(new SourceComboRenderer());
309: sourceCombo.setEditable(false);
310: sourceCombo.addActionListener(actionListener);
311: titledBorder1 = new TitledBorder(BorderFactory
312: .createEtchedBorder(Color.white, new Color(165, 163,
313: 151)), " " + bundle.getMessage("colProps")
314: + " "); //NOI18N
315: lblAvailable.setText(bundle.getMessage("avail")); //NOI18N
316: this .setLayout(gridBagLayout1);
317: lblDisplayed.setToolTipText(""); //NOI18N
318: lblDisplayed.setText(bundle.getMessage("displ")); //NOI18N
319: btnAdd.setMargin(new Insets(2, 6, 2, 6));
320: btnAdd.setText(">"); //NOI18N
321: btnAdd.addActionListener(actionListener);
322: btnRemoveOne.setText("<"); //NOI18N
323: btnRemoveOne.addActionListener(actionListener);
324: btnRemoveOne.setMargin(new Insets(2, 6, 2, 6));
325: btnUp.setText(bundle.getMessage("up")); //NOI18N
326: btnUp.addActionListener(actionListener);
327: btnUp.setMargin(new Insets(2, 10, 2, 10));
328: btnDown.setMargin(new Insets(2, 10, 2, 10));
329: btnDown.setText(bundle.getMessage("down")); //NOI18N
330: btnDown.addActionListener(actionListener);
331: btnNew.setMargin(new Insets(2, 10, 2, 10));
332: btnNew.setText(bundle.getMessage("new")); //NOI18N
333: btnNew.addActionListener(actionListener);
334: btnRemoveAll.setMargin(new Insets(2, 6, 2, 6));
335: btnRemoveAll.setText("<<"); //NOI18N
336: btnRemoveAll.addActionListener(actionListener);
337: panColProps.setBorder(titledBorder1);
338: panColProps.setDebugGraphicsOptions(0);
339: // panColProps.setMaximumSize(new Dimension(32767, 32767));
340: panColProps.setLayout(gridBagLayout2);
341: lblHeaderText.setText(bundle.getMessage("hdrTxt") + " "); //NOI18N
342: lblFooterText.setText(bundle.getMessage("ftrTxt") + " "); //NOI18N
343: lblCompType.setText(bundle.getMessage("compType") + " "); //NOI18N
344: lblValue.setText(bundle.getMessage("val") + " "); //NOI18N
345: tfHeaderText.setText(""); //NOI18N
346: tfHeaderText.getDocument()
347: .addDocumentListener(documentListener);
348: tfFooterText.setText(""); //NOI18N
349: tfFooterText.getDocument()
350: .addDocumentListener(documentListener);
351: tfValue.setText(""); //NOI18N
352: tfValue.getDocument().addDocumentListener(documentListener);
353: listAvailable
354: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
355: listDisplayed
356: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
357: scrollAvailable.setPreferredSize(new Dimension(200, 200));
358: scrollDisplayed.setPreferredSize(new Dimension(200, 200));
359: listAvailable.getSelectionModel().addListSelectionListener(
360: listSelectionListener);
361: listDisplayed.getSelectionModel().addListSelectionListener(
362: listSelectionListener);
363: scrollDisplayed.getViewport().add(listDisplayed, null);
364: listDisplayed.setModel(modelDisplayed);
365: comboCompType.setModel(modelCompType);
366: comboCompType.addActionListener(actionListener);
367: scrollAvailable.getViewport().add(listAvailable, null);
368: listAvailable.setModel(modelAvailable);
369: listAvailable.addMouseListener(mouseListener);
370: listDisplayed.addMouseListener(listDisplayedMouseListener);
371:
372: this .add(sourceLabel, new GridBagConstraints(0, 0, 3, 1, 0.0,
373: 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
374: new Insets(8, 8, 4, 8), 0, 0));
375: this .add(sourceCombo, new GridBagConstraints(0, 1, 3, 1, 1.0,
376: 0.0, GridBagConstraints.WEST,
377: GridBagConstraints.HORIZONTAL, new Insets(0, 8, 8, 0),
378: 0, 0));
379: this .add(lblAvailable, new GridBagConstraints(0, 2, 1, 1, 0.0,
380: 0.0, GridBagConstraints.WEST,
381: GridBagConstraints.HORIZONTAL, new Insets(8, 8, 4, 8),
382: 0, 0));
383: this .add(scrollAvailable, new GridBagConstraints(0, 3, 1, 3,
384: 1.0, 0.5, GridBagConstraints.CENTER,
385: GridBagConstraints.BOTH, new Insets(0, 8, 8, 4), 0, 0));
386: this .add(btnAdd, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
387: GridBagConstraints.CENTER,
388: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 4, 0),
389: 0, 0));
390: this .add(lblDisplayed, new GridBagConstraints(2, 2, 1, 1, 0.0,
391: 0.0, GridBagConstraints.WEST,
392: GridBagConstraints.HORIZONTAL, new Insets(8, 4, 4, 8),
393: 0, 0));
394: this .add(scrollDisplayed, new GridBagConstraints(2, 3, 1, 3,
395: 1.0, 0.5, GridBagConstraints.CENTER,
396: GridBagConstraints.BOTH, new Insets(0, 4, 8, 0), 0, 0));
397: this .add(btnRemoveOne, new GridBagConstraints(1, 4, 1, 1, 0.0,
398: 0.0, GridBagConstraints.CENTER,
399: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 0),
400: 0, 0));
401: this .add(btnUp, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0,
402: GridBagConstraints.NORTH,
403: GridBagConstraints.HORIZONTAL, new Insets(0, 4, 4, 8),
404: 0, 0));
405: this .add(btnDown, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0,
406: GridBagConstraints.CENTER,
407: GridBagConstraints.HORIZONTAL, new Insets(0, 4, 8, 8),
408: 0, 0));
409: this .add(btnRemoveAll, new GridBagConstraints(1, 5, 1, 1, 0.0,
410: 0.0, GridBagConstraints.SOUTHWEST,
411: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 0),
412: 0, 0));
413: this .add(btnNew, new GridBagConstraints(3, 5, 1, 1, 0.0, 0.0,
414: GridBagConstraints.SOUTHWEST,
415: GridBagConstraints.HORIZONTAL, new Insets(0, 4, 8, 8),
416: 0, 0));
417: this .add(panColProps, new GridBagConstraints(0, 6, 4, 1, 1.0,
418: 1.0, GridBagConstraints.CENTER,
419: GridBagConstraints.BOTH, new Insets(0, 8, 8, 8), 0, 0));
420: panColProps.add(lblHeaderText, new GridBagConstraints(0, 0, 1,
421: 1, 0.0, 0.0, GridBagConstraints.WEST,
422: GridBagConstraints.NONE, new Insets(8, 8, 0, 8), 0, 0));
423: panColProps.add(lblFooterText, new GridBagConstraints(0, 1, 1,
424: 1, 0.0, 0.0, GridBagConstraints.WEST,
425: GridBagConstraints.NONE, new Insets(0, 8, 8, 4), 0, 0));
426: panColProps.add(lblCompType, new GridBagConstraints(0, 2, 1, 1,
427: 0.0, 0.0, GridBagConstraints.WEST,
428: GridBagConstraints.NONE, new Insets(0, 8, 8, 4), 0, 0));
429: panColProps.add(lblValue, new GridBagConstraints(0, 3, 1, 1,
430: 0.0, 0.0, GridBagConstraints.WEST,
431: GridBagConstraints.NONE, new Insets(0, 8, 8, 4), 0, 0));
432: panColProps.add(tfHeaderText, new GridBagConstraints(1, 0, 1,
433: 1, 1.0, 0.0, GridBagConstraints.WEST,
434: GridBagConstraints.HORIZONTAL, new Insets(8, 0, 8, 8),
435: 0, 0));
436: panColProps.add(comboCompType, new GridBagConstraints(1, 2, 1,
437: 1, 1.0, 0.0, GridBagConstraints.CENTER,
438: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 8),
439: 0, 0));
440: panColProps.add(tfFooterText, new GridBagConstraints(1, 1, 1,
441: 1, 1.0, 0.0, GridBagConstraints.WEST,
442: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 8),
443: 0, 0));
444: panColProps.add(tfValue, new GridBagConstraints(1, 3, 1, 1,
445: 1.0, 0.0, GridBagConstraints.WEST,
446: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 8),
447: 0, 0));
448: panColProps.add(jPanel2, new GridBagConstraints(0, 5, 2, 1,
449: 1.0, 1.0, GridBagConstraints.CENTER,
450: GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
451:
452: updateColumnProps();
453: updating = false;
454: }
455:
456: boolean initialized = false;
457:
458: void initState() {
459: updating = true;
460: DesignBean sourceBean = table.getSourceBean();
461: sourceCombo.setSelectedItem(sourceBean); //perfectly fine to have sourceBean null here
462: updating = false;
463: initialized = true;
464: }
465:
466: void saveState() {
467: }
468:
469: private void validateIfJsfELSyntax(Result result, JTextField tf,
470: int displayListColumnIndex, String dcText,
471: String messageDisplayName, String messageDescription) {
472: if (table.isJsfELSyntax(dcText)) {
473: if (!table.validateJsfEL(dcText)) {
474: if (result.getMessageCount() == 0) {
475: java.awt.Container container = this .getParent();
476: if (container instanceof JTabbedPane) {
477: ((JTabbedPane) container)
478: .setSelectedComponent(this );
479: }
480: listDisplayed
481: .setSelectedIndex(displayListColumnIndex);
482: tf.requestFocus();
483: tf.setSelectionStart(0);
484: tf.setSelectionEnd(dcText.length());
485: }
486: result.setSuccess(false);
487: result.addMessage(ResultMessage.create(
488: ResultMessage.TYPE_CRITICAL,
489: messageDisplayName, messageDescription));
490: }
491: }
492: }
493:
494: void validate(Result result) {
495: if (result == null) {
496: result = new Result(true);
497: }
498: HtmlDataTableState.DisplayColumn[] dca = table.display
499: .getColumns();
500: for (int i = 0; i < dca.length; i++) {
501: HtmlDataTableState.DisplayColumn dc = dca[i];
502: validateIfJsfELSyntax(result, tfHeaderText, i,
503: dc.headerText, bundle.getMessage("invalidEntry",
504: "header text"), bundle.getMessage(
505: "tfInvalidJsf", //NOI18N
506: dc.itemText, "header")); //NOI18N
507: validateIfJsfELSyntax(result, tfFooterText, i,
508: dc.footerText, bundle.getMessage("invalidEntry",
509: "footer text"), bundle.getMessage(
510: "tfInvalidJsf", //NOI18N
511: dc.itemText, "footer")); //NOI18N
512: validateIfJsfELSyntax(result, tfValue, i, dc.compValueRef,
513: bundle.getMessage("invalidEntry", "value"), bundle
514: .getMessage("tfInvalidJsf", //NOI18N
515: dc.itemText, "value")); //NOI18N
516: }
517: }
518:
519: private void sourceCombo_actionPerformed(ActionEvent e) {
520: if (updating) {
521: return;
522: }
523: updating = true;
524: DesignBean sourceBean = (DesignBean) sourceCombo
525: .getSelectedItem();
526: table.setSourceBean(sourceBean);
527: if (sourceBean == table.getSavedSourceBean()) {
528: table.loadColumnState();
529: } else {
530: table.refreshColumnInfo();
531: }
532: refreshResultSetColumns();
533: refreshDisplayColumns();
534: updateColumnProps();
535: updating = false;
536: }
537:
538: private void refreshResultSetColumns() {
539: modelAvailable.fire();
540: listAvailable.clearSelection();
541: enableOrDisableListAvailableButtons();
542: }
543:
544: private void refreshDisplayColumns() {
545: modelDisplayed.fire();
546: if (modelDisplayed.getSize() > 0) {
547: listDisplayed.setSelectedIndex(0);
548: } else {
549: listDisplayed.clearSelection();
550: }
551: enableOrDisableListDisplayedButtons();
552: }
553:
554: private void btnAdd_actionPerformed(ActionEvent e) {
555: if (updating) {
556: return;
557: }
558: updating = true;
559: int[] selectedIndices = listAvailable.getSelectedIndices();
560: if (selectedIndices.length == 0) {
561: updating = false;
562: return;
563: }
564: int modelDisplayedPreviousSize = modelDisplayed.getSize();
565: for (int i = 0; i < selectedIndices.length; i++) {
566: Object o = modelAvailable.getElementAt(selectedIndices[i]);
567: if (o instanceof HtmlDataTableState.ResultSetColumn) {
568: HtmlDataTableState.ResultSetColumn rsc = (HtmlDataTableState.ResultSetColumn) o;
569: table.display.addColumn(rsc);
570: }
571: }
572: modelDisplayed.fire();
573: if (modelDisplayedPreviousSize == 0
574: && modelDisplayed.getSize() > 0) {
575: listDisplayed.setSelectedIndex(0);
576: }
577: enableOrDisableListAvailableButtons();
578: enableOrDisableListDisplayedButtons();
579: updateColumnProps();
580: updating = false;
581: }
582:
583: private void btnNew_actionPerformed(ActionEvent e) {
584: if (updating) {
585: return;
586: }
587: updating = true;
588: HtmlDataTableState.DisplayColumn dc = table.display
589: .addNewColumn();
590: modelDisplayed.fire();
591: listDisplayed.setSelectedValue(dc, true);
592: enableOrDisableListDisplayedButtons();
593: updateColumnProps();
594: updating = false;
595: }
596:
597: private void btnRemoveOne_actionPerformed(ActionEvent e) {
598: if (updating) {
599: return;
600: }
601: updating = true;
602: Object o = listDisplayed.getSelectedValue();
603: if (!(o instanceof HtmlDataTableState.DisplayColumn)) {
604: updating = false;
605: return;
606: }
607: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
608: table.display.removeColumn(dc);
609: modelDisplayed.fire();
610: int mdsize = modelDisplayed.getSize();
611: if (mdsize == 0) {
612: listDisplayed.clearSelection();
613: } else if (listDisplayed.getSelectedIndex() >= mdsize) {
614: listDisplayed.setSelectedIndex(mdsize - 1);
615: }
616: enableOrDisableListDisplayedButtons();
617: updateColumnProps();
618: updating = false;
619: }
620:
621: private void btnRemoveAll_actionPerformed(ActionEvent e) {
622: if (updating) {
623: return;
624: }
625: updating = true;
626: table.display.clearColumns();
627: modelDisplayed.fire();
628: listDisplayed.clearSelection();
629: enableOrDisableListDisplayedButtons();
630: updateColumnProps();
631: updating = false;
632: }
633:
634: private void btnUp_actionPerformed(ActionEvent e) {
635: if (updating) {
636: return;
637: }
638: updating = true;
639: Object o = listDisplayed.getSelectedValue();
640: if (!(o instanceof HtmlDataTableState.DisplayColumn)) {
641: updating = false;
642: return;
643: }
644: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
645: table.display.moveColumnUp(dc);
646: modelDisplayed.fire();
647: listDisplayed.setSelectedValue(dc, true);
648: enableOrDisableListDisplayedButtons();
649: updateColumnProps();
650: updating = false;
651: }
652:
653: private void btnDown_actionPerformed(ActionEvent e) {
654: if (updating) {
655: return;
656: }
657: updating = true;
658: Object o = listDisplayed.getSelectedValue();
659: if (!(o instanceof HtmlDataTableState.DisplayColumn)) {
660: updating = false;
661: return;
662: }
663: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
664: table.display.moveColumnDown(dc);
665: modelDisplayed.fire();
666: listDisplayed.setSelectedValue(dc, true);
667: enableOrDisableListDisplayedButtons();
668: updateColumnProps();
669: updating = false;
670: }
671:
672: private void comboCompType_actionPerformed(ActionEvent e) {
673: if (updating) {
674: return;
675: }
676: updating = true;
677: updateColumnProps();
678: updating = false;
679: }
680:
681: private void listAvailable_valueChanged(ListSelectionEvent e) {
682: if (updating) {
683: return;
684: }
685: updating = true;
686: enableOrDisableListAvailableButtons();
687: updating = false;
688: }
689:
690: private void listDisplayed_valueChanged(ListSelectionEvent e) {
691: if (updating) {
692: return;
693: }
694: updating = true;
695: enableOrDisableListDisplayedButtons();
696: updateColumnProps();
697: updating = false;
698: }
699:
700: private void enableOrDisableListAvailableButtons() {
701: btnAdd.setEnabled(modelAvailable.getSize() > 0
702: && listAvailable.getSelectedIndices().length > 0);
703: }
704:
705: private void enableOrDisableListDisplayedButtons() {
706: Object o = listDisplayed.getSelectedValue();
707: if (o instanceof HtmlDataTableState.DisplayColumn) {
708: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
709: btnUp.setEnabled(table.display.canMoveUp(dc));
710: btnDown.setEnabled(table.display.canMoveDown(dc));
711: btnRemoveOne.setEnabled(true);
712: } else {
713: btnUp.setEnabled(false);
714: btnDown.setEnabled(false);
715: btnRemoveOne.setEnabled(false);
716: }
717: if (modelDisplayed.getSize() > 0) {
718: btnRemoveAll.setEnabled(true);
719: } else {
720: btnRemoveAll.setEnabled(false);
721: }
722: }
723:
724: private boolean updating = false;
725:
726: private void updateColumnProps() {
727: boolean valueNotApplicable = false;
728: Object o = listDisplayed.getSelectedValue();
729: HtmlDataTableState.DisplayColumn dc = null;
730: if (o instanceof HtmlDataTableState.DisplayColumn) {
731: dc = (HtmlDataTableState.DisplayColumn) o;
732: titledBorder1
733: .setTitle(" "
734: + bundle.getMessage("dcProps", dc
735: .toString()) + " "); //NOI18N
736: tfHeaderText.setText(dc.headerText);
737: tfFooterText.setText(dc.footerText);
738: modelCompType.setDisplayColumn(dc);
739:
740: if (HtmlMessage.class.getName().equals(dc.compClassName)
741: || HtmlPanelGroup.class.getName().equals(
742: dc.compClassName)
743: || HtmlPanelGrid.class.getName().equals(
744: dc.compClassName)) {
745: valueNotApplicable = true;
746: }
747:
748: tfValue.setText(valueNotApplicable ? "" : dc.compValueRef); //NOI18N
749: } else {
750: titledBorder1.setTitle(" " + bundle.getMessage("colProps")
751: + " "); //NOI18N
752: tfHeaderText.setText(""); //NOI18N
753: tfFooterText.setText(""); //NOI18N
754: modelCompType.setDisplayColumn(null);
755: tfValue.setText(""); //NOI18N
756: }
757: boolean enabled = true;
758: boolean valueEnabled = true;
759: //look for reasons to make enabled or valueEnabled false
760: if (dc == null) {
761: enabled = false;
762: valueEnabled = false;
763: } else if (dc.hasResultSetColumnPeer) {
764: valueEnabled = false;
765: } else if (valueNotApplicable) {
766: valueEnabled = false;
767: }
768: tfHeaderText.setEnabled(enabled);
769: tfFooterText.setEnabled(enabled);
770: comboCompType.setEnabled(enabled);
771: tfValue.setEnabled(valueEnabled);
772:
773: tfHeaderText.setBackground(enabled ? SystemColor.text
774: : SystemColor.control);
775: tfFooterText.setBackground(enabled ? SystemColor.text
776: : SystemColor.control);
777: tfValue.setBackground(valueEnabled ? SystemColor.text
778: : SystemColor.control);
779:
780: validate();
781: repaint(100);
782: }
783:
784: private void tfHeaderText_changed(DocumentEvent e) {
785: if (updating) {
786: return;
787: }
788: updating = true;
789: Object o = listDisplayed.getSelectedValue();
790: if (o instanceof HtmlDataTableState.DisplayColumn) {
791: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
792: Document d = e.getDocument();
793: try {
794: dc.headerText = d.getText(
795: d.getStartPosition().getOffset(),
796: d.getEndPosition().getOffset()).trim();
797: } catch (BadLocationException x) {
798: }
799: }
800: updating = false;
801: }
802:
803: private void tfFooterText_changed(DocumentEvent e) {
804: if (updating) {
805: return;
806: }
807: updating = true;
808: Object o = listDisplayed.getSelectedValue();
809: if (o instanceof HtmlDataTableState.DisplayColumn) {
810: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
811: Document d = e.getDocument();
812: try {
813: dc.footerText = d.getText(
814: d.getStartPosition().getOffset(),
815: d.getEndPosition().getOffset()).trim();
816: } catch (BadLocationException x) {
817: }
818: }
819: updating = false;
820: }
821:
822: private void tfValue_changed(DocumentEvent e) {
823: if (updating) {
824: return;
825: }
826: updating = true;
827: Object o = listDisplayed.getSelectedValue();
828: if (o instanceof HtmlDataTableState.DisplayColumn) {
829: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
830: Document d = e.getDocument();
831: try {
832: dc.compValueRef = d.getText(
833: d.getStartPosition().getOffset(),
834: d.getEndPosition().getOffset()).trim();
835: } catch (BadLocationException x) {
836: }
837: }
838: updating = false;
839: }
840:
841: private class ResultSetColumnListModel extends AbstractListModel {
842: public int getSize() {
843: return table.rsinfo == null ? 0 : table.rsinfo
844: .getColumnCount();
845: }
846:
847: public Object getElementAt(int index) {
848: if (table.rsinfo != null && index >= 0
849: && index <= table.rsinfo.getColumnCount() - 1) {
850: return table.rsinfo.getColumn(index);
851: } else {
852: return null;
853: }
854: }
855:
856: public void fire() {
857: fireContentsChanged(this , -1, -1);
858: }
859: }
860:
861: private class DisplayColumnListModel extends AbstractListModel {
862: public int getSize() {
863: return table.display.getColumnCount();
864: }
865:
866: public Object getElementAt(int index) {
867: if (index >= 0 && index <= getSize() - 1) {
868: return table.display.getColumn(index);
869: } else {
870: return null;
871: }
872: }
873:
874: public void fire() {
875: fireContentsChanged(this , -1, -1);
876: }
877: }
878:
879: private class CompTypeComboModel extends AbstractListModel
880: implements ComboBoxModel {
881: private CompType[] types = new CompType[] {
882: new CompType(bundle.getMessage("outputTextParenRO"),
883: HtmlOutputText.class.getName(), "outputText"), //NOI18N
884: new CompType(bundle.getMessage("inputTextParenE"),
885: HtmlInputText.class.getName(), "textField"), //NOI18N
886: new CompType(bundle.getMessage("secretTextParenE"),
887: HtmlInputSecret.class.getName(), "secretField"), //NOI18N
888: new CompType(bundle.getMessage("textAreaParenMulti"),
889: HtmlInputTextarea.class.getName(), "textArea"), //NOI18N
890: new CompType(bundle.getMessage("btnParenA"),
891: HtmlCommandButton.class.getName(), "button"), //NOI18N
892: new CompType(bundle.getMessage("linkParenA"),
893: HtmlCommandLink.class.getName(), "linkAction"), //NOI18N
894: new CompType(bundle.getMessage("chkParenTF"),
895: HtmlSelectBooleanCheckbox.class.getName(),
896: "checkbox"), //NOI18N
897: new CompType(bundle.getMessage("dropdnParenLOI"),
898: HtmlSelectOneMenu.class.getName(), "dropdown"), //NOI18N
899: new CompType(bundle.getMessage("radioButtonList"),
900: HtmlSelectOneRadio.class.getName(),
901: "radioButtonList"), //NOI18N
902: new CompType(bundle.getMessage("image"),
903: HtmlGraphicImage.class.getName(), "image"), //NOI18N
904: new CompType(bundle.getMessage("inlineMsg"),
905: HtmlMessage.class.getName(), "inlineMessage"), //NOI18N
906: new CompType(bundle.getMessage("gridPanel"),
907: HtmlPanelGrid.class.getName(), "gridPanel"), //NOI18N
908: new CompType(bundle.getMessage("groupPanel"),
909: HtmlPanelGroup.class.getName(), "groupPanel") //NOI18N
910: };
911:
912: private HashMap compTypeHash = new HashMap();
913:
914: private CompTypeComboModel() {
915: for (int i = 0; i < types.length; i++) {
916: compTypeHash.put(types[i].compClassName, types[i]);
917: }
918: }
919:
920: private HtmlDataTableState.DisplayColumn dc = null;
921:
922: private void setDisplayColumn(
923: HtmlDataTableState.DisplayColumn dc) {
924: this .dc = dc;
925: fire();
926: }
927:
928: public void setSelectedItem(Object anItem) {
929: if (anItem instanceof CompType && dc != null) {
930: CompType ct = (CompType) anItem;
931: dc.compClassName = ct.compClassName;
932: //dc.compInstanceName = ct.compInstanceName;
933: }
934: }
935:
936: public Object getSelectedItem() {
937: if (dc != null) {
938: return compTypeHash.get(dc.compClassName);
939: }
940: return null;
941: }
942:
943: public int getSize() {
944: return types.length;
945: }
946:
947: public Object getElementAt(int index) {
948: return types[index];
949: }
950:
951: public void fire() {
952: fireContentsChanged(this , -1, -1);
953: }
954: }
955:
956: private class CompType {
957: public String display;
958: public String compClassName;
959: public String compInstanceName;
960:
961: public CompType(String display, String compClassName,
962: String compInstanceName) {
963: this .display = display;
964: this .compClassName = compClassName;
965: this .compInstanceName = compInstanceName;
966: }
967:
968: public String toString() {
969: return display;
970: }
971: }
972:
973: private class SourceComboRenderer extends DefaultListCellRenderer {
974: public Component getListCellRendererComponent(JList list,
975: Object value, int index, boolean isSelected,
976: boolean cellHasFocus) {
977: super .getListCellRendererComponent(list, value, index,
978: isSelected, cellHasFocus);
979: if (value == null) {
980: this .setText(bundle.getMessage("bracketsNone")); //NOI18N
981: } else {
982: DesignBean bean = (DesignBean) value;
983: this .setText(bundle.getMessage("sourceComboRend", bean
984: .getInstanceName(), //NOI18N
985: bean.getDesignContext().getDisplayName())); //NOI18N
986: }
987: return this;
988: }
989: }
990: }
|