001: package org.enhydra.jawe.base.editor;
002:
003: import java.awt.Container;
004: import java.awt.Window;
005: import java.awt.event.ActionEvent;
006: import java.awt.event.ActionListener;
007: import java.awt.event.KeyEvent;
008: import java.awt.event.WindowAdapter;
009: import java.awt.event.WindowEvent;
010: import java.awt.event.WindowListener;
011: import java.util.List;
012: import java.util.Observable;
013: import java.util.Observer;
014:
015: import javax.swing.AbstractAction;
016: import javax.swing.BoxLayout;
017: import javax.swing.JComponent;
018: import javax.swing.JDialog;
019: import javax.swing.JOptionPane;
020: import javax.swing.KeyStroke;
021: import javax.swing.WindowConstants;
022:
023: import org.enhydra.jawe.JaWEComponent;
024: import org.enhydra.jawe.JaWEComponentView;
025: import org.enhydra.jawe.JaWEManager;
026: import org.enhydra.jawe.JaWEComponentSettings;
027: import org.enhydra.jawe.base.panel.InlinePanel;
028: import org.enhydra.jawe.base.panel.PanelSettings;
029: import org.enhydra.jawe.base.panel.panels.XMLPanel;
030: import org.enhydra.shark.xpdl.XMLCollection;
031: import org.enhydra.shark.xpdl.XMLElement;
032: import org.enhydra.shark.xpdl.elements.Package;
033:
034: /**
035: *
036: */
037: public class NewStandardXPDLElementEditor extends JDialog implements
038: JaWEComponent, Observer, XPDLElementEditor {
039:
040: protected String type = JaWEComponent.OTHER_COMPONENT;
041:
042: public final static int STATUS_OK = 0;
043: public final static int STATUS_CANCEL = 1;
044:
045: protected int status = STATUS_OK;
046:
047: protected InlinePanel inlinePanel;
048: protected PanelSettings settings;
049:
050: public JaWEComponentSettings getSettings() {
051: return settings;
052: }
053:
054: public NewStandardXPDLElementEditor(JaWEComponentSettings settings) {
055: super (JaWEManager.getInstance().getJaWEController()
056: .getJaWEFrame());
057: this .settings = (PanelSettings) settings;
058: init();
059: }
060:
061: public void update(Observable o, Object arg) {
062: return;
063: }
064:
065: public JaWEComponentView getView() {
066: return inlinePanel;
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 "STANDARD_XPDL_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 void configure() {
118: }
119:
120: protected void init() {
121: try {
122: ClassLoader cl = getClass().getClassLoader();
123: inlinePanel = (InlinePanel) cl
124: .loadClass(
125: JaWEManager.getInstance()
126: .getInlinePanelClassName())
127: .newInstance();
128: } catch (Exception ex) {
129: String msg = "NewStandardXPDLElementEditor --> Problems while instantiating InlinePanel class '"
130: + JaWEManager.getInstance()
131: .getInlinePanelClassName()
132: + "' - using default implementation!";
133: JaWEManager.getInstance().getLoggingManager()
134: .error(msg, ex);
135: inlinePanel = new InlinePanel();
136: }
137:
138: try {
139: inlinePanel.setJaWEComponent(this );
140: // settings must be initialized after creation of InlinePanel
141: this .settings.init(this );
142: inlinePanel.init();
143:
144: JaWEManager.getInstance().getJaWEController().addObserver(
145: this );
146:
147: initDialog();
148:
149: } catch (Exception e) {
150: e.printStackTrace();
151: }
152: }
153:
154: /** Returns the panel that is currently beeing edited. */
155: public XMLPanel getEditingPanel() {
156: return inlinePanel.getViewPanel();
157: }
158:
159: public XMLElement getEditingElement() {
160: return inlinePanel.getActiveElement();
161: }
162:
163: public void editXPDLElement(XMLElement el) {
164: inlinePanel.setActiveElement(el);
165: if (el != null) {
166: setTitle(JaWEManager.getInstance().getLabelGenerator()
167: .getLabel(el));
168: }
169:
170: setDialogVisible();
171: }
172:
173: public void editXPDLElement() {
174: editXPDLElement(JaWEManager.getInstance().getJaWEController()
175: .getSelectionManager().getSelectedElement());
176: }
177:
178: protected void setDialogVisible() {
179: setSize(this .inlinePanel.getDisplay().getSize());
180: pack();
181: if (!isVisible()) {
182: setLocationRelativeTo(getParentWindow());
183: setVisible(true);
184: }
185: JaWEManager.getInstance().getJaWEController().adjustActions();
186: }
187:
188: public boolean canApplyChanges() {
189: return true;
190: }
191:
192: public void requestFocus() {
193: try {
194: inlinePanel.getDisplay().requestFocus();
195: } catch (Exception ex) {
196: // dialog.requestFocus();
197: }
198: }
199:
200: public int getStatus() {
201: return status;
202: }
203:
204: public Window getWindow() {
205: return this ;
206: }
207:
208: public Window getParentWindow() {
209: return JaWEManager.getInstance().getJaWEController()
210: .getJaWEFrame();
211: }
212:
213: protected void initDialog() {
214: try {
215: Container cp = getContentPane();
216: cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
217:
218: cp.add(inlinePanel.getDisplay());
219: getRootPane()
220: .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
221: .put(
222: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,
223: 0, false), "Cancel");
224: getRootPane().getInputMap(JComponent.WHEN_FOCUSED)
225: .put(
226: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,
227: 0, false), "Cancel");
228: getRootPane().getActionMap().put("Cancel",
229: new AbstractAction() {
230: public void actionPerformed(ActionEvent e) {
231: al.actionPerformed(e);
232: }
233: });
234: addWindowListener(wl);
235:
236: } catch (Exception e) {
237: e.printStackTrace();
238: }
239: setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
240: setResizable(true);
241: setModal(true);
242: }
243:
244: protected WindowListener wl = new WindowAdapter() {
245: public void windowClosing(WindowEvent e) {
246: close();
247: }
248: };
249:
250: protected ActionListener al = new ActionListener() {
251: public void actionPerformed(ActionEvent ae) {
252: close();
253: }
254: };
255:
256: public InlinePanel getInlinePanel() {
257: return this .inlinePanel;
258: }
259:
260: public void close() {
261: status = STATUS_CANCEL;
262: if (inlinePanel.isModified()) {
263: int sw = inlinePanel.showModifiedWarning();
264: if (sw == JOptionPane.CANCEL_OPTION
265: || (sw == JOptionPane.YES_OPTION && inlinePanel
266: .isModified()))
267: return;
268: }
269: setVisible(false);
270: inlinePanel.setActiveElement(null);
271: JaWEManager.getInstance().getJaWEController().adjustActions();
272: getInlinePanel().cleanup();
273: dispose();
274: }
275:
276: public XPDLElementEditor getParentEditor() {
277: return null;
278: }
279:
280: public void setModified(boolean modif) {
281:
282: }
283:
284: public void setUpdateInProgress(boolean inProgress) {
285: }
286:
287: public boolean isUpdateInProgress() {
288: return false;
289: }
290:
291: }
|