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: import java.util.Collection;
022:
023: import javax.swing.AbstractAction;
024: import javax.swing.Action;
025: import javax.swing.JOptionPane;
026:
027: import de.finix.contelligent.client.ContelligentClient;
028: import de.finix.contelligent.client.base.ComponentFactory;
029: import de.finix.contelligent.client.event.ContelligentComponentEvent;
030: import de.finix.contelligent.client.gui.ContelligentAction;
031: import de.finix.contelligent.client.i18n.Resources;
032: import de.finix.contelligent.client.remote.ActionResult;
033: import de.finix.contelligent.client.remote.Actions;
034: import de.finix.contelligent.client.remote.RemoteActionException;
035: import de.finix.contelligent.client.util.ExceptionDialog;
036:
037: public class ShowDeletedComponentsAction extends AbstractAction
038: implements ContelligentAction {
039: /**
040: *
041: */
042: private final ExplorerEditor editor;
043:
044: public ShowDeletedComponentsAction(ExplorerEditor editor) {
045: super ("show_deleted_components_action",
046: Resources.showDeletedIcon);
047: this .editor = editor;
048: putValue(TYPE, PUSH_ACTION);
049: putValue(ACTION_TYPE, VIEW_ACTION);
050: putValue(ACTION_GROUP, VIEW_CONTEXT_GROUP);
051: putValue(ACTION_POS, VIEW_CONTEXT_DELETED);
052: putValue(MENU_TARGET, MENU);
053: putValue(BUTTON_TARGET, TOOLBAR);
054: putValue(POPUP_TARGET, NO_POPUP);
055: }
056:
057: public void actionPerformed(ActionEvent e) {
058: try {
059: ActionResult response = Actions.modifiedComponents(
060: this .editor.currentContext, true);
061: Collection paths = response.getPaths();
062: if (this .editor.pathSelectionManager != null) {
063: this .editor.pathSelectionManager
064: .setPaths(
065: Resources
066: .getLocalString("show_deleted_components_action"),
067: paths,
068: new Action[] { new AbstractAction(
069: "restore_component") {
070: public void actionPerformed(
071: ActionEvent e) {
072: String path = ShowDeletedComponentsAction.this .editor.pathSelectionManager
073: .getSelectedPath();
074: if (path != null
075: && ShowDeletedComponentsAction.this .editor.currentContext != null
076: && JOptionPane
077: .showOptionDialog(
078: ContelligentClient
079: .getTopLevelFrame(ShowDeletedComponentsAction.this .editor),
080: Resources
081: .getLocalString("try_to_resurrect_question"),
082: Resources
083: .getLocalString("component_does_not_exist"),
084: JOptionPane.YES_NO_OPTION,
085: JOptionPane.WARNING_MESSAGE,
086: null,
087: ExplorerEditor.YES_CANCEL_OPTIONS,
088: ExplorerEditor.YES_CANCEL_OPTIONS[0]) == JOptionPane.YES_OPTION) {
089: try {
090: ActionResult response = Actions
091: .discardChanges(
092: editor
093: .getView()
094: .getEnvironment(),
095: ShowDeletedComponentsAction.this .editor.currentContext,
096: path);
097: response.showErrors();
098: // XXX as event from server will be
099: // "changed", not "added", send correct
100: // event here
101: if (response
102: .getState()
103: .equals(
104: ActionResult.OK)) {
105: ContelligentComponentEvent event = new ContelligentComponentEvent(
106: this ,
107: path,
108: ContelligentComponentEvent.COMPONENT_ADDED);
109: ComponentFactory
110: .getInstance()
111: .fireComponentAddEvent(
112: event);
113: }
114: } catch (RemoteActionException rae) {
115: ExceptionDialog
116: .show(rae);
117: }
118: }
119: }
120: } });
121: this .editor.pathSelectionManager.showPaths();
122: }
123: } catch (RemoteActionException rae) {
124: ExceptionDialog.show(rae);
125: }
126: }
127: }
|