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.Dimension;
021: import java.awt.Rectangle;
022: import java.awt.Toolkit;
023: import java.awt.event.ActionEvent;
024:
025: import javax.swing.AbstractAction;
026: import javax.swing.JOptionPane;
027:
028: import de.finix.contelligent.client.ContelligentClient;
029: import de.finix.contelligent.client.base.ComponentFactory;
030: import de.finix.contelligent.client.base.ContelligentComponent;
031: import de.finix.contelligent.client.gui.ContelligentAction;
032: import de.finix.contelligent.client.gui.directory.ConvertTypeDialog;
033: import de.finix.contelligent.client.i18n.Resources;
034: import de.finix.contelligent.client.remote.ActionResult;
035: import de.finix.contelligent.client.remote.Actions;
036: import de.finix.contelligent.client.remote.RemoteActionException;
037: import de.finix.contelligent.client.util.ExceptionDialog;
038:
039: public class ConvertTypeAction extends AbstractAction implements
040: ContelligentAction {
041: /**
042: *
043: */
044: private final ExplorerEditor editor;
045:
046: public ConvertTypeAction(ExplorerEditor editor) {
047: super ("convert_blueprint", Resources.defaultViewIcon);
048: this .editor = editor;
049: putValue(ROLLOVER_ICON, Resources.defaultViewIcon);
050: putValue(TYPE, PUSH_ACTION);
051: putValue(ACTION_TYPE, EDIT_ACTION);
052: putValue(ACTION_GROUP, EDIT_BLUEPRINT_GROUP);
053: putValue(ACTION_POS, EDIT_BLUEPRINT_CONVERT);
054: putValue(MENU_TARGET, NO_MENU);
055: putValue(BUTTON_TARGET, NO_BUTTON);
056: putValue(POPUP_TARGET, POPUP_SUBMENU);
057: putValue(POPUP_PARENT_ACTION, this .editor.typeAction);
058: }
059:
060: public void actionPerformed(ActionEvent e) {
061: if (!this .editor.getView().isEditInProgress()) {
062: ConvertTypeDialog dialog = new ConvertTypeDialog(
063: ContelligentClient.getFrame(), null);
064: dialog.pack();
065: // center dialog...
066: Dimension screenDim = Toolkit.getDefaultToolkit()
067: .getScreenSize();
068: Rectangle winDim = dialog.getBounds();
069: dialog.setLocation((screenDim.width - winDim.width) / 2,
070: (screenDim.height - winDim.height) / 2);
071: // ...and show it
072: dialog.setVisible(true);
073: if (dialog.getOption() == JOptionPane.OK_OPTION) {
074: try {
075: ContelligentComponent component = this .editor
076: .getSelectedComponent();
077: ActionResult response = Actions
078: .changeBlueprintType(editor.getView()
079: .getEnvironment(), component
080: .getPath(), dialog.getType());
081: response.showErrors();
082: } catch (RemoteActionException rae) {
083: ExceptionDialog.show(rae);
084: }
085: }
086: }
087: }
088:
089: public void update() {
090: ContelligentComponent component = this .editor
091: .getSelectedComponent();
092: if (component != null) {
093: setEnabled(!this .editor.getView().isEditInProgress()
094: && component.getType().isBlueprint()
095: && !component.isBlueprint()
096: && ComponentFactory.getInstance().isRootContext());
097: } else {
098: setEnabled(false);
099: }
100: }
101: }
|