package cn.com.origin.autocode.saveas;

import java.awt.Frame;

import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFCommand;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.commands.saveas.SaveArchitectureAsDialog;
import com.teamcenter.rac.commands.saveas.SaveAsCommand;
import com.teamcenter.rac.commands.saveas.SaveBOMViewRevisionAsDialog;
import com.teamcenter.rac.commands.saveas.SaveCCObjectAsDialog;
import com.teamcenter.rac.commands.saveas.SaveConfigurationContextAsDialog;
import com.teamcenter.rac.commands.saveas.SaveDatasetAsDialog;
import com.teamcenter.rac.commands.saveas.SaveFolderAsDialog;
import com.teamcenter.rac.commands.saveas.SaveFormAsDialog;
import com.teamcenter.rac.commands.saveas.SaveStructureContextAsDialog;
//import com.teamcenter.rac.commands.saveasconnection.SaveConnectionAsDialog;
import com.teamcenter.rac.commands.saveassignal.SaveSignalAsDialog;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMViewRevision;
import com.teamcenter.rac.kernel.TCComponentCfgAttachmentLine;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.Instancer;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.Registry;

public class ORSaveAsCommand extends SaveAsCommand {

	public ORSaveAsCommand() {
	}

	public ORSaveAsCommand(final Frame paramFrame, final InterfaceAIFComponent[] paramArrayOfInterfaceAIFComponent, Boolean paramBoolean) {
		// super(frame, ainterfaceaifcomponent, boolean1);
		Registry localRegistry1 = Registry.getRegistry(this);
		if (paramArrayOfInterfaceAIFComponent == null) {
			MessageBox.post(paramFrame, localRegistry1.getString("noObjectsSelected"), localRegistry1.getString("saveAsNoSelection.TITLE"), 4);
		} else if (paramArrayOfInterfaceAIFComponent.length != 1) {
			MessageBox.post(paramFrame, localRegistry1.getString("toomanyobjects"), localRegistry1.getString("saveAs.TITLE"), 4);
		} else {
			Object localObject1 = null;
			if (paramArrayOfInterfaceAIFComponent[0] instanceof TCComponentCfgAttachmentLine)
				try {
					localObject1 = ((TCComponentCfgAttachmentLine) paramArrayOfInterfaceAIFComponent[0]).getUnderlyingComponent();
					paramArrayOfInterfaceAIFComponent[0] = (InterfaceAIFComponent) localObject1;
				} catch (TCException localTCException1) {
					MessageBox.post(paramFrame, localTCException1);
				}
			else
				localObject1 = paramArrayOfInterfaceAIFComponent[0];
			TCComponent localTCComponent = (TCComponent) localObject1;
			try {
				Object localObject2;
				Object localObject3;
				String str1 = null;
				String str2 = null;
				str1 = "saveAs" + localTCComponent.getType().replaceAll(" ", "") + ".DIALOG";
				str2 = localRegistry1.getString(str1, null);
				if (str2 == null) {
					str1 = "saveAs" + getClassTypeName(localTCComponent) + ".DIALOG";
					str2 = localRegistry1.getString(str1, null);
				}
				Registry localRegistry2 = Registry.getRegistry("com.teamcenter.rac.common.actions.actions");
				if (str2 != null) {
					localObject2 = null;
					if (localTCComponent.isTypeOf("ItemRevision")) {
						localObject2 = new Object[] { paramFrame, localObject1, null, paramBoolean };
					} else {
						if ((localTCComponent.isTypeOf("GDELine")) || (localTCComponent.isTypeOf("GDEBOPLine"))) {
							MessageBox.post(paramFrame, localRegistry1.getString("saveGDELineAction.ERRORMSG"), localRegistry1.getString("saveGDELineAction.ERROR"), 4);
							return;
						}
						if ((localTCComponent.isTypeOf("BOMLine")) || (localTCComponent.isTypeOf("ImanItemBOPLine"))) {
							localObject3 = (TCComponentBOMLine) localTCComponent;
							localObject2 = new Object[] { paramFrame, ((TCComponentBOMLine) localObject3).getItemRevision(), ((TCComponentBOMLine) localObject3).window(), paramBoolean };
						} else {
							localObject2 = new Object[] { paramFrame, localObject1 };
						}
					}
					localObject3 = (AbstractAIFDialog) localRegistry1.newInstanceFor(str1, localObject2);
					setRunnable((Runnable) localObject3);
				} else if (localTCComponent.isTypeOf("Folder")) {
					setRunnable(new SaveFolderAsDialog(paramFrame, (InterfaceAIFComponent) localObject1));
				} else if ((localTCComponent.isTypeOf("EngChange")) || (localTCComponent.isTypeOf("EngChange Revision"))) {
					localObject2 = localTCComponent.getSession();
					((TCSession) localObject2).queueOperation(new AbstractAIFOperation() {
						public void executeOperation() throws Exception {
							AbstractAIFDialog abstractaifdialog2 = (AbstractAIFDialog) Instancer.newInstance("com.teamcenter.rac.commands.create.CreateECDialog", new Object[] { paramFrame, paramArrayOfInterfaceAIFComponent, Boolean.valueOf(true), Integer.valueOf(2) });
							setRunnable(abstractaifdialog2);
						}
					});
				} else if (localTCComponent.isTypeOf("Architecture")) {
					setRunnable(new SaveArchitectureAsDialog(paramFrame, (InterfaceAIFComponent) localObject1));
				} else if (localTCComponent.isTypeOf("ArchitectureRevision")) {
					localObject2 = (AbstractAIFCommand) localRegistry2.newInstanceFor("saveAsArchitectureRevCommand", new Object[] { paramFrame, paramArrayOfInterfaceAIFComponent });
					setRunnable((Runnable) localObject2);
				} else if (localTCComponent.isTypeOf("Item")) {
					if (localTCComponent.getClassType().toString().equals("PSConnection")) {
						//setRunnable(new SaveConnectionAsDialog(paramFrame, (InterfaceAIFComponent) localObject1));
					} else if (localTCComponent.getClassType().toString().equals("PSSignal")) {
						setRunnable(new SaveSignalAsDialog(paramFrame, (InterfaceAIFComponent) localObject1));
					} else if (localTCComponent.isTypeOf("Schedule")) {
						localObject2 = (AbstractAIFDialog) localRegistry2.newInstanceFor("saveAsScheduleDialog", new Object[] { paramFrame, localObject1 });
						setRunnable((Runnable) localObject2);
					} else {
						// ====================tyl
						// 20110810=======================//
						if (paramArrayOfInterfaceAIFComponent[0] instanceof TCComponentItem) {
							TCComponentItem item = (TCComponentItem) paramArrayOfInterfaceAIFComponent[0];
							new ORSaveItemAsDialog(AIFDesktop.getFrames()[0], item).run();
						}
						// ====================tyl
						// 20110810=======================//

						// setRunnable(new SaveItemAsDialog(paramFrame,
						// (InterfaceAIFComponent) localObject1));
					}
				} else if ((localTCComponent.isTypeOf("CAEBCItemRevision")) || (localTCComponent.isTypeOf("CAELoadItemRevision"))) {
					localObject2 = (AbstractAIFCommand) localRegistry1.newInstanceFor("saveAsCAEItemRevCommand", new Object[] { paramFrame, paramArrayOfInterfaceAIFComponent });
					setRunnable((Runnable) localObject2);
				} else if (localTCComponent.isTypeOf("CAEItemRevision")) {
					localObject2 = (AbstractAIFCommand) localRegistry1.newInstanceFor("saveAsCAEIRCommand", new Object[] { paramFrame, paramArrayOfInterfaceAIFComponent });
					setRunnable((Runnable) localObject2);
				} else if (localTCComponent.isTypeOf("ManufacturerPart Revision")) {
					localObject2 = localRegistry1.getString("saveAsManufacturerPartRevCommand", null);
					if (localObject2 == null)
						localObject2 = localRegistry1.getString("saveAsItemRevCommand");
					try {
						localObject3 = (AbstractAIFCommand) Instancer.newInstanceEx((String) localObject2, new Object[] { paramFrame, paramArrayOfInterfaceAIFComponent });
						setRunnable((Runnable) localObject3);
					} catch (Exception localException1) {
						MessageBox.post(paramFrame, localException1);
					}
				} else if (localTCComponent.isTypeOf("ItemRevision")) {
					if (localTCComponent.getClassType().toString().equals("PSConnectionRevision")) {
						localObject2 = (AbstractAIFCommand) localRegistry2.newInstanceFor("saveAsConnectionRevCommand", new Object[] { paramFrame, paramArrayOfInterfaceAIFComponent });
						setRunnable((Runnable) localObject2);
					} else if (localTCComponent.getClassType().toString().equals("PSSignalRevision")) {
						localObject2 = (AbstractAIFCommand) localRegistry2.newInstanceFor("saveAsSignalRevCommand", new Object[] { paramFrame, paramArrayOfInterfaceAIFComponent });
						setRunnable((Runnable) localObject2);
					} else if (localTCComponent.isTypeOf("ScheduleRevision")) {
						localObject2 = (AbstractAIFCommand) localRegistry2.newInstanceFor("saveAsScheduleRevCommand", new Object[] { paramFrame, paramArrayOfInterfaceAIFComponent });
						setRunnable((Runnable) localObject2);
					} else {
						// ====================tyl
						// 20110810=======================//
						TCComponentItem item = null;
						if (paramArrayOfInterfaceAIFComponent[0] instanceof TCComponentItemRevision) {
							item = ((TCComponentItemRevision) paramArrayOfInterfaceAIFComponent[0]).getItem();
						}
						new ORSaveItemAsDialog(AIFDesktop.getFrames()[0], item).run();
						// ====================tyl
						// 20110810=======================//
					}
				} else {
					if ((localTCComponent.isTypeOf("GDELine")) || (localTCComponent.isTypeOf("GDEBOPLine"))) {
						MessageBox.post(paramFrame, localRegistry1.getString("saveGDELineAction.ERRORMSG"), localRegistry1.getString("saveGDELineAction.ERROR"), 4);
						return;
					}
					if ((localTCComponent.isTypeOf("BOMLine")) || (localTCComponent.isTypeOf("ImanItemBOPLine"))) {
						localObject2 = ((TCComponentBOMLine) localTCComponent).getUnderlyingComponent();
						if (((TCComponent) localObject2).isTypeOf("Architecture")) {
							setRunnable(new SaveArchitectureAsDialog(paramFrame, (InterfaceAIFComponent) localObject1));
						} else {
							AbstractAIFCommand localAbstractAIFCommand;
							if (((TCComponent) localObject2).isTypeOf("ArchitectureRevision")) {
								localAbstractAIFCommand = (AbstractAIFCommand) localRegistry2.newInstanceFor("saveAsArchitectureRevCommand", new Object[] { paramFrame, paramArrayOfInterfaceAIFComponent });
								setRunnable(localAbstractAIFCommand);
							} else {
								localAbstractAIFCommand = (AbstractAIFCommand) localRegistry2.newInstanceFor("saveAsItemRevCommand", new Object[] { paramFrame, paramArrayOfInterfaceAIFComponent });
								setRunnable(localAbstractAIFCommand);
							}
						}
					} else if (localTCComponent.isTypeOf("PSBOMViewRevision")) {
						setRunnable(new SaveBOMViewRevisionAsDialog(paramFrame, (TCComponentBOMViewRevision) localObject1));
					} else if (localTCComponent.isTypeOf("Form")) {
						setRunnable(new SaveFormAsDialog(paramFrame, (InterfaceAIFComponent) localObject1));
					} else if (localTCComponent.isTypeOf("Dataset")) {
						setRunnable(new SaveDatasetAsDialog(paramFrame, (InterfaceAIFComponent) localObject1));
					} else if (localTCComponent.isTypeOf("CCObject")) {
						setRunnable(new SaveCCObjectAsDialog(paramFrame, (InterfaceAIFComponent) localObject1));
					} else if (localTCComponent.isTypeOf("StructureContext")) {
						setRunnable(new SaveStructureContextAsDialog(paramFrame, (InterfaceAIFComponent) localObject1));
					} else if (localTCComponent.isTypeOf("ConfigurationContext")) {
						setRunnable(new SaveConfigurationContextAsDialog(paramFrame, (InterfaceAIFComponent) localObject1));
					} else {
						MessageBox.post(paramFrame, localRegistry1.getString("unknown.TYPE") + " " + localTCComponent.getDisplayType(), localRegistry1.getString("saveAs.TITLE"), 1);
					}
				}
			} catch (TCException localTCException2) {
				MessageBox.post(paramFrame, localTCException2);
			}
		}
	}
}
