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.awt.event.KeyEvent;
022:
023: import javax.swing.Action;
024: import javax.swing.JOptionPane;
025: import javax.swing.KeyStroke;
026: import javax.swing.tree.DefaultMutableTreeNode;
027: import javax.swing.tree.TreePath;
028:
029: import de.finix.contelligent.client.ContelligentClient;
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.util.ComponentMovement;
036: import de.finix.contelligent.client.util.ExceptionDialog;
037: import de.finix.contelligent.client.util.MnemonicAbstractAction;
038:
039: public class DeleteComponentAction extends MnemonicAbstractAction
040: implements ContelligentAction {
041:
042: /**
043: *
044: */
045: private final ExplorerEditor editor;
046:
047: public DeleteComponentAction(ExplorerEditor editor) {
048: super ("delete_component_action", Resources.deleteComponentIcon);
049: this .editor = editor;
050: putValue(ROLLOVER_ICON, Resources.deleteComponentIconRollOver);
051: putValue(TYPE, PUSH_ACTION);
052: putValue(ACTION_TYPE, EDIT_ACTION);
053: putValue(ACTION_GROUP, EDIT_COPYPASTE_GROUP);
054: putValue(ACTION_POS, EDIT_COPYPASTE_DELETE);
055: putValue(MENU_TARGET, MENU);
056: putValue(BUTTON_TARGET, TOOLBAR);
057: putValue(POPUP_TARGET, POPUP_MENU);
058: putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
059: KeyEvent.VK_DELETE, 0));
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: DefaultMutableTreeNode firstNode = ((DefaultMutableTreeNode) selectionPaths[0]
070: .getLastPathComponent());
071: if (firstNode != null
072: && firstNode.getUserObject() instanceof ComponentReference) {
073: ContelligentComponent component = ((ComponentReference) firstNode
074: .getUserObject()).getComponent();
075: if (component.isBlueprint()) {
076: String typeName = component
077: .getDefinedBlueprintType();
078: this .editor.deleteType(typeName, false,
079: true);
080: } else {
081: String componentName = component
082: .getName();
083: int answer = JOptionPane.NO_OPTION;
084: if (component.isBlueprintSubComponent()) {
085: answer = JOptionPane
086: .showOptionDialog(
087: ContelligentClient
088: .getActiveFrame(),
089: Resources
090: .getLocalString(
091: "delete_blueprint_subcomponent_question",
092: new String[] { componentName }),
093: Resources
094: .getLocalString("comfirm_delete"),
095: JOptionPane.YES_NO_OPTION,
096: JOptionPane.QUESTION_MESSAGE,
097: null,
098: new String[] {
099: Resources
100: .getLocalString("delete"),
101: Resources
102: .getLocalString("cancel") },
103: Resources
104: .getLocalString("delete"));
105: } else if (selectionPaths.length == 1) {
106: answer = JOptionPane
107: .showOptionDialog(
108: ContelligentClient
109: .getActiveFrame(),
110: Resources
111: .getLocalString(
112: "delete_component_question",
113: new String[] { componentName }),
114: Resources
115: .getLocalString("comfirm_delete"),
116: JOptionPane.YES_NO_OPTION,
117: JOptionPane.QUESTION_MESSAGE,
118: null,
119: new String[] {
120: Resources
121: .getLocalString("delete"),
122: Resources
123: .getLocalString("cancel") },
124: Resources
125: .getLocalString("delete"));
126: } else {
127: answer = JOptionPane
128: .showOptionDialog(
129: ContelligentClient
130: .getActiveFrame(),
131: Resources
132: .getLocalString("delete_selected_components_question"),
133: Resources
134: .getLocalString("comfirm_delete"),
135: JOptionPane.YES_NO_OPTION,
136: JOptionPane.QUESTION_MESSAGE,
137: null,
138: new String[] {
139: Resources
140: .getLocalString("delete"),
141: Resources
142: .getLocalString("cancel") },
143: Resources
144: .getLocalString("delete"));
145: }
146: if (answer == JOptionPane.YES_OPTION) {
147: ContelligentComponent[] componentsToDelete = new ContelligentComponent[selectionPaths.length];
148: for (int i = 0; i < selectionPaths.length; i++) {
149: TreePath selectionPath = selectionPaths[i];
150: DefaultMutableTreeNode node = ((DefaultMutableTreeNode) selectionPath
151: .getLastPathComponent());
152: if (node.getUserObject() instanceof ComponentReference) {
153: componentsToDelete[i] = ((ComponentReference) node
154: .getUserObject())
155: .getComponent();
156: }
157: if (component
158: .equals(ExplorerEditor.componentToCopy)) {
159: ExplorerEditor.componentToCopy = null;
160: }
161: ComponentMovement
162: .nonBlockingDelete(
163: editor
164: .getView()
165: .getEnvironment(),
166: componentsToDelete[i],
167: false,
168: this .editor.pathSelectionManager);
169: }
170: }
171: }
172: }
173: }
174: }
175: } else {
176: setEnabled(false);
177: }
178: } catch (ComponentNotFoundException cnfe) {
179: ExceptionDialog.show(cnfe);
180: }
181: }
182: }
|