001: package org.enhydra.jawe.base.panel.panels;
002:
003: import java.awt.Component;
004: import java.awt.Dimension;
005: import java.awt.event.ActionEvent;
006: import java.awt.event.ActionListener;
007:
008: import javax.swing.Box;
009: import javax.swing.JComboBox;
010: import javax.swing.JScrollPane;
011: import javax.swing.JViewport;
012:
013: import org.enhydra.jawe.base.panel.PanelContainer;
014: import org.enhydra.shark.xpdl.XMLAttribute;
015: import org.enhydra.shark.xpdl.XMLElement;
016:
017: /**
018: * Creates a combo panel and a panel which type is determined by the
019: * chosen element from combo panel.
020: * @author Sasa Bojanic
021: * @author Zoran Milakovic
022: */
023: public class XMLComboChoicePanel extends XMLBasicPanel {
024:
025: protected XMLPanel prevPanel = null;
026: protected XMLComboPanel pCombo;
027: protected JScrollPane jsp;
028:
029: public XMLComboChoicePanel(PanelContainer pc, XMLElement myOwnerL,
030: boolean isEnabled) {
031: this (pc, myOwnerL, false, "", true, false, true, false,
032: isEnabled);
033: }
034:
035: public XMLComboChoicePanel(PanelContainer pc, XMLElement myOwner,
036: boolean addListener, String title, boolean isVertical,
037: boolean isChoiceVertical, boolean hasBorder,
038: boolean isEditable, boolean isEnabled) {
039:
040: super (pc, myOwner, title, isVertical, hasBorder, true);
041:
042: int noOfPanels = 2;
043: if (myOwner instanceof XMLAttribute) {
044: noOfPanels = 1;
045: }
046:
047: pCombo = new XMLComboPanel(pc, myOwner, null, false, false,
048: isChoiceVertical, isEditable, isEnabled);
049: //System.err.println(pCombo.getSelectedItem().getClass().getName());
050: XMLElement choosen = (XMLElement) pCombo.getSelectedItem();
051: add(pCombo);
052:
053: if (noOfPanels == 2) {
054: jsp = new JScrollPane();
055: jsp.setAlignmentX(Component.LEFT_ALIGNMENT);
056: jsp.setAlignmentY(Component.TOP_ALIGNMENT);
057: jsp.setMinimumSize(new Dimension(250, 200));
058:
059: add(jsp);
060:
061: prevPanel = pc.getPanelGenerator().getPanel(choosen);
062: jsp.setViewportView(prevPanel);
063:
064: final JComboBox jcb = pCombo.getComboBox();
065: jcb.addActionListener(new ActionListener() {
066: public void actionPerformed(ActionEvent ae) {
067: // if (prevPanel!=null) {
068: // prevPanel.setElements();
069: // }
070: XMLElement chosen = (XMLElement) pCombo
071: .getSelectedItem();
072: if (chosen != null) {
073: prevPanel = getPanelContainer()
074: .getPanelGenerator().getPanel(chosen);
075: jsp.setViewportView(prevPanel);
076: }
077: }
078: });
079:
080: }
081:
082: if (isVertical) {
083: add(Box.createVerticalGlue());
084: } else {
085: add(Box.createHorizontalGlue());
086: }
087:
088: }
089:
090: public XMLComboPanel getComboPanel() {
091: return pCombo;
092: }
093:
094: public boolean validateEntry() {
095: // checking Combo panel
096: boolean isOK = pCombo.validateEntry();
097: // checking implementation panel
098: if (!(getOwner() instanceof XMLAttribute)) {
099: JViewport jvp = (JViewport) jsp.getComponent(0);
100: if (jvp.getComponentCount() > 0) {
101: XMLPanel p = (XMLPanel) jvp.getComponent(0);
102: isOK = isOK && p.validateEntry();
103: }
104: }
105: return isOK;
106: }
107:
108: public void setElements() {
109: if (!getOwner().isReadOnly()) {
110: // setting Combo panel
111: pCombo.setElements();
112: // setting implementation panel
113: if (!(myOwner instanceof XMLAttribute)) {
114: JViewport jvp = jsp.getViewport();
115: if (jvp.getComponentCount() > 0) {
116: XMLPanel p = (XMLPanel) jvp.getComponent(0);
117: p.setElements();
118: }
119: }
120: }
121: }
122:
123: public Object getValue() {
124: return pCombo.getValue();
125: }
126:
127: public void cleanup() {
128: pCombo.cleanup();
129: if (!(myOwner instanceof XMLAttribute)) {
130: JViewport jvp = jsp.getViewport();
131: if (jvp.getComponentCount() > 0) {
132: XMLPanel p = (XMLPanel) jvp.getComponent(0);
133: p.cleanup();
134: }
135: }
136: }
137:
138: public void requestFocus() {
139: pCombo.requestFocus();
140: }
141:
142: }
|