001: package org.enhydra.jawe.base.editor;
002:
003: import java.awt.Container;
004: import java.awt.event.ActionEvent;
005: import java.awt.event.ActionListener;
006: import java.awt.event.KeyEvent;
007: import java.awt.event.WindowAdapter;
008: import java.awt.event.WindowEvent;
009: import java.awt.event.WindowListener;
010: import java.util.List;
011: import java.util.Properties;
012:
013: import javax.swing.AbstractAction;
014: import javax.swing.Action;
015: import javax.swing.BoxLayout;
016: import javax.swing.JComponent;
017: import javax.swing.JDialog;
018: import javax.swing.KeyStroke;
019: import javax.swing.WindowConstants;
020:
021: import org.enhydra.jawe.JaWEComponent;
022: import org.enhydra.jawe.JaWEComponentSettings;
023: import org.enhydra.jawe.JaWEComponentView;
024: import org.enhydra.jawe.JaWEManager;
025: import org.enhydra.jawe.base.panel.InlinePanel;
026: import org.enhydra.jawe.base.panel.panels.XMLSimpleTablePanel;
027: import org.enhydra.shark.xpdl.XMLCollection;
028: import org.enhydra.shark.xpdl.XMLElement;
029: import org.enhydra.shark.xpdl.elements.Package;
030:
031: /**
032: *
033: */
034: public class TableEditor extends JDialog implements JaWEComponent {
035:
036: protected String type = JaWEComponent.OTHER_COMPONENT;
037:
038: protected Properties properties = new Properties();
039:
040: protected XMLSimpleTablePanel panelToEdit = null;
041:
042: protected InlinePanel inlinePanel;
043:
044: private TableEditorSettings settings;
045:
046: public TableEditor(TableEditorSettings ts) {
047: super (JaWEManager.getInstance().getJaWEController()
048: .getJaWEFrame(), true);
049: settings = ts;
050: init();
051: }
052:
053: public Properties getProperties() {
054: return properties;
055: }
056:
057: public JaWEComponentSettings getSettings() {
058: return settings;
059: }
060:
061: public JaWEComponentView getView() {
062: return null;
063: }
064:
065: public JComponent getDisplay() {
066: return null;
067: }
068:
069: public String getType() {
070: return type;
071: }
072:
073: public void setType(String type) {
074: this .type = type;
075: }
076:
077: public String getName() {
078: return "TABLE_EDITOR";
079: }
080:
081: public boolean adjustXPDL(Package pkg) {
082: return false;
083: }
084:
085: public List checkValidity(XMLElement el, boolean fullCheck) {
086: return null;
087: }
088:
089: public boolean canCreateElement(XMLCollection col) {
090: return true;
091: }
092:
093: public boolean canInsertElement(XMLCollection col, XMLElement el) {
094: return true;
095: }
096:
097: public boolean canModifyElement(XMLCollection col, XMLElement el) {
098: return true;
099: }
100:
101: public boolean canModifyElement(XMLElement col) {
102: return true;
103: }
104:
105: public boolean canRemoveElement(XMLCollection col, XMLElement el) {
106: return true;
107: }
108:
109: public boolean canDuplicateElement(XMLCollection col, XMLElement el) {
110: return true;
111: }
112:
113: public boolean canRepositionElement(XMLCollection col, XMLElement el) {
114: return true;
115: }
116:
117: public Action getAction(String cmd) {
118: return null;
119: }
120:
121: public Action[] getActions() {
122: return null;
123: }
124:
125: public void configure(Properties props) {
126: this .properties = props;
127: }
128:
129: protected void init() {
130: try {
131:
132: initDialog();
133:
134: } catch (Exception e) {
135: e.printStackTrace();
136: }
137: }
138:
139: protected void initDialog() {
140: Container cp = getContentPane();
141: cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
142:
143: getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(
144: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false),
145: "Cancel");
146: getRootPane().getActionMap().put("Cancel",
147: new AbstractAction() {
148: public void actionPerformed(ActionEvent e) {
149: al.actionPerformed(e);
150: }
151: });
152: addWindowListener(wl);
153:
154: try {
155: ClassLoader cl = getClass().getClassLoader();
156: inlinePanel = (InlinePanel) cl
157: .loadClass(
158: JaWEManager.getInstance()
159: .getInlinePanelClassName())
160: .newInstance();
161: } catch (Exception ex) {
162: String msg = "TableEditor --> Problems while instantiating InlinePanel class '"
163: + JaWEManager.getInstance()
164: .getInlinePanelClassName()
165: + "' - using default implementation!";
166: JaWEManager.getInstance().getLoggingManager()
167: .error(msg, ex);
168: inlinePanel = new InlinePanel();
169: }
170: try {
171:
172: inlinePanel.setJaWEComponent(this );
173: // settings must be initialized after creation of InlinePanel
174: settings.init(this );
175: inlinePanel.init();
176:
177: } catch (Exception e) {
178: e.printStackTrace();
179: }
180: setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
181: setResizable(true);
182:
183: }
184:
185: protected WindowListener wl = new WindowAdapter() {
186: public void windowClosing(WindowEvent e) {
187: close();
188: }
189: };
190:
191: protected ActionListener al = new ActionListener() {
192: public void actionPerformed(ActionEvent ae) {
193: close();
194: }
195: };
196:
197: public void close() {
198: setVisible(false);
199: if (panelToEdit != null) {
200: panelToEdit.cleanup();
201: Container cp = getContentPane();
202: cp.remove(panelToEdit);
203: panelToEdit = null;
204: }
205: }
206:
207: public void showTable(String title, XMLCollection owner,
208: List elements, List columnsToShow) {
209: Container cp = getContentPane();
210: if (panelToEdit != null) {
211: cp.remove(panelToEdit);
212: }
213: panelToEdit = createSTP(title, owner, elements, columnsToShow);
214:
215: cp.add(panelToEdit, 0);
216: pack();
217:
218: // panelToEdit.requestFocus();
219: pack();
220:
221: setTitle(panelToEdit.getTitle());
222: if (!isVisible()) {
223: setLocationRelativeTo(JaWEManager.getInstance()
224: .getJaWEController().getJaWEFrame());
225: setVisible(true);
226: }
227: }
228:
229: public void setUpdateInProgress(boolean inProgress) {
230: }
231:
232: public boolean isUpdateInProgress() {
233: return false;
234: }
235:
236: protected XMLSimpleTablePanel createSTP(String title,
237: XMLCollection owner, List elements, List columnsToShow) {
238: return new XMLSimpleTablePanel(inlinePanel, owner,
239: columnsToShow, elements, title, true, true, false);
240: }
241:
242: }
|