001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.ui.variant.test;
025:
026: import java.io.File;
027:
028: import javax.xml.transform.TransformerFactoryConfigurationError;
029:
030: import org.eclipse.core.resources.IFile;
031: import org.eclipse.jface.wizard.WizardDialog;
032: import org.eclipse.ui.IWorkbenchPage;
033: import org.eclipse.ui.IWorkbenchWindow;
034: import org.eclipse.ui.PartInitException;
035: import org.eclipse.ui.PlatformUI;
036: import org.eclipse.ui.ide.IDE;
037: import org.eclipse.ui.ide.ResourceUtil;
038:
039: import com.bostechcorp.cbesb.common.i18n.I18N;
040: import com.bostechcorp.cbesb.common.i18n.Messages;
041: import com.bostechcorp.cbesb.ui.util.MsgUtil;
042: import com.bostechcorp.cbesb.ui.util.editor.TestEditorWizard;
043: import com.bostechcorp.cbesb.ui.variant.editor.editors.VariantEditor;
044:
045: public class CommonMethod {
046:
047: private static CommonMethod instance = null;
048:
049: public static String Var_type = null;
050:
051: public String getVar_type() {
052: return Var_type;
053: }
054:
055: public void setVar_type(String var_type) {
056: Var_type = var_type;
057: }
058:
059: private CommonMethod() {
060: }
061:
062: public static CommonMethod getInstance() {
063: if (instance == null)
064: instance = new CommonMethod();
065: return instance;
066: }
067:
068: public void openTestEditor(VariantEditor editor) {
069:
070: IWorkbenchWindow dwindow = PlatformUI.getWorkbench()
071: .getActiveWorkbenchWindow();
072:
073: ResourceUtil.getFile(editor.getEditorInput());
074:
075: IWorkbenchPage page = dwindow.getActivePage();
076: if (editor.getEsbFileName() == null) {
077: MsgUtil.warningMsg(I18N
078: .getString(Messages.TEST_EDITOR_DOUBLE_CLICK));
079: return;
080: }
081: if (editor.getEsbFileName().endsWith("/segment")) {
082: MsgUtil.warningMsg(I18N
083: .getString(Messages.TEST_EDITOR_SELECT_MESSAGE));
084: return;
085: }
086: IFile iEditorInput = editor.getCurrentProject().getFile(
087: editor.getCurrentFileName());
088:
089: String varName = iEditorInput.getName().substring(0,
090: iEditorInput.getName().indexOf("."));
091: try {
092: IDE
093: .openEditor(
094: page,
095: iEditorInput,
096: "com.bostechcorp.cbesb.ui.variant.test.VariantTestEditor",
097: true);
098: openWizard(handleEsbName(editor.getEsbFileName(), varName),
099: editor.getFormatType());
100: } catch (PartInitException e) {
101: e.printStackTrace();
102: MsgUtil.warningMsg(e.toString());
103: }
104: }
105:
106: private String handleEsbName(String esbName, String varName) {
107: if (esbName.indexOf("::") == -1)
108: return esbName;
109: String[] array = esbName.split("::");
110: if (array.length < 3) {
111: if (array[1].endsWith("/message"))
112: return esbName.substring(0, esbName
113: .lastIndexOf("/message"));
114:
115: }
116: int pos = array[2].indexOf("//");
117: String temp = array[2].substring(0, pos + 1) + varName
118: + array[2].substring(pos + 1);
119: if (temp.endsWith("/message"))
120: temp = temp.substring(0, temp.lastIndexOf("/message"));
121: return array[0] + "::" + temp;
122:
123: }
124:
125: public void openWizard(String esbFileName, String formatType) {
126:
127: TestEditorWizard test = new TestEditorWizard(
128: (VariantTestEditor) PlatformUI.getWorkbench()
129: .getActiveWorkbenchWindow().getActivePage()
130: .getActiveEditor(),
131: "Format Test Editor Wizard Page", null);
132: WizardDialog wizard = new WizardDialog(PlatformUI
133: .getWorkbench().getActiveWorkbenchWindow().getShell(),
134: test);
135: if (wizard.open() == WizardDialog.CANCEL)
136: return;
137:
138: String filePath = test.getFilePath();
139: String readStyle = test.getReadStyle();
140: VariantTestEditor formatTestEditor = (VariantTestEditor) PlatformUI
141: .getWorkbench().getActiveWorkbenchWindow()
142: .getActivePage().getActiveEditor();
143: formatTestEditor.setEsbFileName(esbFileName);
144: formatTestEditor.setFormatType(formatType);
145:
146: // return mainPage.finish();
147: File file = new File(filePath);
148:
149: try {
150: formatTestEditor.TestMDLFile(filePath, readStyle);
151: } catch (Exception e) {
152: e.printStackTrace();
153: MsgUtil.warningMsg(e.toString());
154: } catch (TransformerFactoryConfigurationError e) {
155: e.printStackTrace();
156: MsgUtil.warningMsg(e.toString());
157: }
158:
159: if (readStyle.equals("EOF")) {
160: formatTestEditor.getComposite().getButtonGoTo().setEnabled(
161: false);
162: formatTestEditor.getComposite().getButtonNext().setEnabled(
163: false);
164: formatTestEditor.getComposite().getButtonPrev().setEnabled(
165: false);
166: formatTestEditor.getComposite().getTextGoTo().setEnabled(
167: false);
168: formatTestEditor.getComposite().getLabelCurrentPage()
169: .setEnabled(false);
170: } else {
171: formatTestEditor.getComposite().getButtonGoTo().setEnabled(
172: true);
173: formatTestEditor.getComposite().getButtonNext().setEnabled(
174: true);
175: formatTestEditor.getComposite().getButtonPrev().setEnabled(
176: true);
177: formatTestEditor.getComposite().getTextGoTo().setEnabled(
178: true);
179: formatTestEditor.getComposite().getLabelCurrentPage()
180: .setEnabled(true);
181: formatTestEditor.getComposite().getTextGoTo().setText("1");
182: formatTestEditor.getComposite().getLabelCurrentPage()
183: .setText(
184: "Page 1 of "
185: + formatTestEditor.getTestData()
186: .size());
187: }
188: formatTestEditor.getCurrentDataFile().setText(
189: "Data file:" + file.getName());
190: }
191: }
|