0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041: package org.netbeans.modules.visualweb.faces.dt.std.table;
0042:
0043: import java.awt.Color;
0044: import java.awt.Component;
0045: import java.awt.Dimension;
0046: import java.awt.GridBagConstraints;
0047: import java.awt.GridBagLayout;
0048: import java.awt.Insets;
0049: import java.awt.SystemColor;
0050: import java.awt.event.ActionEvent;
0051: import java.awt.event.ActionListener;
0052: import java.awt.event.MouseAdapter;
0053: import java.awt.event.MouseEvent;
0054: import java.awt.event.MouseListener;
0055: import java.sql.ResultSet;
0056: import java.util.ArrayList;
0057: import java.util.HashMap;
0058: import java.util.Iterator;
0059: import javax.faces.component.html.HtmlCommandButton;
0060: import javax.faces.component.html.HtmlCommandLink;
0061: import javax.faces.component.html.HtmlGraphicImage;
0062: import javax.faces.component.html.HtmlInputSecret;
0063: import javax.faces.component.html.HtmlInputText;
0064: import javax.faces.component.html.HtmlInputTextarea;
0065: import javax.faces.component.html.HtmlMessage;
0066: import javax.faces.component.html.HtmlOutputText;
0067: import javax.faces.component.html.HtmlPanelGrid;
0068: import javax.faces.component.html.HtmlPanelGroup;
0069: import javax.faces.component.html.HtmlSelectBooleanCheckbox;
0070: import javax.faces.component.html.HtmlSelectOneMenu;
0071: import javax.faces.component.html.HtmlSelectOneRadio;
0072: import javax.swing.AbstractListModel;
0073: import javax.swing.BorderFactory;
0074: import javax.swing.ComboBoxModel;
0075: import javax.swing.DefaultComboBoxModel;
0076: import javax.swing.DefaultListCellRenderer;
0077: import javax.swing.JButton;
0078: import javax.swing.JComboBox;
0079: import javax.swing.JLabel;
0080: import javax.swing.JList;
0081: import javax.swing.JPanel;
0082: import javax.swing.JScrollPane;
0083: import javax.swing.JTabbedPane;
0084: import javax.swing.JTextField;
0085: import javax.swing.ListSelectionModel;
0086: import javax.swing.border.TitledBorder;
0087: import javax.swing.event.DocumentEvent;
0088: import javax.swing.event.DocumentListener;
0089: import javax.swing.event.ListSelectionEvent;
0090: import javax.swing.event.ListSelectionListener;
0091: import javax.swing.text.BadLocationException;
0092: import javax.swing.text.Document;
0093:
0094: import org.netbeans.modules.visualweb.faces.dt.util.ComponentBundle;
0095: import com.sun.rave.designtime.Constants;
0096: import com.sun.rave.designtime.DesignBean;
0097: import com.sun.rave.designtime.DesignContext;
0098: import com.sun.rave.designtime.DesignProject;
0099: import com.sun.rave.designtime.Result;
0100: import com.sun.rave.designtime.ResultMessage;
0101: import com.sun.rave.designtime.faces.FacesDesignProject;
0102:
0103: public class HtmlDataTableCustomizerColumnsPanel extends JPanel {
0104:
0105: private static final ComponentBundle bundle = ComponentBundle
0106: .getBundle(HtmlDataTableCustomizerColumnsPanel.class);
0107:
0108: private JLabel lblAvailable = new JLabel();
0109: private JLabel lblDisplayed = new JLabel();
0110: private JScrollPane scrollAvailable = new JScrollPane();
0111: private JScrollPane scrollDisplayed = new JScrollPane();
0112: private JList listAvailable = new JList();
0113: private JList listDisplayed = new JList();
0114: private ResultSetColumnListModel modelAvailable = new ResultSetColumnListModel();
0115: private DisplayColumnListModel modelDisplayed = new DisplayColumnListModel();
0116: private CompTypeComboModel modelCompType = new CompTypeComboModel();
0117: private JButton btnAdd = new JButton();
0118: private JButton btnRemoveOne = new JButton();
0119: private JButton btnUp = new JButton();
0120: private JButton btnDown = new JButton();
0121: private JButton btnNew = new JButton();
0122: private JButton btnRemoveAll = new JButton();
0123: private JPanel panColProps = new JPanel();
0124: private TitledBorder titledBorder1;
0125: private GridBagLayout gridBagLayout1 = new GridBagLayout();
0126: private JLabel lblHeaderText = new JLabel();
0127: private JLabel lblFooterText = new JLabel();
0128: private JLabel lblCompType = new JLabel();
0129: private JLabel lblValue = new JLabel();
0130: private JTextField tfHeaderText = new JTextField();
0131: private JComboBox comboCompType = new JComboBox();
0132: private GridBagLayout gridBagLayout2 = new GridBagLayout();
0133: private JPanel jPanel2 = new JPanel();
0134: private JTextField tfFooterText = new JTextField();
0135: private JTextField tfValue = new JTextField();
0136: private HtmlDataTableState table;
0137: private DesignContext context;
0138: private JComboBox sourceCombo = new JComboBox();
0139: private DefaultComboBoxModel sourceComboModel = new DefaultComboBoxModel();
0140: private JLabel sourceLabel = new JLabel();
0141:
0142: HtmlDataTableCustomizerColumnsPanel() {
0143: try {
0144: jbInit();
0145: } catch (Exception ex) {
0146: ex.printStackTrace();
0147: }
0148: }
0149:
0150: void setTable(HtmlDataTableState table) {
0151: this .table = table;
0152: }
0153:
0154: void setContext(DesignContext context) {
0155: updating = true;
0156: this .context = context;
0157: populateSourceComboModel();
0158: sourceCombo.setModel(sourceComboModel);
0159: updating = false;
0160: initState();
0161: }
0162:
0163: // For performance improvement. No need to get all the contexts in the project
0164: private DesignContext[] getDesignContexts(DesignContext context) {
0165: DesignProject designProject = context.getProject();
0166: DesignContext[] contexts;
0167: if (designProject instanceof FacesDesignProject) {
0168: contexts = ((FacesDesignProject) designProject)
0169: .findDesignContexts(new String[] { "request",
0170: "session", "application" });
0171: } else {
0172: contexts = new DesignContext[0];
0173: }
0174: DesignContext[] designContexts = new DesignContext[contexts.length + 1];
0175: designContexts[0] = context;
0176: System.arraycopy(contexts, 0, designContexts, 1,
0177: contexts.length);
0178: return designContexts;
0179: }
0180:
0181: private void populateSourceComboModel() {
0182: sourceComboModel.removeAllElements();
0183: sourceComboModel.addElement(null);
0184:
0185: java.util.List sortedContexts = new ArrayList();
0186: sortedContexts.add(this .context);
0187: java.util.List sessionContexts = new ArrayList();
0188: java.util.List applicationContexts = new ArrayList();
0189: //DesignContext[] contexts = context.getProject().getDesignContexts();
0190: DesignContext[] contexts = getDesignContexts(context);
0191: for (int i = 0; i < contexts.length; i++) {
0192: if (contexts[i] == this .context) {
0193: continue;
0194: }
0195: Object scope = contexts[i]
0196: .getContextData(Constants.ContextData.SCOPE);
0197: if ("session".equals(scope)) { //NOI18N
0198: sessionContexts.add(contexts[i]);
0199: } else if ("application".equals(scope)) { //NOI18N
0200: applicationContexts.add(contexts[i]);
0201: }
0202: }
0203: sortedContexts.addAll(sessionContexts);
0204: sortedContexts.addAll(applicationContexts);
0205:
0206: for (Iterator iter = sortedContexts.iterator(); iter.hasNext();) {
0207: DesignContext aContext = (DesignContext) iter.next();
0208: DesignBean root = aContext.getRootContainer();
0209: fillCombo(root.getChildBeans());
0210: }
0211: }
0212:
0213: private void fillCombo(DesignBean[] beans) {
0214: for (int i = 0; i < beans.length; i++) {
0215: Object inst = beans[i].getInstance();
0216: if (inst instanceof javax.faces.model.DataModel
0217: || inst instanceof java.util.List
0218: || inst instanceof Object[]
0219: || inst instanceof ResultSet) {
0220: if (!(inst instanceof com.sun.jsfcl.data.RowSetDataModel)
0221: && //do not put in RowSetDataModels
0222: !(inst instanceof com.sun.rave.faces.data.CachedRowSetDataModel)) { //do not put in CachedRowSetDataModels
0223: sourceComboModel.addElement(beans[i]);
0224: }
0225: }
0226: }
0227: }
0228:
0229: private void columnsPanel_actionPerformed(ActionEvent e) {
0230: Object s = e.getSource();
0231: if (s == sourceCombo) {
0232: sourceCombo_actionPerformed(e);
0233: } else if (s == btnAdd) {
0234: btnAdd_actionPerformed(e);
0235: } else if (s == btnRemoveOne) {
0236: btnRemoveOne_actionPerformed(e);
0237: } else if (s == btnUp) {
0238: btnUp_actionPerformed(e);
0239: } else if (s == btnDown) {
0240: btnDown_actionPerformed(e);
0241: } else if (s == btnNew) {
0242: btnNew_actionPerformed(e);
0243: } else if (s == btnRemoveAll) {
0244: btnRemoveAll_actionPerformed(e);
0245: } else if (s == comboCompType) {
0246: comboCompType_actionPerformed(e);
0247: }
0248: }
0249:
0250: private void tf_changed(DocumentEvent e) {
0251: Object s = e.getDocument();
0252: if (s == tfHeaderText.getDocument()) {
0253: tfHeaderText_changed(e);
0254: } else if (s == tfFooterText.getDocument()) {
0255: tfFooterText_changed(e);
0256: } else if (s == tfValue.getDocument()) {
0257: tfValue_changed(e);
0258: }
0259: }
0260:
0261: private void list_valueChanged(ListSelectionEvent e) {
0262: Object s = e.getSource();
0263: if (s == listAvailable.getSelectionModel()) {
0264: listAvailable_valueChanged(e);
0265: } else if (s == listDisplayed.getSelectionModel()) {
0266: listDisplayed_valueChanged(e);
0267: }
0268: }
0269:
0270: private void columnsPanel_mouseClicked(MouseEvent e) {
0271: Object s = e.getSource();
0272: if (s == listAvailable) {
0273: if (e.getClickCount() == 2) {
0274: btnAdd_actionPerformed(null);
0275: }
0276: }
0277: }
0278:
0279: private void listDisplayed_mouseClicked(MouseEvent e) {
0280: Object s = e.getSource();
0281: if (s == listDisplayed) {
0282: if (e.getClickCount() == 2) {
0283: btnRemoveOne_actionPerformed(null);
0284: }
0285: }
0286: }
0287:
0288: private void jbInit() throws Exception {
0289: updating = true;
0290:
0291: ActionListener actionListener = new ActionListener() {
0292: public void actionPerformed(ActionEvent e) {
0293: columnsPanel_actionPerformed(e);
0294: }
0295: };
0296: DocumentListener documentListener = new DocumentListener() {
0297: public void insertUpdate(DocumentEvent e) {
0298: tf_changed(e);
0299: }
0300:
0301: public void removeUpdate(DocumentEvent e) {
0302: tf_changed(e);
0303: }
0304:
0305: public void changedUpdate(DocumentEvent e) {
0306: tf_changed(e);
0307: }
0308: };
0309: ListSelectionListener listSelectionListener = new ListSelectionListener() {
0310: public void valueChanged(ListSelectionEvent e) {
0311: list_valueChanged(e);
0312: }
0313: };
0314:
0315: MouseListener mouseListener = new MouseAdapter() {
0316: public void mouseClicked(MouseEvent e) {
0317: columnsPanel_mouseClicked(e);
0318: }
0319: };
0320:
0321: MouseListener listDisplayedMouseListener = new MouseAdapter() {
0322: public void mouseClicked(MouseEvent e) {
0323: listDisplayed_mouseClicked(e);
0324: }
0325: };
0326:
0327: sourceLabel.setText(bundle.getMessage("tableCustDataSource")); //NOI18N
0328: sourceCombo.setRenderer(new SourceComboRenderer());
0329: sourceCombo.setEditable(false);
0330: sourceCombo.addActionListener(actionListener);
0331: titledBorder1 = new TitledBorder(BorderFactory
0332: .createEtchedBorder(Color.white, new Color(165, 163,
0333: 151)), " " + bundle.getMessage("colProps")
0334: + " "); //NOI18N
0335: lblAvailable.setText(bundle.getMessage("avail")); //NOI18N
0336: this .setLayout(gridBagLayout1);
0337: lblDisplayed.setToolTipText(""); //NOI18N
0338: lblDisplayed.setText(bundle.getMessage("displ")); //NOI18N
0339: btnAdd.setMargin(new Insets(2, 6, 2, 6));
0340: btnAdd.setText(">"); //NOI18N
0341: btnAdd.addActionListener(actionListener);
0342: btnRemoveOne.setText("<"); //NOI18N
0343: btnRemoveOne.addActionListener(actionListener);
0344: btnRemoveOne.setMargin(new Insets(2, 6, 2, 6));
0345: btnUp.setText(bundle.getMessage("up")); //NOI18N
0346: btnUp.addActionListener(actionListener);
0347: btnUp.setMargin(new Insets(2, 10, 2, 10));
0348: btnDown.setMargin(new Insets(2, 10, 2, 10));
0349: btnDown.setText(bundle.getMessage("down")); //NOI18N
0350: btnDown.addActionListener(actionListener);
0351: btnNew.setMargin(new Insets(2, 10, 2, 10));
0352: btnNew.setText(bundle.getMessage("new")); //NOI18N
0353: btnNew.addActionListener(actionListener);
0354: btnRemoveAll.setMargin(new Insets(2, 6, 2, 6));
0355: btnRemoveAll.setText("<<"); //NOI18N
0356: btnRemoveAll.addActionListener(actionListener);
0357: panColProps.setBorder(titledBorder1);
0358: panColProps.setDebugGraphicsOptions(0);
0359: //panColProps.setMaximumSize(new Dimension(32767, 32767));
0360: panColProps.setLayout(gridBagLayout2);
0361: lblHeaderText.setText(bundle.getMessage("hdrTxt") + " "); //NOI18N
0362: lblFooterText.setText(bundle.getMessage("ftrTxt") + " "); //NOI18N
0363: lblCompType.setText(bundle.getMessage("compType") + " "); //NOI18N
0364: lblValue.setText(bundle.getMessage("val") + " "); //NOI18N
0365: tfHeaderText.setText(""); //NOI18N
0366: tfHeaderText.getDocument()
0367: .addDocumentListener(documentListener);
0368: tfFooterText.setText(""); //NOI18N
0369: tfFooterText.getDocument()
0370: .addDocumentListener(documentListener);
0371: tfValue.setText(""); //NOI18N
0372: tfValue.getDocument().addDocumentListener(documentListener);
0373: listAvailable
0374: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
0375: listDisplayed
0376: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
0377: scrollAvailable.setPreferredSize(new Dimension(200, 200));
0378: scrollDisplayed.setPreferredSize(new Dimension(200, 200));
0379: listAvailable.getSelectionModel().addListSelectionListener(
0380: listSelectionListener);
0381: listDisplayed.getSelectionModel().addListSelectionListener(
0382: listSelectionListener);
0383: scrollDisplayed.getViewport().add(listDisplayed, null);
0384: listDisplayed.setModel(modelDisplayed);
0385: comboCompType.setModel(modelCompType);
0386: comboCompType.addActionListener(actionListener);
0387: scrollAvailable.getViewport().add(listAvailable, null);
0388: listAvailable.setModel(modelAvailable);
0389: listAvailable.addMouseListener(mouseListener);
0390: listDisplayed.addMouseListener(listDisplayedMouseListener);
0391:
0392: this .add(sourceLabel, new GridBagConstraints(0, 0, 3, 1, 0.0,
0393: 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
0394: new Insets(8, 8, 4, 8), 0, 0));
0395: this .add(sourceCombo, new GridBagConstraints(0, 1, 3, 1, 1.0,
0396: 0.0, GridBagConstraints.WEST,
0397: GridBagConstraints.HORIZONTAL, new Insets(0, 8, 8, 0),
0398: 0, 0));
0399: this .add(lblAvailable, new GridBagConstraints(0, 2, 1, 1, 0.0,
0400: 0.0, GridBagConstraints.WEST,
0401: GridBagConstraints.HORIZONTAL, new Insets(8, 8, 4, 8),
0402: 0, 0));
0403: this .add(scrollAvailable, new GridBagConstraints(0, 3, 1, 3,
0404: 1.0, 0.5, GridBagConstraints.CENTER,
0405: GridBagConstraints.BOTH, new Insets(0, 8, 8, 4), 0, 0));
0406: this .add(btnAdd, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
0407: GridBagConstraints.CENTER,
0408: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 4, 0),
0409: 0, 0));
0410: this .add(lblDisplayed, new GridBagConstraints(2, 2, 1, 1, 0.0,
0411: 0.0, GridBagConstraints.WEST,
0412: GridBagConstraints.HORIZONTAL, new Insets(8, 4, 4, 8),
0413: 0, 0));
0414: this .add(scrollDisplayed, new GridBagConstraints(2, 3, 1, 3,
0415: 1.0, 0.5, GridBagConstraints.CENTER,
0416: GridBagConstraints.BOTH, new Insets(0, 4, 8, 0), 0, 0));
0417: this .add(btnRemoveOne, new GridBagConstraints(1, 4, 1, 1, 0.0,
0418: 0.0, GridBagConstraints.CENTER,
0419: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 0),
0420: 0, 0));
0421: this .add(btnUp, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0,
0422: GridBagConstraints.NORTH,
0423: GridBagConstraints.HORIZONTAL, new Insets(0, 4, 4, 8),
0424: 0, 0));
0425: this .add(btnDown, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0,
0426: GridBagConstraints.CENTER,
0427: GridBagConstraints.HORIZONTAL, new Insets(0, 4, 8, 8),
0428: 0, 0));
0429: this .add(btnRemoveAll, new GridBagConstraints(1, 5, 1, 1, 0.0,
0430: 0.0, GridBagConstraints.SOUTHWEST,
0431: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 0),
0432: 0, 0));
0433: this .add(btnNew, new GridBagConstraints(3, 5, 1, 1, 0.0, 0.0,
0434: GridBagConstraints.SOUTHWEST,
0435: GridBagConstraints.HORIZONTAL, new Insets(0, 4, 8, 8),
0436: 0, 0));
0437: this .add(panColProps, new GridBagConstraints(0, 6, 4, 1, 1.0,
0438: 1.0, GridBagConstraints.CENTER,
0439: GridBagConstraints.BOTH, new Insets(0, 8, 8, 8), 0, 0));
0440: panColProps.add(lblHeaderText, new GridBagConstraints(0, 0, 1,
0441: 1, 0.0, 0.0, GridBagConstraints.WEST,
0442: GridBagConstraints.NONE, new Insets(8, 8, 0, 8), 0, 0));
0443: panColProps.add(lblFooterText, new GridBagConstraints(0, 1, 1,
0444: 1, 0.0, 0.0, GridBagConstraints.WEST,
0445: GridBagConstraints.NONE, new Insets(0, 8, 8, 4), 0, 0));
0446: panColProps.add(lblCompType, new GridBagConstraints(0, 2, 1, 1,
0447: 0.0, 0.0, GridBagConstraints.WEST,
0448: GridBagConstraints.NONE, new Insets(0, 8, 8, 4), 0, 0));
0449: panColProps.add(lblValue, new GridBagConstraints(0, 3, 1, 1,
0450: 0.0, 0.0, GridBagConstraints.WEST,
0451: GridBagConstraints.NONE, new Insets(0, 8, 8, 4), 0, 0));
0452: panColProps.add(tfHeaderText, new GridBagConstraints(1, 0, 1,
0453: 1, 1.0, 0.0, GridBagConstraints.WEST,
0454: GridBagConstraints.HORIZONTAL, new Insets(8, 0, 8, 8),
0455: 0, 0));
0456: panColProps.add(comboCompType, new GridBagConstraints(1, 2, 1,
0457: 1, 1.0, 0.0, GridBagConstraints.CENTER,
0458: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 8),
0459: 0, 0));
0460: panColProps.add(tfFooterText, new GridBagConstraints(1, 1, 1,
0461: 1, 1.0, 0.0, GridBagConstraints.WEST,
0462: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 8),
0463: 0, 0));
0464: panColProps.add(tfValue, new GridBagConstraints(1, 3, 1, 1,
0465: 1.0, 0.0, GridBagConstraints.WEST,
0466: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 8),
0467: 0, 0));
0468: panColProps.add(jPanel2, new GridBagConstraints(0, 5, 2, 1,
0469: 1.0, 1.0, GridBagConstraints.CENTER,
0470: GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
0471:
0472: updateColumnProps();
0473: updating = false;
0474: }
0475:
0476: boolean initialized = false;
0477:
0478: void initState() {
0479: updating = true;
0480: DesignBean sourceBean = table.getSourceBean();
0481: sourceCombo.setSelectedItem(sourceBean); //perfectly fine to have sourceBean null here
0482: updating = false;
0483: initialized = true;
0484: }
0485:
0486: void saveState() {
0487: }
0488:
0489: private void validateIfJsfELSyntax(Result result, JTextField tf,
0490: int displayListColumnIndex, String dcText,
0491: String messageDisplayName, String messageDescription) {
0492: if (table.isJsfELSyntax(dcText)) {
0493: if (!table.validateJsfEL(dcText)) {
0494: if (result.getMessageCount() == 0) {
0495: java.awt.Container container = this .getParent();
0496: if (container instanceof JTabbedPane) {
0497: ((JTabbedPane) container)
0498: .setSelectedComponent(this );
0499: }
0500: listDisplayed
0501: .setSelectedIndex(displayListColumnIndex);
0502: tf.requestFocus();
0503: tf.setSelectionStart(0);
0504: tf.setSelectionEnd(dcText.length());
0505: }
0506: result.setSuccess(false);
0507: result.addMessage(ResultMessage.create(
0508: ResultMessage.TYPE_CRITICAL,
0509: messageDisplayName, messageDescription));
0510: }
0511: }
0512: }
0513:
0514: void validate(Result result) {
0515: if (result == null) {
0516: result = new Result(true);
0517: }
0518: HtmlDataTableState.DisplayColumn[] dca = table.display
0519: .getColumns();
0520: for (int i = 0; i < dca.length; i++) {
0521: HtmlDataTableState.DisplayColumn dc = dca[i];
0522: validateIfJsfELSyntax(result, tfHeaderText, i,
0523: dc.headerText, bundle.getMessage("invalidEntry",
0524: "header text"), bundle.getMessage(
0525: "tfInvalidJsf", //NOI18N
0526: dc.itemText, "header")); //NOI18N
0527: validateIfJsfELSyntax(result, tfFooterText, i,
0528: dc.footerText, bundle.getMessage("invalidEntry",
0529: "footer text"), bundle.getMessage(
0530: "tfInvalidJsf", //NOI18N
0531: dc.itemText, "footer")); //NOI18N
0532: validateIfJsfELSyntax(result, tfValue, i, dc.compValueRef,
0533: bundle.getMessage("invalidEntry", "value"), bundle
0534: .getMessage("tfInvalidJsf", //NOI18N
0535: dc.itemText, "value")); //NOI18N
0536: }
0537: }
0538:
0539: private void sourceCombo_actionPerformed(ActionEvent e) {
0540: if (updating) {
0541: return;
0542: }
0543: updating = true;
0544: DesignBean sourceBean = (DesignBean) sourceCombo
0545: .getSelectedItem();
0546: table.setSourceBean(sourceBean);
0547: if (sourceBean == table.getSavedSourceBean()) {
0548: table.loadColumnState();
0549: } else {
0550: table.refreshColumnInfo();
0551: }
0552: refreshResultSetColumns();
0553: refreshDisplayColumns();
0554: updateColumnProps();
0555: updating = false;
0556: }
0557:
0558: private void refreshResultSetColumns() {
0559: modelAvailable.fire();
0560: listAvailable.clearSelection();
0561: enableOrDisableListAvailableButtons();
0562: }
0563:
0564: private void refreshDisplayColumns() {
0565: modelDisplayed.fire();
0566: if (modelDisplayed.getSize() > 0) {
0567: listDisplayed.setSelectedIndex(0);
0568: } else {
0569: listDisplayed.clearSelection();
0570: }
0571: enableOrDisableListDisplayedButtons();
0572: }
0573:
0574: private void btnAdd_actionPerformed(ActionEvent e) {
0575: if (updating) {
0576: return;
0577: }
0578: updating = true;
0579: int[] selectedIndices = listAvailable.getSelectedIndices();
0580: if (selectedIndices.length == 0) {
0581: updating = false;
0582: return;
0583: }
0584: int modelDisplayedPreviousSize = modelDisplayed.getSize();
0585: for (int i = 0; i < selectedIndices.length; i++) {
0586: Object o = modelAvailable.getElementAt(selectedIndices[i]);
0587: if (o instanceof HtmlDataTableState.ResultSetColumn) {
0588: HtmlDataTableState.ResultSetColumn rsc = (HtmlDataTableState.ResultSetColumn) o;
0589: table.display.addColumn(rsc);
0590: }
0591: }
0592: modelDisplayed.fire();
0593: if (modelDisplayedPreviousSize == 0
0594: && modelDisplayed.getSize() > 0) {
0595: listDisplayed.setSelectedIndex(0);
0596: }
0597: enableOrDisableListAvailableButtons();
0598: enableOrDisableListDisplayedButtons();
0599: updateColumnProps();
0600: updating = false;
0601: }
0602:
0603: private void btnNew_actionPerformed(ActionEvent e) {
0604: if (updating) {
0605: return;
0606: }
0607: updating = true;
0608: HtmlDataTableState.DisplayColumn dc = table.display
0609: .addNewColumn();
0610: modelDisplayed.fire();
0611: listDisplayed.setSelectedValue(dc, true);
0612: enableOrDisableListDisplayedButtons();
0613: updateColumnProps();
0614: updating = false;
0615: }
0616:
0617: private void btnRemoveOne_actionPerformed(ActionEvent e) {
0618: if (updating) {
0619: return;
0620: }
0621: updating = true;
0622: Object o = listDisplayed.getSelectedValue();
0623: if (!(o instanceof HtmlDataTableState.DisplayColumn)) {
0624: updating = false;
0625: return;
0626: }
0627: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
0628: table.display.removeColumn(dc);
0629: modelDisplayed.fire();
0630: int mdsize = modelDisplayed.getSize();
0631: if (mdsize == 0) {
0632: listDisplayed.clearSelection();
0633: } else if (listDisplayed.getSelectedIndex() >= mdsize) {
0634: listDisplayed.setSelectedIndex(mdsize - 1);
0635: }
0636: enableOrDisableListDisplayedButtons();
0637: updateColumnProps();
0638: updating = false;
0639: }
0640:
0641: private void btnRemoveAll_actionPerformed(ActionEvent e) {
0642: if (updating) {
0643: return;
0644: }
0645: updating = true;
0646: table.display.clearColumns();
0647: modelDisplayed.fire();
0648: listDisplayed.clearSelection();
0649: enableOrDisableListDisplayedButtons();
0650: updateColumnProps();
0651: updating = false;
0652: }
0653:
0654: private void btnUp_actionPerformed(ActionEvent e) {
0655: if (updating) {
0656: return;
0657: }
0658: updating = true;
0659: Object o = listDisplayed.getSelectedValue();
0660: if (!(o instanceof HtmlDataTableState.DisplayColumn)) {
0661: updating = false;
0662: return;
0663: }
0664: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
0665: table.display.moveColumnUp(dc);
0666: modelDisplayed.fire();
0667: listDisplayed.setSelectedValue(dc, true);
0668: enableOrDisableListDisplayedButtons();
0669: updateColumnProps();
0670: updating = false;
0671: }
0672:
0673: private void btnDown_actionPerformed(ActionEvent e) {
0674: if (updating) {
0675: return;
0676: }
0677: updating = true;
0678: Object o = listDisplayed.getSelectedValue();
0679: if (!(o instanceof HtmlDataTableState.DisplayColumn)) {
0680: updating = false;
0681: return;
0682: }
0683: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
0684: table.display.moveColumnDown(dc);
0685: modelDisplayed.fire();
0686: listDisplayed.setSelectedValue(dc, true);
0687: enableOrDisableListDisplayedButtons();
0688: updateColumnProps();
0689: updating = false;
0690: }
0691:
0692: private void comboCompType_actionPerformed(ActionEvent e) {
0693: if (updating) {
0694: return;
0695: }
0696: updating = true;
0697: updateColumnProps();
0698: updating = false;
0699: }
0700:
0701: private void listAvailable_valueChanged(ListSelectionEvent e) {
0702: if (updating) {
0703: return;
0704: }
0705: updating = true;
0706: enableOrDisableListAvailableButtons();
0707: updating = false;
0708: }
0709:
0710: private void listDisplayed_valueChanged(ListSelectionEvent e) {
0711: if (updating) {
0712: return;
0713: }
0714: updating = true;
0715: enableOrDisableListDisplayedButtons();
0716: updateColumnProps();
0717: updating = false;
0718: }
0719:
0720: private void enableOrDisableListAvailableButtons() {
0721: btnAdd.setEnabled(modelAvailable.getSize() > 0
0722: && listAvailable.getSelectedIndices().length > 0);
0723: }
0724:
0725: private void enableOrDisableListDisplayedButtons() {
0726: Object o = listDisplayed.getSelectedValue();
0727: if (o instanceof HtmlDataTableState.DisplayColumn) {
0728: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
0729: btnUp.setEnabled(table.display.canMoveUp(dc));
0730: btnDown.setEnabled(table.display.canMoveDown(dc));
0731: btnRemoveOne.setEnabled(true);
0732: } else {
0733: btnUp.setEnabled(false);
0734: btnDown.setEnabled(false);
0735: btnRemoveOne.setEnabled(false);
0736: }
0737: if (modelDisplayed.getSize() > 0) {
0738: btnRemoveAll.setEnabled(true);
0739: } else {
0740: btnRemoveAll.setEnabled(false);
0741: }
0742: }
0743:
0744: private boolean updating = false;
0745:
0746: private void updateColumnProps() {
0747: boolean valueNotApplicable = false;
0748: Object o = listDisplayed.getSelectedValue();
0749: HtmlDataTableState.DisplayColumn dc = null;
0750: if (o instanceof HtmlDataTableState.DisplayColumn) {
0751: dc = (HtmlDataTableState.DisplayColumn) o;
0752: titledBorder1
0753: .setTitle(" "
0754: + bundle.getMessage("dcProps", dc
0755: .toString()) + " "); //NOI18N
0756: tfHeaderText.setText(dc.headerText);
0757: tfFooterText.setText(dc.footerText);
0758: modelCompType.setDisplayColumn(dc);
0759:
0760: if (HtmlMessage.class.getName().equals(dc.compClassName)
0761: || HtmlPanelGroup.class.getName().equals(
0762: dc.compClassName)
0763: || HtmlPanelGrid.class.getName().equals(
0764: dc.compClassName)) {
0765: valueNotApplicable = true;
0766: }
0767:
0768: tfValue.setText(valueNotApplicable ? "" : dc.compValueRef); //NOI18N
0769: } else {
0770: titledBorder1.setTitle(" " + bundle.getMessage("colProps")
0771: + " "); //NOI18N
0772: tfHeaderText.setText(""); //NOI18N
0773: tfFooterText.setText(""); //NOI18N
0774: modelCompType.setDisplayColumn(null);
0775: tfValue.setText(""); //NOI18N
0776: }
0777: boolean enabled = true;
0778: boolean valueEnabled = true;
0779: //look for reasons to make enabled or valueEnabled false
0780: if (dc == null) {
0781: enabled = false;
0782: valueEnabled = false;
0783: } else if (dc.hasResultSetColumnPeer) {
0784: valueEnabled = false;
0785: } else if (valueNotApplicable) {
0786: valueEnabled = false;
0787: }
0788: tfHeaderText.setEnabled(enabled);
0789: tfFooterText.setEnabled(enabled);
0790: comboCompType.setEnabled(enabled);
0791: tfValue.setEnabled(valueEnabled);
0792:
0793: tfHeaderText.setBackground(enabled ? SystemColor.text
0794: : SystemColor.control);
0795: tfFooterText.setBackground(enabled ? SystemColor.text
0796: : SystemColor.control);
0797: tfValue.setBackground(valueEnabled ? SystemColor.text
0798: : SystemColor.control);
0799:
0800: validate();
0801: repaint(100);
0802: }
0803:
0804: private void tfHeaderText_changed(DocumentEvent e) {
0805: if (updating) {
0806: return;
0807: }
0808: updating = true;
0809: Object o = listDisplayed.getSelectedValue();
0810: if (o instanceof HtmlDataTableState.DisplayColumn) {
0811: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
0812: Document d = e.getDocument();
0813: try {
0814: dc.headerText = d.getText(
0815: d.getStartPosition().getOffset(),
0816: d.getEndPosition().getOffset()).trim();
0817: } catch (BadLocationException x) {
0818: }
0819: }
0820: updating = false;
0821: }
0822:
0823: private void tfFooterText_changed(DocumentEvent e) {
0824: if (updating) {
0825: return;
0826: }
0827: updating = true;
0828: Object o = listDisplayed.getSelectedValue();
0829: if (o instanceof HtmlDataTableState.DisplayColumn) {
0830: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
0831: Document d = e.getDocument();
0832: try {
0833: dc.footerText = d.getText(
0834: d.getStartPosition().getOffset(),
0835: d.getEndPosition().getOffset()).trim();
0836: } catch (BadLocationException x) {
0837: }
0838: }
0839: updating = false;
0840: }
0841:
0842: private void tfValue_changed(DocumentEvent e) {
0843: if (updating) {
0844: return;
0845: }
0846: updating = true;
0847: Object o = listDisplayed.getSelectedValue();
0848: if (o instanceof HtmlDataTableState.DisplayColumn) {
0849: HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn) o;
0850: Document d = e.getDocument();
0851: try {
0852: dc.compValueRef = d.getText(
0853: d.getStartPosition().getOffset(),
0854: d.getEndPosition().getOffset()).trim();
0855: } catch (BadLocationException x) {
0856: }
0857: }
0858: updating = false;
0859: }
0860:
0861: private class ResultSetColumnListModel extends AbstractListModel {
0862: public int getSize() {
0863: return table.rsinfo == null ? 0 : table.rsinfo
0864: .getColumnCount();
0865: }
0866:
0867: public Object getElementAt(int index) {
0868: if (table.rsinfo != null && index >= 0
0869: && index <= table.rsinfo.getColumnCount() - 1) {
0870: return table.rsinfo.getColumn(index);
0871: } else {
0872: return null;
0873: }
0874: }
0875:
0876: public void fire() {
0877: fireContentsChanged(this , -1, -1);
0878: }
0879: }
0880:
0881: private class DisplayColumnListModel extends AbstractListModel {
0882: public int getSize() {
0883: return table.display.getColumnCount();
0884: }
0885:
0886: public Object getElementAt(int index) {
0887: if (index >= 0 && index <= getSize() - 1) {
0888: return table.display.getColumn(index);
0889: } else {
0890: return null;
0891: }
0892: }
0893:
0894: public void fire() {
0895: fireContentsChanged(this , -1, -1);
0896: }
0897: }
0898:
0899: private class CompTypeComboModel extends AbstractListModel
0900: implements ComboBoxModel {
0901: private CompType[] types = new CompType[] {
0902: new CompType(bundle.getMessage("outputTextParenRO"),
0903: HtmlOutputText.class.getName(), "outputText"), //NOI18N
0904: new CompType(bundle.getMessage("inputTextParenE"),
0905: HtmlInputText.class.getName(), "textField"), //NOI18N
0906: new CompType(bundle.getMessage("secretTextParenE"),
0907: HtmlInputSecret.class.getName(), "secretField"), //NOI18N
0908: new CompType(bundle.getMessage("textAreaParenMulti"),
0909: HtmlInputTextarea.class.getName(), "textArea"), //NOI18N
0910: new CompType(bundle.getMessage("btnParenA"),
0911: HtmlCommandButton.class.getName(), "button"), //NOI18N
0912: new CompType(bundle.getMessage("linkParenA"),
0913: HtmlCommandLink.class.getName(), "linkAction"), //NOI18N
0914: new CompType(bundle.getMessage("chkParenTF"),
0915: HtmlSelectBooleanCheckbox.class.getName(),
0916: "checkbox"), //NOI18N
0917: new CompType(bundle.getMessage("dropdnParenLOI"),
0918: HtmlSelectOneMenu.class.getName(), "dropdown"), //NOI18N
0919: new CompType(bundle.getMessage("radioButtonList"),
0920: HtmlSelectOneRadio.class.getName(),
0921: "radioButtonList"), //NOI18N
0922: new CompType(bundle.getMessage("image"),
0923: HtmlGraphicImage.class.getName(), "image"), //NOI18N
0924: new CompType(bundle.getMessage("inlineMsg"),
0925: HtmlMessage.class.getName(), "inlineMessage"), //NOI18N
0926: new CompType(bundle.getMessage("gridPanel"),
0927: HtmlPanelGrid.class.getName(), "gridPanel"), //NOI18N
0928: new CompType(bundle.getMessage("groupPanel"),
0929: HtmlPanelGroup.class.getName(), "groupPanel") //NOI18N
0930: };
0931:
0932: private HashMap compTypeHash = new HashMap();
0933:
0934: private CompTypeComboModel() {
0935: for (int i = 0; i < types.length; i++) {
0936: compTypeHash.put(types[i].compClassName, types[i]);
0937: }
0938: }
0939:
0940: private HtmlDataTableState.DisplayColumn dc = null;
0941:
0942: private void setDisplayColumn(
0943: HtmlDataTableState.DisplayColumn dc) {
0944: this .dc = dc;
0945: fire();
0946: }
0947:
0948: public void setSelectedItem(Object anItem) {
0949: if (anItem instanceof CompType && dc != null) {
0950: CompType ct = (CompType) anItem;
0951: dc.compClassName = ct.compClassName;
0952: //dc.compInstanceName = ct.compInstanceName;
0953: }
0954: }
0955:
0956: public Object getSelectedItem() {
0957: if (dc != null) {
0958: return compTypeHash.get(dc.compClassName);
0959: }
0960: return null;
0961: }
0962:
0963: public int getSize() {
0964: return types.length;
0965: }
0966:
0967: public Object getElementAt(int index) {
0968: return types[index];
0969: }
0970:
0971: public void fire() {
0972: fireContentsChanged(this , -1, -1);
0973: }
0974: }
0975:
0976: private class CompType {
0977: public String display;
0978: public String compClassName;
0979: public String compInstanceName;
0980:
0981: public CompType(String display, String compClassName,
0982: String compInstanceName) {
0983: this .display = display;
0984: this .compClassName = compClassName;
0985: this .compInstanceName = compInstanceName;
0986: }
0987:
0988: public String toString() {
0989: return display;
0990: }
0991: }
0992:
0993: private class SourceComboRenderer extends DefaultListCellRenderer {
0994: public Component getListCellRendererComponent(JList list,
0995: Object value, int index, boolean isSelected,
0996: boolean cellHasFocus) {
0997: super .getListCellRendererComponent(list, value, index,
0998: isSelected, cellHasFocus);
0999: if (value == null) {
1000: this .setText(bundle.getMessage("bracketsNone")); //NOI18N
1001: } else {
1002: DesignBean bean = (DesignBean) value;
1003: this .setText(bundle.getMessage("sourceComboRend", bean
1004: .getInstanceName(), //NOI18N
1005: bean.getDesignContext().getDisplayName())); //NOI18N
1006: }
1007: return this;
1008: }
1009: }
1010: }
|