01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.gui.explorer;
19:
20: import java.awt.event.ActionEvent;
21: import java.io.IOException;
22: import java.util.HashMap;
23: import java.util.logging.Level;
24:
25: import javax.swing.AbstractAction;
26: import javax.swing.Action;
27:
28: import de.finix.contelligent.client.base.ComponentFactory;
29: import de.finix.contelligent.client.base.ContelligentComponent;
30: import de.finix.contelligent.client.base.Session;
31: import de.finix.contelligent.client.base.TypeFactory;
32: import de.finix.contelligent.client.gui.ContelligentAction;
33: import de.finix.contelligent.client.gui.CreateContextOptionPane;
34: import de.finix.contelligent.client.i18n.Resources;
35: import de.finix.contelligent.client.remote.Actions;
36: import de.finix.contelligent.client.util.ExceptionDialog;
37:
38: final public class CreateContextAction extends AbstractAction implements
39: ContelligentAction {
40: /**
41: *
42: */
43: private final ExplorerEditor editor;
44:
45: public CreateContextAction(ExplorerEditor editor) {
46: super ("create_context_action", Resources.createContextIcon);
47: this .editor = editor;
48: putValue(ROLLOVER_ICON, Resources.createContextIconRollOver);
49: putValue(Action.SHORT_DESCRIPTION,
50: "create_context_action_description");
51: putValue(TYPE, PUSH_ACTION);
52: putValue(ACTION_TYPE, SERVER_ACTION);
53: putValue(ACTION_GROUP, SERVER_GLOBAL_GROUP);
54: putValue(ACTION_POS, SERVER_GLOBAL_CREATE);
55: putValue(MENU_TARGET, MENU);
56: }
57:
58: public void actionPerformed(ActionEvent e) {
59: if (!this .editor.openEditors()) {
60: // open editor of the referenced component
61: ContelligentComponent tmpComponent = new ContelligentComponent(
62: "__TMP__", "__TMP__");
63: tmpComponent.setType(TypeFactory.getInstance()
64: .getDummyType());
65: tmpComponent.addOwner(Session.getInstance().getUser()
66: .getPrincipal());
67: CreateContextOptionPane createContextOptionPane = new CreateContextOptionPane(
68: tmpComponent);
69: if (createContextOptionPane.showDialog("") == CreateContextOptionPane.OK_OPTION) {
70: try {
71: String context = createContextOptionPane
72: .getContextName();
73: String xml = Actions.modifiedComponentToXml(
74: tmpComponent, new HashMap());
75: ExplorerEditor.logger.log(Level.FINE,
76: "XML for create context: " + xml);
77: if (ComponentFactory.getInstance().createContext(
78: context, xml)) {
79: ComponentFactory.getInstance()
80: .switchCurrentContext(
81: ComponentFactory.getInstance()
82: .getCurrentContext()
83: .getName()
84: + "." + context);
85: }
86: } catch (IOException ioe) {
87: ExceptionDialog.show(ioe);
88: }
89: }
90: }
91: }
92: }
|