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.Observable;
012: import java.util.Observer;
013: import java.util.Properties;
014:
015: import javax.swing.AbstractAction;
016: import javax.swing.Action;
017: import javax.swing.BoxLayout;
018: import javax.swing.JComponent;
019: import javax.swing.JDialog;
020: import javax.swing.KeyStroke;
021: import javax.swing.WindowConstants;
022:
023: import org.enhydra.jawe.JaWEComponent;
024: import org.enhydra.jawe.JaWEComponentSettings;
025: import org.enhydra.jawe.JaWEComponentView;
026: import org.enhydra.jawe.JaWEManager;
027: import org.enhydra.jawe.ResourceManager;
028: import org.enhydra.jawe.XPDLElementChangeInfo;
029: import org.enhydra.jawe.base.panel.InlinePanel;
030: import org.enhydra.jawe.base.panel.panels.ValidationErrorOrSearchResultListPanel;
031: import org.enhydra.jawe.base.panel.panels.XMLBasicPanel;
032: import org.enhydra.jawe.base.panel.panels.XMLPanel;
033: import org.enhydra.shark.xpdl.XMLCollection;
034: import org.enhydra.shark.xpdl.XMLElement;
035: import org.enhydra.shark.xpdl.elements.Package;
036:
037: /**
038: *
039: */
040: public class ValidationOrSearchResultEditor extends JDialog implements
041: JaWEComponent, Observer {
042:
043: protected String type = JaWEComponent.OTHER_COMPONENT;
044:
045: protected Properties properties = new Properties();
046:
047: protected XMLPanel panelToEdit = new XMLBasicPanel();
048:
049: protected boolean validationDisplayEnabled = true;
050:
051: protected boolean searchDisplayEnabled = true;
052:
053: public String getLanguageDependentString(String nm) {
054: return ResourceManager.getLanguageDependentString(nm);
055: }
056:
057: public ValidationOrSearchResultEditor() {
058: super (JaWEManager.getInstance().getJaWEController()
059: .getJaWEFrame(), false);
060: init();
061: }
062:
063: public JaWEComponentSettings getSettings() {
064: return null;
065: }
066:
067: public Properties getProperties() {
068: return properties;
069: }
070:
071: public void setValidationDisplayEnabled(boolean enabled) {
072: this .validationDisplayEnabled = enabled;
073: }
074:
075: public void setSearchDisplayEnabled(boolean enabled) {
076: this .searchDisplayEnabled = enabled;
077: }
078:
079: public void update(Observable o, Object arg) {
080: if (!(arg instanceof XPDLElementChangeInfo))
081: return;
082:
083: XPDLElementChangeInfo info = (XPDLElementChangeInfo) arg;
084: if (info.getChangedElement() == null)
085: return;
086: int action = info.getAction();
087:
088: if (!((action == XPDLElementChangeInfo.VALIDATION_ERRORS
089: && validationDisplayEnabled && (info.getOldValue() instanceof Boolean && !((Boolean) info
090: .getOldValue()).booleanValue())) || ((action == XPDLElementChangeInfo.SEARCH_RESULT) || action == XPDLElementChangeInfo.REFERENCES)
091: && searchDisplayEnabled))
092: return;
093:
094: String t = "";
095: if (action == XPDLElementChangeInfo.VALIDATION_ERRORS) {
096: t = getLanguageDependentString("DialogValidationReport");
097: } else {
098: t = getLanguageDependentString("DialogSearchResult");
099: }
100: setTitle(t);
101: setDisplayPanel(t, info.getChangedElement(), info
102: .getChangedSubElements());
103: }
104:
105: public JaWEComponentView getView() {
106: return null;
107: }
108:
109: public JComponent getDisplay() {
110: return null;
111: }
112:
113: public String getType() {
114: return type;
115: }
116:
117: public void setType(String type) {
118: this .type = type;
119: }
120:
121: public String getName() {
122: return "VALIDATION_EDITOR";
123: }
124:
125: public boolean adjustXPDL(Package pkg) {
126: return false;
127: }
128:
129: public List checkValidity(XMLElement el, boolean fullCheck) {
130: return null;
131: }
132:
133: public boolean canCreateElement(XMLCollection col) {
134: return true;
135: }
136:
137: public boolean canInsertElement(XMLCollection col, XMLElement el) {
138: return true;
139: }
140:
141: public boolean canModifyElement(XMLCollection col, XMLElement el) {
142: return true;
143: }
144:
145: public boolean canModifyElement(XMLElement col) {
146: return true;
147: }
148:
149: public boolean canRemoveElement(XMLCollection col, XMLElement el) {
150: return true;
151: }
152:
153: public boolean canDuplicateElement(XMLCollection col, XMLElement el) {
154: return true;
155: }
156:
157: public boolean canRepositionElement(XMLCollection col, XMLElement el) {
158: return true;
159: }
160:
161: public Action getAction(String cmd) {
162: return null;
163: }
164:
165: public Action[] getActions() {
166: return null;
167: }
168:
169: public void configure(Properties props) {
170: this .properties = props;
171: }
172:
173: protected void init() {
174: try {
175: JaWEManager.getInstance().getJaWEController().addObserver(
176: this );
177:
178: initDialog();
179:
180: } catch (Exception e) {
181: e.printStackTrace();
182: }
183: }
184:
185: protected void initDialog() {
186: try {
187:
188: Container cp = getContentPane();
189: cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
190:
191: cp.add(panelToEdit);
192: getRootPane()
193: .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
194: .put(
195: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,
196: 0, false), "Cancel");
197: getRootPane().getInputMap(JComponent.WHEN_FOCUSED)
198: .put(
199: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,
200: 0, false), "Cancel");
201: getRootPane().getActionMap().put("Cancel",
202: new AbstractAction() {
203: public void actionPerformed(ActionEvent e) {
204: cl.actionPerformed(e);
205: }
206: });
207: addWindowListener(wl);
208:
209: } catch (Exception e) {
210: e.printStackTrace();
211: }
212: setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
213: setResizable(true);
214:
215: }
216:
217: protected WindowListener wl = new WindowAdapter() {
218: public void windowClosing(WindowEvent e) {
219: close();
220: }
221: };
222:
223: protected ActionListener cl = new ActionListener() {
224: public void actionPerformed(ActionEvent ae) {
225: close();
226: }
227: };
228:
229: public InlinePanel getInlinePanel() {
230: return null;
231: }
232:
233: public void close() {
234: setVisible(false);
235: panelToEdit.cleanup();
236: Container cp = getContentPane();
237: cp.remove(panelToEdit);
238: panelToEdit = new XMLBasicPanel();
239: cp.add(panelToEdit, 0);
240: }
241:
242: public void setDisplayPanel(String t, XMLElement el, List errors) {
243: setModal(true);
244: showPanel(new ValidationErrorOrSearchResultListPanel(el,
245: errors, t, true, true));
246: }
247:
248: public void showPanel(XMLPanel newPanel) {
249: Container cp = getContentPane();
250: cp.remove(panelToEdit);
251: panelToEdit = newPanel;
252: cp.add(panelToEdit, 0);
253: pack();
254:
255: panelToEdit.requestFocus();
256: pack();
257:
258: if (!isVisible()) {
259: setLocationRelativeTo(JaWEManager.getInstance()
260: .getJaWEController().getJaWEFrame());
261: setVisible(true);
262: }
263: }
264:
265: public void setUpdateInProgress(boolean inProgress) {
266: }
267:
268: public boolean isUpdateInProgress() {
269: return false;
270: }
271:
272: }
|