001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.gui.explorer;
019:
020: import java.awt.event.ActionEvent;
021:
022: import javax.swing.AbstractAction;
023: import javax.swing.Action;
024: import javax.swing.JOptionPane;
025: import javax.swing.tree.DefaultMutableTreeNode;
026: import javax.swing.tree.TreePath;
027:
028: import de.finix.contelligent.client.ContelligentClient;
029: import de.finix.contelligent.client.base.ComponentFactory;
030: import de.finix.contelligent.client.base.ComponentNotFoundException;
031: import de.finix.contelligent.client.base.ComponentReference;
032: import de.finix.contelligent.client.base.ContelligentComponent;
033: import de.finix.contelligent.client.gui.ContelligentAction;
034: import de.finix.contelligent.client.i18n.Resources;
035: import de.finix.contelligent.client.remote.ActionResult;
036: import de.finix.contelligent.client.remote.Actions;
037: import de.finix.contelligent.client.remote.RemoteActionException;
038: import de.finix.contelligent.client.util.ExceptionDialog;
039:
040: final public class RollbackSubtreeAction extends AbstractAction
041: implements ContelligentAction {
042: /**
043: *
044: */
045: private final ExplorerEditor editor;
046:
047: public RollbackSubtreeAction(ExplorerEditor editor) {
048: super ("rollback_subtree_action", Resources.defaultViewIcon);
049: this .editor = editor;
050: putValue(Action.SHORT_DESCRIPTION,
051: "rollback_subtree_action_description");
052: putValue(TYPE, PUSH_ACTION);
053: putValue(ACTION_TYPE, SERVER_ACTION);
054: putValue(ACTION_GROUP, SERVER_SUBTREE_GROUP);
055: putValue(ACTION_POS, SERVER_SUBTREE_DISCARD);
056: putValue(MENU_TARGET, MENU);
057: putValue(BUTTON_TARGET, NO_BUTTON);
058: // putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control
059: // L"));
060: }
061:
062: public void actionPerformed(ActionEvent e) {
063: try {
064: if (!this .editor.getView().isEditInProgress()) {
065: final TreePath[] selectionPaths = this .editor.tree
066: .getSelectionPaths();
067: if (selectionPaths != null) {
068: if (selectionPaths.length > 0) {
069: if (JOptionPane
070: .showConfirmDialog(
071: ContelligentClient.getFrame(),
072: Resources
073: .getLocalString("rollback_subtree_question"),
074: Resources
075: .getLocalString("rollback_subtree_title"),
076: JOptionPane.OK_CANCEL_OPTION,
077: JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
078: DefaultMutableTreeNode firstNode = ((DefaultMutableTreeNode) selectionPaths[0]
079: .getLastPathComponent());
080: if (firstNode != null
081: && firstNode.getUserObject() instanceof ComponentReference) {
082: ContelligentComponent component = ((ComponentReference) firstNode
083: .getUserObject())
084: .getComponent();
085: try {
086: ActionResult response = Actions
087: .discardChanges(
088: editor
089: .getView()
090: .getEnvironment(),
091: ComponentFactory
092: .getInstance()
093: .getCurrentContext()
094: .getName(),
095: component.getPath());
096: response.showErrors();
097: } catch (RemoteActionException rae) {
098: ExceptionDialog.show(rae);
099: }
100: }
101: }
102: }
103: }
104: } else {
105: setEnabled(false);
106: }
107: } catch (ComponentNotFoundException cnfe) {
108: ExceptionDialog.show(cnfe);
109: }
110: }
111: }
|