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 CleanUpBlueprintInstancesAction extends
041: AbstractAction implements ContelligentAction {
042: /**
043: *
044: */
045: private final ExplorerEditor editor;
046:
047: public CleanUpBlueprintInstancesAction(ExplorerEditor editor) {
048: super ("clean_up_blueprint_instances_action",
049: Resources.cleanUpBlueprintInstancesIcon);
050: this .editor = editor;
051: putValue(Action.SHORT_DESCRIPTION,
052: "clean_up_blueprint_instances_action_description");
053: putValue(TYPE, PUSH_ACTION);
054: putValue(ACTION_TYPE, EDIT_ACTION);
055: putValue(ACTION_GROUP, EDIT_BLUEPRINT_GROUP);
056: putValue(ACTION_GROUP, EDIT_BLUEPRINT_CLEANUP);
057: putValue(MENU_TARGET, NO_MENU);
058: putValue(BUTTON_TARGET, NO_BUTTON);
059: putValue(POPUP_TARGET, POPUP_SUBMENU);
060: putValue(POPUP_PARENT_ACTION, this .editor.typeAction);
061:
062: // putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control
063: // L"));
064: }
065:
066: public void actionPerformed(ActionEvent e) {
067: try {
068: if (!this .editor.getView().isEditInProgress()) {
069: final TreePath[] selectionPaths = this .editor.tree
070: .getSelectionPaths();
071: if (selectionPaths != null) {
072: if (selectionPaths.length > 0) {
073: if (JOptionPane
074: .showConfirmDialog(
075: ContelligentClient.getFrame(),
076: Resources
077: .getLocalString("clean_up_instances_question"),
078: Resources
079: .getLocalString("clean_up_instances_title"),
080: JOptionPane.OK_CANCEL_OPTION,
081: JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
082: DefaultMutableTreeNode firstNode = ((DefaultMutableTreeNode) selectionPaths[0]
083: .getLastPathComponent());
084: if (firstNode != null
085: && firstNode.getUserObject() instanceof ComponentReference) {
086: ContelligentComponent component = ((ComponentReference) firstNode
087: .getUserObject())
088: .getComponent();
089: try {
090: ActionResult response = Actions
091: .cleanUpBlueprintInstances(
092: editor
093: .getView()
094: .getEnvironment(),
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:
112: public void update() {
113: ContelligentComponent component = this.editor
114: .getSelectedComponent();
115: setEnabled(component != null && component.isBlueprint()
116: && !this.editor.getView().isEditInProgress()
117: && this.editor.getView().getAllowBlueprintDefinition()
118: && ComponentFactory.getInstance().isRootContext());
119: }
120: }
|