01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.gui.explorer;
19:
20: import java.awt.event.ActionEvent;
21:
22: import javax.swing.AbstractAction;
23: import javax.swing.Action;
24: import javax.swing.JOptionPane;
25: import javax.swing.tree.DefaultMutableTreeNode;
26:
27: import de.finix.contelligent.client.base.ComponentFactory;
28: import de.finix.contelligent.client.base.ComponentNotFoundException;
29: import de.finix.contelligent.client.base.ComponentReference;
30: import de.finix.contelligent.client.base.ContelligentComponent;
31: import de.finix.contelligent.client.base.Type;
32: import de.finix.contelligent.client.gui.ContelligentAction;
33: import de.finix.contelligent.client.i18n.Resources;
34: import de.finix.contelligent.client.util.ComponentMovement;
35: import de.finix.contelligent.client.util.ExceptionDialog;
36:
37: final public class UnlinkAction extends AbstractAction implements
38: ContelligentAction {
39: /**
40: *
41: */
42: private final ExplorerEditor editor;
43:
44: public UnlinkAction(ExplorerEditor editor) {
45: super ("unlink_action", Resources.unlinkIcon);
46: this .editor = editor;
47: putValue(Action.SHORT_DESCRIPTION, "unlink_action");
48: putValue(TYPE, PUSH_ACTION);
49: putValue(ACTION_TYPE, EDIT_ACTION);
50: putValue(ACTION_GROUP, EDIT_COPYPASTE_GROUP);
51: putValue(ACTION_POS, EDIT_COPYPASTE_UNLINK);
52: putValue(MENU_TARGET, MENU);
53: putValue(POPUP_TARGET, POPUP_MENU);
54: }
55:
56: public void actionPerformed(ActionEvent e) {
57: DefaultMutableTreeNode node = (DefaultMutableTreeNode) this .editor.tree
58: .getLastSelectedPathComponent();
59: if (node != null
60: && node.getUserObject() instanceof ComponentReference) {
61: try {
62: ContelligentComponent component = ((ComponentReference) node
63: .getUserObject()).getComponent();
64: // is link?
65: if (component.getType().getName().equals(Type.LINK)) {
66: if (JOptionPane.showOptionDialog(this .editor
67: .getParent(), Resources
68: .getLocalString("unlink_message"),
69: Resources.getLocalString("unlink_title"),
70: JOptionPane.YES_NO_OPTION,
71: JOptionPane.QUESTION_MESSAGE, null,
72: ExplorerEditor.YES_NO_OPTIONS,
73: ExplorerEditor.YES_NO_OPTIONS[0]) == JOptionPane.YES_OPTION) {
74: // force copy of linked component
75: ContelligentComponent linkedComponent = ComponentFactory
76: .getInstance()
77: .getComponent(
78: component.getPath(),
79: component
80: .getPropertyValue(ContelligentComponent.TARGET_PATH));
81: ComponentMovement.nonBlockingCopy(editor
82: .getView().getEnvironment(), editor
83: .getView().getEnvironment(),
84: linkedComponent, component
85: .getParentComponent(),
86: component.getName(), false, true, true);
87: }
88: }
89: } catch (ComponentNotFoundException cnfe) {
90: ExceptionDialog.show(cnfe);
91: }
92: }
93:
94: }
95: }
|