001: package org.osbl.client.wings.action;
002:
003: import org.wings.util.SessionLocal;
004: import org.wings.SIcon;
005: import org.osbl.client.wings.form.*;
006: import org.osbl.client.wings.shell.Window;
007: import org.osbl.client.wings.shell.Client;
008: import org.osbl.client.action.AuthorizedAction;
009: import org.osbl.*;
010:
011: import java.util.HashMap;
012: import java.util.Map;
013: import java.awt.event.ActionEvent;
014:
015: public class ShowViewerAction extends NavigationAction {
016: private ObjectLocators objectLocators;
017:
018: Class type;
019:
020: static final SessionLocal windows = new SessionLocal() {
021: protected Object initialValue() {
022: return new HashMap();
023: }
024: };
025:
026: public ShowViewerAction(Class type, String command, SIcon icon) {
027: super (command, icon);
028: this .type = type;
029: putValue(PERMISSION_KEY, type.getName() + "[r]");
030: }
031:
032: public ShowViewerAction(Class type, String command) {
033: super (command);
034: this .type = type;
035: putValue(PERMISSION_KEY, type.getName() + "[r]");
036: }
037:
038: public void actionPerformed(ActionEvent event) {
039: ViewerWindow viewerWindow = getViewer();
040: ObjectViewer viewer = viewerWindow.getViewer();
041: viewer.showList();
042: Client.getInstance().pushWindow(viewerWindow);
043: }
044:
045: public void navigate(Object object) {
046: ViewerWindow viewerWindow = getViewer();
047: ObjectViewer viewer = viewerWindow.getViewer();
048: viewer.setObject(object);
049: viewer.showForm();
050: Client.getInstance().pushWindow(viewerWindow);
051: }
052:
053: public void navigate(Map<String, String> query) {
054: ViewerWindow viewerWindow = getViewer();
055: ObjectViewer viewer = viewerWindow.getViewer();
056:
057: ObjectLocator objectLocator = getObjectLocators().get(type);
058: if (objectLocator != null) {
059: Object object = objectLocator.objectByQuery(query);
060: if (object != null) {
061: viewer.setObject(object);
062: viewer.showForm();
063: } else
064: viewer.showList();
065: } else
066: viewer.showList();
067:
068: Client.getInstance().pushWindow(viewerWindow);
069: }
070:
071: private ViewerWindow getViewer() {
072: Map<Class, ViewerWindow> map = (Map<Class, ViewerWindow>) windows
073: .get();
074: ViewerWindow viewerWindow = map.get(type);
075: if (viewerWindow == null) {
076: ObjectViewer viewer = Viewers.get(type);
077: viewerWindow = new ViewerWindow(viewer);
078: map.put(type, viewerWindow);
079: }
080:
081: return viewerWindow;
082: }
083:
084: public ObjectLocators getObjectLocators() {
085: if (objectLocators == null)
086: objectLocators = (ObjectLocators) ServiceProvider
087: .getInstance().getService("ObjectLocators");
088: return objectLocators;
089: }
090:
091: static class ViewerWindow extends Window {
092: ObjectViewer viewer;
093:
094: public ViewerWindow(ObjectViewer viewer) {
095: this .viewer = viewer;
096: viewer.getEnvironment().setDelegate(this );
097: }
098:
099: public ObjectViewer getViewer() {
100: return viewer;
101: }
102: }
103: }
|