0001: /*
0002: * Copyright 2001-2006 C:1 Financial Services GmbH
0003: *
0004: * This software is free software; you can redistribute it and/or
0005: * modify it under the terms of the GNU Lesser General Public
0006: * License Version 2.1, as published by the Free Software Foundation.
0007: *
0008: * This software is distributed in the hope that it will be useful,
0009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0011: * Lesser General Public License for more details.
0012: *
0013: * You should have received a copy of the GNU Lesser General Public
0014: * License along with this library; if not, write to the Free Software
0015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
0016: */
0017:
0018: package de.finix.contelligent.client.util;
0019:
0020: import java.awt.event.ActionEvent;
0021: import java.lang.reflect.InvocationTargetException;
0022: import java.util.Collections;
0023: import java.util.LinkedList;
0024: import java.util.List;
0025: import java.util.logging.Level;
0026: import java.util.logging.Logger;
0027:
0028: import javax.swing.AbstractAction;
0029: import javax.swing.Action;
0030: import javax.swing.JOptionPane;
0031: import javax.swing.SwingUtilities;
0032:
0033: import de.finix.contelligent.client.ContelligentClient;
0034: import de.finix.contelligent.client.base.ComponentFactory;
0035: import de.finix.contelligent.client.base.ContelligentComponent;
0036: import de.finix.contelligent.client.base.Errors;
0037: import de.finix.contelligent.client.base.Session;
0038: import de.finix.contelligent.client.event.ContelligentComponentDisplayEvent;
0039: import de.finix.contelligent.client.event.TaskFinishedEvent;
0040: import de.finix.contelligent.client.event.TaskStartedEvent;
0041: import de.finix.contelligent.client.gui.ContelligentAction;
0042: import de.finix.contelligent.client.gui.PathSelectionManager;
0043: import de.finix.contelligent.client.i18n.Resources;
0044: import de.finix.contelligent.client.remote.ActionResult;
0045: import de.finix.contelligent.client.remote.Actions;
0046: import de.finix.contelligent.client.remote.RemoteActionException;
0047:
0048: public final class ComponentMovement implements Runnable {
0049:
0050: private final static Logger logger = Logger
0051: .getLogger(ComponentMovement.class.getName());
0052:
0053: private final static int DOPTION_YES = 0;
0054:
0055: private final static int DOPTION_YESALL = 1;
0056:
0057: private final static int DOPTION_NO = 2;
0058:
0059: private final static int DOPTION_CANCEL = 3;
0060:
0061: private final static Object[] YES_CANCEL_OPTIONS = {
0062: Resources.getLocalString("yes"),
0063: Resources.getLocalString("cancel") };
0064:
0065: private final static Object[] YES_YESALL_NO_CANCEL_OPTIONS = {
0066: Resources.getLocalString("yes"),
0067: Resources.getLocalString("yes_all"),
0068: Resources.getLocalString("no"),
0069: Resources.getLocalString("cancel") };
0070:
0071: private final static ComponentMovement movement = new ComponentMovement();
0072:
0073: private static Thread actionThread;
0074:
0075: private static List<Runnable> actionQueue = Collections
0076: .synchronizedList(new LinkedList<Runnable>());
0077:
0078: static {
0079: actionThread = new Thread(movement);
0080: actionThread.start();
0081: }
0082:
0083: public void run() {
0084: while (true) {
0085: while (actionQueue.size() > 0) {
0086: Runnable queuedAction = (Runnable) actionQueue.get(0);
0087: queuedAction.run();
0088: actionQueue.remove(0);
0089: }
0090: try {
0091: Thread.sleep(1000);
0092: } catch (InterruptedException e) {
0093: logger.log(Level.WARNING, "Action queue interrupted!",
0094: e);
0095: }
0096: }
0097: }
0098:
0099: public static void execute(Runnable runnable) {
0100: actionQueue.add(runnable);
0101: }
0102:
0103: public static void nonBlockingCopy(String environment,
0104: String sourceEnvironment,
0105: ContelligentComponent sourceComponent,
0106: ContelligentComponent targetComponent, String name,
0107: boolean createLink, boolean overwrite) {
0108: execute(new CopyAction(environment, sourceEnvironment,
0109: sourceComponent, targetComponent, name, createLink,
0110: overwrite));
0111: }
0112:
0113: public static void nonBlockingCopy(String environment,
0114: String sourceEnvironment,
0115: ContelligentComponent sourceComponent,
0116: ContelligentComponent targetComponent, String name,
0117: boolean createLink, boolean overwrite,
0118: boolean overrideFinals) {
0119: execute(new CopyAction(environment, sourceEnvironment,
0120: sourceComponent, targetComponent, name, createLink,
0121: overwrite, overrideFinals));
0122: }
0123:
0124: public static void nonBlockingCopy(String environment,
0125: String sourceEnvironment,
0126: ContelligentComponent sourceComponent,
0127: ContelligentComponent targetComponent, String name,
0128: boolean createLink, boolean overwrite,
0129: boolean overrideFinals, boolean cloningCopy) {
0130: execute(new CopyAction(environment, sourceEnvironment,
0131: sourceComponent, targetComponent, name, createLink,
0132: overwrite, overrideFinals, cloningCopy));
0133: }
0134:
0135: public static void nonBlockingMove(String environment,
0136: String sourceEnvironment,
0137: ContelligentComponent sourceComponent,
0138: ContelligentComponent targetComponent, String name,
0139: boolean overwrite, boolean forceMove,
0140: PathSelectionManager pathSelectionManager) {
0141: execute(new MoveAction(environment, sourceEnvironment,
0142: sourceComponent, targetComponent, name, overwrite,
0143: forceMove, pathSelectionManager));
0144: }
0145:
0146: public static void nonBlockingCopy(String environment,
0147: String sourceEnvironment,
0148: ContelligentComponent sourceComponents[],
0149: ContelligentComponent targetComponent, boolean createLink,
0150: boolean overwrite) {
0151: execute(new MultiCopyAction(environment, sourceEnvironment,
0152: sourceComponents, targetComponent, createLink,
0153: overwrite));
0154: }
0155:
0156: public static void nonBlockingMove(String environment,
0157: String sourceEnvironment,
0158: ContelligentComponent sourceComponents[],
0159: ContelligentComponent targetComponent, boolean overwrite,
0160: boolean forceMove, PathSelectionManager pathSelectionManager) {
0161: execute(new MultiMoveAction(environment, sourceEnvironment,
0162: sourceComponents, targetComponent, overwrite,
0163: forceMove, pathSelectionManager));
0164: }
0165:
0166: public static void nonBlockingDelete(String environment,
0167: ContelligentComponent component, boolean forceDelete,
0168: PathSelectionManager pathSelectionManager) {
0169: execute(new DeleteAction(environment, component, forceDelete,
0170: pathSelectionManager));
0171: }
0172:
0173: static class CopyAction extends AbstractAction implements
0174: ContelligentAction, Runnable {
0175: private ContelligentComponent sourceComponent, targetComponent;
0176:
0177: private String name, environment, sourceEnvironment;
0178:
0179: private boolean overwrite, createLink, overrideFinals,
0180: cloningCopy;
0181:
0182: public CopyAction(String environment, String sourceEnvironment,
0183: ContelligentComponent sourceComponent,
0184: ContelligentComponent targetComponent, String name,
0185: boolean createLink, boolean overwrite) {
0186: this (environment, sourceEnvironment, sourceComponent,
0187: targetComponent, name, createLink, overwrite,
0188: false, false);
0189: }
0190:
0191: public CopyAction(String environment, String sourceEnvironment,
0192: ContelligentComponent sourceComponent,
0193: ContelligentComponent targetComponent, String name,
0194: boolean createLink, boolean overwrite,
0195: boolean overrideFinals) {
0196: this (environment, sourceEnvironment, sourceComponent,
0197: targetComponent, name, createLink, overwrite,
0198: overrideFinals, false);
0199: }
0200:
0201: public CopyAction(String environment, String sourceEnvironment,
0202: ContelligentComponent sourceComponent,
0203: ContelligentComponent targetComponent, String name,
0204: boolean createLink, boolean overwrite,
0205: boolean overrideFinals, boolean cloningCopy) {
0206: super ("copy_action", Resources.deleteComponentIcon);
0207: putValue(ROLLOVER_ICON,
0208: Resources.deleteComponentIconRollOver);
0209: putValue(TYPE, PUSH_ACTION);
0210: putValue(ACTION_TYPE, EDIT_ACTION);
0211: putValue(MENU_TARGET, NO_MENU);
0212: putValue(BUTTON_TARGET, NO_BUTTON);
0213: putValue(POPUP_TARGET, NO_POPUP);
0214: this .sourceComponent = sourceComponent;
0215: this .targetComponent = targetComponent;
0216: this .name = name;
0217: this .overwrite = overwrite;
0218: this .createLink = createLink;
0219: this .overrideFinals = overrideFinals;
0220: this .cloningCopy = cloningCopy;
0221: this .environment = environment;
0222: this .sourceEnvironment = sourceEnvironment;
0223: }
0224:
0225: public void run() {
0226: logger.log(Level.FINE, "Trying to copy '"
0227: + sourceComponent.getPath() + "' to '"
0228: + targetComponent.getPath() + "' with name '"
0229: + name + "'");
0230: Session.getInstance().fireTaskStartEvent(
0231: new TaskStartedEvent(sourceComponent, Resources
0232: .getLocalString("copy")));
0233: ComponentFactory
0234: .getInstance()
0235: .fireComponentAddInProgressEvent(
0236: new ContelligentComponentDisplayEvent(
0237: sourceComponent,
0238: targetComponent.getPath() + "/"
0239: + name,
0240: ContelligentComponentDisplayEvent.COMPONENT_ADD_IN_PROGRESS));
0241: try {
0242: ActionResult response = Actions.copy(environment,
0243: sourceEnvironment, sourceComponent,
0244: targetComponent, name, createLink, overwrite,
0245: overrideFinals, cloningCopy);
0246: Session.getInstance().fireTaskFinishEvent(
0247: new TaskFinishedEvent(sourceComponent));
0248: if (!overwrite
0249: && response.hasError(Errors.COMPONENT_EXISTS)) {
0250: if (JOptionPane.showOptionDialog(ContelligentClient
0251: .getActiveFrame(), Resources
0252: .getLocalString(
0253: "target_component_exists_override",
0254: new String[] { name }), Resources
0255: .getLocalString("component_exists"),
0256: JOptionPane.YES_NO_OPTION,
0257: JOptionPane.WARNING_MESSAGE, null,
0258: YES_CANCEL_OPTIONS, YES_CANCEL_OPTIONS[0]) != JOptionPane.YES_OPTION) {
0259: ComponentFactory
0260: .getInstance()
0261: .fireComponentAddAbortedEvent(
0262: new ContelligentComponentDisplayEvent(
0263: sourceComponent,
0264: targetComponent
0265: .getPath()
0266: + "/" + name,
0267: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0268: return;
0269: }
0270: execute(new CopyAction(environment,
0271: sourceEnvironment, sourceComponent,
0272: targetComponent, name, createLink, true,
0273: overrideFinals, cloningCopy));
0274: } else if (!response.getState().equals(ActionResult.OK)) {
0275: response.showErrors();
0276: ComponentFactory
0277: .getInstance()
0278: .fireComponentAddAbortedEvent(
0279: new ContelligentComponentDisplayEvent(
0280: sourceComponent,
0281: targetComponent.getPath()
0282: + "/" + name,
0283: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0284: }
0285: } catch (RemoteActionException rae) {
0286: ExceptionDialog.show(rae);
0287: ComponentFactory
0288: .getInstance()
0289: .fireComponentAddAbortedEvent(
0290: new ContelligentComponentDisplayEvent(
0291: sourceComponent,
0292: targetComponent.getPath() + "/"
0293: + name,
0294: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0295: }
0296: }
0297:
0298: public void actionPerformed(ActionEvent e) {
0299: execute(this );
0300: }
0301: }
0302:
0303: static class MultiCopyAction extends AbstractAction implements
0304: ContelligentAction, Runnable {
0305: private ContelligentComponent[] sourceComponents;
0306:
0307: private ContelligentComponent targetComponent;
0308:
0309: private String environment, sourceEnvironment;
0310:
0311: private boolean overwrite, createLink;
0312:
0313: public MultiCopyAction(String environment,
0314: String sourceEnvironment,
0315: ContelligentComponent[] sourceComponents,
0316: ContelligentComponent targetComponent,
0317: boolean createLink, boolean overwrite) {
0318: super ("copy_action", Resources.deleteComponentIcon);
0319: putValue(ROLLOVER_ICON,
0320: Resources.deleteComponentIconRollOver);
0321: putValue(TYPE, PUSH_ACTION);
0322: putValue(ACTION_TYPE, EDIT_ACTION);
0323: putValue(MENU_TARGET, NO_MENU);
0324: putValue(BUTTON_TARGET, NO_BUTTON);
0325: putValue(POPUP_TARGET, NO_POPUP);
0326: this .sourceComponents = sourceComponents;
0327: this .targetComponent = targetComponent;
0328: this .overwrite = overwrite;
0329: this .createLink = createLink;
0330: this .environment = environment;
0331: this .sourceEnvironment = sourceEnvironment;
0332: }
0333:
0334: public void run() {
0335: logger.log(Level.FINE,
0336: "Trying to copy multiple components to '"
0337: + targetComponent.getPath());
0338:
0339: for (int a = 0; a < sourceComponents.length; a++) {
0340: Session.getInstance().fireTaskStartEvent(
0341: new TaskStartedEvent(sourceComponents[a],
0342: Resources.getLocalString("copy")));
0343: ComponentFactory
0344: .getInstance()
0345: .fireComponentAddInProgressEvent(
0346: new ContelligentComponentDisplayEvent(
0347: sourceComponents[a],
0348: targetComponent.getPath()
0349: + "/"
0350: + sourceComponents[a]
0351: .getName(),
0352: ContelligentComponentDisplayEvent.COMPONENT_ADD_IN_PROGRESS));
0353: try {
0354: ActionResult response = Actions.copy(environment,
0355: sourceEnvironment, sourceComponents[a],
0356: targetComponent, sourceComponents[a]
0357: .getName(), createLink, overwrite);
0358: Session.getInstance().fireTaskFinishEvent(
0359: new TaskFinishedEvent(sourceComponents[a]));
0360: if (!overwrite
0361: && response
0362: .hasError(Errors.COMPONENT_EXISTS)) {
0363: try {
0364: final ContelligentComponent cComponent = sourceComponents[a];
0365: final ResultHolder optionResult = new ResultHolder(
0366: ResultHolder.RESULT_INTEGER);
0367: SwingUtilities
0368: .invokeAndWait(new Runnable() {
0369: public void run() {
0370: optionResult
0371: .setIntResult(JOptionPane
0372: .showOptionDialog(
0373: ContelligentClient
0374: .getActiveFrame(),
0375: Resources
0376: .getLocalString(
0377: "target_component_exists_override",
0378: new String[] { cComponent
0379: .getName() }),
0380: Resources
0381: .getLocalString("component_exists"),
0382: JOptionPane.YES_NO_OPTION,
0383: JOptionPane.WARNING_MESSAGE,
0384: null,
0385: YES_YESALL_NO_CANCEL_OPTIONS,
0386: YES_YESALL_NO_CANCEL_OPTIONS[0]));
0387: // if ( optionResult.getIntResult() == 2) {
0388: // ComponentFactory.getInstance().fireComponentAddAbortedEvent(new
0389: // ContelligentComponentDisplayEvent(cComponent,
0390: // targetComponent.getPath() + "/" +
0391: // cComponent.getName(),
0392: // ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0393: // return;
0394: // }
0395: }
0396: });
0397:
0398: if (optionResult.getIntResult() == DOPTION_CANCEL) {
0399: ComponentFactory
0400: .getInstance()
0401: .fireComponentAddAbortedEvent(
0402: new ContelligentComponentDisplayEvent(
0403: sourceComponents[a],
0404: targetComponent
0405: .getPath()
0406: + "/"
0407: + sourceComponents[a]
0408: .getName(),
0409: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0410: return;
0411: } else if (optionResult.getIntResult() == DOPTION_YES) {
0412: // if YES
0413: // ComponentFactory.getInstance().fireComponentAddAbortedEvent(new
0414: // ContelligentComponentDisplayEvent(sourceComponents[a],
0415: // targetComponent.getPath() + "/" +
0416: // sourceComponents[a].getName(),
0417: // ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0418: execute(new CopyAction(environment,
0419: sourceEnvironment,
0420: sourceComponents[a],
0421: targetComponent,
0422: sourceComponents[a].getName(),
0423: createLink, true));
0424: } else if (optionResult.getIntResult() == DOPTION_YESALL) {
0425: // if YES to All
0426: // ComponentFactory.getInstance().fireComponentAddAbortedEvent(new
0427: // ContelligentComponentDisplayEvent(sourceComponents[a],
0428: // targetComponent.getPath() + "/" +
0429: // sourceComponents[a].getName(),
0430: // ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0431: ContelligentComponent[] restSources = new ContelligentComponent[sourceComponents.length
0432: - a];
0433: System.arraycopy(sourceComponents, a,
0434: restSources, 0,
0435: sourceComponents.length - a);
0436: execute(new MultiCopyAction(
0437: environment, sourceEnvironment,
0438: restSources, targetComponent,
0439: createLink, true));
0440: // return here, because the rest is done by the
0441: // execute above
0442: return;
0443: } else if (optionResult.getIntResult() == DOPTION_NO) {
0444: // if NO
0445: ComponentFactory
0446: .getInstance()
0447: .fireComponentAddAbortedEvent(
0448: new ContelligentComponentDisplayEvent(
0449: sourceComponents[a],
0450: targetComponent
0451: .getPath()
0452: + "/"
0453: + sourceComponents[a]
0454: .getName(),
0455: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0456: // do not return here .. go on with the next
0457: }
0458: } catch (InterruptedException ie) {
0459: logger.log(Level.WARNING,
0460: "Interrupted while showing error",
0461: ie);
0462: return;
0463: } catch (InvocationTargetException ite) {
0464: logger.log(Level.WARNING,
0465: "Could not show error", ite);
0466: return;
0467: }
0468: } else if (!response.getState().equals(
0469: ActionResult.OK)) {
0470: response.showErrors();
0471: ComponentFactory
0472: .getInstance()
0473: .fireComponentAddAbortedEvent(
0474: new ContelligentComponentDisplayEvent(
0475: sourceComponents[a],
0476: targetComponent
0477: .getPath()
0478: + "/"
0479: + sourceComponents[a]
0480: .getName(),
0481: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0482: return;
0483: }
0484: } catch (RemoteActionException rae) {
0485: ExceptionDialog.show(rae);
0486: ComponentFactory
0487: .getInstance()
0488: .fireComponentAddAbortedEvent(
0489: new ContelligentComponentDisplayEvent(
0490: sourceComponents[a],
0491: targetComponent.getPath()
0492: + "/"
0493: + sourceComponents[a]
0494: .getName(),
0495: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0496: return;
0497: }
0498: }
0499: }
0500:
0501: public void actionPerformed(ActionEvent e) {
0502: execute(this );
0503: }
0504: }
0505:
0506: public static class DeleteAction extends AbstractAction implements
0507: ContelligentAction, Runnable {
0508: private ContelligentComponent component;
0509:
0510: private String environment;
0511:
0512: private boolean forceDelete;
0513:
0514: private PathSelectionManager pathSelectionManager;
0515:
0516: public DeleteAction(String environment,
0517: ContelligentComponent component, boolean forceMove,
0518: PathSelectionManager pathSelectionManager) {
0519: super ("delete_action", Resources.deleteComponentIcon);
0520: putValue(ROLLOVER_ICON,
0521: Resources.deleteComponentIconRollOver);
0522: putValue(TYPE, PUSH_ACTION);
0523: putValue(ACTION_TYPE, EDIT_ACTION);
0524: putValue(MENU_TARGET, NO_MENU);
0525: putValue(BUTTON_TARGET, NO_BUTTON);
0526: putValue(POPUP_TARGET, NO_POPUP);
0527: this .component = component;
0528: this .forceDelete = forceMove;
0529: this .pathSelectionManager = pathSelectionManager;
0530: this .environment = environment;
0531: }
0532:
0533: public void run() {
0534: logger.log(Level.FINE, "Trying to delete '"
0535: + component.getPath() + "'");
0536:
0537: Session.getInstance().fireTaskStartEvent(
0538: new TaskStartedEvent(component, Resources
0539: .getLocalString("delete")));
0540: ComponentFactory
0541: .getInstance()
0542: .fireComponentRemoveInProgressEvent(
0543: new ContelligentComponentDisplayEvent(
0544: component,
0545: component.getPath(),
0546: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_IN_PROGRESS));
0547: try {
0548: try {
0549: final ActionResult response = Actions.delete(
0550: environment, component, forceDelete);
0551: SwingUtilities.invokeAndWait(new Runnable() {
0552: public void run() {
0553: Session.getInstance().fireTaskFinishEvent(
0554: new TaskFinishedEvent(component));
0555: if (!forceDelete
0556: && response
0557: .hasError(Errors.RELATION_EXITS)) {
0558: pathSelectionManager
0559: .setPaths(
0560: Resources
0561: .getLocalString("links_exists_delete"),
0562: response.getPaths(),
0563: new Action[] { new DeleteAction(
0564: environment,
0565: component,
0566: true,
0567: pathSelectionManager) });
0568: pathSelectionManager.showPaths();
0569: ComponentFactory
0570: .getInstance()
0571: .fireComponentRemoveAbortedEvent(
0572: new ContelligentComponentDisplayEvent(
0573: component,
0574: component
0575: .getPath(),
0576: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_ABORTED));
0577: } else if (!response.getState().equals(
0578: ActionResult.OK)) {
0579: response.showErrors();
0580: ComponentFactory
0581: .getInstance()
0582: .fireComponentRemoveAbortedEvent(
0583: new ContelligentComponentDisplayEvent(
0584: component,
0585: component
0586: .getPath(),
0587: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_ABORTED));
0588: }
0589: }
0590: });
0591: } catch (RemoteActionException rae) {
0592: ExceptionDialog.show(rae);
0593: ComponentFactory
0594: .getInstance()
0595: .fireComponentRemoveAbortedEvent(
0596: new ContelligentComponentDisplayEvent(
0597: component,
0598: component.getPath(),
0599: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_ABORTED));
0600: }
0601: } catch (InterruptedException e) {
0602: logger.log(Level.SEVERE, "Delete interrupted!", e);
0603: } catch (InvocationTargetException e) {
0604: logger
0605: .log(Level.SEVERE, "Delete invokation failed!",
0606: e);
0607: }
0608: }
0609:
0610: public void actionPerformed(ActionEvent e) {
0611: pathSelectionManager.hidePaths();
0612: execute(this );
0613: }
0614: }
0615:
0616: public static class MoveAction extends AbstractAction implements
0617: ContelligentAction, Runnable {
0618: private ContelligentComponent sourceComponent, targetComponent;
0619:
0620: private String name, environment, sourceEnvironment;
0621:
0622: private boolean overwrite, forceMove;
0623:
0624: private PathSelectionManager pathSelectionManager;
0625:
0626: public MoveAction(String environment, String sourceEnvironment,
0627: ContelligentComponent sourceComponent,
0628: ContelligentComponent targetComponent, String name,
0629: boolean overwrite, boolean forceMove,
0630: PathSelectionManager pathSelectionManager) {
0631: super ("move_action", Resources.deleteComponentIcon);
0632: putValue(ROLLOVER_ICON,
0633: Resources.deleteComponentIconRollOver);
0634: putValue(TYPE, PUSH_ACTION);
0635: putValue(ACTION_TYPE, EDIT_ACTION);
0636: putValue(MENU_TARGET, NO_MENU);
0637: putValue(BUTTON_TARGET, NO_BUTTON);
0638: putValue(POPUP_TARGET, NO_POPUP);
0639: this .sourceComponent = sourceComponent;
0640: this .targetComponent = targetComponent;
0641: this .name = name;
0642: this .overwrite = overwrite;
0643: this .forceMove = forceMove;
0644: this .pathSelectionManager = pathSelectionManager;
0645: this .environment = environment;
0646: this .sourceEnvironment = sourceEnvironment;
0647: }
0648:
0649: public void run() {
0650: if (targetComponent != null) {
0651: logger.log(Level.FINE, "Trying to move '"
0652: + sourceComponent.getPath() + "' to '"
0653: + targetComponent.getPath() + "' with name '"
0654: + name + "'");
0655: } else {
0656: logger.log(Level.FINE, "Trying to rename '"
0657: + sourceComponent.getPath() + "' to '" + name
0658: + "'");
0659: }
0660:
0661: Session.getInstance().fireTaskStartEvent(
0662: new TaskStartedEvent(sourceComponent, Resources
0663: .getLocalString("move")));
0664:
0665: if (targetComponent != null) {
0666: ComponentFactory
0667: .getInstance()
0668: .fireComponentAddInProgressEvent(
0669: new ContelligentComponentDisplayEvent(
0670: sourceComponent,
0671: targetComponent.getPath() + "/"
0672: + name,
0673: ContelligentComponentDisplayEvent.COMPONENT_ADD_IN_PROGRESS));
0674: } else {
0675: ComponentFactory
0676: .getInstance()
0677: .fireComponentAddInProgressEvent(
0678: new ContelligentComponentDisplayEvent(
0679: sourceComponent,
0680: sourceComponent.getPath() + "/"
0681: + name,
0682: ContelligentComponentDisplayEvent.COMPONENT_ADD_IN_PROGRESS));
0683: }
0684: ComponentFactory
0685: .getInstance()
0686: .fireComponentRemoveInProgressEvent(
0687: new ContelligentComponentDisplayEvent(
0688: sourceComponent,
0689: sourceComponent.getPath(),
0690: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_IN_PROGRESS));
0691: try {
0692: ActionResult response = Actions.move(environment,
0693: sourceEnvironment, sourceComponent,
0694: targetComponent, name, overwrite, forceMove);
0695: Session.getInstance().fireTaskFinishEvent(
0696: new TaskFinishedEvent(sourceComponent));
0697: if (!forceMove
0698: && response.hasError(Errors.RELATION_EXITS)) {
0699: pathSelectionManager.setPaths(Resources
0700: .getLocalString("links_exists_move"),
0701: response.getPaths(),
0702: new Action[] { new MoveAction(environment,
0703: sourceEnvironment, sourceComponent,
0704: targetComponent, name, false, true,
0705: pathSelectionManager) });
0706: pathSelectionManager.showPaths();
0707: } else if (!overwrite
0708: && response.hasError(Errors.COMPONENT_EXISTS)) {
0709: if (JOptionPane.showOptionDialog(ContelligentClient
0710: .getActiveFrame(), Resources
0711: .getLocalString(
0712: "target_component_exists_override",
0713: new String[] { name }), Resources
0714: .getLocalString("component_exists"),
0715: JOptionPane.YES_NO_OPTION,
0716: JOptionPane.WARNING_MESSAGE, null,
0717: YES_CANCEL_OPTIONS, YES_CANCEL_OPTIONS[0]) != JOptionPane.YES_OPTION) {
0718: ComponentFactory
0719: .getInstance()
0720: .fireComponentRemoveAbortedEvent(
0721: new ContelligentComponentDisplayEvent(
0722: sourceComponent,
0723: sourceComponent
0724: .getPath(),
0725: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_ABORTED));
0726: if (targetComponent != null) {
0727: ComponentFactory
0728: .getInstance()
0729: .fireComponentAddAbortedEvent(
0730: new ContelligentComponentDisplayEvent(
0731: sourceComponent,
0732: targetComponent
0733: .getPath()
0734: + "/"
0735: + name,
0736: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0737: } else {
0738: ComponentFactory
0739: .getInstance()
0740: .fireComponentAddAbortedEvent(
0741: new ContelligentComponentDisplayEvent(
0742: sourceComponent,
0743: sourceComponent
0744: .getPath()
0745: + "/"
0746: + name,
0747: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0748: }
0749: return;
0750: }
0751: execute(new MoveAction(environment,
0752: sourceEnvironment, sourceComponent,
0753: targetComponent, name, true, true,
0754: pathSelectionManager));
0755: } else if (response.hasError()) {
0756: response.showErrors();
0757: ComponentFactory
0758: .getInstance()
0759: .fireComponentRemoveAbortedEvent(
0760: new ContelligentComponentDisplayEvent(
0761: sourceComponent,
0762: sourceComponent.getPath(),
0763: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_ABORTED));
0764: if (targetComponent != null) {
0765: ComponentFactory
0766: .getInstance()
0767: .fireComponentAddAbortedEvent(
0768: new ContelligentComponentDisplayEvent(
0769: sourceComponent,
0770: targetComponent
0771: .getPath()
0772: + "/" + name,
0773: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0774: } else {
0775: ComponentFactory
0776: .getInstance()
0777: .fireComponentAddAbortedEvent(
0778: new ContelligentComponentDisplayEvent(
0779: sourceComponent,
0780: sourceComponent
0781: .getPath()
0782: + "/" + name,
0783: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0784: }
0785: } else {
0786: response.showErrors();
0787:
0788: }
0789: } catch (RemoteActionException rae) {
0790: ExceptionDialog.show(rae);
0791: ComponentFactory
0792: .getInstance()
0793: .fireComponentRemoveAbortedEvent(
0794: new ContelligentComponentDisplayEvent(
0795: sourceComponent,
0796: sourceComponent.getPath(),
0797: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_ABORTED));
0798: if (targetComponent != null) {
0799: ComponentFactory
0800: .getInstance()
0801: .fireComponentAddAbortedEvent(
0802: new ContelligentComponentDisplayEvent(
0803: sourceComponent,
0804: targetComponent.getPath()
0805: + "/" + name,
0806: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0807: } else {
0808: ComponentFactory
0809: .getInstance()
0810: .fireComponentAddAbortedEvent(
0811: new ContelligentComponentDisplayEvent(
0812: sourceComponent,
0813: sourceComponent.getPath()
0814: + "/" + name,
0815: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0816: }
0817: }
0818: }
0819:
0820: public void actionPerformed(ActionEvent e) {
0821: pathSelectionManager.hidePaths();
0822: execute(this );
0823: }
0824: }
0825:
0826: public static class MultiMoveAction extends AbstractAction
0827: implements ContelligentAction, Runnable {
0828: private ContelligentComponent[] sourceComponents;
0829:
0830: private ContelligentComponent targetComponent;
0831:
0832: private String name, environment, sourceEnvironment;
0833:
0834: private boolean overwrite, forceFirstMove;
0835:
0836: private PathSelectionManager pathSelectionManager;
0837:
0838: public MultiMoveAction(String environment,
0839: String sourceEnvironment,
0840: ContelligentComponent[] sourceComponents,
0841: ContelligentComponent targetComponent,
0842: boolean overwrite, boolean forceMove,
0843: PathSelectionManager pathSelectionManager) {
0844: super ("move_action", Resources.deleteComponentIcon);
0845: putValue(ROLLOVER_ICON,
0846: Resources.deleteComponentIconRollOver);
0847: putValue(TYPE, PUSH_ACTION);
0848: putValue(ACTION_TYPE, EDIT_ACTION);
0849: putValue(MENU_TARGET, NO_MENU);
0850: putValue(BUTTON_TARGET, NO_BUTTON);
0851: putValue(POPUP_TARGET, NO_POPUP);
0852: this .sourceComponents = sourceComponents;
0853: this .targetComponent = targetComponent;
0854: this .overwrite = overwrite;
0855: this .forceFirstMove = forceMove;
0856: this .pathSelectionManager = pathSelectionManager;
0857: this .environment = environment;
0858: this .sourceEnvironment = sourceEnvironment;
0859: }
0860:
0861: public void run() {
0862: for (int a = 0; a < sourceComponents.length; a++) {
0863: logger.log(Level.FINE,
0864: "Trying to move multi components to '"
0865: + targetComponent.getPath() + "' ");
0866:
0867: Session.getInstance().fireTaskStartEvent(
0868: new TaskStartedEvent(sourceComponents,
0869: Resources.getLocalString("move")));
0870:
0871: ComponentFactory
0872: .getInstance()
0873: .fireComponentAddInProgressEvent(
0874: new ContelligentComponentDisplayEvent(
0875: sourceComponents[a],
0876: targetComponent.getPath()
0877: + "/"
0878: + sourceComponents[a]
0879: .getName(),
0880: ContelligentComponentDisplayEvent.COMPONENT_ADD_IN_PROGRESS));
0881:
0882: ComponentFactory
0883: .getInstance()
0884: .fireComponentRemoveInProgressEvent(
0885: new ContelligentComponentDisplayEvent(
0886: sourceComponents[a],
0887: sourceComponents[a].getPath(),
0888: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_IN_PROGRESS));
0889:
0890: try {
0891: ActionResult response = Actions.move(environment,
0892: sourceEnvironment, sourceComponents[a],
0893: targetComponent, sourceComponents[a]
0894: .getName(), overwrite,
0895: forceFirstMove);
0896: Session.getInstance().fireTaskFinishEvent(
0897: new TaskFinishedEvent(sourceComponents[a]));
0898: if (!forceFirstMove
0899: && response.hasError(Errors.RELATION_EXITS)) {
0900: // XXX: dirty recursion: allow the path selection
0901: // manager to call the multi
0902: // the rest will be done in a second multi move instance
0903: // (recursion)
0904: ContelligentComponent[] newSources = new ContelligentComponent[sourceComponents.length
0905: - a];
0906: System.arraycopy(sourceComponents, a,
0907: newSources, 0, newSources.length);
0908: pathSelectionManager
0909: .setPaths(
0910: Resources
0911: .getLocalString(
0912: "links_exists_move_multi",
0913: new String[] { sourceComponents[a]
0914: .getName() }),
0915: response.getPaths(),
0916: new Action[] { new MultiMoveAction(
0917: environment,
0918: sourceEnvironment,
0919: newSources,
0920: targetComponent,
0921: overwrite, true,
0922: pathSelectionManager) });
0923: pathSelectionManager.showPaths();
0924:
0925: ComponentFactory
0926: .getInstance()
0927: .fireComponentAddAbortedEvent(
0928: new ContelligentComponentDisplayEvent(
0929: sourceComponents[a],
0930: targetComponent
0931: .getPath()
0932: + "/"
0933: + sourceComponents[a]
0934: .getName(),
0935: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0936: ComponentFactory
0937: .getInstance()
0938: .fireComponentRemoveAbortedEvent(
0939: new ContelligentComponentDisplayEvent(
0940: sourceComponents[a],
0941: sourceComponents[a]
0942: .getPath(),
0943: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_ABORTED));
0944:
0945: // the rest is triggered by the action passed to the
0946: // pathSelectionManager
0947: return;
0948: } else if (!overwrite
0949: && response
0950: .hasError(Errors.COMPONENT_EXISTS)) {
0951: final ContelligentComponent cComponent = sourceComponents[a];
0952: final ResultHolder optionResult = new ResultHolder(
0953: ResultHolder.RESULT_INTEGER);
0954: optionResult
0955: .setIntResult(JOptionPane
0956: .showOptionDialog(
0957: ContelligentClient
0958: .getActiveFrame(),
0959: Resources
0960: .getLocalString(
0961: "target_component_exists_override",
0962: new String[] { cComponent
0963: .getName() }),
0964: Resources
0965: .getLocalString("component_exists"),
0966: JOptionPane.YES_NO_OPTION,
0967: JOptionPane.WARNING_MESSAGE,
0968: null,
0969: YES_YESALL_NO_CANCEL_OPTIONS,
0970: YES_YESALL_NO_CANCEL_OPTIONS[0]));
0971:
0972: if (optionResult.getIntResult() == DOPTION_CANCEL) {
0973: ComponentFactory
0974: .getInstance()
0975: .fireComponentAddAbortedEvent(
0976: new ContelligentComponentDisplayEvent(
0977: sourceComponents[a],
0978: targetComponent
0979: .getPath()
0980: + "/"
0981: + sourceComponents[a]
0982: .getName(),
0983: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
0984: ComponentFactory
0985: .getInstance()
0986: .fireComponentRemoveAbortedEvent(
0987: new ContelligentComponentDisplayEvent(
0988: sourceComponents[a],
0989: sourceComponents[a]
0990: .getPath(),
0991: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_ABORTED));
0992: return;
0993: } else if (optionResult.getIntResult() == DOPTION_YES) {
0994: // if YES
0995: execute(new MoveAction(environment,
0996: sourceEnvironment,
0997: sourceComponents[a],
0998: targetComponent,
0999: sourceComponents[a].getName(),
1000: true, forceFirstMove,
1001: pathSelectionManager));
1002: } else if (optionResult.getIntResult() == DOPTION_YESALL) {
1003: // if YES to All
1004: ContelligentComponent[] restSources = new ContelligentComponent[sourceComponents.length
1005: - a];
1006: System.arraycopy(sourceComponents, a,
1007: restSources, 0,
1008: sourceComponents.length - a);
1009: execute(new MultiMoveAction(environment,
1010: sourceEnvironment, restSources,
1011: targetComponent, true,
1012: forceFirstMove,
1013: pathSelectionManager));
1014: // return here, because the rest is done by the
1015: // execute above
1016: return;
1017: } else if (optionResult.getIntResult() == DOPTION_NO) {
1018: // if NO
1019: ComponentFactory
1020: .getInstance()
1021: .fireComponentAddAbortedEvent(
1022: new ContelligentComponentDisplayEvent(
1023: sourceComponents[a],
1024: targetComponent
1025: .getPath()
1026: + "/"
1027: + sourceComponents[a]
1028: .getName(),
1029: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
1030: ComponentFactory
1031: .getInstance()
1032: .fireComponentRemoveAbortedEvent(
1033: new ContelligentComponentDisplayEvent(
1034: sourceComponents[a],
1035: sourceComponents[a]
1036: .getPath(),
1037: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_ABORTED));
1038: // do not return here .. go on with the next
1039: }
1040:
1041: } else if (response.hasError()) {
1042: response.showErrors();
1043: ComponentFactory
1044: .getInstance()
1045: .fireComponentRemoveAbortedEvent(
1046: new ContelligentComponentDisplayEvent(
1047: sourceComponents[a],
1048: sourceComponents[a]
1049: .getPath(),
1050: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_ABORTED));
1051: ComponentFactory
1052: .getInstance()
1053: .fireComponentAddAbortedEvent(
1054: new ContelligentComponentDisplayEvent(
1055: sourceComponents[a],
1056: targetComponent
1057: .getPath()
1058: + "/"
1059: + sourceComponents[a]
1060: .getName(),
1061: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
1062: } else {
1063: response.showErrors();
1064: }
1065: } catch (RemoteActionException rae) {
1066: ExceptionDialog.show(rae);
1067: ComponentFactory
1068: .getInstance()
1069: .fireComponentRemoveAbortedEvent(
1070: new ContelligentComponentDisplayEvent(
1071: sourceComponents[a],
1072: sourceComponents[a]
1073: .getPath(),
1074: ContelligentComponentDisplayEvent.COMPONENT_REMOVE_ABORTED));
1075: ComponentFactory
1076: .getInstance()
1077: .fireComponentAddAbortedEvent(
1078: new ContelligentComponentDisplayEvent(
1079: sourceComponents[a],
1080: targetComponent.getPath()
1081: + "/"
1082: + sourceComponents[a]
1083: .getName(),
1084: ContelligentComponentDisplayEvent.COMPONENT_ADD_ABORTED));
1085: }
1086: // secondRound is next
1087: forceFirstMove = false;
1088: }
1089: }
1090:
1091: public void actionPerformed(ActionEvent e) {
1092: pathSelectionManager.hidePaths();
1093: execute(this);
1094: }
1095: }
1096: }
|