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 AddToBlueprintInstancesAction extends AbstractAction
041: implements ContelligentAction {
042: /**
043: *
044: */
045: private final ExplorerEditor editor;
046:
047: public AddToBlueprintInstancesAction(ExplorerEditor editor) {
048: super ("add_to_blueprint_instances_action",
049: Resources.addToBlueprintInstancesIcon);
050: this .editor = editor;
051: putValue(Action.SHORT_DESCRIPTION,
052: "add_to_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_ADDTOINST);
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: // putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control
062: // L"));
063: }
064:
065: public void actionPerformed(ActionEvent e) {
066: try {
067: if (!this .editor.getView().isEditInProgress()) {
068: final TreePath[] selectionPaths = this .editor.tree
069: .getSelectionPaths();
070: if (selectionPaths != null) {
071: if (selectionPaths.length > 0) {
072: if (JOptionPane
073: .showConfirmDialog(
074: ContelligentClient.getFrame(),
075: Resources
076: .getLocalString("add_to_instances_question"),
077: Resources
078: .getLocalString("add_to_instances_title"),
079: JOptionPane.OK_CANCEL_OPTION,
080: JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
081: DefaultMutableTreeNode firstNode = ((DefaultMutableTreeNode) selectionPaths[0]
082: .getLastPathComponent());
083: if (firstNode != null
084: && firstNode.getUserObject() instanceof ComponentReference) {
085: ContelligentComponent component = ((ComponentReference) firstNode
086: .getUserObject())
087: .getComponent();
088: try {
089: ActionResult response = Actions
090: .addToAllBlueprintInstances(
091: editor
092: .getView()
093: .getEnvironment(),
094: component.getPath());
095: response.showErrors();
096: } catch (RemoteActionException rae) {
097: ExceptionDialog.show(rae);
098: }
099: }
100: }
101: }
102: }
103: } else {
104: setEnabled(false);
105: }
106: } catch (ComponentNotFoundException cnfe) {
107: ExceptionDialog.show(cnfe);
108: }
109: }
110:
111: public void update() {
112: ContelligentComponent component = this.editor
113: .getSelectedComponent();
114: setEnabled(component != null
115: && component.isBlueprintSubComponent()
116: && !this.editor.getView().isEditInProgress()
117: && this.editor.getView().getAllowBlueprintDefinition()
118: && ComponentFactory.getInstance().isRootContext());
119: }
120: }
|