01: package org.osbl.client.wings.action;
02:
03: import org.osbl.client.wings.action.ShowViewerAction;
04: import org.osbl.client.wings.action.ShowEditorAction;
05: import org.osbl.client.wings.shell.Client;
06: import org.osbl.client.action.ActionProvider;
07:
08: import javax.swing.*;
09: import java.util.*;
10: import java.awt.event.ActionEvent;
11:
12: public class QueryAction extends AbstractAction implements Cloneable {
13: private Map<String, String> query = new HashMap<String, String>();
14:
15: public QueryAction(String command, String query) {
16: putValue(ACTION_COMMAND_KEY, command);
17: for (StringTokenizer entries = new StringTokenizer(query, "&"); entries
18: .hasMoreTokens();) {
19: String entry = entries.nextToken();
20: int pos = entry.indexOf('=');
21: if (pos == -1)
22: this .query.put(entry, null);
23: else {
24: String name = entry.substring(0, pos);
25: String value = entry.substring(pos + 1);
26: this .query.put(name, value);
27: }
28: }
29: }
30:
31: public void actionPerformed(ActionEvent event) {
32: ActionProvider sessionActionProvider = Client.getInstance()
33: .getActionProvider();
34: String navigate = query.get("navigate");
35: if (navigate != null) {
36: Action action = sessionActionProvider.getAction(navigate);
37: if (action != null && action.isEnabled()) {
38: action.actionPerformed(new ActionEvent(this , 0,
39: navigate));
40: }
41: return;
42: }
43:
44: String view = query.get("view");
45: if (view != null) {
46: try {
47: ClassLoader classLoader = Thread.currentThread()
48: .getContextClassLoader();
49: ShowViewerAction action = new ShowViewerAction(
50: classLoader.loadClass(view), view);
51: action = (ShowViewerAction) sessionActionProvider
52: .configure(action);
53: if (action.isEnabled()) {
54: action.navigate(query);
55: }
56: } catch (ClassNotFoundException e) {
57: throw new RuntimeException(e);
58: }
59: return;
60: }
61:
62: String edit = query.get("edit");
63: if (edit != null) {
64: try {
65: ClassLoader classLoader = Thread.currentThread()
66: .getContextClassLoader();
67: ShowEditorAction action = new ShowEditorAction(
68: classLoader.loadClass(edit), edit);
69: action = (ShowEditorAction) sessionActionProvider
70: .configure(action);
71: if (action.isEnabled()) {
72: action.navigate(query);
73: }
74: } catch (ClassNotFoundException e) {
75: throw new RuntimeException(e);
76: }
77: return;
78: }
79: }
80:
81: public Object clone() {
82: try {
83: return super .clone();
84: } catch (CloneNotSupportedException e) {
85: throw new RuntimeException(e);
86: }
87: }
88: }
|