001: package org.osbl.domain.gui;
002:
003: import org.conform.*;
004: import org.conform.format.Format;
005: import org.conform.hibernate.HibernateEnvironment;
006: import org.conform.wings.Editor;
007: import org.conform.wings.PropertyAdapter;
008: import org.conform.wings.editor.*;
009: import org.osbl.ServiceProvider;
010: import org.osbl.client.action.*;
011: import org.osbl.client.wings.XButton;
012: import org.osbl.client.wings.XIcons;
013: import org.osbl.client.wings.form.ObjectEditor;
014: import org.osbl.client.wings.form.editor.EditorWindow;
015: import org.osbl.client.wings.form.editor.ListTableModel;
016: import org.osbl.client.wings.shell.Client;
017: import org.osbl.domain.logic.DomainLogic;
018: import org.osbl.domain.logic.ManagableDomainProvider;
019: import org.osbl.domain.model.Domain;
020: import org.osbl.domain.DomainRegistry;
021: import org.osbl.persistence.Persistence;
022: import org.osbl.persistence.LoadCommand;
023: import org.wings.*;
024: import org.wings.event.SParentFrameEvent;
025: import org.wings.event.SParentFrameListener;
026:
027: import javax.swing.*;
028: import javax.swing.event.ChangeEvent;
029: import javax.swing.event.ChangeListener;
030: import java.awt.event.ActionEvent;
031: import java.beans.PropertyChangeEvent;
032: import java.beans.PropertyChangeListener;
033: import java.util.ArrayList;
034: import java.util.Arrays;
035:
036: public class ManagableDomainEditor implements Editor,
037: SParentFrameListener {
038: public SComponent createComponent(PropertyMeta propertyMeta) {
039: ComboPanel comboPanel = new ComboPanel(propertyMeta);
040: configureComponent(propertyMeta, comboPanel, false);
041: comboPanel.addParentFrameListener(this );
042: return comboPanel;
043: }
044:
045: public void configureComponent(PropertyMeta propertyMeta,
046: SComponent component, boolean erroneous) {
047: ComboPanel comboPanel = (ComboPanel) component;
048: SComboBox comboBox = comboPanel.getComboBox();
049: comboBox.setEnabled(propertyMeta.isWritable());
050: comboBox.setVisible(propertyMeta.isReadable());
051: if (propertyMeta
052: .getAttribute(PropertyMeta.ATTRIBUTE_CHANGE_LISTENER) != null
053: && !Arrays.asList(comboBox.getActionListeners())
054: .contains(NoAction.INSTANCE))
055: comboBox.addActionListener(NoAction.INSTANCE);
056: DefaultEditorStyles.applyEditorState(propertyMeta, comboBox,
057: erroneous);
058: }
059:
060: public void parentFrameAdded(SParentFrameEvent e) {
061: final ComboPanel component = (ComboPanel) e.getSource();
062: PropertyData propertyData = getPropertyData(component);
063: PropertyMeta propertyMeta = propertyData.getPropertyMeta();
064: DynamicDomainProvider domainProvider = (DynamicDomainProvider) propertyMeta
065: .getDomainProvider();
066: ChangeListener listener = new ChangeListener() {
067: public void stateChanged(ChangeEvent e) {
068: component.getComboBoxModel().refresh();
069: }
070: };
071: domainProvider.addChangeListener(listener);
072: component.putClientProperty("domainChangeListener", listener);
073: }
074:
075: public void parentFrameRemoved(SParentFrameEvent e) {
076: final ComboPanel component = (ComboPanel) e.getSource();
077: PropertyData propertyData = getPropertyData(component);
078: PropertyMeta propertyMeta = propertyData.getPropertyMeta();
079: DynamicDomainProvider domainProvider = (DynamicDomainProvider) propertyMeta
080: .getDomainProvider();
081: ChangeListener listener = (ChangeListener) component
082: .getClientProperty("domainChangeListener");
083: domainProvider.removeChangeListener(listener);
084: }
085:
086: public void setPropertyData(SComponent component,
087: PropertyData propertyData) {
088: BeanData beanData = propertyData.getBeanData();
089: if (beanData != null)
090: beanData.addPropertyChangeListener(propertyData
091: .getPropertyMeta().getName(),
092: new ComponentInvalidator(component));
093:
094: if (component instanceof ComboPanel) {
095: ComboPanel comboPanel = (ComboPanel) component;
096: comboPanel.setPropertyData(propertyData);
097:
098: if (beanData != null)
099: beanData.addPropertyChangeListener(propertyData
100: .getPropertyMeta().getName(), comboPanel);
101: }
102: }
103:
104: public PropertyData getPropertyData(SComponent component) {
105: if (component instanceof ComboPanel) {
106: ComboPanel comboPanel = (ComboPanel) component;
107: return comboPanel.getPropertyData();
108: }
109:
110: return null;
111: }
112:
113: static class ComboPanel extends SContainer implements
114: PropertyChangeListener {
115: private PropertyMeta propertyMeta;
116: private SComboBox comboBox;
117: private SButton manageDomain;
118: PropertyData propertyData;
119: private EditorWindow window;
120: private org.osbl.domain.gui.DomainEditor domainEditor;
121:
122: public ComboPanel(PropertyMeta propertyMeta) {
123: super (new SBorderLayout());
124: this .propertyMeta = propertyMeta;
125:
126: manageDomain = new XButton(new ManageDomainAction());
127: comboBox = new SComboBox();
128: comboBox.setPreferredSize(SDimension.FULLWIDTH);
129:
130: add(comboBox, SBorderLayout.CENTER);
131: add(manageDomain, SBorderLayout.EAST);
132: }
133:
134: public PropertyData getPropertyData() {
135: return propertyData;
136: }
137:
138: public void setPropertyData(PropertyData propertyData) {
139: this .propertyData = propertyData;
140:
141: PropertyMeta propertyMeta = propertyData.getPropertyMeta();
142: comboBox.setModel(new ComboBoxModelPropertyAdapter(
143: propertyMeta));
144: Format format = propertyMeta.getFormat();
145: if (format != null)
146: comboBox.setRenderer(new FormattedListCellRenderer(
147: format));
148:
149: getComboBoxModel().setPropertyData(propertyData);
150: }
151:
152: public SComboBox getComboBox() {
153: return comboBox;
154: }
155:
156: public ComboBoxModelPropertyAdapter getComboBoxModel() {
157: return (ComboBoxModelPropertyAdapter) comboBox.getModel();
158: }
159:
160: public void setComboBoxModel(ComboBoxModel model) {
161: comboBox.setModel(model);
162: }
163:
164: public void setEnabled(boolean b) {
165: comboBox.setEnabled(b);
166: manageDomain.setEnabled(b);
167: }
168:
169: private EditorWindow getEditorWindow() {
170: if (window == null) {
171: ObjectEditor editor = getObjectEditor();
172: window = new EditorWindow(editor);
173: window.addPopAction(new PopAction());
174: }
175: return window;
176: }
177:
178: private ObjectEditor getObjectEditor() {
179: if (domainEditor == null)
180: domainEditor = new org.osbl.domain.gui.DomainEditor();
181: return domainEditor;
182: }
183:
184: public void propertyChange(PropertyChangeEvent evt) {
185: if (getComboBoxModel() instanceof ListTableModel) {
186: final Object value = propertyData.getValue();
187: if (value == null)
188: propertyData.setValue(new ArrayList());
189: ((ListTableModel) getComboBoxModel())
190: .setList((java.util.List) value);
191: }
192: }
193:
194: class ManageDomainAction extends AbstractAction {
195: public ManageDomainAction() {
196: putValue(Action.ACTION_COMMAND_KEY,
197: ".buttons.manageDomain");
198: putValue(AuthorizedAction.PERMISSION_KEY, propertyMeta
199: .getBeanMeta().getType().getName()
200: + "[w]");
201: putValue(Action.SMALL_ICON, XIcons.DOMAIN);
202: }
203:
204: public void actionPerformed(ActionEvent e) {
205: Domain domain = getDomain();
206:
207: EditorWindow window = getEditorWindow();
208: ObjectEditor editor = window.getEditor();
209: editor.setObject(domain);
210: editor.showForm();
211: org.osbl.client.wings.shell.Window parent = org.osbl.client.wings.shell.Window
212: .currentWindow(comboBox);
213: Client.getInstance().pushWindow(parent, window);
214: }
215: }
216:
217: private class PopAction extends AbstractObjectAction {
218: public PopAction() {
219: putValue(Action.ACTION_COMMAND_KEY, ".buttons.back");
220: }
221:
222: public void actionPerformed(ObjectActionEvent event) {
223: ((DynamicDomainProvider) propertyData.getPropertyMeta()
224: .getDomainProvider()).refresh();
225: }
226:
227: public void setEnabled(boolean enabled) {
228: }
229: }
230:
231: private Domain getDomain() {
232: ManagableDomainProvider domainProvider = (ManagableDomainProvider) getPropertyData()
233: .getPropertyMeta().getDomainProvider();
234: String key = domainProvider.getKey();
235: Domain domain = DomainRegistry.getDomain(key);
236: return domain;
237: }
238:
239: protected Object getRow(int index) {
240: LoadCommand command = (LoadCommand) getCommandFactory()
241: .createCommand("load");
242: command.setType(Domain.class);
243: command.setId(getDomain().getId());
244: try {
245: HibernateEnvironment.getInstance().beginTransaction();
246: return command.execute();
247: } finally {
248: HibernateEnvironment.getInstance().endTransaction();
249: }
250: }
251:
252: private Persistence persistence;
253:
254: public Persistence getCommandFactory() {
255: if (persistence == null)
256: persistence = (Persistence) ServiceProvider
257: .getInstance()
258: .getService("LocationPersistence");
259: return persistence;
260: }
261:
262: DomainLogic domainLogic = (DomainLogic) ServiceProvider
263: .getInstance().getService("DomainLogic");
264: }
265:
266: static class ComboBoxModelPropertyAdapter extends
267: SDefaultComboBoxModel implements PropertyAdapter {
268: private PropertyData propertyData;
269: private PropertyMeta property;
270:
271: public ComboBoxModelPropertyAdapter(PropertyMeta property) {
272: this .property = property;
273: }
274:
275: public PropertyData getPropertyData() {
276: return propertyData;
277: }
278:
279: public void setPropertyData(PropertyData propertyData) {
280: this .propertyData = propertyData;
281: fireContentsChanged(this , -1, -1);
282: }
283:
284: public Object getElementAt(int i) {
285: return property.getDomainProvider().getDomain().get(i);
286: }
287:
288: public int getSize() {
289: return property.getDomainProvider().getDomain().size();
290: }
291:
292: public Object getSelectedItem() {
293: if (propertyData == null)
294: return null;
295:
296: return propertyData.getValue();
297: }
298:
299: public void setSelectedItem(Object value) {
300: propertyData.setValue(value);
301: fireContentsChanged(this , -1, -1);
302: }
303:
304: protected void refresh() {
305: int end = getSize() - 1;
306: fireIntervalRemoved(this , 0, end);
307: fireIntervalAdded(this , 0, end);
308: }
309: }
310: }
311:
312: /*
313: select s1.username || '(at)' || s1.machine
314: || ' ( SID=' || s1.sid || ' ) is blocking '
315: || s2.username || '(at)' || s2.machine || ' ( SID=' || s2.sid || ' ) ' AS blocking_status
316: from v$$lock l1, v$$session s1, v$$lock l2, v$$session s2
317: where s1.sid=l1.sid and s2.sid=l2.sid
318: and l1.BLOCK=1 and l2.request > 0
319: and l1.id1 = l2.id1
320: and l2.id2 = l2.id2 ;
321:
322:
323: select do.object_name,
324: row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#,
325: dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# )
326: from v$$session s, dba_objects do
327: where sid=1102
328: and s.ROW_WAIT_OBJ# = do.OBJECT_ID ;
329: */
|