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.tree.DefaultMutableTreeNode;
024:
025: import de.finix.contelligent.client.base.ComponentFactory;
026: import de.finix.contelligent.client.base.ComponentNotFoundException;
027: import de.finix.contelligent.client.base.ComponentPath;
028: import de.finix.contelligent.client.base.ComponentReference;
029: import de.finix.contelligent.client.base.ContelligentComponent;
030: import de.finix.contelligent.client.base.ContelligentConstants;
031: import de.finix.contelligent.client.base.PackageManager;
032: import de.finix.contelligent.client.base.PackageNotFoundException;
033: import de.finix.contelligent.client.base.Type;
034: import de.finix.contelligent.client.gui.ContelligentAction;
035: import de.finix.contelligent.client.i18n.Resources;
036: import de.finix.contelligent.client.remote.ActionResult;
037: import de.finix.contelligent.client.remote.Actions;
038: import de.finix.contelligent.client.remote.RemoteActionException;
039: import de.finix.contelligent.client.util.ExceptionDialog;
040: import de.finix.contelligent.client.wizard.TypeWizard;
041:
042: public class CreateTypeAction extends AbstractAction implements
043: ContelligentAction {
044: /**
045: *
046: */
047: private final ExplorerEditor editor;
048:
049: public CreateTypeAction(ExplorerEditor editor) {
050: super ("create_blueprint", Resources.defaultViewIcon);
051: this .editor = editor;
052: putValue(ROLLOVER_ICON, Resources.defaultViewIcon);
053: putValue(TYPE, PUSH_ACTION);
054: putValue(ACTION_TYPE, EDIT_ACTION);
055: putValue(ACTION_GROUP, EDIT_BLUEPRINT_GROUP);
056: putValue(ACTION_POS, EDIT_BLUEPRINT_CREATE);
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:
063: public void createType() {
064: DefaultMutableTreeNode node = (DefaultMutableTreeNode) this .editor.tree
065: .getLastSelectedPathComponent();
066: // create new component on selected node
067: if (node != null
068: && node.getUserObject() instanceof ComponentReference
069: && this .editor.guiContainer != null
070: && !this .editor.getView().isEditInProgress()) {
071: try {
072: // remote add on server
073: ContelligentComponent component = ((ComponentReference) node
074: .getUserObject()).getComponent();
075: TypeWizard wizard = new TypeWizard(component, "create",
076: editor.getView().getEnvironment());
077: final Type type = wizard.startWizard();
078: final String packageName = wizard.getPackageName();
079:
080: if (type != null) {
081: // XXX this is not too nice
082: String xml = ContelligentConstants.XML_HEADER
083: + "<!DOCTYPE type-list PUBLIC \"-//finix AG/contelligent/Type List V1.0/EN\" \"http://www.c1-fse.de/contelligent/dtds/type-list_1_0.dtd\">\n<type-list>\n"
084: + type.toXML() + "\n</type-list>";
085: ActionResult result = Actions.createType(editor
086: .getView().getEnvironment(), packageName,
087: type.getName(), xml);
088: result.showErrors();
089: }
090: } catch (RemoteActionException e) {
091: ExceptionDialog.show(e);
092: } catch (ComponentNotFoundException cnfe) {
093: ExceptionDialog.show(cnfe);
094: } catch (PackageNotFoundException pnfe) {
095: ExceptionDialog.show(pnfe);
096: }
097: }
098: }
099:
100: public void actionPerformed(ActionEvent e) {
101: createType();
102: }
103:
104: public void update() {
105: ContelligentComponent component = this .editor
106: .getSelectedComponent();
107: boolean canDefine = component != null
108: && !component.isBlueprint()
109: && !component.isBlueprintInstance()
110: && !component.isBlueprintInstanceSubComponent()
111: && !component.isBlueprintSubComponent()
112: && !this .editor.getView().isEditInProgress()
113: && this .editor.getView().getAllowBlueprintDefinition()
114: && ComponentFactory.getInstance().isRootContext();
115: try {
116: if (component != null) {
117: String cp = component.getPath();
118: PackageManager.Package pkg = PackageManager
119: .getInstance().getPackage(cp);
120: if (pkg.isReadOnly()) {
121: canDefine = false;
122: } else {
123: if (cp.equals(ComponentPath.toComponentPath(pkg
124: .getPath()))) {
125: // The base component of a package may not be a
126: // blueprint
127: canDefine = false;
128: }
129: }
130: } else {
131: canDefine = false;
132: }
133: } catch (PackageNotFoundException pne) {
134: // No package here; cant define a blueprint then
135: canDefine = false;
136: }
137:
138: setEnabled(canDefine);
139: }
140: }
|